{"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s678124965", "group_id": "codeNet:p02536", "input_text": "#|\n------------------------------------\n Utils \n------------------------------------\n|#\n\n(in-package :cl-user)\n\n(defconstant +mod+ 1000000007)\n;(defconstant +mod+ 998244353)\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (term-char #\\Space))\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let* ((,buffer (load-time-value (make-string ,buffer-size :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n ,(if (member :swank *features*)\n `(read-char ,in nil #\\Newline) ; on SLIME\n `(code-char (read-byte ,in nil #.(char-code #\\Newline))))\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,term-char))\n (return (values ,buffer ,idx))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare (inline read-byte)\n #-swank (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (read-byte in nil 0))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))\n (return (if minus (- result) result))))))))\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n(declaim (inline read-numbers-to-list))\n(defun read-numbers-to-list (size)\n (loop repeat size collect (read-fixnum)))\n\n(declaim (inline read-numbers-to-array))\n(defun read-numbers-to-array (size)\n (let ((arr (make-array size\n :element-type 'fixnum\n :adjustable nil)))\n (declare ((array fixnum 1) arr))\n (loop for i of-type fixnum below size do\n (setf (aref arr i) (read-fixnum))\n finally\n (return arr))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (buffered-read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(declaim (inline princ-for-each-line))\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(declaim (inline unwrap))\n(defun unwrap (list)\n (the string\n (format nil \"~{~a~^ ~}\" list)))\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(defmacro maxf (place cand)\n `(setf ,place (max ,place ,cand)))\n\n(defmacro minf (place cand)\n `(setf ,place (min ,place ,cand)))\n\n(defmacro modf (place &optional (m +mod+))\n `(setf ,place (mod ,place ,m)))\n\n(defmacro alambda (parms &body body)\n `(labels ((self ,parms ,@body))\n #'self))\n\n(declaim (inline iota))\n(defun iota (count &optional (start 0) (step 1))\n (loop for i from 0 below count collect (+ start (* i step))))\n\n(declaim (inline int->lst))\n(defun int->lst (integer)\n (declare ((integer 0) integer))\n (labels ((sub (int &optional (acc nil))\n (declare ((integer 0) int)\n (list acc))\n (if (zerop int)\n acc\n (sub (floor int 10) (cons (rem int 10) acc)))))\n (sub integer)))\n\n(declaim (inline lst->int))\n(defun lst->int (list)\n (declare (list list))\n (labels ((sub (xs &optional (acc 0))\n (declare (ftype (function (list &optional (integer 0)) (integer 0)) sub))\n (declare (list xs)\n ((integer 0) acc))\n (if (null xs)\n acc\n (sub (rest xs) (+ (* acc 10)\n (rem (first xs) 10))))))\n (the fixnum\n (sub list))))\n\n(defun int->str (integer)\n (format nil \"~a\" integer))\n\n(defun str->int (str)\n (parse-integer str))\n\n(defun char->int (char)\n (declare (character char))\n (- (char-code char) #.(char-code #\\0)))\n\n(declaim (inline prime-factorize-to-list))\n(defun prime-factorize-to-list (integer)\n (declare ((integer 0) integer))\n (the list\n (if (<= integer 1)\n nil\n (loop\n while (<= (* f f) integer)\n with acc list = nil\n with f integer = 2\n do\n (if (zerop (rem integer f))\n (progn\n (push f acc)\n (setq integer (floor integer f)))\n (incf f))\n finally\n (when (/= integer 1)\n (push integer acc))\n (return (reverse acc))))))\n\n(declaim (inline prime-p))\n(defun prime-p (integer)\n (declare ((integer 1) integer))\n (if (= integer 1)\n nil\n (loop\n with f = 2\n while (<= (* f f) integer)\n do\n (when (zerop (rem integer f))\n (return nil))\n (incf f)\n finally\n (return t))))\n\n(declaim (inline count-subsequence))\n(defun count-subsequence (mainstr substr)\n (let ((main-len (length mainstr))\n (sub-len (length substr)))\n (count-if (lambda (i)\n (every (lambda (j)\n (char-equal (char mainstr (+ i j))\n (char substr j)))\n (iota sub-len)))\n (iota (1+ (- main-len sub-len))))))\n\n(defmacro def-memoized-function (name lambda-list &body body)\n (let ((cache (gensym))\n (val (gensym))\n (win (gensym)))\n `(let ((,cache (make-hash-table :test #'equal)))\n (defun ,name ,lambda-list\n (multiple-value-bind (,val ,win) (gethash (list ,@lambda-list) ,cache)\n (if ,win\n ,val\n (setf (gethash (list ,@lambda-list) ,cache)\n (progn\n ,@body))))))))\n\n#|\n------------------------------------\n Body \n------------------------------------\n|#\n\n(in-package :cl-user)\n\n\n(defclass uf-tree ()\n ((parents\n :initarg :parents\n :accessor parents)\n (group-count\n :initarg :group-count\n :accessor group-count)))\n\n\n(defun uf-create (size)\n (declare (fixnum size))\n (make-instance 'uf-tree\n :parents (make-array size :initial-element -1)\n :group-count size))\n\n(defmethod uf-find ((uf uf-tree) (x fixnum))\n (if (minusp (aref (parents uf) x))\n x\n (setf (aref (parents uf) x)\n (uf-find uf (aref (parents uf) x)))))\n\n(defmethod uf-show-parents ((uf uf-tree))\n (map 'vector\n (lambda (x)\n (if (minusp x)\n x\n (uf-find uf x)))\n (parents uf)))\n \n\n(defmethod uf-unite ((uf uf-tree) (x fixnum) (y fixnum))\n (when (> x y)\n (rotatef x y))\n (let ((x-parent (uf-find uf x))\n (y-parent (uf-find uf y)))\n (unless (= x-parent y-parent)\n (incf (aref (parents uf) x-parent)\n (aref (parents uf) y-parent))\n (setf (aref (parents uf) y-parent) x-parent)\n (decf (group-count uf)))))\n\n(defmethod uf-get-tree-size ((uf uf-tree) (x fixnum))\n (- (aref (parents uf) (uf-find uf x))))\n\n\n(defmethod uf-count-trees ((uf uf-tree))\n (group-count uf))\n\n(defmethod uf-friends-p ((uf uf-tree) (x fixnum) (y fixnum))\n (= (uf-find uf x)\n (uf-find uf y)))\n\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (uf (uf-create n)))\n (declare (fixnum n m)\n (uf-tree uf))\n (dotimes (_ m)\n (let ((a (1- (read-fixnum)))\n (b (1- (read-fixnum))))\n (declare (fixnum a b))\n (uf-unite uf a b)))\n (princ (1- (uf-count-trees uf)))\n (fresh-line)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1601219760, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02536.html", "problem_id": "p02536", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02536/input.txt", "sample_output_relpath": "derived/input_output/data/p02536/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02536/Lisp/s678124965.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s678124965", "user_id": "u425762225"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "#|\n------------------------------------\n Utils \n------------------------------------\n|#\n\n(in-package :cl-user)\n\n(defconstant +mod+ 1000000007)\n;(defconstant +mod+ 998244353)\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (term-char #\\Space))\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let* ((,buffer (load-time-value (make-string ,buffer-size :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n ,(if (member :swank *features*)\n `(read-char ,in nil #\\Newline) ; on SLIME\n `(code-char (read-byte ,in nil #.(char-code #\\Newline))))\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,term-char))\n (return (values ,buffer ,idx))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare (inline read-byte)\n #-swank (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (read-byte in nil 0))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))\n (return (if minus (- result) result))))))))\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n(declaim (inline read-numbers-to-list))\n(defun read-numbers-to-list (size)\n (loop repeat size collect (read-fixnum)))\n\n(declaim (inline read-numbers-to-array))\n(defun read-numbers-to-array (size)\n (let ((arr (make-array size\n :element-type 'fixnum\n :adjustable nil)))\n (declare ((array fixnum 1) arr))\n (loop for i of-type fixnum below size do\n (setf (aref arr i) (read-fixnum))\n finally\n (return arr))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (buffered-read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(declaim (inline princ-for-each-line))\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(declaim (inline unwrap))\n(defun unwrap (list)\n (the string\n (format nil \"~{~a~^ ~}\" list)))\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(defmacro maxf (place cand)\n `(setf ,place (max ,place ,cand)))\n\n(defmacro minf (place cand)\n `(setf ,place (min ,place ,cand)))\n\n(defmacro modf (place &optional (m +mod+))\n `(setf ,place (mod ,place ,m)))\n\n(defmacro alambda (parms &body body)\n `(labels ((self ,parms ,@body))\n #'self))\n\n(declaim (inline iota))\n(defun iota (count &optional (start 0) (step 1))\n (loop for i from 0 below count collect (+ start (* i step))))\n\n(declaim (inline int->lst))\n(defun int->lst (integer)\n (declare ((integer 0) integer))\n (labels ((sub (int &optional (acc nil))\n (declare ((integer 0) int)\n (list acc))\n (if (zerop int)\n acc\n (sub (floor int 10) (cons (rem int 10) acc)))))\n (sub integer)))\n\n(declaim (inline lst->int))\n(defun lst->int (list)\n (declare (list list))\n (labels ((sub (xs &optional (acc 0))\n (declare (ftype (function (list &optional (integer 0)) (integer 0)) sub))\n (declare (list xs)\n ((integer 0) acc))\n (if (null xs)\n acc\n (sub (rest xs) (+ (* acc 10)\n (rem (first xs) 10))))))\n (the fixnum\n (sub list))))\n\n(defun int->str (integer)\n (format nil \"~a\" integer))\n\n(defun str->int (str)\n (parse-integer str))\n\n(defun char->int (char)\n (declare (character char))\n (- (char-code char) #.(char-code #\\0)))\n\n(declaim (inline prime-factorize-to-list))\n(defun prime-factorize-to-list (integer)\n (declare ((integer 0) integer))\n (the list\n (if (<= integer 1)\n nil\n (loop\n while (<= (* f f) integer)\n with acc list = nil\n with f integer = 2\n do\n (if (zerop (rem integer f))\n (progn\n (push f acc)\n (setq integer (floor integer f)))\n (incf f))\n finally\n (when (/= integer 1)\n (push integer acc))\n (return (reverse acc))))))\n\n(declaim (inline prime-p))\n(defun prime-p (integer)\n (declare ((integer 1) integer))\n (if (= integer 1)\n nil\n (loop\n with f = 2\n while (<= (* f f) integer)\n do\n (when (zerop (rem integer f))\n (return nil))\n (incf f)\n finally\n (return t))))\n\n(declaim (inline count-subsequence))\n(defun count-subsequence (mainstr substr)\n (let ((main-len (length mainstr))\n (sub-len (length substr)))\n (count-if (lambda (i)\n (every (lambda (j)\n (char-equal (char mainstr (+ i j))\n (char substr j)))\n (iota sub-len)))\n (iota (1+ (- main-len sub-len))))))\n\n(defmacro def-memoized-function (name lambda-list &body body)\n (let ((cache (gensym))\n (val (gensym))\n (win (gensym)))\n `(let ((,cache (make-hash-table :test #'equal)))\n (defun ,name ,lambda-list\n (multiple-value-bind (,val ,win) (gethash (list ,@lambda-list) ,cache)\n (if ,win\n ,val\n (setf (gethash (list ,@lambda-list) ,cache)\n (progn\n ,@body))))))))\n\n#|\n------------------------------------\n Body \n------------------------------------\n|#\n\n(in-package :cl-user)\n\n\n(defclass uf-tree ()\n ((parents\n :initarg :parents\n :accessor parents)\n (group-count\n :initarg :group-count\n :accessor group-count)))\n\n\n(defun uf-create (size)\n (declare (fixnum size))\n (make-instance 'uf-tree\n :parents (make-array size :initial-element -1)\n :group-count size))\n\n(defmethod uf-find ((uf uf-tree) (x fixnum))\n (if (minusp (aref (parents uf) x))\n x\n (setf (aref (parents uf) x)\n (uf-find uf (aref (parents uf) x)))))\n\n(defmethod uf-show-parents ((uf uf-tree))\n (map 'vector\n (lambda (x)\n (if (minusp x)\n x\n (uf-find uf x)))\n (parents uf)))\n \n\n(defmethod uf-unite ((uf uf-tree) (x fixnum) (y fixnum))\n (when (> x y)\n (rotatef x y))\n (let ((x-parent (uf-find uf x))\n (y-parent (uf-find uf y)))\n (unless (= x-parent y-parent)\n (incf (aref (parents uf) x-parent)\n (aref (parents uf) y-parent))\n (setf (aref (parents uf) y-parent) x-parent)\n (decf (group-count uf)))))\n\n(defmethod uf-get-tree-size ((uf uf-tree) (x fixnum))\n (- (aref (parents uf) (uf-find uf x))))\n\n\n(defmethod uf-count-trees ((uf uf-tree))\n (group-count uf))\n\n(defmethod uf-friends-p ((uf uf-tree) (x fixnum) (y fixnum))\n (= (uf-find uf x)\n (uf-find uf y)))\n\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (uf (uf-create n)))\n (declare (fixnum n m)\n (uf-tree uf))\n (dotimes (_ m)\n (let ((a (1- (read-fixnum)))\n (b (1- (read-fixnum))))\n (declare (fixnum a b))\n (uf-unite uf a b)))\n (princ (1- (uf-count-trees uf)))\n (fresh-line)))\n\n#-swank (main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M.\nRoad i connects City A_i and City B_i.\n\nSnuke can perform the following operation zero or more times:\n\nChoose two distinct cities that are not directly connected by a road, and build a new road between the two cities.\n\nAfter he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times).\n\nWhat is the minimum number of roads he must build to achieve the goal?\n\nConstraints\n\n2 \\leq N \\leq 100,000\n\n1 \\leq M \\leq 100,000\n\n1 \\leq A_i < B_i \\leq N\n\nNo two roads connect the same pair of cities.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\n:\nA_M B_M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3 1\n1 2\n\nSample Output 1\n\n1\n\nInitially, there are three cities, and there is a road between City 1 and City 2.\n\nSnuke can achieve the goal by building one new road, for example, between City 1 and City 3.\nAfter that,\n\nWe can travel between 1 and 2 directly.\n\nWe can travel between 1 and 3 directly.\n\nWe can travel between 2 and 3 by following both roads (2 - 1 - 3).", "sample_input": "3 1\n1 2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02536", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M.\nRoad i connects City A_i and City B_i.\n\nSnuke can perform the following operation zero or more times:\n\nChoose two distinct cities that are not directly connected by a road, and build a new road between the two cities.\n\nAfter he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times).\n\nWhat is the minimum number of roads he must build to achieve the goal?\n\nConstraints\n\n2 \\leq N \\leq 100,000\n\n1 \\leq M \\leq 100,000\n\n1 \\leq A_i < B_i \\leq N\n\nNo two roads connect the same pair of cities.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\n:\nA_M B_M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3 1\n1 2\n\nSample Output 1\n\n1\n\nInitially, there are three cities, and there is a road between City 1 and City 2.\n\nSnuke can achieve the goal by building one new road, for example, between City 1 and City 3.\nAfter that,\n\nWe can travel between 1 and 2 directly.\n\nWe can travel between 1 and 3 directly.\n\nWe can travel between 2 and 3 by following both roads (2 - 1 - 3).", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10356, "cpu_time_ms": 74, "memory_kb": 29172}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s350537542", "group_id": "codeNet:p02536", "input_text": "#|\n------------------------------------\n Utils \n------------------------------------\n|#\n\n(in-package :cl-user)\n\n(defconstant +mod+ 1000000007)\n;(defconstant +mod+ 998244353)\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (term-char #\\Space))\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let* ((,buffer (load-time-value (make-string ,buffer-size :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n ,(if (member :swank *features*)\n `(read-char ,in nil #\\Newline) ; on SLIME\n `(code-char (read-byte ,in nil #.(char-code #\\Newline))))\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,term-char))\n (return (values ,buffer ,idx))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare (inline read-byte)\n #-swank (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (read-byte in nil 0))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))\n (return (if minus (- result) result))))))))\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n(declaim (inline read-numbers-to-list))\n(defun read-numbers-to-list (size)\n (loop repeat size collect (read-fixnum)))\n\n(declaim (inline read-numbers-to-array))\n(defun read-numbers-to-array (size)\n (let ((arr (make-array size\n :element-type 'fixnum\n :adjustable nil)))\n (declare ((array fixnum 1) arr))\n (loop for i of-type fixnum below size do\n (setf (aref arr i) (read-fixnum))\n finally\n (return arr))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (buffered-read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(declaim (inline princ-for-each-line))\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(declaim (inline unwrap))\n(defun unwrap (list)\n (the string\n (format nil \"~{~a~^ ~}\" list)))\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(defmacro maxf (place cand)\n `(setf ,place (max ,place ,cand)))\n\n(defmacro minf (place cand)\n `(setf ,place (min ,place ,cand)))\n\n(defmacro modf (place &optional (m +mod+))\n `(setf ,place (mod ,place ,m)))\n\n(defmacro alambda (parms &body body)\n `(labels ((self ,parms ,@body))\n #'self))\n\n(declaim (inline iota))\n(defun iota (count &optional (start 0) (step 1))\n (loop for i from 0 below count collect (+ start (* i step))))\n\n(declaim (inline int->lst))\n(defun int->lst (integer)\n (declare ((integer 0) integer))\n (labels ((sub (int &optional (acc nil))\n (declare ((integer 0) int)\n (list acc))\n (if (zerop int)\n acc\n (sub (floor int 10) (cons (rem int 10) acc)))))\n (sub integer)))\n\n(declaim (inline lst->int))\n(defun lst->int (list)\n (declare (list list))\n (labels ((sub (xs &optional (acc 0))\n (declare (ftype (function (list &optional (integer 0)) (integer 0)) sub))\n (declare (list xs)\n ((integer 0) acc))\n (if (null xs)\n acc\n (sub (rest xs) (+ (* acc 10)\n (rem (first xs) 10))))))\n (the fixnum\n (sub list))))\n\n(defun int->str (integer)\n (format nil \"~a\" integer))\n\n(defun str->int (str)\n (parse-integer str))\n\n(defun char->int (char)\n (declare (character char))\n (- (char-code char) #.(char-code #\\0)))\n\n(declaim (inline prime-factorize-to-list))\n(defun prime-factorize-to-list (integer)\n (declare ((integer 0) integer))\n (the list\n (if (<= integer 1)\n nil\n (loop\n while (<= (* f f) integer)\n with acc list = nil\n with f integer = 2\n do\n (if (zerop (rem integer f))\n (progn\n (push f acc)\n (setq integer (floor integer f)))\n (incf f))\n finally\n (when (/= integer 1)\n (push integer acc))\n (return (reverse acc))))))\n\n(declaim (inline prime-p))\n(defun prime-p (integer)\n (declare ((integer 1) integer))\n (if (= integer 1)\n nil\n (loop\n with f = 2\n while (<= (* f f) integer)\n do\n (when (zerop (rem integer f))\n (return nil))\n (incf f)\n finally\n (return t))))\n\n(declaim (inline count-subsequence))\n(defun count-subsequence (mainstr substr)\n (let ((main-len (length mainstr))\n (sub-len (length substr)))\n (count-if (lambda (i)\n (every (lambda (j)\n (char-equal (char mainstr (+ i j))\n (char substr j)))\n (iota sub-len)))\n (iota (1+ (- main-len sub-len))))))\n\n(defmacro def-memoized-function (name lambda-list &body body)\n (let ((cache (gensym))\n (val (gensym))\n (win (gensym)))\n `(let ((,cache (make-hash-table :test #'equal)))\n (defun ,name ,lambda-list\n (multiple-value-bind (,val ,win) (gethash (list ,@lambda-list) ,cache)\n (if ,win\n ,val\n (setf (gethash (list ,@lambda-list) ,cache)\n (progn\n ,@body))))))))\n\n#|\n------------------------------------\n Body \n------------------------------------\n|#\n\n(in-package :cl-user)\n\n(let (parents)\n ;; \"parents\" retain uf-tree\n\n (defun uf-init (size)\n (setf parents (make-array size :initial-element -1)))\n\n (defun uf-show-parents ()\n parents)\n \n (defun uf-find (x)\n (if (minusp (aref parents x))\n x ; x is root\n (setf (aref parents x) (uf-find (aref parents x)))))\n\n (defun uf-unite (x y)\n (when (> x y)\n (rotatef x y))\n (let ((x-parent (uf-find x))\n (y-parent (uf-find y)))\n (unless (= x-parent y-parent)\n (incf (aref parents x-parent)\n (aref parents y-parent))\n (setf (aref parents y-parent) x-parent))))\n\n (defun uf-get-tree-size (x)\n (- (aref parents (uf-find x))))\n\n (defun uf-count-trees ()\n (length (remove-duplicates\n (mapcar (lambda (idx)\n (uf-find idx))\n (loop for i below (length parents) collect i))\n :test #'=)))\n\n (defun uf-friends-p (x y)\n (= (uf-find x)\n (uf-find y))))\n\n\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (res (1- n)))\n (uf-init n)\n (dotimes (_ m)\n (let ((a (1- (read-fixnum)))\n (b (1- (read-fixnum))))\n (if (not (uf-friends-p a b))\n (progn\n (uf-unite a b)\n (decf res)))))\n (princ res)\n (fresh-line)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1601169397, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02536.html", "problem_id": "p02536", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02536/input.txt", "sample_output_relpath": "derived/input_output/data/p02536/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02536/Lisp/s350537542.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s350537542", "user_id": "u425762225"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "#|\n------------------------------------\n Utils \n------------------------------------\n|#\n\n(in-package :cl-user)\n\n(defconstant +mod+ 1000000007)\n;(defconstant +mod+ 998244353)\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (term-char #\\Space))\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let* ((,buffer (load-time-value (make-string ,buffer-size :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n ,(if (member :swank *features*)\n `(read-char ,in nil #\\Newline) ; on SLIME\n `(code-char (read-byte ,in nil #.(char-code #\\Newline))))\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,term-char))\n (return (values ,buffer ,idx))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare (inline read-byte)\n #-swank (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (read-byte in nil 0))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))\n (return (if minus (- result) result))))))))\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n(declaim (inline read-numbers-to-list))\n(defun read-numbers-to-list (size)\n (loop repeat size collect (read-fixnum)))\n\n(declaim (inline read-numbers-to-array))\n(defun read-numbers-to-array (size)\n (let ((arr (make-array size\n :element-type 'fixnum\n :adjustable nil)))\n (declare ((array fixnum 1) arr))\n (loop for i of-type fixnum below size do\n (setf (aref arr i) (read-fixnum))\n finally\n (return arr))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (buffered-read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(declaim (inline princ-for-each-line))\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(declaim (inline unwrap))\n(defun unwrap (list)\n (the string\n (format nil \"~{~a~^ ~}\" list)))\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(defmacro maxf (place cand)\n `(setf ,place (max ,place ,cand)))\n\n(defmacro minf (place cand)\n `(setf ,place (min ,place ,cand)))\n\n(defmacro modf (place &optional (m +mod+))\n `(setf ,place (mod ,place ,m)))\n\n(defmacro alambda (parms &body body)\n `(labels ((self ,parms ,@body))\n #'self))\n\n(declaim (inline iota))\n(defun iota (count &optional (start 0) (step 1))\n (loop for i from 0 below count collect (+ start (* i step))))\n\n(declaim (inline int->lst))\n(defun int->lst (integer)\n (declare ((integer 0) integer))\n (labels ((sub (int &optional (acc nil))\n (declare ((integer 0) int)\n (list acc))\n (if (zerop int)\n acc\n (sub (floor int 10) (cons (rem int 10) acc)))))\n (sub integer)))\n\n(declaim (inline lst->int))\n(defun lst->int (list)\n (declare (list list))\n (labels ((sub (xs &optional (acc 0))\n (declare (ftype (function (list &optional (integer 0)) (integer 0)) sub))\n (declare (list xs)\n ((integer 0) acc))\n (if (null xs)\n acc\n (sub (rest xs) (+ (* acc 10)\n (rem (first xs) 10))))))\n (the fixnum\n (sub list))))\n\n(defun int->str (integer)\n (format nil \"~a\" integer))\n\n(defun str->int (str)\n (parse-integer str))\n\n(defun char->int (char)\n (declare (character char))\n (- (char-code char) #.(char-code #\\0)))\n\n(declaim (inline prime-factorize-to-list))\n(defun prime-factorize-to-list (integer)\n (declare ((integer 0) integer))\n (the list\n (if (<= integer 1)\n nil\n (loop\n while (<= (* f f) integer)\n with acc list = nil\n with f integer = 2\n do\n (if (zerop (rem integer f))\n (progn\n (push f acc)\n (setq integer (floor integer f)))\n (incf f))\n finally\n (when (/= integer 1)\n (push integer acc))\n (return (reverse acc))))))\n\n(declaim (inline prime-p))\n(defun prime-p (integer)\n (declare ((integer 1) integer))\n (if (= integer 1)\n nil\n (loop\n with f = 2\n while (<= (* f f) integer)\n do\n (when (zerop (rem integer f))\n (return nil))\n (incf f)\n finally\n (return t))))\n\n(declaim (inline count-subsequence))\n(defun count-subsequence (mainstr substr)\n (let ((main-len (length mainstr))\n (sub-len (length substr)))\n (count-if (lambda (i)\n (every (lambda (j)\n (char-equal (char mainstr (+ i j))\n (char substr j)))\n (iota sub-len)))\n (iota (1+ (- main-len sub-len))))))\n\n(defmacro def-memoized-function (name lambda-list &body body)\n (let ((cache (gensym))\n (val (gensym))\n (win (gensym)))\n `(let ((,cache (make-hash-table :test #'equal)))\n (defun ,name ,lambda-list\n (multiple-value-bind (,val ,win) (gethash (list ,@lambda-list) ,cache)\n (if ,win\n ,val\n (setf (gethash (list ,@lambda-list) ,cache)\n (progn\n ,@body))))))))\n\n#|\n------------------------------------\n Body \n------------------------------------\n|#\n\n(in-package :cl-user)\n\n(let (parents)\n ;; \"parents\" retain uf-tree\n\n (defun uf-init (size)\n (setf parents (make-array size :initial-element -1)))\n\n (defun uf-show-parents ()\n parents)\n \n (defun uf-find (x)\n (if (minusp (aref parents x))\n x ; x is root\n (setf (aref parents x) (uf-find (aref parents x)))))\n\n (defun uf-unite (x y)\n (when (> x y)\n (rotatef x y))\n (let ((x-parent (uf-find x))\n (y-parent (uf-find y)))\n (unless (= x-parent y-parent)\n (incf (aref parents x-parent)\n (aref parents y-parent))\n (setf (aref parents y-parent) x-parent))))\n\n (defun uf-get-tree-size (x)\n (- (aref parents (uf-find x))))\n\n (defun uf-count-trees ()\n (length (remove-duplicates\n (mapcar (lambda (idx)\n (uf-find idx))\n (loop for i below (length parents) collect i))\n :test #'=)))\n\n (defun uf-friends-p (x y)\n (= (uf-find x)\n (uf-find y))))\n\n\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (res (1- n)))\n (uf-init n)\n (dotimes (_ m)\n (let ((a (1- (read-fixnum)))\n (b (1- (read-fixnum))))\n (if (not (uf-friends-p a b))\n (progn\n (uf-unite a b)\n (decf res)))))\n (princ res)\n (fresh-line)))\n\n#-swank (main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M.\nRoad i connects City A_i and City B_i.\n\nSnuke can perform the following operation zero or more times:\n\nChoose two distinct cities that are not directly connected by a road, and build a new road between the two cities.\n\nAfter he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times).\n\nWhat is the minimum number of roads he must build to achieve the goal?\n\nConstraints\n\n2 \\leq N \\leq 100,000\n\n1 \\leq M \\leq 100,000\n\n1 \\leq A_i < B_i \\leq N\n\nNo two roads connect the same pair of cities.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\n:\nA_M B_M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3 1\n1 2\n\nSample Output 1\n\n1\n\nInitially, there are three cities, and there is a road between City 1 and City 2.\n\nSnuke can achieve the goal by building one new road, for example, between City 1 and City 3.\nAfter that,\n\nWe can travel between 1 and 2 directly.\n\nWe can travel between 1 and 3 directly.\n\nWe can travel between 2 and 3 by following both roads (2 - 1 - 3).", "sample_input": "3 1\n1 2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02536", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M.\nRoad i connects City A_i and City B_i.\n\nSnuke can perform the following operation zero or more times:\n\nChoose two distinct cities that are not directly connected by a road, and build a new road between the two cities.\n\nAfter he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times).\n\nWhat is the minimum number of roads he must build to achieve the goal?\n\nConstraints\n\n2 \\leq N \\leq 100,000\n\n1 \\leq M \\leq 100,000\n\n1 \\leq A_i < B_i \\leq N\n\nNo two roads connect the same pair of cities.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\n:\nA_M B_M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3 1\n1 2\n\nSample Output 1\n\n1\n\nInitially, there are three cities, and there is a road between City 1 and City 2.\n\nSnuke can achieve the goal by building one new road, for example, between City 1 and City 3.\nAfter that,\n\nWe can travel between 1 and 2 directly.\n\nWe can travel between 1 and 3 directly.\n\nWe can travel between 2 and 3 by following both roads (2 - 1 - 3).", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10015, "cpu_time_ms": 58, "memory_kb": 27224}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s198040919", "group_id": "codeNet:p02538", "input_text": "(let* ((n (read))\n (s (make-string n :initial-element #\\1))\n (q (read)))\n (loop for i below q do\n (let ((l (read))\n (r (read))\n (dd (read-char)))\n (setq s (concatenate 'string \n (subseq s 0 (- l 1))\n (make-string (+ (- r l) 1) :initial-element dd)\n (subseq s r n)))\n (format t \"~D~%\"\n (rem (parse-integer s) 998244353)\n )\n )\n )\n)\n", "language": "Lisp", "metadata": {"date": 1601173330, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02538.html", "problem_id": "p02538", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02538/input.txt", "sample_output_relpath": "derived/input_output/data/p02538/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02538/Lisp/s198040919.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s198040919", "user_id": "u136500538"}, "prompt_components": {"gold_output": "11222211\n77772211\n77333333\n72333333\n72311333\n", "input_to_evaluate": "(let* ((n (read))\n (s (make-string n :initial-element #\\1))\n (q (read)))\n (loop for i below q do\n (let ((l (read))\n (r (read))\n (dd (read-char)))\n (setq s (concatenate 'string \n (subseq s 0 (- l 1))\n (make-string (+ (- r l) 1) :initial-element dd)\n (subseq s r n)))\n (format t \"~D~%\"\n (rem (parse-integer s) 998244353)\n )\n )\n )\n)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nYou have a string S of length N.\nInitially, all characters in S are 1s.\n\nYou will perform queries Q times.\nIn the i-th query, you are given two integers L_i, R_i and a character D_i (which is a digit).\nThen, you must replace all characters from the L_i-th to the R_i-th (inclusive) with D_i.\n\nAfter each query, read the string S as a decimal integer, and print its value modulo 998,244,353.\n\nConstraints\n\n1 \\leq N, Q \\leq 200,000\n\n1 \\leq L_i \\leq R_i \\leq N\n\n1 \\leq D_i \\leq 9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nL_1 R_1 D_1\n:\nL_Q R_Q D_Q\n\nOutput\n\nPrint Q lines.\nIn the i-th line print the value of S after the i-th query, modulo 998,244,353.\n\nSample Input 1\n\n8 5\n3 6 2\n1 4 7\n3 8 3\n2 2 2\n4 5 1\n\nSample Output 1\n\n11222211\n77772211\n77333333\n72333333\n72311333\n\nSample Input 2\n\n200000 1\n123 456 7\n\nSample Output 2\n\n641437905\n\nDon't forget to take the modulo.", "sample_input": "8 5\n3 6 2\n1 4 7\n3 8 3\n2 2 2\n4 5 1\n"}, "reference_outputs": ["11222211\n77772211\n77333333\n72333333\n72311333\n"], "source_document_id": "p02538", "source_text": "Score : 500 points\n\nProblem Statement\n\nYou have a string S of length N.\nInitially, all characters in S are 1s.\n\nYou will perform queries Q times.\nIn the i-th query, you are given two integers L_i, R_i and a character D_i (which is a digit).\nThen, you must replace all characters from the L_i-th to the R_i-th (inclusive) with D_i.\n\nAfter each query, read the string S as a decimal integer, and print its value modulo 998,244,353.\n\nConstraints\n\n1 \\leq N, Q \\leq 200,000\n\n1 \\leq L_i \\leq R_i \\leq N\n\n1 \\leq D_i \\leq 9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nL_1 R_1 D_1\n:\nL_Q R_Q D_Q\n\nOutput\n\nPrint Q lines.\nIn the i-th line print the value of S after the i-th query, modulo 998,244,353.\n\nSample Input 1\n\n8 5\n3 6 2\n1 4 7\n3 8 3\n2 2 2\n4 5 1\n\nSample Output 1\n\n11222211\n77772211\n77333333\n72333333\n72311333\n\nSample Input 2\n\n200000 1\n123 456 7\n\nSample Output 2\n\n641437905\n\nDon't forget to take the modulo.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 495, "cpu_time_ms": 2209, "memory_kb": 131216}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s884797683", "group_id": "codeNet:p02540", "input_text": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Disjoint set (union by size & path compression)\n;;;\n\n(defpackage :cp/disjoint-set\n (:use :cl)\n (:export #:disjoint-set #:make-disjoint-set #:ds-data\n #:ds-root #:ds-unite! #:ds-connected-p #:ds-size))\n(in-package :cp/disjoint-set)\n\n(defstruct (disjoint-set\n (:constructor make-disjoint-set\n (size &aux (data (make-array size :element-type 'fixnum :initial-element -1))))\n (:conc-name ds-)\n (:predicate nil)\n (:copier nil))\n (data nil :type (simple-array fixnum (*))))\n\n(declaim (inline ds-root))\n(defun ds-root (disjoint-set x)\n \"Returns the root of X.\"\n (declare ((mod #.array-total-size-limit) x))\n (let ((data (ds-data disjoint-set)))\n (labels ((recur (x)\n (if (< (aref data x) 0)\n x\n (setf (aref data x)\n (recur (aref data x))))))\n (recur x))))\n\n(declaim (inline ds-unite!))\n(defun ds-unite! (disjoint-set x1 x2)\n \"Destructively unites X1 and X2 and returns true iff X1 and X2 become\nconnected for the first time.\"\n (let ((root1 (ds-root disjoint-set x1))\n (root2 (ds-root disjoint-set x2)))\n (unless (= root1 root2)\n (let ((data (ds-data disjoint-set)))\n ;; NOTE: If you want X1 to always be root, just delete this form. (Time\n ;; complexity becomes worse, however.)\n (when (> (aref data root1) (aref data root2))\n (rotatef root1 root2))\n (incf (aref data root1) (aref data root2))\n (setf (aref data root2) root1)))))\n\n(declaim (inline ds-connected-p))\n(defun ds-connected-p (disjoint-set x1 x2)\n \"Returns true iff X1 and X2 have the same root.\"\n (= (ds-root disjoint-set x1) (ds-root disjoint-set x2)))\n\n(declaim (inline ds-size))\n(defun ds-size (disjoint-set x)\n \"Returns the size of the connected component to which X belongs.\"\n (- (aref (ds-data disjoint-set)\n (ds-root disjoint-set x))))\n\n;;;\n;;; 1-dimensional binary indexed tree on arbitrary commutative monoid\n;;;\n\n(defpackage :cp/abstract-bit\n (:use :cl)\n (:export #:define-bitree))\n(in-package :cp/abstract-bit)\n\n(defmacro define-bitree (name &key (operator '#'+) (identity 0) sum-type (order '#'<))\n \"OPERATOR := binary operator (comprising a commutative monoid)\nIDENTITY := object (identity element of the monoid)\nORDER := nil | strict comparison operator on the monoid\nSUM-TYPE := nil | type specifier\n\nDefines no structure; BIT is just a vector. This macro defines the three\nfunctions: -UPDATE!, point-update function, -FOLD, query function for\nprefix sum, and COERCE-TO-!, constructor. If ORDER is specified, this\nmacro in addition defines -BISECT-LEFT and -BISECT-RIGHT, the\nbisection functions for prefix sums. (Note that these functions work only when\nthe sequence of prefix sums (VECTOR[0], VECTOR[0]+VECTOR[1], ...) is monotone.)\n\nSUM-TYPE is used only for the type declaration: each sum\nVECTOR[i]+VECTOR[i+1]...+VECTOR[i+k] is declared to be this type. When SUM-TYPE\nis NIL, type declaration is omitted. (The array-element-type of vector itself\ndoesn't need to be identical to SUM-TYPE.)\"\n (let* ((name (string name))\n (fname-update (intern (format nil \"~A-UPDATE!\" name)))\n (fname-fold (intern (format nil \"~A-FOLD\" name)))\n (fname-coerce (intern (format nil \"COERCE-TO-~A!\" name)))\n (fname-bisect-left (intern (format nil \"~A-BISECT-LEFT\" name)))\n (fname-bisect-right (intern (format nil \"~A-BISECT-RIGHT\" name))))\n `(progn\n (declaim (inline ,fname-update))\n (defun ,fname-update (bitree index delta)\n \"Destructively increments the vector: vector[INDEX] = vector[INDEX] +\nDELTA\"\n (let ((len (length bitree)))\n (do ((i index (logior i (+ i 1))))\n ((>= i len) bitree)\n (declare ((integer 0 #.most-positive-fixnum) i))\n (setf (aref bitree i)\n (funcall ,operator (aref bitree i) delta)))))\n\n (declaim (inline ,fname-fold))\n (defun ,fname-fold (bitree end)\n \"Returns the sum of the prefix: vector[0] + ... + vector[END-1].\"\n (declare ((integer 0 #.most-positive-fixnum) end))\n (let ((res ,identity))\n ,@(when sum-type `((declare (type ,sum-type res))))\n (do ((i (- end 1) (- (logand i (+ i 1)) 1)))\n ((< i 0) res)\n (declare ((integer -1 #.most-positive-fixnum) i))\n (setf res (funcall ,operator res (aref bitree i))))))\n\n (declaim (inline ,fname-coerce))\n (defun ,fname-coerce (vector)\n \"Destructively constructs BIT from VECTOR. (You doesn't need to call\nthis constructor if what you need is a `zero-filled' BIT, because a vector\nfilled with the identity element is a valid BIT as it is.)\"\n (loop with len = (length vector)\n for i below len\n for dest-i = (logior i (+ i 1))\n when (< dest-i len)\n do (setf (aref vector dest-i)\n (funcall ,operator (aref vector dest-i) (aref vector i)))\n finally (return vector)))\n\n ,@(when order\n `((declaim (inline ,fname-bisect-left))\n (defun ,fname-bisect-left (bitree value)\n \"Returns the smallest index that satisfies VECTOR[0]+ ... +\nVECTOR[index] >= VALUE. Returns the length of VECTOR if VECTOR[0]+\n... +VECTOR[length-1] < VALUE. Note that this function deals with a **closed**\ninterval.\"\n (declare (vector bitree))\n (if (not (funcall ,order ,identity value))\n 0\n (let ((len (length bitree))\n (index+1 0)\n (cumul ,identity))\n (declare ((integer 0 #.most-positive-fixnum) index+1)\n ,@(when sum-type\n `((type ,sum-type cumul))))\n (do ((delta (ash 1 (- (integer-length len) 1))\n (ash delta -1)))\n ((zerop delta) index+1)\n (declare ((integer 0 #.most-positive-fixnum) delta))\n (let ((next-index (+ index+1 delta -1)))\n (when (< next-index len)\n (let ((next-cumul (funcall ,operator cumul (aref bitree next-index))))\n ,@(when sum-type\n `((declare (type ,sum-type next-cumul))))\n (when (funcall ,order next-cumul value)\n (setf cumul next-cumul)\n (incf index+1 delta)))))))))\n (declaim (inline ,fname-bisect-right))\n (defun ,fname-bisect-right (bitree value)\n \"Returns the smallest index that satisfies VECTOR[0]+ ... +\nVECTOR[index] > VALUE. Returns the length of VECTOR if VECTOR[0]+\n... +VECTOR[length-1] <= VALUE. Note that this function deals with a **closed**\ninterval.\"\n (declare (vector bitree))\n (if (funcall ,order value ,identity)\n 0\n (let ((len (length bitree))\n (index+1 0)\n (cumul ,identity))\n (declare ((integer 0 #.most-positive-fixnum) index+1)\n ,@(when sum-type\n `((type ,sum-type cumul))))\n (do ((delta (ash 1 (- (integer-length len) 1))\n (ash delta -1)))\n ((zerop delta) index+1)\n (declare ((integer 0 #.most-positive-fixnum) delta))\n (let ((next-index (+ index+1 delta -1)))\n (when (< next-index len)\n (let ((next-cumul (funcall ,operator cumul (aref bitree next-index))))\n ,@(when sum-type\n `((declare (type ,sum-type next-cumul))))\n (unless (funcall ,order value next-cumul)\n (setf cumul next-cumul)\n (incf index+1 delta))))))))))))))\n\n#+(or)\n(define-bitree bitree\n :operator #'+\n :identity 0\n :sum-type fixnum\n :order #'<)\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/abstract-bit :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/disjoint-set :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(define-bitree bitree\n :operator #'+\n :identity 0\n :sum-type fixnum\n :order #'<)\n\n(declaim (inline less))\n(defun less (a b)\n (declare (fixnum a b))\n (< a b))\n(defun main ()\n (declare #.cl-user::opt\n (inline sort sb-impl::stable-sort-list))\n (let* ((n (read))\n (xs (make-array n :element-type 'uint31 :initial-element 0))\n (ys (make-array n :element-type 'uint31 :initial-element 0))\n (points (make-array n :element-type 'list :initial-element nil))\n (points-xsorted (make-array n :element-type 'list :initial-element nil))\n (points-ysorted (make-array n :element-type 'list :initial-element nil))\n (dset (make-disjoint-set n)))\n (dotimes (i n)\n (let ((x (- (read-fixnum) 1))\n (y (- (read-fixnum) 1)))\n (setf (aref points i) (cons x y)\n (aref points-xsorted i) (list x y i)\n (aref points-ysorted i) (list x y i)\n (aref xs i) x\n (aref ys i) y)))\n (setq points-xsorted (sort points-xsorted #'less :key #'first))\n (setq points-ysorted (sort points-ysorted #'less :key #'second))\n (let ((bitree (make-array n :element-type 'uint31 :initial-element 0)))\n (loop for x1 from 0 below n\n for (_ y1 i1) of-type (uint31 uint31 uint31) = (aref points-xsorted x1)\n do (when (> x1 0)\n (let ((index (bitree-fold bitree y1)))\n (when (> index 0)\n (let* ((y2 (bitree-bisect-left bitree index))\n (i2 (third (aref points-ysorted y2))))\n (ds-unite! dset i1 i2)))))\n (bitree-update! bitree y1 1)))\n (let ((bitree (make-array n :element-type 'uint31 :initial-element 0)))\n (loop for x1 from (- n 1) downto 0\n for (_ y1 i1) of-type (uint31 uint31 uint31) = (aref points-xsorted x1)\n do (when (< x1 (- n 1))\n (let ((index (bitree-fold bitree y1)))\n (when (< index (bitree-fold bitree n))\n (let* ((y2 (bitree-bisect-left bitree (+ index 1)))\n (i2 (third (aref points-ysorted y2))))\n (ds-unite! dset i1 i2)))))\n (bitree-update! bitree y1 1)))\n (let ((bitree (make-array n :element-type 'uint31 :initial-element 0)))\n (loop for y1 from 0 below n\n for (x1 _ i1) of-type (uint31 uint31 uint31) = (aref points-ysorted y1)\n do (when (> y1 0)\n (let ((index (bitree-fold bitree x1)))\n (when (> index 0)\n (let* ((x2 (bitree-bisect-left bitree index))\n (i2 (third (aref points-xsorted x2))))\n (ds-unite! dset i1 i2)))))\n (bitree-update! bitree x1 1)))\n (let ((bitree (make-array n :element-type 'uint31 :initial-element 0)))\n (loop for y1 from (- n 1) downto 0\n for (x1 _ i1) of-type (uint31 uint31 uint31) = (aref points-ysorted y1)\n do (when (< y1 (- n 1))\n (let ((index (bitree-fold bitree x1)))\n (when (< index (bitree-fold bitree n))\n (let* ((x2 (bitree-bisect-left bitree (+ index 1)))\n (i2 (third (aref points-xsorted x2))))\n (ds-unite! dset i1 i2)))))\n (bitree-update! bitree x1 1)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (i n)\n (println (ds-size dset i)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (5am:is\n (equal \"1\n1\n2\n2\n\"\n (run \"4\n1 4\n2 3\n3 1\n4 2\n\" nil)))\n (5am:is\n (equal \"3\n3\n1\n1\n2\n3\n2\n\"\n (run \"7\n6 4\n4 3\n3 5\n7 1\n2 7\n5 2\n1 6\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1600644977, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02540.html", "problem_id": "p02540", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02540/input.txt", "sample_output_relpath": "derived/input_output/data/p02540/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02540/Lisp/s884797683.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s884797683", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n1\n2\n2\n", "input_to_evaluate": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Disjoint set (union by size & path compression)\n;;;\n\n(defpackage :cp/disjoint-set\n (:use :cl)\n (:export #:disjoint-set #:make-disjoint-set #:ds-data\n #:ds-root #:ds-unite! #:ds-connected-p #:ds-size))\n(in-package :cp/disjoint-set)\n\n(defstruct (disjoint-set\n (:constructor make-disjoint-set\n (size &aux (data (make-array size :element-type 'fixnum :initial-element -1))))\n (:conc-name ds-)\n (:predicate nil)\n (:copier nil))\n (data nil :type (simple-array fixnum (*))))\n\n(declaim (inline ds-root))\n(defun ds-root (disjoint-set x)\n \"Returns the root of X.\"\n (declare ((mod #.array-total-size-limit) x))\n (let ((data (ds-data disjoint-set)))\n (labels ((recur (x)\n (if (< (aref data x) 0)\n x\n (setf (aref data x)\n (recur (aref data x))))))\n (recur x))))\n\n(declaim (inline ds-unite!))\n(defun ds-unite! (disjoint-set x1 x2)\n \"Destructively unites X1 and X2 and returns true iff X1 and X2 become\nconnected for the first time.\"\n (let ((root1 (ds-root disjoint-set x1))\n (root2 (ds-root disjoint-set x2)))\n (unless (= root1 root2)\n (let ((data (ds-data disjoint-set)))\n ;; NOTE: If you want X1 to always be root, just delete this form. (Time\n ;; complexity becomes worse, however.)\n (when (> (aref data root1) (aref data root2))\n (rotatef root1 root2))\n (incf (aref data root1) (aref data root2))\n (setf (aref data root2) root1)))))\n\n(declaim (inline ds-connected-p))\n(defun ds-connected-p (disjoint-set x1 x2)\n \"Returns true iff X1 and X2 have the same root.\"\n (= (ds-root disjoint-set x1) (ds-root disjoint-set x2)))\n\n(declaim (inline ds-size))\n(defun ds-size (disjoint-set x)\n \"Returns the size of the connected component to which X belongs.\"\n (- (aref (ds-data disjoint-set)\n (ds-root disjoint-set x))))\n\n;;;\n;;; 1-dimensional binary indexed tree on arbitrary commutative monoid\n;;;\n\n(defpackage :cp/abstract-bit\n (:use :cl)\n (:export #:define-bitree))\n(in-package :cp/abstract-bit)\n\n(defmacro define-bitree (name &key (operator '#'+) (identity 0) sum-type (order '#'<))\n \"OPERATOR := binary operator (comprising a commutative monoid)\nIDENTITY := object (identity element of the monoid)\nORDER := nil | strict comparison operator on the monoid\nSUM-TYPE := nil | type specifier\n\nDefines no structure; BIT is just a vector. This macro defines the three\nfunctions: -UPDATE!, point-update function, -FOLD, query function for\nprefix sum, and COERCE-TO-!, constructor. If ORDER is specified, this\nmacro in addition defines -BISECT-LEFT and -BISECT-RIGHT, the\nbisection functions for prefix sums. (Note that these functions work only when\nthe sequence of prefix sums (VECTOR[0], VECTOR[0]+VECTOR[1], ...) is monotone.)\n\nSUM-TYPE is used only for the type declaration: each sum\nVECTOR[i]+VECTOR[i+1]...+VECTOR[i+k] is declared to be this type. When SUM-TYPE\nis NIL, type declaration is omitted. (The array-element-type of vector itself\ndoesn't need to be identical to SUM-TYPE.)\"\n (let* ((name (string name))\n (fname-update (intern (format nil \"~A-UPDATE!\" name)))\n (fname-fold (intern (format nil \"~A-FOLD\" name)))\n (fname-coerce (intern (format nil \"COERCE-TO-~A!\" name)))\n (fname-bisect-left (intern (format nil \"~A-BISECT-LEFT\" name)))\n (fname-bisect-right (intern (format nil \"~A-BISECT-RIGHT\" name))))\n `(progn\n (declaim (inline ,fname-update))\n (defun ,fname-update (bitree index delta)\n \"Destructively increments the vector: vector[INDEX] = vector[INDEX] +\nDELTA\"\n (let ((len (length bitree)))\n (do ((i index (logior i (+ i 1))))\n ((>= i len) bitree)\n (declare ((integer 0 #.most-positive-fixnum) i))\n (setf (aref bitree i)\n (funcall ,operator (aref bitree i) delta)))))\n\n (declaim (inline ,fname-fold))\n (defun ,fname-fold (bitree end)\n \"Returns the sum of the prefix: vector[0] + ... + vector[END-1].\"\n (declare ((integer 0 #.most-positive-fixnum) end))\n (let ((res ,identity))\n ,@(when sum-type `((declare (type ,sum-type res))))\n (do ((i (- end 1) (- (logand i (+ i 1)) 1)))\n ((< i 0) res)\n (declare ((integer -1 #.most-positive-fixnum) i))\n (setf res (funcall ,operator res (aref bitree i))))))\n\n (declaim (inline ,fname-coerce))\n (defun ,fname-coerce (vector)\n \"Destructively constructs BIT from VECTOR. (You doesn't need to call\nthis constructor if what you need is a `zero-filled' BIT, because a vector\nfilled with the identity element is a valid BIT as it is.)\"\n (loop with len = (length vector)\n for i below len\n for dest-i = (logior i (+ i 1))\n when (< dest-i len)\n do (setf (aref vector dest-i)\n (funcall ,operator (aref vector dest-i) (aref vector i)))\n finally (return vector)))\n\n ,@(when order\n `((declaim (inline ,fname-bisect-left))\n (defun ,fname-bisect-left (bitree value)\n \"Returns the smallest index that satisfies VECTOR[0]+ ... +\nVECTOR[index] >= VALUE. Returns the length of VECTOR if VECTOR[0]+\n... +VECTOR[length-1] < VALUE. Note that this function deals with a **closed**\ninterval.\"\n (declare (vector bitree))\n (if (not (funcall ,order ,identity value))\n 0\n (let ((len (length bitree))\n (index+1 0)\n (cumul ,identity))\n (declare ((integer 0 #.most-positive-fixnum) index+1)\n ,@(when sum-type\n `((type ,sum-type cumul))))\n (do ((delta (ash 1 (- (integer-length len) 1))\n (ash delta -1)))\n ((zerop delta) index+1)\n (declare ((integer 0 #.most-positive-fixnum) delta))\n (let ((next-index (+ index+1 delta -1)))\n (when (< next-index len)\n (let ((next-cumul (funcall ,operator cumul (aref bitree next-index))))\n ,@(when sum-type\n `((declare (type ,sum-type next-cumul))))\n (when (funcall ,order next-cumul value)\n (setf cumul next-cumul)\n (incf index+1 delta)))))))))\n (declaim (inline ,fname-bisect-right))\n (defun ,fname-bisect-right (bitree value)\n \"Returns the smallest index that satisfies VECTOR[0]+ ... +\nVECTOR[index] > VALUE. Returns the length of VECTOR if VECTOR[0]+\n... +VECTOR[length-1] <= VALUE. Note that this function deals with a **closed**\ninterval.\"\n (declare (vector bitree))\n (if (funcall ,order value ,identity)\n 0\n (let ((len (length bitree))\n (index+1 0)\n (cumul ,identity))\n (declare ((integer 0 #.most-positive-fixnum) index+1)\n ,@(when sum-type\n `((type ,sum-type cumul))))\n (do ((delta (ash 1 (- (integer-length len) 1))\n (ash delta -1)))\n ((zerop delta) index+1)\n (declare ((integer 0 #.most-positive-fixnum) delta))\n (let ((next-index (+ index+1 delta -1)))\n (when (< next-index len)\n (let ((next-cumul (funcall ,operator cumul (aref bitree next-index))))\n ,@(when sum-type\n `((declare (type ,sum-type next-cumul))))\n (unless (funcall ,order value next-cumul)\n (setf cumul next-cumul)\n (incf index+1 delta))))))))))))))\n\n#+(or)\n(define-bitree bitree\n :operator #'+\n :identity 0\n :sum-type fixnum\n :order #'<)\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/abstract-bit :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/disjoint-set :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(define-bitree bitree\n :operator #'+\n :identity 0\n :sum-type fixnum\n :order #'<)\n\n(declaim (inline less))\n(defun less (a b)\n (declare (fixnum a b))\n (< a b))\n(defun main ()\n (declare #.cl-user::opt\n (inline sort sb-impl::stable-sort-list))\n (let* ((n (read))\n (xs (make-array n :element-type 'uint31 :initial-element 0))\n (ys (make-array n :element-type 'uint31 :initial-element 0))\n (points (make-array n :element-type 'list :initial-element nil))\n (points-xsorted (make-array n :element-type 'list :initial-element nil))\n (points-ysorted (make-array n :element-type 'list :initial-element nil))\n (dset (make-disjoint-set n)))\n (dotimes (i n)\n (let ((x (- (read-fixnum) 1))\n (y (- (read-fixnum) 1)))\n (setf (aref points i) (cons x y)\n (aref points-xsorted i) (list x y i)\n (aref points-ysorted i) (list x y i)\n (aref xs i) x\n (aref ys i) y)))\n (setq points-xsorted (sort points-xsorted #'less :key #'first))\n (setq points-ysorted (sort points-ysorted #'less :key #'second))\n (let ((bitree (make-array n :element-type 'uint31 :initial-element 0)))\n (loop for x1 from 0 below n\n for (_ y1 i1) of-type (uint31 uint31 uint31) = (aref points-xsorted x1)\n do (when (> x1 0)\n (let ((index (bitree-fold bitree y1)))\n (when (> index 0)\n (let* ((y2 (bitree-bisect-left bitree index))\n (i2 (third (aref points-ysorted y2))))\n (ds-unite! dset i1 i2)))))\n (bitree-update! bitree y1 1)))\n (let ((bitree (make-array n :element-type 'uint31 :initial-element 0)))\n (loop for x1 from (- n 1) downto 0\n for (_ y1 i1) of-type (uint31 uint31 uint31) = (aref points-xsorted x1)\n do (when (< x1 (- n 1))\n (let ((index (bitree-fold bitree y1)))\n (when (< index (bitree-fold bitree n))\n (let* ((y2 (bitree-bisect-left bitree (+ index 1)))\n (i2 (third (aref points-ysorted y2))))\n (ds-unite! dset i1 i2)))))\n (bitree-update! bitree y1 1)))\n (let ((bitree (make-array n :element-type 'uint31 :initial-element 0)))\n (loop for y1 from 0 below n\n for (x1 _ i1) of-type (uint31 uint31 uint31) = (aref points-ysorted y1)\n do (when (> y1 0)\n (let ((index (bitree-fold bitree x1)))\n (when (> index 0)\n (let* ((x2 (bitree-bisect-left bitree index))\n (i2 (third (aref points-xsorted x2))))\n (ds-unite! dset i1 i2)))))\n (bitree-update! bitree x1 1)))\n (let ((bitree (make-array n :element-type 'uint31 :initial-element 0)))\n (loop for y1 from (- n 1) downto 0\n for (x1 _ i1) of-type (uint31 uint31 uint31) = (aref points-ysorted y1)\n do (when (< y1 (- n 1))\n (let ((index (bitree-fold bitree x1)))\n (when (< index (bitree-fold bitree n))\n (let* ((x2 (bitree-bisect-left bitree (+ index 1)))\n (i2 (third (aref points-xsorted x2))))\n (ds-unite! dset i1 i2)))))\n (bitree-update! bitree x1 1)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (i n)\n (println (ds-size dset i)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (5am:is\n (equal \"1\n1\n2\n2\n\"\n (run \"4\n1 4\n2 3\n3 1\n4 2\n\" nil)))\n (5am:is\n (equal \"3\n3\n1\n1\n2\n3\n2\n\"\n (run \"7\n6 4\n4 3\n3 5\n7 1\n2 7\n5 2\n1 6\n\" nil))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N cities on a 2D plane. The coordinate of the i-th city is (x_i, y_i). Here (x_1, x_2, \\dots, x_N) and (y_1, y_2, \\dots, y_N) are both permuations of (1, 2, \\dots, N).\n\nFor each k = 1,2,\\dots,N, find the answer to the following question:\n\nRng is in City k.\nRng can perform the following move arbitrarily many times:\n\nmove to another city that has a smaller x-coordinate and a smaller y-coordinate, or a larger x-coordinate and a larger y-coordinate, than the city he is currently in.\n\nHow many cities (including City k) are reachable from City k?\n\nConstraints\n\n1 \\leq N \\leq 200,000\n\n(x_1, x_2, \\dots, x_N) is a permutation of (1, 2, \\dots, N).\n\n(y_1, y_2, \\dots, y_N) is a permutation of (1, 2, \\dots, N).\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\nx_2 y_2\n:\nx_N y_N\n\nOutput\n\nPrint N lines. In i-th line print the answer to the question when k = i.\n\nSample Input 1\n\n4\n1 4\n2 3\n3 1\n4 2\n\nSample Output 1\n\n1\n1\n2\n2\n\nRng can reach City 4 from City 3, or conversely City 3 from City 4.\n\nSample Input 2\n\n7\n6 4\n4 3\n3 5\n7 1\n2 7\n5 2\n1 6\n\nSample Output 2\n\n3\n3\n1\n1\n2\n3\n2", "sample_input": "4\n1 4\n2 3\n3 1\n4 2\n"}, "reference_outputs": ["1\n1\n2\n2\n"], "source_document_id": "p02540", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N cities on a 2D plane. The coordinate of the i-th city is (x_i, y_i). Here (x_1, x_2, \\dots, x_N) and (y_1, y_2, \\dots, y_N) are both permuations of (1, 2, \\dots, N).\n\nFor each k = 1,2,\\dots,N, find the answer to the following question:\n\nRng is in City k.\nRng can perform the following move arbitrarily many times:\n\nmove to another city that has a smaller x-coordinate and a smaller y-coordinate, or a larger x-coordinate and a larger y-coordinate, than the city he is currently in.\n\nHow many cities (including City k) are reachable from City k?\n\nConstraints\n\n1 \\leq N \\leq 200,000\n\n(x_1, x_2, \\dots, x_N) is a permutation of (1, 2, \\dots, N).\n\n(y_1, y_2, \\dots, y_N) is a permutation of (1, 2, \\dots, N).\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\nx_2 y_2\n:\nx_N y_N\n\nOutput\n\nPrint N lines. In i-th line print the answer to the question when k = i.\n\nSample Input 1\n\n4\n1 4\n2 3\n3 1\n4 2\n\nSample Output 1\n\n1\n1\n2\n2\n\nRng can reach City 4 from City 3, or conversely City 3 from City 4.\n\nSample Input 2\n\n7\n6 4\n4 3\n3 5\n7 1\n2 7\n5 2\n1 6\n\nSample Output 2\n\n3\n3\n1\n1\n2\n3\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 16750, "cpu_time_ms": 592, "memory_kb": 61552}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s282229305", "group_id": "codeNet:p02546", "input_text": "(let ((s (read-line)))\n (if (string= (char s (- (length s) 1)) \"s\")\n (format t \"~Aes~%\" s)\n (format t \"~As~%\" s)\n )\n)", "language": "Lisp", "metadata": {"date": 1600542143, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02546.html", "problem_id": "p02546", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02546/input.txt", "sample_output_relpath": "derived/input_output/data/p02546/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02546/Lisp/s282229305.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s282229305", "user_id": "u136500538"}, "prompt_components": {"gold_output": "apples\n", "input_to_evaluate": "(let ((s (read-line)))\n (if (string= (char s (- (length s) 1)) \"s\")\n (format t \"~Aes~%\" s)\n (format t \"~As~%\" s)\n )\n)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIn the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters.\n\nIn Taknese, the plural form of a noun is spelled based on the following rules:\n\nIf a noun's singular form does not end with s, append s to the end of the singular form.\n\nIf a noun's singular form ends with s, append es to the end of the singular form.\n\nYou are given the singular form S of a Taknese noun. Output its plural form.\n\nConstraints\n\nS is a string of length 1 between 1000, inclusive.\n\nS contains only lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the plural form of the given Taknese word.\n\nSample Input 1\n\napple\n\nSample Output 1\n\napples\n\napple ends with e, so its plural form is apples.\n\nSample Input 2\n\nbus\n\nSample Output 2\n\nbuses\n\nbus ends with s, so its plural form is buses.\n\nSample Input 3\n\nbox\n\nSample Output 3\n\nboxs", "sample_input": "apple\n"}, "reference_outputs": ["apples\n"], "source_document_id": "p02546", "source_text": "Score : 100 points\n\nProblem Statement\n\nIn the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters.\n\nIn Taknese, the plural form of a noun is spelled based on the following rules:\n\nIf a noun's singular form does not end with s, append s to the end of the singular form.\n\nIf a noun's singular form ends with s, append es to the end of the singular form.\n\nYou are given the singular form S of a Taknese noun. Output its plural form.\n\nConstraints\n\nS is a string of length 1 between 1000, inclusive.\n\nS contains only lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the plural form of the given Taknese word.\n\nSample Input 1\n\napple\n\nSample Output 1\n\napples\n\napple ends with e, so its plural form is apples.\n\nSample Input 2\n\nbus\n\nSample Output 2\n\nbuses\n\nbus ends with s, so its plural form is buses.\n\nSample Input 3\n\nbox\n\nSample Output 3\n\nboxs", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 137, "cpu_time_ms": 20, "memory_kb": 24300}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s749915429", "group_id": "codeNet:p02547", "input_text": "(defun solve (xs &optional (cnt 0))\n (cond\n ((= cnt 3) t)\n ((null xs) nil)\n ((= (first (first xs)) (rest (first xs))) (solve (rest xs) (1+ cnt)))\n (t (solve (rest xs) 0))))\n\n\n(defun main ()\n (let* ((n (read))\n (xs (loop repeat n collect (cons (read) (read)))))\n (princ (if (solve xs)\n \"Yes\"\n \"No\"))\n (fresh-line)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1600542755, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02547.html", "problem_id": "p02547", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02547/input.txt", "sample_output_relpath": "derived/input_output/data/p02547/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02547/Lisp/s749915429.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s749915429", "user_id": "u425762225"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun solve (xs &optional (cnt 0))\n (cond\n ((= cnt 3) t)\n ((null xs) nil)\n ((= (first (first xs)) (rest (first xs))) (solve (rest xs) (1+ cnt)))\n (t (solve (rest xs) 0))))\n\n\n(defun main ()\n (let* ((n (read))\n (xs (loop repeat n collect (cons (read) (read)))))\n (princ (if (solve xs)\n \"Yes\"\n \"No\"))\n (fresh-line)))\n\n#-swank (main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTak performed the following action N times: rolling two dice.\nThe result of the i-th roll is D_{i,1} and D_{i,2}.\n\nCheck if doublets occurred at least three times in a row.\nSpecifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.\n\nConstraints\n\n3 \\leq N \\leq 100\n\n1\\leq D_{i,j} \\leq 6\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nD_{1,1} D_{1,2}\n\\vdots\nD_{N,1} D_{N,2}\n\nOutput\n\nPrint Yes if doublets occurred at least three times in a row. Print No otherwise.\n\nSample Input 1\n\n5\n1 2\n6 6\n4 4\n3 3\n3 2\n\nSample Output 1\n\nYes\n\nFrom the second roll to the fourth roll, three doublets occurred in a row.\n\nSample Input 2\n\n5\n1 1\n2 2\n3 4\n5 5\n6 6\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n6\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n\nSample Output 3\n\nYes", "sample_input": "5\n1 2\n6 6\n4 4\n3 3\n3 2\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02547", "source_text": "Score : 200 points\n\nProblem Statement\n\nTak performed the following action N times: rolling two dice.\nThe result of the i-th roll is D_{i,1} and D_{i,2}.\n\nCheck if doublets occurred at least three times in a row.\nSpecifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.\n\nConstraints\n\n3 \\leq N \\leq 100\n\n1\\leq D_{i,j} \\leq 6\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nD_{1,1} D_{1,2}\n\\vdots\nD_{N,1} D_{N,2}\n\nOutput\n\nPrint Yes if doublets occurred at least three times in a row. Print No otherwise.\n\nSample Input 1\n\n5\n1 2\n6 6\n4 4\n3 3\n3 2\n\nSample Output 1\n\nYes\n\nFrom the second roll to the fourth roll, three doublets occurred in a row.\n\nSample Input 2\n\n5\n1 1\n2 2\n3 4\n5 5\n6 6\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n6\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 387, "cpu_time_ms": 17, "memory_kb": 23680}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s024424959", "group_id": "codeNet:p02547", "input_text": "(let ((n (read))\n (a 0)\n (ans \"No\"))\n\n (loop for i below n do\n (progn\n (if (= (read) (read))\n (incf a)\n (setq a 0)\n )\n (if (= a 3)\n (progn\n (setq ans \"Yes\")\n (return)\n )\n )\n )\n )\n (format t \"~A~%\" ans)\n)", "language": "Lisp", "metadata": {"date": 1600542701, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02547.html", "problem_id": "p02547", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02547/input.txt", "sample_output_relpath": "derived/input_output/data/p02547/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02547/Lisp/s024424959.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s024424959", "user_id": "u136500538"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((n (read))\n (a 0)\n (ans \"No\"))\n\n (loop for i below n do\n (progn\n (if (= (read) (read))\n (incf a)\n (setq a 0)\n )\n (if (= a 3)\n (progn\n (setq ans \"Yes\")\n (return)\n )\n )\n )\n )\n (format t \"~A~%\" ans)\n)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTak performed the following action N times: rolling two dice.\nThe result of the i-th roll is D_{i,1} and D_{i,2}.\n\nCheck if doublets occurred at least three times in a row.\nSpecifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.\n\nConstraints\n\n3 \\leq N \\leq 100\n\n1\\leq D_{i,j} \\leq 6\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nD_{1,1} D_{1,2}\n\\vdots\nD_{N,1} D_{N,2}\n\nOutput\n\nPrint Yes if doublets occurred at least three times in a row. Print No otherwise.\n\nSample Input 1\n\n5\n1 2\n6 6\n4 4\n3 3\n3 2\n\nSample Output 1\n\nYes\n\nFrom the second roll to the fourth roll, three doublets occurred in a row.\n\nSample Input 2\n\n5\n1 1\n2 2\n3 4\n5 5\n6 6\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n6\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n\nSample Output 3\n\nYes", "sample_input": "5\n1 2\n6 6\n4 4\n3 3\n3 2\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02547", "source_text": "Score : 200 points\n\nProblem Statement\n\nTak performed the following action N times: rolling two dice.\nThe result of the i-th roll is D_{i,1} and D_{i,2}.\n\nCheck if doublets occurred at least three times in a row.\nSpecifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.\n\nConstraints\n\n3 \\leq N \\leq 100\n\n1\\leq D_{i,j} \\leq 6\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nD_{1,1} D_{1,2}\n\\vdots\nD_{N,1} D_{N,2}\n\nOutput\n\nPrint Yes if doublets occurred at least three times in a row. Print No otherwise.\n\nSample Input 1\n\n5\n1 2\n6 6\n4 4\n3 3\n3 2\n\nSample Output 1\n\nYes\n\nFrom the second roll to the fourth roll, three doublets occurred in a row.\n\nSample Input 2\n\n5\n1 1\n2 2\n3 4\n5 5\n6 6\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n6\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 366, "cpu_time_ms": 18, "memory_kb": 23600}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s363614683", "group_id": "codeNet:p02547", "input_text": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/run-length\n (:use :cl)\n (:export #:map-run-length))\n(in-package :cp/run-length)\n\n(declaim (inline map-run-length))\n(defun map-run-length (function seq &key (test #'eql))\n \"Applies FUNCTION to each equal successive element of SEQ. FUNCTION must take\ntwo arguments: the first one receives an element in SEQ and the second one\nreceives the number of the successive elements equal to the first one.\n\nExample: (map-run-length (lambda (x c) (format t \\\"~D ~D~%\\\" x c)) #(1 1 1 2 2 1 3))\n1 3\n2 2\n1 1\n3 1\n\"\n (declare (sequence seq)\n (function test function))\n (etypecase seq\n (vector\n (unless (zerop (length seq))\n (let ((prev (aref seq 0))\n (start 0))\n (loop for pos from 1 below (length seq)\n unless (funcall test prev (aref seq pos))\n do (funcall function prev (- pos start))\n (setf prev (aref seq pos)\n start pos)\n finally (funcall function prev (- pos start))))))\n (list\n (when seq\n (labels ((recur (lst prev count)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null lst)\n (funcall function prev count))\n ((funcall test prev (car lst))\n (recur (cdr lst) prev (+ 1 count)))\n (t (funcall function prev count)\n (recur (cdr lst) (car lst) 1)))))\n (recur (cdr seq) (car seq) 1))))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/run-length :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (ds (loop repeat n\n for d1 = (read)\n for d2 = (read)\n collect (= d1 d2))))\n (map-run-length (lambda (bool count)\n (when (and bool (>= count 3))\n (write-line \"Yes\")\n (return-from main)))\n ds)\n (write-line \"No\n\")))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (5am:is\n (equal \"Yes\n\"\n (run \"5\n1 2\n6 6\n4 4\n3 3\n3 2\n\" nil)))\n (5am:is\n (equal \"No\n\"\n (run \"5\n1 1\n2 2\n3 4\n5 5\n6 6\n\" nil)))\n (5am:is\n (equal \"Yes\n\"\n (run \"6\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1600542137, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02547.html", "problem_id": "p02547", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02547/input.txt", "sample_output_relpath": "derived/input_output/data/p02547/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02547/Lisp/s363614683.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s363614683", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/run-length\n (:use :cl)\n (:export #:map-run-length))\n(in-package :cp/run-length)\n\n(declaim (inline map-run-length))\n(defun map-run-length (function seq &key (test #'eql))\n \"Applies FUNCTION to each equal successive element of SEQ. FUNCTION must take\ntwo arguments: the first one receives an element in SEQ and the second one\nreceives the number of the successive elements equal to the first one.\n\nExample: (map-run-length (lambda (x c) (format t \\\"~D ~D~%\\\" x c)) #(1 1 1 2 2 1 3))\n1 3\n2 2\n1 1\n3 1\n\"\n (declare (sequence seq)\n (function test function))\n (etypecase seq\n (vector\n (unless (zerop (length seq))\n (let ((prev (aref seq 0))\n (start 0))\n (loop for pos from 1 below (length seq)\n unless (funcall test prev (aref seq pos))\n do (funcall function prev (- pos start))\n (setf prev (aref seq pos)\n start pos)\n finally (funcall function prev (- pos start))))))\n (list\n (when seq\n (labels ((recur (lst prev count)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null lst)\n (funcall function prev count))\n ((funcall test prev (car lst))\n (recur (cdr lst) prev (+ 1 count)))\n (t (funcall function prev count)\n (recur (cdr lst) (car lst) 1)))))\n (recur (cdr seq) (car seq) 1))))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/run-length :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (ds (loop repeat n\n for d1 = (read)\n for d2 = (read)\n collect (= d1 d2))))\n (map-run-length (lambda (bool count)\n (when (and bool (>= count 3))\n (write-line \"Yes\")\n (return-from main)))\n ds)\n (write-line \"No\n\")))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (5am:is\n (equal \"Yes\n\"\n (run \"5\n1 2\n6 6\n4 4\n3 3\n3 2\n\" nil)))\n (5am:is\n (equal \"No\n\"\n (run \"5\n1 1\n2 2\n3 4\n5 5\n6 6\n\" nil)))\n (5am:is\n (equal \"Yes\n\"\n (run \"6\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n\" nil))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTak performed the following action N times: rolling two dice.\nThe result of the i-th roll is D_{i,1} and D_{i,2}.\n\nCheck if doublets occurred at least three times in a row.\nSpecifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.\n\nConstraints\n\n3 \\leq N \\leq 100\n\n1\\leq D_{i,j} \\leq 6\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nD_{1,1} D_{1,2}\n\\vdots\nD_{N,1} D_{N,2}\n\nOutput\n\nPrint Yes if doublets occurred at least three times in a row. Print No otherwise.\n\nSample Input 1\n\n5\n1 2\n6 6\n4 4\n3 3\n3 2\n\nSample Output 1\n\nYes\n\nFrom the second roll to the fourth roll, three doublets occurred in a row.\n\nSample Input 2\n\n5\n1 1\n2 2\n3 4\n5 5\n6 6\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n6\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n\nSample Output 3\n\nYes", "sample_input": "5\n1 2\n6 6\n4 4\n3 3\n3 2\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02547", "source_text": "Score : 200 points\n\nProblem Statement\n\nTak performed the following action N times: rolling two dice.\nThe result of the i-th roll is D_{i,1} and D_{i,2}.\n\nCheck if doublets occurred at least three times in a row.\nSpecifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.\n\nConstraints\n\n3 \\leq N \\leq 100\n\n1\\leq D_{i,j} \\leq 6\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nD_{1,1} D_{1,2}\n\\vdots\nD_{N,1} D_{N,2}\n\nOutput\n\nPrint Yes if doublets occurred at least three times in a row. Print No otherwise.\n\nSample Input 1\n\n5\n1 2\n6 6\n4 4\n3 3\n3 2\n\nSample Output 1\n\nYes\n\nFrom the second roll to the fourth roll, three doublets occurred in a row.\n\nSample Input 2\n\n5\n1 1\n2 2\n3 4\n5 5\n6 6\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n6\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5417, "cpu_time_ms": 22, "memory_kb": 24268}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s649570993", "group_id": "codeNet:p02548", "input_text": "(let ((n (read))\n (a 0)\n (ans 0))\n (setq a n)\n (loop for i from 1 to n do\n (loop for j from a downto 1 do\n (if (< (* i j) n)\n (progn\n ;; (format t \"~D ~D ~%\" i j)\n (incf ans j)\n (setq a j)\n (return)\n )\n ;; (format t \"NO~D ~D ~%\" i j)\n )\n \n )\n \n )\n (format t \"~D~%\" ans)\n)", "language": "Lisp", "metadata": {"date": 1600543806, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02548.html", "problem_id": "p02548", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02548/input.txt", "sample_output_relpath": "derived/input_output/data/p02548/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02548/Lisp/s649570993.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s649570993", "user_id": "u136500538"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((n (read))\n (a 0)\n (ans 0))\n (setq a n)\n (loop for i from 1 to n do\n (loop for j from a downto 1 do\n (if (< (* i j) n)\n (progn\n ;; (format t \"~D ~D ~%\" i j)\n (incf ans j)\n (setq a j)\n (return)\n )\n ;; (format t \"NO~D ~D ~%\" i j)\n )\n \n )\n \n )\n (format t \"~D~%\" ans)\n)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven is a positive integer N.\nHow many tuples (A,B,C) of positive integers satisfy A \\times B + C = N?\n\nConstraints\n\n2 \\leq N \\leq 10^6\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n3\n\nThere are 3 tuples of integers that satisfy A \\times B + C = 3: (A, B, C) = (1, 1, 2), (1, 2, 1), (2, 1, 1).\n\nSample Input 2\n\n100\n\nSample Output 2\n\n473\n\nSample Input 3\n\n1000000\n\nSample Output 3\n\n13969985", "sample_input": "3\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02548", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven is a positive integer N.\nHow many tuples (A,B,C) of positive integers satisfy A \\times B + C = N?\n\nConstraints\n\n2 \\leq N \\leq 10^6\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n3\n\nThere are 3 tuples of integers that satisfy A \\times B + C = 3: (A, B, C) = (1, 1, 2), (1, 2, 1), (2, 1, 1).\n\nSample Input 2\n\n100\n\nSample Output 2\n\n473\n\nSample Input 3\n\n1000000\n\nSample Output 3\n\n13969985", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 456, "cpu_time_ms": 37, "memory_kb": 24396}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s801072943", "group_id": "codeNet:p02552", "input_text": "(princ (if (zerop (read)) 1 0))", "language": "Lisp", "metadata": {"date": 1600023636, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02552.html", "problem_id": "p02552", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02552/input.txt", "sample_output_relpath": "derived/input_output/data/p02552/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02552/Lisp/s801072943.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s801072943", "user_id": "u334552723"}, "prompt_components": {"gold_output": "0\n", "input_to_evaluate": "(princ (if (zerop (read)) 1 0))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nGiven is an integer x that is greater than or equal to 0, and less than or equal to 1.\nOutput 1 if x is equal to 0, or 0 if x is equal to 1.\n\nConstraints\n\n0 \\leq x \\leq 1\n\nx is an integer\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx\n\nOutput\n\nPrint 1 if x is equal to 0, or 0 if x is equal to 1.\n\nSample Input 1\n\n1\n\nSample Output 1\n\n0\n\nSample Input 2\n\n0\n\nSample Output 2\n\n1", "sample_input": "1\n"}, "reference_outputs": ["0\n"], "source_document_id": "p02552", "source_text": "Score : 100 points\n\nProblem Statement\n\nGiven is an integer x that is greater than or equal to 0, and less than or equal to 1.\nOutput 1 if x is equal to 0, or 0 if x is equal to 1.\n\nConstraints\n\n0 \\leq x \\leq 1\n\nx is an integer\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx\n\nOutput\n\nPrint 1 if x is equal to 0, or 0 if x is equal to 1.\n\nSample Input 1\n\n1\n\nSample Output 1\n\n0\n\nSample Input 2\n\n0\n\nSample Output 2\n\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 31, "cpu_time_ms": 25, "memory_kb": 24224}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s840633646", "group_id": "codeNet:p02553", "input_text": "(defun straddlep (a b)\n (and (< a 0)\n (>= b 0)))\n\n(defun hoge (a b c d)\n (cond\n ((and (>= a 0) (>= c 0)) (* b d))\n ((and (< b 0) (< d 0)) (* a c))\n ((and (straddlep a b) (>= c 0)) (* c b))\n ((and (straddlep a b) (< d 0)) (* a c))\n ((and (>= a 0) (straddlep c d)) (* a c))\n ((and (< b 0) (straddlep c d)) (* a c))\n (t (let ((ac (* a c))\n (bd (* b d)))\n (if (> ac bd) ac bd)))))\n(let ((a (read))\n (b (read))\n (c (read))\n (d (read)))\n (format t \"~a - ~a\" a b))\n", "language": "Lisp", "metadata": {"date": 1600025237, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02553.html", "problem_id": "p02553", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02553/input.txt", "sample_output_relpath": "derived/input_output/data/p02553/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02553/Lisp/s840633646.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s840633646", "user_id": "u611236551"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun straddlep (a b)\n (and (< a 0)\n (>= b 0)))\n\n(defun hoge (a b c d)\n (cond\n ((and (>= a 0) (>= c 0)) (* b d))\n ((and (< b 0) (< d 0)) (* a c))\n ((and (straddlep a b) (>= c 0)) (* c b))\n ((and (straddlep a b) (< d 0)) (* a c))\n ((and (>= a 0) (straddlep c d)) (* a c))\n ((and (< b 0) (straddlep c d)) (* a c))\n (t (let ((ac (* a c))\n (bd (* b d)))\n (if (> ac bd) ac bd)))))\n(let ((a (read))\n (b (read))\n (c (read))\n (d (read)))\n (format t \"~a - ~a\" a b))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven are integers a,b,c and d.\nIf x and y are integers and a \\leq x \\leq b and c\\leq y \\leq d hold, what is the maximum possible value of x \\times y?\n\nConstraints\n\n-10^9 \\leq a \\leq b \\leq 10^9\n\n-10^9 \\leq c \\leq d \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b c d\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n1 2 1 1\n\nSample Output 1\n\n2\n\nIf x = 1 and y = 1 then x \\times y = 1.\nIf x = 2 and y = 1 then x \\times y = 2.\nTherefore, the answer is 2.\n\nSample Input 2\n\n3 5 -4 -2\n\nSample Output 2\n\n-6\n\nThe answer can be negative.\n\nSample Input 3\n\n-1000000000 0 -1000000000 0\n\nSample Output 3\n\n1000000000000000000", "sample_input": "1 2 1 1\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02553", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven are integers a,b,c and d.\nIf x and y are integers and a \\leq x \\leq b and c\\leq y \\leq d hold, what is the maximum possible value of x \\times y?\n\nConstraints\n\n-10^9 \\leq a \\leq b \\leq 10^9\n\n-10^9 \\leq c \\leq d \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b c d\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n1 2 1 1\n\nSample Output 1\n\n2\n\nIf x = 1 and y = 1 then x \\times y = 1.\nIf x = 2 and y = 1 then x \\times y = 2.\nTherefore, the answer is 2.\n\nSample Input 2\n\n3 5 -4 -2\n\nSample Output 2\n\n-6\n\nThe answer can be negative.\n\nSample Input 3\n\n-1000000000 0 -1000000000 0\n\nSample Output 3\n\n1000000000000000000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 523, "cpu_time_ms": 19, "memory_kb": 24400}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s263609256", "group_id": "codeNet:p02554", "input_text": "(let* ((n (read))\n (strn (princ-to-string n))\n (ans 0))\n (loop for i below (expt 10 n) do\n (progn\n (if (not (null (find #\\9 (princ-to-string i) :test #'equalp)))\n (if (> (parse-integer strn) (length (princ-to-string i)))\n (incf ans)\n (if (not (null (find #\\9 (princ-to-string i) :test #'equalp)))\n (incf ans)\n )\n )\n )\n (setq ans (rem ans 1000000007))\n )\n )\n (princ ans)\n)", "language": "Lisp", "metadata": {"date": 1600118307, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02554.html", "problem_id": "p02554", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02554/input.txt", "sample_output_relpath": "derived/input_output/data/p02554/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02554/Lisp/s263609256.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s263609256", "user_id": "u136500538"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (read))\n (strn (princ-to-string n))\n (ans 0))\n (loop for i below (expt 10 n) do\n (progn\n (if (not (null (find #\\9 (princ-to-string i) :test #'equalp)))\n (if (> (parse-integer strn) (length (princ-to-string i)))\n (incf ans)\n (if (not (null (find #\\9 (princ-to-string i) :test #'equalp)))\n (incf ans)\n )\n )\n )\n (setq ans (rem ans 1000000007))\n )\n )\n (princ ans)\n)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nHow many integer sequences A_1,A_2,\\ldots,A_N of length N satisfy all of the following conditions?\n\n0 \\leq A_i \\leq 9\n\nThere exists some i such that A_i=0 holds.\n\nThere exists some i such that A_i=9 holds.\n\nThe answer can be very large, so output it modulo 10^9 + 7.\n\nConstraints\n\n1 \\leq N \\leq 10^6\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer modulo 10^9 + 7.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n2\n\nTwo sequences \\{0,9\\} and \\{9,0\\} satisfy all conditions.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n0\n\nSample Input 3\n\n869121\n\nSample Output 3\n\n2511445", "sample_input": "2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02554", "source_text": "Score : 300 points\n\nProblem Statement\n\nHow many integer sequences A_1,A_2,\\ldots,A_N of length N satisfy all of the following conditions?\n\n0 \\leq A_i \\leq 9\n\nThere exists some i such that A_i=0 holds.\n\nThere exists some i such that A_i=9 holds.\n\nThe answer can be very large, so output it modulo 10^9 + 7.\n\nConstraints\n\n1 \\leq N \\leq 10^6\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer modulo 10^9 + 7.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n2\n\nTwo sequences \\{0,9\\} and \\{9,0\\} satisfy all conditions.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n0\n\nSample Input 3\n\n869121\n\nSample Output 3\n\n2511445", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 535, "cpu_time_ms": 2207, "memory_kb": 76864}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s862416913", "group_id": "codeNet:p02554", "input_text": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/mod-power\n (:use :cl)\n (:export #:mod-power))\n(in-package :cp/mod-power)\n\n(declaim (inline mod-power))\n(defun mod-power (base power modulus)\n \"Returns BASE^POWER mod MODULUS. Note: 0^0 = 1.\n\nBASE := integer\nPOWER, MODULUS := non-negative fixnum\"\n (declare ((integer 0 #.most-positive-fixnum) modulus power)\n (integer base))\n (let ((base (mod base modulus))\n (res (mod 1 modulus)))\n (declare ((integer 0 #.most-positive-fixnum) base res))\n (loop while (> power 0)\n when (oddp power)\n do (setq res (mod (* res base) modulus))\n do (setq base (mod (* base base) modulus)\n power (ash power -1)))\n res))\n\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/mod-power :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read)))\n (println (mod (+ (mod-power 10 n +mod+)\n (* -2 (mod-power 9 n +mod+))\n (mod-power 8 n +mod+))\n +mod+))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"2\n\"\n (run \"2\n\" nil)))\n (it.bese.fiveam:is\n (equal \"0\n\"\n (run \"1\n\" nil)))\n (it.bese.fiveam:is\n (equal \"2511445\n\"\n (run \"869121\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1600023791, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02554.html", "problem_id": "p02554", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02554/input.txt", "sample_output_relpath": "derived/input_output/data/p02554/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02554/Lisp/s862416913.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s862416913", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/mod-power\n (:use :cl)\n (:export #:mod-power))\n(in-package :cp/mod-power)\n\n(declaim (inline mod-power))\n(defun mod-power (base power modulus)\n \"Returns BASE^POWER mod MODULUS. Note: 0^0 = 1.\n\nBASE := integer\nPOWER, MODULUS := non-negative fixnum\"\n (declare ((integer 0 #.most-positive-fixnum) modulus power)\n (integer base))\n (let ((base (mod base modulus))\n (res (mod 1 modulus)))\n (declare ((integer 0 #.most-positive-fixnum) base res))\n (loop while (> power 0)\n when (oddp power)\n do (setq res (mod (* res base) modulus))\n do (setq base (mod (* base base) modulus)\n power (ash power -1)))\n res))\n\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/mod-power :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read)))\n (println (mod (+ (mod-power 10 n +mod+)\n (* -2 (mod-power 9 n +mod+))\n (mod-power 8 n +mod+))\n +mod+))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"2\n\"\n (run \"2\n\" nil)))\n (it.bese.fiveam:is\n (equal \"0\n\"\n (run \"1\n\" nil)))\n (it.bese.fiveam:is\n (equal \"2511445\n\"\n (run \"869121\n\" nil))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nHow many integer sequences A_1,A_2,\\ldots,A_N of length N satisfy all of the following conditions?\n\n0 \\leq A_i \\leq 9\n\nThere exists some i such that A_i=0 holds.\n\nThere exists some i such that A_i=9 holds.\n\nThe answer can be very large, so output it modulo 10^9 + 7.\n\nConstraints\n\n1 \\leq N \\leq 10^6\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer modulo 10^9 + 7.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n2\n\nTwo sequences \\{0,9\\} and \\{9,0\\} satisfy all conditions.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n0\n\nSample Input 3\n\n869121\n\nSample Output 3\n\n2511445", "sample_input": "2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02554", "source_text": "Score : 300 points\n\nProblem Statement\n\nHow many integer sequences A_1,A_2,\\ldots,A_N of length N satisfy all of the following conditions?\n\n0 \\leq A_i \\leq 9\n\nThere exists some i such that A_i=0 holds.\n\nThere exists some i such that A_i=9 holds.\n\nThe answer can be very large, so output it modulo 10^9 + 7.\n\nConstraints\n\n1 \\leq N \\leq 10^6\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer modulo 10^9 + 7.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n2\n\nTwo sequences \\{0,9\\} and \\{9,0\\} satisfy all conditions.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n0\n\nSample Input 3\n\n869121\n\nSample Output 3\n\n2511445", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4368, "cpu_time_ms": 17, "memory_kb": 24852}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s685331932", "group_id": "codeNet:p02557", "input_text": "(defstruct queue (entrance nil) (exit nil))\n\n(defun enqueue (item queue)\n (let ((cell (list item)))\n (if (queue-entrance queue)\n (setf (cdr (queue-entrance queue)) cell)\n (setf (queue-exit queue) cell))\n (setf (queue-entrance queue) cell)))\n\n(defun dequeue (queue)\n (when (queue-exit queue)\n (prog1 (pop (queue-exit queue))\n (unless (queue-exit queue)\n (setf (queue-entrance queue) nil)))))\n\n;;;; main\n(defun main ()\n (let* ((n (read))\n (a (make-array (list n)))\n (b (make-array (list n)))\n (c (make-array (list n)))\n (stack nil))\n (loop :for i :from 0 :to (1- n)\n :do (setf (aref a i) (read)))\n (loop :for i :from 0 :to (1- n)\n :do (setf (aref b i) (read)))\n (loop :for i :downfrom (1- n) :to 0\n :do (push (aref b i) stack))\n ;;\n (loop :named main\n :with sub := (make-queue)\n :for i :from 0 :to (1- n)\n :do (loop :named inner\n :for x := (pop stack)\n :do (cond ((/= (aref a i) x)\n (setf (aref c i) x)\n (return-from inner nil))\n (t\n (enqueue x sub)))\n :if (null stack)\n :do (progn\n (format t \"No~%\")\n (return-from main)))\n :do (setf stack (queue-exit sub))\n :do (setf sub (make-queue))\n :finally (progn\n (format t \"Yes~%\")\n (loop :for j :from 0 :to (- n 2)\n :do (format t \"~A \" (aref c j))\n :finally (format t \"~A~%\" (aref c (1- n))))))))\n(main)\n", "language": "Lisp", "metadata": {"date": 1600029588, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02557.html", "problem_id": "p02557", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02557/input.txt", "sample_output_relpath": "derived/input_output/data/p02557/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02557/Lisp/s685331932.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s685331932", "user_id": "u608227593"}, "prompt_components": {"gold_output": "Yes\n2 2 3 1 1 1\n", "input_to_evaluate": "(defstruct queue (entrance nil) (exit nil))\n\n(defun enqueue (item queue)\n (let ((cell (list item)))\n (if (queue-entrance queue)\n (setf (cdr (queue-entrance queue)) cell)\n (setf (queue-exit queue) cell))\n (setf (queue-entrance queue) cell)))\n\n(defun dequeue (queue)\n (when (queue-exit queue)\n (prog1 (pop (queue-exit queue))\n (unless (queue-exit queue)\n (setf (queue-entrance queue) nil)))))\n\n;;;; main\n(defun main ()\n (let* ((n (read))\n (a (make-array (list n)))\n (b (make-array (list n)))\n (c (make-array (list n)))\n (stack nil))\n (loop :for i :from 0 :to (1- n)\n :do (setf (aref a i) (read)))\n (loop :for i :from 0 :to (1- n)\n :do (setf (aref b i) (read)))\n (loop :for i :downfrom (1- n) :to 0\n :do (push (aref b i) stack))\n ;;\n (loop :named main\n :with sub := (make-queue)\n :for i :from 0 :to (1- n)\n :do (loop :named inner\n :for x := (pop stack)\n :do (cond ((/= (aref a i) x)\n (setf (aref c i) x)\n (return-from inner nil))\n (t\n (enqueue x sub)))\n :if (null stack)\n :do (progn\n (format t \"No~%\")\n (return-from main)))\n :do (setf stack (queue-exit sub))\n :do (setf sub (make-queue))\n :finally (progn\n (format t \"Yes~%\")\n (loop :for j :from 0 :to (- n 2)\n :do (format t \"~A \" (aref c j))\n :finally (format t \"~A~%\" (aref c (1- n))))))))\n(main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven are two sequences A and B, both of length N.\nA and B are each sorted in the ascending order.\nCheck if it is possible to reorder the terms of B so that for each i (1 \\leq i \\leq N) A_i \\neq B_i holds, and if it is possible, output any of the reorderings that achieve it.\n\nConstraints\n\n1\\leq N \\leq 2 \\times 10^5\n\n1\\leq A_i,B_i \\leq N\n\nA and B are each sorted in the ascending order.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 \\cdots A_N\nB_1 B_2 \\cdots B_N\n\nOutput\n\nIf there exist no reorderings that satisfy the condition, print No.\n\nIf there exists a reordering that satisfies the condition, print Yes on the first line.\nAfter that, print a reordering of B on the second line, separating terms with a whitespace.\n\nIf there are multiple reorderings that satisfy the condition, you can print any of them.\n\nSample Input 1\n\n6\n1 1 1 2 2 3\n1 1 1 2 2 3\n\nSample Output 1\n\nYes\n2 2 3 1 1 1\n\nSample Input 2\n\n3\n1 1 2\n1 1 3\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n4\n1 1 2 3\n1 2 3 3\n\nSample Output 3\n\nYes\n3 3 1 2", "sample_input": "6\n1 1 1 2 2 3\n1 1 1 2 2 3\n"}, "reference_outputs": ["Yes\n2 2 3 1 1 1\n"], "source_document_id": "p02557", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are two sequences A and B, both of length N.\nA and B are each sorted in the ascending order.\nCheck if it is possible to reorder the terms of B so that for each i (1 \\leq i \\leq N) A_i \\neq B_i holds, and if it is possible, output any of the reorderings that achieve it.\n\nConstraints\n\n1\\leq N \\leq 2 \\times 10^5\n\n1\\leq A_i,B_i \\leq N\n\nA and B are each sorted in the ascending order.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 \\cdots A_N\nB_1 B_2 \\cdots B_N\n\nOutput\n\nIf there exist no reorderings that satisfy the condition, print No.\n\nIf there exists a reordering that satisfies the condition, print Yes on the first line.\nAfter that, print a reordering of B on the second line, separating terms with a whitespace.\n\nIf there are multiple reorderings that satisfy the condition, you can print any of them.\n\nSample Input 1\n\n6\n1 1 1 2 2 3\n1 1 1 2 2 3\n\nSample Output 1\n\nYes\n2 2 3 1 1 1\n\nSample Input 2\n\n3\n1 1 2\n1 1 3\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n4\n1 1 2 3\n1 2 3 3\n\nSample Output 3\n\nYes\n3 3 1 2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1750, "cpu_time_ms": 401, "memory_kb": 82788}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s849821188", "group_id": "codeNet:p02560", "input_text": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/floor-sum\n (:use :cl)\n (:export #:floor-sum))\n(in-package :cp/floor-sum)\n\n(defun floor-sum (n slope intercept denom)\n (declare #.cl-user::opt\n ((unsigned-byte 31) slope intercept n denom)\n (values (unsigned-byte 62) &optional))\n (let ((res 0))\n (declare ((unsigned-byte 62) res))\n (when (>= slope denom)\n (multiple-value-bind (quot rem) (floor slope denom)\n (declare ((unsigned-byte 31) quot rem))\n (incf res (the (unsigned-byte 62)\n (* (the (unsigned-byte 62) (floor (* n (- n 1)) 2)) quot)))\n (setq slope rem)))\n (when (>= intercept denom)\n (multiple-value-bind (quot rem) (floor intercept denom)\n (incf res (* n quot))\n (setq intercept rem)))\n (let ((y (floor (+ (* slope n) intercept) denom)))\n (declare ((unsigned-byte 31) y))\n (if (zerop y)\n res\n (let ((num (- (* denom y) intercept)))\n (declare ((unsigned-byte 62) num))\n (incf res (* y (the (unsigned-byte 31) (- n (ceiling num slope)))))\n (incf res (floor-sum y denom (mod (- slope (mod num slope)) slope) slope))\n res)))))\n\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/floor-sum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((tt (read-fixnum)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (_ tt)\n (let ((n (read-fixnum))\n (m (read-fixnum))\n (a (read-fixnum))\n (b (read-fixnum)))\n (println (floor-sum n a b m))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"3\n13\n0\n314095480\n499999999500000000\n\"\n (run \"5\n4 10 6 3\n6 5 4 3\n1 1 0 0\n31415 92653 58979 32384\n1000000000 1000000000 999999999 999999999\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1599561480, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02560.html", "problem_id": "p02560", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02560/input.txt", "sample_output_relpath": "derived/input_output/data/p02560/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02560/Lisp/s849821188.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s849821188", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n13\n0\n314095480\n499999999500000000\n", "input_to_evaluate": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/floor-sum\n (:use :cl)\n (:export #:floor-sum))\n(in-package :cp/floor-sum)\n\n(defun floor-sum (n slope intercept denom)\n (declare #.cl-user::opt\n ((unsigned-byte 31) slope intercept n denom)\n (values (unsigned-byte 62) &optional))\n (let ((res 0))\n (declare ((unsigned-byte 62) res))\n (when (>= slope denom)\n (multiple-value-bind (quot rem) (floor slope denom)\n (declare ((unsigned-byte 31) quot rem))\n (incf res (the (unsigned-byte 62)\n (* (the (unsigned-byte 62) (floor (* n (- n 1)) 2)) quot)))\n (setq slope rem)))\n (when (>= intercept denom)\n (multiple-value-bind (quot rem) (floor intercept denom)\n (incf res (* n quot))\n (setq intercept rem)))\n (let ((y (floor (+ (* slope n) intercept) denom)))\n (declare ((unsigned-byte 31) y))\n (if (zerop y)\n res\n (let ((num (- (* denom y) intercept)))\n (declare ((unsigned-byte 62) num))\n (incf res (* y (the (unsigned-byte 31) (- n (ceiling num slope)))))\n (incf res (floor-sum y denom (mod (- slope (mod num slope)) slope) slope))\n res)))))\n\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/floor-sum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((tt (read-fixnum)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (_ tt)\n (let ((n (read-fixnum))\n (m (read-fixnum))\n (a (read-fixnum))\n (b (read-fixnum)))\n (println (floor-sum n a b m))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"3\n13\n0\n314095480\n499999999500000000\n\"\n (run \"5\n4 10 6 3\n6 5 4 3\n1 1 0 0\n31415 92653 58979 32384\n1000000000 1000000000 999999999 999999999\n\" nil))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIn this problem, you should process T testcases.\n\nFor each testcase, you are given four integers N, M, A, B.\n\nCalculate \\sum_{i = 0}^{N - 1} floor((A \\times i + B) / M).\n\nConstraints\n\n1 \\leq T \\leq 100,000\n\n1 \\leq N, M \\leq 10^9\n\n0 \\leq A, B < M\n\nInput\n\nInput is given from Standard Input in the following format:\n\nT\nN_0 M_0 A_0 B_0\nN_1 M_1 A_1 B_1\n:\nN_{T - 1} M_{T - 1} A_{T - 1} B_{T - 1}\n\nOutput\n\nPrint the answer for each testcase.\n\nSample Input 1\n\n5\n4 10 6 3\n6 5 4 3\n1 1 0 0\n31415 92653 58979 32384\n1000000000 1000000000 999999999 999999999\n\nSample Output 1\n\n3\n13\n0\n314095480\n499999999500000000", "sample_input": "5\n4 10 6 3\n6 5 4 3\n1 1 0 0\n31415 92653 58979 32384\n1000000000 1000000000 999999999 999999999\n"}, "reference_outputs": ["3\n13\n0\n314095480\n499999999500000000\n"], "source_document_id": "p02560", "source_text": "Score : 100 points\n\nProblem Statement\n\nIn this problem, you should process T testcases.\n\nFor each testcase, you are given four integers N, M, A, B.\n\nCalculate \\sum_{i = 0}^{N - 1} floor((A \\times i + B) / M).\n\nConstraints\n\n1 \\leq T \\leq 100,000\n\n1 \\leq N, M \\leq 10^9\n\n0 \\leq A, B < M\n\nInput\n\nInput is given from Standard Input in the following format:\n\nT\nN_0 M_0 A_0 B_0\nN_1 M_1 A_1 B_1\n:\nN_{T - 1} M_{T - 1} A_{T - 1} B_{T - 1}\n\nOutput\n\nPrint the answer for each testcase.\n\nSample Input 1\n\n5\n4 10 6 3\n6 5 4 3\n1 1 0 0\n31415 92653 58979 32384\n1000000000 1000000000 999999999 999999999\n\nSample Output 1\n\n3\n13\n0\n314095480\n499999999500000000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6347, "cpu_time_ms": 160, "memory_kb": 27816}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s596701226", "group_id": "codeNet:p02560", "input_text": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/floor-sum\n (:use :cl)\n (:export #:floor-sum))\n(in-package :cp/floor-sum)\n\n(defun floor-sum (n slope intercept denom)\n (declare ((integer 0) slope intercept n)\n ((integer 1) denom))\n (let ((res 0))\n (declare ((integer 0) res))\n (when (>= slope denom)\n (multiple-value-bind (quot rem) (floor slope denom)\n (incf res (* (floor (* n (- n 1)) 2) quot))\n (setq slope rem)))\n (when (>= intercept denom)\n (multiple-value-bind (quot rem) (floor intercept denom)\n (incf res (* n quot))\n (setq intercept rem)))\n (let ((y (floor (+ (* slope n) intercept) denom)))\n (if (zerop y)\n res\n (let ((num (- (* denom y) intercept)))\n (incf res (* y (- n (ceiling num slope))))\n (incf res (floor-sum y denom (mod (- slope (mod num slope)) slope) slope))\n res)))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/floor-sum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((tt (read-fixnum)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (_ tt)\n (let ((n (read-fixnum))\n (m (read-fixnum))\n (a (read-fixnum))\n (b (read-fixnum)))\n (println (floor-sum n a b m))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"3\n13\n0\n314095480\n499999999500000000\n\"\n (run \"5\n4 10 6 3\n6 5 4 3\n1 1 0 0\n31415 92653 58979 32384\n1000000000 1000000000 999999999 999999999\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1599561170, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02560.html", "problem_id": "p02560", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02560/input.txt", "sample_output_relpath": "derived/input_output/data/p02560/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02560/Lisp/s596701226.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s596701226", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n13\n0\n314095480\n499999999500000000\n", "input_to_evaluate": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/floor-sum\n (:use :cl)\n (:export #:floor-sum))\n(in-package :cp/floor-sum)\n\n(defun floor-sum (n slope intercept denom)\n (declare ((integer 0) slope intercept n)\n ((integer 1) denom))\n (let ((res 0))\n (declare ((integer 0) res))\n (when (>= slope denom)\n (multiple-value-bind (quot rem) (floor slope denom)\n (incf res (* (floor (* n (- n 1)) 2) quot))\n (setq slope rem)))\n (when (>= intercept denom)\n (multiple-value-bind (quot rem) (floor intercept denom)\n (incf res (* n quot))\n (setq intercept rem)))\n (let ((y (floor (+ (* slope n) intercept) denom)))\n (if (zerop y)\n res\n (let ((num (- (* denom y) intercept)))\n (incf res (* y (- n (ceiling num slope))))\n (incf res (floor-sum y denom (mod (- slope (mod num slope)) slope) slope))\n res)))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/floor-sum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((tt (read-fixnum)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (_ tt)\n (let ((n (read-fixnum))\n (m (read-fixnum))\n (a (read-fixnum))\n (b (read-fixnum)))\n (println (floor-sum n a b m))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"3\n13\n0\n314095480\n499999999500000000\n\"\n (run \"5\n4 10 6 3\n6 5 4 3\n1 1 0 0\n31415 92653 58979 32384\n1000000000 1000000000 999999999 999999999\n\" nil))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIn this problem, you should process T testcases.\n\nFor each testcase, you are given four integers N, M, A, B.\n\nCalculate \\sum_{i = 0}^{N - 1} floor((A \\times i + B) / M).\n\nConstraints\n\n1 \\leq T \\leq 100,000\n\n1 \\leq N, M \\leq 10^9\n\n0 \\leq A, B < M\n\nInput\n\nInput is given from Standard Input in the following format:\n\nT\nN_0 M_0 A_0 B_0\nN_1 M_1 A_1 B_1\n:\nN_{T - 1} M_{T - 1} A_{T - 1} B_{T - 1}\n\nOutput\n\nPrint the answer for each testcase.\n\nSample Input 1\n\n5\n4 10 6 3\n6 5 4 3\n1 1 0 0\n31415 92653 58979 32384\n1000000000 1000000000 999999999 999999999\n\nSample Output 1\n\n3\n13\n0\n314095480\n499999999500000000", "sample_input": "5\n4 10 6 3\n6 5 4 3\n1 1 0 0\n31415 92653 58979 32384\n1000000000 1000000000 999999999 999999999\n"}, "reference_outputs": ["3\n13\n0\n314095480\n499999999500000000\n"], "source_document_id": "p02560", "source_text": "Score : 100 points\n\nProblem Statement\n\nIn this problem, you should process T testcases.\n\nFor each testcase, you are given four integers N, M, A, B.\n\nCalculate \\sum_{i = 0}^{N - 1} floor((A \\times i + B) / M).\n\nConstraints\n\n1 \\leq T \\leq 100,000\n\n1 \\leq N, M \\leq 10^9\n\n0 \\leq A, B < M\n\nInput\n\nInput is given from Standard Input in the following format:\n\nT\nN_0 M_0 A_0 B_0\nN_1 M_1 A_1 B_1\n:\nN_{T - 1} M_{T - 1} A_{T - 1} B_{T - 1}\n\nOutput\n\nPrint the answer for each testcase.\n\nSample Input 1\n\n5\n4 10 6 3\n6 5 4 3\n1 1 0 0\n31415 92653 58979 32384\n1000000000 1000000000 999999999 999999999\n\nSample Output 1\n\n3\n13\n0\n314095480\n499999999500000000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4683, "cpu_time_ms": 24, "memory_kb": 26828}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s702371861", "group_id": "codeNet:p02564", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"256MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Strongly connected components of directed graph, 2-SAT\n;;;\n\n(defpackage :cp/scc\n (:use :cl)\n (:export #:scc #:scc-graph #:scc-components #:scc-sizes #:scc-count\n #:scc-p #:make-scc #:make-condensed-graph))\n(in-package :cp/scc)\n\n(defstruct (scc (:constructor %make-scc (graph components sizes count))\n (:copier nil))\n (graph nil :type vector)\n ;; components[i] := strongly connected component of the i-th vertex\n (components nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n ;; sizes[k] := size of the k-th strongly connected component\n (sizes nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n ;; the total number of strongly connected components\n (count 0 :type (integer 0 #.most-positive-fixnum)))\n\n;; Tarjan's algorithm\n;; Reference: http://www.prefield.com/algorithm/graph/strongly_connected_components.html\n;; (Kosaraju's algorithm is put in the test file)\n(defun make-scc (graph)\n (declare (optimize (speed 3))\n (vector graph))\n (let* ((n (length graph))\n (ord 0)\n (ords (make-array n :element-type 'fixnum :initial-element -1)) ; in-order\n ;; store the lowest in-order number as the representative element of a\n ;; strongly connected component\n (lowlinks (make-array n :element-type 'fixnum))\n (components (make-array n :element-type '(integer 0 #.most-positive-fixnum)))\n (comp-index 0) ; index number of component\n (sizes (make-array n :element-type '(integer 0 #.most-positive-fixnum)\n :initial-element 0))\n (stack (make-array n :element-type '(integer 0 #.most-positive-fixnum)))\n (end 0) ; stack pointer\n (in-stack (make-array n :element-type 'bit :initial-element 0)))\n (declare ((integer 0 #.most-positive-fixnum) ord end comp-index))\n (labels ((%push (v)\n (setf (aref stack end) v\n (aref in-stack v) 1)\n (incf end))\n (%pop ()\n (decf end)\n (let ((v (aref stack end)))\n (setf (aref in-stack v) 0)\n v))\n (visit (v)\n (setf (aref ords v) ord\n (aref lowlinks v) ord)\n (incf ord)\n (%push v)\n (dolist (next (aref graph v))\n (cond ((= -1 (aref ords next))\n (visit next)\n (setf (aref lowlinks v)\n (min (aref lowlinks v) (aref lowlinks next))))\n ((= 1 (aref in-stack next))\n (setf (aref lowlinks v)\n (min (aref lowlinks v) (aref ords next))))))\n (when (= (aref lowlinks v) (aref ords v))\n (loop for size of-type (integer 0 #.most-positive-fixnum) from 1\n for w = (%pop)\n do (setf (aref components w) comp-index)\n until (= v w)\n finally (setf (aref sizes comp-index) size)\n (incf comp-index)))))\n (dotimes (v n)\n (when (= -1 (aref ords v))\n (visit v)))\n ;; Reverse the order of strongly connected components, because now\n ;; everything is in the reversed topological order\n (dotimes (v n)\n (setf (aref components v)\n (- comp-index (aref components v) 1)))\n (dotimes (i (ash comp-index -1))\n (rotatef (aref sizes i) (aref sizes (- comp-index i 1))))\n (%make-scc graph components sizes comp-index))))\n\n;; FIXME: Constant factor of this implementation is too large. Can we avoid\n;; hash-table?\n(declaim (ftype (function * (values (simple-array t (*)) &optional))\n make-condensed-graph))\n(defun make-condensed-graph (scc)\n \"Does graph condensation. This function is non-destructive.\"\n (declare (optimize (speed 3)))\n (let* ((graph (scc-graph scc))\n (n (length graph))\n (comp-n (scc-count scc))\n (components (scc-components scc))\n (condensed (make-array comp-n :element-type t)))\n (dotimes (i comp-n)\n (setf (aref condensed i) (make-hash-table :test #'eql)))\n (dotimes (i n)\n (let ((i-comp (aref components i)))\n (dolist (neighbor (aref graph i))\n (let ((neighbor-comp (aref components neighbor)))\n (unless (= i-comp neighbor-comp)\n (setf (gethash neighbor-comp (aref condensed i-comp)) t))))))\n (dotimes (i comp-n)\n (setf (aref condensed i)\n (loop for x being each hash-key of (aref condensed i) collect x)))\n condensed))\n\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.cl-user::opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/scc :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil)))\n (declare (uint31 n m))\n (dotimes (i m)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (push b (aref graph a))))\n (let* ((scc (make-scc graph))\n (components (scc-components scc))\n (count (scc-count scc))\n (sizes (scc-sizes scc))\n (res (make-array count :element-type 'list :initial-element nil)))\n (dotimes (v n)\n (push v (aref res (aref components v))))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (println count)\n (dotimes (i count)\n (write (aref sizes i))\n (dolist (v (aref res i) (terpri))\n (write-char #\\ )\n (write v))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"4\n1 5\n2 4 1\n1 2\n2 3 0\n\"\n (run \"6 7\n1 4\n5 2\n3 0\n5 5\n4 1\n0 3\n4 2\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1599545495, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02564.html", "problem_id": "p02564", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02564/input.txt", "sample_output_relpath": "derived/input_output/data/p02564/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02564/Lisp/s702371861.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s702371861", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n1 5\n2 4 1\n1 2\n2 3 0\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"256MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Strongly connected components of directed graph, 2-SAT\n;;;\n\n(defpackage :cp/scc\n (:use :cl)\n (:export #:scc #:scc-graph #:scc-components #:scc-sizes #:scc-count\n #:scc-p #:make-scc #:make-condensed-graph))\n(in-package :cp/scc)\n\n(defstruct (scc (:constructor %make-scc (graph components sizes count))\n (:copier nil))\n (graph nil :type vector)\n ;; components[i] := strongly connected component of the i-th vertex\n (components nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n ;; sizes[k] := size of the k-th strongly connected component\n (sizes nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n ;; the total number of strongly connected components\n (count 0 :type (integer 0 #.most-positive-fixnum)))\n\n;; Tarjan's algorithm\n;; Reference: http://www.prefield.com/algorithm/graph/strongly_connected_components.html\n;; (Kosaraju's algorithm is put in the test file)\n(defun make-scc (graph)\n (declare (optimize (speed 3))\n (vector graph))\n (let* ((n (length graph))\n (ord 0)\n (ords (make-array n :element-type 'fixnum :initial-element -1)) ; in-order\n ;; store the lowest in-order number as the representative element of a\n ;; strongly connected component\n (lowlinks (make-array n :element-type 'fixnum))\n (components (make-array n :element-type '(integer 0 #.most-positive-fixnum)))\n (comp-index 0) ; index number of component\n (sizes (make-array n :element-type '(integer 0 #.most-positive-fixnum)\n :initial-element 0))\n (stack (make-array n :element-type '(integer 0 #.most-positive-fixnum)))\n (end 0) ; stack pointer\n (in-stack (make-array n :element-type 'bit :initial-element 0)))\n (declare ((integer 0 #.most-positive-fixnum) ord end comp-index))\n (labels ((%push (v)\n (setf (aref stack end) v\n (aref in-stack v) 1)\n (incf end))\n (%pop ()\n (decf end)\n (let ((v (aref stack end)))\n (setf (aref in-stack v) 0)\n v))\n (visit (v)\n (setf (aref ords v) ord\n (aref lowlinks v) ord)\n (incf ord)\n (%push v)\n (dolist (next (aref graph v))\n (cond ((= -1 (aref ords next))\n (visit next)\n (setf (aref lowlinks v)\n (min (aref lowlinks v) (aref lowlinks next))))\n ((= 1 (aref in-stack next))\n (setf (aref lowlinks v)\n (min (aref lowlinks v) (aref ords next))))))\n (when (= (aref lowlinks v) (aref ords v))\n (loop for size of-type (integer 0 #.most-positive-fixnum) from 1\n for w = (%pop)\n do (setf (aref components w) comp-index)\n until (= v w)\n finally (setf (aref sizes comp-index) size)\n (incf comp-index)))))\n (dotimes (v n)\n (when (= -1 (aref ords v))\n (visit v)))\n ;; Reverse the order of strongly connected components, because now\n ;; everything is in the reversed topological order\n (dotimes (v n)\n (setf (aref components v)\n (- comp-index (aref components v) 1)))\n (dotimes (i (ash comp-index -1))\n (rotatef (aref sizes i) (aref sizes (- comp-index i 1))))\n (%make-scc graph components sizes comp-index))))\n\n;; FIXME: Constant factor of this implementation is too large. Can we avoid\n;; hash-table?\n(declaim (ftype (function * (values (simple-array t (*)) &optional))\n make-condensed-graph))\n(defun make-condensed-graph (scc)\n \"Does graph condensation. This function is non-destructive.\"\n (declare (optimize (speed 3)))\n (let* ((graph (scc-graph scc))\n (n (length graph))\n (comp-n (scc-count scc))\n (components (scc-components scc))\n (condensed (make-array comp-n :element-type t)))\n (dotimes (i comp-n)\n (setf (aref condensed i) (make-hash-table :test #'eql)))\n (dotimes (i n)\n (let ((i-comp (aref components i)))\n (dolist (neighbor (aref graph i))\n (let ((neighbor-comp (aref components neighbor)))\n (unless (= i-comp neighbor-comp)\n (setf (gethash neighbor-comp (aref condensed i-comp)) t))))))\n (dotimes (i comp-n)\n (setf (aref condensed i)\n (loop for x being each hash-key of (aref condensed i) collect x)))\n condensed))\n\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.cl-user::opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/scc :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil)))\n (declare (uint31 n m))\n (dotimes (i m)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (push b (aref graph a))))\n (let* ((scc (make-scc graph))\n (components (scc-components scc))\n (count (scc-count scc))\n (sizes (scc-sizes scc))\n (res (make-array count :element-type 'list :initial-element nil)))\n (dotimes (v n)\n (push v (aref res (aref components v))))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (println count)\n (dotimes (i count)\n (write (aref sizes i))\n (dolist (v (aref res i) (terpri))\n (write-char #\\ )\n (write v))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"4\n1 5\n2 4 1\n1 2\n2 3 0\n\"\n (run \"6 7\n1 4\n5 2\n3 0\n5 5\n4 1\n0 3\n4 2\n\" nil))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i.\nDivide this graph into strongly connected components and print them in their topological order.\n\nConstraints\n\n1 \\leq N \\leq 500,000\n\n1 \\leq M \\leq 500,000\n\n0 \\leq a_i, b_i < N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_0 b_0\na_1 b_1\n:\na_{M - 1} b_{M - 1}\n\nOutput\n\nPrint 1+K lines, where K is the number of strongly connected components.\nPrint K on the first line.\nPrint the information of each strongly connected component in next K lines in the following format, where l is the number of vertices in the strongly connected component and v_i is the index of the vertex in it.\n\nl v_0 v_1 ... v_{l-1}\n\nHere, for each edge (a_i, b_i), b_i should not appear in earlier line than a_i.\n\nIf there are multiple correct output, print any of them.\n\nSample Input 1\n\n6 7\n1 4\n5 2\n3 0\n5 5\n4 1\n0 3\n4 2\n\nSample Output 1\n\n4\n1 5\n2 4 1\n1 2\n2 3 0", "sample_input": "6 7\n1 4\n5 2\n3 0\n5 5\n4 1\n0 3\n4 2\n"}, "reference_outputs": ["4\n1 5\n2 4 1\n1 2\n2 3 0\n"], "source_document_id": "p02564", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i.\nDivide this graph into strongly connected components and print them in their topological order.\n\nConstraints\n\n1 \\leq N \\leq 500,000\n\n1 \\leq M \\leq 500,000\n\n0 \\leq a_i, b_i < N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_0 b_0\na_1 b_1\n:\na_{M - 1} b_{M - 1}\n\nOutput\n\nPrint 1+K lines, where K is the number of strongly connected components.\nPrint K on the first line.\nPrint the information of each strongly connected component in next K lines in the following format, where l is the number of vertices in the strongly connected component and v_i is the index of the vertex in it.\n\nl v_0 v_1 ... v_{l-1}\n\nHere, for each edge (a_i, b_i), b_i should not appear in earlier line than a_i.\n\nIf there are multiple correct output, print any of them.\n\nSample Input 1\n\n6 7\n1 4\n5 2\n3 0\n5 5\n4 1\n0 3\n4 2\n\nSample Output 1\n\n4\n1 5\n2 4 1\n1 2\n2 3 0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10732, "cpu_time_ms": 441, "memory_kb": 74440}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s393759951", "group_id": "codeNet:p02570", "input_text": "(let ((dd (read))\n (tt (read))\n (s (read))\n (ans \"No\"))\n\n (if (<= (/ dd s) tt)\n (setq ans \"Yes\")\n )\n\n (format t \"~A~%\" ans) \n)", "language": "Lisp", "metadata": {"date": 1598727737, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02570.html", "problem_id": "p02570", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02570/input.txt", "sample_output_relpath": "derived/input_output/data/p02570/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02570/Lisp/s393759951.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s393759951", "user_id": "u136500538"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((dd (read))\n (tt (read))\n (s (read))\n (ans \"No\"))\n\n (if (<= (/ dd s) tt)\n (setq ans \"Yes\")\n )\n\n (format t \"~A~%\" ans) \n)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi is meeting up with Aoki.\n\nThey have planned to meet at a place that is D meters away from Takahashi's house in T minutes from now.\n\nTakahashi will leave his house now and go straight to the place at a speed of S meters per minute.\n\nWill he arrive in time?\n\nConstraints\n\n1 \\leq D \\leq 10000\n\n1 \\leq T \\leq 10000\n\n1 \\leq S \\leq 10000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nD T S\n\nOutput\n\nIf Takahashi will reach the place in time, print Yes; otherwise, print No.\n\nSample Input 1\n\n1000 15 80\n\nSample Output 1\n\nYes\n\nIt takes 12.5 minutes to go 1000 meters to the place at a speed of 80 meters per minute. They have planned to meet in 15 minutes so he will arrive in time.\n\nSample Input 2\n\n2000 20 100\n\nSample Output 2\n\nYes\n\nIt takes 20 minutes to go 2000 meters to the place at a speed of 100 meters per minute. They have planned to meet in 20 minutes so he will arrive just on time.\n\nSample Input 3\n\n10000 1 1\n\nSample Output 3\n\nNo\n\nHe will be late.", "sample_input": "1000 15 80\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02570", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi is meeting up with Aoki.\n\nThey have planned to meet at a place that is D meters away from Takahashi's house in T minutes from now.\n\nTakahashi will leave his house now and go straight to the place at a speed of S meters per minute.\n\nWill he arrive in time?\n\nConstraints\n\n1 \\leq D \\leq 10000\n\n1 \\leq T \\leq 10000\n\n1 \\leq S \\leq 10000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nD T S\n\nOutput\n\nIf Takahashi will reach the place in time, print Yes; otherwise, print No.\n\nSample Input 1\n\n1000 15 80\n\nSample Output 1\n\nYes\n\nIt takes 12.5 minutes to go 1000 meters to the place at a speed of 80 meters per minute. They have planned to meet in 15 minutes so he will arrive in time.\n\nSample Input 2\n\n2000 20 100\n\nSample Output 2\n\nYes\n\nIt takes 20 minutes to go 2000 meters to the place at a speed of 100 meters per minute. They have planned to meet in 20 minutes so he will arrive just on time.\n\nSample Input 3\n\n10000 1 1\n\nSample Output 3\n\nNo\n\nHe will be late.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 154, "cpu_time_ms": 22, "memory_kb": 23636}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s449749251", "group_id": "codeNet:p02571", "input_text": "(format t \"~A~%\"\n (loop with s1 = (read-line)\n with s2 = (read-line)\n with ls2 = (length s2)\n for i from 0 to (- (length s1) ls2)\n for subst = (subseq s1 i (+ i ls2))\n minimize (loop for i across s2\n for j across subst\n count (not (eql i j)))))\n", "language": "Lisp", "metadata": {"date": 1598728353, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02571.html", "problem_id": "p02571", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02571/input.txt", "sample_output_relpath": "derived/input_output/data/p02571/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02571/Lisp/s449749251.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s449749251", "user_id": "u607637432"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(format t \"~A~%\"\n (loop with s1 = (read-line)\n with s2 = (read-line)\n with ls2 = (length s2)\n for i from 0 to (- (length s1) ls2)\n for subst = (subseq s1 i (+ i ls2))\n minimize (loop for i across s2\n for j across subst\n count (not (eql i j)))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven are two strings S and T.\n\nLet us change some of the characters in S so that T will be a substring of S.\n\nAt least how many characters do we need to change?\n\nHere, a substring is a consecutive subsequence. For example, xxx is a substring of yxxxy, but not a substring of xxyxx.\n\nConstraints\n\nThe lengths of S and T are each at least 1 and at most 1000.\n\nThe length of T is at most that of S.\n\nS and T consist of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nPrint the minimum number of characters in S that need to be changed.\n\nSample Input 1\n\ncabacc\nabc\n\nSample Output 1\n\n1\n\nFor example, changing the fourth character a in S to c will match the second through fourth characters in S to T.\n\nSince S itself does not have T as its substring, this number of changes - one - is the minimum needed.\n\nSample Input 2\n\ncodeforces\natcoder\n\nSample Output 2\n\n6", "sample_input": "cabacc\nabc\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02571", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven are two strings S and T.\n\nLet us change some of the characters in S so that T will be a substring of S.\n\nAt least how many characters do we need to change?\n\nHere, a substring is a consecutive subsequence. For example, xxx is a substring of yxxxy, but not a substring of xxyxx.\n\nConstraints\n\nThe lengths of S and T are each at least 1 and at most 1000.\n\nThe length of T is at most that of S.\n\nS and T consist of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nPrint the minimum number of characters in S that need to be changed.\n\nSample Input 1\n\ncabacc\nabc\n\nSample Output 1\n\n1\n\nFor example, changing the fourth character a in S to c will match the second through fourth characters in S to T.\n\nSince S itself does not have T as its substring, this number of changes - one - is the minimum needed.\n\nSample Input 2\n\ncodeforces\natcoder\n\nSample Output 2\n\n6", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 373, "cpu_time_ms": 24, "memory_kb": 25544}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s309821633", "group_id": "codeNet:p02573", "input_text": "(defun root (x)\n (let (root)\n (prog1\n (setf root (last x))\n (loop for y on x\n if (not (eq root y))\n do (rplacd y root)))))\n\n(defun solve (N M)\n (loop repeat M \n with arr = (make-array N :initial-contents (loop for x below N collect (list 0))) and x and y do\n (setf x (read)\n y (read))\n (if (< x y) (rotatef x y))\n (setf x (root (aref arr (1- x)))\n y (root (aref arr (1- y))))\n (if (not (eq x y))\n (rplacd (last x)\n (last y)))\n finally (return (loop for x from (1- N) downto 0 \n if (null (cdr (aref arr x)))\n maximize (1+ (car (aref arr x)))\n else do (incf (car (root (aref arr x))))))))\n \n(princ (solve (read) (read)))", "language": "Lisp", "metadata": {"date": 1598804548, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02573.html", "problem_id": "p02573", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02573/input.txt", "sample_output_relpath": "derived/input_output/data/p02573/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02573/Lisp/s309821633.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s309821633", "user_id": "u289580381"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun root (x)\n (let (root)\n (prog1\n (setf root (last x))\n (loop for y on x\n if (not (eq root y))\n do (rplacd y root)))))\n\n(defun solve (N M)\n (loop repeat M \n with arr = (make-array N :initial-contents (loop for x below N collect (list 0))) and x and y do\n (setf x (read)\n y (read))\n (if (< x y) (rotatef x y))\n (setf x (root (aref arr (1- x)))\n y (root (aref arr (1- y))))\n (if (not (eq x y))\n (rplacd (last x)\n (last y)))\n finally (return (loop for x from (1- N) downto 0 \n if (null (cdr (aref arr x)))\n maximize (1+ (car (aref arr x)))\n else do (incf (car (root (aref arr x))))))))\n \n(princ (solve (read) (read)))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are N persons called Person 1 through Person N.\n\nYou are given M facts that \"Person A_i and Person B_i are friends.\" The same fact may be given multiple times.\n\nIf X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.\n\nTakahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.\n\nAt least how many groups does he need to make?\n\nConstraints\n\n2 \\leq N \\leq 2\\times 10^5\n\n0 \\leq M \\leq 2\\times 10^5\n\n1\\leq A_i,B_i\\leq N\n\nA_i \\neq B_i\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\n\\vdots\nA_M B_M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n5 3\n1 2\n3 4\n5 1\n\nSample Output 1\n\n3\n\nDividing them into three groups such as \\{1,3\\}, \\{2,4\\}, and \\{5\\} achieves the goal.\n\nSample Input 2\n\n4 10\n1 2\n2 1\n1 2\n2 1\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n\nSample Output 2\n\n4\n\nSample Input 3\n\n10 4\n3 1\n4 1\n5 9\n2 6\n\nSample Output 3\n\n3", "sample_input": "5 3\n1 2\n3 4\n5 1\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02573", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are N persons called Person 1 through Person N.\n\nYou are given M facts that \"Person A_i and Person B_i are friends.\" The same fact may be given multiple times.\n\nIf X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.\n\nTakahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.\n\nAt least how many groups does he need to make?\n\nConstraints\n\n2 \\leq N \\leq 2\\times 10^5\n\n0 \\leq M \\leq 2\\times 10^5\n\n1\\leq A_i,B_i\\leq N\n\nA_i \\neq B_i\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\n\\vdots\nA_M B_M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n5 3\n1 2\n3 4\n5 1\n\nSample Output 1\n\n3\n\nDividing them into three groups such as \\{1,3\\}, \\{2,4\\}, and \\{5\\} achieves the goal.\n\nSample Input 2\n\n4 10\n1 2\n2 1\n1 2\n2 1\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n\nSample Output 2\n\n4\n\nSample Input 3\n\n10 4\n3 1\n4 1\n5 9\n2 6\n\nSample Output 3\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 848, "cpu_time_ms": 2208, "memory_kb": 81824}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s458166921", "group_id": "codeNet:p02573", "input_text": "(let* ((n (read))\n (m (read))\n (c (make-array (list (1+ n)) :initial-element nil))\n (r (make-array (list (1+ n)) :initial-element nil))\n (num (make-array (list (1+ n)) :initial-element 0)))\n (loop :for _ :from 1 :to m\n :for a := (read)\n :for b := (read)\n :do (push a (aref r b))\n :do (push b (aref r a)))\n (defun cnt (x gn)\n (setf (aref c x) t)\n (incf (aref num gn))\n (loop :for y :in (aref r x)\n :if (null (aref c y))\n :do (cnt y gn)))\n (loop :for x :from 1 :to n\n :if (null (aref c x))\n :do (cnt x x))\n (format t \"~A~%\" (loop :for i :from 1 :to n\n :maximize (aref num i))))\n", "language": "Lisp", "metadata": {"date": 1598733917, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02573.html", "problem_id": "p02573", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02573/input.txt", "sample_output_relpath": "derived/input_output/data/p02573/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02573/Lisp/s458166921.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s458166921", "user_id": "u608227593"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (c (make-array (list (1+ n)) :initial-element nil))\n (r (make-array (list (1+ n)) :initial-element nil))\n (num (make-array (list (1+ n)) :initial-element 0)))\n (loop :for _ :from 1 :to m\n :for a := (read)\n :for b := (read)\n :do (push a (aref r b))\n :do (push b (aref r a)))\n (defun cnt (x gn)\n (setf (aref c x) t)\n (incf (aref num gn))\n (loop :for y :in (aref r x)\n :if (null (aref c y))\n :do (cnt y gn)))\n (loop :for x :from 1 :to n\n :if (null (aref c x))\n :do (cnt x x))\n (format t \"~A~%\" (loop :for i :from 1 :to n\n :maximize (aref num i))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are N persons called Person 1 through Person N.\n\nYou are given M facts that \"Person A_i and Person B_i are friends.\" The same fact may be given multiple times.\n\nIf X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.\n\nTakahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.\n\nAt least how many groups does he need to make?\n\nConstraints\n\n2 \\leq N \\leq 2\\times 10^5\n\n0 \\leq M \\leq 2\\times 10^5\n\n1\\leq A_i,B_i\\leq N\n\nA_i \\neq B_i\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\n\\vdots\nA_M B_M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n5 3\n1 2\n3 4\n5 1\n\nSample Output 1\n\n3\n\nDividing them into three groups such as \\{1,3\\}, \\{2,4\\}, and \\{5\\} achieves the goal.\n\nSample Input 2\n\n4 10\n1 2\n2 1\n1 2\n2 1\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n\nSample Output 2\n\n4\n\nSample Input 3\n\n10 4\n3 1\n4 1\n5 9\n2 6\n\nSample Output 3\n\n3", "sample_input": "5 3\n1 2\n3 4\n5 1\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02573", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are N persons called Person 1 through Person N.\n\nYou are given M facts that \"Person A_i and Person B_i are friends.\" The same fact may be given multiple times.\n\nIf X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.\n\nTakahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.\n\nAt least how many groups does he need to make?\n\nConstraints\n\n2 \\leq N \\leq 2\\times 10^5\n\n0 \\leq M \\leq 2\\times 10^5\n\n1\\leq A_i,B_i\\leq N\n\nA_i \\neq B_i\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\n\\vdots\nA_M B_M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n5 3\n1 2\n3 4\n5 1\n\nSample Output 1\n\n3\n\nDividing them into three groups such as \\{1,3\\}, \\{2,4\\}, and \\{5\\} achieves the goal.\n\nSample Input 2\n\n4 10\n1 2\n2 1\n1 2\n2 1\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n\nSample Output 2\n\n4\n\nSample Input 3\n\n10 4\n3 1\n4 1\n5 9\n2 6\n\nSample Output 3\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 697, "cpu_time_ms": 433, "memory_kb": 87428}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s591530407", "group_id": "codeNet:p02573", "input_text": " (defmacro %% ()\n '(cond ((and (null (aref g a)) (null (aref g b)))\n (setf (aref g a) a)\n (setf (aref g b) a)\n (incf (aref num a)))\n ((and (aref g a) (aref g b))\n (when (/= (aref g a) (aref g b))\n (incf (aref num (aref g a)) (aref g b))\n (incf (aref num (aref g b)) (aref g a))\n ))\n ((aref g a)\n (setf (aref g b) (aref g a))\n (incf (aref num (aref g a))))\n ((aref g b)\n (setf (aref g a) (aref g b))\n (incf (aref num (aref g b))))))\n(let* ((n (read))\n (m (read))\n (p (make-array (list m) :initial-element nil))\n (r (make-array (list (1+ n)) :initial-element nil))\n (c (make-array (list (1+ n)) :initial-element nil))\n (g (make-array (list (1+ n)) :initial-element nil))\n (num (make-array (list (1+ n)) :initial-element 1)))\n (loop :for _ :from 0 :to (1- m)\n :for a := (read)\n :for b := (read)\n :do (push (cons a b) (aref r a)) \n :do (push (cons a b) (aref r b))\n :do (setf (aref p _) (cons a b)))\n (loop :for pair :across p\n :for x := (car pair)\n :for y := (cdr pair)\n :if (and (null (aref c x)) (null (aref c y)))\n :do (loop :for z :in (aref r x)\n :for a := (car z)\n :for b := (cdr z)\n :do (%%))\n :do (loop :for z :in (aref r x)\n :for a := (car z)\n :for b := (cdr z)\n :do (%%))\n :do (setf (aref c x) t)\n :do (setf (aref c y) t))\n (format t \"~A~%\" (loop :for i :from 1 :to n\n :maximize (aref num i))))\n", "language": "Lisp", "metadata": {"date": 1598731199, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02573.html", "problem_id": "p02573", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02573/input.txt", "sample_output_relpath": "derived/input_output/data/p02573/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02573/Lisp/s591530407.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s591530407", "user_id": "u608227593"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": " (defmacro %% ()\n '(cond ((and (null (aref g a)) (null (aref g b)))\n (setf (aref g a) a)\n (setf (aref g b) a)\n (incf (aref num a)))\n ((and (aref g a) (aref g b))\n (when (/= (aref g a) (aref g b))\n (incf (aref num (aref g a)) (aref g b))\n (incf (aref num (aref g b)) (aref g a))\n ))\n ((aref g a)\n (setf (aref g b) (aref g a))\n (incf (aref num (aref g a))))\n ((aref g b)\n (setf (aref g a) (aref g b))\n (incf (aref num (aref g b))))))\n(let* ((n (read))\n (m (read))\n (p (make-array (list m) :initial-element nil))\n (r (make-array (list (1+ n)) :initial-element nil))\n (c (make-array (list (1+ n)) :initial-element nil))\n (g (make-array (list (1+ n)) :initial-element nil))\n (num (make-array (list (1+ n)) :initial-element 1)))\n (loop :for _ :from 0 :to (1- m)\n :for a := (read)\n :for b := (read)\n :do (push (cons a b) (aref r a)) \n :do (push (cons a b) (aref r b))\n :do (setf (aref p _) (cons a b)))\n (loop :for pair :across p\n :for x := (car pair)\n :for y := (cdr pair)\n :if (and (null (aref c x)) (null (aref c y)))\n :do (loop :for z :in (aref r x)\n :for a := (car z)\n :for b := (cdr z)\n :do (%%))\n :do (loop :for z :in (aref r x)\n :for a := (car z)\n :for b := (cdr z)\n :do (%%))\n :do (setf (aref c x) t)\n :do (setf (aref c y) t))\n (format t \"~A~%\" (loop :for i :from 1 :to n\n :maximize (aref num i))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are N persons called Person 1 through Person N.\n\nYou are given M facts that \"Person A_i and Person B_i are friends.\" The same fact may be given multiple times.\n\nIf X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.\n\nTakahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.\n\nAt least how many groups does he need to make?\n\nConstraints\n\n2 \\leq N \\leq 2\\times 10^5\n\n0 \\leq M \\leq 2\\times 10^5\n\n1\\leq A_i,B_i\\leq N\n\nA_i \\neq B_i\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\n\\vdots\nA_M B_M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n5 3\n1 2\n3 4\n5 1\n\nSample Output 1\n\n3\n\nDividing them into three groups such as \\{1,3\\}, \\{2,4\\}, and \\{5\\} achieves the goal.\n\nSample Input 2\n\n4 10\n1 2\n2 1\n1 2\n2 1\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n\nSample Output 2\n\n4\n\nSample Input 3\n\n10 4\n3 1\n4 1\n5 9\n2 6\n\nSample Output 3\n\n3", "sample_input": "5 3\n1 2\n3 4\n5 1\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02573", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are N persons called Person 1 through Person N.\n\nYou are given M facts that \"Person A_i and Person B_i are friends.\" The same fact may be given multiple times.\n\nIf X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.\n\nTakahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.\n\nAt least how many groups does he need to make?\n\nConstraints\n\n2 \\leq N \\leq 2\\times 10^5\n\n0 \\leq M \\leq 2\\times 10^5\n\n1\\leq A_i,B_i\\leq N\n\nA_i \\neq B_i\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\n\\vdots\nA_M B_M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n5 3\n1 2\n3 4\n5 1\n\nSample Output 1\n\n3\n\nDividing them into three groups such as \\{1,3\\}, \\{2,4\\}, and \\{5\\} achieves the goal.\n\nSample Input 2\n\n4 10\n1 2\n2 1\n1 2\n2 1\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n\nSample Output 2\n\n4\n\nSample Input 3\n\n10 4\n3 1\n4 1\n5 9\n2 6\n\nSample Output 3\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1711, "cpu_time_ms": 2209, "memory_kb": 99192}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s210531857", "group_id": "codeNet:p02576", "input_text": "(let* ((n (read))\n (m (read))\n (a (read)))\n (princ (* a (ceiling (/ n m)))))", "language": "Lisp", "metadata": {"date": 1598936513, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02576.html", "problem_id": "p02576", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02576/input.txt", "sample_output_relpath": "derived/input_output/data/p02576/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02576/Lisp/s210531857.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s210531857", "user_id": "u610490393"}, "prompt_components": {"gold_output": "12\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (a (read)))\n (princ (* a (ceiling (/ n m)))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi loves takoyaki - a ball-shaped snack.\n\nWith a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.\n\nHow long does it take to make N takoyaki?\n\nConstraints\n\n1 \\leq N,X,T \\leq 1000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X T\n\nOutput\n\nPrint an integer representing the minimum number of minutes needed to make N pieces of takoyaki.\n\nSample Input 1\n\n20 12 6\n\nSample Output 1\n\n12\n\nHe can make 12 pieces of takoyaki in the first 6 minutes and 8 more in the next 6 minutes, so he can make 20 in a total of 12 minutes.\n\nNote that being able to make 12 in 6 minutes does not mean he can make 2 in 1 minute.\n\nSample Input 2\n\n1000 1 1000\n\nSample Output 2\n\n1000000\n\nIt seems to take a long time to make this kind of takoyaki.", "sample_input": "20 12 6\n"}, "reference_outputs": ["12\n"], "source_document_id": "p02576", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi loves takoyaki - a ball-shaped snack.\n\nWith a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.\n\nHow long does it take to make N takoyaki?\n\nConstraints\n\n1 \\leq N,X,T \\leq 1000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X T\n\nOutput\n\nPrint an integer representing the minimum number of minutes needed to make N pieces of takoyaki.\n\nSample Input 1\n\n20 12 6\n\nSample Output 1\n\n12\n\nHe can make 12 pieces of takoyaki in the first 6 minutes and 8 more in the next 6 minutes, so he can make 20 in a total of 12 minutes.\n\nNote that being able to make 12 in 6 minutes does not mean he can make 2 in 1 minute.\n\nSample Input 2\n\n1000 1 1000\n\nSample Output 2\n\n1000000\n\nIt seems to take a long time to make this kind of takoyaki.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 89, "cpu_time_ms": 15, "memory_kb": 24136}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s206205750", "group_id": "codeNet:p02576", "input_text": "(let ((n (read))\n (x (read))\n (ti (read)))\n (princ (* (ceiling (/ n x)) ti))\n)", "language": "Lisp", "metadata": {"date": 1598122937, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02576.html", "problem_id": "p02576", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02576/input.txt", "sample_output_relpath": "derived/input_output/data/p02576/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02576/Lisp/s206205750.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s206205750", "user_id": "u136500538"}, "prompt_components": {"gold_output": "12\n", "input_to_evaluate": "(let ((n (read))\n (x (read))\n (ti (read)))\n (princ (* (ceiling (/ n x)) ti))\n)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi loves takoyaki - a ball-shaped snack.\n\nWith a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.\n\nHow long does it take to make N takoyaki?\n\nConstraints\n\n1 \\leq N,X,T \\leq 1000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X T\n\nOutput\n\nPrint an integer representing the minimum number of minutes needed to make N pieces of takoyaki.\n\nSample Input 1\n\n20 12 6\n\nSample Output 1\n\n12\n\nHe can make 12 pieces of takoyaki in the first 6 minutes and 8 more in the next 6 minutes, so he can make 20 in a total of 12 minutes.\n\nNote that being able to make 12 in 6 minutes does not mean he can make 2 in 1 minute.\n\nSample Input 2\n\n1000 1 1000\n\nSample Output 2\n\n1000000\n\nIt seems to take a long time to make this kind of takoyaki.", "sample_input": "20 12 6\n"}, "reference_outputs": ["12\n"], "source_document_id": "p02576", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi loves takoyaki - a ball-shaped snack.\n\nWith a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.\n\nHow long does it take to make N takoyaki?\n\nConstraints\n\n1 \\leq N,X,T \\leq 1000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X T\n\nOutput\n\nPrint an integer representing the minimum number of minutes needed to make N pieces of takoyaki.\n\nSample Input 1\n\n20 12 6\n\nSample Output 1\n\n12\n\nHe can make 12 pieces of takoyaki in the first 6 minutes and 8 more in the next 6 minutes, so he can make 20 in a total of 12 minutes.\n\nNote that being able to make 12 in 6 minutes does not mean he can make 2 in 1 minute.\n\nSample Input 2\n\n1000 1 1000\n\nSample Output 2\n\n1000000\n\nIt seems to take a long time to make this kind of takoyaki.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 87, "cpu_time_ms": 20, "memory_kb": 24256}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s208802714", "group_id": "codeNet:p02577", "input_text": "(defun digit-sum(x)\n (let ((x-str (format nil \"~a\" x)))\n (reduce #'+\n (map 'vector (lambda (xxx)\n (- (char-code xxx) (char-code #\\0))) x-str))))\n(format t \"~a~%\" (if (= (rem (digit-sum (read)) 9) 0) \"Yes\" \"No\"))", "language": "Lisp", "metadata": {"date": 1598125461, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02577.html", "problem_id": "p02577", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02577/input.txt", "sample_output_relpath": "derived/input_output/data/p02577/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02577/Lisp/s208802714.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s208802714", "user_id": "u816441392"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun digit-sum(x)\n (let ((x-str (format nil \"~a\" x)))\n (reduce #'+\n (map 'vector (lambda (xxx)\n (- (char-code xxx) (char-code #\\0))) x-str))))\n(format t \"~a~%\" (if (= (rem (digit-sum (read)) 9) 0) \"Yes\" \"No\"))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nAn integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9.\n\nDetermine whether N is a multiple of 9.\n\nConstraints\n\n0 \\leq N < 10^{200000}\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf N is a multiple of 9, print Yes; otherwise, print No.\n\nSample Input 1\n\n123456789\n\nSample Output 1\n\nYes\n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so 123456789 is a multiple of 9.\n\nSample Input 2\n\n0\n\nSample Output 2\n\nYes\n\nSample Input 3\n\n31415926535897932384626433832795028841971693993751058209749445923078164062862089986280\n\nSample Output 3\n\nNo", "sample_input": "123456789\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02577", "source_text": "Score : 200 points\n\nProblem Statement\n\nAn integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9.\n\nDetermine whether N is a multiple of 9.\n\nConstraints\n\n0 \\leq N < 10^{200000}\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf N is a multiple of 9, print Yes; otherwise, print No.\n\nSample Input 1\n\n123456789\n\nSample Output 1\n\nYes\n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so 123456789 is a multiple of 9.\n\nSample Input 2\n\n0\n\nSample Output 2\n\nYes\n\nSample Input 3\n\n31415926535897932384626433832795028841971693993751058209749445923078164062862089986280\n\nSample Output 3\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 275, "cpu_time_ms": 604, "memory_kb": 113432}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s595335007", "group_id": "codeNet:p02578", "input_text": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defpackage :cp/modify-macro\n (:use :cl)\n (:export #:minf #:maxf #:mulf #:divf #:iorf #:xorf #:andf))\n(in-package :cp/modify-macro)\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/modify-macro :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (let ((height (aref as 0))\n (res 0))\n (loop for i from 1 below n\n for a = (aref as i)\n when (< a height)\n do (incf res (- height a))\n do (maxf height a))\n (println res))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"4\n\"\n (run \"5\n2 1 5 4 3\n\" nil)))\n (it.bese.fiveam:is\n (equal \"0\n\"\n (run \"5\n3 3 3 3 3\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1598158735, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02578.html", "problem_id": "p02578", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02578/input.txt", "sample_output_relpath": "derived/input_output/data/p02578/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02578/Lisp/s595335007.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s595335007", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defpackage :cp/modify-macro\n (:use :cl)\n (:export #:minf #:maxf #:mulf #:divf #:iorf #:xorf #:andf))\n(in-package :cp/modify-macro)\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/modify-macro :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (let ((height (aref as 0))\n (res 0))\n (loop for i from 1 below n\n for a = (aref as i)\n when (< a height)\n do (incf res (- height a))\n do (maxf height a))\n (println res))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"4\n\"\n (run \"5\n2 1 5 4 3\n\" nil)))\n (it.bese.fiveam:is\n (equal \"0\n\"\n (run \"5\n3 3 3 3 3\n\" nil))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nN persons are standing in a row. The height of the i-th person from the front is A_i.\n\nWe want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:\n\nCondition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool.\n\nFind the minimum total height of the stools needed to meet this goal.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 \\ldots A_N\n\nOutput\n\nPrint the minimum total height of the stools needed to meet the goal.\n\nSample Input 1\n\n5\n2 1 5 4 3\n\nSample Output 1\n\n4\n\nIf the persons stand on stools of heights 0, 1, 0, 1, and 2, respectively, their heights will be 2, 2, 5, 5, and 5, satisfying the condition.\n\nWe cannot meet the goal with a smaller total height of the stools.\n\nSample Input 2\n\n5\n3 3 3 3 3\n\nSample Output 2\n\n0\n\nGiving a stool of height 0 to everyone will work.", "sample_input": "5\n2 1 5 4 3\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02578", "source_text": "Score : 300 points\n\nProblem Statement\n\nN persons are standing in a row. The height of the i-th person from the front is A_i.\n\nWe want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:\n\nCondition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool.\n\nFind the minimum total height of the stools needed to meet this goal.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 \\ldots A_N\n\nOutput\n\nPrint the minimum total height of the stools needed to meet the goal.\n\nSample Input 1\n\n5\n2 1 5 4 3\n\nSample Output 1\n\n4\n\nIf the persons stand on stools of heights 0, 1, 0, 1, and 2, respectively, their heights will be 2, 2, 5, 5, and 5, satisfying the condition.\n\nWe cannot meet the goal with a smaller total height of the stools.\n\nSample Input 2\n\n5\n3 3 3 3 3\n\nSample Output 2\n\n0\n\nGiving a stool of height 0 to everyone will work.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5329, "cpu_time_ms": 52, "memory_kb": 25812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s282691684", "group_id": "codeNet:p02578", "input_text": " (defun read-n-num (n)\n (let ((result)) (dotimes (x n (nreverse result)) (push (read) result))))\n(let* ((v-n (read))\n (v-ai (read-n-num v-n))\n (need-hight (first v-ai)))\n (reduce #'+ (reduce\n (lambda (result v-a)\n (when (< need-hight v-a)\n (setf need-hight v-a))\n (cons (- need-hight v-a) result))\n v-ai :initial-value nil))\n )", "language": "Lisp", "metadata": {"date": 1598127042, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02578.html", "problem_id": "p02578", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02578/input.txt", "sample_output_relpath": "derived/input_output/data/p02578/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02578/Lisp/s282691684.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s282691684", "user_id": "u816441392"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": " (defun read-n-num (n)\n (let ((result)) (dotimes (x n (nreverse result)) (push (read) result))))\n(let* ((v-n (read))\n (v-ai (read-n-num v-n))\n (need-hight (first v-ai)))\n (reduce #'+ (reduce\n (lambda (result v-a)\n (when (< need-hight v-a)\n (setf need-hight v-a))\n (cons (- need-hight v-a) result))\n v-ai :initial-value nil))\n )", "problem_context": "Score : 300 points\n\nProblem Statement\n\nN persons are standing in a row. The height of the i-th person from the front is A_i.\n\nWe want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:\n\nCondition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool.\n\nFind the minimum total height of the stools needed to meet this goal.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 \\ldots A_N\n\nOutput\n\nPrint the minimum total height of the stools needed to meet the goal.\n\nSample Input 1\n\n5\n2 1 5 4 3\n\nSample Output 1\n\n4\n\nIf the persons stand on stools of heights 0, 1, 0, 1, and 2, respectively, their heights will be 2, 2, 5, 5, and 5, satisfying the condition.\n\nWe cannot meet the goal with a smaller total height of the stools.\n\nSample Input 2\n\n5\n3 3 3 3 3\n\nSample Output 2\n\n0\n\nGiving a stool of height 0 to everyone will work.", "sample_input": "5\n2 1 5 4 3\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02578", "source_text": "Score : 300 points\n\nProblem Statement\n\nN persons are standing in a row. The height of the i-th person from the front is A_i.\n\nWe want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:\n\nCondition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool.\n\nFind the minimum total height of the stools needed to meet this goal.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 \\ldots A_N\n\nOutput\n\nPrint the minimum total height of the stools needed to meet the goal.\n\nSample Input 1\n\n5\n2 1 5 4 3\n\nSample Output 1\n\n4\n\nIf the persons stand on stools of heights 0, 1, 0, 1, and 2, respectively, their heights will be 2, 2, 5, 5, and 5, satisfying the condition.\n\nWe cannot meet the goal with a smaller total height of the stools.\n\nSample Input 2\n\n5\n3 3 3 3 3\n\nSample Output 2\n\n0\n\nGiving a stool of height 0 to everyone will work.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 449, "cpu_time_ms": 261, "memory_kb": 79112}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s216320561", "group_id": "codeNet:p02578", "input_text": "(defun solve (lst)\n (loop for x in lst\n with height = 0\n if (< x height) sum (- height x)\n else do (setf height x)))\n\n(princ (solve (loop repeat (read) collect (read))))", "language": "Lisp", "metadata": {"date": 1598125833, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02578.html", "problem_id": "p02578", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02578/input.txt", "sample_output_relpath": "derived/input_output/data/p02578/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02578/Lisp/s216320561.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s216320561", "user_id": "u289580381"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun solve (lst)\n (loop for x in lst\n with height = 0\n if (< x height) sum (- height x)\n else do (setf height x)))\n\n(princ (solve (loop repeat (read) collect (read))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nN persons are standing in a row. The height of the i-th person from the front is A_i.\n\nWe want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:\n\nCondition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool.\n\nFind the minimum total height of the stools needed to meet this goal.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 \\ldots A_N\n\nOutput\n\nPrint the minimum total height of the stools needed to meet the goal.\n\nSample Input 1\n\n5\n2 1 5 4 3\n\nSample Output 1\n\n4\n\nIf the persons stand on stools of heights 0, 1, 0, 1, and 2, respectively, their heights will be 2, 2, 5, 5, and 5, satisfying the condition.\n\nWe cannot meet the goal with a smaller total height of the stools.\n\nSample Input 2\n\n5\n3 3 3 3 3\n\nSample Output 2\n\n0\n\nGiving a stool of height 0 to everyone will work.", "sample_input": "5\n2 1 5 4 3\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02578", "source_text": "Score : 300 points\n\nProblem Statement\n\nN persons are standing in a row. The height of the i-th person from the front is A_i.\n\nWe want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:\n\nCondition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool.\n\nFind the minimum total height of the stools needed to meet this goal.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 \\ldots A_N\n\nOutput\n\nPrint the minimum total height of the stools needed to meet the goal.\n\nSample Input 1\n\n5\n2 1 5 4 3\n\nSample Output 1\n\n4\n\nIf the persons stand on stools of heights 0, 1, 0, 1, and 2, respectively, their heights will be 2, 2, 5, 5, and 5, satisfying the condition.\n\nWe cannot meet the goal with a smaller total height of the stools.\n\nSample Input 2\n\n5\n3 3 3 3 3\n\nSample Output 2\n\n0\n\nGiving a stool of height 0 to everyone will work.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 191, "cpu_time_ms": 268, "memory_kb": 80004}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s171400897", "group_id": "codeNet:p02579", "input_text": "(let* ((h (read))\n (w (read))\n (ci (read))\n (cj (read))\n (di (read))\n (dj (read))\n (f (make-array (list (1+ h) (1+ w)) :initial-element t)))\n ;\n (loop :for i :from 1 :to h\n :for s := (read-line)\n :do (loop :for c :across s\n :for j :from 1 :to w\n :if (char= c #\\#)\n :do (setf (aref f i j) nil)))\n ;\n (defun check (q)\n (let ((c nil))\n (loop :while q\n :for pos := (pop q)\n :for i := (car pos)\n :for j := (cdr pos)\n :if (and (= i di) (= j dj))\n :do (progn\n (setf (aref f i j) nil)\n (return-from check nil))\n :if (aref f i j)\n :do (progn\n (setf (aref f i j) nil)\n (loop :for y :from (max 1 (- i 2)) :to (min h (+ i 2))\n :do (loop :for x :from (max 1 (- j 2)) :to (min w (+ j 2))\n :do (when (aref f y x)\n (let ((d (+ (abs (- i y)) (abs (- j x)))))\n (if (= 1 d)\n (push (cons y x) q)\n (push (cons y x) c))))))))\n c))\n ;\n (let ((q nil)\n (cost 0))\n (push (cons ci cj) q)\n (loop :named main\n :while q\n :do (progn\n (setf q (check q))\n (unless (aref f di dj)\n (format t \"~A~%\" cost)\n (return-from main))\n (incf cost))\n :finally (format t \"-1~%\"))))\n", "language": "Lisp", "metadata": {"date": 1599073927, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02579.html", "problem_id": "p02579", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02579/input.txt", "sample_output_relpath": "derived/input_output/data/p02579/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02579/Lisp/s171400897.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s171400897", "user_id": "u608227593"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let* ((h (read))\n (w (read))\n (ci (read))\n (cj (read))\n (di (read))\n (dj (read))\n (f (make-array (list (1+ h) (1+ w)) :initial-element t)))\n ;\n (loop :for i :from 1 :to h\n :for s := (read-line)\n :do (loop :for c :across s\n :for j :from 1 :to w\n :if (char= c #\\#)\n :do (setf (aref f i j) nil)))\n ;\n (defun check (q)\n (let ((c nil))\n (loop :while q\n :for pos := (pop q)\n :for i := (car pos)\n :for j := (cdr pos)\n :if (and (= i di) (= j dj))\n :do (progn\n (setf (aref f i j) nil)\n (return-from check nil))\n :if (aref f i j)\n :do (progn\n (setf (aref f i j) nil)\n (loop :for y :from (max 1 (- i 2)) :to (min h (+ i 2))\n :do (loop :for x :from (max 1 (- j 2)) :to (min w (+ j 2))\n :do (when (aref f y x)\n (let ((d (+ (abs (- i y)) (abs (- j x)))))\n (if (= 1 d)\n (push (cons y x) q)\n (push (cons y x) c))))))))\n c))\n ;\n (let ((q nil)\n (cost 0))\n (push (cons ci cj) q)\n (loop :named main\n :while q\n :do (progn\n (setf q (check q))\n (unless (aref f di dj)\n (format t \"~A~%\" cost)\n (return-from main))\n (incf cost))\n :finally (format t \"-1~%\"))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nA maze is composed of a grid of H \\times W squares - H vertical, W horizontal.\n\nThe square at the i-th row from the top and the j-th column from the left - (i,j) - is a wall if S_{ij} is # and a road if S_{ij} is ..\n\nThere is a magician in (C_h,C_w). He can do the following two kinds of moves:\n\nMove A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in.\n\nMove B: Use magic to warp himself to a road square in the 5\\times 5 area centered at the square he is currently in.\n\nIn either case, he cannot go out of the maze.\n\nAt least how many times does he need to use the magic to reach (D_h, D_w)?\n\nConstraints\n\n1 \\leq H,W \\leq 10^3\n\n1 \\leq C_h,D_h \\leq H\n\n1 \\leq C_w,D_w \\leq W\n\nS_{ij} is # or ..\n\nS_{C_h C_w} and S_{D_h D_w} are ..\n\n(C_h,C_w) \\neq (D_h,D_w)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nC_h C_w\nD_h D_w\nS_{11}\\ldots S_{1W}\n\\vdots\nS_{H1}\\ldots S_{HW}\n\nOutput\n\nPrint the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print -1 instead.\n\nSample Input 1\n\n4 4\n1 1\n4 4\n..#.\n..#.\n.#..\n.#..\n\nSample Output 1\n\n1\n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4), just one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\nSample Input 2\n\n4 4\n1 4\n4 1\n.##.\n####\n####\n.##.\n\nSample Output 2\n\n-1\n\nHe cannot move from there.\n\nSample Input 3\n\n4 4\n2 2\n3 3\n....\n....\n....\n....\n\nSample Output 3\n\n0\n\nNo use of magic is needed.\n\nSample Input 4\n\n4 5\n1 2\n2 5\n#.###\n####.\n#..##\n#..##\n\nSample Output 4\n\n2", "sample_input": "4 4\n1 1\n4 4\n..#.\n..#.\n.#..\n.#..\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02579", "source_text": "Score : 400 points\n\nProblem Statement\n\nA maze is composed of a grid of H \\times W squares - H vertical, W horizontal.\n\nThe square at the i-th row from the top and the j-th column from the left - (i,j) - is a wall if S_{ij} is # and a road if S_{ij} is ..\n\nThere is a magician in (C_h,C_w). He can do the following two kinds of moves:\n\nMove A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in.\n\nMove B: Use magic to warp himself to a road square in the 5\\times 5 area centered at the square he is currently in.\n\nIn either case, he cannot go out of the maze.\n\nAt least how many times does he need to use the magic to reach (D_h, D_w)?\n\nConstraints\n\n1 \\leq H,W \\leq 10^3\n\n1 \\leq C_h,D_h \\leq H\n\n1 \\leq C_w,D_w \\leq W\n\nS_{ij} is # or ..\n\nS_{C_h C_w} and S_{D_h D_w} are ..\n\n(C_h,C_w) \\neq (D_h,D_w)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nC_h C_w\nD_h D_w\nS_{11}\\ldots S_{1W}\n\\vdots\nS_{H1}\\ldots S_{HW}\n\nOutput\n\nPrint the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print -1 instead.\n\nSample Input 1\n\n4 4\n1 1\n4 4\n..#.\n..#.\n.#..\n.#..\n\nSample Output 1\n\n1\n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4), just one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\nSample Input 2\n\n4 4\n1 4\n4 1\n.##.\n####\n####\n.##.\n\nSample Output 2\n\n-1\n\nHe cannot move from there.\n\nSample Input 3\n\n4 4\n2 2\n3 3\n....\n....\n....\n....\n\nSample Output 3\n\n0\n\nNo use of magic is needed.\n\nSample Input 4\n\n4 5\n1 2\n2 5\n#.###\n####.\n#..##\n#..##\n\nSample Output 4\n\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1646, "cpu_time_ms": 213, "memory_kb": 78940}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s050804566", "group_id": "codeNet:p02579", "input_text": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Queue with singly linked list\n;;;\n\n(defpackage :cp/queue\n (:use :cl)\n (:export #:queue #:make-queue #:enqueue #:dequeue #:queue-empty-p #:queue-peek #:enqueue-front))\n(in-package :cp/queue)\n\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list))))\n (:copier nil)\n (:predicate nil))\n (list nil :type list)\n (tail nil :type list))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Removes and returns the element at the front of QUEUE. Returns NIL if QUEUE\nis empty.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline queue-peek))\n(defun queue-peek (queue)\n (car (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(defpackage :cp/read-schar\n (:use :cl)\n (:export #:read-schar))\n(in-package :cp/read-schar)\n\n(declaim (inline read-schar))\n(defun read-schar (&optional (stream *standard-input*))\n (declare #-swank (sb-kernel:ansi-stream stream)\n (inline read-byte))\n #+swank (read-char stream nil #\\Newline) ; on SLIME\n #-swank (code-char (read-byte stream nil #.(char-code #\\Newline))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-schar :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/queue :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #x7fffffff)\n(defun main ()\n (declare #.opt\n (inline sort sb-impl::stable-sort-list))\n (let* ((h (read))\n (w (read))\n (ch (- (read) 1))\n (cw (- (read) 1))\n (dh (- (read) 1))\n (dw (- (read) 1))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0))\n (dists (make-array (list h w) :element-type 'uint31 :initial-element +inf+))\n (que (make-queue)))\n (declare (uint16 h w ch cw dh dw))\n (dotimes (i h)\n (dotimes (j w (read-schar))\n (ecase (read-schar)\n (#\\.)\n (#\\# (setf (aref plan i j) 1)))))\n (setf (aref dists ch cw) 0)\n (enqueue (list* ch cw 0) que)\n (loop until (queue-empty-p que)\n for (i1 j1 . dist) of-type (uint31 uint31 . uint31) = (dequeue que)\n when (= dist (aref dists i1 j1))\n do (labels ((calc-cost (i2 j2)\n (cond ((= 1 (aref plan i2 j2)) +inf+)\n ((= 1 (+ (abs (- i1 i2)) (abs (- j1 j2)))) 0)\n (t 1)))\n (visit (i2 j2)\n (when (and (<= 0 i2 (- h 1))\n (<= 0 j2 (- w 1)))\n (let ((new-dist (+ dist (calc-cost i2 j2))))\n (when (< new-dist (aref dists i2 j2))\n (setf (aref dists i2 j2) new-dist)\n (if (= dist new-dist)\n (enqueue-front (list* i2 j2 new-dist) que)\n (enqueue (list* i2 j2 new-dist) que)))))))\n (loop for i2 from (- i1 2) to (+ i1 2)\n do (loop for j2 from (- j1 2) to (+ j1 2)\n do (visit i2 j2)))))\n (println (if (= (aref dists dh dw) +inf+)\n -1\n (aref dists dh dw)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"1\n\"\n (run \"4 4\n1 1\n4 4\n..#.\n..#.\n.#..\n.#..\n\" nil)))\n (it.bese.fiveam:is\n (equal \"-1\n\"\n (run \"4 4\n1 4\n4 1\n.##.\n####\n####\n.##.\n\" nil)))\n (it.bese.fiveam:is\n (equal \"0\n\"\n (run \"4 4\n2 2\n3 3\n....\n....\n....\n....\n\" nil)))\n (it.bese.fiveam:is\n (equal \"2\n\"\n (run \"4 5\n1 2\n2 5\n#.###\n####.\n#..##\n#..##\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1598176277, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02579.html", "problem_id": "p02579", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02579/input.txt", "sample_output_relpath": "derived/input_output/data/p02579/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02579/Lisp/s050804566.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s050804566", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Queue with singly linked list\n;;;\n\n(defpackage :cp/queue\n (:use :cl)\n (:export #:queue #:make-queue #:enqueue #:dequeue #:queue-empty-p #:queue-peek #:enqueue-front))\n(in-package :cp/queue)\n\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list))))\n (:copier nil)\n (:predicate nil))\n (list nil :type list)\n (tail nil :type list))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Removes and returns the element at the front of QUEUE. Returns NIL if QUEUE\nis empty.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline queue-peek))\n(defun queue-peek (queue)\n (car (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(defpackage :cp/read-schar\n (:use :cl)\n (:export #:read-schar))\n(in-package :cp/read-schar)\n\n(declaim (inline read-schar))\n(defun read-schar (&optional (stream *standard-input*))\n (declare #-swank (sb-kernel:ansi-stream stream)\n (inline read-byte))\n #+swank (read-char stream nil #\\Newline) ; on SLIME\n #-swank (code-char (read-byte stream nil #.(char-code #\\Newline))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-schar :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/queue :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #x7fffffff)\n(defun main ()\n (declare #.opt\n (inline sort sb-impl::stable-sort-list))\n (let* ((h (read))\n (w (read))\n (ch (- (read) 1))\n (cw (- (read) 1))\n (dh (- (read) 1))\n (dw (- (read) 1))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0))\n (dists (make-array (list h w) :element-type 'uint31 :initial-element +inf+))\n (que (make-queue)))\n (declare (uint16 h w ch cw dh dw))\n (dotimes (i h)\n (dotimes (j w (read-schar))\n (ecase (read-schar)\n (#\\.)\n (#\\# (setf (aref plan i j) 1)))))\n (setf (aref dists ch cw) 0)\n (enqueue (list* ch cw 0) que)\n (loop until (queue-empty-p que)\n for (i1 j1 . dist) of-type (uint31 uint31 . uint31) = (dequeue que)\n when (= dist (aref dists i1 j1))\n do (labels ((calc-cost (i2 j2)\n (cond ((= 1 (aref plan i2 j2)) +inf+)\n ((= 1 (+ (abs (- i1 i2)) (abs (- j1 j2)))) 0)\n (t 1)))\n (visit (i2 j2)\n (when (and (<= 0 i2 (- h 1))\n (<= 0 j2 (- w 1)))\n (let ((new-dist (+ dist (calc-cost i2 j2))))\n (when (< new-dist (aref dists i2 j2))\n (setf (aref dists i2 j2) new-dist)\n (if (= dist new-dist)\n (enqueue-front (list* i2 j2 new-dist) que)\n (enqueue (list* i2 j2 new-dist) que)))))))\n (loop for i2 from (- i1 2) to (+ i1 2)\n do (loop for j2 from (- j1 2) to (+ j1 2)\n do (visit i2 j2)))))\n (println (if (= (aref dists dh dw) +inf+)\n -1\n (aref dists dh dw)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"1\n\"\n (run \"4 4\n1 1\n4 4\n..#.\n..#.\n.#..\n.#..\n\" nil)))\n (it.bese.fiveam:is\n (equal \"-1\n\"\n (run \"4 4\n1 4\n4 1\n.##.\n####\n####\n.##.\n\" nil)))\n (it.bese.fiveam:is\n (equal \"0\n\"\n (run \"4 4\n2 2\n3 3\n....\n....\n....\n....\n\" nil)))\n (it.bese.fiveam:is\n (equal \"2\n\"\n (run \"4 5\n1 2\n2 5\n#.###\n####.\n#..##\n#..##\n\" nil))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nA maze is composed of a grid of H \\times W squares - H vertical, W horizontal.\n\nThe square at the i-th row from the top and the j-th column from the left - (i,j) - is a wall if S_{ij} is # and a road if S_{ij} is ..\n\nThere is a magician in (C_h,C_w). He can do the following two kinds of moves:\n\nMove A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in.\n\nMove B: Use magic to warp himself to a road square in the 5\\times 5 area centered at the square he is currently in.\n\nIn either case, he cannot go out of the maze.\n\nAt least how many times does he need to use the magic to reach (D_h, D_w)?\n\nConstraints\n\n1 \\leq H,W \\leq 10^3\n\n1 \\leq C_h,D_h \\leq H\n\n1 \\leq C_w,D_w \\leq W\n\nS_{ij} is # or ..\n\nS_{C_h C_w} and S_{D_h D_w} are ..\n\n(C_h,C_w) \\neq (D_h,D_w)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nC_h C_w\nD_h D_w\nS_{11}\\ldots S_{1W}\n\\vdots\nS_{H1}\\ldots S_{HW}\n\nOutput\n\nPrint the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print -1 instead.\n\nSample Input 1\n\n4 4\n1 1\n4 4\n..#.\n..#.\n.#..\n.#..\n\nSample Output 1\n\n1\n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4), just one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\nSample Input 2\n\n4 4\n1 4\n4 1\n.##.\n####\n####\n.##.\n\nSample Output 2\n\n-1\n\nHe cannot move from there.\n\nSample Input 3\n\n4 4\n2 2\n3 3\n....\n....\n....\n....\n\nSample Output 3\n\n0\n\nNo use of magic is needed.\n\nSample Input 4\n\n4 5\n1 2\n2 5\n#.###\n####.\n#..##\n#..##\n\nSample Output 4\n\n2", "sample_input": "4 4\n1 1\n4 4\n..#.\n..#.\n.#..\n.#..\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02579", "source_text": "Score : 400 points\n\nProblem Statement\n\nA maze is composed of a grid of H \\times W squares - H vertical, W horizontal.\n\nThe square at the i-th row from the top and the j-th column from the left - (i,j) - is a wall if S_{ij} is # and a road if S_{ij} is ..\n\nThere is a magician in (C_h,C_w). He can do the following two kinds of moves:\n\nMove A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in.\n\nMove B: Use magic to warp himself to a road square in the 5\\times 5 area centered at the square he is currently in.\n\nIn either case, he cannot go out of the maze.\n\nAt least how many times does he need to use the magic to reach (D_h, D_w)?\n\nConstraints\n\n1 \\leq H,W \\leq 10^3\n\n1 \\leq C_h,D_h \\leq H\n\n1 \\leq C_w,D_w \\leq W\n\nS_{ij} is # or ..\n\nS_{C_h C_w} and S_{D_h D_w} are ..\n\n(C_h,C_w) \\neq (D_h,D_w)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nC_h C_w\nD_h D_w\nS_{11}\\ldots S_{1W}\n\\vdots\nS_{H1}\\ldots S_{HW}\n\nOutput\n\nPrint the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print -1 instead.\n\nSample Input 1\n\n4 4\n1 1\n4 4\n..#.\n..#.\n.#..\n.#..\n\nSample Output 1\n\n1\n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4), just one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\nSample Input 2\n\n4 4\n1 4\n4 1\n.##.\n####\n####\n.##.\n\nSample Output 2\n\n-1\n\nHe cannot move from there.\n\nSample Input 3\n\n4 4\n2 2\n3 3\n....\n....\n....\n....\n\nSample Output 3\n\n0\n\nNo use of magic is needed.\n\nSample Input 4\n\n4 5\n1 2\n2 5\n#.###\n####.\n#..##\n#..##\n\nSample Output 4\n\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7232, "cpu_time_ms": 224, "memory_kb": 67904}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s082621301", "group_id": "codeNet:p02582", "input_text": "(princ ((lambda (x)\n (let ((count 0)\n (ans-list nil))\n (dotimes (n 3)\n (let ((c (aref x n)))\n (if (eql c #\\R)\n (incf count)\n (progn\n (push count ans-list)\n (setq count 0)))))\n (push count ans-list)\n (sort ans-list #'>)\n (car ans-list)))\n (read-line)))\n", "language": "Lisp", "metadata": {"date": 1597528456, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02582.html", "problem_id": "p02582", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02582/input.txt", "sample_output_relpath": "derived/input_output/data/p02582/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02582/Lisp/s082621301.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s082621301", "user_id": "u631655863"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(princ ((lambda (x)\n (let ((count 0)\n (ans-list nil))\n (dotimes (n 3)\n (let ((c (aref x n)))\n (if (eql c #\\R)\n (incf count)\n (progn\n (push count ans-list)\n (setq count 0)))))\n (push count ans-list)\n (sort ans-list #'>)\n (car ans-list)))\n (read-line)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe have weather records at AtCoder Town for some consecutive three days. A string of length 3, S, represents the records - if the i-th character is S, it means it was sunny on the i-th day; if that character is R, it means it was rainy on that day.\n\nFind the maximum number of consecutive rainy days in this period.\n\nConstraints\n\n|S| = 3\n\nEach character of S is S or R.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the maximum number of consecutive rainy days in the period.\n\nSample Input 1\n\nRRS\n\nSample Output 1\n\n2\n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number of consecutive rainy days is 2, so we should print 2.\n\nSample Input 2\n\nSSS\n\nSample Output 2\n\n0\n\nIt was sunny throughout the period. We had no rainy days, so we should print 0.\n\nSample Input 3\n\nRSR\n\nSample Output 3\n\n1\n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we should print 1.", "sample_input": "RRS\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02582", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe have weather records at AtCoder Town for some consecutive three days. A string of length 3, S, represents the records - if the i-th character is S, it means it was sunny on the i-th day; if that character is R, it means it was rainy on that day.\n\nFind the maximum number of consecutive rainy days in this period.\n\nConstraints\n\n|S| = 3\n\nEach character of S is S or R.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the maximum number of consecutive rainy days in the period.\n\nSample Input 1\n\nRRS\n\nSample Output 1\n\n2\n\nWe had rain on the 1-st and 2-nd days in the period. Here, the maximum number of consecutive rainy days is 2, so we should print 2.\n\nSample Input 2\n\nSSS\n\nSample Output 2\n\n0\n\nIt was sunny throughout the period. We had no rainy days, so we should print 0.\n\nSample Input 3\n\nRSR\n\nSample Output 3\n\n1\n\nWe had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we should print 1.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 435, "cpu_time_ms": 15, "memory_kb": 24392}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s746057080", "group_id": "codeNet:p02583", "input_text": "(defun solve(l)\n (loop for l1 on l with x\n do (setf x (car l1))\n sum (loop for l2 on (cdr l1) with y\n do (setf y (car l2))\n sum (loop for l3 on (cdr l2) with z\n do (setf z (car l3))\n count (and (/= x y z)\n (< (* 2 (max x y z))\n (+ x y z)))))))\n\n(princ (solve (loop repeat (read) collect (read))))", "language": "Lisp", "metadata": {"date": 1597589486, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02583.html", "problem_id": "p02583", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02583/input.txt", "sample_output_relpath": "derived/input_output/data/p02583/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02583/Lisp/s746057080.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s746057080", "user_id": "u289580381"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defun solve(l)\n (loop for l1 on l with x\n do (setf x (car l1))\n sum (loop for l2 on (cdr l1) with y\n do (setf y (car l2))\n sum (loop for l3 on (cdr l2) with z\n do (setf z (car l3))\n count (and (/= x y z)\n (< (* 2 (max x y z))\n (+ x y z)))))))\n\n(princ (solve (loop repeat (read) collect (read))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have sticks numbered 1, \\cdots, N. The length of Stick i (1 \\leq i \\leq N) is L_i.\n\nIn how many ways can we choose three of the sticks with different lengths that can form a triangle?\n\nThat is, find the number of triples of integers (i, j, k) (1 \\leq i < j < k \\leq N) that satisfy both of the following conditions:\n\nL_i, L_j, and L_k are all different.\n\nThere exists a triangle whose sides have lengths L_i, L_j, and L_k.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq L_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nL_1 L_2 \\cdots L_N\n\nOutput\n\nPrint the number of ways to choose three of the sticks with different lengths that can form a triangle.\n\nSample Input 1\n\n5\n4 4 9 7 5\n\nSample Output 1\n\n5\n\nThe following five triples (i, j, k) satisfy the conditions: (1, 3, 4), (1, 4, 5), (2, 3, 4), (2, 4, 5), and (3, 4, 5).\n\nSample Input 2\n\n6\n4 5 4 3 3 5\n\nSample Output 2\n\n8\n\nWe have two sticks for each of the lengths 3, 4, and 5. To satisfy the first condition, we have to choose one from each length.\n\nThere is a triangle whose sides have lengths 3, 4, and 5, so we have 2 ^ 3 = 8 triples (i, j, k) that satisfy the conditions.\n\nSample Input 3\n\n10\n9 4 6 1 9 6 10 6 6 8\n\nSample Output 3\n\n39\n\nSample Input 4\n\n2\n1 1\n\nSample Output 4\n\n0\n\nNo triple (i, j, k) satisfies 1 \\leq i < j < k \\leq N, so we should print 0.", "sample_input": "5\n4 4 9 7 5\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02583", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have sticks numbered 1, \\cdots, N. The length of Stick i (1 \\leq i \\leq N) is L_i.\n\nIn how many ways can we choose three of the sticks with different lengths that can form a triangle?\n\nThat is, find the number of triples of integers (i, j, k) (1 \\leq i < j < k \\leq N) that satisfy both of the following conditions:\n\nL_i, L_j, and L_k are all different.\n\nThere exists a triangle whose sides have lengths L_i, L_j, and L_k.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq L_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nL_1 L_2 \\cdots L_N\n\nOutput\n\nPrint the number of ways to choose three of the sticks with different lengths that can form a triangle.\n\nSample Input 1\n\n5\n4 4 9 7 5\n\nSample Output 1\n\n5\n\nThe following five triples (i, j, k) satisfy the conditions: (1, 3, 4), (1, 4, 5), (2, 3, 4), (2, 4, 5), and (3, 4, 5).\n\nSample Input 2\n\n6\n4 5 4 3 3 5\n\nSample Output 2\n\n8\n\nWe have two sticks for each of the lengths 3, 4, and 5. To satisfy the first condition, we have to choose one from each length.\n\nThere is a triangle whose sides have lengths 3, 4, and 5, so we have 2 ^ 3 = 8 triples (i, j, k) that satisfy the conditions.\n\nSample Input 3\n\n10\n9 4 6 1 9 6 10 6 6 8\n\nSample Output 3\n\n39\n\nSample Input 4\n\n2\n1 1\n\nSample Output 4\n\n0\n\nNo triple (i, j, k) satisfies 1 \\leq i < j < k \\leq N, so we should print 0.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 478, "cpu_time_ms": 20, "memory_kb": 24528}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s358486783", "group_id": "codeNet:p02584", "input_text": "(let* ((n (abs (read)))\n (m (read))\n (l (read))\n (mn1 (mod n l))\n (mn1a (floor n l))\n (mn2 (- mn1 l))\n (mn2a (1+ (floor n l))))\n (if (if (= mn1 (min (abs mn1) (abs mn2)))\n (<= m mn1a)\n (<= m mn2a))\n (princ (- n (* m l)))\n (let* ((k (if (= mn1 (min (abs mn1) (abs mn2)))\n (- m mn1a)\n (- m mn2a))))\n (if (evenp k)\n (princ (abs (if (= mn1 (min (abs mn1) (abs mn2)))\n mn1 mn2)))\n (princ (abs (if (= mn1 (min (abs mn1) (abs mn2)))\n mn2 mn1)))))))", "language": "Lisp", "metadata": {"date": 1597523889, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02584.html", "problem_id": "p02584", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02584/input.txt", "sample_output_relpath": "derived/input_output/data/p02584/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02584/Lisp/s358486783.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s358486783", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (abs (read)))\n (m (read))\n (l (read))\n (mn1 (mod n l))\n (mn1a (floor n l))\n (mn2 (- mn1 l))\n (mn2a (1+ (floor n l))))\n (if (if (= mn1 (min (abs mn1) (abs mn2)))\n (<= m mn1a)\n (<= m mn2a))\n (princ (- n (* m l)))\n (let* ((k (if (= mn1 (min (abs mn1) (abs mn2)))\n (- m mn1a)\n (- m mn2a))))\n (if (evenp k)\n (princ (abs (if (= mn1 (min (abs mn1) (abs mn2)))\n mn1 mn2)))\n (princ (abs (if (= mn1 (min (abs mn1) (abs mn2)))\n mn2 mn1)))))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.\n\nMore specifically, in one move, he can go from coordinate x to x + D or x - D.\n\nHe wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.\n\nFind the minimum possible absolute value of the coordinate of the destination.\n\nConstraints\n\n-10^{15} \\leq X \\leq 10^{15}\n\n1 \\leq K \\leq 10^{15}\n\n1 \\leq D \\leq 10^{15}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX K D\n\nOutput\n\nPrint the minimum possible absolute value of the coordinate of the destination.\n\nSample Input 1\n\n6 2 4\n\nSample Output 1\n\n2\n\nTakahashi is now at coordinate 6. It is optimal to make the following moves:\n\nMove from coordinate 6 to (6 - 4 =) 2.\n\nMove from coordinate 2 to (2 - 4 =) -2.\n\nHere, the absolute value of the coordinate of the destination is 2, and we cannot make it smaller.\n\nSample Input 2\n\n7 4 3\n\nSample Output 2\n\n1\n\nTakahashi is now at coordinate 7. It is optimal to make, for example, the following moves:\n\nMove from coordinate 7 to 4.\n\nMove from coordinate 4 to 7.\n\nMove from coordinate 7 to 4.\n\nMove from coordinate 4 to 1.\n\nHere, the absolute value of the coordinate of the destination is 1, and we cannot make it smaller.\n\nSample Input 3\n\n10 1 2\n\nSample Output 3\n\n8\n\nSample Input 4\n\n1000000000000000 1000000000000000 1000000000000000\n\nSample Output 4\n\n1000000000000000\n\nThe answer can be enormous.", "sample_input": "6 2 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02584", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.\n\nMore specifically, in one move, he can go from coordinate x to x + D or x - D.\n\nHe wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.\n\nFind the minimum possible absolute value of the coordinate of the destination.\n\nConstraints\n\n-10^{15} \\leq X \\leq 10^{15}\n\n1 \\leq K \\leq 10^{15}\n\n1 \\leq D \\leq 10^{15}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX K D\n\nOutput\n\nPrint the minimum possible absolute value of the coordinate of the destination.\n\nSample Input 1\n\n6 2 4\n\nSample Output 1\n\n2\n\nTakahashi is now at coordinate 6. It is optimal to make the following moves:\n\nMove from coordinate 6 to (6 - 4 =) 2.\n\nMove from coordinate 2 to (2 - 4 =) -2.\n\nHere, the absolute value of the coordinate of the destination is 2, and we cannot make it smaller.\n\nSample Input 2\n\n7 4 3\n\nSample Output 2\n\n1\n\nTakahashi is now at coordinate 7. It is optimal to make, for example, the following moves:\n\nMove from coordinate 7 to 4.\n\nMove from coordinate 4 to 7.\n\nMove from coordinate 7 to 4.\n\nMove from coordinate 4 to 1.\n\nHere, the absolute value of the coordinate of the destination is 1, and we cannot make it smaller.\n\nSample Input 3\n\n10 1 2\n\nSample Output 3\n\n8\n\nSample Input 4\n\n1000000000000000 1000000000000000 1000000000000000\n\nSample Output 4\n\n1000000000000000\n\nThe answer can be enormous.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 627, "cpu_time_ms": 26, "memory_kb": 24228}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s616867207", "group_id": "codeNet:p02584", "input_text": "(let* ((x (read))\n (x (if (minusp x) (- x) x))\n (k (read))\n (d (read))\n (f (floor (/ x d))))\n (format t \"~A~%\"\n (if (>= f k)\n (- x (* d k))\n (abs (- x (* d f) (if (evenp (- k f)) 0 d))))))", "language": "Lisp", "metadata": {"date": 1597521097, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02584.html", "problem_id": "p02584", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02584/input.txt", "sample_output_relpath": "derived/input_output/data/p02584/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02584/Lisp/s616867207.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s616867207", "user_id": "u607637432"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((x (read))\n (x (if (minusp x) (- x) x))\n (k (read))\n (d (read))\n (f (floor (/ x d))))\n (format t \"~A~%\"\n (if (>= f k)\n (- x (* d k))\n (abs (- x (* d f) (if (evenp (- k f)) 0 d))))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.\n\nMore specifically, in one move, he can go from coordinate x to x + D or x - D.\n\nHe wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.\n\nFind the minimum possible absolute value of the coordinate of the destination.\n\nConstraints\n\n-10^{15} \\leq X \\leq 10^{15}\n\n1 \\leq K \\leq 10^{15}\n\n1 \\leq D \\leq 10^{15}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX K D\n\nOutput\n\nPrint the minimum possible absolute value of the coordinate of the destination.\n\nSample Input 1\n\n6 2 4\n\nSample Output 1\n\n2\n\nTakahashi is now at coordinate 6. It is optimal to make the following moves:\n\nMove from coordinate 6 to (6 - 4 =) 2.\n\nMove from coordinate 2 to (2 - 4 =) -2.\n\nHere, the absolute value of the coordinate of the destination is 2, and we cannot make it smaller.\n\nSample Input 2\n\n7 4 3\n\nSample Output 2\n\n1\n\nTakahashi is now at coordinate 7. It is optimal to make, for example, the following moves:\n\nMove from coordinate 7 to 4.\n\nMove from coordinate 4 to 7.\n\nMove from coordinate 7 to 4.\n\nMove from coordinate 4 to 1.\n\nHere, the absolute value of the coordinate of the destination is 1, and we cannot make it smaller.\n\nSample Input 3\n\n10 1 2\n\nSample Output 3\n\n8\n\nSample Input 4\n\n1000000000000000 1000000000000000 1000000000000000\n\nSample Output 4\n\n1000000000000000\n\nThe answer can be enormous.", "sample_input": "6 2 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02584", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.\n\nMore specifically, in one move, he can go from coordinate x to x + D or x - D.\n\nHe wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.\n\nFind the minimum possible absolute value of the coordinate of the destination.\n\nConstraints\n\n-10^{15} \\leq X \\leq 10^{15}\n\n1 \\leq K \\leq 10^{15}\n\n1 \\leq D \\leq 10^{15}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX K D\n\nOutput\n\nPrint the minimum possible absolute value of the coordinate of the destination.\n\nSample Input 1\n\n6 2 4\n\nSample Output 1\n\n2\n\nTakahashi is now at coordinate 6. It is optimal to make the following moves:\n\nMove from coordinate 6 to (6 - 4 =) 2.\n\nMove from coordinate 2 to (2 - 4 =) -2.\n\nHere, the absolute value of the coordinate of the destination is 2, and we cannot make it smaller.\n\nSample Input 2\n\n7 4 3\n\nSample Output 2\n\n1\n\nTakahashi is now at coordinate 7. It is optimal to make, for example, the following moves:\n\nMove from coordinate 7 to 4.\n\nMove from coordinate 4 to 7.\n\nMove from coordinate 7 to 4.\n\nMove from coordinate 4 to 1.\n\nHere, the absolute value of the coordinate of the destination is 1, and we cannot make it smaller.\n\nSample Input 3\n\n10 1 2\n\nSample Output 3\n\n8\n\nSample Input 4\n\n1000000000000000 1000000000000000 1000000000000000\n\nSample Output 4\n\n1000000000000000\n\nThe answer can be enormous.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 248, "cpu_time_ms": 21, "memory_kb": 24160}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s907826477", "group_id": "codeNet:p02585", "input_text": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Some operations on symmetric group\n;;;\n\n(defpackage :cp/symmetric-group\n (:use :cl)\n (:export #:decompose-to-cycles #:perm* #:perm-inverse #:make-identity-permutation))\n(in-package :cp/symmetric-group)\n\n;; NOTE: Here the underlying set is 0-based: {0, 1, 2, ..., N-1}\n\n(declaim (inline decompose-to-cycles))\n(defun decompose-to-cycles (permutation)\n \"Returns the list of all the cyclic permutations in PERMUTATION and returns\nits parity as the second value. (Actually the second value is the distance to\nthe identity permutation, (0, 1, ..., N-1), w.r.t. swapping.)\"\n (declare (vector permutation))\n (let* ((n (length permutation))\n result\n (visited (make-array n :element-type 'bit :initial-element 0))\n (sign 0))\n (declare ((integer 0 #.most-positive-fixnum) sign))\n (dotimes (init n)\n (when (zerop (sbit visited init))\n (push (loop for x = init then (aref permutation x)\n until (= (sbit visited x) 1)\n collect x\n do (setf (sbit visited x) 1)\n (incf sign))\n result)\n (decf sign)))\n (values result sign)))\n\n(declaim (inline perm*))\n(defun perm* (perm1 perm2)\n \"Composes two permutations. (Actually the arguments doesn't need to be\npermutations. This is just a composition of two maps.)\"\n (let* ((n (length perm1))\n (result (make-array n :element-type 'fixnum)))\n (dotimes (i n)\n (setf (aref result i) (aref perm2 (aref perm1 i))))\n result))\n\n(declaim (inline perm-inverse))\n(defun perm-inverse (perm)\n (let* ((n (length perm))\n (result (make-array n :element-type 'fixnum)))\n (dotimes (i n)\n (setf (aref result (aref perm i)) i))\n result))\n\n(declaim (inline make-identity-permutation))\n(defun make-identity-permutation (size)\n \"Returns #(0 1 2 ... SIZE-1).\"\n (declare ((integer 0 #.most-positive-fixnum) size))\n (let ((result (make-array size :element-type 'fixnum)))\n (dotimes (i size)\n (setf (aref result i) i))\n result))\n\n;;;;\n;;;; Sliding window optimum\n;;;;\n\n(defpackage :cp/sliding-window\n (:use :cl)\n (:export #:calc-window-opt #:sliding-window #:make-sliding-window\n #:swindow-extend #:swindow-shrink #:swindow-get #:swindow-empty-p #:swindow-reinitialize))\n(in-package :cp/sliding-window)\n\n;;;\n;;; For window of fixed width\n;;;\n\n(declaim (inline calc-window-opt))\n(defun calc-window-opt (vector width order)\n \"Computes all the minima (or maxima) of the subsequences of the given width,\nVECTOR[i, i+WIDTH), in O(n). Returns a vector, whose i-th element is the\nminimum (or maximum) of the subsequence beginning with the index i.\n\nORDER := strict order (#'< corresponds to slide min. and #'> to slide max.)\"\n (declare (vector vector)\n ((integer 1 #.most-positive-fixnum) width))\n (let* ((n (length vector))\n (deq (make-array n :element-type '(integer 0 #.most-positive-fixnum)))\n (front-pos 0)\n (end-pos -1)\n (l 0)\n (r 0)\n (res (make-array (+ 1 (- n width)) :element-type (array-element-type vector))))\n (declare ((integer -1 #.most-positive-fixnum) front-pos end-pos l r))\n (assert (<= width n))\n (labels ((push-back (x)\n (incf end-pos)\n (setf (aref deq end-pos) x))\n (pop-back () (decf end-pos))\n (pop-front () (incf front-pos))\n (peek-back () (aref deq end-pos))\n (peek-front () (aref deq front-pos))\n (extend ()\n (loop while (and (<= front-pos end-pos)\n (not (funcall order\n (aref vector (peek-back))\n (aref vector r))))\n do (pop-back))\n (push-back r)\n (incf r))\n (shrink ()\n (when (= (aref deq front-pos) l)\n (pop-front))\n (incf l)))\n (declare (inline push-back pop-back pop-front peek-back peek-front))\n (loop for i below width\n do (extend))\n (loop for i from width below n\n do (setf (aref res (- i width))\n (aref vector (peek-front)))\n (extend)\n (shrink)\n finally (setf (aref res (- i width))\n (aref vector (peek-front))))\n res)))\n\n;;;\n;;; For window of variable width\n;;;\n\n(defstruct (sliding-window (:constructor make-sliding-window\n (size &aux\n (times (make-array size :element-type 'fixnum))\n (values (make-array size :element-type 'fixnum))))\n (:conc-name %swindow-)\n (:copier nil)\n (:predicate nil))\n (front-pos 0 :type (integer 0 #.most-positive-fixnum))\n (end-pos -1 :type (integer -1 #.most-positive-fixnum))\n (times nil :type (simple-array fixnum (*)))\n (values nil :type (simple-array fixnum (*))))\n\n(defun %swindow-push-back (time value sw)\n (let ((new-end-pos (+ 1 (%swindow-end-pos sw))))\n (setf (aref (%swindow-times sw) new-end-pos) time\n (aref (%swindow-values sw) new-end-pos) value\n (%swindow-end-pos sw) new-end-pos)))\n\n(defun %swindow-pop-back (sw)\n (decf (%swindow-end-pos sw)))\n\n(defun %swindow-pop-front (sw)\n (incf (%swindow-front-pos sw)))\n\n(declaim (inline swindow-extend))\n(defun swindow-extend (time value sw order)\n \"ORDER := #'< => minimum\nORDER := #'> => maximum\"\n (let ((values (%swindow-values sw)))\n (loop while (and (<= (%swindow-front-pos sw) (%swindow-end-pos sw))\n (not (funcall order\n (aref values (%swindow-end-pos sw))\n value)))\n do (%swindow-pop-back sw))\n (%swindow-push-back time value sw)))\n\n(declaim (inline swindow-shrink))\n(defun swindow-shrink (time sw)\n \"Advance the left end of the time range to TIME (inclusive).\"\n (let ((times (%swindow-times sw)))\n (loop while (and (<= (%swindow-front-pos sw) (%swindow-end-pos sw))\n (< (aref times (%swindow-front-pos sw)) time))\n do (%swindow-pop-front sw))))\n\n(declaim (inline swindow-empty-p))\n(defun swindow-empty-p (sw)\n (> (%swindow-front-pos sw) (%swindow-end-pos sw)))\n\n(declaim (inline swindow-get-opt))\n(defun swindow-get (sw)\n (assert (not (swindow-empty-p sw)))\n (let ((front-pos (%swindow-front-pos sw)))\n (aref (%swindow-values sw) front-pos)))\n\n(declaim (inline swindow-reinitialize))\n(defun swindow-reinitialize (sw)\n (setf (%swindow-front-pos sw) 0\n (%swindow-end-pos sw) -1))\n\n(defpackage :cp/modify-macro\n (:use :cl)\n (:export #:minf #:maxf #:mulf #:divf #:iorf #:xorf #:andf))\n(in-package :cp/modify-macro)\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/modify-macro :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/sliding-window :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/symmetric-group :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (ps (make-array n :element-type 'fixnum :initial-element 0))\n (cs (make-array n :element-type 'fixnum :initial-element 0))\n (res most-negative-fixnum))\n (dotimes (i n)\n (setf (aref ps i) (- (read-fixnum) 1)))\n (dotimes (i n)\n (setf (aref cs i) (read-fixnum)))\n (let ((cycles (decompose-to-cycles ps)))\n (dolist (cycle cycles)\n (let* ((len (length cycle))\n (scores (loop for p in cycle collect (aref cs p)))\n (lap-sum (reduce #'+ scores))\n (scores (concatenate '(simple-array fixnum (*)) scores scores))\n (cumuls (make-array (+ (length scores) 1) :element-type 'fixnum :initial-element 0)))\n (dotimes (i (length scores))\n (setf (aref cumuls (+ i 1))\n (+ (aref cumuls i) (aref scores i))))\n #>cycle #>cumuls\n (dotimes (i len)\n (dotimes (stride len)\n (let ((incr (- (aref cumuls (+ i stride)) (aref cumuls i)))\n (quot (floor (- k stride) len)))\n (dbg i stride incr quot)\n (unless (and (zerop stride) (zerop quot))\n (maxf res (+ (* quot lap-sum) incr)))\n (unless (zerop stride)\n (maxf res incr))))))))\n (sb-int:dovector (c cs)\n (maxf res c))\n (println res)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"8\n\"\n (run \"5 2\n2 4 5 1 3\n3 4 -10 -8 8\n\" nil)))\n (it.bese.fiveam:is\n (equal \"13\n\"\n (run \"2 3\n2 1\n10 -7\n\" nil)))\n (it.bese.fiveam:is\n (equal \"-1000\n\"\n (run \"3 3\n3 1 2\n-1000 -2000 -3000\n\" nil)))\n (it.bese.fiveam:is\n (equal \"29507023469\n\"\n (run \"10 58\n9 1 6 7 8 4 3 2 10 5\n695279662 988782657 -119067776 382975538 -151885171 -177220596 -169777795 37619092 389386780 980092719\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1597541212, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02585.html", "problem_id": "p02585", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02585/input.txt", "sample_output_relpath": "derived/input_output/data/p02585/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02585/Lisp/s907826477.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s907826477", "user_id": "u352600849"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Some operations on symmetric group\n;;;\n\n(defpackage :cp/symmetric-group\n (:use :cl)\n (:export #:decompose-to-cycles #:perm* #:perm-inverse #:make-identity-permutation))\n(in-package :cp/symmetric-group)\n\n;; NOTE: Here the underlying set is 0-based: {0, 1, 2, ..., N-1}\n\n(declaim (inline decompose-to-cycles))\n(defun decompose-to-cycles (permutation)\n \"Returns the list of all the cyclic permutations in PERMUTATION and returns\nits parity as the second value. (Actually the second value is the distance to\nthe identity permutation, (0, 1, ..., N-1), w.r.t. swapping.)\"\n (declare (vector permutation))\n (let* ((n (length permutation))\n result\n (visited (make-array n :element-type 'bit :initial-element 0))\n (sign 0))\n (declare ((integer 0 #.most-positive-fixnum) sign))\n (dotimes (init n)\n (when (zerop (sbit visited init))\n (push (loop for x = init then (aref permutation x)\n until (= (sbit visited x) 1)\n collect x\n do (setf (sbit visited x) 1)\n (incf sign))\n result)\n (decf sign)))\n (values result sign)))\n\n(declaim (inline perm*))\n(defun perm* (perm1 perm2)\n \"Composes two permutations. (Actually the arguments doesn't need to be\npermutations. This is just a composition of two maps.)\"\n (let* ((n (length perm1))\n (result (make-array n :element-type 'fixnum)))\n (dotimes (i n)\n (setf (aref result i) (aref perm2 (aref perm1 i))))\n result))\n\n(declaim (inline perm-inverse))\n(defun perm-inverse (perm)\n (let* ((n (length perm))\n (result (make-array n :element-type 'fixnum)))\n (dotimes (i n)\n (setf (aref result (aref perm i)) i))\n result))\n\n(declaim (inline make-identity-permutation))\n(defun make-identity-permutation (size)\n \"Returns #(0 1 2 ... SIZE-1).\"\n (declare ((integer 0 #.most-positive-fixnum) size))\n (let ((result (make-array size :element-type 'fixnum)))\n (dotimes (i size)\n (setf (aref result i) i))\n result))\n\n;;;;\n;;;; Sliding window optimum\n;;;;\n\n(defpackage :cp/sliding-window\n (:use :cl)\n (:export #:calc-window-opt #:sliding-window #:make-sliding-window\n #:swindow-extend #:swindow-shrink #:swindow-get #:swindow-empty-p #:swindow-reinitialize))\n(in-package :cp/sliding-window)\n\n;;;\n;;; For window of fixed width\n;;;\n\n(declaim (inline calc-window-opt))\n(defun calc-window-opt (vector width order)\n \"Computes all the minima (or maxima) of the subsequences of the given width,\nVECTOR[i, i+WIDTH), in O(n). Returns a vector, whose i-th element is the\nminimum (or maximum) of the subsequence beginning with the index i.\n\nORDER := strict order (#'< corresponds to slide min. and #'> to slide max.)\"\n (declare (vector vector)\n ((integer 1 #.most-positive-fixnum) width))\n (let* ((n (length vector))\n (deq (make-array n :element-type '(integer 0 #.most-positive-fixnum)))\n (front-pos 0)\n (end-pos -1)\n (l 0)\n (r 0)\n (res (make-array (+ 1 (- n width)) :element-type (array-element-type vector))))\n (declare ((integer -1 #.most-positive-fixnum) front-pos end-pos l r))\n (assert (<= width n))\n (labels ((push-back (x)\n (incf end-pos)\n (setf (aref deq end-pos) x))\n (pop-back () (decf end-pos))\n (pop-front () (incf front-pos))\n (peek-back () (aref deq end-pos))\n (peek-front () (aref deq front-pos))\n (extend ()\n (loop while (and (<= front-pos end-pos)\n (not (funcall order\n (aref vector (peek-back))\n (aref vector r))))\n do (pop-back))\n (push-back r)\n (incf r))\n (shrink ()\n (when (= (aref deq front-pos) l)\n (pop-front))\n (incf l)))\n (declare (inline push-back pop-back pop-front peek-back peek-front))\n (loop for i below width\n do (extend))\n (loop for i from width below n\n do (setf (aref res (- i width))\n (aref vector (peek-front)))\n (extend)\n (shrink)\n finally (setf (aref res (- i width))\n (aref vector (peek-front))))\n res)))\n\n;;;\n;;; For window of variable width\n;;;\n\n(defstruct (sliding-window (:constructor make-sliding-window\n (size &aux\n (times (make-array size :element-type 'fixnum))\n (values (make-array size :element-type 'fixnum))))\n (:conc-name %swindow-)\n (:copier nil)\n (:predicate nil))\n (front-pos 0 :type (integer 0 #.most-positive-fixnum))\n (end-pos -1 :type (integer -1 #.most-positive-fixnum))\n (times nil :type (simple-array fixnum (*)))\n (values nil :type (simple-array fixnum (*))))\n\n(defun %swindow-push-back (time value sw)\n (let ((new-end-pos (+ 1 (%swindow-end-pos sw))))\n (setf (aref (%swindow-times sw) new-end-pos) time\n (aref (%swindow-values sw) new-end-pos) value\n (%swindow-end-pos sw) new-end-pos)))\n\n(defun %swindow-pop-back (sw)\n (decf (%swindow-end-pos sw)))\n\n(defun %swindow-pop-front (sw)\n (incf (%swindow-front-pos sw)))\n\n(declaim (inline swindow-extend))\n(defun swindow-extend (time value sw order)\n \"ORDER := #'< => minimum\nORDER := #'> => maximum\"\n (let ((values (%swindow-values sw)))\n (loop while (and (<= (%swindow-front-pos sw) (%swindow-end-pos sw))\n (not (funcall order\n (aref values (%swindow-end-pos sw))\n value)))\n do (%swindow-pop-back sw))\n (%swindow-push-back time value sw)))\n\n(declaim (inline swindow-shrink))\n(defun swindow-shrink (time sw)\n \"Advance the left end of the time range to TIME (inclusive).\"\n (let ((times (%swindow-times sw)))\n (loop while (and (<= (%swindow-front-pos sw) (%swindow-end-pos sw))\n (< (aref times (%swindow-front-pos sw)) time))\n do (%swindow-pop-front sw))))\n\n(declaim (inline swindow-empty-p))\n(defun swindow-empty-p (sw)\n (> (%swindow-front-pos sw) (%swindow-end-pos sw)))\n\n(declaim (inline swindow-get-opt))\n(defun swindow-get (sw)\n (assert (not (swindow-empty-p sw)))\n (let ((front-pos (%swindow-front-pos sw)))\n (aref (%swindow-values sw) front-pos)))\n\n(declaim (inline swindow-reinitialize))\n(defun swindow-reinitialize (sw)\n (setf (%swindow-front-pos sw) 0\n (%swindow-end-pos sw) -1))\n\n(defpackage :cp/modify-macro\n (:use :cl)\n (:export #:minf #:maxf #:mulf #:divf #:iorf #:xorf #:andf))\n(in-package :cp/modify-macro)\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/modify-macro :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/sliding-window :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/symmetric-group :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (ps (make-array n :element-type 'fixnum :initial-element 0))\n (cs (make-array n :element-type 'fixnum :initial-element 0))\n (res most-negative-fixnum))\n (dotimes (i n)\n (setf (aref ps i) (- (read-fixnum) 1)))\n (dotimes (i n)\n (setf (aref cs i) (read-fixnum)))\n (let ((cycles (decompose-to-cycles ps)))\n (dolist (cycle cycles)\n (let* ((len (length cycle))\n (scores (loop for p in cycle collect (aref cs p)))\n (lap-sum (reduce #'+ scores))\n (scores (concatenate '(simple-array fixnum (*)) scores scores))\n (cumuls (make-array (+ (length scores) 1) :element-type 'fixnum :initial-element 0)))\n (dotimes (i (length scores))\n (setf (aref cumuls (+ i 1))\n (+ (aref cumuls i) (aref scores i))))\n #>cycle #>cumuls\n (dotimes (i len)\n (dotimes (stride len)\n (let ((incr (- (aref cumuls (+ i stride)) (aref cumuls i)))\n (quot (floor (- k stride) len)))\n (dbg i stride incr quot)\n (unless (and (zerop stride) (zerop quot))\n (maxf res (+ (* quot lap-sum) incr)))\n (unless (zerop stride)\n (maxf res incr))))))))\n (sb-int:dovector (c cs)\n (maxf res c))\n (println res)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"8\n\"\n (run \"5 2\n2 4 5 1 3\n3 4 -10 -8 8\n\" nil)))\n (it.bese.fiveam:is\n (equal \"13\n\"\n (run \"2 3\n2 1\n10 -7\n\" nil)))\n (it.bese.fiveam:is\n (equal \"-1000\n\"\n (run \"3 3\n3 1 2\n-1000 -2000 -3000\n\" nil)))\n (it.bese.fiveam:is\n (equal \"29507023469\n\"\n (run \"10 58\n9 1 6 7 8 4 3 2 10 5\n695279662 988782657 -119067776 382975538 -151885171 -177220596 -169777795 37619092 389386780 980092719\n\" nil))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nTakahashi will play a game using a piece on an array of squares numbered 1, 2, \\cdots, N. Square i has an integer C_i written on it. Also, he is given a permutation of 1, 2, \\cdots, N: P_1, P_2, \\cdots, P_N.\n\nNow, he will choose one square and place the piece on that square. Then, he will make the following move some number of times between 1 and K (inclusive):\n\nIn one move, if the piece is now on Square i (1 \\leq i \\leq N), move it to Square P_i. Here, his score increases by C_{P_i}.\n\nHelp him by finding the maximum possible score at the end of the game. (The score is 0 at the beginning of the game.)\n\nConstraints\n\n2 \\leq N \\leq 5000\n\n1 \\leq K \\leq 10^9\n\n1 \\leq P_i \\leq N\n\nP_i \\neq i\n\nP_1, P_2, \\cdots, P_N are all different.\n\n-10^9 \\leq C_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nP_1 P_2 \\cdots P_N\nC_1 C_2 \\cdots C_N\n\nOutput\n\nPrint the maximum possible score at the end of the game.\n\nSample Input 1\n\n5 2\n2 4 5 1 3\n3 4 -10 -8 8\n\nSample Output 1\n\n8\n\nWhen we start at some square of our choice and make at most two moves, we have the following options:\n\nIf we start at Square 1, making one move sends the piece to Square 2, after which the score is 4. Making another move sends the piece to Square 4, after which the score is 4 + (-8) = -4.\n\nIf we start at Square 2, making one move sends the piece to Square 4, after which the score is -8. Making another move sends the piece to Square 1, after which the score is -8 + 3 = -5.\n\nIf we start at Square 3, making one move sends the piece to Square 5, after which the score is 8. Making another move sends the piece to Square 3, after which the score is 8 + (-10) = -2.\n\nIf we start at Square 4, making one move sends the piece to Square 1, after which the score is 3. Making another move sends the piece to Square 2, after which the score is 3 + 4 = 7.\n\nIf we start at Square 5, making one move sends the piece to Square 3, after which the score is -10. Making another move sends the piece to Square 5, after which the score is -10 + 8 = -2.\n\nThe maximum score achieved is 8.\n\nSample Input 2\n\n2 3\n2 1\n10 -7\n\nSample Output 2\n\n13\n\nSample Input 3\n\n3 3\n3 1 2\n-1000 -2000 -3000\n\nSample Output 3\n\n-1000\n\nWe have to make at least one move.\n\nSample Input 4\n\n10 58\n9 1 6 7 8 4 3 2 10 5\n695279662 988782657 -119067776 382975538 -151885171 -177220596 -169777795 37619092 389386780 980092719\n\nSample Output 4\n\n29507023469\n\nThe absolute value of the answer may be enormous.", "sample_input": "5 2\n2 4 5 1 3\n3 4 -10 -8 8\n"}, "reference_outputs": ["8\n"], "source_document_id": "p02585", "source_text": "Score : 400 points\n\nProblem Statement\n\nTakahashi will play a game using a piece on an array of squares numbered 1, 2, \\cdots, N. Square i has an integer C_i written on it. Also, he is given a permutation of 1, 2, \\cdots, N: P_1, P_2, \\cdots, P_N.\n\nNow, he will choose one square and place the piece on that square. Then, he will make the following move some number of times between 1 and K (inclusive):\n\nIn one move, if the piece is now on Square i (1 \\leq i \\leq N), move it to Square P_i. Here, his score increases by C_{P_i}.\n\nHelp him by finding the maximum possible score at the end of the game. (The score is 0 at the beginning of the game.)\n\nConstraints\n\n2 \\leq N \\leq 5000\n\n1 \\leq K \\leq 10^9\n\n1 \\leq P_i \\leq N\n\nP_i \\neq i\n\nP_1, P_2, \\cdots, P_N are all different.\n\n-10^9 \\leq C_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nP_1 P_2 \\cdots P_N\nC_1 C_2 \\cdots C_N\n\nOutput\n\nPrint the maximum possible score at the end of the game.\n\nSample Input 1\n\n5 2\n2 4 5 1 3\n3 4 -10 -8 8\n\nSample Output 1\n\n8\n\nWhen we start at some square of our choice and make at most two moves, we have the following options:\n\nIf we start at Square 1, making one move sends the piece to Square 2, after which the score is 4. Making another move sends the piece to Square 4, after which the score is 4 + (-8) = -4.\n\nIf we start at Square 2, making one move sends the piece to Square 4, after which the score is -8. Making another move sends the piece to Square 1, after which the score is -8 + 3 = -5.\n\nIf we start at Square 3, making one move sends the piece to Square 5, after which the score is 8. Making another move sends the piece to Square 3, after which the score is 8 + (-10) = -2.\n\nIf we start at Square 4, making one move sends the piece to Square 1, after which the score is 3. Making another move sends the piece to Square 2, after which the score is 3 + 4 = 7.\n\nIf we start at Square 5, making one move sends the piece to Square 3, after which the score is -10. Making another move sends the piece to Square 5, after which the score is -10 + 8 = -2.\n\nThe maximum score achieved is 8.\n\nSample Input 2\n\n2 3\n2 1\n10 -7\n\nSample Output 2\n\n13\n\nSample Input 3\n\n3 3\n3 1 2\n-1000 -2000 -3000\n\nSample Output 3\n\n-1000\n\nWe have to make at least one move.\n\nSample Input 4\n\n10 58\n9 1 6 7 8 4 3 2 10 5\n695279662 988782657 -119067776 382975538 -151885171 -177220596 -169777795 37619092 389386780 980092719\n\nSample Output 4\n\n29507023469\n\nThe absolute value of the answer may be enormous.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 13555, "cpu_time_ms": 639, "memory_kb": 26172}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s058168081", "group_id": "codeNet:p02586", "input_text": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum+))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values (unsigned-byte 31) &optional)) read-fixnum+))\n(defun read-fixnum+ (&optional (in *standard-input*))\n (declare #.cl-user::opt\n (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((result (loop (let ((byte (%read-byte)))\n (when (<= 48 byte)\n (return (- byte 48)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return result)))))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.cl-user::opt)\n (let* ((r (read))\n (c (read))\n (k (read))\n (plan (make-array '(3001 3001) :element-type 'uint31 :initial-element 0))\n (dp0 (sb-int:make-static-vector 3001 :element-type 'uint62 :initial-element 0))\n (dp1 (sb-int:make-static-vector 3001 :element-type 'uint62 :initial-element 0))\n (dp2 (sb-int:make-static-vector 3001 :element-type 'uint62 :initial-element 0))\n (dp3 (sb-int:make-static-vector 3001 :element-type 'uint62 :initial-element 0)))\n (declare (uint31 r c k)\n ((simple-array uint62 (*)) dp0 dp1 dp2 dp3))\n (dotimes (i k)\n (let ((r (read-fixnum+))\n (c (read-fixnum+))\n (v (read-fixnum+)))\n (setf (aref plan r c) v)))\n (loop for i from 1 to r\n do (loop for j from 1 to c\n for v = (aref plan i j)\n do (setf (aref dp0 j) (max (aref dp3 j)\n (aref dp0 (- j 1))))\n (setf (aref dp1 j) (max (aref dp0 j)\n (aref dp1 (- j 1))\n (+ v (aref dp3 j))\n (+ v (aref dp0 (- j 1)))))\n (setf (aref dp2 j) (max (aref dp1 j)\n (aref dp2 (- j 1))\n (+ v (aref dp1 (- j 1)))))\n (setf (aref dp3 j) (max (aref dp2 j)\n (aref dp3 (- j 1))\n (+ v (aref dp2 (- j 1)))))))\n (println (aref dp3 c))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"8\n\"\n (run \"2 2 3\n1 1 3\n2 1 4\n1 2 5\n\" nil)))\n (it.bese.fiveam:is\n (equal \"29\n\"\n (run \"2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2\n\" nil)))\n (it.bese.fiveam:is\n (equal \"142\n\"\n (run \"4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1597579935, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02586.html", "problem_id": "p02586", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02586/input.txt", "sample_output_relpath": "derived/input_output/data/p02586/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02586/Lisp/s058168081.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s058168081", "user_id": "u352600849"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum+))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values (unsigned-byte 31) &optional)) read-fixnum+))\n(defun read-fixnum+ (&optional (in *standard-input*))\n (declare #.cl-user::opt\n (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((result (loop (let ((byte (%read-byte)))\n (when (<= 48 byte)\n (return (- byte 48)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return result)))))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.cl-user::opt)\n (let* ((r (read))\n (c (read))\n (k (read))\n (plan (make-array '(3001 3001) :element-type 'uint31 :initial-element 0))\n (dp0 (sb-int:make-static-vector 3001 :element-type 'uint62 :initial-element 0))\n (dp1 (sb-int:make-static-vector 3001 :element-type 'uint62 :initial-element 0))\n (dp2 (sb-int:make-static-vector 3001 :element-type 'uint62 :initial-element 0))\n (dp3 (sb-int:make-static-vector 3001 :element-type 'uint62 :initial-element 0)))\n (declare (uint31 r c k)\n ((simple-array uint62 (*)) dp0 dp1 dp2 dp3))\n (dotimes (i k)\n (let ((r (read-fixnum+))\n (c (read-fixnum+))\n (v (read-fixnum+)))\n (setf (aref plan r c) v)))\n (loop for i from 1 to r\n do (loop for j from 1 to c\n for v = (aref plan i j)\n do (setf (aref dp0 j) (max (aref dp3 j)\n (aref dp0 (- j 1))))\n (setf (aref dp1 j) (max (aref dp0 j)\n (aref dp1 (- j 1))\n (+ v (aref dp3 j))\n (+ v (aref dp0 (- j 1)))))\n (setf (aref dp2 j) (max (aref dp1 j)\n (aref dp2 (- j 1))\n (+ v (aref dp1 (- j 1)))))\n (setf (aref dp3 j) (max (aref dp2 j)\n (aref dp3 (- j 1))\n (+ v (aref dp2 (- j 1)))))))\n (println (aref dp3 c))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"8\n\"\n (run \"2 2 3\n1 1 3\n2 1 4\n1 2 5\n\" nil)))\n (it.bese.fiveam:is\n (equal \"29\n\"\n (run \"2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2\n\" nil)))\n (it.bese.fiveam:is\n (equal \"142\n\"\n (run \"4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10\n\" nil))))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \\leq i \\leq R) and the j-th column (1 \\leq j \\leq C). The i-th item is at (r_i, c_i) and has the value v_i.\n\nTakahashi will begin at (1, 1), the start, and get to (R, C), the goal. When he is at (i, j), he can move to (i + 1, j) or (i, j + 1) (but cannot move to a non-existent square).\n\nHe can pick up items on the squares he visits, including the start and the goal, but at most three for each row. It is allowed to ignore the item on a square he visits.\n\nFind the maximum possible sum of the values of items he picks up.\n\nConstraints\n\n1 \\leq R, C \\leq 3000\n\n1 \\leq K \\leq \\min(2 \\times 10^5, R \\times C)\n\n1 \\leq r_i \\leq R\n\n1 \\leq c_i \\leq C\n\n(r_i, c_i) \\neq (r_j, c_j) (i \\neq j)\n\n1 \\leq v_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR C K\nr_1 c_1 v_1\nr_2 c_2 v_2\n:\nr_K c_K v_K\n\nOutput\n\nPrint the maximum possible sum of the values of items Takahashi picks up.\n\nSample Input 1\n\n2 2 3\n1 1 3\n2 1 4\n1 2 5\n\nSample Output 1\n\n8\n\nHe has two ways to get to the goal:\n\nVisit (1, 1), (1, 2), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 5 = 8.\n\nVisit (1, 1), (2, 1), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 4 = 7.\n\nThus, the maximum possible sum of the values of items he picks up is 8.\n\nSample Input 2\n\n2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2\n\nSample Output 2\n\n29\n\nWe have four items in the 1-st row. The optimal choices are as follows:\n\nVisit (1, 1) (1, 2), (1, 3), (1, 4), (2, 4), and (2, 5), in this order, and pick up all items except the one on (1, 2). Then, the total value of the items he picks up will be 3 + 4 + 2 + 20 = 29.\n\nSample Input 3\n\n4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10\n\nSample Output 3\n\n142", "sample_input": "2 2 3\n1 1 3\n2 1 4\n1 2 5\n"}, "reference_outputs": ["8\n"], "source_document_id": "p02586", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \\leq i \\leq R) and the j-th column (1 \\leq j \\leq C). The i-th item is at (r_i, c_i) and has the value v_i.\n\nTakahashi will begin at (1, 1), the start, and get to (R, C), the goal. When he is at (i, j), he can move to (i + 1, j) or (i, j + 1) (but cannot move to a non-existent square).\n\nHe can pick up items on the squares he visits, including the start and the goal, but at most three for each row. It is allowed to ignore the item on a square he visits.\n\nFind the maximum possible sum of the values of items he picks up.\n\nConstraints\n\n1 \\leq R, C \\leq 3000\n\n1 \\leq K \\leq \\min(2 \\times 10^5, R \\times C)\n\n1 \\leq r_i \\leq R\n\n1 \\leq c_i \\leq C\n\n(r_i, c_i) \\neq (r_j, c_j) (i \\neq j)\n\n1 \\leq v_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR C K\nr_1 c_1 v_1\nr_2 c_2 v_2\n:\nr_K c_K v_K\n\nOutput\n\nPrint the maximum possible sum of the values of items Takahashi picks up.\n\nSample Input 1\n\n2 2 3\n1 1 3\n2 1 4\n1 2 5\n\nSample Output 1\n\n8\n\nHe has two ways to get to the goal:\n\nVisit (1, 1), (1, 2), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 5 = 8.\n\nVisit (1, 1), (2, 1), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 4 = 7.\n\nThus, the maximum possible sum of the values of items he picks up is 8.\n\nSample Input 2\n\n2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2\n\nSample Output 2\n\n29\n\nWe have four items in the 1-st row. The optimal choices are as follows:\n\nVisit (1, 1) (1, 2), (1, 3), (1, 4), (2, 4), and (2, 5), in this order, and pick up all items except the one on (1, 2). Then, the total value of the items he picks up will be 3 + 4 + 2 + 20 = 29.\n\nSample Input 3\n\n4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10\n\nSample Output 3\n\n142", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6113, "cpu_time_ms": 157, "memory_kb": 60188}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s250533466", "group_id": "codeNet:p02586", "input_text": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum+))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values (unsigned-byte 31) &optional)) read-fixnum+))\n(defun read-fixnum+ (&optional (in *standard-input*))\n (declare #.cl-user::opt\n (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((result (loop (let ((byte (%read-byte)))\n (when (<= 48 byte)\n (return (- byte 48)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return result)))))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.cl-user::opt)\n (let* ((r (read))\n (c (read))\n (k (read))\n (plan (make-array '(3001 3001) :element-type 'uint31 :initial-element 0))\n (dp0 (make-array 3001 :element-type 'uint62 :initial-element 0))\n (dp1 (make-array 3001 :element-type 'uint62 :initial-element 0))\n (dp2 (make-array 3001 :element-type 'uint62 :initial-element 0))\n (dp3 (make-array 3001 :element-type 'uint62 :initial-element 0)))\n (declare (uint31 r c k))\n (dotimes (i k)\n (let ((r (read-fixnum+))\n (c (read-fixnum+))\n (v (read-fixnum+)))\n (setf (aref plan r c) v)))\n (loop for i from 1 to r\n do (loop for j from 1 to c\n for v = (aref plan i j)\n do (setf (aref dp0 j) (max (aref dp3 j)\n (aref dp0 (- j 1))))\n (setf (aref dp1 j) (max (aref dp0 j)\n (aref dp1 (- j 1))\n (+ v (aref dp3 j))\n (+ v (aref dp0 (- j 1)))))\n (setf (aref dp2 j) (max (aref dp1 j)\n (aref dp2 (- j 1))\n (+ v (aref dp1 (- j 1)))))\n (setf (aref dp3 j) (max (aref dp2 j)\n (aref dp3 (- j 1))\n (+ v (aref dp2 (- j 1)))))))\n (println (aref dp3 c))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"8\n\"\n (run \"2 2 3\n1 1 3\n2 1 4\n1 2 5\n\" nil)))\n (it.bese.fiveam:is\n (equal \"29\n\"\n (run \"2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2\n\" nil)))\n (it.bese.fiveam:is\n (equal \"142\n\"\n (run \"4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1597579793, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02586.html", "problem_id": "p02586", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02586/input.txt", "sample_output_relpath": "derived/input_output/data/p02586/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02586/Lisp/s250533466.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s250533466", "user_id": "u352600849"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum+))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values (unsigned-byte 31) &optional)) read-fixnum+))\n(defun read-fixnum+ (&optional (in *standard-input*))\n (declare #.cl-user::opt\n (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((result (loop (let ((byte (%read-byte)))\n (when (<= 48 byte)\n (return (- byte 48)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return result)))))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.cl-user::opt)\n (let* ((r (read))\n (c (read))\n (k (read))\n (plan (make-array '(3001 3001) :element-type 'uint31 :initial-element 0))\n (dp0 (make-array 3001 :element-type 'uint62 :initial-element 0))\n (dp1 (make-array 3001 :element-type 'uint62 :initial-element 0))\n (dp2 (make-array 3001 :element-type 'uint62 :initial-element 0))\n (dp3 (make-array 3001 :element-type 'uint62 :initial-element 0)))\n (declare (uint31 r c k))\n (dotimes (i k)\n (let ((r (read-fixnum+))\n (c (read-fixnum+))\n (v (read-fixnum+)))\n (setf (aref plan r c) v)))\n (loop for i from 1 to r\n do (loop for j from 1 to c\n for v = (aref plan i j)\n do (setf (aref dp0 j) (max (aref dp3 j)\n (aref dp0 (- j 1))))\n (setf (aref dp1 j) (max (aref dp0 j)\n (aref dp1 (- j 1))\n (+ v (aref dp3 j))\n (+ v (aref dp0 (- j 1)))))\n (setf (aref dp2 j) (max (aref dp1 j)\n (aref dp2 (- j 1))\n (+ v (aref dp1 (- j 1)))))\n (setf (aref dp3 j) (max (aref dp2 j)\n (aref dp3 (- j 1))\n (+ v (aref dp2 (- j 1)))))))\n (println (aref dp3 c))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"8\n\"\n (run \"2 2 3\n1 1 3\n2 1 4\n1 2 5\n\" nil)))\n (it.bese.fiveam:is\n (equal \"29\n\"\n (run \"2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2\n\" nil)))\n (it.bese.fiveam:is\n (equal \"142\n\"\n (run \"4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10\n\" nil))))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \\leq i \\leq R) and the j-th column (1 \\leq j \\leq C). The i-th item is at (r_i, c_i) and has the value v_i.\n\nTakahashi will begin at (1, 1), the start, and get to (R, C), the goal. When he is at (i, j), he can move to (i + 1, j) or (i, j + 1) (but cannot move to a non-existent square).\n\nHe can pick up items on the squares he visits, including the start and the goal, but at most three for each row. It is allowed to ignore the item on a square he visits.\n\nFind the maximum possible sum of the values of items he picks up.\n\nConstraints\n\n1 \\leq R, C \\leq 3000\n\n1 \\leq K \\leq \\min(2 \\times 10^5, R \\times C)\n\n1 \\leq r_i \\leq R\n\n1 \\leq c_i \\leq C\n\n(r_i, c_i) \\neq (r_j, c_j) (i \\neq j)\n\n1 \\leq v_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR C K\nr_1 c_1 v_1\nr_2 c_2 v_2\n:\nr_K c_K v_K\n\nOutput\n\nPrint the maximum possible sum of the values of items Takahashi picks up.\n\nSample Input 1\n\n2 2 3\n1 1 3\n2 1 4\n1 2 5\n\nSample Output 1\n\n8\n\nHe has two ways to get to the goal:\n\nVisit (1, 1), (1, 2), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 5 = 8.\n\nVisit (1, 1), (2, 1), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 4 = 7.\n\nThus, the maximum possible sum of the values of items he picks up is 8.\n\nSample Input 2\n\n2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2\n\nSample Output 2\n\n29\n\nWe have four items in the 1-st row. The optimal choices are as follows:\n\nVisit (1, 1) (1, 2), (1, 3), (1, 4), (2, 4), and (2, 5), in this order, and pick up all items except the one on (1, 2). Then, the total value of the items he picks up will be 3 + 4 + 2 + 20 = 29.\n\nSample Input 3\n\n4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10\n\nSample Output 3\n\n142", "sample_input": "2 2 3\n1 1 3\n2 1 4\n1 2 5\n"}, "reference_outputs": ["8\n"], "source_document_id": "p02586", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \\leq i \\leq R) and the j-th column (1 \\leq j \\leq C). The i-th item is at (r_i, c_i) and has the value v_i.\n\nTakahashi will begin at (1, 1), the start, and get to (R, C), the goal. When he is at (i, j), he can move to (i + 1, j) or (i, j + 1) (but cannot move to a non-existent square).\n\nHe can pick up items on the squares he visits, including the start and the goal, but at most three for each row. It is allowed to ignore the item on a square he visits.\n\nFind the maximum possible sum of the values of items he picks up.\n\nConstraints\n\n1 \\leq R, C \\leq 3000\n\n1 \\leq K \\leq \\min(2 \\times 10^5, R \\times C)\n\n1 \\leq r_i \\leq R\n\n1 \\leq c_i \\leq C\n\n(r_i, c_i) \\neq (r_j, c_j) (i \\neq j)\n\n1 \\leq v_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR C K\nr_1 c_1 v_1\nr_2 c_2 v_2\n:\nr_K c_K v_K\n\nOutput\n\nPrint the maximum possible sum of the values of items Takahashi picks up.\n\nSample Input 1\n\n2 2 3\n1 1 3\n2 1 4\n1 2 5\n\nSample Output 1\n\n8\n\nHe has two ways to get to the goal:\n\nVisit (1, 1), (1, 2), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 5 = 8.\n\nVisit (1, 1), (2, 1), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 4 = 7.\n\nThus, the maximum possible sum of the values of items he picks up is 8.\n\nSample Input 2\n\n2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2\n\nSample Output 2\n\n29\n\nWe have four items in the 1-st row. The optimal choices are as follows:\n\nVisit (1, 1) (1, 2), (1, 3), (1, 4), (2, 4), and (2, 5), in this order, and pick up all items except the one on (1, 2). Then, the total value of the items he picks up will be 3 + 4 + 2 + 20 = 29.\n\nSample Input 3\n\n4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10\n\nSample Output 3\n\n142", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5996, "cpu_time_ms": 171, "memory_kb": 60064}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s930655471", "group_id": "codeNet:p02586", "input_text": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.cl-user::opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.cl-user::opt)\n (let* ((r (read))\n (c (read))\n (k (read))\n (plan (make-array '(3001 3001) :element-type 'uint31 :initial-element 0))\n (dp0 (make-array 3001 :element-type 'uint62 :initial-element 0))\n (dp1 (make-array 3001 :element-type 'uint62 :initial-element 0))\n (dp2 (make-array 3001 :element-type 'uint62 :initial-element 0))\n (dp3 (make-array 3001 :element-type 'uint62 :initial-element 0)))\n (declare (uint31 r c k))\n (dotimes (i k)\n (let ((r (read-fixnum))\n (c (read-fixnum))\n (v (read-fixnum)))\n (setf (aref plan r c) v)))\n (loop for i from 1 to r\n do (loop for j from 1 to c\n for v = (aref plan i j)\n do (setf (aref dp0 j) (max (aref dp3 j)\n (aref dp0 (- j 1))))\n (setf (aref dp1 j) (max (aref dp0 j)\n (aref dp1 (- j 1))\n (+ v (aref dp3 j))\n (+ v (aref dp0 (- j 1)))))\n (setf (aref dp2 j) (max (aref dp1 j)\n (aref dp2 (- j 1))\n (+ v (aref dp1 (- j 1)))))\n (setf (aref dp3 j) (max (aref dp2 j)\n (aref dp3 (- j 1))\n (+ v (aref dp2 (- j 1)))))))\n (println (aref dp3 c))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"8\n\"\n (run \"2 2 3\n1 1 3\n2 1 4\n1 2 5\n\" nil)))\n (it.bese.fiveam:is\n (equal \"29\n\"\n (run \"2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2\n\" nil)))\n (it.bese.fiveam:is\n (equal \"142\n\"\n (run \"4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1597570402, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02586.html", "problem_id": "p02586", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02586/input.txt", "sample_output_relpath": "derived/input_output/data/p02586/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02586/Lisp/s930655471.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s930655471", "user_id": "u352600849"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.cl-user::opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.cl-user::opt)\n (let* ((r (read))\n (c (read))\n (k (read))\n (plan (make-array '(3001 3001) :element-type 'uint31 :initial-element 0))\n (dp0 (make-array 3001 :element-type 'uint62 :initial-element 0))\n (dp1 (make-array 3001 :element-type 'uint62 :initial-element 0))\n (dp2 (make-array 3001 :element-type 'uint62 :initial-element 0))\n (dp3 (make-array 3001 :element-type 'uint62 :initial-element 0)))\n (declare (uint31 r c k))\n (dotimes (i k)\n (let ((r (read-fixnum))\n (c (read-fixnum))\n (v (read-fixnum)))\n (setf (aref plan r c) v)))\n (loop for i from 1 to r\n do (loop for j from 1 to c\n for v = (aref plan i j)\n do (setf (aref dp0 j) (max (aref dp3 j)\n (aref dp0 (- j 1))))\n (setf (aref dp1 j) (max (aref dp0 j)\n (aref dp1 (- j 1))\n (+ v (aref dp3 j))\n (+ v (aref dp0 (- j 1)))))\n (setf (aref dp2 j) (max (aref dp1 j)\n (aref dp2 (- j 1))\n (+ v (aref dp1 (- j 1)))))\n (setf (aref dp3 j) (max (aref dp2 j)\n (aref dp3 (- j 1))\n (+ v (aref dp2 (- j 1)))))))\n (println (aref dp3 c))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"8\n\"\n (run \"2 2 3\n1 1 3\n2 1 4\n1 2 5\n\" nil)))\n (it.bese.fiveam:is\n (equal \"29\n\"\n (run \"2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2\n\" nil)))\n (it.bese.fiveam:is\n (equal \"142\n\"\n (run \"4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10\n\" nil))))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \\leq i \\leq R) and the j-th column (1 \\leq j \\leq C). The i-th item is at (r_i, c_i) and has the value v_i.\n\nTakahashi will begin at (1, 1), the start, and get to (R, C), the goal. When he is at (i, j), he can move to (i + 1, j) or (i, j + 1) (but cannot move to a non-existent square).\n\nHe can pick up items on the squares he visits, including the start and the goal, but at most three for each row. It is allowed to ignore the item on a square he visits.\n\nFind the maximum possible sum of the values of items he picks up.\n\nConstraints\n\n1 \\leq R, C \\leq 3000\n\n1 \\leq K \\leq \\min(2 \\times 10^5, R \\times C)\n\n1 \\leq r_i \\leq R\n\n1 \\leq c_i \\leq C\n\n(r_i, c_i) \\neq (r_j, c_j) (i \\neq j)\n\n1 \\leq v_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR C K\nr_1 c_1 v_1\nr_2 c_2 v_2\n:\nr_K c_K v_K\n\nOutput\n\nPrint the maximum possible sum of the values of items Takahashi picks up.\n\nSample Input 1\n\n2 2 3\n1 1 3\n2 1 4\n1 2 5\n\nSample Output 1\n\n8\n\nHe has two ways to get to the goal:\n\nVisit (1, 1), (1, 2), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 5 = 8.\n\nVisit (1, 1), (2, 1), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 4 = 7.\n\nThus, the maximum possible sum of the values of items he picks up is 8.\n\nSample Input 2\n\n2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2\n\nSample Output 2\n\n29\n\nWe have four items in the 1-st row. The optimal choices are as follows:\n\nVisit (1, 1) (1, 2), (1, 3), (1, 4), (2, 4), and (2, 5), in this order, and pick up all items except the one on (1, 2). Then, the total value of the items he picks up will be 3 + 4 + 2 + 20 = 29.\n\nSample Input 3\n\n4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10\n\nSample Output 3\n\n142", "sample_input": "2 2 3\n1 1 3\n2 1 4\n1 2 5\n"}, "reference_outputs": ["8\n"], "source_document_id": "p02586", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \\leq i \\leq R) and the j-th column (1 \\leq j \\leq C). The i-th item is at (r_i, c_i) and has the value v_i.\n\nTakahashi will begin at (1, 1), the start, and get to (R, C), the goal. When he is at (i, j), he can move to (i + 1, j) or (i, j + 1) (but cannot move to a non-existent square).\n\nHe can pick up items on the squares he visits, including the start and the goal, but at most three for each row. It is allowed to ignore the item on a square he visits.\n\nFind the maximum possible sum of the values of items he picks up.\n\nConstraints\n\n1 \\leq R, C \\leq 3000\n\n1 \\leq K \\leq \\min(2 \\times 10^5, R \\times C)\n\n1 \\leq r_i \\leq R\n\n1 \\leq c_i \\leq C\n\n(r_i, c_i) \\neq (r_j, c_j) (i \\neq j)\n\n1 \\leq v_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR C K\nr_1 c_1 v_1\nr_2 c_2 v_2\n:\nr_K c_K v_K\n\nOutput\n\nPrint the maximum possible sum of the values of items Takahashi picks up.\n\nSample Input 1\n\n2 2 3\n1 1 3\n2 1 4\n1 2 5\n\nSample Output 1\n\n8\n\nHe has two ways to get to the goal:\n\nVisit (1, 1), (1, 2), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 5 = 8.\n\nVisit (1, 1), (2, 1), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 4 = 7.\n\nThus, the maximum possible sum of the values of items he picks up is 8.\n\nSample Input 2\n\n2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2\n\nSample Output 2\n\n29\n\nWe have four items in the 1-st row. The optimal choices are as follows:\n\nVisit (1, 1) (1, 2), (1, 3), (1, 4), (2, 4), and (2, 5), in this order, and pick up all items except the one on (1, 2). Then, the total value of the items he picks up will be 3 + 4 + 2 + 20 = 29.\n\nSample Input 3\n\n4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10\n\nSample Output 3\n\n142", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6256, "cpu_time_ms": 175, "memory_kb": 60040}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s051163916", "group_id": "codeNet:p02586", "input_text": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.cl-user::opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defpackage :cp/modify-macro\n (:use :cl)\n (:export #:minf #:maxf #:mulf #:divf #:iorf #:xorf #:andf))\n(in-package :cp/modify-macro)\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/modify-macro :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.cl-user::opt)\n (let* ((r (read))\n (c (read))\n (k (read))\n (plan (make-array '(3000 3000) :element-type 'uint31 :initial-element 0))\n (dp (make-array '(3000 4) :element-type 'uint62 :initial-element 0)))\n (declare (uint31 r c k))\n (dotimes (i k)\n (let ((r (- (read-fixnum) 1))\n (c (- (read-fixnum) 1))\n (v (read-fixnum)))\n (setf (aref plan r c) v)))\n (setf (aref dp 0 1) (aref plan 0 0))\n (dotimes (i r)\n (dotimes (j c)\n (let ((v (aref plan i j)))\n (dotimes (num 4)\n (when (> num 0)\n (maxf (aref dp j num) (aref dp j (- num 1))))\n (cond ((= num 0)\n (maxf (aref dp j 0) (aref dp j 3)))\n ((= num 1)\n (maxf (aref dp j 1) (+ v (aref dp j 3)))))\n (when (> j 0)\n (when (> num 0)\n (maxf (aref dp j num)\n (+ v (aref dp (- j 1) (- num 1)))))\n (maxf (aref dp j num) (aref dp (- j 1) num)))))))\n (println (aref dp (- c 1) 3))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"8\n\"\n (run \"2 2 3\n1 1 3\n2 1 4\n1 2 5\n\" nil)))\n (it.bese.fiveam:is\n (equal \"29\n\"\n (run \"2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2\n\" nil)))\n (it.bese.fiveam:is\n (equal \"142\n\"\n (run \"4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1597569314, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02586.html", "problem_id": "p02586", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02586/input.txt", "sample_output_relpath": "derived/input_output/data/p02586/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02586/Lisp/s051163916.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s051163916", "user_id": "u352600849"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.cl-user::opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defpackage :cp/modify-macro\n (:use :cl)\n (:export #:minf #:maxf #:mulf #:divf #:iorf #:xorf #:andf))\n(in-package :cp/modify-macro)\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/modify-macro :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.cl-user::opt)\n (let* ((r (read))\n (c (read))\n (k (read))\n (plan (make-array '(3000 3000) :element-type 'uint31 :initial-element 0))\n (dp (make-array '(3000 4) :element-type 'uint62 :initial-element 0)))\n (declare (uint31 r c k))\n (dotimes (i k)\n (let ((r (- (read-fixnum) 1))\n (c (- (read-fixnum) 1))\n (v (read-fixnum)))\n (setf (aref plan r c) v)))\n (setf (aref dp 0 1) (aref plan 0 0))\n (dotimes (i r)\n (dotimes (j c)\n (let ((v (aref plan i j)))\n (dotimes (num 4)\n (when (> num 0)\n (maxf (aref dp j num) (aref dp j (- num 1))))\n (cond ((= num 0)\n (maxf (aref dp j 0) (aref dp j 3)))\n ((= num 1)\n (maxf (aref dp j 1) (+ v (aref dp j 3)))))\n (when (> j 0)\n (when (> num 0)\n (maxf (aref dp j num)\n (+ v (aref dp (- j 1) (- num 1)))))\n (maxf (aref dp j num) (aref dp (- j 1) num)))))))\n (println (aref dp (- c 1) 3))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"8\n\"\n (run \"2 2 3\n1 1 3\n2 1 4\n1 2 5\n\" nil)))\n (it.bese.fiveam:is\n (equal \"29\n\"\n (run \"2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2\n\" nil)))\n (it.bese.fiveam:is\n (equal \"142\n\"\n (run \"4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10\n\" nil))))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \\leq i \\leq R) and the j-th column (1 \\leq j \\leq C). The i-th item is at (r_i, c_i) and has the value v_i.\n\nTakahashi will begin at (1, 1), the start, and get to (R, C), the goal. When he is at (i, j), he can move to (i + 1, j) or (i, j + 1) (but cannot move to a non-existent square).\n\nHe can pick up items on the squares he visits, including the start and the goal, but at most three for each row. It is allowed to ignore the item on a square he visits.\n\nFind the maximum possible sum of the values of items he picks up.\n\nConstraints\n\n1 \\leq R, C \\leq 3000\n\n1 \\leq K \\leq \\min(2 \\times 10^5, R \\times C)\n\n1 \\leq r_i \\leq R\n\n1 \\leq c_i \\leq C\n\n(r_i, c_i) \\neq (r_j, c_j) (i \\neq j)\n\n1 \\leq v_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR C K\nr_1 c_1 v_1\nr_2 c_2 v_2\n:\nr_K c_K v_K\n\nOutput\n\nPrint the maximum possible sum of the values of items Takahashi picks up.\n\nSample Input 1\n\n2 2 3\n1 1 3\n2 1 4\n1 2 5\n\nSample Output 1\n\n8\n\nHe has two ways to get to the goal:\n\nVisit (1, 1), (1, 2), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 5 = 8.\n\nVisit (1, 1), (2, 1), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 4 = 7.\n\nThus, the maximum possible sum of the values of items he picks up is 8.\n\nSample Input 2\n\n2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2\n\nSample Output 2\n\n29\n\nWe have four items in the 1-st row. The optimal choices are as follows:\n\nVisit (1, 1) (1, 2), (1, 3), (1, 4), (2, 4), and (2, 5), in this order, and pick up all items except the one on (1, 2). Then, the total value of the items he picks up will be 3 + 4 + 2 + 20 = 29.\n\nSample Input 3\n\n4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10\n\nSample Output 3\n\n142", "sample_input": "2 2 3\n1 1 3\n2 1 4\n1 2 5\n"}, "reference_outputs": ["8\n"], "source_document_id": "p02586", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \\leq i \\leq R) and the j-th column (1 \\leq j \\leq C). The i-th item is at (r_i, c_i) and has the value v_i.\n\nTakahashi will begin at (1, 1), the start, and get to (R, C), the goal. When he is at (i, j), he can move to (i + 1, j) or (i, j + 1) (but cannot move to a non-existent square).\n\nHe can pick up items on the squares he visits, including the start and the goal, but at most three for each row. It is allowed to ignore the item on a square he visits.\n\nFind the maximum possible sum of the values of items he picks up.\n\nConstraints\n\n1 \\leq R, C \\leq 3000\n\n1 \\leq K \\leq \\min(2 \\times 10^5, R \\times C)\n\n1 \\leq r_i \\leq R\n\n1 \\leq c_i \\leq C\n\n(r_i, c_i) \\neq (r_j, c_j) (i \\neq j)\n\n1 \\leq v_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR C K\nr_1 c_1 v_1\nr_2 c_2 v_2\n:\nr_K c_K v_K\n\nOutput\n\nPrint the maximum possible sum of the values of items Takahashi picks up.\n\nSample Input 1\n\n2 2 3\n1 1 3\n2 1 4\n1 2 5\n\nSample Output 1\n\n8\n\nHe has two ways to get to the goal:\n\nVisit (1, 1), (1, 2), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 5 = 8.\n\nVisit (1, 1), (2, 1), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 4 = 7.\n\nThus, the maximum possible sum of the values of items he picks up is 8.\n\nSample Input 2\n\n2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2\n\nSample Output 2\n\n29\n\nWe have four items in the 1-st row. The optimal choices are as follows:\n\nVisit (1, 1) (1, 2), (1, 3), (1, 4), (2, 4), and (2, 5), in this order, and pick up all items except the one on (1, 2). Then, the total value of the items he picks up will be 3 + 4 + 2 + 20 = 29.\n\nSample Input 3\n\n4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10\n\nSample Output 3\n\n142", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6238, "cpu_time_ms": 286, "memory_kb": 60004}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s511406562", "group_id": "codeNet:p02588", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; 2D range tree with fractional cascading\n;;;\n;;; build: O(nlog(n))\n;;; query: O(log(n))\n;;;\n;;; Reference:\n;;; Mark de Berg et al., Computational Geometry: Algorithms and Applications, 3rd Edition\n;;;\n\n;; TODO: introduce abelian group\n\n(defstruct (ynode (:constructor make-ynode (xkeys ykeys lpointers rpointers values cumuls))\n (:conc-name %ynode-)\n (:copier nil))\n (xkeys nil :type (simple-array fixnum (*)))\n (ykeys nil :type (simple-array fixnum (*)))\n (lpointers nil :type (or null (simple-array (integer 0 #.most-positive-fixnum) (*))))\n (rpointers nil :type (or null (simple-array (integer 0 #.most-positive-fixnum) (*))))\n (values nil :type (simple-array fixnum (*)))\n (cumuls nil :type (or null (simple-array fixnum (*)))))\n\n(defstruct (xnode (:constructor make-xnode (xkey ynode left right))\n (:conc-name %xnode-)\n (:copier nil))\n (xkey 0 :type fixnum)\n (ynode nil :type ynode)\n (left nil :type (or null xnode))\n (right nil :type (or null xnode)))\n\n(defun %ynode-merge (ynode1 ynode2)\n \"Merges two YNODEs non-destructively in O(n).\"\n (declare (optimize (speed 3)))\n (let* ((xkeys1 (%ynode-xkeys ynode1))\n (ykeys1 (%ynode-ykeys ynode1))\n (xkeys2 (%ynode-xkeys ynode2))\n (ykeys2 (%ynode-ykeys ynode2))\n (values1 (%ynode-values ynode1))\n (values2 (%ynode-values ynode2))\n (len1 (length xkeys1))\n (len2 (length xkeys2))\n (new-len (+ len1 len2))\n (new-xkeys (make-array new-len :element-type 'fixnum))\n (new-ykeys (make-array new-len :element-type 'fixnum))\n (new-values (make-array new-len :element-type 'fixnum))\n (new-cumuls (make-array (+ new-len 1) :element-type 'fixnum :initial-element 0))\n (lpointers (make-array (+ 1 new-len)\n :element-type '(integer 0 #.most-positive-fixnum)))\n (rpointers (make-array (+ 1 new-len)\n :element-type '(integer 0 #.most-positive-fixnum)))\n \n (new-pos 0)\n (pos1 0)\n (pos2 0))\n (declare ((integer 0 #.most-positive-fixnum) len1 len2 new-len new-pos pos1 pos2))\n ;; merge two vectors\n (loop\n (when (= pos1 len1)\n (loop\n for i from pos2 below len2\n do (setf (aref new-xkeys new-pos) (aref xkeys2 i)\n (aref new-ykeys new-pos) (aref ykeys2 i)\n (aref new-values new-pos) (aref values2 i)\n (aref lpointers new-pos) pos1\n (aref rpointers new-pos) i)\n (incf new-pos))\n (return))\n (when (= pos2 len2)\n (loop\n for i from pos1 below len1\n do (setf (aref new-xkeys new-pos) (aref xkeys1 i)\n (aref new-ykeys new-pos) (aref ykeys1 i)\n (aref new-values new-pos) (aref values1 i)\n (aref lpointers new-pos) i\n (aref rpointers new-pos) pos2)\n (incf new-pos))\n (return))\n (if (or (< (aref ykeys1 pos1) (aref ykeys2 pos2))\n (and (= (aref ykeys1 pos1) (aref ykeys2 pos2))\n (< (aref xkeys1 pos1) (aref xkeys2 pos2))))\n (setf (aref new-xkeys new-pos) (aref xkeys1 pos1)\n (aref new-ykeys new-pos) (aref ykeys1 pos1)\n (aref new-values new-pos) (aref values1 pos1)\n (aref lpointers new-pos) pos1\n (aref rpointers new-pos) pos2\n pos1 (+ pos1 1))\n (setf (aref new-xkeys new-pos) (aref xkeys2 pos2)\n (aref new-ykeys new-pos) (aref ykeys2 pos2)\n (aref new-values new-pos) (aref values2 pos2)\n (aref lpointers new-pos) pos1\n (aref rpointers new-pos) pos2\n pos2 (+ pos2 1)))\n (incf new-pos))\n (dotimes (i new-len)\n (setf (aref new-cumuls (+ i 1))\n (+ (aref new-cumuls i) (aref new-values i))))\n (setf (aref lpointers new-len) len1\n (aref rpointers new-len) len2)\n (make-ynode new-xkeys new-ykeys lpointers rpointers new-values new-cumuls)))\n\n(declaim (inline make-range-tree))\n(defun make-range-tree (points &key (xkey #'car) (ykey #'cdr) value-key)\n \"points := vector of points\n\nMakes a range tree from the points. These points must be sorted\nw.r.t. lexicographical order and must not contain duplicate points. (Duplicate\ncoordinates are allowed.) E.g. (-1, 3), (-1, 4), (-1, 7) (0, 1) (0, 3) (2,\n-1) (2, 1)).\"\n (declare (vector points))\n (when (zerop (length points))\n (return-from make-range-tree nil))\n (let ((pointers-for-leaf\n (make-array 2\n :element-type '(integer 0 #.most-positive-fixnum)\n :initial-element 0)))\n (labels\n ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= (- r l) 1)\n (let* ((point (aref points l))\n (x (funcall xkey point))\n (y (funcall ykey point))\n (value (if value-key (funcall value-key point) 0))\n (xkeys (make-array 1 :element-type 'fixnum :initial-element x))\n (ykeys (make-array 1 :element-type 'fixnum :initial-element y))\n (values (make-array 1 :element-type 'fixnum :initial-element value))\n (cumuls (make-array 2 :element-type 'fixnum :initial-element 0)))\n (setf (aref cumuls 1) value)\n (make-xnode x (make-ynode xkeys ykeys\n pointers-for-leaf\n pointers-for-leaf\n values cumuls)\n nil nil))\n (let* ((mid (ash (+ l r) -1))\n (left (build l mid))\n (right (build mid r)))\n (make-xnode (funcall xkey (aref points mid))\n (%ynode-merge (%xnode-ynode left)\n (%xnode-ynode right))\n left right)))))\n (build 0 (length points)))))\n\n(defconstant +neg-inf+ most-negative-fixnum)\n(defconstant +pos-inf+ most-positive-fixnum)\n\n(declaim (inline xleaf-p))\n(defun xleaf-p (xnode)\n (and (null (%xnode-left xnode)) (null (%xnode-right xnode))))\n\n(defun rt-count (range-tree x1 y1 x2 y2)\n \"Returns the number of the nodes within the rectangle [x1, x2)*[y1, y2). A\npart or all of these coordinates can be NIL; then they are regarded as the\nnegative or positive infinity.\"\n (declare (optimize (speed 3))\n ((or null fixnum) x1 y1 x2 y2))\n (setq x1 (or x1 +neg-inf+)\n x2 (or x2 +pos-inf+)\n y1 (or y1 +neg-inf+)\n y2 (or y2 +pos-inf+))\n (unless range-tree\n (return-from rt-count 0))\n (let* ((ynode (%xnode-ynode range-tree))\n (xkeys (%ynode-xkeys ynode))\n (ykeys (%ynode-ykeys ynode)))\n (labels ((bisect-left (y)\n (declare (fixnum y))\n (let ((left 0)\n (ok (length xkeys)))\n (declare ((integer 0 #.most-positive-fixnum) left ok))\n (loop\n (let ((mid (ash (+ left ok) -1)))\n (if (= mid left)\n (if (< (aref ykeys left) y)\n (return ok)\n (return left))\n (if (< (aref ykeys mid) y)\n (setq left mid)\n (setq ok mid)))))))\n (recur (xnode x1 x2 start end)\n (declare ((or null xnode) xnode)\n (fixnum x1 x2)\n ;; KLUDGE: declaring ftype is not sufficient for the\n ;; optimization on SBCL 1.1.14.\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (cond ((null xnode) 0)\n ((and (= x1 +neg-inf+) (= x2 +pos-inf+))\n (- end start))\n (t\n (let* ((xkey (%xnode-xkey xnode))\n (ynode (%xnode-ynode xnode))\n (lpointers (%ynode-lpointers ynode))\n (rpointers (%ynode-rpointers ynode)))\n (if (<= x1 xkey)\n (if (< xkey x2)\n ;; XKEY is in [X1, X2)\n (if (xleaf-p xnode)\n (- end start)\n (+ (recur (%xnode-left xnode)\n x1 +pos-inf+\n (aref lpointers start)\n (aref lpointers end))\n (recur (%xnode-right xnode)\n +neg-inf+ x2\n (aref rpointers start)\n (aref rpointers end))))\n ;; XKEY is in [X2, +inf)\n (recur (%xnode-left xnode)\n x1 x2\n (aref lpointers start)\n (aref lpointers end)))\n ;; XKEY is in (-inf, X1)\n (recur (%xnode-right xnode)\n x1 x2\n (aref rpointers start)\n (aref rpointers end))))))))\n (let ((start (bisect-left y1))\n (end (bisect-left y2)))\n (recur range-tree x1 x2 start end)))))\n\n(defun rt-query (range-tree x1 y1 x2 y2)\n \"Returns the sum of the values within the rectangle [x1, x2)*[y1, y2). A\npart or all of these coordinates can be NIL; then they are regarded as the\nnegative or positive infinity.\"\n (declare (optimize (speed 3))\n ((or null fixnum) x1 y1 x2 y2))\n (setq x1 (or x1 +neg-inf+)\n x2 (or x2 +pos-inf+)\n y1 (or y1 +neg-inf+)\n y2 (or y2 +pos-inf+))\n (unless range-tree\n (return-from rt-query 0))\n (let* ((ynode (%xnode-ynode range-tree))\n (xkeys (%ynode-xkeys ynode))\n (ykeys (%ynode-ykeys ynode)))\n (labels ((bisect-left (y)\n (declare (fixnum y))\n (let ((left 0)\n (ok (length xkeys)))\n (declare ((integer 0 #.most-positive-fixnum) left ok))\n (loop\n (let ((mid (ash (+ left ok) -1)))\n (if (= mid left)\n (if (< (aref ykeys left) y)\n (return ok)\n (return left))\n (if (< (aref ykeys mid) y)\n (setq left mid)\n (setq ok mid)))))))\n (recur (xnode x1 x2 start end)\n (declare ((or null xnode) xnode)\n (fixnum x1 x2)\n ;; KLUDGE: declaring ftype is not sufficient for the\n ;; optimization on SBCL 1.1.14.\n #+sbcl (values fixnum))\n (if (null xnode)\n 0\n (let* ((xkey (%xnode-xkey xnode))\n (ynode (%xnode-ynode xnode))\n (cumuls (%ynode-cumuls ynode))\n (lpointers (%ynode-lpointers ynode))\n (rpointers (%ynode-rpointers ynode)))\n (if (and (= x1 +neg-inf+) (= x2 +pos-inf+))\n (- (aref cumuls end) (aref cumuls start))\n (if (<= x1 xkey)\n (if (< xkey x2)\n ;; XKEY is in [X1, X2)\n (if (xleaf-p xnode)\n (- (aref cumuls end) (aref cumuls start))\n (+ (recur (%xnode-left xnode)\n x1 +pos-inf+\n (aref lpointers start)\n (aref lpointers end))\n (recur (%xnode-right xnode)\n +neg-inf+ x2\n (aref rpointers start)\n (aref rpointers end))))\n ;; XKEY is in [X2, +inf)\n (recur (%xnode-left xnode)\n x1 x2\n (aref lpointers start)\n (aref lpointers end)))\n ;; XKEY is in (-inf, X1)\n (recur (%xnode-right xnode)\n x1 x2\n (aref rpointers start)\n (aref rpointers end))))))))\n (let ((start (bisect-left y1))\n (end (bisect-left y2)))\n (recur range-tree x1 x2 start end)))))\n\n;; not tested\n(defun rt-map (function range-tree x1 y1 x2 y2)\n \"Applies FUNCTION to all the points within the rectangle [x1, x2)*[y1, y2).\"\n (declare (optimize (speed 3))\n ((or null fixnum) x1 y1 x2 y2)\n (function function))\n (setq x1 (or x1 +neg-inf+)\n x2 (or x2 +pos-inf+)\n y1 (or y1 +neg-inf+)\n y2 (or y2 +pos-inf+))\n (when range-tree\n (let* ((ynode (%xnode-ynode range-tree))\n (xkeys (%ynode-xkeys ynode))\n (ykeys (%ynode-ykeys ynode)))\n (labels ((bisect-left (y)\n (declare (fixnum y))\n (let ((left 0)\n (ok (length xkeys)))\n (declare ((integer 0 #.most-positive-fixnum) left ok))\n (loop\n (let ((mid (ash (+ left ok) -1)))\n (if (= mid left)\n (if (< (aref ykeys left) y)\n (return ok)\n (return left))\n (if (< (aref ykeys mid) y)\n (setq left mid)\n (setq ok mid)))))))\n (recur (xnode x1 x2 start end)\n (declare ((or null xnode) xnode)\n (fixnum x1 x2))\n (cond ((null xnode))\n ((and (= x1 +neg-inf+) (= x2 +pos-inf+))\n (loop with ynode = (%xnode-ynode xnode)\n with xkeys = (%ynode-xkeys ynode)\n with ykeys = (%ynode-ykeys ynode)\n for i from start below end\n for x = (aref xkeys i)\n for y = (aref ykeys i)\n do (funcall function x y)))\n (t\n (let* ((xkey (%xnode-xkey xnode))\n (ynode (%xnode-ynode xnode))\n (lpointers (%ynode-lpointers ynode))\n (rpointers (%ynode-rpointers ynode)))\n (if (<= x1 xkey)\n (if (< xkey x2)\n ;; XKEY is in [X1, X2)\n (if (xleaf-p xnode)\n (loop with ynode = (%xnode-ynode xnode)\n with xkeys = (%ynode-xkeys ynode)\n with ykeys = (%ynode-ykeys ynode)\n for i from start below end\n for x = (aref xkeys i)\n for y = (aref ykeys i)\n do (funcall function x y))\n (progn\n (recur (%xnode-left xnode)\n x1 +pos-inf+\n (aref lpointers start)\n (aref lpointers end))\n (recur (%xnode-right xnode)\n +neg-inf+ x2\n (aref rpointers start)\n (aref rpointers end))))\n ;; XKEY is in [X2, +inf)\n (recur (%xnode-left xnode)\n x1 x2\n (aref lpointers start)\n (aref lpointers end)))\n ;; XKEY is in (-inf, X1)\n (recur (%xnode-right xnode)\n x1 x2\n (aref rpointers start)\n (aref rpointers end))))))))\n (let ((start (bisect-left y1))\n (end (bisect-left y2)))\n (recur range-tree x1 x2 start end))))))\n\n\n;; Treap accessible by index (O(log(n))).\n;; Virtually it works like std::set of C++ or TreeSet of Java. \n\n;; Note:\n;; - You shouldn't insert duplicate keys into a treap unless you know what you\n;; are doing.\n;; - You cannot rely on the side effect when you call any destructive operations\n;; on a treap. Always use the returned value.\n;; - An empty treap is NIL.\n\n(defstruct (treap (:constructor %make-treap (key priority &key left right (count 1)))\n (:copier nil)\n (:conc-name %treap-))\n key\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 0 :type (integer 0 #.most-positive-fixnum))\n (left nil :type (or null treap))\n (right nil :type (or null treap)))\n\n(declaim (inline treap-count))\n(defun treap-count (treap)\n \"Returns the size of the (nullable) TREAP.\"\n (declare ((or null treap) treap))\n (if (null treap)\n 0\n (%treap-count treap)))\n\n(declaim (inline update-count))\n(defun update-count (treap)\n (declare (treap treap))\n (setf (%treap-count treap)\n (+ 1\n (treap-count (%treap-left treap))\n (treap-count (%treap-right treap)))))\n\n(declaim (inline treap-find))\n(defun treap-find (key treap &key (order #'<))\n \"Returns KEY if TREAP contains it, otherwise NIL.\n\nAn element in TREAP is considered to be equal to KEY iff (and (not (funcall\norder key )) (not (funcall order key))) is true.\"\n (declare ((or null treap) treap))\n (labels ((recur (treap)\n (cond ((null treap) nil)\n ((funcall order key (%treap-key treap))\n (recur (%treap-left treap)))\n ((funcall order (%treap-key treap) key)\n (recur (%treap-right treap)))\n (t key))))\n (recur treap)))\n\n(declaim (inline treap-position))\n(defun treap-position (key treap &key (order #'<))\n \"Returns the index if TREAP contains KEY, otherwise NIL.\n\nAn element in TREAP is considered to be equal to KEY iff (and (not (funcall\norder key )) (not (funcall order key))) is true.\"\n (declare ((or null treap) treap))\n (labels ((recur (count treap)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null treap) nil)\n ((funcall order (%treap-key treap) key)\n (recur count (%treap-right treap)))\n ((funcall order key (%treap-key treap))\n (let ((left-count (- count (treap-count (%treap-right treap)) 1)))\n (recur left-count (%treap-left treap))))\n (t (- count (treap-count (%treap-right treap)) 1)))))\n (recur (treap-count treap) treap)))\n\n(declaim (inline treap-bisect-left)\n (ftype (function * (values (integer 0 #.most-positive-fixnum) t &optional)) treap-bisect-left))\n(defun treap-bisect-left (value treap &key (order #'<))\n \"Returns the smallest index and the corresponding key that satisfies\nTREAP[index] >= VALUE. Returns the size of TREAP and VALUE if TREAP[size-1] <\nVALUE.\"\n (labels ((recur (count treap)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null treap) (values nil nil))\n ((funcall order (%treap-key treap) value)\n (recur count (%treap-right treap)))\n (t (let ((left-count (- count (treap-count (%treap-right treap)) 1)))\n (multiple-value-bind (idx key)\n (recur left-count (%treap-left treap))\n (if idx\n (values idx key)\n (values left-count (%treap-key treap)))))))))\n (declare (ftype (function * (values t t &optional)) recur))\n (multiple-value-bind (idx key)\n (recur (treap-count treap) treap)\n (if idx\n (values idx key)\n (values (treap-count treap) value)))))\n\n(declaim (inline treap-split)\n (ftype (function * (values (or null treap) (or null treap) &optional)) treap-split))\n(defun treap-split (key treap &key (order #'<))\n \"Destructively splits the TREAP with reference to KEY and returns two treaps,\nthe smaller sub-treap (< KEY) and the larger one (>= KEY).\"\n (declare ((or null treap) treap))\n (labels ((recur (treap)\n (cond ((null treap)\n (values nil nil))\n ((funcall order (%treap-key treap) key)\n (multiple-value-bind (left right) (recur (%treap-right treap))\n (setf (%treap-right treap) left)\n (update-count treap)\n (values treap right)))\n (t\n (multiple-value-bind (left right) (recur (%treap-left treap))\n (setf (%treap-left treap) right)\n (update-count treap)\n (values left treap))))))\n (recur treap)))\n\n(declaim (inline treap-insert))\n(defun treap-insert (key treap &key (order #'<))\n \"Destructively inserts KEY into TREAP and returns the resultant treap.\"\n (declare ((or null treap) treap))\n (let ((node (%make-treap key (random most-positive-fixnum))))\n (labels ((recur (treap)\n (declare (treap node))\n (cond ((null treap) node)\n ((> (%treap-priority node) (%treap-priority treap))\n (setf (values (%treap-left node) (%treap-right node))\n (treap-split (%treap-key node) treap :order order))\n (update-count node)\n node)\n (t\n (if (funcall order (%treap-key node) (%treap-key treap))\n (setf (%treap-left treap)\n (recur (%treap-left treap)))\n (setf (%treap-right treap)\n (recur (%treap-right treap))))\n (update-count treap)\n treap))))\n (recur treap))))\n\n(defmacro treap-push (key treap order)\n \"Pushes KEY to TREAP.\"\n `(setf ,treap (treap-insert ,key ,treap :order ,order)))\n\n(defmacro treap-pop (key treap order)\n \"Deletes KEY from TREAP.\"\n `(setf ,treap (treap-delete ,key ,treap :order ,order)))\n\n;; It takes O(nlog(n)).\n(defun treap (order &rest keys)\n (loop with res = nil\n for key in keys\n do (setf res (treap-insert key res :order order))\n finally (return res)))\n\n;; Reference: https://cp-algorithms.com/data_structures/treap.html\n(declaim (inline make-treap))\n(defun make-treap (sorted-vector)\n \"Makes a treap from the given SORTED-VECTOR in O(n) time. Note that this\nfunction doesn't check if the SORTED-VECTOR is actually sorted w.r.t. your\nintended order. The consequence is undefined when a non-sorted vector is\npassed.\"\n (declare (vector sorted-vector))\n (labels ((heapify (top)\n (when top\n (let ((prioritized-node top))\n (when (and (%treap-left top)\n (> (%treap-priority (%treap-left top))\n (%treap-priority prioritized-node)))\n (setq prioritized-node (%treap-left top)))\n (when (and (%treap-right top)\n (> (%treap-priority (%treap-right top))\n (%treap-priority prioritized-node)))\n (setq prioritized-node (%treap-right top)))\n (unless (eql prioritized-node top)\n (rotatef (%treap-priority prioritized-node)\n (%treap-priority top))\n (heapify prioritized-node)))))\n (build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-treap (aref sorted-vector mid)\n (random most-positive-fixnum))))\n (setf (%treap-left node) (build l mid))\n (setf (%treap-right node) (build (+ mid 1) r))\n (heapify node)\n (update-count node)\n node))))\n (build 0 (length sorted-vector))))\n\n(defun treap-merge (left right)\n \"Destructively concatenates two treaps. Assumes that all keys of LEFT are\nsmaller (or larger, depending on the order) than those of RIGHT.\n\nNote that this `merge' is different from CL:MERGE and rather close to\nCL:CONCATENATE. (TREAP-UNITE is the analogue of the former.)\"\n (declare (optimize (speed 3))\n ((or null treap) left right))\n (cond ((null left) right)\n ((null right) left)\n ((> (%treap-priority left) (%treap-priority right))\n (setf (%treap-right left)\n (treap-merge (%treap-right left) right))\n (update-count left)\n left)\n (t\n (setf (%treap-left right)\n (treap-merge left (%treap-left right)))\n (update-count right)\n right)))\n\n(declaim (inline treap-delete))\n(defun treap-delete (key treap &key (order #'<))\n \"Destructively deletes the KEY in TREAP and returns the resultant treap.\"\n (declare ((or null treap) treap))\n (labels ((recur (treap)\n (cond ((null treap) nil)\n ((funcall order key (%treap-key treap))\n (setf (%treap-left treap) (recur (%treap-left treap)))\n (update-count treap)\n treap)\n ((funcall order (%treap-key treap) key)\n (setf (%treap-right treap) (recur (%treap-right treap)))\n (update-count treap)\n treap)\n (t\n (treap-merge (%treap-left treap) (%treap-right treap))))))\n (declare (ftype (function * (values (or null treap) &optional)) recur))\n (recur treap)))\n\n(declaim (inline treap-map))\n(defun treap-map (function treap)\n \"Successively applies FUNCTION to TREAP[0], ..., TREAP[SIZE-1]. FUNCTION must\ntake one argument.\"\n (declare (function function))\n (labels ((recur (treap)\n (when treap\n (recur (%treap-left treap))\n (funcall function (%treap-key treap))\n (recur (%treap-right treap)))))\n (recur treap)))\n\n(defmethod print-object ((object treap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (treap-map (lambda (key)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write key :stream stream))\n object))))\n\n(define-condition invalid-treap-index-error (type-error)\n ((treap :initarg :treap :reader invalid-treap-index-error-treap)\n (index :initarg :index :reader invalid-treap-index-error-index))\n (:report\n (lambda (condition stream)\n (format stream \"Invalid index ~W for treap ~W.\"\n (invalid-treap-index-error-index condition)\n (invalid-treap-index-error-treap condition)))))\n\n(defun treap-ref (treap index)\n \"Index access\"\n (declare (optimize (speed 3))\n ((or null treap) treap)\n ((integer 0 #.most-positive-fixnum) index))\n (when (>= index (treap-count treap))\n (error 'invalid-treap-index-error :treap treap :index index))\n (labels ((%ref (treap index)\n (declare (optimize (speed 3) (safety 0))\n ((integer 0 #.most-positive-fixnum) index))\n (let ((left-count (treap-count (%treap-left treap))))\n (cond ((< index left-count)\n (%ref (%treap-left treap) index))\n ((> index left-count)\n (%ref (%treap-right treap) (- index left-count 1)))\n (t (%treap-key treap))))))\n (%ref treap index)))\n\n(defun treap-first (treap)\n (declare (optimize (speed 3))\n (treap treap))\n (if (%treap-left treap)\n (treap-first (%treap-left treap))\n (%treap-key treap)))\n\n(defun treap-last (treap)\n (declare (optimize (speed 3))\n (treap treap))\n (if (%treap-right treap)\n (treap-last (%treap-right treap))\n (%treap-key treap)))\n\n(declaim (inline treap-unite))\n(defun treap-unite (treap1 treap2 &key (order #'<))\n \"Merges two treaps with keeping the order.\"\n (labels\n ((recur (l r)\n (cond ((null l) r)\n ((null r) l)\n (t (when (< (%treap-priority l) (%treap-priority r))\n (rotatef l r))\n (multiple-value-bind (lchild rchild)\n (treap-split (%treap-key l) r :order order)\n (setf (%treap-left l) (recur (%treap-left l) lchild)\n (%treap-right l) (recur (%treap-right l) rchild))\n (update-count l)\n l)))))\n (recur treap1 treap2)))\n\n(declaim (inline treap-reverse))\n(defun treap-reverse (treap)\n \"Destructively reverses the order of the whole treap.\"\n (labels ((recur (treap)\n (when treap\n (let ((left (recur (%treap-left treap)))\n (right (recur (%treap-right treap))))\n (setf (%treap-left treap) right\n (%treap-right treap) left)\n treap))))\n (recur treap)))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun calc (x factor)\n (loop for i from 0\n while (zerop (mod x factor))\n do (setq x (floor x factor))\n finally (return i)))\n\n(defun main ()\n (let* ((n (read))\n (twos (make-array n :element-type 'uint8 :fill-pointer 0))\n (fives (make-array n :element-type 'uint8 :fill-pointer 0))\n (trails (make-array n :element-type 'uint8 :fill-pointer 0))\n (zeros 0))\n (dotimes (_ n)\n (block continue\n (let* ((s (read-line))\n (end (position #\\0 s :from-end t :test-not #'eql)))\n (unless (find #\\. s)\n (let ((a (read-from-string s)))\n (assert (vector-push 0 trails))\n (assert (vector-push (calc a 2) twos))\n (assert (vector-push (calc a 5) fives)))\n (return-from continue))\n (when (null end)\n (incf zeros)\n (return-from continue))\n (unless (char= (aref s end) #\\.)\n (incf end))\n (let* ((s (subseq s 0 end))\n (pos-point (or (position #\\. s) (length s)))\n (trail (max 0 (- (length s) pos-point 1)))\n (a (read-from-string (remove #\\. s))))\n (if (zerop a)\n (incf zeros)\n (progn\n (assert (vector-push trail trails))\n (assert (vector-push (calc a 2) twos))\n (assert (vector-push (calc a 5) fives))))))))\n (dbg twos fives trails)\n (let ((points (make-array (length twos) :element-type 'list))\n (res (+ (ash (* zeros (- zeros 1)) -1)\n (* zeros (- n zeros)))))\n (dotimes (i (length twos))\n (let ((two (aref twos i))\n (five (aref fives i))\n (trail (aref trails i)))\n (setf (aref points i) (cons (- two trail) (- five trail)))))\n (setq points (sort points (lambda (x y)\n (or (< (car x) (car y))\n (and (= (car x) (car y))\n (< (cdr x) (cdr y)))))))\n (let ((rtree (make-range-tree points))\n (delta 0))\n (dotimes (i (length twos))\n (let ((two (aref twos i))\n (five (aref fives i))\n (trail (aref trails i)))\n (incf delta (rt-count rtree (- trail two) (- trail five) nil nil))))\n (dotimes (i (length twos))\n (when (zerop (aref trails i))\n (decf delta)))\n (println (+ res (ash delta -1)))))))\n\n;; (defun main ()\n;; (let* ((n (read))\n;; (twos (make-array n :element-type 'uint8 :fill-pointer 0))\n;; (fives (make-array n :element-type 'uint8 :fill-pointer 0))\n;; (trails (make-array n :element-type 'uint8 :fill-pointer 0))\n;; (zeros 0))\n;; (dotimes (_ n)\n;; (block continue\n;; (let* ((s (read-line))\n;; (end (position #\\0 s :from-end t :test-not #'eql)))\n;; (when (null end)\n;; (incf zeros)\n;; (return-from continue))\n;; (unless (char= (aref s end) #\\.)\n;; (incf end))\n;; (let* ((s (subseq s 0 end))\n;; (pos-point (or (position #\\. s) (length s)))\n;; (trail (max 0 (- (length s) pos-point 1)))\n;; (a (read-from-string (remove #\\. s))))\n;; (if (zerop a)\n;; (incf zeros)\n;; (progn\n;; (assert (vector-push trail trails))\n;; (assert (vector-push (calc a 2) twos))\n;; (assert (vector-push (calc a 5) fives))))))))\n;; (let ((ords (make-array (length trails) :element-type 'uint31 :initial-element 0))\n;; treap\n;; (res (+ (ash (* zeros (- zeros 1)) -1)\n;; (* zeros (- n zeros))))\n;; stack)\n;; (dotimes (i (length ords))\n;; (setf (aref ords i) i))\n;; (setq ords (sort ords #'> :key (lambda (i) (- (aref trails i) (aref twos i)))))\n;; #>zeros\n;; (sb-int:dovector (ord ords)\n;; (let ((two (aref twos ord))\n;; (five (aref fives ord))\n;; (trail (aref trails ord)))\n;; (dbg ord two five trail)\n;; (loop (unless stack\n;; (return))\n;; (destructuring-bind (two-old five-old trail-old) (car stack)\n;; (let ((f-g (- two-old trail-old)))\n;; (if (>= f-g (- trail two))\n;; (progn (pop stack)\n;; (treap-push (- five-old trail-old) treap #'<))\n;; (return)))))\n;; (let ((pos (treap-bisect-left (- trail five) treap)))\n;; (incf res #>(- (treap-count treap) pos))\n;; (push (list two five trail) stack))))\n;; (println res))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"3\n\"\n (run \"5\n7.5\n2.4\n17.000000001\n17\n16.000000000\n\" nil)))\n (it.bese.fiveam:is\n (equal \"8\n\"\n (run \"11\n0.9\n1\n1\n1.25\n2.30000\n5\n70\n0.000000001\n9999.999999999\n0.999999999\n1.000000001\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1597024962, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02588.html", "problem_id": "p02588", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02588/input.txt", "sample_output_relpath": "derived/input_output/data/p02588/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02588/Lisp/s511406562.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s511406562", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; 2D range tree with fractional cascading\n;;;\n;;; build: O(nlog(n))\n;;; query: O(log(n))\n;;;\n;;; Reference:\n;;; Mark de Berg et al., Computational Geometry: Algorithms and Applications, 3rd Edition\n;;;\n\n;; TODO: introduce abelian group\n\n(defstruct (ynode (:constructor make-ynode (xkeys ykeys lpointers rpointers values cumuls))\n (:conc-name %ynode-)\n (:copier nil))\n (xkeys nil :type (simple-array fixnum (*)))\n (ykeys nil :type (simple-array fixnum (*)))\n (lpointers nil :type (or null (simple-array (integer 0 #.most-positive-fixnum) (*))))\n (rpointers nil :type (or null (simple-array (integer 0 #.most-positive-fixnum) (*))))\n (values nil :type (simple-array fixnum (*)))\n (cumuls nil :type (or null (simple-array fixnum (*)))))\n\n(defstruct (xnode (:constructor make-xnode (xkey ynode left right))\n (:conc-name %xnode-)\n (:copier nil))\n (xkey 0 :type fixnum)\n (ynode nil :type ynode)\n (left nil :type (or null xnode))\n (right nil :type (or null xnode)))\n\n(defun %ynode-merge (ynode1 ynode2)\n \"Merges two YNODEs non-destructively in O(n).\"\n (declare (optimize (speed 3)))\n (let* ((xkeys1 (%ynode-xkeys ynode1))\n (ykeys1 (%ynode-ykeys ynode1))\n (xkeys2 (%ynode-xkeys ynode2))\n (ykeys2 (%ynode-ykeys ynode2))\n (values1 (%ynode-values ynode1))\n (values2 (%ynode-values ynode2))\n (len1 (length xkeys1))\n (len2 (length xkeys2))\n (new-len (+ len1 len2))\n (new-xkeys (make-array new-len :element-type 'fixnum))\n (new-ykeys (make-array new-len :element-type 'fixnum))\n (new-values (make-array new-len :element-type 'fixnum))\n (new-cumuls (make-array (+ new-len 1) :element-type 'fixnum :initial-element 0))\n (lpointers (make-array (+ 1 new-len)\n :element-type '(integer 0 #.most-positive-fixnum)))\n (rpointers (make-array (+ 1 new-len)\n :element-type '(integer 0 #.most-positive-fixnum)))\n \n (new-pos 0)\n (pos1 0)\n (pos2 0))\n (declare ((integer 0 #.most-positive-fixnum) len1 len2 new-len new-pos pos1 pos2))\n ;; merge two vectors\n (loop\n (when (= pos1 len1)\n (loop\n for i from pos2 below len2\n do (setf (aref new-xkeys new-pos) (aref xkeys2 i)\n (aref new-ykeys new-pos) (aref ykeys2 i)\n (aref new-values new-pos) (aref values2 i)\n (aref lpointers new-pos) pos1\n (aref rpointers new-pos) i)\n (incf new-pos))\n (return))\n (when (= pos2 len2)\n (loop\n for i from pos1 below len1\n do (setf (aref new-xkeys new-pos) (aref xkeys1 i)\n (aref new-ykeys new-pos) (aref ykeys1 i)\n (aref new-values new-pos) (aref values1 i)\n (aref lpointers new-pos) i\n (aref rpointers new-pos) pos2)\n (incf new-pos))\n (return))\n (if (or (< (aref ykeys1 pos1) (aref ykeys2 pos2))\n (and (= (aref ykeys1 pos1) (aref ykeys2 pos2))\n (< (aref xkeys1 pos1) (aref xkeys2 pos2))))\n (setf (aref new-xkeys new-pos) (aref xkeys1 pos1)\n (aref new-ykeys new-pos) (aref ykeys1 pos1)\n (aref new-values new-pos) (aref values1 pos1)\n (aref lpointers new-pos) pos1\n (aref rpointers new-pos) pos2\n pos1 (+ pos1 1))\n (setf (aref new-xkeys new-pos) (aref xkeys2 pos2)\n (aref new-ykeys new-pos) (aref ykeys2 pos2)\n (aref new-values new-pos) (aref values2 pos2)\n (aref lpointers new-pos) pos1\n (aref rpointers new-pos) pos2\n pos2 (+ pos2 1)))\n (incf new-pos))\n (dotimes (i new-len)\n (setf (aref new-cumuls (+ i 1))\n (+ (aref new-cumuls i) (aref new-values i))))\n (setf (aref lpointers new-len) len1\n (aref rpointers new-len) len2)\n (make-ynode new-xkeys new-ykeys lpointers rpointers new-values new-cumuls)))\n\n(declaim (inline make-range-tree))\n(defun make-range-tree (points &key (xkey #'car) (ykey #'cdr) value-key)\n \"points := vector of points\n\nMakes a range tree from the points. These points must be sorted\nw.r.t. lexicographical order and must not contain duplicate points. (Duplicate\ncoordinates are allowed.) E.g. (-1, 3), (-1, 4), (-1, 7) (0, 1) (0, 3) (2,\n-1) (2, 1)).\"\n (declare (vector points))\n (when (zerop (length points))\n (return-from make-range-tree nil))\n (let ((pointers-for-leaf\n (make-array 2\n :element-type '(integer 0 #.most-positive-fixnum)\n :initial-element 0)))\n (labels\n ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= (- r l) 1)\n (let* ((point (aref points l))\n (x (funcall xkey point))\n (y (funcall ykey point))\n (value (if value-key (funcall value-key point) 0))\n (xkeys (make-array 1 :element-type 'fixnum :initial-element x))\n (ykeys (make-array 1 :element-type 'fixnum :initial-element y))\n (values (make-array 1 :element-type 'fixnum :initial-element value))\n (cumuls (make-array 2 :element-type 'fixnum :initial-element 0)))\n (setf (aref cumuls 1) value)\n (make-xnode x (make-ynode xkeys ykeys\n pointers-for-leaf\n pointers-for-leaf\n values cumuls)\n nil nil))\n (let* ((mid (ash (+ l r) -1))\n (left (build l mid))\n (right (build mid r)))\n (make-xnode (funcall xkey (aref points mid))\n (%ynode-merge (%xnode-ynode left)\n (%xnode-ynode right))\n left right)))))\n (build 0 (length points)))))\n\n(defconstant +neg-inf+ most-negative-fixnum)\n(defconstant +pos-inf+ most-positive-fixnum)\n\n(declaim (inline xleaf-p))\n(defun xleaf-p (xnode)\n (and (null (%xnode-left xnode)) (null (%xnode-right xnode))))\n\n(defun rt-count (range-tree x1 y1 x2 y2)\n \"Returns the number of the nodes within the rectangle [x1, x2)*[y1, y2). A\npart or all of these coordinates can be NIL; then they are regarded as the\nnegative or positive infinity.\"\n (declare (optimize (speed 3))\n ((or null fixnum) x1 y1 x2 y2))\n (setq x1 (or x1 +neg-inf+)\n x2 (or x2 +pos-inf+)\n y1 (or y1 +neg-inf+)\n y2 (or y2 +pos-inf+))\n (unless range-tree\n (return-from rt-count 0))\n (let* ((ynode (%xnode-ynode range-tree))\n (xkeys (%ynode-xkeys ynode))\n (ykeys (%ynode-ykeys ynode)))\n (labels ((bisect-left (y)\n (declare (fixnum y))\n (let ((left 0)\n (ok (length xkeys)))\n (declare ((integer 0 #.most-positive-fixnum) left ok))\n (loop\n (let ((mid (ash (+ left ok) -1)))\n (if (= mid left)\n (if (< (aref ykeys left) y)\n (return ok)\n (return left))\n (if (< (aref ykeys mid) y)\n (setq left mid)\n (setq ok mid)))))))\n (recur (xnode x1 x2 start end)\n (declare ((or null xnode) xnode)\n (fixnum x1 x2)\n ;; KLUDGE: declaring ftype is not sufficient for the\n ;; optimization on SBCL 1.1.14.\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (cond ((null xnode) 0)\n ((and (= x1 +neg-inf+) (= x2 +pos-inf+))\n (- end start))\n (t\n (let* ((xkey (%xnode-xkey xnode))\n (ynode (%xnode-ynode xnode))\n (lpointers (%ynode-lpointers ynode))\n (rpointers (%ynode-rpointers ynode)))\n (if (<= x1 xkey)\n (if (< xkey x2)\n ;; XKEY is in [X1, X2)\n (if (xleaf-p xnode)\n (- end start)\n (+ (recur (%xnode-left xnode)\n x1 +pos-inf+\n (aref lpointers start)\n (aref lpointers end))\n (recur (%xnode-right xnode)\n +neg-inf+ x2\n (aref rpointers start)\n (aref rpointers end))))\n ;; XKEY is in [X2, +inf)\n (recur (%xnode-left xnode)\n x1 x2\n (aref lpointers start)\n (aref lpointers end)))\n ;; XKEY is in (-inf, X1)\n (recur (%xnode-right xnode)\n x1 x2\n (aref rpointers start)\n (aref rpointers end))))))))\n (let ((start (bisect-left y1))\n (end (bisect-left y2)))\n (recur range-tree x1 x2 start end)))))\n\n(defun rt-query (range-tree x1 y1 x2 y2)\n \"Returns the sum of the values within the rectangle [x1, x2)*[y1, y2). A\npart or all of these coordinates can be NIL; then they are regarded as the\nnegative or positive infinity.\"\n (declare (optimize (speed 3))\n ((or null fixnum) x1 y1 x2 y2))\n (setq x1 (or x1 +neg-inf+)\n x2 (or x2 +pos-inf+)\n y1 (or y1 +neg-inf+)\n y2 (or y2 +pos-inf+))\n (unless range-tree\n (return-from rt-query 0))\n (let* ((ynode (%xnode-ynode range-tree))\n (xkeys (%ynode-xkeys ynode))\n (ykeys (%ynode-ykeys ynode)))\n (labels ((bisect-left (y)\n (declare (fixnum y))\n (let ((left 0)\n (ok (length xkeys)))\n (declare ((integer 0 #.most-positive-fixnum) left ok))\n (loop\n (let ((mid (ash (+ left ok) -1)))\n (if (= mid left)\n (if (< (aref ykeys left) y)\n (return ok)\n (return left))\n (if (< (aref ykeys mid) y)\n (setq left mid)\n (setq ok mid)))))))\n (recur (xnode x1 x2 start end)\n (declare ((or null xnode) xnode)\n (fixnum x1 x2)\n ;; KLUDGE: declaring ftype is not sufficient for the\n ;; optimization on SBCL 1.1.14.\n #+sbcl (values fixnum))\n (if (null xnode)\n 0\n (let* ((xkey (%xnode-xkey xnode))\n (ynode (%xnode-ynode xnode))\n (cumuls (%ynode-cumuls ynode))\n (lpointers (%ynode-lpointers ynode))\n (rpointers (%ynode-rpointers ynode)))\n (if (and (= x1 +neg-inf+) (= x2 +pos-inf+))\n (- (aref cumuls end) (aref cumuls start))\n (if (<= x1 xkey)\n (if (< xkey x2)\n ;; XKEY is in [X1, X2)\n (if (xleaf-p xnode)\n (- (aref cumuls end) (aref cumuls start))\n (+ (recur (%xnode-left xnode)\n x1 +pos-inf+\n (aref lpointers start)\n (aref lpointers end))\n (recur (%xnode-right xnode)\n +neg-inf+ x2\n (aref rpointers start)\n (aref rpointers end))))\n ;; XKEY is in [X2, +inf)\n (recur (%xnode-left xnode)\n x1 x2\n (aref lpointers start)\n (aref lpointers end)))\n ;; XKEY is in (-inf, X1)\n (recur (%xnode-right xnode)\n x1 x2\n (aref rpointers start)\n (aref rpointers end))))))))\n (let ((start (bisect-left y1))\n (end (bisect-left y2)))\n (recur range-tree x1 x2 start end)))))\n\n;; not tested\n(defun rt-map (function range-tree x1 y1 x2 y2)\n \"Applies FUNCTION to all the points within the rectangle [x1, x2)*[y1, y2).\"\n (declare (optimize (speed 3))\n ((or null fixnum) x1 y1 x2 y2)\n (function function))\n (setq x1 (or x1 +neg-inf+)\n x2 (or x2 +pos-inf+)\n y1 (or y1 +neg-inf+)\n y2 (or y2 +pos-inf+))\n (when range-tree\n (let* ((ynode (%xnode-ynode range-tree))\n (xkeys (%ynode-xkeys ynode))\n (ykeys (%ynode-ykeys ynode)))\n (labels ((bisect-left (y)\n (declare (fixnum y))\n (let ((left 0)\n (ok (length xkeys)))\n (declare ((integer 0 #.most-positive-fixnum) left ok))\n (loop\n (let ((mid (ash (+ left ok) -1)))\n (if (= mid left)\n (if (< (aref ykeys left) y)\n (return ok)\n (return left))\n (if (< (aref ykeys mid) y)\n (setq left mid)\n (setq ok mid)))))))\n (recur (xnode x1 x2 start end)\n (declare ((or null xnode) xnode)\n (fixnum x1 x2))\n (cond ((null xnode))\n ((and (= x1 +neg-inf+) (= x2 +pos-inf+))\n (loop with ynode = (%xnode-ynode xnode)\n with xkeys = (%ynode-xkeys ynode)\n with ykeys = (%ynode-ykeys ynode)\n for i from start below end\n for x = (aref xkeys i)\n for y = (aref ykeys i)\n do (funcall function x y)))\n (t\n (let* ((xkey (%xnode-xkey xnode))\n (ynode (%xnode-ynode xnode))\n (lpointers (%ynode-lpointers ynode))\n (rpointers (%ynode-rpointers ynode)))\n (if (<= x1 xkey)\n (if (< xkey x2)\n ;; XKEY is in [X1, X2)\n (if (xleaf-p xnode)\n (loop with ynode = (%xnode-ynode xnode)\n with xkeys = (%ynode-xkeys ynode)\n with ykeys = (%ynode-ykeys ynode)\n for i from start below end\n for x = (aref xkeys i)\n for y = (aref ykeys i)\n do (funcall function x y))\n (progn\n (recur (%xnode-left xnode)\n x1 +pos-inf+\n (aref lpointers start)\n (aref lpointers end))\n (recur (%xnode-right xnode)\n +neg-inf+ x2\n (aref rpointers start)\n (aref rpointers end))))\n ;; XKEY is in [X2, +inf)\n (recur (%xnode-left xnode)\n x1 x2\n (aref lpointers start)\n (aref lpointers end)))\n ;; XKEY is in (-inf, X1)\n (recur (%xnode-right xnode)\n x1 x2\n (aref rpointers start)\n (aref rpointers end))))))))\n (let ((start (bisect-left y1))\n (end (bisect-left y2)))\n (recur range-tree x1 x2 start end))))))\n\n\n;; Treap accessible by index (O(log(n))).\n;; Virtually it works like std::set of C++ or TreeSet of Java. \n\n;; Note:\n;; - You shouldn't insert duplicate keys into a treap unless you know what you\n;; are doing.\n;; - You cannot rely on the side effect when you call any destructive operations\n;; on a treap. Always use the returned value.\n;; - An empty treap is NIL.\n\n(defstruct (treap (:constructor %make-treap (key priority &key left right (count 1)))\n (:copier nil)\n (:conc-name %treap-))\n key\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 0 :type (integer 0 #.most-positive-fixnum))\n (left nil :type (or null treap))\n (right nil :type (or null treap)))\n\n(declaim (inline treap-count))\n(defun treap-count (treap)\n \"Returns the size of the (nullable) TREAP.\"\n (declare ((or null treap) treap))\n (if (null treap)\n 0\n (%treap-count treap)))\n\n(declaim (inline update-count))\n(defun update-count (treap)\n (declare (treap treap))\n (setf (%treap-count treap)\n (+ 1\n (treap-count (%treap-left treap))\n (treap-count (%treap-right treap)))))\n\n(declaim (inline treap-find))\n(defun treap-find (key treap &key (order #'<))\n \"Returns KEY if TREAP contains it, otherwise NIL.\n\nAn element in TREAP is considered to be equal to KEY iff (and (not (funcall\norder key )) (not (funcall order key))) is true.\"\n (declare ((or null treap) treap))\n (labels ((recur (treap)\n (cond ((null treap) nil)\n ((funcall order key (%treap-key treap))\n (recur (%treap-left treap)))\n ((funcall order (%treap-key treap) key)\n (recur (%treap-right treap)))\n (t key))))\n (recur treap)))\n\n(declaim (inline treap-position))\n(defun treap-position (key treap &key (order #'<))\n \"Returns the index if TREAP contains KEY, otherwise NIL.\n\nAn element in TREAP is considered to be equal to KEY iff (and (not (funcall\norder key )) (not (funcall order key))) is true.\"\n (declare ((or null treap) treap))\n (labels ((recur (count treap)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null treap) nil)\n ((funcall order (%treap-key treap) key)\n (recur count (%treap-right treap)))\n ((funcall order key (%treap-key treap))\n (let ((left-count (- count (treap-count (%treap-right treap)) 1)))\n (recur left-count (%treap-left treap))))\n (t (- count (treap-count (%treap-right treap)) 1)))))\n (recur (treap-count treap) treap)))\n\n(declaim (inline treap-bisect-left)\n (ftype (function * (values (integer 0 #.most-positive-fixnum) t &optional)) treap-bisect-left))\n(defun treap-bisect-left (value treap &key (order #'<))\n \"Returns the smallest index and the corresponding key that satisfies\nTREAP[index] >= VALUE. Returns the size of TREAP and VALUE if TREAP[size-1] <\nVALUE.\"\n (labels ((recur (count treap)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null treap) (values nil nil))\n ((funcall order (%treap-key treap) value)\n (recur count (%treap-right treap)))\n (t (let ((left-count (- count (treap-count (%treap-right treap)) 1)))\n (multiple-value-bind (idx key)\n (recur left-count (%treap-left treap))\n (if idx\n (values idx key)\n (values left-count (%treap-key treap)))))))))\n (declare (ftype (function * (values t t &optional)) recur))\n (multiple-value-bind (idx key)\n (recur (treap-count treap) treap)\n (if idx\n (values idx key)\n (values (treap-count treap) value)))))\n\n(declaim (inline treap-split)\n (ftype (function * (values (or null treap) (or null treap) &optional)) treap-split))\n(defun treap-split (key treap &key (order #'<))\n \"Destructively splits the TREAP with reference to KEY and returns two treaps,\nthe smaller sub-treap (< KEY) and the larger one (>= KEY).\"\n (declare ((or null treap) treap))\n (labels ((recur (treap)\n (cond ((null treap)\n (values nil nil))\n ((funcall order (%treap-key treap) key)\n (multiple-value-bind (left right) (recur (%treap-right treap))\n (setf (%treap-right treap) left)\n (update-count treap)\n (values treap right)))\n (t\n (multiple-value-bind (left right) (recur (%treap-left treap))\n (setf (%treap-left treap) right)\n (update-count treap)\n (values left treap))))))\n (recur treap)))\n\n(declaim (inline treap-insert))\n(defun treap-insert (key treap &key (order #'<))\n \"Destructively inserts KEY into TREAP and returns the resultant treap.\"\n (declare ((or null treap) treap))\n (let ((node (%make-treap key (random most-positive-fixnum))))\n (labels ((recur (treap)\n (declare (treap node))\n (cond ((null treap) node)\n ((> (%treap-priority node) (%treap-priority treap))\n (setf (values (%treap-left node) (%treap-right node))\n (treap-split (%treap-key node) treap :order order))\n (update-count node)\n node)\n (t\n (if (funcall order (%treap-key node) (%treap-key treap))\n (setf (%treap-left treap)\n (recur (%treap-left treap)))\n (setf (%treap-right treap)\n (recur (%treap-right treap))))\n (update-count treap)\n treap))))\n (recur treap))))\n\n(defmacro treap-push (key treap order)\n \"Pushes KEY to TREAP.\"\n `(setf ,treap (treap-insert ,key ,treap :order ,order)))\n\n(defmacro treap-pop (key treap order)\n \"Deletes KEY from TREAP.\"\n `(setf ,treap (treap-delete ,key ,treap :order ,order)))\n\n;; It takes O(nlog(n)).\n(defun treap (order &rest keys)\n (loop with res = nil\n for key in keys\n do (setf res (treap-insert key res :order order))\n finally (return res)))\n\n;; Reference: https://cp-algorithms.com/data_structures/treap.html\n(declaim (inline make-treap))\n(defun make-treap (sorted-vector)\n \"Makes a treap from the given SORTED-VECTOR in O(n) time. Note that this\nfunction doesn't check if the SORTED-VECTOR is actually sorted w.r.t. your\nintended order. The consequence is undefined when a non-sorted vector is\npassed.\"\n (declare (vector sorted-vector))\n (labels ((heapify (top)\n (when top\n (let ((prioritized-node top))\n (when (and (%treap-left top)\n (> (%treap-priority (%treap-left top))\n (%treap-priority prioritized-node)))\n (setq prioritized-node (%treap-left top)))\n (when (and (%treap-right top)\n (> (%treap-priority (%treap-right top))\n (%treap-priority prioritized-node)))\n (setq prioritized-node (%treap-right top)))\n (unless (eql prioritized-node top)\n (rotatef (%treap-priority prioritized-node)\n (%treap-priority top))\n (heapify prioritized-node)))))\n (build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-treap (aref sorted-vector mid)\n (random most-positive-fixnum))))\n (setf (%treap-left node) (build l mid))\n (setf (%treap-right node) (build (+ mid 1) r))\n (heapify node)\n (update-count node)\n node))))\n (build 0 (length sorted-vector))))\n\n(defun treap-merge (left right)\n \"Destructively concatenates two treaps. Assumes that all keys of LEFT are\nsmaller (or larger, depending on the order) than those of RIGHT.\n\nNote that this `merge' is different from CL:MERGE and rather close to\nCL:CONCATENATE. (TREAP-UNITE is the analogue of the former.)\"\n (declare (optimize (speed 3))\n ((or null treap) left right))\n (cond ((null left) right)\n ((null right) left)\n ((> (%treap-priority left) (%treap-priority right))\n (setf (%treap-right left)\n (treap-merge (%treap-right left) right))\n (update-count left)\n left)\n (t\n (setf (%treap-left right)\n (treap-merge left (%treap-left right)))\n (update-count right)\n right)))\n\n(declaim (inline treap-delete))\n(defun treap-delete (key treap &key (order #'<))\n \"Destructively deletes the KEY in TREAP and returns the resultant treap.\"\n (declare ((or null treap) treap))\n (labels ((recur (treap)\n (cond ((null treap) nil)\n ((funcall order key (%treap-key treap))\n (setf (%treap-left treap) (recur (%treap-left treap)))\n (update-count treap)\n treap)\n ((funcall order (%treap-key treap) key)\n (setf (%treap-right treap) (recur (%treap-right treap)))\n (update-count treap)\n treap)\n (t\n (treap-merge (%treap-left treap) (%treap-right treap))))))\n (declare (ftype (function * (values (or null treap) &optional)) recur))\n (recur treap)))\n\n(declaim (inline treap-map))\n(defun treap-map (function treap)\n \"Successively applies FUNCTION to TREAP[0], ..., TREAP[SIZE-1]. FUNCTION must\ntake one argument.\"\n (declare (function function))\n (labels ((recur (treap)\n (when treap\n (recur (%treap-left treap))\n (funcall function (%treap-key treap))\n (recur (%treap-right treap)))))\n (recur treap)))\n\n(defmethod print-object ((object treap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (treap-map (lambda (key)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write key :stream stream))\n object))))\n\n(define-condition invalid-treap-index-error (type-error)\n ((treap :initarg :treap :reader invalid-treap-index-error-treap)\n (index :initarg :index :reader invalid-treap-index-error-index))\n (:report\n (lambda (condition stream)\n (format stream \"Invalid index ~W for treap ~W.\"\n (invalid-treap-index-error-index condition)\n (invalid-treap-index-error-treap condition)))))\n\n(defun treap-ref (treap index)\n \"Index access\"\n (declare (optimize (speed 3))\n ((or null treap) treap)\n ((integer 0 #.most-positive-fixnum) index))\n (when (>= index (treap-count treap))\n (error 'invalid-treap-index-error :treap treap :index index))\n (labels ((%ref (treap index)\n (declare (optimize (speed 3) (safety 0))\n ((integer 0 #.most-positive-fixnum) index))\n (let ((left-count (treap-count (%treap-left treap))))\n (cond ((< index left-count)\n (%ref (%treap-left treap) index))\n ((> index left-count)\n (%ref (%treap-right treap) (- index left-count 1)))\n (t (%treap-key treap))))))\n (%ref treap index)))\n\n(defun treap-first (treap)\n (declare (optimize (speed 3))\n (treap treap))\n (if (%treap-left treap)\n (treap-first (%treap-left treap))\n (%treap-key treap)))\n\n(defun treap-last (treap)\n (declare (optimize (speed 3))\n (treap treap))\n (if (%treap-right treap)\n (treap-last (%treap-right treap))\n (%treap-key treap)))\n\n(declaim (inline treap-unite))\n(defun treap-unite (treap1 treap2 &key (order #'<))\n \"Merges two treaps with keeping the order.\"\n (labels\n ((recur (l r)\n (cond ((null l) r)\n ((null r) l)\n (t (when (< (%treap-priority l) (%treap-priority r))\n (rotatef l r))\n (multiple-value-bind (lchild rchild)\n (treap-split (%treap-key l) r :order order)\n (setf (%treap-left l) (recur (%treap-left l) lchild)\n (%treap-right l) (recur (%treap-right l) rchild))\n (update-count l)\n l)))))\n (recur treap1 treap2)))\n\n(declaim (inline treap-reverse))\n(defun treap-reverse (treap)\n \"Destructively reverses the order of the whole treap.\"\n (labels ((recur (treap)\n (when treap\n (let ((left (recur (%treap-left treap)))\n (right (recur (%treap-right treap))))\n (setf (%treap-left treap) right\n (%treap-right treap) left)\n treap))))\n (recur treap)))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun calc (x factor)\n (loop for i from 0\n while (zerop (mod x factor))\n do (setq x (floor x factor))\n finally (return i)))\n\n(defun main ()\n (let* ((n (read))\n (twos (make-array n :element-type 'uint8 :fill-pointer 0))\n (fives (make-array n :element-type 'uint8 :fill-pointer 0))\n (trails (make-array n :element-type 'uint8 :fill-pointer 0))\n (zeros 0))\n (dotimes (_ n)\n (block continue\n (let* ((s (read-line))\n (end (position #\\0 s :from-end t :test-not #'eql)))\n (unless (find #\\. s)\n (let ((a (read-from-string s)))\n (assert (vector-push 0 trails))\n (assert (vector-push (calc a 2) twos))\n (assert (vector-push (calc a 5) fives)))\n (return-from continue))\n (when (null end)\n (incf zeros)\n (return-from continue))\n (unless (char= (aref s end) #\\.)\n (incf end))\n (let* ((s (subseq s 0 end))\n (pos-point (or (position #\\. s) (length s)))\n (trail (max 0 (- (length s) pos-point 1)))\n (a (read-from-string (remove #\\. s))))\n (if (zerop a)\n (incf zeros)\n (progn\n (assert (vector-push trail trails))\n (assert (vector-push (calc a 2) twos))\n (assert (vector-push (calc a 5) fives))))))))\n (dbg twos fives trails)\n (let ((points (make-array (length twos) :element-type 'list))\n (res (+ (ash (* zeros (- zeros 1)) -1)\n (* zeros (- n zeros)))))\n (dotimes (i (length twos))\n (let ((two (aref twos i))\n (five (aref fives i))\n (trail (aref trails i)))\n (setf (aref points i) (cons (- two trail) (- five trail)))))\n (setq points (sort points (lambda (x y)\n (or (< (car x) (car y))\n (and (= (car x) (car y))\n (< (cdr x) (cdr y)))))))\n (let ((rtree (make-range-tree points))\n (delta 0))\n (dotimes (i (length twos))\n (let ((two (aref twos i))\n (five (aref fives i))\n (trail (aref trails i)))\n (incf delta (rt-count rtree (- trail two) (- trail five) nil nil))))\n (dotimes (i (length twos))\n (when (zerop (aref trails i))\n (decf delta)))\n (println (+ res (ash delta -1)))))))\n\n;; (defun main ()\n;; (let* ((n (read))\n;; (twos (make-array n :element-type 'uint8 :fill-pointer 0))\n;; (fives (make-array n :element-type 'uint8 :fill-pointer 0))\n;; (trails (make-array n :element-type 'uint8 :fill-pointer 0))\n;; (zeros 0))\n;; (dotimes (_ n)\n;; (block continue\n;; (let* ((s (read-line))\n;; (end (position #\\0 s :from-end t :test-not #'eql)))\n;; (when (null end)\n;; (incf zeros)\n;; (return-from continue))\n;; (unless (char= (aref s end) #\\.)\n;; (incf end))\n;; (let* ((s (subseq s 0 end))\n;; (pos-point (or (position #\\. s) (length s)))\n;; (trail (max 0 (- (length s) pos-point 1)))\n;; (a (read-from-string (remove #\\. s))))\n;; (if (zerop a)\n;; (incf zeros)\n;; (progn\n;; (assert (vector-push trail trails))\n;; (assert (vector-push (calc a 2) twos))\n;; (assert (vector-push (calc a 5) fives))))))))\n;; (let ((ords (make-array (length trails) :element-type 'uint31 :initial-element 0))\n;; treap\n;; (res (+ (ash (* zeros (- zeros 1)) -1)\n;; (* zeros (- n zeros))))\n;; stack)\n;; (dotimes (i (length ords))\n;; (setf (aref ords i) i))\n;; (setq ords (sort ords #'> :key (lambda (i) (- (aref trails i) (aref twos i)))))\n;; #>zeros\n;; (sb-int:dovector (ord ords)\n;; (let ((two (aref twos ord))\n;; (five (aref fives ord))\n;; (trail (aref trails ord)))\n;; (dbg ord two five trail)\n;; (loop (unless stack\n;; (return))\n;; (destructuring-bind (two-old five-old trail-old) (car stack)\n;; (let ((f-g (- two-old trail-old)))\n;; (if (>= f-g (- trail two))\n;; (progn (pop stack)\n;; (treap-push (- five-old trail-old) treap #'<))\n;; (return)))))\n;; (let ((pos (treap-bisect-left (- trail five) treap)))\n;; (incf res #>(- (treap-count treap) pos))\n;; (push (list two five trail) stack))))\n;; (println res))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"3\n\"\n (run \"5\n7.5\n2.4\n17.000000001\n17\n16.000000000\n\" nil)))\n (it.bese.fiveam:is\n (equal \"8\n\"\n (run \"11\n0.9\n1\n1\n1.25\n2.30000\n5\n70\n0.000000001\n9999.999999999\n0.999999999\n1.000000001\n\" nil))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given N real values A_1, A_2, \\ldots, A_N.\nCompute the number of pairs of indices (i, j)\nsuch that i < j and the product A_i \\cdot A_j is integer.\n\nConstraints\n\n2 \\leq N \\leq 200\\,000\n\n0 < A_i < 10^4\n\nA_i is given with at most 9 digits after the decimal.\n\nInput\n\nInput is given from Standard Input in the following format.\n\nN\nA_1\nA_2\n\\vdots\nA_N\n\nOutput\n\nPrint the number of pairs with integer product A_i \\cdot A_j (and i < j).\n\nSample Input 1\n\n5\n7.5\n2.4\n17.000000001\n17\n16.000000000\n\nSample Output 1\n\n3\n\nThere are 3 pairs with integer product:\n\n7.5 \\cdot 2.4 = 18\n\n7.5 \\cdot 16 = 120\n\n17 \\cdot 16 = 272\n\nSample Input 2\n\n11\n0.9\n1\n1\n1.25\n2.30000\n5\n70\n0.000000001\n9999.999999999\n0.999999999\n1.000000001\n\nSample Output 2\n\n8", "sample_input": "5\n7.5\n2.4\n17.000000001\n17\n16.000000000\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02588", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given N real values A_1, A_2, \\ldots, A_N.\nCompute the number of pairs of indices (i, j)\nsuch that i < j and the product A_i \\cdot A_j is integer.\n\nConstraints\n\n2 \\leq N \\leq 200\\,000\n\n0 < A_i < 10^4\n\nA_i is given with at most 9 digits after the decimal.\n\nInput\n\nInput is given from Standard Input in the following format.\n\nN\nA_1\nA_2\n\\vdots\nA_N\n\nOutput\n\nPrint the number of pairs with integer product A_i \\cdot A_j (and i < j).\n\nSample Input 1\n\n5\n7.5\n2.4\n17.000000001\n17\n16.000000000\n\nSample Output 1\n\n3\n\nThere are 3 pairs with integer product:\n\n7.5 \\cdot 2.4 = 18\n\n7.5 \\cdot 16 = 120\n\n17 \\cdot 16 = 272\n\nSample Input 2\n\n11\n0.9\n1\n1\n1.25\n2.30000\n5\n70\n0.000000001\n9999.999999999\n0.999999999\n1.000000001\n\nSample Output 2\n\n8", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 38593, "cpu_time_ms": 973, "memory_kb": 387316}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s807738718", "group_id": "codeNet:p02588", "input_text": "(let ((n (read))\n (x nil)\n (ans 0))\n (push (read) x)\n (loop :for i :from 2 :to n\n :for a := (read-from-string (format nil \"~Ad0\" (read-line)))\n :do (loop :for b :in x\n :if (= (- (* a b) (floor (* a b))) 0)\n :do (incf ans))\n :do (push a x))\n (format t \"~A~%\" ans))\n", "language": "Lisp", "metadata": {"date": 1597023527, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02588.html", "problem_id": "p02588", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02588/input.txt", "sample_output_relpath": "derived/input_output/data/p02588/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02588/Lisp/s807738718.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s807738718", "user_id": "u608227593"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((n (read))\n (x nil)\n (ans 0))\n (push (read) x)\n (loop :for i :from 2 :to n\n :for a := (read-from-string (format nil \"~Ad0\" (read-line)))\n :do (loop :for b :in x\n :if (= (- (* a b) (floor (* a b))) 0)\n :do (incf ans))\n :do (push a x))\n (format t \"~A~%\" ans))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given N real values A_1, A_2, \\ldots, A_N.\nCompute the number of pairs of indices (i, j)\nsuch that i < j and the product A_i \\cdot A_j is integer.\n\nConstraints\n\n2 \\leq N \\leq 200\\,000\n\n0 < A_i < 10^4\n\nA_i is given with at most 9 digits after the decimal.\n\nInput\n\nInput is given from Standard Input in the following format.\n\nN\nA_1\nA_2\n\\vdots\nA_N\n\nOutput\n\nPrint the number of pairs with integer product A_i \\cdot A_j (and i < j).\n\nSample Input 1\n\n5\n7.5\n2.4\n17.000000001\n17\n16.000000000\n\nSample Output 1\n\n3\n\nThere are 3 pairs with integer product:\n\n7.5 \\cdot 2.4 = 18\n\n7.5 \\cdot 16 = 120\n\n17 \\cdot 16 = 272\n\nSample Input 2\n\n11\n0.9\n1\n1\n1.25\n2.30000\n5\n70\n0.000000001\n9999.999999999\n0.999999999\n1.000000001\n\nSample Output 2\n\n8", "sample_input": "5\n7.5\n2.4\n17.000000001\n17\n16.000000000\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02588", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given N real values A_1, A_2, \\ldots, A_N.\nCompute the number of pairs of indices (i, j)\nsuch that i < j and the product A_i \\cdot A_j is integer.\n\nConstraints\n\n2 \\leq N \\leq 200\\,000\n\n0 < A_i < 10^4\n\nA_i is given with at most 9 digits after the decimal.\n\nInput\n\nInput is given from Standard Input in the following format.\n\nN\nA_1\nA_2\n\\vdots\nA_N\n\nOutput\n\nPrint the number of pairs with integer product A_i \\cdot A_j (and i < j).\n\nSample Input 1\n\n5\n7.5\n2.4\n17.000000001\n17\n16.000000000\n\nSample Output 1\n\n3\n\nThere are 3 pairs with integer product:\n\n7.5 \\cdot 2.4 = 18\n\n7.5 \\cdot 16 = 120\n\n17 \\cdot 16 = 272\n\nSample Input 2\n\n11\n0.9\n1\n1\n1.25\n2.30000\n5\n70\n0.000000001\n9999.999999999\n0.999999999\n1.000000001\n\nSample Output 2\n\n8", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 332, "cpu_time_ms": 2207, "memory_kb": 79280}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s554929292", "group_id": "codeNet:p02594", "input_text": "(let ((x (read)))\n (if (<= 30 x)\n (format t \"Yes~%\")\n (format t \"No~%\")))\n", "language": "Lisp", "metadata": {"date": 1596416482, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02594.html", "problem_id": "p02594", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02594/input.txt", "sample_output_relpath": "derived/input_output/data/p02594/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02594/Lisp/s554929292.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s554929292", "user_id": "u608227593"}, "prompt_components": {"gold_output": "No\n", "input_to_evaluate": "(let ((x (read)))\n (if (<= 30 x)\n (format t \"Yes~%\")\n (format t \"No~%\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.\n\nThe current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?\n\nConstraints\n\n-40 \\leq X \\leq 40\n\nX is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint Yes if you will turn on the air conditioner; print No otherwise.\n\nSample Input 1\n\n25\n\nSample Output 1\n\nNo\n\nSample Input 2\n\n30\n\nSample Output 2\n\nYes", "sample_input": "25\n"}, "reference_outputs": ["No\n"], "source_document_id": "p02594", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.\n\nThe current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?\n\nConstraints\n\n-40 \\leq X \\leq 40\n\nX is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint Yes if you will turn on the air conditioner; print No otherwise.\n\nSample Input 1\n\n25\n\nSample Output 1\n\nNo\n\nSample Input 2\n\n30\n\nSample Output 2\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 85, "cpu_time_ms": 17, "memory_kb": 23256}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s452994641", "group_id": "codeNet:p02595", "input_text": "(let ((n (read))\n (d (read))\n (ans 0))\n (loop :for i :from 1 :to n\n :for x := (read)\n :for y := (read)\n :if (<= (+ (* x x) (* y y)) (* d d))\n :do (incf ans))\n (princ ans))\n", "language": "Lisp", "metadata": {"date": 1596841437, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02595.html", "problem_id": "p02595", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02595/input.txt", "sample_output_relpath": "derived/input_output/data/p02595/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02595/Lisp/s452994641.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s452994641", "user_id": "u761519515"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((n (read))\n (d (read))\n (ans 0))\n (loop :for i :from 1 :to n\n :for x := (read)\n :for y := (read)\n :if (<= (+ (* x x) (* y y)) (* d d))\n :do (incf ans))\n (princ ans))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).\n\nAmong them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?\n\nWe remind you that the distance between the origin and the point (p, q) can be represented as \\sqrt{p^2+q^2}.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\n0 \\leq D \\leq 2\\times 10^5\n\n|X_i|,|Y_i| \\leq 2\\times 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN D\nX_1 Y_1\n\\vdots\nX_N Y_N\n\nOutput\n\nPrint an integer representing the number of points such that the distance from the origin is at most D.\n\nSample Input 1\n\n4 5\n0 5\n-2 4\n3 4\n4 -4\n\nSample Output 1\n\n3\n\nThe distance between the origin and each of the given points is as follows:\n\n\\sqrt{0^2+5^2}=5\n\n\\sqrt{(-2)^2+4^2}=4.472\\ldots\n\n\\sqrt{3^2+4^2}=5\n\n\\sqrt{4^2+(-4)^2}=5.656\\ldots\n\nThus, we have three points such that the distance from the origin is at most 5.\n\nSample Input 2\n\n12 3\n1 1\n1 1\n1 1\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n\nSample Output 2\n\n7\n\nMultiple points may exist at the same coordinates.\n\nSample Input 3\n\n20 100000\n14309 -32939\n-56855 100340\n151364 25430\n103789 -113141\n147404 -136977\n-37006 -30929\n188810 -49557\n13419 70401\n-88280 165170\n-196399 137941\n-176527 -61904\n46659 115261\n-153551 114185\n98784 -6820\n94111 -86268\n-30401 61477\n-55056 7872\n5901 -163796\n138819 -185986\n-69848 -96669\n\nSample Output 3\n\n6", "sample_input": "4 5\n0 5\n-2 4\n3 4\n4 -4\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02595", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).\n\nAmong them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?\n\nWe remind you that the distance between the origin and the point (p, q) can be represented as \\sqrt{p^2+q^2}.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\n0 \\leq D \\leq 2\\times 10^5\n\n|X_i|,|Y_i| \\leq 2\\times 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN D\nX_1 Y_1\n\\vdots\nX_N Y_N\n\nOutput\n\nPrint an integer representing the number of points such that the distance from the origin is at most D.\n\nSample Input 1\n\n4 5\n0 5\n-2 4\n3 4\n4 -4\n\nSample Output 1\n\n3\n\nThe distance between the origin and each of the given points is as follows:\n\n\\sqrt{0^2+5^2}=5\n\n\\sqrt{(-2)^2+4^2}=4.472\\ldots\n\n\\sqrt{3^2+4^2}=5\n\n\\sqrt{4^2+(-4)^2}=5.656\\ldots\n\nThus, we have three points such that the distance from the origin is at most 5.\n\nSample Input 2\n\n12 3\n1 1\n1 1\n1 1\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n\nSample Output 2\n\n7\n\nMultiple points may exist at the same coordinates.\n\nSample Input 3\n\n20 100000\n14309 -32939\n-56855 100340\n151364 25430\n103789 -113141\n147404 -136977\n-37006 -30929\n188810 -49557\n13419 70401\n-88280 165170\n-196399 137941\n-176527 -61904\n46659 115261\n-153551 114185\n98784 -6820\n94111 -86268\n-30401 61477\n-55056 7872\n5901 -163796\n138819 -185986\n-69848 -96669\n\nSample Output 3\n\n6", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 214, "cpu_time_ms": 370, "memory_kb": 77088}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s483704503", "group_id": "codeNet:p02595", "input_text": "(let* ((n (read))\n (d (read))\n (ans 0))\n (loop :for i :from 1 :to n\n :for x := (read)\n :for y := (read)\n :if (<= (+ (* x x) (* y y)) (* d d))\n :do (incf ans))\n (format t \"~A~%\" ans))\n", "language": "Lisp", "metadata": {"date": 1596416646, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02595.html", "problem_id": "p02595", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02595/input.txt", "sample_output_relpath": "derived/input_output/data/p02595/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02595/Lisp/s483704503.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s483704503", "user_id": "u608227593"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let* ((n (read))\n (d (read))\n (ans 0))\n (loop :for i :from 1 :to n\n :for x := (read)\n :for y := (read)\n :if (<= (+ (* x x) (* y y)) (* d d))\n :do (incf ans))\n (format t \"~A~%\" ans))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).\n\nAmong them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?\n\nWe remind you that the distance between the origin and the point (p, q) can be represented as \\sqrt{p^2+q^2}.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\n0 \\leq D \\leq 2\\times 10^5\n\n|X_i|,|Y_i| \\leq 2\\times 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN D\nX_1 Y_1\n\\vdots\nX_N Y_N\n\nOutput\n\nPrint an integer representing the number of points such that the distance from the origin is at most D.\n\nSample Input 1\n\n4 5\n0 5\n-2 4\n3 4\n4 -4\n\nSample Output 1\n\n3\n\nThe distance between the origin and each of the given points is as follows:\n\n\\sqrt{0^2+5^2}=5\n\n\\sqrt{(-2)^2+4^2}=4.472\\ldots\n\n\\sqrt{3^2+4^2}=5\n\n\\sqrt{4^2+(-4)^2}=5.656\\ldots\n\nThus, we have three points such that the distance from the origin is at most 5.\n\nSample Input 2\n\n12 3\n1 1\n1 1\n1 1\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n\nSample Output 2\n\n7\n\nMultiple points may exist at the same coordinates.\n\nSample Input 3\n\n20 100000\n14309 -32939\n-56855 100340\n151364 25430\n103789 -113141\n147404 -136977\n-37006 -30929\n188810 -49557\n13419 70401\n-88280 165170\n-196399 137941\n-176527 -61904\n46659 115261\n-153551 114185\n98784 -6820\n94111 -86268\n-30401 61477\n-55056 7872\n5901 -163796\n138819 -185986\n-69848 -96669\n\nSample Output 3\n\n6", "sample_input": "4 5\n0 5\n-2 4\n3 4\n4 -4\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02595", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).\n\nAmong them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?\n\nWe remind you that the distance between the origin and the point (p, q) can be represented as \\sqrt{p^2+q^2}.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\n0 \\leq D \\leq 2\\times 10^5\n\n|X_i|,|Y_i| \\leq 2\\times 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN D\nX_1 Y_1\n\\vdots\nX_N Y_N\n\nOutput\n\nPrint an integer representing the number of points such that the distance from the origin is at most D.\n\nSample Input 1\n\n4 5\n0 5\n-2 4\n3 4\n4 -4\n\nSample Output 1\n\n3\n\nThe distance between the origin and each of the given points is as follows:\n\n\\sqrt{0^2+5^2}=5\n\n\\sqrt{(-2)^2+4^2}=4.472\\ldots\n\n\\sqrt{3^2+4^2}=5\n\n\\sqrt{4^2+(-4)^2}=5.656\\ldots\n\nThus, we have three points such that the distance from the origin is at most 5.\n\nSample Input 2\n\n12 3\n1 1\n1 1\n1 1\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n\nSample Output 2\n\n7\n\nMultiple points may exist at the same coordinates.\n\nSample Input 3\n\n20 100000\n14309 -32939\n-56855 100340\n151364 25430\n103789 -113141\n147404 -136977\n-37006 -30929\n188810 -49557\n13419 70401\n-88280 165170\n-196399 137941\n-176527 -61904\n46659 115261\n-153551 114185\n98784 -6820\n94111 -86268\n-30401 61477\n-55056 7872\n5901 -163796\n138819 -185986\n-69848 -96669\n\nSample Output 3\n\n6", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 225, "cpu_time_ms": 366, "memory_kb": 77228}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s958441026", "group_id": "codeNet:p02598", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun calc (as max)\n (declare ((simple-array uint31 (*)) as)\n (uint31 max))\n (if (zerop max)\n 0\n (loop for a across as\n sum (- (ceiling a max) 1))))\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (sb-int:named-let bisect ((ng -1) (ok (reduce #'max as)))\n (if (<= (- ok ng) 1)\n (println ok)\n (let ((mid (floor (+ ng ok) 2)))\n (if (<= (calc as mid) k)\n (bisect ng mid)\n (bisect mid ok)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 3\n7 9\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 0\n3 4 5\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 10\n158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202\n\"\n \"292638192\n\")))\n", "language": "Lisp", "metadata": {"date": 1596418803, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02598.html", "problem_id": "p02598", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02598/input.txt", "sample_output_relpath": "derived/input_output/data/p02598/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02598/Lisp/s958441026.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s958441026", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun calc (as max)\n (declare ((simple-array uint31 (*)) as)\n (uint31 max))\n (if (zerop max)\n 0\n (loop for a across as\n sum (- (ceiling a max) 1))))\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (sb-int:named-let bisect ((ng -1) (ok (reduce #'max as)))\n (if (<= (- ok ng) 1)\n (println ok)\n (let ((mid (floor (+ ng ok) 2)))\n (if (<= (calc as mid) k)\n (bisect ng mid)\n (bisect mid ok)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 3\n7 9\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 0\n3 4 5\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 10\n158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202\n\"\n \"292638192\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nWe have N logs of lengths A_1,A_2,\\cdots A_N.\n\nWe can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0 (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Persistent segment tree\n;;;\n\n;; TODO:\n;; - abstraction\n;; - test\n;; - linear-time initialization\n;; - avoid sb-int:power-of-two-ceiling\n;; - out-of-bound error\n\n(defparameter *store* (make-array 200000000 :element-type 'uint31))\n(declaim ((simple-array uint31 (*)) *store*)\n (always-bound *store*))\n(defparameter *end* 0)\n(declaim ((mod #.array-total-size-limit) *end*)\n (always-bound *end*))\n\n(declaim (inline node-value))\n(defun node-value (node)\n (the uint31 (aref *store* node)))\n(declaim (inline (setf node-value)))\n(defun (setf node-value) (new-value node)\n (declare (uint31 new-value))\n (setf (aref *store* node) new-value))\n(declaim (inline node-left))\n(defun node-left (node)\n (declare ((mod #.array-total-size-limit) node))\n (aref *store* (+ node 1)))\n(declaim (inline (setf node-left)))\n(defun (setf node-left) (new-value node)\n (setf (aref *store* (+ node 1)) new-value))\n(declaim (inline node-right))\n(defun node-right (node)\n (declare ((mod #.array-total-size-limit) node))\n (aref *store* (+ node 2)))\n(declaim (inline (setf node-right)))\n(defun (setf node-right) (new-value node)\n (setf (aref *store* (+ node 2)) new-value))\n\n(declaim (inline make-node))\n(defun make-node (&optional (value 0))\n (let ((end *end*))\n (when (= end (length *store*))\n (setq *store* (adjust-array *store* (* 2 end))))\n (setf (aref *store* end) value)\n (incf *end* 3)\n end))\n\n(declaim (inline copy-node))\n(defun copy-node (node)\n (let ((end *end*))\n (when (= end (length *store*))\n (setq *store* (adjust-array *store* (* 2 end))))\n (setf (aref *store* end) (aref *store* node)\n (aref *store* (+ end 1)) (aref *store* (+ node 1))\n (aref *store* (+ end 2)) (aref *store* (+ node 2)))\n (incf *end* 3)\n end))\n\n(defstruct (psegtree (:constructor %make-psegtree)\n (:conc-name %psegtree-))\n (length 0 :type (mod #.array-total-size-limit))\n (root 0 :type (mod #.array-total-size-limit)))\n\n(defun make-psegtree (length)\n \"Note that the actual length becomes a power of two.\"\n (declare ((integer 0 #.most-positive-fixnum) length))\n (let ((n (ash 1 (integer-length (- length 1))))) ; power of two ceiling\n (labels ((recur (i)\n (declare (uint31 i))\n (if (<= i n)\n (let ((node (make-node)))\n (setf (node-left node) (recur (ash i 1))\n (node-right node) (recur (ash i 1)))\n node)\n 0)))\n (%make-psegtree :length length :root (recur 1)))))\n\n(defun psegtree-query (psegtree left right)\n \"Queries the sum of the interval [LEFT, RIGHT).\"\n (declare #.opt\n (uint31 left right))\n (labels ((recur (root l r)\n (declare (uint31 l r)\n (values uint31 &optional))\n (cond ((or (<= right l) (<= r left))\n 0)\n ((and (<= left l) (<= r right))\n (node-value root))\n (t\n (+ (recur (node-left root) l (ash (+ l r) -1))\n (recur (node-right root) (ash (+ l r) -1) r))))))\n (recur (%psegtree-root psegtree)\n 0\n (sb-int:power-of-two-ceiling (%psegtree-length psegtree)))))\n\n(defun psegtree-inc (psegtree index delta)\n \"Returns a new psegtree updated by PSEGTREE[INDEX] += DELTA. This function is\nnon-destructive.\"\n (declare #.opt\n (uint31 index)\n (int32 delta))\n (labels ((recur (root l r)\n (declare (int32 l r))\n (cond ((or (<= (+ index 1) l) (<= r index)))\n ((and (<= index l) (<= r (+ index 1)))\n (incf (node-value root) delta))\n (t\n (let ((new-lnode (copy-node (node-left root)))\n (new-rnode (copy-node (node-right root))))\n (setf (node-left root) new-lnode\n (node-right root) new-rnode)\n (recur new-lnode l (ash (+ l r) -1))\n (recur new-rnode (ash (+ l r) -1) r)\n (setf (node-value root)\n (+ (node-value (node-left root))\n (node-value (node-right root)))))))))\n (let ((new-psegtree (copy-psegtree psegtree))\n (new-root (copy-node (%psegtree-root psegtree))))\n (recur new-root 0 (sb-int:power-of-two-ceiling (%psegtree-length psegtree)))\n (setf (%psegtree-root new-psegtree) new-root)\n new-psegtree)))\n\n(defmethod print-object ((object psegtree) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t)\n (length (%psegtree-length object)))\n (labels ((recur (node index)\n (if (node-left node)\n (progn\n (recur (node-left node) (ash index 1))\n (recur (node-right node) (+ (ash index 1) 1)))\n (when (< index length)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write (node-value node) :stream stream)))))\n (recur (%psegtree-root object) 0)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +nan+ #x7fffffff)\n\n(defun main ()\n (declare #.opt)\n (let* ((n (read))\n (q (read))\n (cs (make-array n :element-type 'uint31 :initial-element 0))\n (ls (make-array q :element-type 'uint31 :initial-element 0))\n (rs (make-array q :element-type 'uint31 :initial-element 0))\n (appeared (make-array (+ n 1) :element-type 'uint31 :initial-element +nan+))\n (psegtrees (make-array (+ n 1) :element-type t)))\n (dotimes (i n)\n (setf (aref cs i) (read-fixnum)))\n (dotimes (i q)\n (setf (aref ls i) (- (read-fixnum) 1)\n (aref rs i) (read-fixnum)))\n (setf (aref psegtrees 0) (make-psegtree n))\n (dotimes (i n)\n (let ((c (aref cs i)))\n (setf (aref psegtrees (+ i 1))\n (psegtree-inc (aref psegtrees i) i 1))\n (unless (= +nan+ (aref appeared c))\n (setf (aref psegtrees (+ i 1))\n (psegtree-inc (aref psegtrees (+ i 1)) (aref appeared c) -1)))\n (setf (aref appeared c) i)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (loop for l across ls\n for r across rs\n for psegtree = (aref psegtrees r)\n do (println (psegtree-query psegtree l r)))))))\n\n\n;; #+linux\n;; (eval-when (:compile-toplevel :load-toplevel :execute)\n;; (require :sb-sprof))\n;; #+linux\n;; (sb-sprof:start-profiling)\n\n#-swank (main)\n\n;; #+linux\n;; (progn\n;; (sb-sprof:stop-profiling)\n;; (sb-sprof:report))\n\n#-swank (main)\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (let ((n 500000)\n (q 500000))\n (format out \"~D ~D~%\" n q)\n (dotimes (_ n)\n (println (+ 1 (random 500000)) out))\n (dotimes (_ q)\n (let ((l (+ 1 (random 500000)))\n (r (+ 1 (random 500000))))\n (when (> l r)\n (rotatef l r))\n (format out \"~D ~D~%\" l r))))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 3\n1 2 1 3\n1 3\n2 4\n3 3\n\"\n \"2\n3\n1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 10\n2 5 6 5 2 1 7 9 7 2\n5 5\n2 4\n6 7\n2 2\n7 8\n7 9\n1 8\n6 9\n8 10\n6 8\n\"\n \"1\n2\n2\n1\n2\n2\n6\n3\n3\n3\n\")))\n", "language": "Lisp", "metadata": {"date": 1596442298, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02599.html", "problem_id": "p02599", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02599/input.txt", "sample_output_relpath": "derived/input_output/data/p02599/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02599/Lisp/s011631574.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s011631574", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n3\n1\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Persistent segment tree\n;;;\n\n;; TODO:\n;; - abstraction\n;; - test\n;; - linear-time initialization\n;; - avoid sb-int:power-of-two-ceiling\n;; - out-of-bound error\n\n(defparameter *store* (make-array 200000000 :element-type 'uint31))\n(declaim ((simple-array uint31 (*)) *store*)\n (always-bound *store*))\n(defparameter *end* 0)\n(declaim ((mod #.array-total-size-limit) *end*)\n (always-bound *end*))\n\n(declaim (inline node-value))\n(defun node-value (node)\n (the uint31 (aref *store* node)))\n(declaim (inline (setf node-value)))\n(defun (setf node-value) (new-value node)\n (declare (uint31 new-value))\n (setf (aref *store* node) new-value))\n(declaim (inline node-left))\n(defun node-left (node)\n (declare ((mod #.array-total-size-limit) node))\n (aref *store* (+ node 1)))\n(declaim (inline (setf node-left)))\n(defun (setf node-left) (new-value node)\n (setf (aref *store* (+ node 1)) new-value))\n(declaim (inline node-right))\n(defun node-right (node)\n (declare ((mod #.array-total-size-limit) node))\n (aref *store* (+ node 2)))\n(declaim (inline (setf node-right)))\n(defun (setf node-right) (new-value node)\n (setf (aref *store* (+ node 2)) new-value))\n\n(declaim (inline make-node))\n(defun make-node (&optional (value 0))\n (let ((end *end*))\n (when (= end (length *store*))\n (setq *store* (adjust-array *store* (* 2 end))))\n (setf (aref *store* end) value)\n (incf *end* 3)\n end))\n\n(declaim (inline copy-node))\n(defun copy-node (node)\n (let ((end *end*))\n (when (= end (length *store*))\n (setq *store* (adjust-array *store* (* 2 end))))\n (setf (aref *store* end) (aref *store* node)\n (aref *store* (+ end 1)) (aref *store* (+ node 1))\n (aref *store* (+ end 2)) (aref *store* (+ node 2)))\n (incf *end* 3)\n end))\n\n(defstruct (psegtree (:constructor %make-psegtree)\n (:conc-name %psegtree-))\n (length 0 :type (mod #.array-total-size-limit))\n (root 0 :type (mod #.array-total-size-limit)))\n\n(defun make-psegtree (length)\n \"Note that the actual length becomes a power of two.\"\n (declare ((integer 0 #.most-positive-fixnum) length))\n (let ((n (ash 1 (integer-length (- length 1))))) ; power of two ceiling\n (labels ((recur (i)\n (declare (uint31 i))\n (if (<= i n)\n (let ((node (make-node)))\n (setf (node-left node) (recur (ash i 1))\n (node-right node) (recur (ash i 1)))\n node)\n 0)))\n (%make-psegtree :length length :root (recur 1)))))\n\n(defun psegtree-query (psegtree left right)\n \"Queries the sum of the interval [LEFT, RIGHT).\"\n (declare #.opt\n (uint31 left right))\n (labels ((recur (root l r)\n (declare (uint31 l r)\n (values uint31 &optional))\n (cond ((or (<= right l) (<= r left))\n 0)\n ((and (<= left l) (<= r right))\n (node-value root))\n (t\n (+ (recur (node-left root) l (ash (+ l r) -1))\n (recur (node-right root) (ash (+ l r) -1) r))))))\n (recur (%psegtree-root psegtree)\n 0\n (sb-int:power-of-two-ceiling (%psegtree-length psegtree)))))\n\n(defun psegtree-inc (psegtree index delta)\n \"Returns a new psegtree updated by PSEGTREE[INDEX] += DELTA. This function is\nnon-destructive.\"\n (declare #.opt\n (uint31 index)\n (int32 delta))\n (labels ((recur (root l r)\n (declare (int32 l r))\n (cond ((or (<= (+ index 1) l) (<= r index)))\n ((and (<= index l) (<= r (+ index 1)))\n (incf (node-value root) delta))\n (t\n (let ((new-lnode (copy-node (node-left root)))\n (new-rnode (copy-node (node-right root))))\n (setf (node-left root) new-lnode\n (node-right root) new-rnode)\n (recur new-lnode l (ash (+ l r) -1))\n (recur new-rnode (ash (+ l r) -1) r)\n (setf (node-value root)\n (+ (node-value (node-left root))\n (node-value (node-right root)))))))))\n (let ((new-psegtree (copy-psegtree psegtree))\n (new-root (copy-node (%psegtree-root psegtree))))\n (recur new-root 0 (sb-int:power-of-two-ceiling (%psegtree-length psegtree)))\n (setf (%psegtree-root new-psegtree) new-root)\n new-psegtree)))\n\n(defmethod print-object ((object psegtree) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t)\n (length (%psegtree-length object)))\n (labels ((recur (node index)\n (if (node-left node)\n (progn\n (recur (node-left node) (ash index 1))\n (recur (node-right node) (+ (ash index 1) 1)))\n (when (< index length)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write (node-value node) :stream stream)))))\n (recur (%psegtree-root object) 0)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +nan+ #x7fffffff)\n\n(defun main ()\n (declare #.opt)\n (let* ((n (read))\n (q (read))\n (cs (make-array n :element-type 'uint31 :initial-element 0))\n (ls (make-array q :element-type 'uint31 :initial-element 0))\n (rs (make-array q :element-type 'uint31 :initial-element 0))\n (appeared (make-array (+ n 1) :element-type 'uint31 :initial-element +nan+))\n (psegtrees (make-array (+ n 1) :element-type t)))\n (dotimes (i n)\n (setf (aref cs i) (read-fixnum)))\n (dotimes (i q)\n (setf (aref ls i) (- (read-fixnum) 1)\n (aref rs i) (read-fixnum)))\n (setf (aref psegtrees 0) (make-psegtree n))\n (dotimes (i n)\n (let ((c (aref cs i)))\n (setf (aref psegtrees (+ i 1))\n (psegtree-inc (aref psegtrees i) i 1))\n (unless (= +nan+ (aref appeared c))\n (setf (aref psegtrees (+ i 1))\n (psegtree-inc (aref psegtrees (+ i 1)) (aref appeared c) -1)))\n (setf (aref appeared c) i)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (loop for l across ls\n for r across rs\n for psegtree = (aref psegtrees r)\n do (println (psegtree-query psegtree l r)))))))\n\n\n;; #+linux\n;; (eval-when (:compile-toplevel :load-toplevel :execute)\n;; (require :sb-sprof))\n;; #+linux\n;; (sb-sprof:start-profiling)\n\n#-swank (main)\n\n;; #+linux\n;; (progn\n;; (sb-sprof:stop-profiling)\n;; (sb-sprof:report))\n\n#-swank (main)\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (let ((n 500000)\n (q 500000))\n (format out \"~D ~D~%\" n q)\n (dotimes (_ n)\n (println (+ 1 (random 500000)) out))\n (dotimes (_ q)\n (let ((l (+ 1 (random 500000)))\n (r (+ 1 (random 500000))))\n (when (> l r)\n (rotatef l r))\n (format out \"~D ~D~%\" l r))))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 3\n1 2 1 3\n1 3\n2 4\n3 3\n\"\n \"2\n3\n1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 10\n2 5 6 5 2 1 7 9 7 2\n5 5\n2 4\n6 7\n2 2\n7 8\n7 9\n1 8\n6 9\n8 10\n6 8\n\"\n \"1\n2\n2\n1\n2\n2\n6\n3\n3\n3\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nWe have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.\n\nYou are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have?\n\nConstraints\n\n1\\leq N,Q \\leq 5 \\times 10^5\n\n1\\leq c_i \\leq N\n\n1\\leq l_i \\leq r_i \\leq N\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nc_1 c_2 \\cdots c_N\nl_1 r_1\nl_2 r_2\n:\nl_Q r_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the response to the i-th query.\n\nSample Input 1\n\n4 3\n1 2 1 3\n1 3\n2 4\n3 3\n\nSample Output 1\n\n2\n3\n1\n\nThe 1-st, 2-nd, and 3-rd balls from the left have the colors 1, 2, and 1 - two different colors.\n\nThe 2-st, 3-rd, and 4-th balls from the left have the colors 2, 1, and 3 - three different colors.\n\nThe 3-rd ball from the left has the color 1 - just one color.\n\nSample Input 2\n\n10 10\n2 5 6 5 2 1 7 9 7 2\n5 5\n2 4\n6 7\n2 2\n7 8\n7 9\n1 8\n6 9\n8 10\n6 8\n\nSample Output 2\n\n1\n2\n2\n1\n2\n2\n6\n3\n3\n3", "sample_input": "4 3\n1 2 1 3\n1 3\n2 4\n3 3\n"}, "reference_outputs": ["2\n3\n1\n"], "source_document_id": "p02599", "source_text": "Score : 600 points\n\nProblem Statement\n\nWe have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.\n\nYou are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have?\n\nConstraints\n\n1\\leq N,Q \\leq 5 \\times 10^5\n\n1\\leq c_i \\leq N\n\n1\\leq l_i \\leq r_i \\leq N\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nc_1 c_2 \\cdots c_N\nl_1 r_1\nl_2 r_2\n:\nl_Q r_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the response to the i-th query.\n\nSample Input 1\n\n4 3\n1 2 1 3\n1 3\n2 4\n3 3\n\nSample Output 1\n\n2\n3\n1\n\nThe 1-st, 2-nd, and 3-rd balls from the left have the colors 1, 2, and 1 - two different colors.\n\nThe 2-st, 3-rd, and 4-th balls from the left have the colors 2, 1, and 3 - three different colors.\n\nThe 3-rd ball from the left has the color 1 - just one color.\n\nSample Input 2\n\n10 10\n2 5 6 5 2 1 7 9 7 2\n5 5\n2 4\n6 7\n2 2\n7 8\n7 9\n1 8\n6 9\n8 10\n6 8\n\nSample Output 2\n\n1\n2\n2\n1\n2\n2\n6\n3\n3\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11806, "cpu_time_ms": 1854, "memory_kb": 543200}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s646655072", "group_id": "codeNet:p02599", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Persistent segment tree\n;;;\n\n;; TODO:\n;; - abstraction\n;; - test\n;; - linear-time initialization\n;; - avoid sb-int:power-of-two-ceiling\n;; - out-of-bound error\n\n(defparameter *store* (make-array 120000000 :element-type t))\n(declaim ((simple-array t (*)) *store*)\n (always-bound *store*))\n(defparameter *end* 0)\n(declaim ((mod #.array-total-size-limit) *end*)\n (always-bound *end*))\n\n(declaim (inline node-value))\n(defun node-value (node)\n (the fixnum (aref *store* node)))\n(declaim (inline (setf node-value)))\n(defun (setf node-value) (new-value node)\n (declare (fixnum new-value))\n (setf (aref *store* node) new-value))\n(declaim (inline node-left))\n(defun node-left (node)\n (declare ((mod #.array-total-size-limit) node))\n (aref *store* (+ node 1)))\n(declaim (inline (setf node-left)))\n(defun (setf node-left) (new-value node)\n (setf (aref *store* (+ node 1)) new-value))\n(declaim (inline node-right))\n(defun node-right (node)\n (declare ((mod #.array-total-size-limit) node))\n (aref *store* (+ node 2)))\n(declaim (inline (setf node-right)))\n(defun (setf node-right) (new-value node)\n (setf (aref *store* (+ node 2)) new-value))\n\n(declaim (inline make-node))\n(defun make-node (&optional (value 0))\n (let ((end *end*))\n (when (= end (length *store*))\n (setq *store* (adjust-array *store* (* 2 end))))\n (setf (aref *store* end) value\n (aref *store* (+ end 1)) -1\n (aref *store* (+ end 2)) -1)\n (incf *end* 3)\n end))\n\n(declaim (inline copy-node))\n(defun copy-node (node)\n (let ((end *end*))\n (when (= end (length *store*))\n (setq *store* (adjust-array *store* (* 2 end))))\n (setf (aref *store* end) (aref *store* node)\n (aref *store* (+ end 1)) (aref *store* (+ node 1))\n (aref *store* (+ end 2)) (aref *store* (+ node 2)))\n (incf *end* 3)\n end))\n\n(defstruct (psegtree (:constructor %make-psegtree)\n (:conc-name %psegtree-))\n (length 0 :type (mod #.array-total-size-limit))\n (root 0 :type (mod #.array-total-size-limit)))\n\n(defun make-psegtree (length)\n \"Note that the actual length becomes a power of two.\"\n (declare ((integer 0 #.most-positive-fixnum) length))\n (let ((n (ash 1 (integer-length (- length 1))))) ; power of two ceiling\n (labels ((recur (i)\n (declare ((integer 0 #.most-positive-fixnum) i))\n (when (<= i n)\n (let ((node (make-node)))\n (setf (node-left node) (recur (ash i 1))\n (node-right node) (recur (ash i 1)))\n node))))\n (%make-psegtree :length length :root (recur 1)))))\n\n(defun psegtree-query (psegtree left right)\n \"Queries the sum of the interval [LEFT, RIGHT).\"\n (declare #.opt\n ((integer 0 #.most-positive-fixnum) left right))\n (labels ((recur (root l r)\n (declare ((integer 0 #.most-positive-fixnum) l r)\n (values fixnum &optional))\n (cond ((or (<= right l) (<= r left))\n 0)\n ((and (<= left l) (<= r right))\n (node-value root))\n (t\n (+ (recur (node-left root) l (ash (+ l r) -1))\n (recur (node-right root) (ash (+ l r) -1) r))))))\n (recur (%psegtree-root psegtree)\n 0\n (sb-int:power-of-two-ceiling (%psegtree-length psegtree)))))\n\n(defun psegtree-inc (psegtree index delta)\n \"Returns a new psegtree updated by PSEGTREE[INDEX] += DELTA. This function is\nnon-destructive.\"\n (declare #.opt\n ((integer 0 #.most-positive-fixnum) index)\n (fixnum delta))\n (labels ((recur (root l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (cond ((or (<= (+ index 1) l) (<= r index)))\n ((and (<= index l) (<= r (+ index 1)))\n (incf (node-value root) delta))\n (t\n (let ((new-lnode (copy-node (node-left root)))\n (new-rnode (copy-node (node-right root))))\n (setf (node-left root) new-lnode\n (node-right root) new-rnode)\n (recur new-lnode l (ash (+ l r) -1))\n (recur new-rnode (ash (+ l r) -1) r)\n (setf (node-value root)\n (+ (node-value (node-left root))\n (node-value (node-right root)))))))))\n (let ((new-psegtree (copy-psegtree psegtree))\n (new-root (copy-node (%psegtree-root psegtree))))\n (recur new-root 0 (sb-int:power-of-two-ceiling (%psegtree-length psegtree)))\n (setf (%psegtree-root new-psegtree) new-root)\n new-psegtree)))\n\n(defmethod print-object ((object psegtree) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t)\n (length (%psegtree-length object)))\n (labels ((recur (node index)\n (if (node-left node)\n (progn\n (recur (node-left node) (ash index 1))\n (recur (node-right node) (+ (ash index 1) 1)))\n (when (< index length)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write (node-value node) :stream stream)))))\n (recur (%psegtree-root object) 0)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +nan+ #x7fffffff)\n\n(defun main ()\n (declare #.opt)\n (let* ((n (read))\n (q (read))\n (cs (make-array n :element-type 'uint31 :initial-element 0))\n (ls (make-array q :element-type 'uint31 :initial-element 0))\n (rs (make-array q :element-type 'uint31 :initial-element 0))\n (appeared (make-array (+ n 1) :element-type 'uint31 :initial-element +nan+))\n (psegtrees (make-array (+ n 1) :element-type t)))\n (dotimes (i n)\n (setf (aref cs i) (read-fixnum)))\n (dotimes (i q)\n (setf (aref ls i) (- (read-fixnum) 1)\n (aref rs i) (read-fixnum)))\n (setf (aref psegtrees 0) (make-psegtree n))\n (dotimes (i n)\n (let ((c (aref cs i)))\n (setf (aref psegtrees (+ i 1))\n (psegtree-inc (aref psegtrees i) i 1))\n (unless (= +nan+ (aref appeared c))\n (setf (aref psegtrees (+ i 1))\n (psegtree-inc (aref psegtrees (+ i 1)) (aref appeared c) -1)))\n (setf (aref appeared c) i)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (loop for l across ls\n for r across rs\n for psegtree = (aref psegtrees r)\n do (println (psegtree-query psegtree l r)))))))\n\n\n;; #+linux\n;; (eval-when (:compile-toplevel :load-toplevel :execute)\n;; (require :sb-sprof))\n;; #+linux\n;; (sb-sprof:start-profiling)\n\n#-swank (main)\n\n;; #+linux\n;; (progn\n;; (sb-sprof:stop-profiling)\n;; (sb-sprof:report))\n\n#-swank (main)\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (let ((n 500000)\n (q 500000))\n (format out \"~D ~D~%\" n q)\n (dotimes (_ n)\n (println (+ 1 (random 500000)) out))\n (dotimes (_ q)\n (let ((l (+ 1 (random 500000)))\n (r (+ 1 (random 500000))))\n (when (> l r)\n (rotatef l r))\n (format out \"~D ~D~%\" l r))))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 3\n1 2 1 3\n1 3\n2 4\n3 3\n\"\n \"2\n3\n1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 10\n2 5 6 5 2 1 7 9 7 2\n5 5\n2 4\n6 7\n2 2\n7 8\n7 9\n1 8\n6 9\n8 10\n6 8\n\"\n \"1\n2\n2\n1\n2\n2\n6\n3\n3\n3\n\")))\n", "language": "Lisp", "metadata": {"date": 1596441933, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02599.html", "problem_id": "p02599", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02599/input.txt", "sample_output_relpath": "derived/input_output/data/p02599/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02599/Lisp/s646655072.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s646655072", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n3\n1\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Persistent segment tree\n;;;\n\n;; TODO:\n;; - abstraction\n;; - test\n;; - linear-time initialization\n;; - avoid sb-int:power-of-two-ceiling\n;; - out-of-bound error\n\n(defparameter *store* (make-array 120000000 :element-type t))\n(declaim ((simple-array t (*)) *store*)\n (always-bound *store*))\n(defparameter *end* 0)\n(declaim ((mod #.array-total-size-limit) *end*)\n (always-bound *end*))\n\n(declaim (inline node-value))\n(defun node-value (node)\n (the fixnum (aref *store* node)))\n(declaim (inline (setf node-value)))\n(defun (setf node-value) (new-value node)\n (declare (fixnum new-value))\n (setf (aref *store* node) new-value))\n(declaim (inline node-left))\n(defun node-left (node)\n (declare ((mod #.array-total-size-limit) node))\n (aref *store* (+ node 1)))\n(declaim (inline (setf node-left)))\n(defun (setf node-left) (new-value node)\n (setf (aref *store* (+ node 1)) new-value))\n(declaim (inline node-right))\n(defun node-right (node)\n (declare ((mod #.array-total-size-limit) node))\n (aref *store* (+ node 2)))\n(declaim (inline (setf node-right)))\n(defun (setf node-right) (new-value node)\n (setf (aref *store* (+ node 2)) new-value))\n\n(declaim (inline make-node))\n(defun make-node (&optional (value 0))\n (let ((end *end*))\n (when (= end (length *store*))\n (setq *store* (adjust-array *store* (* 2 end))))\n (setf (aref *store* end) value\n (aref *store* (+ end 1)) -1\n (aref *store* (+ end 2)) -1)\n (incf *end* 3)\n end))\n\n(declaim (inline copy-node))\n(defun copy-node (node)\n (let ((end *end*))\n (when (= end (length *store*))\n (setq *store* (adjust-array *store* (* 2 end))))\n (setf (aref *store* end) (aref *store* node)\n (aref *store* (+ end 1)) (aref *store* (+ node 1))\n (aref *store* (+ end 2)) (aref *store* (+ node 2)))\n (incf *end* 3)\n end))\n\n(defstruct (psegtree (:constructor %make-psegtree)\n (:conc-name %psegtree-))\n (length 0 :type (mod #.array-total-size-limit))\n (root 0 :type (mod #.array-total-size-limit)))\n\n(defun make-psegtree (length)\n \"Note that the actual length becomes a power of two.\"\n (declare ((integer 0 #.most-positive-fixnum) length))\n (let ((n (ash 1 (integer-length (- length 1))))) ; power of two ceiling\n (labels ((recur (i)\n (declare ((integer 0 #.most-positive-fixnum) i))\n (when (<= i n)\n (let ((node (make-node)))\n (setf (node-left node) (recur (ash i 1))\n (node-right node) (recur (ash i 1)))\n node))))\n (%make-psegtree :length length :root (recur 1)))))\n\n(defun psegtree-query (psegtree left right)\n \"Queries the sum of the interval [LEFT, RIGHT).\"\n (declare #.opt\n ((integer 0 #.most-positive-fixnum) left right))\n (labels ((recur (root l r)\n (declare ((integer 0 #.most-positive-fixnum) l r)\n (values fixnum &optional))\n (cond ((or (<= right l) (<= r left))\n 0)\n ((and (<= left l) (<= r right))\n (node-value root))\n (t\n (+ (recur (node-left root) l (ash (+ l r) -1))\n (recur (node-right root) (ash (+ l r) -1) r))))))\n (recur (%psegtree-root psegtree)\n 0\n (sb-int:power-of-two-ceiling (%psegtree-length psegtree)))))\n\n(defun psegtree-inc (psegtree index delta)\n \"Returns a new psegtree updated by PSEGTREE[INDEX] += DELTA. This function is\nnon-destructive.\"\n (declare #.opt\n ((integer 0 #.most-positive-fixnum) index)\n (fixnum delta))\n (labels ((recur (root l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (cond ((or (<= (+ index 1) l) (<= r index)))\n ((and (<= index l) (<= r (+ index 1)))\n (incf (node-value root) delta))\n (t\n (let ((new-lnode (copy-node (node-left root)))\n (new-rnode (copy-node (node-right root))))\n (setf (node-left root) new-lnode\n (node-right root) new-rnode)\n (recur new-lnode l (ash (+ l r) -1))\n (recur new-rnode (ash (+ l r) -1) r)\n (setf (node-value root)\n (+ (node-value (node-left root))\n (node-value (node-right root)))))))))\n (let ((new-psegtree (copy-psegtree psegtree))\n (new-root (copy-node (%psegtree-root psegtree))))\n (recur new-root 0 (sb-int:power-of-two-ceiling (%psegtree-length psegtree)))\n (setf (%psegtree-root new-psegtree) new-root)\n new-psegtree)))\n\n(defmethod print-object ((object psegtree) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t)\n (length (%psegtree-length object)))\n (labels ((recur (node index)\n (if (node-left node)\n (progn\n (recur (node-left node) (ash index 1))\n (recur (node-right node) (+ (ash index 1) 1)))\n (when (< index length)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write (node-value node) :stream stream)))))\n (recur (%psegtree-root object) 0)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +nan+ #x7fffffff)\n\n(defun main ()\n (declare #.opt)\n (let* ((n (read))\n (q (read))\n (cs (make-array n :element-type 'uint31 :initial-element 0))\n (ls (make-array q :element-type 'uint31 :initial-element 0))\n (rs (make-array q :element-type 'uint31 :initial-element 0))\n (appeared (make-array (+ n 1) :element-type 'uint31 :initial-element +nan+))\n (psegtrees (make-array (+ n 1) :element-type t)))\n (dotimes (i n)\n (setf (aref cs i) (read-fixnum)))\n (dotimes (i q)\n (setf (aref ls i) (- (read-fixnum) 1)\n (aref rs i) (read-fixnum)))\n (setf (aref psegtrees 0) (make-psegtree n))\n (dotimes (i n)\n (let ((c (aref cs i)))\n (setf (aref psegtrees (+ i 1))\n (psegtree-inc (aref psegtrees i) i 1))\n (unless (= +nan+ (aref appeared c))\n (setf (aref psegtrees (+ i 1))\n (psegtree-inc (aref psegtrees (+ i 1)) (aref appeared c) -1)))\n (setf (aref appeared c) i)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (loop for l across ls\n for r across rs\n for psegtree = (aref psegtrees r)\n do (println (psegtree-query psegtree l r)))))))\n\n\n;; #+linux\n;; (eval-when (:compile-toplevel :load-toplevel :execute)\n;; (require :sb-sprof))\n;; #+linux\n;; (sb-sprof:start-profiling)\n\n#-swank (main)\n\n;; #+linux\n;; (progn\n;; (sb-sprof:stop-profiling)\n;; (sb-sprof:report))\n\n#-swank (main)\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (let ((n 500000)\n (q 500000))\n (format out \"~D ~D~%\" n q)\n (dotimes (_ n)\n (println (+ 1 (random 500000)) out))\n (dotimes (_ q)\n (let ((l (+ 1 (random 500000)))\n (r (+ 1 (random 500000))))\n (when (> l r)\n (rotatef l r))\n (format out \"~D ~D~%\" l r))))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 3\n1 2 1 3\n1 3\n2 4\n3 3\n\"\n \"2\n3\n1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 10\n2 5 6 5 2 1 7 9 7 2\n5 5\n2 4\n6 7\n2 2\n7 8\n7 9\n1 8\n6 9\n8 10\n6 8\n\"\n \"1\n2\n2\n1\n2\n2\n6\n3\n3\n3\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nWe have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.\n\nYou are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have?\n\nConstraints\n\n1\\leq N,Q \\leq 5 \\times 10^5\n\n1\\leq c_i \\leq N\n\n1\\leq l_i \\leq r_i \\leq N\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nc_1 c_2 \\cdots c_N\nl_1 r_1\nl_2 r_2\n:\nl_Q r_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the response to the i-th query.\n\nSample Input 1\n\n4 3\n1 2 1 3\n1 3\n2 4\n3 3\n\nSample Output 1\n\n2\n3\n1\n\nThe 1-st, 2-nd, and 3-rd balls from the left have the colors 1, 2, and 1 - two different colors.\n\nThe 2-st, 3-rd, and 4-th balls from the left have the colors 2, 1, and 3 - three different colors.\n\nThe 3-rd ball from the left has the color 1 - just one color.\n\nSample Input 2\n\n10 10\n2 5 6 5 2 1 7 9 7 2\n5 5\n2 4\n6 7\n2 2\n7 8\n7 9\n1 8\n6 9\n8 10\n6 8\n\nSample Output 2\n\n1\n2\n2\n1\n2\n2\n6\n3\n3\n3", "sample_input": "4 3\n1 2 1 3\n1 3\n2 4\n3 3\n"}, "reference_outputs": ["2\n3\n1\n"], "source_document_id": "p02599", "source_text": "Score : 600 points\n\nProblem Statement\n\nWe have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.\n\nYou are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have?\n\nConstraints\n\n1\\leq N,Q \\leq 5 \\times 10^5\n\n1\\leq c_i \\leq N\n\n1\\leq l_i \\leq r_i \\leq N\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nc_1 c_2 \\cdots c_N\nl_1 r_1\nl_2 r_2\n:\nl_Q r_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the response to the i-th query.\n\nSample Input 1\n\n4 3\n1 2 1 3\n1 3\n2 4\n3 3\n\nSample Output 1\n\n2\n3\n1\n\nThe 1-st, 2-nd, and 3-rd balls from the left have the colors 1, 2, and 1 - two different colors.\n\nThe 2-st, 3-rd, and 4-th balls from the left have the colors 2, 1, and 3 - three different colors.\n\nThe 3-rd ball from the left has the color 1 - just one color.\n\nSample Input 2\n\n10 10\n2 5 6 5 2 1 7 9 7 2\n5 5\n2 4\n6 7\n2 2\n7 8\n7 9\n1 8\n6 9\n8 10\n6 8\n\nSample Output 2\n\n1\n2\n2\n1\n2\n2\n6\n3\n3\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11986, "cpu_time_ms": 2227, "memory_kb": 1021660}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s756047757", "group_id": "codeNet:p02599", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Persistent segment tree\n;;;\n\n;; TODO:\n;; - abstraction\n;; - test\n;; - linear-time initialization\n;; - avoid sb-int:power-of-two-ceiling\n;; - out-of-bound error\n\n(declaim (inline make-node))\n(defstruct (node (:constructor make-node (&optional (value 0))))\n (value 0 :type fixnum)\n (left nil :type (or null node))\n (right nil :type (or null node)))\n\n(defstruct (psegtree (:constructor %make-psegtree)\n (:conc-name %psegtree-))\n (length 0 :type (integer 0 #.most-positive-fixnum))\n (root nil :type node))\n\n(defun make-psegtree (length)\n \"Note that the actual length becomes a power of two.\"\n (declare ((integer 0 #.most-positive-fixnum) length))\n (let ((n (ash 1 (integer-length (- length 1))))) ; power of two ceiling\n (labels ((recur (i)\n (declare ((integer 0 #.most-positive-fixnum) i))\n (when (<= i n)\n (let ((node (make-node)))\n (setf (node-left node) (recur (ash i 1))\n (node-right node) (recur (ash i 1)))\n node))))\n (%make-psegtree :length length :root (recur 1)))))\n\n(defun psegtree-query (psegtree left right)\n \"Queries the sum of the interval [LEFT, RIGHT).\"\n (declare #.opt\n ((integer 0 #.most-positive-fixnum) left right))\n (labels ((recur (root l r)\n (declare ((integer 0 #.most-positive-fixnum) l r)\n (values fixnum &optional))\n (cond ((or (<= right l) (<= r left))\n 0)\n ((and (<= left l) (<= r right))\n (node-value root))\n (t\n (+ (recur (node-left root) l (ash (+ l r) -1))\n (recur (node-right root) (ash (+ l r) -1) r))))))\n (recur (%psegtree-root psegtree)\n 0\n (sb-int:power-of-two-ceiling (%psegtree-length psegtree)))))\n\n(defun psegtree-inc (psegtree index delta)\n \"Returns a new psegtree updated by PSEGTREE[INDEX] += DELTA. This function is\nnon-destructive.\"\n (declare #.opt\n ((integer 0 #.most-positive-fixnum) index)\n (fixnum delta))\n (labels ((recur (root l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (cond ((or (<= (+ index 1) l) (<= r index)))\n ((and (<= index l) (<= r (+ index 1)))\n (incf (node-value root) delta))\n (t\n (let ((new-lnode (copy-node (node-left root)))\n (new-rnode (copy-node (node-right root))))\n (setf (node-left root) new-lnode\n (node-right root) new-rnode)\n (recur new-lnode l (ash (+ l r) -1))\n (recur new-rnode (ash (+ l r) -1) r)\n (setf (node-value root)\n (+ (node-value (node-left root))\n (node-value (node-right root)))))))))\n (let ((new-psegtree (copy-psegtree psegtree))\n (new-root (copy-node (%psegtree-root psegtree))))\n (recur new-root 0 (sb-int:power-of-two-ceiling (%psegtree-length psegtree)))\n (setf (%psegtree-root new-psegtree) new-root)\n new-psegtree)))\n\n(defmethod print-object ((object psegtree) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t)\n (length (%psegtree-length object)))\n (labels ((recur (node index)\n (if (node-left node)\n (progn\n (recur (node-left node) (ash index 1))\n (recur (node-right node) (+ (ash index 1) 1)))\n (when (< index length)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write (node-value node) :stream stream)))))\n (recur (%psegtree-root object) 0)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +nan+ #x7fffffff)\n\n(defun main ()\n (declare #.opt)\n (let* ((n (read))\n (q (read))\n (cs (make-array n :element-type 'uint31 :initial-element 0))\n (ls (make-array q :element-type 'uint31 :initial-element 0))\n (rs (make-array q :element-type 'uint31 :initial-element 0))\n (appeared (make-array (+ n 1) :element-type 'uint31 :initial-element +nan+))\n (psegtrees (make-array (+ n 1) :element-type t)))\n (dotimes (i n)\n (setf (aref cs i) (read-fixnum)))\n (dotimes (i q)\n (setf (aref ls i) (- (read-fixnum) 1)\n (aref rs i) (read-fixnum)))\n (setf (aref psegtrees 0) (make-psegtree n))\n (dotimes (i n)\n (let ((c (aref cs i)))\n (setf (aref psegtrees (+ i 1))\n (psegtree-inc (aref psegtrees i) i 1))\n (unless (= +nan+ (aref appeared c))\n (setf (aref psegtrees (+ i 1))\n (psegtree-inc (aref psegtrees (+ i 1)) (aref appeared c) -1)))\n (setf (aref appeared c) i)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (loop for l across ls\n for r across rs\n for psegtree = (aref psegtrees r)\n do (println (psegtree-query psegtree l r)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 3\n1 2 1 3\n1 3\n2 4\n3 3\n\"\n \"2\n3\n1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 10\n2 5 6 5 2 1 7 9 7 2\n5 5\n2 4\n6 7\n2 2\n7 8\n7 9\n1 8\n6 9\n8 10\n6 8\n\"\n \"1\n2\n2\n1\n2\n2\n6\n3\n3\n3\n\")))\n", "language": "Lisp", "metadata": {"date": 1596426915, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02599.html", "problem_id": "p02599", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02599/input.txt", "sample_output_relpath": "derived/input_output/data/p02599/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02599/Lisp/s756047757.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s756047757", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n3\n1\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Persistent segment tree\n;;;\n\n;; TODO:\n;; - abstraction\n;; - test\n;; - linear-time initialization\n;; - avoid sb-int:power-of-two-ceiling\n;; - out-of-bound error\n\n(declaim (inline make-node))\n(defstruct (node (:constructor make-node (&optional (value 0))))\n (value 0 :type fixnum)\n (left nil :type (or null node))\n (right nil :type (or null node)))\n\n(defstruct (psegtree (:constructor %make-psegtree)\n (:conc-name %psegtree-))\n (length 0 :type (integer 0 #.most-positive-fixnum))\n (root nil :type node))\n\n(defun make-psegtree (length)\n \"Note that the actual length becomes a power of two.\"\n (declare ((integer 0 #.most-positive-fixnum) length))\n (let ((n (ash 1 (integer-length (- length 1))))) ; power of two ceiling\n (labels ((recur (i)\n (declare ((integer 0 #.most-positive-fixnum) i))\n (when (<= i n)\n (let ((node (make-node)))\n (setf (node-left node) (recur (ash i 1))\n (node-right node) (recur (ash i 1)))\n node))))\n (%make-psegtree :length length :root (recur 1)))))\n\n(defun psegtree-query (psegtree left right)\n \"Queries the sum of the interval [LEFT, RIGHT).\"\n (declare #.opt\n ((integer 0 #.most-positive-fixnum) left right))\n (labels ((recur (root l r)\n (declare ((integer 0 #.most-positive-fixnum) l r)\n (values fixnum &optional))\n (cond ((or (<= right l) (<= r left))\n 0)\n ((and (<= left l) (<= r right))\n (node-value root))\n (t\n (+ (recur (node-left root) l (ash (+ l r) -1))\n (recur (node-right root) (ash (+ l r) -1) r))))))\n (recur (%psegtree-root psegtree)\n 0\n (sb-int:power-of-two-ceiling (%psegtree-length psegtree)))))\n\n(defun psegtree-inc (psegtree index delta)\n \"Returns a new psegtree updated by PSEGTREE[INDEX] += DELTA. This function is\nnon-destructive.\"\n (declare #.opt\n ((integer 0 #.most-positive-fixnum) index)\n (fixnum delta))\n (labels ((recur (root l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (cond ((or (<= (+ index 1) l) (<= r index)))\n ((and (<= index l) (<= r (+ index 1)))\n (incf (node-value root) delta))\n (t\n (let ((new-lnode (copy-node (node-left root)))\n (new-rnode (copy-node (node-right root))))\n (setf (node-left root) new-lnode\n (node-right root) new-rnode)\n (recur new-lnode l (ash (+ l r) -1))\n (recur new-rnode (ash (+ l r) -1) r)\n (setf (node-value root)\n (+ (node-value (node-left root))\n (node-value (node-right root)))))))))\n (let ((new-psegtree (copy-psegtree psegtree))\n (new-root (copy-node (%psegtree-root psegtree))))\n (recur new-root 0 (sb-int:power-of-two-ceiling (%psegtree-length psegtree)))\n (setf (%psegtree-root new-psegtree) new-root)\n new-psegtree)))\n\n(defmethod print-object ((object psegtree) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t)\n (length (%psegtree-length object)))\n (labels ((recur (node index)\n (if (node-left node)\n (progn\n (recur (node-left node) (ash index 1))\n (recur (node-right node) (+ (ash index 1) 1)))\n (when (< index length)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write (node-value node) :stream stream)))))\n (recur (%psegtree-root object) 0)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +nan+ #x7fffffff)\n\n(defun main ()\n (declare #.opt)\n (let* ((n (read))\n (q (read))\n (cs (make-array n :element-type 'uint31 :initial-element 0))\n (ls (make-array q :element-type 'uint31 :initial-element 0))\n (rs (make-array q :element-type 'uint31 :initial-element 0))\n (appeared (make-array (+ n 1) :element-type 'uint31 :initial-element +nan+))\n (psegtrees (make-array (+ n 1) :element-type t)))\n (dotimes (i n)\n (setf (aref cs i) (read-fixnum)))\n (dotimes (i q)\n (setf (aref ls i) (- (read-fixnum) 1)\n (aref rs i) (read-fixnum)))\n (setf (aref psegtrees 0) (make-psegtree n))\n (dotimes (i n)\n (let ((c (aref cs i)))\n (setf (aref psegtrees (+ i 1))\n (psegtree-inc (aref psegtrees i) i 1))\n (unless (= +nan+ (aref appeared c))\n (setf (aref psegtrees (+ i 1))\n (psegtree-inc (aref psegtrees (+ i 1)) (aref appeared c) -1)))\n (setf (aref appeared c) i)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (loop for l across ls\n for r across rs\n for psegtree = (aref psegtrees r)\n do (println (psegtree-query psegtree l r)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 3\n1 2 1 3\n1 3\n2 4\n3 3\n\"\n \"2\n3\n1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 10\n2 5 6 5 2 1 7 9 7 2\n5 5\n2 4\n6 7\n2 2\n7 8\n7 9\n1 8\n6 9\n8 10\n6 8\n\"\n \"1\n2\n2\n1\n2\n2\n6\n3\n3\n3\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nWe have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.\n\nYou are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have?\n\nConstraints\n\n1\\leq N,Q \\leq 5 \\times 10^5\n\n1\\leq c_i \\leq N\n\n1\\leq l_i \\leq r_i \\leq N\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nc_1 c_2 \\cdots c_N\nl_1 r_1\nl_2 r_2\n:\nl_Q r_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the response to the i-th query.\n\nSample Input 1\n\n4 3\n1 2 1 3\n1 3\n2 4\n3 3\n\nSample Output 1\n\n2\n3\n1\n\nThe 1-st, 2-nd, and 3-rd balls from the left have the colors 1, 2, and 1 - two different colors.\n\nThe 2-st, 3-rd, and 4-th balls from the left have the colors 2, 1, and 3 - three different colors.\n\nThe 3-rd ball from the left has the color 1 - just one color.\n\nSample Input 2\n\n10 10\n2 5 6 5 2 1 7 9 7 2\n5 5\n2 4\n6 7\n2 2\n7 8\n7 9\n1 8\n6 9\n8 10\n6 8\n\nSample Output 2\n\n1\n2\n2\n1\n2\n2\n6\n3\n3\n3", "sample_input": "4 3\n1 2 1 3\n1 3\n2 4\n3 3\n"}, "reference_outputs": ["2\n3\n1\n"], "source_document_id": "p02599", "source_text": "Score : 600 points\n\nProblem Statement\n\nWe have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.\n\nYou are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have?\n\nConstraints\n\n1\\leq N,Q \\leq 5 \\times 10^5\n\n1\\leq c_i \\leq N\n\n1\\leq l_i \\leq r_i \\leq N\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nc_1 c_2 \\cdots c_N\nl_1 r_1\nl_2 r_2\n:\nl_Q r_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the response to the i-th query.\n\nSample Input 1\n\n4 3\n1 2 1 3\n1 3\n2 4\n3 3\n\nSample Output 1\n\n2\n3\n1\n\nThe 1-st, 2-nd, and 3-rd balls from the left have the colors 1, 2, and 1 - two different colors.\n\nThe 2-st, 3-rd, and 4-th balls from the left have the colors 2, 1, and 3 - three different colors.\n\nThe 3-rd ball from the left has the color 1 - just one color.\n\nSample Input 2\n\n10 10\n2 5 6 5 2 1 7 9 7 2\n5 5\n2 4\n6 7\n2 2\n7 8\n7 9\n1 8\n6 9\n8 10\n6 8\n\nSample Output 2\n\n1\n2\n2\n1\n2\n2\n6\n3\n3\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9961, "cpu_time_ms": 2227, "memory_kb": 743952}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s861004886", "group_id": "codeNet:p02600", "input_text": "(defun main ()\n (let ((x (read))\n\t(ans))\n (cond ((and (<= 400 x) (>= 599 x)) (setf ans 8))\n\t ((and (<= 600 x) (>= 799 x)) (setf ans 7))\n\t ((and (<= 800 x) (>= 999 x)) (setf ans 6))\n\t ((and (<= 1000 x) (>= 1199 x)) (setf ans 5))\n\t ((and (<= 1200 x) (>= 1399 x)) (setf ans 4))\n\t ((and (<= 1400 x) (>= 1599 x)) (setf ans 3))\n\t ((and (<= 1600 x) (>= 1799 x)) (setf ans 2))\n\t (t (setf ans 1)))\n (format t \"~a~%\" ans)))\n(main)", "language": "Lisp", "metadata": {"date": 1595725820, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02600.html", "problem_id": "p02600", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02600/input.txt", "sample_output_relpath": "derived/input_output/data/p02600/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02600/Lisp/s861004886.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s861004886", "user_id": "u091381267"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(defun main ()\n (let ((x (read))\n\t(ans))\n (cond ((and (<= 400 x) (>= 599 x)) (setf ans 8))\n\t ((and (<= 600 x) (>= 799 x)) (setf ans 7))\n\t ((and (<= 800 x) (>= 999 x)) (setf ans 6))\n\t ((and (<= 1000 x) (>= 1199 x)) (setf ans 5))\n\t ((and (<= 1200 x) (>= 1399 x)) (setf ans 4))\n\t ((and (<= 1400 x) (>= 1599 x)) (setf ans 3))\n\t ((and (<= 1600 x) (>= 1799 x)) (setf ans 2))\n\t (t (setf ans 1)))\n (format t \"~a~%\" ans)))\n(main)", "problem_context": "Score: 100 points\n\nProblem Statement\n\nM-kun is a competitor in AtCoder, whose highest rating is X.\n\nIn this site, a competitor is given a kyu (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given:\n\nFrom 400 through 599: 8-kyu\n\nFrom 600 through 799: 7-kyu\n\nFrom 800 through 999: 6-kyu\n\nFrom 1000 through 1199: 5-kyu\n\nFrom 1200 through 1399: 4-kyu\n\nFrom 1400 through 1599: 3-kyu\n\nFrom 1600 through 1799: 2-kyu\n\nFrom 1800 through 1999: 1-kyu\n\nWhat kyu does M-kun have?\n\nConstraints\n\n400 \\leq X \\leq 1999\n\nX is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the kyu M-kun has, as an integer.\nFor example, if he has 8-kyu, print 8.\n\nSample Input 1\n\n725\n\nSample Output 1\n\n7\n\nM-kun's highest rating is 725, which corresponds to 7-kyu.\n\nThus, 7 is the correct output.\n\nSample Input 2\n\n1600\n\nSample Output 2\n\n2\n\nM-kun's highest rating is 1600, which corresponds to 2-kyu.\n\nThus, 2 is the correct output.", "sample_input": "725\n"}, "reference_outputs": ["7\n"], "source_document_id": "p02600", "source_text": "Score: 100 points\n\nProblem Statement\n\nM-kun is a competitor in AtCoder, whose highest rating is X.\n\nIn this site, a competitor is given a kyu (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given:\n\nFrom 400 through 599: 8-kyu\n\nFrom 600 through 799: 7-kyu\n\nFrom 800 through 999: 6-kyu\n\nFrom 1000 through 1199: 5-kyu\n\nFrom 1200 through 1399: 4-kyu\n\nFrom 1400 through 1599: 3-kyu\n\nFrom 1600 through 1799: 2-kyu\n\nFrom 1800 through 1999: 1-kyu\n\nWhat kyu does M-kun have?\n\nConstraints\n\n400 \\leq X \\leq 1999\n\nX is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the kyu M-kun has, as an integer.\nFor example, if he has 8-kyu, print 8.\n\nSample Input 1\n\n725\n\nSample Output 1\n\n7\n\nM-kun's highest rating is 725, which corresponds to 7-kyu.\n\nThus, 7 is the correct output.\n\nSample Input 2\n\n1600\n\nSample Output 2\n\n2\n\nM-kun's highest rating is 1600, which corresponds to 2-kyu.\n\nThus, 2 is the correct output.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 434, "cpu_time_ms": 23, "memory_kb": 24384}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s276734591", "group_id": "codeNet:p02600", "input_text": "(let ((x (read)))\n (if (and (<= 400 x) (> 600 x ))\n (princ \"8\")\n )\n (if (and (<= 600 x) (> 800 x ))\n (princ \"7\")\n )\n (if (and (<= 800 x) (> 1000 x ))\n (princ \"6\")\n )\n (if (and (<= 1000 x) (> 1200 x ))\n (princ \"5\")\n )\n (if (and (<= 1200 x) (> 1400 x ))\n (princ \"4\")\n )\n (if (and (<= 1400 x) (> 1600 x ))\n (princ \"3\")\n )\n (if (and (<= 1600 x) (> 1800 x ))\n (princ \"2\")\n )\n (if (and (<= 1800 x) (> 2000 x ))\n (princ \"1\")\n )\n)", "language": "Lisp", "metadata": {"date": 1595725447, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02600.html", "problem_id": "p02600", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02600/input.txt", "sample_output_relpath": "derived/input_output/data/p02600/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02600/Lisp/s276734591.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s276734591", "user_id": "u136500538"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(let ((x (read)))\n (if (and (<= 400 x) (> 600 x ))\n (princ \"8\")\n )\n (if (and (<= 600 x) (> 800 x ))\n (princ \"7\")\n )\n (if (and (<= 800 x) (> 1000 x ))\n (princ \"6\")\n )\n (if (and (<= 1000 x) (> 1200 x ))\n (princ \"5\")\n )\n (if (and (<= 1200 x) (> 1400 x ))\n (princ \"4\")\n )\n (if (and (<= 1400 x) (> 1600 x ))\n (princ \"3\")\n )\n (if (and (<= 1600 x) (> 1800 x ))\n (princ \"2\")\n )\n (if (and (<= 1800 x) (> 2000 x ))\n (princ \"1\")\n )\n)", "problem_context": "Score: 100 points\n\nProblem Statement\n\nM-kun is a competitor in AtCoder, whose highest rating is X.\n\nIn this site, a competitor is given a kyu (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given:\n\nFrom 400 through 599: 8-kyu\n\nFrom 600 through 799: 7-kyu\n\nFrom 800 through 999: 6-kyu\n\nFrom 1000 through 1199: 5-kyu\n\nFrom 1200 through 1399: 4-kyu\n\nFrom 1400 through 1599: 3-kyu\n\nFrom 1600 through 1799: 2-kyu\n\nFrom 1800 through 1999: 1-kyu\n\nWhat kyu does M-kun have?\n\nConstraints\n\n400 \\leq X \\leq 1999\n\nX is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the kyu M-kun has, as an integer.\nFor example, if he has 8-kyu, print 8.\n\nSample Input 1\n\n725\n\nSample Output 1\n\n7\n\nM-kun's highest rating is 725, which corresponds to 7-kyu.\n\nThus, 7 is the correct output.\n\nSample Input 2\n\n1600\n\nSample Output 2\n\n2\n\nM-kun's highest rating is 1600, which corresponds to 2-kyu.\n\nThus, 2 is the correct output.", "sample_input": "725\n"}, "reference_outputs": ["7\n"], "source_document_id": "p02600", "source_text": "Score: 100 points\n\nProblem Statement\n\nM-kun is a competitor in AtCoder, whose highest rating is X.\n\nIn this site, a competitor is given a kyu (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given:\n\nFrom 400 through 599: 8-kyu\n\nFrom 600 through 799: 7-kyu\n\nFrom 800 through 999: 6-kyu\n\nFrom 1000 through 1199: 5-kyu\n\nFrom 1200 through 1399: 4-kyu\n\nFrom 1400 through 1599: 3-kyu\n\nFrom 1600 through 1799: 2-kyu\n\nFrom 1800 through 1999: 1-kyu\n\nWhat kyu does M-kun have?\n\nConstraints\n\n400 \\leq X \\leq 1999\n\nX is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the kyu M-kun has, as an integer.\nFor example, if he has 8-kyu, print 8.\n\nSample Input 1\n\n725\n\nSample Output 1\n\n7\n\nM-kun's highest rating is 725, which corresponds to 7-kyu.\n\nThus, 7 is the correct output.\n\nSample Input 2\n\n1600\n\nSample Output 2\n\n2\n\nM-kun's highest rating is 1600, which corresponds to 2-kyu.\n\nThus, 2 is the correct output.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 526, "cpu_time_ms": 19, "memory_kb": 24228}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s703045807", "group_id": "codeNet:p02601", "input_text": "(let ((a (read))\n (b (read))\n (c (read))\n (k (read))\n (ans \"No\"))\n (loop for i below k do\n (if (>= a b)\n (setq b (* b 2))\n (if (>= b c)\n (setq c (* c 2))\n )\n )\n (if (and (< a b) (< b c))\n (progn\n (setq ans \"Yes\")\n (return)\n )\n )\n )\n (princ ans)\n)", "language": "Lisp", "metadata": {"date": 1595725936, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02601.html", "problem_id": "p02601", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02601/input.txt", "sample_output_relpath": "derived/input_output/data/p02601/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02601/Lisp/s703045807.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s703045807", "user_id": "u136500538"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (c (read))\n (k (read))\n (ans \"No\"))\n (loop for i below k do\n (if (>= a b)\n (setq b (* b 2))\n (if (>= b c)\n (setq c (* c 2))\n )\n )\n (if (and (< a b) (< b c))\n (progn\n (setq ans \"Yes\")\n (return)\n )\n )\n )\n (princ ans)\n)", "problem_context": "Score: 200 points\n\nProblem Statement\n\nM-kun has the following three cards:\n\nA red card with the integer A.\n\nA green card with the integer B.\n\nA blue card with the integer C.\n\nHe is a genius magician who can do the following operation at most K times:\n\nChoose one of the three cards and multiply the written integer by 2.\n\nHis magic is successful if both of the following conditions are satisfied after the operations:\n\nThe integer on the green card is strictly greater than the integer on the red card.\n\nThe integer on the blue card is strictly greater than the integer on the green card.\n\nDetermine whether the magic can be successful.\n\nConstraints\n\n1 \\leq A, B, C \\leq 7\n\n1 \\leq K \\leq 7\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\nK\n\nOutput\n\nIf the magic can be successful, print Yes; otherwise, print No.\n\nSample Input 1\n\n7 2 5\n3\n\nSample Output 1\n\nYes\n\nThe magic will be successful if, for example, he does the following operations:\n\nFirst, choose the blue card. The integers on the red, green, and blue cards are now 7, 2, and 10, respectively.\n\nSecond, choose the green card. The integers on the red, green, and blue cards are now 7, 4, and 10, respectively.\n\nThird, choose the green card. The integers on the red, green, and blue cards are now 7, 8, and 10, respectively.\n\nSample Input 2\n\n7 4 2\n3\n\nSample Output 2\n\nNo\n\nHe has no way to succeed in the magic with at most three operations.", "sample_input": "7 2 5\n3\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02601", "source_text": "Score: 200 points\n\nProblem Statement\n\nM-kun has the following three cards:\n\nA red card with the integer A.\n\nA green card with the integer B.\n\nA blue card with the integer C.\n\nHe is a genius magician who can do the following operation at most K times:\n\nChoose one of the three cards and multiply the written integer by 2.\n\nHis magic is successful if both of the following conditions are satisfied after the operations:\n\nThe integer on the green card is strictly greater than the integer on the red card.\n\nThe integer on the blue card is strictly greater than the integer on the green card.\n\nDetermine whether the magic can be successful.\n\nConstraints\n\n1 \\leq A, B, C \\leq 7\n\n1 \\leq K \\leq 7\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\nK\n\nOutput\n\nIf the magic can be successful, print Yes; otherwise, print No.\n\nSample Input 1\n\n7 2 5\n3\n\nSample Output 1\n\nYes\n\nThe magic will be successful if, for example, he does the following operations:\n\nFirst, choose the blue card. The integers on the red, green, and blue cards are now 7, 2, and 10, respectively.\n\nSecond, choose the green card. The integers on the red, green, and blue cards are now 7, 4, and 10, respectively.\n\nThird, choose the green card. The integers on the red, green, and blue cards are now 7, 8, and 10, respectively.\n\nSample Input 2\n\n7 4 2\n3\n\nSample Output 2\n\nNo\n\nHe has no way to succeed in the magic with at most three operations.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 395, "cpu_time_ms": 17, "memory_kb": 23608}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s134619680", "group_id": "codeNet:p02602", "input_text": "#|\n------------------------------------\n| Utils |\n------------------------------------\n|#\n\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n(defconstant +mod+ 1000000007)\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n\n(defmacro read-numbers-to-list (size)\n `(loop repeat ,size collect (read)))\n\n\n(defmacro read-numbers-to-array (size)\n (let ((i (gensym))\n (arr (gensym)))\n `(let ((,arr (make-array ,size\n :element-type 'fixnum)))\n (declare ((array fixnum 1) ,arr))\n (loop for ,i of-type fixnum below ,size do\n (setf (aref ,arr ,i) (read))\n finally\n (return ,arr)))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(defun unwrap (list)\n (format nil \"~{~a~^ ~}\" list))\n\n\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n\n\n\n\n#|\n------------------------------------\n| Body |\n------------------------------------\n|#\n\n(declaim (ftype (function (fixnum fixnum (array fixnum 1)) list)))\n(defun solve (n k a)\n (declare (fixnum n k)\n ((array fixnum 1) a))\n (loop for i below (- n k) collect\n (if (< (aref a i) (aref a (+ i k)))\n \"Yes\"\n \"No\")))\n\n\n(defun main ()\n (declare #.OPT)\n (let ((n (read))\n (k (read)))\n (declare (fixnum n k))\n (let ((a (read-numbers-to-array n)))\n (declare ((array fixnum 1) a))\n (princ-for-each-line (solve n k a)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1600272460, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02602.html", "problem_id": "p02602", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02602/input.txt", "sample_output_relpath": "derived/input_output/data/p02602/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02602/Lisp/s134619680.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s134619680", "user_id": "u425762225"}, "prompt_components": {"gold_output": "Yes\nNo\n", "input_to_evaluate": "#|\n------------------------------------\n| Utils |\n------------------------------------\n|#\n\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n(defconstant +mod+ 1000000007)\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n\n(defmacro read-numbers-to-list (size)\n `(loop repeat ,size collect (read)))\n\n\n(defmacro read-numbers-to-array (size)\n (let ((i (gensym))\n (arr (gensym)))\n `(let ((,arr (make-array ,size\n :element-type 'fixnum)))\n (declare ((array fixnum 1) ,arr))\n (loop for ,i of-type fixnum below ,size do\n (setf (aref ,arr ,i) (read))\n finally\n (return ,arr)))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(defun unwrap (list)\n (format nil \"~{~a~^ ~}\" list))\n\n\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n\n\n\n\n#|\n------------------------------------\n| Body |\n------------------------------------\n|#\n\n(declaim (ftype (function (fixnum fixnum (array fixnum 1)) list)))\n(defun solve (n k a)\n (declare (fixnum n k)\n ((array fixnum 1) a))\n (loop for i below (- n k) collect\n (if (< (aref a i) (aref a (+ i k)))\n \"Yes\"\n \"No\")))\n\n\n(defun main ()\n (declare #.OPT)\n (let ((n (read))\n (k (read)))\n (declare (fixnum n k))\n (let ((a (read-numbers-to-array n)))\n (declare ((array fixnum 1) a))\n (princ-for-each-line (solve n k a)))))\n\n#-swank (main)\n", "problem_context": "Score: 300 points\n\nProblem Statement\n\nM-kun is a student in Aoki High School, where a year is divided into N terms.\n\nThere is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows:\n\nFor the first through (K-1)-th terms: not given.\n\nFor each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term.\n\nM-kun scored A_i in the exam at the end of the i-th term.\n\nFor each i such that K+1 \\leq i \\leq N, determine whether his grade for the i-th term is strictly greater than the grade for the (i-1)-th term.\n\nConstraints\n\n2 \\leq N \\leq 200000\n\n1 \\leq K \\leq N-1\n\n1 \\leq A_i \\leq 10^{9}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 A_3 \\ldots A_N\n\nOutput\n\nPrint the answer in N-K lines.\n\nThe i-th line should contain Yes if the grade for the (K+i)-th term is greater than the grade for the (K+i-1)-th term, and No otherwise.\n\nSample Input 1\n\n5 3\n96 98 95 100 20\n\nSample Output 1\n\nYes\nNo\n\nHis grade for each term is computed as follows:\n\n3-rd term: (96 \\times 98 \\times 95) = 893760\n\n4-th term: (98 \\times 95 \\times 100) = 931000\n\n5-th term: (95 \\times 100 \\times 20) = 190000\n\nSample Input 2\n\n3 2\n1001 869120 1001\n\nSample Output 2\n\nNo\n\nNote that the output should be No if the grade for the 3-rd term is equal to the grade for the 2-nd term.\n\nSample Input 3\n\n15 7\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9\n\nSample Output 3\n\nYes\nYes\nNo\nYes\nYes\nNo\nYes\nYes", "sample_input": "5 3\n96 98 95 100 20\n"}, "reference_outputs": ["Yes\nNo\n"], "source_document_id": "p02602", "source_text": "Score: 300 points\n\nProblem Statement\n\nM-kun is a student in Aoki High School, where a year is divided into N terms.\n\nThere is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows:\n\nFor the first through (K-1)-th terms: not given.\n\nFor each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term.\n\nM-kun scored A_i in the exam at the end of the i-th term.\n\nFor each i such that K+1 \\leq i \\leq N, determine whether his grade for the i-th term is strictly greater than the grade for the (i-1)-th term.\n\nConstraints\n\n2 \\leq N \\leq 200000\n\n1 \\leq K \\leq N-1\n\n1 \\leq A_i \\leq 10^{9}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 A_3 \\ldots A_N\n\nOutput\n\nPrint the answer in N-K lines.\n\nThe i-th line should contain Yes if the grade for the (K+i)-th term is greater than the grade for the (K+i-1)-th term, and No otherwise.\n\nSample Input 1\n\n5 3\n96 98 95 100 20\n\nSample Output 1\n\nYes\nNo\n\nHis grade for each term is computed as follows:\n\n3-rd term: (96 \\times 98 \\times 95) = 893760\n\n4-th term: (98 \\times 95 \\times 100) = 931000\n\n5-th term: (95 \\times 100 \\times 20) = 190000\n\nSample Input 2\n\n3 2\n1001 869120 1001\n\nSample Output 2\n\nNo\n\nNote that the output should be No if the grade for the 3-rd term is equal to the grade for the 2-nd term.\n\nSample Input 3\n\n15 7\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9\n\nSample Output 3\n\nYes\nYes\nNo\nYes\nYes\nNo\nYes\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3665, "cpu_time_ms": 573, "memory_kb": 82252}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s493226330", "group_id": "codeNet:p02602", "input_text": "(defun main ()\n (let* ((n (read))\n\t (k (read))\n\t (a (make-array (1+ n))))\n (dotimes (i n)\n (setf (aref a (1+ i)) (read)))\n (loop for i\n\t from (1+ k)\n below (1+ n)\n if (< (aref a (- i k)) (aref a i))\n\t do (format t \"Yes~%\")\n else\n\t do (format t \"No~%\"))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1595769931, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02602.html", "problem_id": "p02602", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02602/input.txt", "sample_output_relpath": "derived/input_output/data/p02602/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02602/Lisp/s493226330.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s493226330", "user_id": "u091381267"}, "prompt_components": {"gold_output": "Yes\nNo\n", "input_to_evaluate": "(defun main ()\n (let* ((n (read))\n\t (k (read))\n\t (a (make-array (1+ n))))\n (dotimes (i n)\n (setf (aref a (1+ i)) (read)))\n (loop for i\n\t from (1+ k)\n below (1+ n)\n if (< (aref a (- i k)) (aref a i))\n\t do (format t \"Yes~%\")\n else\n\t do (format t \"No~%\"))))\n\n(main)\n", "problem_context": "Score: 300 points\n\nProblem Statement\n\nM-kun is a student in Aoki High School, where a year is divided into N terms.\n\nThere is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows:\n\nFor the first through (K-1)-th terms: not given.\n\nFor each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term.\n\nM-kun scored A_i in the exam at the end of the i-th term.\n\nFor each i such that K+1 \\leq i \\leq N, determine whether his grade for the i-th term is strictly greater than the grade for the (i-1)-th term.\n\nConstraints\n\n2 \\leq N \\leq 200000\n\n1 \\leq K \\leq N-1\n\n1 \\leq A_i \\leq 10^{9}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 A_3 \\ldots A_N\n\nOutput\n\nPrint the answer in N-K lines.\n\nThe i-th line should contain Yes if the grade for the (K+i)-th term is greater than the grade for the (K+i-1)-th term, and No otherwise.\n\nSample Input 1\n\n5 3\n96 98 95 100 20\n\nSample Output 1\n\nYes\nNo\n\nHis grade for each term is computed as follows:\n\n3-rd term: (96 \\times 98 \\times 95) = 893760\n\n4-th term: (98 \\times 95 \\times 100) = 931000\n\n5-th term: (95 \\times 100 \\times 20) = 190000\n\nSample Input 2\n\n3 2\n1001 869120 1001\n\nSample Output 2\n\nNo\n\nNote that the output should be No if the grade for the 3-rd term is equal to the grade for the 2-nd term.\n\nSample Input 3\n\n15 7\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9\n\nSample Output 3\n\nYes\nYes\nNo\nYes\nYes\nNo\nYes\nYes", "sample_input": "5 3\n96 98 95 100 20\n"}, "reference_outputs": ["Yes\nNo\n"], "source_document_id": "p02602", "source_text": "Score: 300 points\n\nProblem Statement\n\nM-kun is a student in Aoki High School, where a year is divided into N terms.\n\nThere is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows:\n\nFor the first through (K-1)-th terms: not given.\n\nFor each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term.\n\nM-kun scored A_i in the exam at the end of the i-th term.\n\nFor each i such that K+1 \\leq i \\leq N, determine whether his grade for the i-th term is strictly greater than the grade for the (i-1)-th term.\n\nConstraints\n\n2 \\leq N \\leq 200000\n\n1 \\leq K \\leq N-1\n\n1 \\leq A_i \\leq 10^{9}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 A_3 \\ldots A_N\n\nOutput\n\nPrint the answer in N-K lines.\n\nThe i-th line should contain Yes if the grade for the (K+i)-th term is greater than the grade for the (K+i-1)-th term, and No otherwise.\n\nSample Input 1\n\n5 3\n96 98 95 100 20\n\nSample Output 1\n\nYes\nNo\n\nHis grade for each term is computed as follows:\n\n3-rd term: (96 \\times 98 \\times 95) = 893760\n\n4-th term: (98 \\times 95 \\times 100) = 931000\n\n5-th term: (95 \\times 100 \\times 20) = 190000\n\nSample Input 2\n\n3 2\n1001 869120 1001\n\nSample Output 2\n\nNo\n\nNote that the output should be No if the grade for the 3-rd term is equal to the grade for the 2-nd term.\n\nSample Input 3\n\n15 7\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9\n\nSample Output 3\n\nYes\nYes\nNo\nYes\nYes\nNo\nYes\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 293, "cpu_time_ms": 527, "memory_kb": 77776}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s151070380", "group_id": "codeNet:p02602", "input_text": "(let* ((n (read))\n (k (read))\n (b (make-array k :initial-element 1)))\n (loop for i from 0 to (1- n)\n with ans = 1\n for last = (aref b (mod i k))\n do (setf ans (read)\n (aref b (mod i k)) ans)\n when (> i (1- k))\n do (format t \"~A~%\" (if (> ans last)\n \"Yes\"\n \"No\"))))", "language": "Lisp", "metadata": {"date": 1595728561, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02602.html", "problem_id": "p02602", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02602/input.txt", "sample_output_relpath": "derived/input_output/data/p02602/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02602/Lisp/s151070380.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s151070380", "user_id": "u607637432"}, "prompt_components": {"gold_output": "Yes\nNo\n", "input_to_evaluate": "(let* ((n (read))\n (k (read))\n (b (make-array k :initial-element 1)))\n (loop for i from 0 to (1- n)\n with ans = 1\n for last = (aref b (mod i k))\n do (setf ans (read)\n (aref b (mod i k)) ans)\n when (> i (1- k))\n do (format t \"~A~%\" (if (> ans last)\n \"Yes\"\n \"No\"))))", "problem_context": "Score: 300 points\n\nProblem Statement\n\nM-kun is a student in Aoki High School, where a year is divided into N terms.\n\nThere is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows:\n\nFor the first through (K-1)-th terms: not given.\n\nFor each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term.\n\nM-kun scored A_i in the exam at the end of the i-th term.\n\nFor each i such that K+1 \\leq i \\leq N, determine whether his grade for the i-th term is strictly greater than the grade for the (i-1)-th term.\n\nConstraints\n\n2 \\leq N \\leq 200000\n\n1 \\leq K \\leq N-1\n\n1 \\leq A_i \\leq 10^{9}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 A_3 \\ldots A_N\n\nOutput\n\nPrint the answer in N-K lines.\n\nThe i-th line should contain Yes if the grade for the (K+i)-th term is greater than the grade for the (K+i-1)-th term, and No otherwise.\n\nSample Input 1\n\n5 3\n96 98 95 100 20\n\nSample Output 1\n\nYes\nNo\n\nHis grade for each term is computed as follows:\n\n3-rd term: (96 \\times 98 \\times 95) = 893760\n\n4-th term: (98 \\times 95 \\times 100) = 931000\n\n5-th term: (95 \\times 100 \\times 20) = 190000\n\nSample Input 2\n\n3 2\n1001 869120 1001\n\nSample Output 2\n\nNo\n\nNote that the output should be No if the grade for the 3-rd term is equal to the grade for the 2-nd term.\n\nSample Input 3\n\n15 7\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9\n\nSample Output 3\n\nYes\nYes\nNo\nYes\nYes\nNo\nYes\nYes", "sample_input": "5 3\n96 98 95 100 20\n"}, "reference_outputs": ["Yes\nNo\n"], "source_document_id": "p02602", "source_text": "Score: 300 points\n\nProblem Statement\n\nM-kun is a student in Aoki High School, where a year is divided into N terms.\n\nThere is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows:\n\nFor the first through (K-1)-th terms: not given.\n\nFor each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term.\n\nM-kun scored A_i in the exam at the end of the i-th term.\n\nFor each i such that K+1 \\leq i \\leq N, determine whether his grade for the i-th term is strictly greater than the grade for the (i-1)-th term.\n\nConstraints\n\n2 \\leq N \\leq 200000\n\n1 \\leq K \\leq N-1\n\n1 \\leq A_i \\leq 10^{9}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 A_3 \\ldots A_N\n\nOutput\n\nPrint the answer in N-K lines.\n\nThe i-th line should contain Yes if the grade for the (K+i)-th term is greater than the grade for the (K+i-1)-th term, and No otherwise.\n\nSample Input 1\n\n5 3\n96 98 95 100 20\n\nSample Output 1\n\nYes\nNo\n\nHis grade for each term is computed as follows:\n\n3-rd term: (96 \\times 98 \\times 95) = 893760\n\n4-th term: (98 \\times 95 \\times 100) = 931000\n\n5-th term: (95 \\times 100 \\times 20) = 190000\n\nSample Input 2\n\n3 2\n1001 869120 1001\n\nSample Output 2\n\nNo\n\nNote that the output should be No if the grade for the 3-rd term is equal to the grade for the 2-nd term.\n\nSample Input 3\n\n15 7\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9\n\nSample Output 3\n\nYes\nYes\nNo\nYes\nYes\nNo\nYes\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 390, "cpu_time_ms": 546, "memory_kb": 77812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s843558187", "group_id": "codeNet:p02603", "input_text": "#|\n------------------------------------\n| Utils |\n------------------------------------\n|#\n\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n(defconstant +mod+ 1000000007)\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n\n(defmacro read-numbers-to-list (size)\n `(loop repeat ,size collect (read)))\n\n\n(defmacro read-numbers-to-array (size)\n (let ((i (gensym))\n (arr (gensym)))\n `(let ((,arr (make-array ,size\n :element-type 'fixnum)))\n (declare ((array fixnum 1) ,arr))\n (loop for ,i of-type fixnum below ,size do\n (setf (aref ,arr ,i) (read))\n finally\n (return ,arr)))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(defun unwrap (list)\n (format nil \"~{~a~^ ~}\" list))\n\n\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n\n\n\n\n#|\n------------------------------------\n| Body |\n------------------------------------\n|#\n\n(defparameter *initial-budget* 1000)\n(defparameter *inf* 1000000)\n\n\n(defun solve (a)\n (labels ((inner (xs &optional (prev 0) (stock-amount 0) (acc *initial-budget*))\n (cond\n ((null xs) acc)\n ((> (first xs) prev) (inner (rest xs) ; uridoki\n (first xs)\n 0\n (+ acc (* stock-amount (first xs)))))\n ((and (second xs) (< (first xs) (second xs))) (inner (rest xs) ;kaidoki\n (first xs)\n (+ stock-amount (floor acc (first xs)))\n (mod acc (first xs))))\n (t (inner (rest xs)\n (first xs)\n stock-amount\n acc)))))\n (max (inner a *inf*)\n (inner a (- *inf*)))))\n\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (a (read-numbers-to-list n)))\n (format t \"~a~&\" (solve a))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1600267114, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02603.html", "problem_id": "p02603", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02603/input.txt", "sample_output_relpath": "derived/input_output/data/p02603/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02603/Lisp/s843558187.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s843558187", "user_id": "u425762225"}, "prompt_components": {"gold_output": "1685\n", "input_to_evaluate": "#|\n------------------------------------\n| Utils |\n------------------------------------\n|#\n\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n(defconstant +mod+ 1000000007)\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n\n(defmacro read-numbers-to-list (size)\n `(loop repeat ,size collect (read)))\n\n\n(defmacro read-numbers-to-array (size)\n (let ((i (gensym))\n (arr (gensym)))\n `(let ((,arr (make-array ,size\n :element-type 'fixnum)))\n (declare ((array fixnum 1) ,arr))\n (loop for ,i of-type fixnum below ,size do\n (setf (aref ,arr ,i) (read))\n finally\n (return ,arr)))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(defun unwrap (list)\n (format nil \"~{~a~^ ~}\" list))\n\n\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n\n\n\n\n#|\n------------------------------------\n| Body |\n------------------------------------\n|#\n\n(defparameter *initial-budget* 1000)\n(defparameter *inf* 1000000)\n\n\n(defun solve (a)\n (labels ((inner (xs &optional (prev 0) (stock-amount 0) (acc *initial-budget*))\n (cond\n ((null xs) acc)\n ((> (first xs) prev) (inner (rest xs) ; uridoki\n (first xs)\n 0\n (+ acc (* stock-amount (first xs)))))\n ((and (second xs) (< (first xs) (second xs))) (inner (rest xs) ;kaidoki\n (first xs)\n (+ stock-amount (floor acc (first xs)))\n (mod acc (first xs))))\n (t (inner (rest xs)\n (first xs)\n stock-amount\n acc)))))\n (max (inner a *inf*)\n (inner a (- *inf*)))))\n\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (a (read-numbers-to-list n)))\n (format t \"~a~&\" (solve a))))\n\n#-swank (main)\n", "problem_context": "Score: 400 points\n\nProblem Statement\n\nTo become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives.\n\nHe is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows:\n\nA_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day.\n\nIn the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time.\n\nBuy stock: Pay A_i yen and receive one stock.\n\nSell stock: Sell one stock for A_i yen.\n\nWhat is the maximum possible amount of money that M-kun can have in the end by trading optimally?\n\nConstraints\n\n2 \\leq N \\leq 80\n\n100 \\leq A_i \\leq 200\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 \\cdots A_N\n\nOutput\n\nPrint the maximum possible amount of money that M-kun can have in the end, as an integer.\n\nSample Input 1\n\n7\n100 130 130 130 115 115 150\n\nSample Output 1\n\n1685\n\nIn this sample input, M-kun has seven days of trading. One way to have 1685 yen in the end is as follows:\n\nInitially, he has 1000 yen and no stocks.\n\nDay 1: Buy 10 stocks for 1000 yen. Now he has 0 yen.\n\nDay 2: Sell 7 stocks for 910 yen. Now he has 910 yen.\n\nDay 3: Sell 3 stocks for 390 yen. Now he has 1300 yen.\n\nDay 4: Do nothing.\n\nDay 5: Buy 1 stock for 115 yen. Now he has 1185 yen.\n\nDay 6: Buy 10 stocks for 1150 yen. Now he has 35 yen.\n\nDay 7: Sell 11 stocks for 1650 yen. Now he has 1685 yen.\n\nThere is no way to have 1686 yen or more in the end, so the answer is 1685.\n\nSample Input 2\n\n6\n200 180 160 140 120 100\n\nSample Output 2\n\n1000\n\nIn this sample input, it is optimal to do nothing throughout the six days, after which we will have 1000 yen.\n\nSample Input 3\n\n2\n157 193\n\nSample Output 3\n\n1216\n\nIn this sample input, it is optimal to buy 6 stocks in Day 1 and sell them in Day 2, after which we will have 1216 yen.", "sample_input": "7\n100 130 130 130 115 115 150\n"}, "reference_outputs": ["1685\n"], "source_document_id": "p02603", "source_text": "Score: 400 points\n\nProblem Statement\n\nTo become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives.\n\nHe is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows:\n\nA_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day.\n\nIn the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time.\n\nBuy stock: Pay A_i yen and receive one stock.\n\nSell stock: Sell one stock for A_i yen.\n\nWhat is the maximum possible amount of money that M-kun can have in the end by trading optimally?\n\nConstraints\n\n2 \\leq N \\leq 80\n\n100 \\leq A_i \\leq 200\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 \\cdots A_N\n\nOutput\n\nPrint the maximum possible amount of money that M-kun can have in the end, as an integer.\n\nSample Input 1\n\n7\n100 130 130 130 115 115 150\n\nSample Output 1\n\n1685\n\nIn this sample input, M-kun has seven days of trading. One way to have 1685 yen in the end is as follows:\n\nInitially, he has 1000 yen and no stocks.\n\nDay 1: Buy 10 stocks for 1000 yen. Now he has 0 yen.\n\nDay 2: Sell 7 stocks for 910 yen. Now he has 910 yen.\n\nDay 3: Sell 3 stocks for 390 yen. Now he has 1300 yen.\n\nDay 4: Do nothing.\n\nDay 5: Buy 1 stock for 115 yen. Now he has 1185 yen.\n\nDay 6: Buy 10 stocks for 1150 yen. Now he has 35 yen.\n\nDay 7: Sell 11 stocks for 1650 yen. Now he has 1685 yen.\n\nThere is no way to have 1686 yen or more in the end, so the answer is 1685.\n\nSample Input 2\n\n6\n200 180 160 140 120 100\n\nSample Output 2\n\n1000\n\nIn this sample input, it is optimal to do nothing throughout the six days, after which we will have 1000 yen.\n\nSample Input 3\n\n2\n157 193\n\nSample Output 3\n\n1216\n\nIn this sample input, it is optimal to buy 6 stocks in Day 1 and sell them in Day 2, after which we will have 1216 yen.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4334, "cpu_time_ms": 33, "memory_kb": 26128}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s812717154", "group_id": "codeNet:p02607", "input_text": "(let* ((n (read))\n (a (make-array n))\n (ans 0))\n (dotimes (i n)\n (setf (aref a i) (read))\n (if (and (zerop (rem i 2)) (not (zerop (rem (aref a i) 2))))\n (incf ans)\n )\n )\n (princ ans)\n)", "language": "Lisp", "metadata": {"date": 1594515937, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02607.html", "problem_id": "p02607", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02607/input.txt", "sample_output_relpath": "derived/input_output/data/p02607/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02607/Lisp/s812717154.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s812717154", "user_id": "u136500538"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (read))\n (a (make-array n))\n (ans 0))\n (dotimes (i n)\n (setf (aref a i) (read))\n (if (and (zerop (rem i 2)) (not (zerop (rem (aref a i) 2))))\n (incf ans)\n )\n )\n (princ ans)\n)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have N squares assigned the numbers 1,2,3,\\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i.\n\nHow many squares i satisfy both of the following conditions?\n\nThe assigned number, i, is odd.\n\nThe written integer is odd.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N, a_i \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 \\cdots a_N\n\nOutput\n\nPrint the number of squares that satisfy both of the conditions.\n\nSample Input 1\n\n5\n1 3 4 5 7\n\nSample Output 1\n\n2\n\nTwo squares, Square 1 and 5, satisfy both of the conditions.\n\nFor Square 2 and 4, the assigned numbers are not odd.\n\nFor Square 3, the written integer is not odd.\n\nSample Input 2\n\n15\n13 76 46 15 50 98 93 77 31 43 84 90 6 24 14\n\nSample Output 2\n\n3", "sample_input": "5\n1 3 4 5 7\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02607", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have N squares assigned the numbers 1,2,3,\\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i.\n\nHow many squares i satisfy both of the following conditions?\n\nThe assigned number, i, is odd.\n\nThe written integer is odd.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N, a_i \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 \\cdots a_N\n\nOutput\n\nPrint the number of squares that satisfy both of the conditions.\n\nSample Input 1\n\n5\n1 3 4 5 7\n\nSample Output 1\n\n2\n\nTwo squares, Square 1 and 5, satisfy both of the conditions.\n\nFor Square 2 and 4, the assigned numbers are not odd.\n\nFor Square 3, the written integer is not odd.\n\nSample Input 2\n\n15\n13 76 46 15 50 98 93 77 31 43 84 90 6 24 14\n\nSample Output 2\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 231, "cpu_time_ms": 19, "memory_kb": 24604}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s462710620", "group_id": "codeNet:p02608", "input_text": "(defun func (&rest args)\n (loop for i on args\n sum\n (loop for j in i\n sum (* (car i) j))))\n\n(defun main (n\n &aux\n (ans (make-array (1+ n) :initial-element 0)))\n (labels ((check (&rest args)\n (<= (apply #'func args) n)))\n (loop for i from 1\n while (check i)\n do\n (loop for j from 1\n while (check i j)\n do\n (loop for k from 1\n while (check i j k)\n do\n (incf (aref ans (func i j k))))))\n (cdr (coerce ans 'list))))\n\n(format t \"~{~a~%~}\"\n (main (read)))\n", "language": "Lisp", "metadata": {"date": 1594574607, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02608.html", "problem_id": "p02608", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02608/input.txt", "sample_output_relpath": "derived/input_output/data/p02608/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02608/Lisp/s462710620.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s462710620", "user_id": "u493610446"}, "prompt_components": {"gold_output": "0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n", "input_to_evaluate": "(defun func (&rest args)\n (loop for i on args\n sum\n (loop for j in i\n sum (* (car i) j))))\n\n(defun main (n\n &aux\n (ans (make-array (1+ n) :initial-element 0)))\n (labels ((check (&rest args)\n (<= (apply #'func args) n)))\n (loop for i from 1\n while (check i)\n do\n (loop for j from 1\n while (check i j)\n do\n (loop for k from 1\n while (check i j k)\n do\n (incf (aref ans (func i j k))))))\n (cdr (coerce ans 'list))))\n\n(format t \"~{~a~%~}\"\n (main (read)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nLet f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions:\n\n1 \\leq x,y,z\n\nx^2 + y^2 + z^2 + xy + yz + zx = n\n\nGiven an integer N, find each of f(1),f(2),f(3),\\ldots,f(N).\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^4\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint N lines. The i-th line should contain the value f(i).\n\nSample Input 1\n\n20\n\nSample Output 1\n\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n\nFor n=6, only (1,1,1) satisfies both of the conditions. Thus, f(6) = 1.\n\nFor n=11, three triples, (1,1,2), (1,2,1), and (2,1,1), satisfy both of the conditions. Thus, f(6) = 3.\n\nFor n=17, three triples, (1,2,2), (2,1,2), and (2,2,1), satisfy both of the conditions. Thus, f(17) = 3.\n\nFor n=18, three triples, (1,1,3), (1,3,1), and (3,1,1), satisfy both of the conditions. Thus, f(18) = 3.", "sample_input": "20\n"}, "reference_outputs": ["0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n"], "source_document_id": "p02608", "source_text": "Score : 300 points\n\nProblem Statement\n\nLet f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions:\n\n1 \\leq x,y,z\n\nx^2 + y^2 + z^2 + xy + yz + zx = n\n\nGiven an integer N, find each of f(1),f(2),f(3),\\ldots,f(N).\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^4\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint N lines. The i-th line should contain the value f(i).\n\nSample Input 1\n\n20\n\nSample Output 1\n\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n\nFor n=6, only (1,1,1) satisfies both of the conditions. Thus, f(6) = 1.\n\nFor n=11, three triples, (1,1,2), (1,2,1), and (2,1,1), satisfy both of the conditions. Thus, f(6) = 3.\n\nFor n=17, three triples, (1,2,2), (2,1,2), and (2,2,1), satisfy both of the conditions. Thus, f(17) = 3.\n\nFor n=18, three triples, (1,1,3), (1,3,1), and (3,1,1), satisfy both of the conditions. Thus, f(18) = 3.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 701, "cpu_time_ms": 77, "memory_kb": 60856}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s264392800", "group_id": "codeNet:p02608", "input_text": "(defparameter *cash* (make-array 1000001))\n(defun calc (x y z)\n #+nil(let ((r (aref *cash* (+ (* x 10000) (* y 100) z))))\n (if (zerop r)\n (setf (aref *cash* (+ (* x 10000) (* y 100) z))\n (+ (* x x)\n (* y y)\n (* z z)\n (* x y)\n (* y z)\n (* z x)))\n r))\n (+ (* x x)\n (* y y)\n (* z z)\n (* x y)\n (* y z)\n (* z x)))\n\n(defun f (n)\n (loop with result = 0\n for x from 1\n while (>= n (calc x 1 1))\n do (loop for y from x\n while (>= n (calc x y 1))\n do (loop for z from (max y (floor (sqrt (- n (calc x y 1)))))\n for r = (calc x y z)\n while (>= n r)\n when (= n r)\n do ;;(print (list :result x y n (calc x y z)))\n (incf result (if (= x y)\n (if (= y z) 1 3)\n (if (= y z) 3 6)))))\n finally (return result)))\n\n(let ((n (read)))\n (loop for i from 1 to n\n do (format t \"~A~%\" (f i))))", "language": "Lisp", "metadata": {"date": 1594521977, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02608.html", "problem_id": "p02608", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02608/input.txt", "sample_output_relpath": "derived/input_output/data/p02608/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02608/Lisp/s264392800.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s264392800", "user_id": "u607637432"}, "prompt_components": {"gold_output": "0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n", "input_to_evaluate": "(defparameter *cash* (make-array 1000001))\n(defun calc (x y z)\n #+nil(let ((r (aref *cash* (+ (* x 10000) (* y 100) z))))\n (if (zerop r)\n (setf (aref *cash* (+ (* x 10000) (* y 100) z))\n (+ (* x x)\n (* y y)\n (* z z)\n (* x y)\n (* y z)\n (* z x)))\n r))\n (+ (* x x)\n (* y y)\n (* z z)\n (* x y)\n (* y z)\n (* z x)))\n\n(defun f (n)\n (loop with result = 0\n for x from 1\n while (>= n (calc x 1 1))\n do (loop for y from x\n while (>= n (calc x y 1))\n do (loop for z from (max y (floor (sqrt (- n (calc x y 1)))))\n for r = (calc x y z)\n while (>= n r)\n when (= n r)\n do ;;(print (list :result x y n (calc x y z)))\n (incf result (if (= x y)\n (if (= y z) 1 3)\n (if (= y z) 3 6)))))\n finally (return result)))\n\n(let ((n (read)))\n (loop for i from 1 to n\n do (format t \"~A~%\" (f i))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nLet f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions:\n\n1 \\leq x,y,z\n\nx^2 + y^2 + z^2 + xy + yz + zx = n\n\nGiven an integer N, find each of f(1),f(2),f(3),\\ldots,f(N).\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^4\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint N lines. The i-th line should contain the value f(i).\n\nSample Input 1\n\n20\n\nSample Output 1\n\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n\nFor n=6, only (1,1,1) satisfies both of the conditions. Thus, f(6) = 1.\n\nFor n=11, three triples, (1,1,2), (1,2,1), and (2,1,1), satisfy both of the conditions. Thus, f(6) = 3.\n\nFor n=17, three triples, (1,2,2), (2,1,2), and (2,2,1), satisfy both of the conditions. Thus, f(17) = 3.\n\nFor n=18, three triples, (1,1,3), (1,3,1), and (3,1,1), satisfy both of the conditions. Thus, f(18) = 3.", "sample_input": "20\n"}, "reference_outputs": ["0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n"], "source_document_id": "p02608", "source_text": "Score : 300 points\n\nProblem Statement\n\nLet f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions:\n\n1 \\leq x,y,z\n\nx^2 + y^2 + z^2 + xy + yz + zx = n\n\nGiven an integer N, find each of f(1),f(2),f(3),\\ldots,f(N).\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^4\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint N lines. The i-th line should contain the value f(i).\n\nSample Input 1\n\n20\n\nSample Output 1\n\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n\nFor n=6, only (1,1,1) satisfies both of the conditions. Thus, f(6) = 1.\n\nFor n=11, three triples, (1,1,2), (1,2,1), and (2,1,1), satisfy both of the conditions. Thus, f(6) = 3.\n\nFor n=17, three triples, (1,2,2), (2,1,2), and (2,2,1), satisfy both of the conditions. Thus, f(17) = 3.\n\nFor n=18, three triples, (1,1,3), (1,3,1), and (3,1,1), satisfy both of the conditions. Thus, f(18) = 3.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1211, "cpu_time_ms": 1131, "memory_kb": 24568}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s448532265", "group_id": "codeNet:p02608", "input_text": "#+nil(defparameter *cash* (make-array 1000001))\n(defun calc (x y z)\n #+nil(let ((r (aref *cash* (+ (* x 10000) (* y 100) z))))\n (if (zerop r)\n (setf (aref *cash* (+ (* x 10000) (* y 100) z))\n (+ (* x x)\n (* y y)\n (* z z)\n (* x y)\n (* y z)\n (* z x)))\n r))\n (+ (* x x)\n (* y y)\n (* z z)\n (* x y)\n (* y z)\n (* z x)))\n\n(defun f (n)\n (loop with result = 0\n for x from 1\n while (>= n (calc x 0 0))\n do (loop for y from x\n while (>= n (calc x y 0))\n do (loop for z from (max y (floor (sqrt (- n (calc x y 0)))))\n for r = (calc x y z)\n while (>= n r)\n when (= n r)\n do ;;(print (list x y z n (calc x y z)))\n (incf result (if (= x y)\n (if (= y z) 1 3)\n (if (= y z) 3 6)))))\n finally (return result)))\n\n(let ((n (read)))\n (loop for i from 1 to n\n do (format t \"~A~%\" (f i))))", "language": "Lisp", "metadata": {"date": 1594520681, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02608.html", "problem_id": "p02608", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02608/input.txt", "sample_output_relpath": "derived/input_output/data/p02608/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02608/Lisp/s448532265.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s448532265", "user_id": "u607637432"}, "prompt_components": {"gold_output": "0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n", "input_to_evaluate": "#+nil(defparameter *cash* (make-array 1000001))\n(defun calc (x y z)\n #+nil(let ((r (aref *cash* (+ (* x 10000) (* y 100) z))))\n (if (zerop r)\n (setf (aref *cash* (+ (* x 10000) (* y 100) z))\n (+ (* x x)\n (* y y)\n (* z z)\n (* x y)\n (* y z)\n (* z x)))\n r))\n (+ (* x x)\n (* y y)\n (* z z)\n (* x y)\n (* y z)\n (* z x)))\n\n(defun f (n)\n (loop with result = 0\n for x from 1\n while (>= n (calc x 0 0))\n do (loop for y from x\n while (>= n (calc x y 0))\n do (loop for z from (max y (floor (sqrt (- n (calc x y 0)))))\n for r = (calc x y z)\n while (>= n r)\n when (= n r)\n do ;;(print (list x y z n (calc x y z)))\n (incf result (if (= x y)\n (if (= y z) 1 3)\n (if (= y z) 3 6)))))\n finally (return result)))\n\n(let ((n (read)))\n (loop for i from 1 to n\n do (format t \"~A~%\" (f i))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nLet f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions:\n\n1 \\leq x,y,z\n\nx^2 + y^2 + z^2 + xy + yz + zx = n\n\nGiven an integer N, find each of f(1),f(2),f(3),\\ldots,f(N).\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^4\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint N lines. The i-th line should contain the value f(i).\n\nSample Input 1\n\n20\n\nSample Output 1\n\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n\nFor n=6, only (1,1,1) satisfies both of the conditions. Thus, f(6) = 1.\n\nFor n=11, three triples, (1,1,2), (1,2,1), and (2,1,1), satisfy both of the conditions. Thus, f(6) = 3.\n\nFor n=17, three triples, (1,2,2), (2,1,2), and (2,2,1), satisfy both of the conditions. Thus, f(17) = 3.\n\nFor n=18, three triples, (1,1,3), (1,3,1), and (3,1,1), satisfy both of the conditions. Thus, f(18) = 3.", "sample_input": "20\n"}, "reference_outputs": ["0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n"], "source_document_id": "p02608", "source_text": "Score : 300 points\n\nProblem Statement\n\nLet f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions:\n\n1 \\leq x,y,z\n\nx^2 + y^2 + z^2 + xy + yz + zx = n\n\nGiven an integer N, find each of f(1),f(2),f(3),\\ldots,f(N).\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^4\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint N lines. The i-th line should contain the value f(i).\n\nSample Input 1\n\n20\n\nSample Output 1\n\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n\nFor n=6, only (1,1,1) satisfies both of the conditions. Thus, f(6) = 1.\n\nFor n=11, three triples, (1,1,2), (1,2,1), and (2,1,1), satisfy both of the conditions. Thus, f(6) = 3.\n\nFor n=17, three triples, (1,2,2), (2,1,2), and (2,2,1), satisfy both of the conditions. Thus, f(17) = 3.\n\nFor n=18, three triples, (1,1,3), (1,3,1), and (3,1,1), satisfy both of the conditions. Thus, f(18) = 3.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1229, "cpu_time_ms": 1197, "memory_kb": 24420}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s276332048", "group_id": "codeNet:p02608", "input_text": "(defun main ()\n (let ((n (read))\n\t(ans 0))\n (dotimes (i n)\n (dotimes (x (1+ i))\n\t(dotimes (y (1+ i))\n\t (dotimes (z (1+ i))\n\t (if (= (1+ i) (+ (expt (1+ x) 2) (expt (1+ y) 2) (expt (1+ z) 2) (* (1+ x) (1+ y)) (* (1+ y) (1+ z)) (* (1+ z) (1+ x))))\n\t\t(incf ans)))))\n (format t \"~d~%\" ans)\n (setf ans 0))))\n(main)\n", "language": "Lisp", "metadata": {"date": 1594519897, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02608.html", "problem_id": "p02608", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02608/input.txt", "sample_output_relpath": "derived/input_output/data/p02608/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02608/Lisp/s276332048.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s276332048", "user_id": "u091381267"}, "prompt_components": {"gold_output": "0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n", "input_to_evaluate": "(defun main ()\n (let ((n (read))\n\t(ans 0))\n (dotimes (i n)\n (dotimes (x (1+ i))\n\t(dotimes (y (1+ i))\n\t (dotimes (z (1+ i))\n\t (if (= (1+ i) (+ (expt (1+ x) 2) (expt (1+ y) 2) (expt (1+ z) 2) (* (1+ x) (1+ y)) (* (1+ y) (1+ z)) (* (1+ z) (1+ x))))\n\t\t(incf ans)))))\n (format t \"~d~%\" ans)\n (setf ans 0))))\n(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nLet f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions:\n\n1 \\leq x,y,z\n\nx^2 + y^2 + z^2 + xy + yz + zx = n\n\nGiven an integer N, find each of f(1),f(2),f(3),\\ldots,f(N).\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^4\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint N lines. The i-th line should contain the value f(i).\n\nSample Input 1\n\n20\n\nSample Output 1\n\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n\nFor n=6, only (1,1,1) satisfies both of the conditions. Thus, f(6) = 1.\n\nFor n=11, three triples, (1,1,2), (1,2,1), and (2,1,1), satisfy both of the conditions. Thus, f(6) = 3.\n\nFor n=17, three triples, (1,2,2), (2,1,2), and (2,2,1), satisfy both of the conditions. Thus, f(17) = 3.\n\nFor n=18, three triples, (1,1,3), (1,3,1), and (3,1,1), satisfy both of the conditions. Thus, f(18) = 3.", "sample_input": "20\n"}, "reference_outputs": ["0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n"], "source_document_id": "p02608", "source_text": "Score : 300 points\n\nProblem Statement\n\nLet f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions:\n\n1 \\leq x,y,z\n\nx^2 + y^2 + z^2 + xy + yz + zx = n\n\nGiven an integer N, find each of f(1),f(2),f(3),\\ldots,f(N).\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^4\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint N lines. The i-th line should contain the value f(i).\n\nSample Input 1\n\n20\n\nSample Output 1\n\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n\nFor n=6, only (1,1,1) satisfies both of the conditions. Thus, f(6) = 1.\n\nFor n=11, three triples, (1,1,2), (1,2,1), and (2,1,1), satisfy both of the conditions. Thus, f(6) = 3.\n\nFor n=17, three triples, (1,2,2), (2,1,2), and (2,2,1), satisfy both of the conditions. Thus, f(17) = 3.\n\nFor n=18, three triples, (1,1,3), (1,3,1), and (3,1,1), satisfy both of the conditions. Thus, f(18) = 3.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 333, "cpu_time_ms": 2206, "memory_kb": 24316}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s325775879", "group_id": "codeNet:p02609", "input_text": "(defun one-step (x)\n (mod x (logcount x)))\n\n(defun f (x)\n (let ((acc 0))\n (loop :while (< 0 x)\n :do (setf x (one-step x))\n :do (incf acc))\n acc))\n\n\n(let* ((n (read))\n (s (read-line))\n (x (parse-integer s :radix 2))\n (p (logcount x))\n (y+ 0)\n (y- 0))\n (setf y+ (mod x (1+ p)))\n (when (/= p 1)\n (setf y- (mod x (1- p))))\n (loop :for i :downfrom (1- n) :to 0\n :for j :from 0 :to (1- n)\n :do (cond ((and (char= (aref s j) #\\1) (= p 1))\n (format t \"0~%\"))\n ((char= (aref s j) #\\1)\n (format t \"~A~%\" (1+ (f (mod (- y- (mod (expt 2 i) (1- p))) (1- p))))))\n (t\n (format t \"~A~%\" (1+ (f (mod (+ y+ (mod (expt 2 i) (1+ p))) (1+ p)))))))))\n\n", "language": "Lisp", "metadata": {"date": 1594527991, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02609.html", "problem_id": "p02609", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02609/input.txt", "sample_output_relpath": "derived/input_output/data/p02609/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02609/Lisp/s325775879.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s325775879", "user_id": "u608227593"}, "prompt_components": {"gold_output": "2\n1\n1\n", "input_to_evaluate": "(defun one-step (x)\n (mod x (logcount x)))\n\n(defun f (x)\n (let ((acc 0))\n (loop :while (< 0 x)\n :do (setf x (one-step x))\n :do (incf acc))\n acc))\n\n\n(let* ((n (read))\n (s (read-line))\n (x (parse-integer s :radix 2))\n (p (logcount x))\n (y+ 0)\n (y- 0))\n (setf y+ (mod x (1+ p)))\n (when (/= p 1)\n (setf y- (mod x (1- p))))\n (loop :for i :downfrom (1- n) :to 0\n :for j :from 0 :to (1- n)\n :do (cond ((and (char= (aref s j) #\\1) (= p 1))\n (format t \"0~%\"))\n ((char= (aref s j) #\\1)\n (format t \"~A~%\" (1+ (f (mod (- y- (mod (expt 2 i) (1- p))) (1- p))))))\n (t\n (format t \"~A~%\" (1+ (f (mod (+ y+ (mod (expt 2 i) (1+ p))) (1+ p)))))))))\n\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nLet \\mathrm{popcount}(n) be the number of 1s in the binary representation of n.\nFor example, \\mathrm{popcount}(3) = 2, \\mathrm{popcount}(7) = 3, and \\mathrm{popcount}(0) = 0.\n\nLet f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: \"replace n with the remainder when n is divided by \\mathrm{popcount}(n).\" (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.)\n\nFor example, when n=7, it becomes 0 after two operations, as follows:\n\n\\mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1.\n\n\\mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0.\n\nYou are given an integer X with N digits in binary.\nFor each integer i such that 1 \\leq i \\leq N, let X_i be what X becomes when the i-th bit from the top is inverted.\nFind f(X_1), f(X_2), \\ldots, f(X_N).\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nX is an integer with N digits in binary, possibly with leading zeros.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nX\n\nOutput\n\nPrint N lines. The i-th line should contain the value f(X_i).\n\nSample Input 1\n\n3\n011\n\nSample Output 1\n\n2\n1\n1\n\nX_1 = 7, which will change as follows: 7 \\rightarrow 1 \\rightarrow 0. Thus, f(7) = 2.\n\nX_2 = 1, which will change as follows: 1 \\rightarrow 0. Thus, f(1) = 1.\n\nX_3 = 2, which will change as follows: 2 \\rightarrow 0. Thus, f(2) = 1.\n\nSample Input 2\n\n23\n00110111001011011001110\n\nSample Output 2\n\n2\n1\n2\n2\n1\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n1\n3", "sample_input": "3\n011\n"}, "reference_outputs": ["2\n1\n1\n"], "source_document_id": "p02609", "source_text": "Score : 400 points\n\nProblem Statement\n\nLet \\mathrm{popcount}(n) be the number of 1s in the binary representation of n.\nFor example, \\mathrm{popcount}(3) = 2, \\mathrm{popcount}(7) = 3, and \\mathrm{popcount}(0) = 0.\n\nLet f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: \"replace n with the remainder when n is divided by \\mathrm{popcount}(n).\" (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.)\n\nFor example, when n=7, it becomes 0 after two operations, as follows:\n\n\\mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1.\n\n\\mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0.\n\nYou are given an integer X with N digits in binary.\nFor each integer i such that 1 \\leq i \\leq N, let X_i be what X becomes when the i-th bit from the top is inverted.\nFind f(X_1), f(X_2), \\ldots, f(X_N).\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nX is an integer with N digits in binary, possibly with leading zeros.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nX\n\nOutput\n\nPrint N lines. The i-th line should contain the value f(X_i).\n\nSample Input 1\n\n3\n011\n\nSample Output 1\n\n2\n1\n1\n\nX_1 = 7, which will change as follows: 7 \\rightarrow 1 \\rightarrow 0. Thus, f(7) = 2.\n\nX_2 = 1, which will change as follows: 1 \\rightarrow 0. Thus, f(1) = 1.\n\nX_3 = 2, which will change as follows: 2 \\rightarrow 0. Thus, f(2) = 1.\n\nSample Input 2\n\n23\n00110111001011011001110\n\nSample Output 2\n\n2\n1\n2\n2\n1\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n1\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 794, "cpu_time_ms": 2209, "memory_kb": 129116}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s165805013", "group_id": "codeNet:p02609", "input_text": "(defun procedure (n &optional (cnt 0))\n (cond\n ((zerop n) cnt)\n (t (procedure (mod n (logcount n)) (1+ cnt)))))\n\n(defun bit->dec (s &optional (ans 0))\n (cond\n ((null s) ans)\n (t\n (let ((num (parse-integer (string (first s)))))\n (bit->dec (rest s) (+ (ash ans 1) num))))))\n\n(defun solve ()\n (let* ((n (read))\n (x (bit->dec (concatenate 'list (read-line))))\n tmp)\n (dotimes (i n)\n (fresh-line)\n (setf tmp (logxor x (ash 1 (1- (- n i)))))\n (princ (procedure tmp)))))\n\n(solve)\n", "language": "Lisp", "metadata": {"date": 1594522516, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02609.html", "problem_id": "p02609", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02609/input.txt", "sample_output_relpath": "derived/input_output/data/p02609/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02609/Lisp/s165805013.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s165805013", "user_id": "u425762225"}, "prompt_components": {"gold_output": "2\n1\n1\n", "input_to_evaluate": "(defun procedure (n &optional (cnt 0))\n (cond\n ((zerop n) cnt)\n (t (procedure (mod n (logcount n)) (1+ cnt)))))\n\n(defun bit->dec (s &optional (ans 0))\n (cond\n ((null s) ans)\n (t\n (let ((num (parse-integer (string (first s)))))\n (bit->dec (rest s) (+ (ash ans 1) num))))))\n\n(defun solve ()\n (let* ((n (read))\n (x (bit->dec (concatenate 'list (read-line))))\n tmp)\n (dotimes (i n)\n (fresh-line)\n (setf tmp (logxor x (ash 1 (1- (- n i)))))\n (princ (procedure tmp)))))\n\n(solve)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nLet \\mathrm{popcount}(n) be the number of 1s in the binary representation of n.\nFor example, \\mathrm{popcount}(3) = 2, \\mathrm{popcount}(7) = 3, and \\mathrm{popcount}(0) = 0.\n\nLet f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: \"replace n with the remainder when n is divided by \\mathrm{popcount}(n).\" (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.)\n\nFor example, when n=7, it becomes 0 after two operations, as follows:\n\n\\mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1.\n\n\\mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0.\n\nYou are given an integer X with N digits in binary.\nFor each integer i such that 1 \\leq i \\leq N, let X_i be what X becomes when the i-th bit from the top is inverted.\nFind f(X_1), f(X_2), \\ldots, f(X_N).\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nX is an integer with N digits in binary, possibly with leading zeros.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nX\n\nOutput\n\nPrint N lines. The i-th line should contain the value f(X_i).\n\nSample Input 1\n\n3\n011\n\nSample Output 1\n\n2\n1\n1\n\nX_1 = 7, which will change as follows: 7 \\rightarrow 1 \\rightarrow 0. Thus, f(7) = 2.\n\nX_2 = 1, which will change as follows: 1 \\rightarrow 0. Thus, f(1) = 1.\n\nX_3 = 2, which will change as follows: 2 \\rightarrow 0. Thus, f(2) = 1.\n\nSample Input 2\n\n23\n00110111001011011001110\n\nSample Output 2\n\n2\n1\n2\n2\n1\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n1\n3", "sample_input": "3\n011\n"}, "reference_outputs": ["2\n1\n1\n"], "source_document_id": "p02609", "source_text": "Score : 400 points\n\nProblem Statement\n\nLet \\mathrm{popcount}(n) be the number of 1s in the binary representation of n.\nFor example, \\mathrm{popcount}(3) = 2, \\mathrm{popcount}(7) = 3, and \\mathrm{popcount}(0) = 0.\n\nLet f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: \"replace n with the remainder when n is divided by \\mathrm{popcount}(n).\" (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.)\n\nFor example, when n=7, it becomes 0 after two operations, as follows:\n\n\\mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1.\n\n\\mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0.\n\nYou are given an integer X with N digits in binary.\nFor each integer i such that 1 \\leq i \\leq N, let X_i be what X becomes when the i-th bit from the top is inverted.\nFind f(X_1), f(X_2), \\ldots, f(X_N).\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nX is an integer with N digits in binary, possibly with leading zeros.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nX\n\nOutput\n\nPrint N lines. The i-th line should contain the value f(X_i).\n\nSample Input 1\n\n3\n011\n\nSample Output 1\n\n2\n1\n1\n\nX_1 = 7, which will change as follows: 7 \\rightarrow 1 \\rightarrow 0. Thus, f(7) = 2.\n\nX_2 = 1, which will change as follows: 1 \\rightarrow 0. Thus, f(1) = 1.\n\nX_3 = 2, which will change as follows: 2 \\rightarrow 0. Thus, f(2) = 1.\n\nSample Input 2\n\n23\n00110111001011011001110\n\nSample Output 2\n\n2\n1\n2\n2\n1\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n1\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 542, "cpu_time_ms": 2210, "memory_kb": 131976}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s101559906", "group_id": "codeNet:p02609", "input_text": "\n(let* ((n (read))\n (loop :for i :downfrom (1- n) :to 0\n :do (let* ((y (if (> (logand x (expt 2 i)) 0)\n (- x (expt 2 i))\n (+ x (expt 2 i))))\n (ans (cond ((= 0 y) 0)\n ((= 1 ) 1)\n ((= 2 (mod y 4)) 1)\n ((= 3 (mod y 4)) 2)\n (format t \"~A~%\" ans))))))))\n", "language": "Lisp", "metadata": {"date": 1594521550, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02609.html", "problem_id": "p02609", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02609/input.txt", "sample_output_relpath": "derived/input_output/data/p02609/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02609/Lisp/s101559906.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s101559906", "user_id": "u608227593"}, "prompt_components": {"gold_output": "2\n1\n1\n", "input_to_evaluate": "\n(let* ((n (read))\n (loop :for i :downfrom (1- n) :to 0\n :do (let* ((y (if (> (logand x (expt 2 i)) 0)\n (- x (expt 2 i))\n (+ x (expt 2 i))))\n (ans (cond ((= 0 y) 0)\n ((= 1 ) 1)\n ((= 2 (mod y 4)) 1)\n ((= 3 (mod y 4)) 2)\n (format t \"~A~%\" ans))))))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nLet \\mathrm{popcount}(n) be the number of 1s in the binary representation of n.\nFor example, \\mathrm{popcount}(3) = 2, \\mathrm{popcount}(7) = 3, and \\mathrm{popcount}(0) = 0.\n\nLet f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: \"replace n with the remainder when n is divided by \\mathrm{popcount}(n).\" (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.)\n\nFor example, when n=7, it becomes 0 after two operations, as follows:\n\n\\mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1.\n\n\\mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0.\n\nYou are given an integer X with N digits in binary.\nFor each integer i such that 1 \\leq i \\leq N, let X_i be what X becomes when the i-th bit from the top is inverted.\nFind f(X_1), f(X_2), \\ldots, f(X_N).\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nX is an integer with N digits in binary, possibly with leading zeros.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nX\n\nOutput\n\nPrint N lines. The i-th line should contain the value f(X_i).\n\nSample Input 1\n\n3\n011\n\nSample Output 1\n\n2\n1\n1\n\nX_1 = 7, which will change as follows: 7 \\rightarrow 1 \\rightarrow 0. Thus, f(7) = 2.\n\nX_2 = 1, which will change as follows: 1 \\rightarrow 0. Thus, f(1) = 1.\n\nX_3 = 2, which will change as follows: 2 \\rightarrow 0. Thus, f(2) = 1.\n\nSample Input 2\n\n23\n00110111001011011001110\n\nSample Output 2\n\n2\n1\n2\n2\n1\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n1\n3", "sample_input": "3\n011\n"}, "reference_outputs": ["2\n1\n1\n"], "source_document_id": "p02609", "source_text": "Score : 400 points\n\nProblem Statement\n\nLet \\mathrm{popcount}(n) be the number of 1s in the binary representation of n.\nFor example, \\mathrm{popcount}(3) = 2, \\mathrm{popcount}(7) = 3, and \\mathrm{popcount}(0) = 0.\n\nLet f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: \"replace n with the remainder when n is divided by \\mathrm{popcount}(n).\" (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.)\n\nFor example, when n=7, it becomes 0 after two operations, as follows:\n\n\\mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1.\n\n\\mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0.\n\nYou are given an integer X with N digits in binary.\nFor each integer i such that 1 \\leq i \\leq N, let X_i be what X becomes when the i-th bit from the top is inverted.\nFind f(X_1), f(X_2), \\ldots, f(X_N).\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nX is an integer with N digits in binary, possibly with leading zeros.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nX\n\nOutput\n\nPrint N lines. The i-th line should contain the value f(X_i).\n\nSample Input 1\n\n3\n011\n\nSample Output 1\n\n2\n1\n1\n\nX_1 = 7, which will change as follows: 7 \\rightarrow 1 \\rightarrow 0. Thus, f(7) = 2.\n\nX_2 = 1, which will change as follows: 1 \\rightarrow 0. Thus, f(1) = 1.\n\nX_3 = 2, which will change as follows: 2 \\rightarrow 0. Thus, f(2) = 1.\n\nSample Input 2\n\n23\n00110111001011011001110\n\nSample Output 2\n\n2\n1\n2\n2\n1\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n1\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 425, "cpu_time_ms": 16, "memory_kb": 23380}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s695877988", "group_id": "codeNet:p02609", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun calc (num)\n (declare (uint62 num))\n (loop for i from 0\n when (zerop num)\n do (return i)\n do (setq num (mod num (logcount num)))))\n\n(defun main ()\n (let* ((n (read))\n (xs (make-array n :element-type 'bit :initial-element 0))\n (powers+1 (make-array (+ n 1) :element-type 'uint31 :initial-element 0))\n (powers-1 (make-array (+ n 1) :element-type 'uint31 :initial-element 0))\n (cumuls+1 (make-array (+ n 1) :element-type 'uint31 :initial-element 0))\n (cumuls-1 (make-array (+ n 1) :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (ecase (read-char)\n (#\\0)\n (#\\1 (setf (aref xs i) 1))))\n (setf (aref powers+1 0) 1\n (aref powers-1 0) 1)\n (let ((c (count 1 xs)))\n (dotimes (i n)\n (setf (aref powers+1 (+ i 1))\n (mod (* 2 (aref powers+1 i)) (+ c 1))))\n (unless (zerop c)\n (dotimes (i n)\n (setf (aref powers-1 (+ i 1))\n (mod (* 2 (aref powers-1 i)) (- c 1)))))\n (let ((xs (reverse xs)))\n (dotimes (i n)\n (setf (aref cumuls+1 (+ i 1))\n (mod (+ (if (= 1 (aref xs i))\n (aref powers+1 i)\n 0)\n (aref cumuls+1 i))\n (+ c 1))))\n (unless (zerop c)\n (dotimes (i n)\n (setf (aref cumuls-1 (+ i 1))\n (mod (+ (if (= 1 (aref xs i))\n (aref powers-1 i)\n 0)\n (aref cumuls-1 i))\n (- c 1))))))\n (dbg cumuls+1 cumuls-1)\n (let ((total+ (aref cumuls+1 n))\n (total- (aref cumuls-1 n)))\n (dotimes (i n)\n (println\n (if (zerop (aref xs i))\n (let ((init (mod (+ total+ (aref powers+1 (- n i 1)))\n (+ c 1))))\n (+ 1 (calc init)))\n (let ((init (mod (- total- (aref powers-1 (- n i 1)))\n (- c 1))))\n (+ 1 (calc init))))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n011\n\"\n \"2\n1\n1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"23\n00110111001011011001110\n\"\n \"2\n1\n2\n2\n1\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n1\n3\n\")))\n", "language": "Lisp", "metadata": {"date": 1594517295, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02609.html", "problem_id": "p02609", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02609/input.txt", "sample_output_relpath": "derived/input_output/data/p02609/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02609/Lisp/s695877988.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s695877988", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n1\n1\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun calc (num)\n (declare (uint62 num))\n (loop for i from 0\n when (zerop num)\n do (return i)\n do (setq num (mod num (logcount num)))))\n\n(defun main ()\n (let* ((n (read))\n (xs (make-array n :element-type 'bit :initial-element 0))\n (powers+1 (make-array (+ n 1) :element-type 'uint31 :initial-element 0))\n (powers-1 (make-array (+ n 1) :element-type 'uint31 :initial-element 0))\n (cumuls+1 (make-array (+ n 1) :element-type 'uint31 :initial-element 0))\n (cumuls-1 (make-array (+ n 1) :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (ecase (read-char)\n (#\\0)\n (#\\1 (setf (aref xs i) 1))))\n (setf (aref powers+1 0) 1\n (aref powers-1 0) 1)\n (let ((c (count 1 xs)))\n (dotimes (i n)\n (setf (aref powers+1 (+ i 1))\n (mod (* 2 (aref powers+1 i)) (+ c 1))))\n (unless (zerop c)\n (dotimes (i n)\n (setf (aref powers-1 (+ i 1))\n (mod (* 2 (aref powers-1 i)) (- c 1)))))\n (let ((xs (reverse xs)))\n (dotimes (i n)\n (setf (aref cumuls+1 (+ i 1))\n (mod (+ (if (= 1 (aref xs i))\n (aref powers+1 i)\n 0)\n (aref cumuls+1 i))\n (+ c 1))))\n (unless (zerop c)\n (dotimes (i n)\n (setf (aref cumuls-1 (+ i 1))\n (mod (+ (if (= 1 (aref xs i))\n (aref powers-1 i)\n 0)\n (aref cumuls-1 i))\n (- c 1))))))\n (dbg cumuls+1 cumuls-1)\n (let ((total+ (aref cumuls+1 n))\n (total- (aref cumuls-1 n)))\n (dotimes (i n)\n (println\n (if (zerop (aref xs i))\n (let ((init (mod (+ total+ (aref powers+1 (- n i 1)))\n (+ c 1))))\n (+ 1 (calc init)))\n (let ((init (mod (- total- (aref powers-1 (- n i 1)))\n (- c 1))))\n (+ 1 (calc init))))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n011\n\"\n \"2\n1\n1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"23\n00110111001011011001110\n\"\n \"2\n1\n2\n2\n1\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n1\n3\n\")))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nLet \\mathrm{popcount}(n) be the number of 1s in the binary representation of n.\nFor example, \\mathrm{popcount}(3) = 2, \\mathrm{popcount}(7) = 3, and \\mathrm{popcount}(0) = 0.\n\nLet f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: \"replace n with the remainder when n is divided by \\mathrm{popcount}(n).\" (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.)\n\nFor example, when n=7, it becomes 0 after two operations, as follows:\n\n\\mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1.\n\n\\mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0.\n\nYou are given an integer X with N digits in binary.\nFor each integer i such that 1 \\leq i \\leq N, let X_i be what X becomes when the i-th bit from the top is inverted.\nFind f(X_1), f(X_2), \\ldots, f(X_N).\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nX is an integer with N digits in binary, possibly with leading zeros.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nX\n\nOutput\n\nPrint N lines. The i-th line should contain the value f(X_i).\n\nSample Input 1\n\n3\n011\n\nSample Output 1\n\n2\n1\n1\n\nX_1 = 7, which will change as follows: 7 \\rightarrow 1 \\rightarrow 0. Thus, f(7) = 2.\n\nX_2 = 1, which will change as follows: 1 \\rightarrow 0. Thus, f(1) = 1.\n\nX_3 = 2, which will change as follows: 2 \\rightarrow 0. Thus, f(2) = 1.\n\nSample Input 2\n\n23\n00110111001011011001110\n\nSample Output 2\n\n2\n1\n2\n2\n1\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n1\n3", "sample_input": "3\n011\n"}, "reference_outputs": ["2\n1\n1\n"], "source_document_id": "p02609", "source_text": "Score : 400 points\n\nProblem Statement\n\nLet \\mathrm{popcount}(n) be the number of 1s in the binary representation of n.\nFor example, \\mathrm{popcount}(3) = 2, \\mathrm{popcount}(7) = 3, and \\mathrm{popcount}(0) = 0.\n\nLet f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: \"replace n with the remainder when n is divided by \\mathrm{popcount}(n).\" (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.)\n\nFor example, when n=7, it becomes 0 after two operations, as follows:\n\n\\mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1.\n\n\\mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0.\n\nYou are given an integer X with N digits in binary.\nFor each integer i such that 1 \\leq i \\leq N, let X_i be what X becomes when the i-th bit from the top is inverted.\nFind f(X_1), f(X_2), \\ldots, f(X_N).\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nX is an integer with N digits in binary, possibly with leading zeros.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nX\n\nOutput\n\nPrint N lines. The i-th line should contain the value f(X_i).\n\nSample Input 1\n\n3\n011\n\nSample Output 1\n\n2\n1\n1\n\nX_1 = 7, which will change as follows: 7 \\rightarrow 1 \\rightarrow 0. Thus, f(7) = 2.\n\nX_2 = 1, which will change as follows: 1 \\rightarrow 0. Thus, f(1) = 1.\n\nX_3 = 2, which will change as follows: 2 \\rightarrow 0. Thus, f(2) = 1.\n\nSample Input 2\n\n23\n00110111001011011001110\n\nSample Output 2\n\n2\n1\n2\n2\n1\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n1\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6894, "cpu_time_ms": 331, "memory_kb": 28088}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s062054074", "group_id": "codeNet:p02613", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (ac 0)\n (wa 0)\n (tle 0)\n (re 0))\n (dotimes (_ n)\n (ecase (read)\n (ac (incf ac))\n (wa (incf wa))\n (tle (incf tle))\n (re (incf re))))\n (format t \"AC x ~D~%\" ac)\n (format t \"WA x ~D~%\" wa)\n (format t \"TLE x ~D~%\" tle)\n (format t \"RE x ~D~%\" re)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" () :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\nAC\nTLE\nAC\nAC\nWA\nTLE\n\"\n \"AC x 3\nWA x 1\nTLE x 2\nRE x 0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\n\"\n \"AC x 10\nWA x 0\nTLE x 0\nRE x 0\n\")))\n", "language": "Lisp", "metadata": {"date": 1594022256, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02613.html", "problem_id": "p02613", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02613/input.txt", "sample_output_relpath": "derived/input_output/data/p02613/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02613/Lisp/s062054074.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s062054074", "user_id": "u352600849"}, "prompt_components": {"gold_output": "AC x 3\nWA x 1\nTLE x 2\nRE x 0\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (ac 0)\n (wa 0)\n (tle 0)\n (re 0))\n (dotimes (_ n)\n (ecase (read)\n (ac (incf ac))\n (wa (incf wa))\n (tle (incf tle))\n (re (incf re))))\n (format t \"AC x ~D~%\" ac)\n (format t \"WA x ~D~%\" wa)\n (format t \"TLE x ~D~%\" tle)\n (format t \"RE x ~D~%\" re)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" () :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\nAC\nTLE\nAC\nAC\nWA\nTLE\n\"\n \"AC x 3\nWA x 1\nTLE x 2\nRE x 0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\n\"\n \"AC x 10\nWA x 0\nTLE x 0\nRE x 0\n\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.\n\nThe problem has N test cases.\n\nFor each test case i (1\\leq i \\leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is AC, WA, TLE, and RE, respectively.\n\nSee the Output section for the output format.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\nS_i is AC, WA, TLE, or RE.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n\\vdots\nS_N\n\nOutput\n\nLet C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict is AC, WA, TLE, and RE, respectively. Print the following:\n\nAC x C_0\nWA x C_1\nTLE x C_2\nRE x C_3\n\nSample Input 1\n\n6\nAC\nTLE\nAC\nAC\nWA\nTLE\n\nSample Output 1\n\nAC x 3\nWA x 1\nTLE x 2\nRE x 0\n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is AC, WA, TLE, and RE, respectively.\n\nSample Input 2\n\n10\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\n\nSample Output 2\n\nAC x 10\nWA x 0\nTLE x 0\nRE x 0", "sample_input": "6\nAC\nTLE\nAC\nAC\nWA\nTLE\n"}, "reference_outputs": ["AC x 3\nWA x 1\nTLE x 2\nRE x 0\n"], "source_document_id": "p02613", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.\n\nThe problem has N test cases.\n\nFor each test case i (1\\leq i \\leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is AC, WA, TLE, and RE, respectively.\n\nSee the Output section for the output format.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\nS_i is AC, WA, TLE, or RE.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n\\vdots\nS_N\n\nOutput\n\nLet C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict is AC, WA, TLE, and RE, respectively. Print the following:\n\nAC x C_0\nWA x C_1\nTLE x C_2\nRE x C_3\n\nSample Input 1\n\n6\nAC\nTLE\nAC\nAC\nWA\nTLE\n\nSample Output 1\n\nAC x 3\nWA x 1\nTLE x 2\nRE x 0\n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is AC, WA, TLE, and RE, respectively.\n\nSample Input 2\n\n10\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\n\nSample Output 2\n\nAC x 10\nWA x 0\nTLE x 0\nRE x 0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3989, "cpu_time_ms": 100, "memory_kb": 77312}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s625503868", "group_id": "codeNet:p02613", "input_text": "(defun main ()\n (let* ((n (read))\n\t (s (make-array n)))\n (dotimes (i n)\n (setf (aref s i) (read-line)))\n (format t \"AC x ~a~%\" (count \"AC\" s :test #'equal))\n (format t \"WA x ~a~%\" (count \"WA\" s :test #'equal))\n (format t \"TLE x ~a~%\" (count \"TLE\" s :test #'equal))\n (format t \"RE x ~a~%\" (count \"RE\" s ::test #'equal))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1593998771, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02613.html", "problem_id": "p02613", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02613/input.txt", "sample_output_relpath": "derived/input_output/data/p02613/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02613/Lisp/s625503868.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s625503868", "user_id": "u425762225"}, "prompt_components": {"gold_output": "AC x 3\nWA x 1\nTLE x 2\nRE x 0\n", "input_to_evaluate": "(defun main ()\n (let* ((n (read))\n\t (s (make-array n)))\n (dotimes (i n)\n (setf (aref s i) (read-line)))\n (format t \"AC x ~a~%\" (count \"AC\" s :test #'equal))\n (format t \"WA x ~a~%\" (count \"WA\" s :test #'equal))\n (format t \"TLE x ~a~%\" (count \"TLE\" s :test #'equal))\n (format t \"RE x ~a~%\" (count \"RE\" s ::test #'equal))))\n\n(main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.\n\nThe problem has N test cases.\n\nFor each test case i (1\\leq i \\leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is AC, WA, TLE, and RE, respectively.\n\nSee the Output section for the output format.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\nS_i is AC, WA, TLE, or RE.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n\\vdots\nS_N\n\nOutput\n\nLet C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict is AC, WA, TLE, and RE, respectively. Print the following:\n\nAC x C_0\nWA x C_1\nTLE x C_2\nRE x C_3\n\nSample Input 1\n\n6\nAC\nTLE\nAC\nAC\nWA\nTLE\n\nSample Output 1\n\nAC x 3\nWA x 1\nTLE x 2\nRE x 0\n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is AC, WA, TLE, and RE, respectively.\n\nSample Input 2\n\n10\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\n\nSample Output 2\n\nAC x 10\nWA x 0\nTLE x 0\nRE x 0", "sample_input": "6\nAC\nTLE\nAC\nAC\nWA\nTLE\n"}, "reference_outputs": ["AC x 3\nWA x 1\nTLE x 2\nRE x 0\n"], "source_document_id": "p02613", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.\n\nThe problem has N test cases.\n\nFor each test case i (1\\leq i \\leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is AC, WA, TLE, and RE, respectively.\n\nSee the Output section for the output format.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\nS_i is AC, WA, TLE, or RE.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n\\vdots\nS_N\n\nOutput\n\nLet C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict is AC, WA, TLE, and RE, respectively. Print the following:\n\nAC x C_0\nWA x C_1\nTLE x C_2\nRE x C_3\n\nSample Input 1\n\n6\nAC\nTLE\nAC\nAC\nWA\nTLE\n\nSample Output 1\n\nAC x 3\nWA x 1\nTLE x 2\nRE x 0\n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is AC, WA, TLE, and RE, respectively.\n\nSample Input 2\n\n10\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\n\nSample Output 2\n\nAC x 10\nWA x 0\nTLE x 0\nRE x 0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 350, "cpu_time_ms": 82, "memory_kb": 59772}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s471638092", "group_id": "codeNet:p02614", "input_text": "(defun convert (h w num)\n (let* ((r1 0))\n (loop for i from 0 below h\n do (setf r1 (+ (ash r1 w)\n (if (zerop (logand (ash 1 (+ i w)) num))\n 0\n (1- (expt 2 w))))))\n\n (loop with pat = (logand num (1- (expt 2 w)))\n for i from 0 below h\n do (setf r1 (logior r1 (ash pat (* i w)))))\n (logxor r1 (1- (expt 2 (* h w))))))\n;;(convert 2 3 #b01000)\n\n(defun cnt (bits)\n (loop with num = 0\n until (zerop bits)\n do (unless (zerop (logand bits 1))\n (incf num))\n (setf bits(ash bits -1))\n finally (return num)))\n\n(let* ((h (read))\n (w (read))\n (k (read))\n (bits (loop with result = 0\n repeat h\n do (loop\n repeat w\n do (setf result (+ (* 2 result) (if (eql (read-char) #\\#) 1 0))))\n do (read-char)\n finally (return result))))\n (format t \"~A~%\" (loop for i from 0 below (expt 2 (+ h w))\n count (eql (cnt (logand bits (convert h w i)))\n k))))", "language": "Lisp", "metadata": {"date": 1594001941, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02614.html", "problem_id": "p02614", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02614/input.txt", "sample_output_relpath": "derived/input_output/data/p02614/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02614/Lisp/s471638092.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s471638092", "user_id": "u607637432"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defun convert (h w num)\n (let* ((r1 0))\n (loop for i from 0 below h\n do (setf r1 (+ (ash r1 w)\n (if (zerop (logand (ash 1 (+ i w)) num))\n 0\n (1- (expt 2 w))))))\n\n (loop with pat = (logand num (1- (expt 2 w)))\n for i from 0 below h\n do (setf r1 (logior r1 (ash pat (* i w)))))\n (logxor r1 (1- (expt 2 (* h w))))))\n;;(convert 2 3 #b01000)\n\n(defun cnt (bits)\n (loop with num = 0\n until (zerop bits)\n do (unless (zerop (logand bits 1))\n (incf num))\n (setf bits(ash bits -1))\n finally (return num)))\n\n(let* ((h (read))\n (w (read))\n (k (read))\n (bits (loop with result = 0\n repeat h\n do (loop\n repeat w\n do (setf result (+ (* 2 result) (if (eql (read-char) #\\#) 1 0))))\n do (read-char)\n finally (return result))))\n (format t \"~A~%\" (loop for i from 0 below (expt 2 (+ h w))\n count (eql (cnt (logand bits (convert h w i)))\n k))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWe have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \\leq i \\leq H, 1 \\leq j \\leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is ., and black if c_{i,j} is #.\n\nConsider doing the following operation:\n\nChoose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns.\n\nYou are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.\n\nConstraints\n\n1 \\leq H, W \\leq 6\n\n1 \\leq K \\leq HW\n\nc_{i,j} is . or #.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W K\nc_{1,1}c_{1,2}...c_{1,W}\nc_{2,1}c_{2,2}...c_{2,W}\n:\nc_{H,1}c_{H,2}...c_{H,W}\n\nOutput\n\nPrint an integer representing the number of choices of rows and columns satisfying the condition.\n\nSample Input 1\n\n2 3 2\n..#\n###\n\nSample Output 1\n\n5\n\nFive choices below satisfy the condition.\n\nThe 1-st row and 1-st column\n\nThe 1-st row and 2-nd column\n\nThe 1-st row and 3-rd column\n\nThe 1-st and 2-nd column\n\nThe 3-rd column\n\nSample Input 2\n\n2 3 4\n..#\n###\n\nSample Output 2\n\n1\n\nOne choice, which is choosing nothing, satisfies the condition.\n\nSample Input 3\n\n2 2 3\n##\n##\n\nSample Output 3\n\n0\n\nSample Input 4\n\n6 6 8\n..##..\n.#..#.\n#....#\n######\n#....#\n#....#\n\nSample Output 4\n\n208", "sample_input": "2 3 2\n..#\n###\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02614", "source_text": "Score : 300 points\n\nProblem Statement\n\nWe have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \\leq i \\leq H, 1 \\leq j \\leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is ., and black if c_{i,j} is #.\n\nConsider doing the following operation:\n\nChoose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns.\n\nYou are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.\n\nConstraints\n\n1 \\leq H, W \\leq 6\n\n1 \\leq K \\leq HW\n\nc_{i,j} is . or #.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W K\nc_{1,1}c_{1,2}...c_{1,W}\nc_{2,1}c_{2,2}...c_{2,W}\n:\nc_{H,1}c_{H,2}...c_{H,W}\n\nOutput\n\nPrint an integer representing the number of choices of rows and columns satisfying the condition.\n\nSample Input 1\n\n2 3 2\n..#\n###\n\nSample Output 1\n\n5\n\nFive choices below satisfy the condition.\n\nThe 1-st row and 1-st column\n\nThe 1-st row and 2-nd column\n\nThe 1-st row and 3-rd column\n\nThe 1-st and 2-nd column\n\nThe 3-rd column\n\nSample Input 2\n\n2 3 4\n..#\n###\n\nSample Output 2\n\n1\n\nOne choice, which is choosing nothing, satisfies the condition.\n\nSample Input 3\n\n2 2 3\n##\n##\n\nSample Output 3\n\n0\n\nSample Input 4\n\n6 6 8\n..##..\n.#..#.\n#....#\n######\n#....#\n#....#\n\nSample Output 4\n\n208", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1180, "cpu_time_ms": 22, "memory_kb": 24632}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s500430343", "group_id": "codeNet:p02615", "input_text": "(defun solve (n a)\n (reduce #'+ (subseq a 0 (1- (length a)))))\n\n(defun main ()\n (let ((n (read))\n\t(a (sort (read-from-string\n\t\t (concatenate 'string \"(\" (read-line) \")\")) #'>=)))\n (princ (solve n a))\n (fresh-line)))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1594001298, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02615.html", "problem_id": "p02615", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02615/input.txt", "sample_output_relpath": "derived/input_output/data/p02615/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02615/Lisp/s500430343.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s500430343", "user_id": "u425762225"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(defun solve (n a)\n (reduce #'+ (subseq a 0 (1- (length a)))))\n\n(defun main ()\n (let ((n (read))\n\t(a (sort (read-from-string\n\t\t (concatenate 'string \"(\" (read-line) \")\")) #'>=)))\n (princ (solve n a))\n (fresh-line)))\n\n(main)\n", "problem_context": "Score: 400 points\n\nProblem Statement\n\nQuickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i.\n\nThe N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere.\n\nWhen each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0.\n\nWhat is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 \\dots A_N\n\nOutput\n\nPrint the maximum total comfort the N players can get.\n\nSample Input 1\n\n4\n2 2 1 3\n\nSample Output 1\n\n7\n\nBy arriving at the place in the order Player 4, 2, 1, 3, and cutting into the circle as shown in the figure, they can get the total comfort of 7.\n\nThey cannot get the total comfort greater than 7, so the answer is 7.\n\nSample Input 2\n\n7\n1 1 1 1 1 1 1\n\nSample Output 2\n\n6", "sample_input": "4\n2 2 1 3\n"}, "reference_outputs": ["7\n"], "source_document_id": "p02615", "source_text": "Score: 400 points\n\nProblem Statement\n\nQuickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i.\n\nThe N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere.\n\nWhen each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0.\n\nWhat is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 \\dots A_N\n\nOutput\n\nPrint the maximum total comfort the N players can get.\n\nSample Input 1\n\n4\n2 2 1 3\n\nSample Output 1\n\n7\n\nBy arriving at the place in the order Player 4, 2, 1, 3, and cutting into the circle as shown in the figure, they can get the total comfort of 7.\n\nThey cannot get the total comfort greater than 7, so the answer is 7.\n\nSample Input 2\n\n7\n1 1 1 1 1 1 1\n\nSample Output 2\n\n6", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 234, "cpu_time_ms": 239, "memory_kb": 59900}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s733260381", "group_id": "codeNet:p02616", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun solve (as k)\n (declare #.OPT\n (uint31 k)\n ((simple-array int32 (*)) as)\n (inline sort))\n (let* ((n (length as))\n (as+ (make-array n :element-type 'int32 :fill-pointer 0))\n (as- (make-array n :element-type 'int32 :fill-pointer 0)))\n (dotimes (i n)\n (let ((a (aref as i)))\n (cond ((> a 0) (vector-push a as+))\n ((< a 0) (vector-push a as-)))))\n (setq as+ (sort as+ #'>)\n as- (sort as- #'<))\n (let ((res (if (oddp k) (aref as+ 0) 1))\n (i+ (if (oddp k) 1 0))\n (i- 0))\n (declare (uint31 res i+ i-))\n (loop while (< (+ i+ i-) k)\n for prod+ = (if (< (+ i+ 1) (length as+))\n (* (aref as+ i+) (aref as+ (+ i+ 1)))\n 1)\n for prod- = (if (< (+ i- 1) (length as-))\n (* (aref as- i-) (aref as- (+ i- 1)))\n 1)\n when (>= prod+ prod-)\n do (mulfmod res (mod prod+ +mod+))\n (incf i+ 2)\n else\n do (mulfmod res (mod prod- +mod+))\n (incf i- 2))\n res)))\n\n(defun main ()\n (declare (inline sort))\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'int32 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (let ((num+ (count-if #'plusp as))\n (num- (count-if #'minusp as)))\n (println\n (if (loop for d- from 0 to k by 2\n for d+ = (- k d-)\n thereis (and (<= d- num-) (<= d+ num+)))\n (solve as k)\n (let ((as (sort as #'< :key #'abs)))\n (reduce #'mod* as :end k :initial-value 1)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"200000 100000~%\")\n (dotimes (i 200000)\n (println (- (random 1000000000) 500000000) out))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 2\n1 2 -3 -4\n\"\n \"12\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 3\n-1 -2 -3 -4\n\"\n \"1000000001\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 1\n-1 1000000000\n\"\n \"1000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 10\n1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1\n\"\n \"999983200\n\")))\n", "language": "Lisp", "metadata": {"date": 1594147038, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02616.html", "problem_id": "p02616", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02616/input.txt", "sample_output_relpath": "derived/input_output/data/p02616/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02616/Lisp/s733260381.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s733260381", "user_id": "u352600849"}, "prompt_components": {"gold_output": "12\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun solve (as k)\n (declare #.OPT\n (uint31 k)\n ((simple-array int32 (*)) as)\n (inline sort))\n (let* ((n (length as))\n (as+ (make-array n :element-type 'int32 :fill-pointer 0))\n (as- (make-array n :element-type 'int32 :fill-pointer 0)))\n (dotimes (i n)\n (let ((a (aref as i)))\n (cond ((> a 0) (vector-push a as+))\n ((< a 0) (vector-push a as-)))))\n (setq as+ (sort as+ #'>)\n as- (sort as- #'<))\n (let ((res (if (oddp k) (aref as+ 0) 1))\n (i+ (if (oddp k) 1 0))\n (i- 0))\n (declare (uint31 res i+ i-))\n (loop while (< (+ i+ i-) k)\n for prod+ = (if (< (+ i+ 1) (length as+))\n (* (aref as+ i+) (aref as+ (+ i+ 1)))\n 1)\n for prod- = (if (< (+ i- 1) (length as-))\n (* (aref as- i-) (aref as- (+ i- 1)))\n 1)\n when (>= prod+ prod-)\n do (mulfmod res (mod prod+ +mod+))\n (incf i+ 2)\n else\n do (mulfmod res (mod prod- +mod+))\n (incf i- 2))\n res)))\n\n(defun main ()\n (declare (inline sort))\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'int32 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (let ((num+ (count-if #'plusp as))\n (num- (count-if #'minusp as)))\n (println\n (if (loop for d- from 0 to k by 2\n for d+ = (- k d-)\n thereis (and (<= d- num-) (<= d+ num+)))\n (solve as k)\n (let ((as (sort as #'< :key #'abs)))\n (reduce #'mod* as :end k :initial-value 1)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"200000 100000~%\")\n (dotimes (i 200000)\n (println (- (random 1000000000) 500000000) out))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 2\n1 2 -3 -4\n\"\n \"12\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 3\n-1 -2 -3 -4\n\"\n \"1000000001\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 1\n-1 1000000000\n\"\n \"1000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 10\n1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1\n\"\n \"999983200\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nGiven are N integers A_1,\\ldots,A_N.\n\nWe will choose exactly K of these elements. Find the maximum possible product of the chosen elements.\n\nThen, print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).\n\nConstraints\n\n1 \\leq K \\leq N \\leq 2\\times 10^5\n\n|A_i| \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 \\ldots A_N\n\nOutput\n\nPrint the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).\n\nSample Input 1\n\n4 2\n1 2 -3 -4\n\nSample Output 1\n\n12\n\nThe possible products of the two chosen elements are 2, -3, -4, -6, -8, and 12, so the maximum product is 12.\n\nSample Input 2\n\n4 3\n-1 -2 -3 -4\n\nSample Output 2\n\n1000000001\n\nThe possible products of the three chosen elements are -24, -12, -8, and -6, so the maximum product is -6.\n\nWe print this value modulo (10^9+7), that is, 1000000001.\n\nSample Input 3\n\n2 1\n-1 1000000000\n\nSample Output 3\n\n1000000000\n\nThe possible products of the one chosen element are -1 and 1000000000, so the maximum product is 1000000000.\n\nSample Input 4\n\n10 10\n1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1\n\nSample Output 4\n\n999983200\n\nBe sure to print the product modulo (10^9+7).", "sample_input": "4 2\n1 2 -3 -4\n"}, "reference_outputs": ["12\n"], "source_document_id": "p02616", "source_text": "Score : 500 points\n\nProblem Statement\n\nGiven are N integers A_1,\\ldots,A_N.\n\nWe will choose exactly K of these elements. Find the maximum possible product of the chosen elements.\n\nThen, print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).\n\nConstraints\n\n1 \\leq K \\leq N \\leq 2\\times 10^5\n\n|A_i| \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 \\ldots A_N\n\nOutput\n\nPrint the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).\n\nSample Input 1\n\n4 2\n1 2 -3 -4\n\nSample Output 1\n\n12\n\nThe possible products of the two chosen elements are 2, -3, -4, -6, -8, and 12, so the maximum product is 12.\n\nSample Input 2\n\n4 3\n-1 -2 -3 -4\n\nSample Output 2\n\n1000000001\n\nThe possible products of the three chosen elements are -24, -12, -8, and -6, so the maximum product is -6.\n\nWe print this value modulo (10^9+7), that is, 1000000001.\n\nSample Input 3\n\n2 1\n-1 1000000000\n\nSample Output 3\n\n1000000000\n\nThe possible products of the one chosen element are -1 and 1000000000, so the maximum product is 1000000000.\n\nSample Input 4\n\n10 10\n1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1\n\nSample Output 4\n\n999983200\n\nBe sure to print the product modulo (10^9+7).", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7979, "cpu_time_ms": 113, "memory_kb": 32164}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s532250243", "group_id": "codeNet:p02616", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun solve (as k)\n (declare ((simple-array int32 (*)) as))\n (let* ((n (length as))\n (n+ 0)\n (n- 0)\n (as+ (make-array n :element-type 'uint31 :initial-element 0))\n (as- (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (let ((a (aref as i)))\n (cond ((> a 0)\n (setf (aref as+ n+) a)\n (incf n+))\n ((< a 0)\n (setf (aref as- n-) (- a))\n (incf n-)))))\n (setq as+ (sort as+ #'>)\n as- (sort as- #'>))\n (dbg as+ as-)\n (let ((cumuls+ (make-array (+ n+ 1) :element-type 'uint31 :initial-element 1))\n (cumuls- (make-array (+ n- 1) :element-type 'uint31 :initial-element 1))\n (logcumuls+ (make-array (+ n+ 1) :element-type 'double-float :initial-element 0d0))\n (logcumuls- (make-array (+ n- 1) :element-type 'double-float :initial-element 0d0))\n (as (delete 0 as)))\n (dotimes (i n+)\n (let ((a (aref as+ i)))\n (setf (aref cumuls+ (+ i 1)) (mod* (aref cumuls+ i) a)\n (aref logcumuls+ (+ i 1)) (+ (aref logcumuls+ i) (log (float a 1d0) 1.1d0)))))\n (dotimes (i n-)\n (let ((a (aref as- i)))\n (setf (aref cumuls- (+ i 1)) (mod* (aref cumuls- i) a)\n (aref logcumuls- (+ i 1)) (+ (aref logcumuls- i) (log (float a 1d0) 1.1d0)))))\n (setq as (sort as #'> :key #'abs))\n (let ((res1 0)\n (maxlog most-negative-double-float)\n fail)\n (loop for d- from 0 to k by 2\n for d+ = (- k d-)\n when (and (<= d- n-) (<= d+ n+))\n do (let ((log (+ (aref logcumuls+ d+) (aref logcumuls- d-))))\n (when (< (abs (- log maxlog)) 1d-8)\n (setq fail t)\n (return))\n (when (> log maxlog)\n (when (or (> (abs (- log maxlog)) 1d-9)\n (< (random 1d0) 0.5d0))\n (setq maxlog log\n res1 (mod* (aref cumuls+ d+) (aref cumuls- d-)))))))\n res1\n ;; (if fail\n ;; (let ((minus 0)\n ;; (res 1))\n ;; #>as\n ;; (dotimes (i (length as))\n ;; (let ((a (aref as i)))\n ;; (if (> a 0)\n ;; (mulfmod res a)\n ;; (if (= i (- k 1))\n ;; (if (evenp minus)\n ;; (let ((new-pos (position-if #'plusp as :start i)))\n ;; (mulfmod res (aref as new-pos)))\n ;; (mulfmod res a))\n ;; (progn\n ;; (mulfmod res a)\n ;; (incf minus))))\n ;; (when (= i (- k 1))\n ;; (return))))\n ;; res)\n ;; res1)\n ))))\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'int32 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (let ((num+ (count-if #'plusp as))\n (num0 (count 0 as))\n (num- (count-if #'minusp as)))\n (dbg num+ num0 num-)\n (println\n (if (loop for d- from 0 to k by 2\n for d+ = (- k d-)\n thereis (and (<= d- num-) (<= d+ num+)))\n (solve as k)\n (let ((as (sort as #'< :key #'abs)))\n (reduce #'mod* as :end k :initial-value 1)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" () :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 2\n1 2 -3 -4\n\"\n \"12\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 3\n-1 -2 -3 -4\n\"\n \"1000000001\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 1\n-1 1000000000\n\"\n \"1000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 10\n1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1\n\"\n \"999983200\n\")))\n", "language": "Lisp", "metadata": {"date": 1594005737, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02616.html", "problem_id": "p02616", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02616/input.txt", "sample_output_relpath": "derived/input_output/data/p02616/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02616/Lisp/s532250243.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s532250243", "user_id": "u352600849"}, "prompt_components": {"gold_output": "12\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun solve (as k)\n (declare ((simple-array int32 (*)) as))\n (let* ((n (length as))\n (n+ 0)\n (n- 0)\n (as+ (make-array n :element-type 'uint31 :initial-element 0))\n (as- (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (let ((a (aref as i)))\n (cond ((> a 0)\n (setf (aref as+ n+) a)\n (incf n+))\n ((< a 0)\n (setf (aref as- n-) (- a))\n (incf n-)))))\n (setq as+ (sort as+ #'>)\n as- (sort as- #'>))\n (dbg as+ as-)\n (let ((cumuls+ (make-array (+ n+ 1) :element-type 'uint31 :initial-element 1))\n (cumuls- (make-array (+ n- 1) :element-type 'uint31 :initial-element 1))\n (logcumuls+ (make-array (+ n+ 1) :element-type 'double-float :initial-element 0d0))\n (logcumuls- (make-array (+ n- 1) :element-type 'double-float :initial-element 0d0))\n (as (delete 0 as)))\n (dotimes (i n+)\n (let ((a (aref as+ i)))\n (setf (aref cumuls+ (+ i 1)) (mod* (aref cumuls+ i) a)\n (aref logcumuls+ (+ i 1)) (+ (aref logcumuls+ i) (log (float a 1d0) 1.1d0)))))\n (dotimes (i n-)\n (let ((a (aref as- i)))\n (setf (aref cumuls- (+ i 1)) (mod* (aref cumuls- i) a)\n (aref logcumuls- (+ i 1)) (+ (aref logcumuls- i) (log (float a 1d0) 1.1d0)))))\n (setq as (sort as #'> :key #'abs))\n (let ((res1 0)\n (maxlog most-negative-double-float)\n fail)\n (loop for d- from 0 to k by 2\n for d+ = (- k d-)\n when (and (<= d- n-) (<= d+ n+))\n do (let ((log (+ (aref logcumuls+ d+) (aref logcumuls- d-))))\n (when (< (abs (- log maxlog)) 1d-8)\n (setq fail t)\n (return))\n (when (> log maxlog)\n (when (or (> (abs (- log maxlog)) 1d-9)\n (< (random 1d0) 0.5d0))\n (setq maxlog log\n res1 (mod* (aref cumuls+ d+) (aref cumuls- d-)))))))\n res1\n ;; (if fail\n ;; (let ((minus 0)\n ;; (res 1))\n ;; #>as\n ;; (dotimes (i (length as))\n ;; (let ((a (aref as i)))\n ;; (if (> a 0)\n ;; (mulfmod res a)\n ;; (if (= i (- k 1))\n ;; (if (evenp minus)\n ;; (let ((new-pos (position-if #'plusp as :start i)))\n ;; (mulfmod res (aref as new-pos)))\n ;; (mulfmod res a))\n ;; (progn\n ;; (mulfmod res a)\n ;; (incf minus))))\n ;; (when (= i (- k 1))\n ;; (return))))\n ;; res)\n ;; res1)\n ))))\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'int32 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (let ((num+ (count-if #'plusp as))\n (num0 (count 0 as))\n (num- (count-if #'minusp as)))\n (dbg num+ num0 num-)\n (println\n (if (loop for d- from 0 to k by 2\n for d+ = (- k d-)\n thereis (and (<= d- num-) (<= d+ num+)))\n (solve as k)\n (let ((as (sort as #'< :key #'abs)))\n (reduce #'mod* as :end k :initial-value 1)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" () :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 2\n1 2 -3 -4\n\"\n \"12\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 3\n-1 -2 -3 -4\n\"\n \"1000000001\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 1\n-1 1000000000\n\"\n \"1000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 10\n1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1\n\"\n \"999983200\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nGiven are N integers A_1,\\ldots,A_N.\n\nWe will choose exactly K of these elements. Find the maximum possible product of the chosen elements.\n\nThen, print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).\n\nConstraints\n\n1 \\leq K \\leq N \\leq 2\\times 10^5\n\n|A_i| \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 \\ldots A_N\n\nOutput\n\nPrint the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).\n\nSample Input 1\n\n4 2\n1 2 -3 -4\n\nSample Output 1\n\n12\n\nThe possible products of the two chosen elements are 2, -3, -4, -6, -8, and 12, so the maximum product is 12.\n\nSample Input 2\n\n4 3\n-1 -2 -3 -4\n\nSample Output 2\n\n1000000001\n\nThe possible products of the three chosen elements are -24, -12, -8, and -6, so the maximum product is -6.\n\nWe print this value modulo (10^9+7), that is, 1000000001.\n\nSample Input 3\n\n2 1\n-1 1000000000\n\nSample Output 3\n\n1000000000\n\nThe possible products of the one chosen element are -1 and 1000000000, so the maximum product is 1000000000.\n\nSample Input 4\n\n10 10\n1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1\n\nSample Output 4\n\n999983200\n\nBe sure to print the product modulo (10^9+7).", "sample_input": "4 2\n1 2 -3 -4\n"}, "reference_outputs": ["12\n"], "source_document_id": "p02616", "source_text": "Score : 500 points\n\nProblem Statement\n\nGiven are N integers A_1,\\ldots,A_N.\n\nWe will choose exactly K of these elements. Find the maximum possible product of the chosen elements.\n\nThen, print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).\n\nConstraints\n\n1 \\leq K \\leq N \\leq 2\\times 10^5\n\n|A_i| \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 \\ldots A_N\n\nOutput\n\nPrint the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).\n\nSample Input 1\n\n4 2\n1 2 -3 -4\n\nSample Output 1\n\n12\n\nThe possible products of the two chosen elements are 2, -3, -4, -6, -8, and 12, so the maximum product is 12.\n\nSample Input 2\n\n4 3\n-1 -2 -3 -4\n\nSample Output 2\n\n1000000001\n\nThe possible products of the three chosen elements are -24, -12, -8, and -6, so the maximum product is -6.\n\nWe print this value modulo (10^9+7), that is, 1000000001.\n\nSample Input 3\n\n2 1\n-1 1000000000\n\nSample Output 3\n\n1000000000\n\nThe possible products of the one chosen element are -1 and 1000000000, so the maximum product is 1000000000.\n\nSample Input 4\n\n10 10\n1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1\n\nSample Output 4\n\n999983200\n\nBe sure to print the product modulo (10^9+7).", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9670, "cpu_time_ms": 434, "memory_kb": 32228}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s924002269", "group_id": "codeNet:p02619", "input_text": "(let* ((d-read (read))\n (c (make-array 27))\n (s (make-array (list (+ d-read 1) 27)))\n (td 0)\n (ans 0)\n (last (make-array '(27) :initial-element 0)))\n\n (loop for i from 1 to 26 do\n (setf (aref c i) (read))\n )\n (loop for i from 1 to d-read do\n (loop for j from 1 to 26 do\n (setf (aref s i j) (read))\n )\n )\n (loop for d from 1 to d-read do\n (progn\n (setq td (read))\n (setf (aref last td) d)\n (incf ans (aref s d td))\n (loop for j from 1 to 26 do\n (decf ans (* (aref c j) (- d (aref last j))))\n )\n (format t \"~D~%\" ans)\n )\n )\n)", "language": "Lisp", "metadata": {"date": 1593442355, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02619.html", "problem_id": "p02619", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02619/input.txt", "sample_output_relpath": "derived/input_output/data/p02619/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02619/Lisp/s924002269.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s924002269", "user_id": "u136500538"}, "prompt_components": {"gold_output": "18398\n35037\n51140\n65837\n79325\n", "input_to_evaluate": "(let* ((d-read (read))\n (c (make-array 27))\n (s (make-array (list (+ d-read 1) 27)))\n (td 0)\n (ans 0)\n (last (make-array '(27) :initial-element 0)))\n\n (loop for i from 1 to 26 do\n (setf (aref c i) (read))\n )\n (loop for i from 1 to d-read do\n (loop for j from 1 to 26 do\n (setf (aref s i j) (read))\n )\n )\n (loop for d from 1 to d-read do\n (progn\n (setq td (read))\n (setf (aref last td) d)\n (incf ans (aref s d td))\n (loop for j from 1 to 26 do\n (decf ans (* (aref c j) (- d (aref last j))))\n )\n (format t \"~D~%\" ans)\n )\n )\n)", "problem_context": "(Please read problem A first. The maximum score you can get by solving this problem B is 1, which will have almost no effect on your ranking.)\n\nBeginner's Guide\n\nLet's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.\n\nProblem Statement\n\nYou will be given a contest schedule for D days.\nFor each d=1,2,\\ldots,D, calculate the satisfaction at the end of day d.\n\nInput\n\nInput is given from Standard Input in the form of the input of Problem A followed by the output of Problem A.\n\nD\nc_1 c_2 \\cdots c_{26}\ns_{1,1} s_{1,2} \\cdots s_{1,26}\n\\vdots\ns_{D,1} s_{D,2} \\cdots s_{D,26}\nt_1\nt_2\n\\vdots\nt_D\n\nThe constraints and generation methods for the input part are the same as those for Problem A.\n\nFor each d, t_d is an integer satisfying 1\\leq t_d \\leq 26, and your program is expected to work correctly for any value that meets the constraints.\n\nOutput\n\nLet v_d be the satisfaction at the end of day d.\nPrint D integers v_d to Standard Output in the following format:\n\nv_1\nv_2\n\\vdots\nv_D\n\nSample Input 1\n\n5\n86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82\n19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424\n6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570\n6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256\n8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452\n19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192\n1\n17\n13\n14\n13\n\nSample Output 1\n\n18398\n35037\n51140\n65837\n79325\n\nNote that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case.\n\nNext Step\n\nWe can build a solution (schedule) for this problem in the order of day 1, day 2, and so on. And for every partial solution we have built, we can calculate the goodness (satisfaction) by using the above score calculator. So we can construct the following algorithm: for each d=1,2,\\ldots,D, we select the contest type that maximizes the satisfaction at the end of day d. You may have already encountered this kind of \"greedy algorithms\" in algorithm contests such as ABC. Greedy algorithms can guarantee the optimality for several problems, but unfortunately, it doesn't ensure optimality for this problem. However, even if it does not ensure optimality, we can still obtain a reasonable solution in many cases. Let's go back to Problem A and implement the greedy algorithm by utilizing the score calculator you just implemented!\n\nGreedy methods can be applied to a variety of problems, are easy to implement, and often run relatively fast compared to other methods. Greedy is often the most powerful method when we need to process huge inputs.\nWe can further improve the score by changing the greedy selection criteria (evaluation function), keeping multiple candidates instead of focusing on one best partial solution (beam search), or using the output of greedy algorithms as an initial solution of other methods.\nFor more information, please refer to the editorial that will be published after the contest.", "sample_input": "5\n86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82\n19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424\n6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570\n6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256\n8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452\n19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192\n1\n17\n13\n14\n13\n"}, "reference_outputs": ["18398\n35037\n51140\n65837\n79325\n"], "source_document_id": "p02619", "source_text": "(Please read problem A first. The maximum score you can get by solving this problem B is 1, which will have almost no effect on your ranking.)\n\nBeginner's Guide\n\nLet's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.\n\nProblem Statement\n\nYou will be given a contest schedule for D days.\nFor each d=1,2,\\ldots,D, calculate the satisfaction at the end of day d.\n\nInput\n\nInput is given from Standard Input in the form of the input of Problem A followed by the output of Problem A.\n\nD\nc_1 c_2 \\cdots c_{26}\ns_{1,1} s_{1,2} \\cdots s_{1,26}\n\\vdots\ns_{D,1} s_{D,2} \\cdots s_{D,26}\nt_1\nt_2\n\\vdots\nt_D\n\nThe constraints and generation methods for the input part are the same as those for Problem A.\n\nFor each d, t_d is an integer satisfying 1\\leq t_d \\leq 26, and your program is expected to work correctly for any value that meets the constraints.\n\nOutput\n\nLet v_d be the satisfaction at the end of day d.\nPrint D integers v_d to Standard Output in the following format:\n\nv_1\nv_2\n\\vdots\nv_D\n\nSample Input 1\n\n5\n86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82\n19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424\n6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570\n6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256\n8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452\n19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192\n1\n17\n13\n14\n13\n\nSample Output 1\n\n18398\n35037\n51140\n65837\n79325\n\nNote that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case.\n\nNext Step\n\nWe can build a solution (schedule) for this problem in the order of day 1, day 2, and so on. And for every partial solution we have built, we can calculate the goodness (satisfaction) by using the above score calculator. So we can construct the following algorithm: for each d=1,2,\\ldots,D, we select the contest type that maximizes the satisfaction at the end of day d. You may have already encountered this kind of \"greedy algorithms\" in algorithm contests such as ABC. Greedy algorithms can guarantee the optimality for several problems, but unfortunately, it doesn't ensure optimality for this problem. However, even if it does not ensure optimality, we can still obtain a reasonable solution in many cases. Let's go back to Problem A and implement the greedy algorithm by utilizing the score calculator you just implemented!\n\nGreedy methods can be applied to a variety of problems, are easy to implement, and often run relatively fast compared to other methods. Greedy is often the most powerful method when we need to process huge inputs.\nWe can further improve the score by changing the greedy selection criteria (evaluation function), keeping multiple candidates instead of focusing on one best partial solution (beam search), or using the output of greedy algorithms as an initial solution of other methods.\nFor more information, please refer to the editorial that will be published after the contest.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 683, "cpu_time_ms": 30, "memory_kb": 29668}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s836073831", "group_id": "codeNet:p02620", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of lower_bound() of C++ or bisect_left() of Python: Returns the\nsmallest index (or input) i that fulfills TARGET[i] >= VALUE, where '>=' is the\ncomplement of ORDER. In other words, this function returns the leftmost index at\nwhich VALUE can be inserted with keeping the order. Therefore, TARGET must be\nmonotonically non-decreasing with respect to ORDER.\n\n- This function returns END if VALUE exceeds TARGET[END-1]. \n- The range [START, END) is half-open.\n- END must be explicitly specified if TARGET is function.\n- KEY is applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-left (ng ok)\n ;; TARGET[OK] >= VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (funcall order (funcall key (,accessor target mid)) value)\n (%bisect-left mid ok)\n (%bisect-left ng mid))))))\n (assert (<= start end))\n (%bisect-left (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.most-positive-fixnum)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of upper_bound() of C++ or bisect_right() of Python: Returns the\nsmallest index (or input) i that fulfills TARGET[i] > VALUE. In other words,\nthis function returns the rightmost index at which VALUE can be inserted with\nkeeping the order. Therefore, TARGET must be monotonically non-decreasing with\nrespect to ORDER.\n\n- This function returns END if VALUE >= TARGET[END-1].\n- The range [START, END) is half-open.\n- END must be explicitly specified if TARGET is function.\n- KEY is applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-right (ng ok)\n ;; TARGET[OK] > VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (funcall order value (funcall key (,accessor target mid)))\n (%bisect-right ng mid)\n (%bisect-right mid ok))))))\n (assert (<= start end))\n (%bisect-right (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.array-total-size-limit)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n(declaim (inline vector-insert))\n(defun vector-insert (vector new-element index)\n (let ((n (length vector)))\n (vector-push new-element vector)\n (loop for i from n above index\n do (rotatef (aref vector i) (aref vector (- i 1)))))\n vector)\n\n(declaim (inline vector-delete))\n(defun vector-delete (vector index)\n (loop for i from index below (- (length vector) 1)\n do (rotatef (aref vector i) (aref vector (+ i 1))))\n (vector-pop vector)\n vector)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defstruct state\n (d 0 :type uint16)\n (cs nil :type (simple-array uint8 (*)))\n (ss nil :type (simple-array uint32 (* *)))\n (schedule nil :type (simple-array uint8 (*)))\n (history-table nil :type (simple-array (array int16 (*)) (26)))\n (score 0 :type fixnum))\n\n(defun make-state-from (d cs ss schedule)\n (declare (uint32 d)\n ((simple-array uint8 (*)) cs schedule)\n ((simple-array uint32 (* *)) ss))\n (let ((history-table (make-array 26 :element-type '(array uint32 (*)))))\n (dotimes (i 26)\n (let ((history (make-array (+ d 2) :element-type 'int16 :fill-pointer 0)))\n (vector-push -1 history)\n (setf (aref history-table i) history)))\n (dotimes (i d)\n (let ((type (aref schedule i)))\n (vector-push i (aref history-table type))))\n (dotimes (i 26)\n (vector-push d (aref history-table i)))\n (let* ((prevs (make-array 26 :element-type 'int32 :initial-element -1))\n (score 0))\n (declare (fixnum score))\n (dotimes (i d)\n (let ((type (aref schedule i)))\n (incf score (aref ss i type))\n (setf (aref prevs type) i)\n (dotimes (j 26)\n (decf score (* (aref cs j) (- i (aref prevs j)))))))\n (make-state :d d\n :cs cs\n :ss ss\n :schedule schedule\n :history-table history-table\n :score score))))\n\n(defun state-update! (state day new-type)\n (declare #.OPT\n (uint32 day new-type))\n (symbol-macrolet ((score (state-score state))\n (cs (state-cs state))\n (ss (state-ss state))\n (history-table (state-history-table state)))\n (let* ((old-type (aref (state-schedule state) day))\n (old-history (aref history-table old-type))\n (new-history (aref history-table new-type)))\n (declare ((array int16 (*)) old-history new-history))\n ;; delete old type\n (decf score (aref ss day old-type))\n (let* ((pos (bisect-left old-history day))\n (prev-day (aref old-history (- pos 1)))\n (next-day (aref old-history (+ pos 1))))\n (assert (= day (aref old-history pos)))\n (decf score (* (aref cs old-type) (- day prev-day) (- next-day day)))\n (vector-delete old-history pos))\n ;; add new type \n (incf score (aref ss day new-type))\n (let* ((pos (bisect-left new-history day))\n (next-day (aref new-history pos))\n (prev-day (aref new-history (- pos 1))))\n (assert (< day (aref new-history pos)))\n (incf score (* (aref cs new-type) (- day prev-day) (- next-day day)))\n (vector-insert new-history day pos))\n (setf (state-score state) score)\n (setf (aref (state-schedule state) day) new-type)\n state)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((d (read-fixnum))\n (cs (make-array 26 :element-type 'uint8 :initial-element 0))\n (ss (make-array (list d 26) :element-type 'uint32 :initial-element 0))\n (schedule (make-array d :element-type 'uint8 :initial-element 0)))\n (dotimes (i 26)\n (setf (aref cs i) (read-fixnum)))\n (dotimes (i d)\n (dotimes (j 26)\n (setf (aref ss i j) (read-fixnum))))\n (dotimes (i d)\n (setf (aref schedule i) (- (read-fixnum) 1)))\n (let ((state (make-state-from d cs ss schedule))\n (m (read-fixnum)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (_ m)\n (let* ((day (- (read-fixnum) 1))\n (new-type (- (read-fixnum) 1)))\n (state-update! state day new-type)\n (println (state-score state)))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n", "language": "Lisp", "metadata": {"date": 1593594586, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02620.html", "problem_id": "p02620", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02620/input.txt", "sample_output_relpath": "derived/input_output/data/p02620/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02620/Lisp/s836073831.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s836073831", "user_id": "u352600849"}, "prompt_components": {"gold_output": "72882\n56634\n38425\n27930\n42884\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of lower_bound() of C++ or bisect_left() of Python: Returns the\nsmallest index (or input) i that fulfills TARGET[i] >= VALUE, where '>=' is the\ncomplement of ORDER. In other words, this function returns the leftmost index at\nwhich VALUE can be inserted with keeping the order. Therefore, TARGET must be\nmonotonically non-decreasing with respect to ORDER.\n\n- This function returns END if VALUE exceeds TARGET[END-1]. \n- The range [START, END) is half-open.\n- END must be explicitly specified if TARGET is function.\n- KEY is applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-left (ng ok)\n ;; TARGET[OK] >= VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (funcall order (funcall key (,accessor target mid)) value)\n (%bisect-left mid ok)\n (%bisect-left ng mid))))))\n (assert (<= start end))\n (%bisect-left (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.most-positive-fixnum)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of upper_bound() of C++ or bisect_right() of Python: Returns the\nsmallest index (or input) i that fulfills TARGET[i] > VALUE. In other words,\nthis function returns the rightmost index at which VALUE can be inserted with\nkeeping the order. Therefore, TARGET must be monotonically non-decreasing with\nrespect to ORDER.\n\n- This function returns END if VALUE >= TARGET[END-1].\n- The range [START, END) is half-open.\n- END must be explicitly specified if TARGET is function.\n- KEY is applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-right (ng ok)\n ;; TARGET[OK] > VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (funcall order value (funcall key (,accessor target mid)))\n (%bisect-right ng mid)\n (%bisect-right mid ok))))))\n (assert (<= start end))\n (%bisect-right (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.array-total-size-limit)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n(declaim (inline vector-insert))\n(defun vector-insert (vector new-element index)\n (let ((n (length vector)))\n (vector-push new-element vector)\n (loop for i from n above index\n do (rotatef (aref vector i) (aref vector (- i 1)))))\n vector)\n\n(declaim (inline vector-delete))\n(defun vector-delete (vector index)\n (loop for i from index below (- (length vector) 1)\n do (rotatef (aref vector i) (aref vector (+ i 1))))\n (vector-pop vector)\n vector)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defstruct state\n (d 0 :type uint16)\n (cs nil :type (simple-array uint8 (*)))\n (ss nil :type (simple-array uint32 (* *)))\n (schedule nil :type (simple-array uint8 (*)))\n (history-table nil :type (simple-array (array int16 (*)) (26)))\n (score 0 :type fixnum))\n\n(defun make-state-from (d cs ss schedule)\n (declare (uint32 d)\n ((simple-array uint8 (*)) cs schedule)\n ((simple-array uint32 (* *)) ss))\n (let ((history-table (make-array 26 :element-type '(array uint32 (*)))))\n (dotimes (i 26)\n (let ((history (make-array (+ d 2) :element-type 'int16 :fill-pointer 0)))\n (vector-push -1 history)\n (setf (aref history-table i) history)))\n (dotimes (i d)\n (let ((type (aref schedule i)))\n (vector-push i (aref history-table type))))\n (dotimes (i 26)\n (vector-push d (aref history-table i)))\n (let* ((prevs (make-array 26 :element-type 'int32 :initial-element -1))\n (score 0))\n (declare (fixnum score))\n (dotimes (i d)\n (let ((type (aref schedule i)))\n (incf score (aref ss i type))\n (setf (aref prevs type) i)\n (dotimes (j 26)\n (decf score (* (aref cs j) (- i (aref prevs j)))))))\n (make-state :d d\n :cs cs\n :ss ss\n :schedule schedule\n :history-table history-table\n :score score))))\n\n(defun state-update! (state day new-type)\n (declare #.OPT\n (uint32 day new-type))\n (symbol-macrolet ((score (state-score state))\n (cs (state-cs state))\n (ss (state-ss state))\n (history-table (state-history-table state)))\n (let* ((old-type (aref (state-schedule state) day))\n (old-history (aref history-table old-type))\n (new-history (aref history-table new-type)))\n (declare ((array int16 (*)) old-history new-history))\n ;; delete old type\n (decf score (aref ss day old-type))\n (let* ((pos (bisect-left old-history day))\n (prev-day (aref old-history (- pos 1)))\n (next-day (aref old-history (+ pos 1))))\n (assert (= day (aref old-history pos)))\n (decf score (* (aref cs old-type) (- day prev-day) (- next-day day)))\n (vector-delete old-history pos))\n ;; add new type \n (incf score (aref ss day new-type))\n (let* ((pos (bisect-left new-history day))\n (next-day (aref new-history pos))\n (prev-day (aref new-history (- pos 1))))\n (assert (< day (aref new-history pos)))\n (incf score (* (aref cs new-type) (- day prev-day) (- next-day day)))\n (vector-insert new-history day pos))\n (setf (state-score state) score)\n (setf (aref (state-schedule state) day) new-type)\n state)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((d (read-fixnum))\n (cs (make-array 26 :element-type 'uint8 :initial-element 0))\n (ss (make-array (list d 26) :element-type 'uint32 :initial-element 0))\n (schedule (make-array d :element-type 'uint8 :initial-element 0)))\n (dotimes (i 26)\n (setf (aref cs i) (read-fixnum)))\n (dotimes (i d)\n (dotimes (j 26)\n (setf (aref ss i j) (read-fixnum))))\n (dotimes (i d)\n (setf (aref schedule i) (- (read-fixnum) 1)))\n (let ((state (make-state-from d cs ss schedule))\n (m (read-fixnum)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (_ m)\n (let* ((day (- (read-fixnum) 1))\n (new-type (- (read-fixnum) 1)))\n (state-update! state day new-type)\n (println (state-score state)))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n", "problem_context": "(Please read problem A first. The maximum score you can get by solving this problem C is 1, which will have almost no effect on your ranking.)\n\nBeginner's Guide\n\n\"Local search\" is a powerful method for finding a high-quality solution.\nIn this method, instead of constructing a solution from scratch, we try to find a better solution by slightly modifying the already found solution.\nIf the solution gets better, update it, and if it gets worse, restore it.\nBy repeating this process, the quality of the solution is gradually improved over time.\nThe pseudo-code is as follows.\n\nsolution = compute an initial solution (by random generation, or by applying other methods such as greedy)\nwhile the remaining time > 0:\nslightly modify the solution (randomly)\nif the solution gets worse:\nrestore the solution\n\nFor example, in this problem, we can use the following modification: pick the date d and contest type q at random and change the type of contest to be held on day d to q.\nThe pseudo-code is as follows.\n\nt[1..D] = compute an initial solution (by random generation, or by applying other methods such as greedy)\nwhile the remaining time > 0:\npick d and q at random\nold = t[d] # Remember the original value so that we can restore it later\nt[d] = q\nif the solution gets worse:\nt[d] = old\n\nThe most important thing when using the local search method is the design of how to modify solutions.\n\nIf the amount of modification is too small, we will soon fall into a dead-end (local optimum) and, conversely, if the amount of modification is too large, the probability of finding an improving move becomes extremely small.\n\nIn order to increase the number of iterations, it is desirable to be able to quickly calculate the score after applying a modification.\n\nIn this problem C, we focus on the second point.\nThe score after the modification can, of course, be obtained by calculating the score from scratch.\nHowever, by focusing on only the parts that have been modified, it may be possible to quickly compute the difference between the scores before and after the modification.\nFrom another viewpoint, the impossibility of such a fast incremental calculation implies that a small modification to the solution affects a majority of the score calculation.\nIn such a case, we may need to redesign how to modify solutions, or there is a high possibility that the problem is not suitable for local search.\nLet's implement fast incremental score computation.\nIt's time to demonstrate the skills of algorithms and data structures you have developed in ABC and ARC!\n\nIn this kind of contest, where the objective is to find a better solution instead of the optimal one, a bug in a program does not result in a wrong answer, which may delay the discovery of the bug.\nFor early detection of bugs, it is a good idea to unit test functions you implemented complicated routines.\nFor example, if you implement fast incremental score calculation, it is a good idea to test that the scores computed by the fast implementation match the scores computed from scratch, as we will do in this problem C.\n\nProblem Statement\n\nYou will be given a contest schedule for D days and M queries of schedule modification.\nIn the i-th query, given integers d_i and q_i, change the type of contest to be held on day d_i to q_i, and then output the final satisfaction at the end of day D on the updated schedule.\nNote that we do not revert each query. That is, the i-th query is applied to the new schedule obtained by the (i-1)-th query.\n\nInput\n\nInput is given from Standard Input in the form of the input of Problem A followed by the output of Problem A and the queries.\n\nD\nc_1 c_2 \\cdots c_{26}\ns_{1,1} s_{1,2} \\cdots s_{1,26}\n\\vdots\ns_{D,1} s_{D,2} \\cdots s_{D,26}\nt_1\nt_2\n\\vdots\nt_D\nM\nd_1 q_1\nd_2 q_2\n\\vdots\nd_M q_M\n\nThe constraints and generation methods for the input part are the same as those for Problem A.\n\nFor each d=1,\\ldots,D, t_d is an integer generated independently and uniformly at random from {1,2,\\ldots,26}.\n\nThe number of queries M is an integer satisfying 1\\leq M\\leq 10^5.\n\nFor each i=1,\\ldots,M, d_i is an integer generated independently and uniformly at random from {1,2,\\ldots,D}.\n\nFor each i=1,\\ldots,26, q_i is an integer satisfying 1\\leq q_i\\leq 26 generated uniformly at random from the 25 values that differ from the type of contest on day d_i.\n\nOutput\n\nLet v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query.\nPrint M integers v_i to Standard Output in the following format:\n\nv_1\nv_2\n\\vdots\nv_M\n\nSample Input 1\n\n5\n86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82\n19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424\n6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570\n6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256\n8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452\n19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192\n1\n17\n13\n14\n13\n5\n1 7\n4 11\n3 4\n5 24\n4 19\n\nSample Output 1\n\n72882\n56634\n38425\n27930\n42884\n\nNote that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case.\n\nNext Step\n\nLet's go back to Problem A and implement the local search algorithm by utilizing the incremental score calculator you just implemented!\nFor this problem, the current modification \"pick the date d and contest type q at random and change the type of contest to be held on day d to q\" is actually not so good. By considering why it is not good, let's improve the modification operation.\nOne of the most powerful and widely used variant of the local search method is \"Simulated Annealing (SA)\", which makes it easier to reach a better solution by stochastically accepting worsening moves.\nFor more information about SA and other local search techniques, please refer to the editorial that will be published after the contest.", "sample_input": "5\n86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82\n19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424\n6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570\n6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256\n8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452\n19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192\n1\n17\n13\n14\n13\n5\n1 7\n4 11\n3 4\n5 24\n4 19\n"}, "reference_outputs": ["72882\n56634\n38425\n27930\n42884\n"], "source_document_id": "p02620", "source_text": "(Please read problem A first. The maximum score you can get by solving this problem C is 1, which will have almost no effect on your ranking.)\n\nBeginner's Guide\n\n\"Local search\" is a powerful method for finding a high-quality solution.\nIn this method, instead of constructing a solution from scratch, we try to find a better solution by slightly modifying the already found solution.\nIf the solution gets better, update it, and if it gets worse, restore it.\nBy repeating this process, the quality of the solution is gradually improved over time.\nThe pseudo-code is as follows.\n\nsolution = compute an initial solution (by random generation, or by applying other methods such as greedy)\nwhile the remaining time > 0:\nslightly modify the solution (randomly)\nif the solution gets worse:\nrestore the solution\n\nFor example, in this problem, we can use the following modification: pick the date d and contest type q at random and change the type of contest to be held on day d to q.\nThe pseudo-code is as follows.\n\nt[1..D] = compute an initial solution (by random generation, or by applying other methods such as greedy)\nwhile the remaining time > 0:\npick d and q at random\nold = t[d] # Remember the original value so that we can restore it later\nt[d] = q\nif the solution gets worse:\nt[d] = old\n\nThe most important thing when using the local search method is the design of how to modify solutions.\n\nIf the amount of modification is too small, we will soon fall into a dead-end (local optimum) and, conversely, if the amount of modification is too large, the probability of finding an improving move becomes extremely small.\n\nIn order to increase the number of iterations, it is desirable to be able to quickly calculate the score after applying a modification.\n\nIn this problem C, we focus on the second point.\nThe score after the modification can, of course, be obtained by calculating the score from scratch.\nHowever, by focusing on only the parts that have been modified, it may be possible to quickly compute the difference between the scores before and after the modification.\nFrom another viewpoint, the impossibility of such a fast incremental calculation implies that a small modification to the solution affects a majority of the score calculation.\nIn such a case, we may need to redesign how to modify solutions, or there is a high possibility that the problem is not suitable for local search.\nLet's implement fast incremental score computation.\nIt's time to demonstrate the skills of algorithms and data structures you have developed in ABC and ARC!\n\nIn this kind of contest, where the objective is to find a better solution instead of the optimal one, a bug in a program does not result in a wrong answer, which may delay the discovery of the bug.\nFor early detection of bugs, it is a good idea to unit test functions you implemented complicated routines.\nFor example, if you implement fast incremental score calculation, it is a good idea to test that the scores computed by the fast implementation match the scores computed from scratch, as we will do in this problem C.\n\nProblem Statement\n\nYou will be given a contest schedule for D days and M queries of schedule modification.\nIn the i-th query, given integers d_i and q_i, change the type of contest to be held on day d_i to q_i, and then output the final satisfaction at the end of day D on the updated schedule.\nNote that we do not revert each query. That is, the i-th query is applied to the new schedule obtained by the (i-1)-th query.\n\nInput\n\nInput is given from Standard Input in the form of the input of Problem A followed by the output of Problem A and the queries.\n\nD\nc_1 c_2 \\cdots c_{26}\ns_{1,1} s_{1,2} \\cdots s_{1,26}\n\\vdots\ns_{D,1} s_{D,2} \\cdots s_{D,26}\nt_1\nt_2\n\\vdots\nt_D\nM\nd_1 q_1\nd_2 q_2\n\\vdots\nd_M q_M\n\nThe constraints and generation methods for the input part are the same as those for Problem A.\n\nFor each d=1,\\ldots,D, t_d is an integer generated independently and uniformly at random from {1,2,\\ldots,26}.\n\nThe number of queries M is an integer satisfying 1\\leq M\\leq 10^5.\n\nFor each i=1,\\ldots,M, d_i is an integer generated independently and uniformly at random from {1,2,\\ldots,D}.\n\nFor each i=1,\\ldots,26, q_i is an integer satisfying 1\\leq q_i\\leq 26 generated uniformly at random from the 25 values that differ from the type of contest on day d_i.\n\nOutput\n\nLet v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query.\nPrint M integers v_i to Standard Output in the following format:\n\nv_1\nv_2\n\\vdots\nv_M\n\nSample Input 1\n\n5\n86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82\n19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424\n6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570\n6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256\n8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452\n19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192\n1\n17\n13\n14\n13\n5\n1 7\n4 11\n3 4\n5 24\n4 19\n\nSample Output 1\n\n72882\n56634\n38425\n27930\n42884\n\nNote that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case.\n\nNext Step\n\nLet's go back to Problem A and implement the local search algorithm by utilizing the incremental score calculator you just implemented!\nFor this problem, the current modification \"pick the date d and contest type q at random and change the type of contest to be held on day d to q\" is actually not so good. By considering why it is not good, let's improve the modification operation.\nOne of the most powerful and widely used variant of the local search method is \"Simulated Annealing (SA)\", which makes it easier to reach a better solution by stochastically accepting worsening moves.\nFor more information about SA and other local search techniques, please refer to the editorial that will be published after the contest.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 12196, "cpu_time_ms": 112, "memory_kb": 27700}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s622038853", "group_id": "codeNet:p02620", "input_text": "(defun calcAns (c s td d-read)\n (declare (optimise (speed 3) (safety 2))\n (type (simple-array (integer) (*)) c)\n (type (simple-array (integer) (* *)) s)\n (type (simple-array (integer) (*)) td))\n (let ((last (make-array 27 :element-type 'uint32))\n (ans 0))\n (loop for d from 1 to d-read do\n (progn\n (incf ans (+ (aref s d (aref td d))))\n (setf (aref last (aref td d)) d)\n (loop for j from 1 to 26 do\n (decf ans (* (aref c j) (- d (aref last j))))\n )\n )\n )\n ans)\n)\n\n(let* ((d-read (read))\n (c (make-array 27 :element-type 'uint8))\n (s (make-array (list (+ d-read 1) 27) :element-type 'uint32))\n (td (make-array (+ d-read 1) :element-type 'uint8))\n (m 0)\n (md 0)\n (mq 0))\n\n (loop for i from 1 to 26 do\n (setf (aref c i) (read))\n )\n (loop for d from 1 to d-read do\n (loop for j from 1 to 26 do\n (setf (aref s d j) (read))\n )\n )\n (loop for d from 1 to d-read do\n (setf (aref td d) (read))\n )\n\n (setq m (read))\n (loop for i below m do\n (progn \n (setq md (read))\n (setq mq (read))\n (setf (aref td md) mq)\n\n (format t \"~D~%\" (calcAns c s td d-read))\n )\n )\n)", "language": "Lisp", "metadata": {"date": 1593468971, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02620.html", "problem_id": "p02620", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02620/input.txt", "sample_output_relpath": "derived/input_output/data/p02620/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02620/Lisp/s622038853.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s622038853", "user_id": "u136500538"}, "prompt_components": {"gold_output": "72882\n56634\n38425\n27930\n42884\n", "input_to_evaluate": "(defun calcAns (c s td d-read)\n (declare (optimise (speed 3) (safety 2))\n (type (simple-array (integer) (*)) c)\n (type (simple-array (integer) (* *)) s)\n (type (simple-array (integer) (*)) td))\n (let ((last (make-array 27 :element-type 'uint32))\n (ans 0))\n (loop for d from 1 to d-read do\n (progn\n (incf ans (+ (aref s d (aref td d))))\n (setf (aref last (aref td d)) d)\n (loop for j from 1 to 26 do\n (decf ans (* (aref c j) (- d (aref last j))))\n )\n )\n )\n ans)\n)\n\n(let* ((d-read (read))\n (c (make-array 27 :element-type 'uint8))\n (s (make-array (list (+ d-read 1) 27) :element-type 'uint32))\n (td (make-array (+ d-read 1) :element-type 'uint8))\n (m 0)\n (md 0)\n (mq 0))\n\n (loop for i from 1 to 26 do\n (setf (aref c i) (read))\n )\n (loop for d from 1 to d-read do\n (loop for j from 1 to 26 do\n (setf (aref s d j) (read))\n )\n )\n (loop for d from 1 to d-read do\n (setf (aref td d) (read))\n )\n\n (setq m (read))\n (loop for i below m do\n (progn \n (setq md (read))\n (setq mq (read))\n (setf (aref td md) mq)\n\n (format t \"~D~%\" (calcAns c s td d-read))\n )\n )\n)", "problem_context": "(Please read problem A first. The maximum score you can get by solving this problem C is 1, which will have almost no effect on your ranking.)\n\nBeginner's Guide\n\n\"Local search\" is a powerful method for finding a high-quality solution.\nIn this method, instead of constructing a solution from scratch, we try to find a better solution by slightly modifying the already found solution.\nIf the solution gets better, update it, and if it gets worse, restore it.\nBy repeating this process, the quality of the solution is gradually improved over time.\nThe pseudo-code is as follows.\n\nsolution = compute an initial solution (by random generation, or by applying other methods such as greedy)\nwhile the remaining time > 0:\nslightly modify the solution (randomly)\nif the solution gets worse:\nrestore the solution\n\nFor example, in this problem, we can use the following modification: pick the date d and contest type q at random and change the type of contest to be held on day d to q.\nThe pseudo-code is as follows.\n\nt[1..D] = compute an initial solution (by random generation, or by applying other methods such as greedy)\nwhile the remaining time > 0:\npick d and q at random\nold = t[d] # Remember the original value so that we can restore it later\nt[d] = q\nif the solution gets worse:\nt[d] = old\n\nThe most important thing when using the local search method is the design of how to modify solutions.\n\nIf the amount of modification is too small, we will soon fall into a dead-end (local optimum) and, conversely, if the amount of modification is too large, the probability of finding an improving move becomes extremely small.\n\nIn order to increase the number of iterations, it is desirable to be able to quickly calculate the score after applying a modification.\n\nIn this problem C, we focus on the second point.\nThe score after the modification can, of course, be obtained by calculating the score from scratch.\nHowever, by focusing on only the parts that have been modified, it may be possible to quickly compute the difference between the scores before and after the modification.\nFrom another viewpoint, the impossibility of such a fast incremental calculation implies that a small modification to the solution affects a majority of the score calculation.\nIn such a case, we may need to redesign how to modify solutions, or there is a high possibility that the problem is not suitable for local search.\nLet's implement fast incremental score computation.\nIt's time to demonstrate the skills of algorithms and data structures you have developed in ABC and ARC!\n\nIn this kind of contest, where the objective is to find a better solution instead of the optimal one, a bug in a program does not result in a wrong answer, which may delay the discovery of the bug.\nFor early detection of bugs, it is a good idea to unit test functions you implemented complicated routines.\nFor example, if you implement fast incremental score calculation, it is a good idea to test that the scores computed by the fast implementation match the scores computed from scratch, as we will do in this problem C.\n\nProblem Statement\n\nYou will be given a contest schedule for D days and M queries of schedule modification.\nIn the i-th query, given integers d_i and q_i, change the type of contest to be held on day d_i to q_i, and then output the final satisfaction at the end of day D on the updated schedule.\nNote that we do not revert each query. That is, the i-th query is applied to the new schedule obtained by the (i-1)-th query.\n\nInput\n\nInput is given from Standard Input in the form of the input of Problem A followed by the output of Problem A and the queries.\n\nD\nc_1 c_2 \\cdots c_{26}\ns_{1,1} s_{1,2} \\cdots s_{1,26}\n\\vdots\ns_{D,1} s_{D,2} \\cdots s_{D,26}\nt_1\nt_2\n\\vdots\nt_D\nM\nd_1 q_1\nd_2 q_2\n\\vdots\nd_M q_M\n\nThe constraints and generation methods for the input part are the same as those for Problem A.\n\nFor each d=1,\\ldots,D, t_d is an integer generated independently and uniformly at random from {1,2,\\ldots,26}.\n\nThe number of queries M is an integer satisfying 1\\leq M\\leq 10^5.\n\nFor each i=1,\\ldots,M, d_i is an integer generated independently and uniformly at random from {1,2,\\ldots,D}.\n\nFor each i=1,\\ldots,26, q_i is an integer satisfying 1\\leq q_i\\leq 26 generated uniformly at random from the 25 values that differ from the type of contest on day d_i.\n\nOutput\n\nLet v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query.\nPrint M integers v_i to Standard Output in the following format:\n\nv_1\nv_2\n\\vdots\nv_M\n\nSample Input 1\n\n5\n86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82\n19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424\n6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570\n6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256\n8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452\n19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192\n1\n17\n13\n14\n13\n5\n1 7\n4 11\n3 4\n5 24\n4 19\n\nSample Output 1\n\n72882\n56634\n38425\n27930\n42884\n\nNote that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case.\n\nNext Step\n\nLet's go back to Problem A and implement the local search algorithm by utilizing the incremental score calculator you just implemented!\nFor this problem, the current modification \"pick the date d and contest type q at random and change the type of contest to be held on day d to q\" is actually not so good. By considering why it is not good, let's improve the modification operation.\nOne of the most powerful and widely used variant of the local search method is \"Simulated Annealing (SA)\", which makes it easier to reach a better solution by stochastically accepting worsening moves.\nFor more information about SA and other local search techniques, please refer to the editorial that will be published after the contest.", "sample_input": "5\n86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82\n19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424\n6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570\n6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256\n8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452\n19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192\n1\n17\n13\n14\n13\n5\n1 7\n4 11\n3 4\n5 24\n4 19\n"}, "reference_outputs": ["72882\n56634\n38425\n27930\n42884\n"], "source_document_id": "p02620", "source_text": "(Please read problem A first. The maximum score you can get by solving this problem C is 1, which will have almost no effect on your ranking.)\n\nBeginner's Guide\n\n\"Local search\" is a powerful method for finding a high-quality solution.\nIn this method, instead of constructing a solution from scratch, we try to find a better solution by slightly modifying the already found solution.\nIf the solution gets better, update it, and if it gets worse, restore it.\nBy repeating this process, the quality of the solution is gradually improved over time.\nThe pseudo-code is as follows.\n\nsolution = compute an initial solution (by random generation, or by applying other methods such as greedy)\nwhile the remaining time > 0:\nslightly modify the solution (randomly)\nif the solution gets worse:\nrestore the solution\n\nFor example, in this problem, we can use the following modification: pick the date d and contest type q at random and change the type of contest to be held on day d to q.\nThe pseudo-code is as follows.\n\nt[1..D] = compute an initial solution (by random generation, or by applying other methods such as greedy)\nwhile the remaining time > 0:\npick d and q at random\nold = t[d] # Remember the original value so that we can restore it later\nt[d] = q\nif the solution gets worse:\nt[d] = old\n\nThe most important thing when using the local search method is the design of how to modify solutions.\n\nIf the amount of modification is too small, we will soon fall into a dead-end (local optimum) and, conversely, if the amount of modification is too large, the probability of finding an improving move becomes extremely small.\n\nIn order to increase the number of iterations, it is desirable to be able to quickly calculate the score after applying a modification.\n\nIn this problem C, we focus on the second point.\nThe score after the modification can, of course, be obtained by calculating the score from scratch.\nHowever, by focusing on only the parts that have been modified, it may be possible to quickly compute the difference between the scores before and after the modification.\nFrom another viewpoint, the impossibility of such a fast incremental calculation implies that a small modification to the solution affects a majority of the score calculation.\nIn such a case, we may need to redesign how to modify solutions, or there is a high possibility that the problem is not suitable for local search.\nLet's implement fast incremental score computation.\nIt's time to demonstrate the skills of algorithms and data structures you have developed in ABC and ARC!\n\nIn this kind of contest, where the objective is to find a better solution instead of the optimal one, a bug in a program does not result in a wrong answer, which may delay the discovery of the bug.\nFor early detection of bugs, it is a good idea to unit test functions you implemented complicated routines.\nFor example, if you implement fast incremental score calculation, it is a good idea to test that the scores computed by the fast implementation match the scores computed from scratch, as we will do in this problem C.\n\nProblem Statement\n\nYou will be given a contest schedule for D days and M queries of schedule modification.\nIn the i-th query, given integers d_i and q_i, change the type of contest to be held on day d_i to q_i, and then output the final satisfaction at the end of day D on the updated schedule.\nNote that we do not revert each query. That is, the i-th query is applied to the new schedule obtained by the (i-1)-th query.\n\nInput\n\nInput is given from Standard Input in the form of the input of Problem A followed by the output of Problem A and the queries.\n\nD\nc_1 c_2 \\cdots c_{26}\ns_{1,1} s_{1,2} \\cdots s_{1,26}\n\\vdots\ns_{D,1} s_{D,2} \\cdots s_{D,26}\nt_1\nt_2\n\\vdots\nt_D\nM\nd_1 q_1\nd_2 q_2\n\\vdots\nd_M q_M\n\nThe constraints and generation methods for the input part are the same as those for Problem A.\n\nFor each d=1,\\ldots,D, t_d is an integer generated independently and uniformly at random from {1,2,\\ldots,26}.\n\nThe number of queries M is an integer satisfying 1\\leq M\\leq 10^5.\n\nFor each i=1,\\ldots,M, d_i is an integer generated independently and uniformly at random from {1,2,\\ldots,D}.\n\nFor each i=1,\\ldots,26, q_i is an integer satisfying 1\\leq q_i\\leq 26 generated uniformly at random from the 25 values that differ from the type of contest on day d_i.\n\nOutput\n\nLet v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query.\nPrint M integers v_i to Standard Output in the following format:\n\nv_1\nv_2\n\\vdots\nv_M\n\nSample Input 1\n\n5\n86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82\n19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424\n6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570\n6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256\n8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452\n19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192\n1\n17\n13\n14\n13\n5\n1 7\n4 11\n3 4\n5 24\n4 19\n\nSample Output 1\n\n72882\n56634\n38425\n27930\n42884\n\nNote that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case.\n\nNext Step\n\nLet's go back to Problem A and implement the local search algorithm by utilizing the incremental score calculator you just implemented!\nFor this problem, the current modification \"pick the date d and contest type q at random and change the type of contest to be held on day d to q\" is actually not so good. By considering why it is not good, let's improve the modification operation.\nOne of the most powerful and widely used variant of the local search method is \"Simulated Annealing (SA)\", which makes it easier to reach a better solution by stochastically accepting worsening moves.\nFor more information about SA and other local search techniques, please refer to the editorial that will be published after the contest.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1321, "cpu_time_ms": 2208, "memory_kb": 66568}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s111951737", "group_id": "codeNet:p02620", "input_text": "(let* ((d-read (read))\n (c (make-array 27))\n (s (make-array (list (+ d-read 1) 27)))\n (td (make-array (+ d-read 1)))\n (m 0)\n (md 0)\n (dq 0)\n (ans 0))\n\n (loop for i from 1 to 26 do\n (setf (aref c i) (read))\n )\n (loop for d from 1 to d-read do\n (loop for j from 1 to 26 do\n (setf (aref s d j) (read))\n )\n )\n (loop for d from 1 to d-read do\n (setf (aref td d) (read))\n )\n\n (setq m (read))\n (loop for i below m do\n (progn\n (setq md (read))\n (setq mq (read))\n (setf (aref td md) mq)\n\n (let ((last (make-array '(27) :initial-element 0)))\n (setq ans 0)\n (loop for d from 1 to d-read do\n (progn\n (incf ans (+ (aref s d (aref td d))))\n (setf (aref last (aref td d)) d)\n (loop for j from 1 to 26 do\n (decf ans (* (aref c j) (- d (aref last j))))\n )\n )\n )\n )\n (format t \"~D~%\" ans)\n )\n )\n)", "language": "Lisp", "metadata": {"date": 1593458955, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02620.html", "problem_id": "p02620", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02620/input.txt", "sample_output_relpath": "derived/input_output/data/p02620/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02620/Lisp/s111951737.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s111951737", "user_id": "u136500538"}, "prompt_components": {"gold_output": "72882\n56634\n38425\n27930\n42884\n", "input_to_evaluate": "(let* ((d-read (read))\n (c (make-array 27))\n (s (make-array (list (+ d-read 1) 27)))\n (td (make-array (+ d-read 1)))\n (m 0)\n (md 0)\n (dq 0)\n (ans 0))\n\n (loop for i from 1 to 26 do\n (setf (aref c i) (read))\n )\n (loop for d from 1 to d-read do\n (loop for j from 1 to 26 do\n (setf (aref s d j) (read))\n )\n )\n (loop for d from 1 to d-read do\n (setf (aref td d) (read))\n )\n\n (setq m (read))\n (loop for i below m do\n (progn\n (setq md (read))\n (setq mq (read))\n (setf (aref td md) mq)\n\n (let ((last (make-array '(27) :initial-element 0)))\n (setq ans 0)\n (loop for d from 1 to d-read do\n (progn\n (incf ans (+ (aref s d (aref td d))))\n (setf (aref last (aref td d)) d)\n (loop for j from 1 to 26 do\n (decf ans (* (aref c j) (- d (aref last j))))\n )\n )\n )\n )\n (format t \"~D~%\" ans)\n )\n )\n)", "problem_context": "(Please read problem A first. The maximum score you can get by solving this problem C is 1, which will have almost no effect on your ranking.)\n\nBeginner's Guide\n\n\"Local search\" is a powerful method for finding a high-quality solution.\nIn this method, instead of constructing a solution from scratch, we try to find a better solution by slightly modifying the already found solution.\nIf the solution gets better, update it, and if it gets worse, restore it.\nBy repeating this process, the quality of the solution is gradually improved over time.\nThe pseudo-code is as follows.\n\nsolution = compute an initial solution (by random generation, or by applying other methods such as greedy)\nwhile the remaining time > 0:\nslightly modify the solution (randomly)\nif the solution gets worse:\nrestore the solution\n\nFor example, in this problem, we can use the following modification: pick the date d and contest type q at random and change the type of contest to be held on day d to q.\nThe pseudo-code is as follows.\n\nt[1..D] = compute an initial solution (by random generation, or by applying other methods such as greedy)\nwhile the remaining time > 0:\npick d and q at random\nold = t[d] # Remember the original value so that we can restore it later\nt[d] = q\nif the solution gets worse:\nt[d] = old\n\nThe most important thing when using the local search method is the design of how to modify solutions.\n\nIf the amount of modification is too small, we will soon fall into a dead-end (local optimum) and, conversely, if the amount of modification is too large, the probability of finding an improving move becomes extremely small.\n\nIn order to increase the number of iterations, it is desirable to be able to quickly calculate the score after applying a modification.\n\nIn this problem C, we focus on the second point.\nThe score after the modification can, of course, be obtained by calculating the score from scratch.\nHowever, by focusing on only the parts that have been modified, it may be possible to quickly compute the difference between the scores before and after the modification.\nFrom another viewpoint, the impossibility of such a fast incremental calculation implies that a small modification to the solution affects a majority of the score calculation.\nIn such a case, we may need to redesign how to modify solutions, or there is a high possibility that the problem is not suitable for local search.\nLet's implement fast incremental score computation.\nIt's time to demonstrate the skills of algorithms and data structures you have developed in ABC and ARC!\n\nIn this kind of contest, where the objective is to find a better solution instead of the optimal one, a bug in a program does not result in a wrong answer, which may delay the discovery of the bug.\nFor early detection of bugs, it is a good idea to unit test functions you implemented complicated routines.\nFor example, if you implement fast incremental score calculation, it is a good idea to test that the scores computed by the fast implementation match the scores computed from scratch, as we will do in this problem C.\n\nProblem Statement\n\nYou will be given a contest schedule for D days and M queries of schedule modification.\nIn the i-th query, given integers d_i and q_i, change the type of contest to be held on day d_i to q_i, and then output the final satisfaction at the end of day D on the updated schedule.\nNote that we do not revert each query. That is, the i-th query is applied to the new schedule obtained by the (i-1)-th query.\n\nInput\n\nInput is given from Standard Input in the form of the input of Problem A followed by the output of Problem A and the queries.\n\nD\nc_1 c_2 \\cdots c_{26}\ns_{1,1} s_{1,2} \\cdots s_{1,26}\n\\vdots\ns_{D,1} s_{D,2} \\cdots s_{D,26}\nt_1\nt_2\n\\vdots\nt_D\nM\nd_1 q_1\nd_2 q_2\n\\vdots\nd_M q_M\n\nThe constraints and generation methods for the input part are the same as those for Problem A.\n\nFor each d=1,\\ldots,D, t_d is an integer generated independently and uniformly at random from {1,2,\\ldots,26}.\n\nThe number of queries M is an integer satisfying 1\\leq M\\leq 10^5.\n\nFor each i=1,\\ldots,M, d_i is an integer generated independently and uniformly at random from {1,2,\\ldots,D}.\n\nFor each i=1,\\ldots,26, q_i is an integer satisfying 1\\leq q_i\\leq 26 generated uniformly at random from the 25 values that differ from the type of contest on day d_i.\n\nOutput\n\nLet v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query.\nPrint M integers v_i to Standard Output in the following format:\n\nv_1\nv_2\n\\vdots\nv_M\n\nSample Input 1\n\n5\n86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82\n19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424\n6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570\n6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256\n8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452\n19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192\n1\n17\n13\n14\n13\n5\n1 7\n4 11\n3 4\n5 24\n4 19\n\nSample Output 1\n\n72882\n56634\n38425\n27930\n42884\n\nNote that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case.\n\nNext Step\n\nLet's go back to Problem A and implement the local search algorithm by utilizing the incremental score calculator you just implemented!\nFor this problem, the current modification \"pick the date d and contest type q at random and change the type of contest to be held on day d to q\" is actually not so good. By considering why it is not good, let's improve the modification operation.\nOne of the most powerful and widely used variant of the local search method is \"Simulated Annealing (SA)\", which makes it easier to reach a better solution by stochastically accepting worsening moves.\nFor more information about SA and other local search techniques, please refer to the editorial that will be published after the contest.", "sample_input": "5\n86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82\n19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424\n6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570\n6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256\n8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452\n19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192\n1\n17\n13\n14\n13\n5\n1 7\n4 11\n3 4\n5 24\n4 19\n"}, "reference_outputs": ["72882\n56634\n38425\n27930\n42884\n"], "source_document_id": "p02620", "source_text": "(Please read problem A first. The maximum score you can get by solving this problem C is 1, which will have almost no effect on your ranking.)\n\nBeginner's Guide\n\n\"Local search\" is a powerful method for finding a high-quality solution.\nIn this method, instead of constructing a solution from scratch, we try to find a better solution by slightly modifying the already found solution.\nIf the solution gets better, update it, and if it gets worse, restore it.\nBy repeating this process, the quality of the solution is gradually improved over time.\nThe pseudo-code is as follows.\n\nsolution = compute an initial solution (by random generation, or by applying other methods such as greedy)\nwhile the remaining time > 0:\nslightly modify the solution (randomly)\nif the solution gets worse:\nrestore the solution\n\nFor example, in this problem, we can use the following modification: pick the date d and contest type q at random and change the type of contest to be held on day d to q.\nThe pseudo-code is as follows.\n\nt[1..D] = compute an initial solution (by random generation, or by applying other methods such as greedy)\nwhile the remaining time > 0:\npick d and q at random\nold = t[d] # Remember the original value so that we can restore it later\nt[d] = q\nif the solution gets worse:\nt[d] = old\n\nThe most important thing when using the local search method is the design of how to modify solutions.\n\nIf the amount of modification is too small, we will soon fall into a dead-end (local optimum) and, conversely, if the amount of modification is too large, the probability of finding an improving move becomes extremely small.\n\nIn order to increase the number of iterations, it is desirable to be able to quickly calculate the score after applying a modification.\n\nIn this problem C, we focus on the second point.\nThe score after the modification can, of course, be obtained by calculating the score from scratch.\nHowever, by focusing on only the parts that have been modified, it may be possible to quickly compute the difference between the scores before and after the modification.\nFrom another viewpoint, the impossibility of such a fast incremental calculation implies that a small modification to the solution affects a majority of the score calculation.\nIn such a case, we may need to redesign how to modify solutions, or there is a high possibility that the problem is not suitable for local search.\nLet's implement fast incremental score computation.\nIt's time to demonstrate the skills of algorithms and data structures you have developed in ABC and ARC!\n\nIn this kind of contest, where the objective is to find a better solution instead of the optimal one, a bug in a program does not result in a wrong answer, which may delay the discovery of the bug.\nFor early detection of bugs, it is a good idea to unit test functions you implemented complicated routines.\nFor example, if you implement fast incremental score calculation, it is a good idea to test that the scores computed by the fast implementation match the scores computed from scratch, as we will do in this problem C.\n\nProblem Statement\n\nYou will be given a contest schedule for D days and M queries of schedule modification.\nIn the i-th query, given integers d_i and q_i, change the type of contest to be held on day d_i to q_i, and then output the final satisfaction at the end of day D on the updated schedule.\nNote that we do not revert each query. That is, the i-th query is applied to the new schedule obtained by the (i-1)-th query.\n\nInput\n\nInput is given from Standard Input in the form of the input of Problem A followed by the output of Problem A and the queries.\n\nD\nc_1 c_2 \\cdots c_{26}\ns_{1,1} s_{1,2} \\cdots s_{1,26}\n\\vdots\ns_{D,1} s_{D,2} \\cdots s_{D,26}\nt_1\nt_2\n\\vdots\nt_D\nM\nd_1 q_1\nd_2 q_2\n\\vdots\nd_M q_M\n\nThe constraints and generation methods for the input part are the same as those for Problem A.\n\nFor each d=1,\\ldots,D, t_d is an integer generated independently and uniformly at random from {1,2,\\ldots,26}.\n\nThe number of queries M is an integer satisfying 1\\leq M\\leq 10^5.\n\nFor each i=1,\\ldots,M, d_i is an integer generated independently and uniformly at random from {1,2,\\ldots,D}.\n\nFor each i=1,\\ldots,26, q_i is an integer satisfying 1\\leq q_i\\leq 26 generated uniformly at random from the 25 values that differ from the type of contest on day d_i.\n\nOutput\n\nLet v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query.\nPrint M integers v_i to Standard Output in the following format:\n\nv_1\nv_2\n\\vdots\nv_M\n\nSample Input 1\n\n5\n86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82\n19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424\n6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570\n6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256\n8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452\n19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192\n1\n17\n13\n14\n13\n5\n1 7\n4 11\n3 4\n5 24\n4 19\n\nSample Output 1\n\n72882\n56634\n38425\n27930\n42884\n\nNote that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case.\n\nNext Step\n\nLet's go back to Problem A and implement the local search algorithm by utilizing the incremental score calculator you just implemented!\nFor this problem, the current modification \"pick the date d and contest type q at random and change the type of contest to be held on day d to q\" is actually not so good. By considering why it is not good, let's improve the modification operation.\nOne of the most powerful and widely used variant of the local search method is \"Simulated Annealing (SA)\", which makes it easier to reach a better solution by stochastically accepting worsening moves.\nFor more information about SA and other local search techniques, please refer to the editorial that will be published after the contest.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1119, "cpu_time_ms": 2208, "memory_kb": 76892}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s408103574", "group_id": "codeNet:p02621", "input_text": "(setq a (read))\n(setq b (expt a 2))\n(print (+ a (expt a 2) (expt a 3)))\n", "language": "Lisp", "metadata": {"date": 1593639554, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02621.html", "problem_id": "p02621", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02621/input.txt", "sample_output_relpath": "derived/input_output/data/p02621/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02621/Lisp/s408103574.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s408103574", "user_id": "u981314341"}, "prompt_components": {"gold_output": "14\n", "input_to_evaluate": "(setq a (read))\n(setq b (expt a 2))\n(print (+ a (expt a 2) (expt a 3)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nGiven an integer a as input, print the value a + a^2 + a^3.\n\nConstraints\n\n1 \\leq a \\leq 10\n\na is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na\n\nOutput\n\nPrint the value a + a^2 + a^3 as an integer.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n14\n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as 14.0 will be judged as incorrect.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n1110", "sample_input": "2\n"}, "reference_outputs": ["14\n"], "source_document_id": "p02621", "source_text": "Score : 100 points\n\nProblem Statement\n\nGiven an integer a as input, print the value a + a^2 + a^3.\n\nConstraints\n\n1 \\leq a \\leq 10\n\na is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na\n\nOutput\n\nPrint the value a + a^2 + a^3 as an integer.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n14\n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as 14.0 will be judged as incorrect.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n1110", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 72, "cpu_time_ms": 19, "memory_kb": 24264}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s781208707", "group_id": "codeNet:p02622", "input_text": "(defun main ()\n (let ((s (read-line))\n\t(t1 (read-line))\n\t(ans 0))\n (loop\n :for char1 :across s\n :for char2 :across t1\n :unless (equal char1 char2)\n :do (incf ans))\n ans))\n\n(format t \"~a~%\" (main))\n", "language": "Lisp", "metadata": {"date": 1593307429, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02622.html", "problem_id": "p02622", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02622/input.txt", "sample_output_relpath": "derived/input_output/data/p02622/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02622/Lisp/s781208707.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s781208707", "user_id": "u091381267"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun main ()\n (let ((s (read-line))\n\t(t1 (read-line))\n\t(ans 0))\n (loop\n :for char1 :across s\n :for char2 :across t1\n :unless (equal char1 char2)\n :do (incf ans))\n ans))\n\n(format t \"~a~%\" (main))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so.\n\nOperation: Choose one character of S and replace it with a different character.\n\nConstraints\n\nS and T have lengths between 1 and 2\\times 10^5 (inclusive).\n\nS and T consists of lowercase English letters.\n\nS and T have equal lengths.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\ncupofcoffee\ncupofhottea\n\nSample Output 1\n\n4\n\nWe can achieve the objective in four operations, such as the following:\n\nFirst, replace the sixth character c with h.\n\nSecond, replace the eighth character f with t.\n\nThird, replace the ninth character f with t.\n\nFourth, replace the eleventh character e with a.\n\nSample Input 2\n\nabcde\nbcdea\n\nSample Output 2\n\n5\n\nSample Input 3\n\napple\napple\n\nSample Output 3\n\n0\n\nNo operations may be needed to achieve the objective.", "sample_input": "cupofcoffee\ncupofhottea\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02622", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so.\n\nOperation: Choose one character of S and replace it with a different character.\n\nConstraints\n\nS and T have lengths between 1 and 2\\times 10^5 (inclusive).\n\nS and T consists of lowercase English letters.\n\nS and T have equal lengths.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\ncupofcoffee\ncupofhottea\n\nSample Output 1\n\n4\n\nWe can achieve the objective in four operations, such as the following:\n\nFirst, replace the sixth character c with h.\n\nSecond, replace the eighth character f with t.\n\nThird, replace the ninth character f with t.\n\nFourth, replace the eleventh character e with a.\n\nSample Input 2\n\nabcde\nbcdea\n\nSample Output 2\n\n5\n\nSample Input 3\n\napple\napple\n\nSample Output 3\n\n0\n\nNo operations may be needed to achieve the objective.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 228, "cpu_time_ms": 42, "memory_kb": 29652}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s632471407", "group_id": "codeNet:p02622", "input_text": "(let ((s (read-line))\n (_t (read-line))\n (ans 0))\n (loop :for c :across s\n :for d :across _t\n :if (char/= c d)\n :do (incf ans))\n (format t \"~A~%\" ans))\n", "language": "Lisp", "metadata": {"date": 1593306247, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02622.html", "problem_id": "p02622", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02622/input.txt", "sample_output_relpath": "derived/input_output/data/p02622/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02622/Lisp/s632471407.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s632471407", "user_id": "u608227593"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let ((s (read-line))\n (_t (read-line))\n (ans 0))\n (loop :for c :across s\n :for d :across _t\n :if (char/= c d)\n :do (incf ans))\n (format t \"~A~%\" ans))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so.\n\nOperation: Choose one character of S and replace it with a different character.\n\nConstraints\n\nS and T have lengths between 1 and 2\\times 10^5 (inclusive).\n\nS and T consists of lowercase English letters.\n\nS and T have equal lengths.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\ncupofcoffee\ncupofhottea\n\nSample Output 1\n\n4\n\nWe can achieve the objective in four operations, such as the following:\n\nFirst, replace the sixth character c with h.\n\nSecond, replace the eighth character f with t.\n\nThird, replace the ninth character f with t.\n\nFourth, replace the eleventh character e with a.\n\nSample Input 2\n\nabcde\nbcdea\n\nSample Output 2\n\n5\n\nSample Input 3\n\napple\napple\n\nSample Output 3\n\n0\n\nNo operations may be needed to achieve the objective.", "sample_input": "cupofcoffee\ncupofhottea\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02622", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so.\n\nOperation: Choose one character of S and replace it with a different character.\n\nConstraints\n\nS and T have lengths between 1 and 2\\times 10^5 (inclusive).\n\nS and T consists of lowercase English letters.\n\nS and T have equal lengths.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\ncupofcoffee\ncupofhottea\n\nSample Output 1\n\n4\n\nWe can achieve the objective in four operations, such as the following:\n\nFirst, replace the sixth character c with h.\n\nSecond, replace the eighth character f with t.\n\nThird, replace the ninth character f with t.\n\nFourth, replace the eleventh character e with a.\n\nSample Input 2\n\nabcde\nbcdea\n\nSample Output 2\n\n5\n\nSample Input 3\n\napple\napple\n\nSample Output 3\n\n0\n\nNo operations may be needed to achieve the objective.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 185, "cpu_time_ms": 43, "memory_kb": 29664}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s714327296", "group_id": "codeNet:p02626", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro xor (form1 form2)\n (let ((f1 (gensym)) (f2 (gensym)))\n `(let ((,f1 ,form1)\n (,f2 ,form2))\n (if ,f1 (not ,f2) ,f2))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun test (a1 a2)\n (loop for x from 0 to a1\n for value = (logxor (- a1 x) (+ a2 x))\n do ;; (format t \"~10,'0B~%\" value)\n (println value)\n ;; (format t \"~D ~D: ~8,'0B~%\" (- a1 x) (+ a2 x) value)\n ))\n\n(defun solve (a1 a2 rhs &optional (length 40))\n (declare (uint62 a1 a2 rhs))\n (labels ((dfs (pos value1)\n (declare ((integer -1 40) pos)\n (uint62 value1))\n (dbg pos value1)\n (let* ((k (- a1 value1))\n (value2 (+ a2 k)))\n (declare (uint62 value2))\n (when (= pos -1)\n (if (and (> value1 0)\n (= (logxor value1 value2) rhs))\n (return-from solve value1)\n (return-from dfs)))\n (let* ((cut (dpb 0 (byte pos 0) value2))\n (mask (ldb (byte 64 0) (lognot (- (ash (logand cut (- cut)) 1) 1)))))\n ;; (format t \"~64,'0B~%\" value1)\n ;; (format t \"~64,'0B~%\" value2)\n ;; (format t \"~64,'0B~%\" mask)\n (unless (= (logand mask (logxor value1 value2))\n (logand mask rhs))\n (return-from dfs)))\n ;; 次を1\n (let* ((next-value1 (+ value1 (ash 1 pos))))\n ;; (dbg next-value1 next-value2)\n (when (< next-value1 a1)\n (dfs (- pos 1) next-value1)))\n (dbg value1 value2 k)\n ;; 次を0\n (dfs (- pos 1) value1))))\n (dfs (- length 1) 0)))\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint62 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read)))\n (let ((a1 (aref as 0))\n (a2 (aref as 1))\n (d (reduce #'logxor as :start 2 :initial-value 0)))\n (dbg a1 a2 d)\n (let ((res (solve a1 a2 d 41)))\n (println\n (if res\n (- a1 res)\n -1))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n5 3\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n3 5\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 1 2\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n10 9 8 7 6 5 4 3\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n4294967297 8589934593 12884901890\n\"\n \"1\n\")))\n", "language": "Lisp", "metadata": {"date": 1593332732, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02626.html", "problem_id": "p02626", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02626/input.txt", "sample_output_relpath": "derived/input_output/data/p02626/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02626/Lisp/s714327296.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s714327296", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro xor (form1 form2)\n (let ((f1 (gensym)) (f2 (gensym)))\n `(let ((,f1 ,form1)\n (,f2 ,form2))\n (if ,f1 (not ,f2) ,f2))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun test (a1 a2)\n (loop for x from 0 to a1\n for value = (logxor (- a1 x) (+ a2 x))\n do ;; (format t \"~10,'0B~%\" value)\n (println value)\n ;; (format t \"~D ~D: ~8,'0B~%\" (- a1 x) (+ a2 x) value)\n ))\n\n(defun solve (a1 a2 rhs &optional (length 40))\n (declare (uint62 a1 a2 rhs))\n (labels ((dfs (pos value1)\n (declare ((integer -1 40) pos)\n (uint62 value1))\n (dbg pos value1)\n (let* ((k (- a1 value1))\n (value2 (+ a2 k)))\n (declare (uint62 value2))\n (when (= pos -1)\n (if (and (> value1 0)\n (= (logxor value1 value2) rhs))\n (return-from solve value1)\n (return-from dfs)))\n (let* ((cut (dpb 0 (byte pos 0) value2))\n (mask (ldb (byte 64 0) (lognot (- (ash (logand cut (- cut)) 1) 1)))))\n ;; (format t \"~64,'0B~%\" value1)\n ;; (format t \"~64,'0B~%\" value2)\n ;; (format t \"~64,'0B~%\" mask)\n (unless (= (logand mask (logxor value1 value2))\n (logand mask rhs))\n (return-from dfs)))\n ;; 次を1\n (let* ((next-value1 (+ value1 (ash 1 pos))))\n ;; (dbg next-value1 next-value2)\n (when (< next-value1 a1)\n (dfs (- pos 1) next-value1)))\n (dbg value1 value2 k)\n ;; 次を0\n (dfs (- pos 1) value1))))\n (dfs (- length 1) 0)))\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint62 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read)))\n (let ((a1 (aref as 0))\n (a2 (aref as 1))\n (d (reduce #'logxor as :start 2 :initial-value 0)))\n (dbg a1 a2 d)\n (let ((res (solve a1 a2 d 41)))\n (println\n (if res\n (- a1 res)\n -1))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n5 3\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n3 5\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 1 2\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n10 9 8 7 6 5 4 3\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n4294967297 8589934593 12884901890\n\"\n \"1\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere are N piles of stones. The i-th pile has A_i stones.\n\nAoki and Takahashi are about to use them to play the following game:\n\nStarting with Aoki, the two players alternately do the following operation:\n\nOperation: Choose one pile of stones, and remove one or more stones from it.\n\nWhen a player is unable to do the operation, he loses, and the other player wins.\n\nWhen the two players play optimally, there are two possibilities in this game: the player who moves first always wins, or the player who moves second always wins, only depending on the initial number of stones in each pile.\n\nIn such a situation, Takahashi, the second player to act, is trying to guarantee his win by moving at least zero and at most (A_1 - 1) stones from the 1-st pile to the 2-nd pile before the game begins.\n\nIf this is possible, print the minimum number of stones to move to guarantee his victory; otherwise, print -1 instead.\n\nConstraints\n\n2 \\leq N \\leq 300\n\n1 \\leq A_i \\leq 10^{12}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 \\ldots A_N\n\nOutput\n\nPrint the minimum number of stones to move to guarantee Takahashi's win; otherwise, print -1 instead.\n\nSample Input 1\n\n2\n5 3\n\nSample Output 1\n\n1\n\nWithout moving stones, if Aoki first removes 2 stones from the 1-st pile, Takahashi cannot win in any way.\n\nIf Takahashi moves 1 stone from the 1-st pile to the 2-nd before the game begins so that both piles have 4 stones, Takahashi can always win by properly choosing his actions.\n\nSample Input 2\n\n2\n3 5\n\nSample Output 2\n\n-1\n\nIt is not allowed to move stones from the 2-nd pile to the 1-st.\n\nSample Input 3\n\n3\n1 1 2\n\nSample Output 3\n\n-1\n\nIt is not allowed to move all stones from the 1-st pile.\n\nSample Input 4\n\n8\n10 9 8 7 6 5 4 3\n\nSample Output 4\n\n3\n\nSample Input 5\n\n3\n4294967297 8589934593 12884901890\n\nSample Output 5\n\n1\n\nWatch out for overflows.", "sample_input": "2\n5 3\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02626", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere are N piles of stones. The i-th pile has A_i stones.\n\nAoki and Takahashi are about to use them to play the following game:\n\nStarting with Aoki, the two players alternately do the following operation:\n\nOperation: Choose one pile of stones, and remove one or more stones from it.\n\nWhen a player is unable to do the operation, he loses, and the other player wins.\n\nWhen the two players play optimally, there are two possibilities in this game: the player who moves first always wins, or the player who moves second always wins, only depending on the initial number of stones in each pile.\n\nIn such a situation, Takahashi, the second player to act, is trying to guarantee his win by moving at least zero and at most (A_1 - 1) stones from the 1-st pile to the 2-nd pile before the game begins.\n\nIf this is possible, print the minimum number of stones to move to guarantee his victory; otherwise, print -1 instead.\n\nConstraints\n\n2 \\leq N \\leq 300\n\n1 \\leq A_i \\leq 10^{12}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 \\ldots A_N\n\nOutput\n\nPrint the minimum number of stones to move to guarantee Takahashi's win; otherwise, print -1 instead.\n\nSample Input 1\n\n2\n5 3\n\nSample Output 1\n\n1\n\nWithout moving stones, if Aoki first removes 2 stones from the 1-st pile, Takahashi cannot win in any way.\n\nIf Takahashi moves 1 stone from the 1-st pile to the 2-nd before the game begins so that both piles have 4 stones, Takahashi can always win by properly choosing his actions.\n\nSample Input 2\n\n2\n3 5\n\nSample Output 2\n\n-1\n\nIt is not allowed to move stones from the 2-nd pile to the 1-st.\n\nSample Input 3\n\n3\n1 1 2\n\nSample Output 3\n\n-1\n\nIt is not allowed to move all stones from the 1-st pile.\n\nSample Input 4\n\n8\n10 9 8 7 6 5 4 3\n\nSample Output 4\n\n3\n\nSample Input 5\n\n3\n4294967297 8589934593 12884901890\n\nSample Output 5\n\n1\n\nWatch out for overflows.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5886, "cpu_time_ms": 21, "memory_kb": 25040}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s559010136", "group_id": "codeNet:p02626", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro xor (form1 form2)\n (let ((f1 (gensym)) (f2 (gensym)))\n `(let ((,f1 ,form1)\n (,f2 ,form2))\n (if ,f1 (not ,f2) ,f2))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun test (a1 a2)\n (loop for x from 0 to a1\n for value = (logxor (- a1 x) (+ a2 x))\n do ;; (format t \"~10,'0B~%\" value)\n (println value)\n ;; (format t \"~D ~D: ~8,'0B~%\" (- a1 x) (+ a2 x) value)\n ))\n\n(defun solve (a1 a2 rhs &optional (length 40))\n (declare #.OPT\n (uint62 a1 a2 rhs))\n (labels ((dfs (pos value1)\n (declare ((integer -1 40) pos)\n (uint62 value1))\n (let* ((k (- a1 value1))\n (value2 (+ a2 k)))\n (declare (uint62 value2))\n (when (= pos -1)\n (if (and (> value1 0)\n (= (logxor value1 value2) rhs))\n (return-from solve value1)\n (return-from dfs)))\n (if (logbitp (+ pos 25) rhs)\n (unless (xor (logbitp (+ pos 25) value1)\n (logbitp (+ pos 25) value2))\n (return-from dfs))\n (when (xor (logbitp (+ pos 25) value1)\n (logbitp (+ pos 25) value2))\n (return-from dfs)))\n ;; 次を1\n (let* ((next-value1 (+ value1 (ash 1 pos))))\n ;; (dbg next-value1 next-value2)\n (when (< next-value1 a1)\n (dfs (- pos 1) next-value1)))\n (dbg value1 value2 k)\n ;; 次を0\n (dfs (- pos 1) value1))))\n (dfs (- length 1) 0)))\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint62 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read)))\n (let ((a1 (aref as 0))\n (a2 (aref as 1))\n (d (reduce #'logxor as :start 2 :initial-value 0)))\n (dbg a1 a2 d)\n (let ((res (solve a1 a2 d 40)))\n (println\n (if res\n (- a1 res)\n -1))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n5 3\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n3 5\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 1 2\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n10 9 8 7 6 5 4 3\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n4294967297 8589934593 12884901890\n\"\n \"1\n\")))\n", "language": "Lisp", "metadata": {"date": 1593316349, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02626.html", "problem_id": "p02626", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02626/input.txt", "sample_output_relpath": "derived/input_output/data/p02626/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02626/Lisp/s559010136.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s559010136", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro xor (form1 form2)\n (let ((f1 (gensym)) (f2 (gensym)))\n `(let ((,f1 ,form1)\n (,f2 ,form2))\n (if ,f1 (not ,f2) ,f2))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun test (a1 a2)\n (loop for x from 0 to a1\n for value = (logxor (- a1 x) (+ a2 x))\n do ;; (format t \"~10,'0B~%\" value)\n (println value)\n ;; (format t \"~D ~D: ~8,'0B~%\" (- a1 x) (+ a2 x) value)\n ))\n\n(defun solve (a1 a2 rhs &optional (length 40))\n (declare #.OPT\n (uint62 a1 a2 rhs))\n (labels ((dfs (pos value1)\n (declare ((integer -1 40) pos)\n (uint62 value1))\n (let* ((k (- a1 value1))\n (value2 (+ a2 k)))\n (declare (uint62 value2))\n (when (= pos -1)\n (if (and (> value1 0)\n (= (logxor value1 value2) rhs))\n (return-from solve value1)\n (return-from dfs)))\n (if (logbitp (+ pos 25) rhs)\n (unless (xor (logbitp (+ pos 25) value1)\n (logbitp (+ pos 25) value2))\n (return-from dfs))\n (when (xor (logbitp (+ pos 25) value1)\n (logbitp (+ pos 25) value2))\n (return-from dfs)))\n ;; 次を1\n (let* ((next-value1 (+ value1 (ash 1 pos))))\n ;; (dbg next-value1 next-value2)\n (when (< next-value1 a1)\n (dfs (- pos 1) next-value1)))\n (dbg value1 value2 k)\n ;; 次を0\n (dfs (- pos 1) value1))))\n (dfs (- length 1) 0)))\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint62 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read)))\n (let ((a1 (aref as 0))\n (a2 (aref as 1))\n (d (reduce #'logxor as :start 2 :initial-value 0)))\n (dbg a1 a2 d)\n (let ((res (solve a1 a2 d 40)))\n (println\n (if res\n (- a1 res)\n -1))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n5 3\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n3 5\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 1 2\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n10 9 8 7 6 5 4 3\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n4294967297 8589934593 12884901890\n\"\n \"1\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere are N piles of stones. The i-th pile has A_i stones.\n\nAoki and Takahashi are about to use them to play the following game:\n\nStarting with Aoki, the two players alternately do the following operation:\n\nOperation: Choose one pile of stones, and remove one or more stones from it.\n\nWhen a player is unable to do the operation, he loses, and the other player wins.\n\nWhen the two players play optimally, there are two possibilities in this game: the player who moves first always wins, or the player who moves second always wins, only depending on the initial number of stones in each pile.\n\nIn such a situation, Takahashi, the second player to act, is trying to guarantee his win by moving at least zero and at most (A_1 - 1) stones from the 1-st pile to the 2-nd pile before the game begins.\n\nIf this is possible, print the minimum number of stones to move to guarantee his victory; otherwise, print -1 instead.\n\nConstraints\n\n2 \\leq N \\leq 300\n\n1 \\leq A_i \\leq 10^{12}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 \\ldots A_N\n\nOutput\n\nPrint the minimum number of stones to move to guarantee Takahashi's win; otherwise, print -1 instead.\n\nSample Input 1\n\n2\n5 3\n\nSample Output 1\n\n1\n\nWithout moving stones, if Aoki first removes 2 stones from the 1-st pile, Takahashi cannot win in any way.\n\nIf Takahashi moves 1 stone from the 1-st pile to the 2-nd before the game begins so that both piles have 4 stones, Takahashi can always win by properly choosing his actions.\n\nSample Input 2\n\n2\n3 5\n\nSample Output 2\n\n-1\n\nIt is not allowed to move stones from the 2-nd pile to the 1-st.\n\nSample Input 3\n\n3\n1 1 2\n\nSample Output 3\n\n-1\n\nIt is not allowed to move all stones from the 1-st pile.\n\nSample Input 4\n\n8\n10 9 8 7 6 5 4 3\n\nSample Output 4\n\n3\n\nSample Input 5\n\n3\n4294967297 8589934593 12884901890\n\nSample Output 5\n\n1\n\nWatch out for overflows.", "sample_input": "2\n5 3\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02626", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere are N piles of stones. The i-th pile has A_i stones.\n\nAoki and Takahashi are about to use them to play the following game:\n\nStarting with Aoki, the two players alternately do the following operation:\n\nOperation: Choose one pile of stones, and remove one or more stones from it.\n\nWhen a player is unable to do the operation, he loses, and the other player wins.\n\nWhen the two players play optimally, there are two possibilities in this game: the player who moves first always wins, or the player who moves second always wins, only depending on the initial number of stones in each pile.\n\nIn such a situation, Takahashi, the second player to act, is trying to guarantee his win by moving at least zero and at most (A_1 - 1) stones from the 1-st pile to the 2-nd pile before the game begins.\n\nIf this is possible, print the minimum number of stones to move to guarantee his victory; otherwise, print -1 instead.\n\nConstraints\n\n2 \\leq N \\leq 300\n\n1 \\leq A_i \\leq 10^{12}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 \\ldots A_N\n\nOutput\n\nPrint the minimum number of stones to move to guarantee Takahashi's win; otherwise, print -1 instead.\n\nSample Input 1\n\n2\n5 3\n\nSample Output 1\n\n1\n\nWithout moving stones, if Aoki first removes 2 stones from the 1-st pile, Takahashi cannot win in any way.\n\nIf Takahashi moves 1 stone from the 1-st pile to the 2-nd before the game begins so that both piles have 4 stones, Takahashi can always win by properly choosing his actions.\n\nSample Input 2\n\n2\n3 5\n\nSample Output 2\n\n-1\n\nIt is not allowed to move stones from the 2-nd pile to the 1-st.\n\nSample Input 3\n\n3\n1 1 2\n\nSample Output 3\n\n-1\n\nIt is not allowed to move all stones from the 1-st pile.\n\nSample Input 4\n\n8\n10 9 8 7 6 5 4 3\n\nSample Output 4\n\n3\n\nSample Input 5\n\n3\n4294967297 8589934593 12884901890\n\nSample Output 5\n\n1\n\nWatch out for overflows.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5789, "cpu_time_ms": 2206, "memory_kb": 25180}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s907885687", "group_id": "codeNet:p02626", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro xor (form1 form2)\n (let ((f1 (gensym)) (f2 (gensym)))\n `(let ((,f1 ,form1)\n (,f2 ,form2))\n (if ,f1 (not ,f2) ,f2))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun test (a1 a2)\n (loop for x from 0 to a1\n for value = (logxor (- a1 x) (+ a2 x))\n do ;; (format t \"~10,'0B~%\" value)\n (println value)\n ;; (format t \"~D ~D: ~8,'0B~%\" (- a1 x) (+ a2 x) value)\n ))\n\n(defun solve (a1 a2 rhs &optional (length 40))\n (declare #.OPT\n (uint62 a1 a2 rhs))\n (labels ((dfs (pos value1)\n (declare ((integer -1 50) pos)\n (uint62 value1))\n (let* ((k (- a1 value1))\n (value2 (+ a2 k)))\n (when (= pos -1)\n (if (and (> value1 0)\n (= (logxor value1 value2) rhs))\n (return-from solve value1)\n (return-from dfs)))\n (if (logbitp (+ pos 25) rhs)\n (unless (xor (logbitp (+ pos 25) value1)\n (logbitp (+ pos 25) value2))\n (return-from dfs))\n (when (xor (logbitp (+ pos 25) value1)\n (logbitp (+ pos 25) value2))\n (return-from dfs)))\n ;; 次を1\n (let* ((next-value1 (+ value1 (ash 1 pos))))\n ;; (dbg next-value1 next-value2)\n (when (< next-value1 a1)\n (dfs (- pos 1) next-value1)))\n ;; 次を0\n (dfs (- pos 1) value1))))\n (dfs (- length 1) 0)))\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint62 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read)))\n (let ((a1 (aref as 0))\n (a2 (aref as 1))\n (d (reduce #'logxor as :start 2 :initial-value 0)))\n (dbg a1 a2 d)\n (let ((res (solve a1 a2 d 41)))\n (println\n (if res\n (- a1 res)\n -1))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n5 3\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n3 5\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 1 2\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n10 9 8 7 6 5 4 3\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n4294967297 8589934593 12884901890\n\"\n \"1\n\")))\n", "language": "Lisp", "metadata": {"date": 1593312091, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02626.html", "problem_id": "p02626", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02626/input.txt", "sample_output_relpath": "derived/input_output/data/p02626/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02626/Lisp/s907885687.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s907885687", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro xor (form1 form2)\n (let ((f1 (gensym)) (f2 (gensym)))\n `(let ((,f1 ,form1)\n (,f2 ,form2))\n (if ,f1 (not ,f2) ,f2))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun test (a1 a2)\n (loop for x from 0 to a1\n for value = (logxor (- a1 x) (+ a2 x))\n do ;; (format t \"~10,'0B~%\" value)\n (println value)\n ;; (format t \"~D ~D: ~8,'0B~%\" (- a1 x) (+ a2 x) value)\n ))\n\n(defun solve (a1 a2 rhs &optional (length 40))\n (declare #.OPT\n (uint62 a1 a2 rhs))\n (labels ((dfs (pos value1)\n (declare ((integer -1 50) pos)\n (uint62 value1))\n (let* ((k (- a1 value1))\n (value2 (+ a2 k)))\n (when (= pos -1)\n (if (and (> value1 0)\n (= (logxor value1 value2) rhs))\n (return-from solve value1)\n (return-from dfs)))\n (if (logbitp (+ pos 25) rhs)\n (unless (xor (logbitp (+ pos 25) value1)\n (logbitp (+ pos 25) value2))\n (return-from dfs))\n (when (xor (logbitp (+ pos 25) value1)\n (logbitp (+ pos 25) value2))\n (return-from dfs)))\n ;; 次を1\n (let* ((next-value1 (+ value1 (ash 1 pos))))\n ;; (dbg next-value1 next-value2)\n (when (< next-value1 a1)\n (dfs (- pos 1) next-value1)))\n ;; 次を0\n (dfs (- pos 1) value1))))\n (dfs (- length 1) 0)))\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint62 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read)))\n (let ((a1 (aref as 0))\n (a2 (aref as 1))\n (d (reduce #'logxor as :start 2 :initial-value 0)))\n (dbg a1 a2 d)\n (let ((res (solve a1 a2 d 41)))\n (println\n (if res\n (- a1 res)\n -1))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n5 3\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n3 5\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 1 2\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n10 9 8 7 6 5 4 3\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n4294967297 8589934593 12884901890\n\"\n \"1\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere are N piles of stones. The i-th pile has A_i stones.\n\nAoki and Takahashi are about to use them to play the following game:\n\nStarting with Aoki, the two players alternately do the following operation:\n\nOperation: Choose one pile of stones, and remove one or more stones from it.\n\nWhen a player is unable to do the operation, he loses, and the other player wins.\n\nWhen the two players play optimally, there are two possibilities in this game: the player who moves first always wins, or the player who moves second always wins, only depending on the initial number of stones in each pile.\n\nIn such a situation, Takahashi, the second player to act, is trying to guarantee his win by moving at least zero and at most (A_1 - 1) stones from the 1-st pile to the 2-nd pile before the game begins.\n\nIf this is possible, print the minimum number of stones to move to guarantee his victory; otherwise, print -1 instead.\n\nConstraints\n\n2 \\leq N \\leq 300\n\n1 \\leq A_i \\leq 10^{12}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 \\ldots A_N\n\nOutput\n\nPrint the minimum number of stones to move to guarantee Takahashi's win; otherwise, print -1 instead.\n\nSample Input 1\n\n2\n5 3\n\nSample Output 1\n\n1\n\nWithout moving stones, if Aoki first removes 2 stones from the 1-st pile, Takahashi cannot win in any way.\n\nIf Takahashi moves 1 stone from the 1-st pile to the 2-nd before the game begins so that both piles have 4 stones, Takahashi can always win by properly choosing his actions.\n\nSample Input 2\n\n2\n3 5\n\nSample Output 2\n\n-1\n\nIt is not allowed to move stones from the 2-nd pile to the 1-st.\n\nSample Input 3\n\n3\n1 1 2\n\nSample Output 3\n\n-1\n\nIt is not allowed to move all stones from the 1-st pile.\n\nSample Input 4\n\n8\n10 9 8 7 6 5 4 3\n\nSample Output 4\n\n3\n\nSample Input 5\n\n3\n4294967297 8589934593 12884901890\n\nSample Output 5\n\n1\n\nWatch out for overflows.", "sample_input": "2\n5 3\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02626", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere are N piles of stones. The i-th pile has A_i stones.\n\nAoki and Takahashi are about to use them to play the following game:\n\nStarting with Aoki, the two players alternately do the following operation:\n\nOperation: Choose one pile of stones, and remove one or more stones from it.\n\nWhen a player is unable to do the operation, he loses, and the other player wins.\n\nWhen the two players play optimally, there are two possibilities in this game: the player who moves first always wins, or the player who moves second always wins, only depending on the initial number of stones in each pile.\n\nIn such a situation, Takahashi, the second player to act, is trying to guarantee his win by moving at least zero and at most (A_1 - 1) stones from the 1-st pile to the 2-nd pile before the game begins.\n\nIf this is possible, print the minimum number of stones to move to guarantee his victory; otherwise, print -1 instead.\n\nConstraints\n\n2 \\leq N \\leq 300\n\n1 \\leq A_i \\leq 10^{12}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 \\ldots A_N\n\nOutput\n\nPrint the minimum number of stones to move to guarantee Takahashi's win; otherwise, print -1 instead.\n\nSample Input 1\n\n2\n5 3\n\nSample Output 1\n\n1\n\nWithout moving stones, if Aoki first removes 2 stones from the 1-st pile, Takahashi cannot win in any way.\n\nIf Takahashi moves 1 stone from the 1-st pile to the 2-nd before the game begins so that both piles have 4 stones, Takahashi can always win by properly choosing his actions.\n\nSample Input 2\n\n2\n3 5\n\nSample Output 2\n\n-1\n\nIt is not allowed to move stones from the 2-nd pile to the 1-st.\n\nSample Input 3\n\n3\n1 1 2\n\nSample Output 3\n\n-1\n\nIt is not allowed to move all stones from the 1-st pile.\n\nSample Input 4\n\n8\n10 9 8 7 6 5 4 3\n\nSample Output 4\n\n3\n\nSample Input 5\n\n3\n4294967297 8589934593 12884901890\n\nSample Output 5\n\n1\n\nWatch out for overflows.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5711, "cpu_time_ms": 2206, "memory_kb": 25188}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s729452100", "group_id": "codeNet:p02627", "input_text": "(princ (if (upper-case-p (read-char) ) \"A\" \"a\"))\n\n", "language": "Lisp", "metadata": {"date": 1593284763, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02627.html", "problem_id": "p02627", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02627/input.txt", "sample_output_relpath": "derived/input_output/data/p02627/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02627/Lisp/s729452100.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s729452100", "user_id": "u526532903"}, "prompt_components": {"gold_output": "A\n", "input_to_evaluate": "(princ (if (upper-case-p (read-char) ) \"A\" \"a\"))\n\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nAn uppercase or lowercase English letter \\alpha will be given as input.\nIf \\alpha is uppercase, print A; if it is lowercase, print a.\n\nConstraints\n\n\\alpha is an uppercase (A - Z) or lowercase (a - z) English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nα\n\nOutput\n\nIf \\alpha is uppercase, print A; if it is lowercase, print a.\n\nSample Input 1\n\nB\n\nSample Output 1\n\nA\n\nB is uppercase, so we should print A.\n\nSample Input 2\n\na\n\nSample Output 2\n\na\n\na is lowercase, so we should print a.", "sample_input": "B\n"}, "reference_outputs": ["A\n"], "source_document_id": "p02627", "source_text": "Score : 100 points\n\nProblem Statement\n\nAn uppercase or lowercase English letter \\alpha will be given as input.\nIf \\alpha is uppercase, print A; if it is lowercase, print a.\n\nConstraints\n\n\\alpha is an uppercase (A - Z) or lowercase (a - z) English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nα\n\nOutput\n\nIf \\alpha is uppercase, print A; if it is lowercase, print a.\n\nSample Input 1\n\nB\n\nSample Output 1\n\nA\n\nB is uppercase, so we should print A.\n\nSample Input 2\n\na\n\nSample Output 2\n\na\n\na is lowercase, so we should print a.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 50, "cpu_time_ms": 14, "memory_kb": 24096}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s124954511", "group_id": "codeNet:p02627", "input_text": "(defun app ()\n (let* ((a (string (read-char)))\n (num (char-code (coerce a 'character))))\n\n (if (> 97 num)\n (princ (string-downcase a))\n (princ (string-upcase a))\n )\n )\n)\n(app )\n", "language": "Lisp", "metadata": {"date": 1592794332, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02627.html", "problem_id": "p02627", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02627/input.txt", "sample_output_relpath": "derived/input_output/data/p02627/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02627/Lisp/s124954511.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s124954511", "user_id": "u136500538"}, "prompt_components": {"gold_output": "A\n", "input_to_evaluate": "(defun app ()\n (let* ((a (string (read-char)))\n (num (char-code (coerce a 'character))))\n\n (if (> 97 num)\n (princ (string-downcase a))\n (princ (string-upcase a))\n )\n )\n)\n(app )\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nAn uppercase or lowercase English letter \\alpha will be given as input.\nIf \\alpha is uppercase, print A; if it is lowercase, print a.\n\nConstraints\n\n\\alpha is an uppercase (A - Z) or lowercase (a - z) English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nα\n\nOutput\n\nIf \\alpha is uppercase, print A; if it is lowercase, print a.\n\nSample Input 1\n\nB\n\nSample Output 1\n\nA\n\nB is uppercase, so we should print A.\n\nSample Input 2\n\na\n\nSample Output 2\n\na\n\na is lowercase, so we should print a.", "sample_input": "B\n"}, "reference_outputs": ["A\n"], "source_document_id": "p02627", "source_text": "Score : 100 points\n\nProblem Statement\n\nAn uppercase or lowercase English letter \\alpha will be given as input.\nIf \\alpha is uppercase, print A; if it is lowercase, print a.\n\nConstraints\n\n\\alpha is an uppercase (A - Z) or lowercase (a - z) English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nα\n\nOutput\n\nIf \\alpha is uppercase, print A; if it is lowercase, print a.\n\nSample Input 1\n\nB\n\nSample Output 1\n\nA\n\nB is uppercase, so we should print A.\n\nSample Input 2\n\na\n\nSample Output 2\n\na\n\na is lowercase, so we should print a.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 202, "cpu_time_ms": 19, "memory_kb": 23560}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s192206815", "group_id": "codeNet:p02628", "input_text": "(defun main ()\n (let ((n (read))\n (k (read))\n (ans 0)\n p)\n (dotimes (i n)\n (push (read) p))\n (setf p (sort p #'<))\n (dotimes (i k)\n (setf ans (+ ans (pop p))))\n ans))\n\n(format t \"~a~%\" (main))\n", "language": "Lisp", "metadata": {"date": 1592788781, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02628.html", "problem_id": "p02628", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02628/input.txt", "sample_output_relpath": "derived/input_output/data/p02628/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02628/Lisp/s192206815.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s192206815", "user_id": "u091381267"}, "prompt_components": {"gold_output": "210\n", "input_to_evaluate": "(defun main ()\n (let ((n (read))\n (k (read))\n (ans 0)\n p)\n (dotimes (i n)\n (push (read) p))\n (setf p (sort p #'<))\n (dotimes (i k)\n (setf ans (+ ans (pop p))))\n ans))\n\n(format t \"~a~%\" (main))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nA shop sells N kinds of fruits, Fruit 1, \\ldots, N, at prices of p_1, \\ldots, p_N yen per item, respectively. (Yen is the currency of Japan.)\n\nHere, we will choose K kinds of fruits and buy one of each chosen kind. Find the minimum possible total price of those fruits.\n\nConstraints\n\n1 \\leq K \\leq N \\leq 1000\n\n1 \\leq p_i \\leq 1000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\np_1 p_2 \\ldots p_N\n\nOutput\n\nPrint an integer representing the minimum possible total price of fruits.\n\nSample Input 1\n\n5 3\n50 100 80 120 80\n\nSample Output 1\n\n210\n\nThis shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen, and 80 yen, respectively.\n\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen when choosing Fruit 1, 3, and 5.\n\nSample Input 2\n\n1 1\n1000\n\nSample Output 2\n\n1000", "sample_input": "5 3\n50 100 80 120 80\n"}, "reference_outputs": ["210\n"], "source_document_id": "p02628", "source_text": "Score : 200 points\n\nProblem Statement\n\nA shop sells N kinds of fruits, Fruit 1, \\ldots, N, at prices of p_1, \\ldots, p_N yen per item, respectively. (Yen is the currency of Japan.)\n\nHere, we will choose K kinds of fruits and buy one of each chosen kind. Find the minimum possible total price of those fruits.\n\nConstraints\n\n1 \\leq K \\leq N \\leq 1000\n\n1 \\leq p_i \\leq 1000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\np_1 p_2 \\ldots p_N\n\nOutput\n\nPrint an integer representing the minimum possible total price of fruits.\n\nSample Input 1\n\n5 3\n50 100 80 120 80\n\nSample Output 1\n\n210\n\nThis shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen, and 80 yen, respectively.\n\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen when choosing Fruit 1, 3, and 5.\n\nSample Input 2\n\n1 1\n1000\n\nSample Output 2\n\n1000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 237, "cpu_time_ms": 22, "memory_kb": 24996}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s042454982", "group_id": "codeNet:p02630", "input_text": "(let* ((n (read))\n (a (make-array 100001 :initial-element 0))\n (q 0)\n (ans 0))\n (dotimes (i n)\n (let ((d (read)))\n (incf (aref a i))\n (incf ans d)\n )\n )\n (setq q (read))\n (dotimes (i q)\n (let ((b (read))\n (c (read)))\n (incf (aref a c) (aref a b))\n (incf ans (* (aref a b) (- c b)))\n (setf (aref a b) 0)\n )\n (format t \"~D~%\" ans)\n )\n)", "language": "Lisp", "metadata": {"date": 1593363384, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02630.html", "problem_id": "p02630", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02630/input.txt", "sample_output_relpath": "derived/input_output/data/p02630/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02630/Lisp/s042454982.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s042454982", "user_id": "u136500538"}, "prompt_components": {"gold_output": "11\n12\n16\n", "input_to_evaluate": "(let* ((n (read))\n (a (make-array 100001 :initial-element 0))\n (q 0)\n (ans 0))\n (dotimes (i n)\n (let ((d (read)))\n (incf (aref a i))\n (incf ans d)\n )\n )\n (setq q (read))\n (dotimes (i q)\n (let ((b (read))\n (c (read)))\n (incf (aref a c) (aref a b))\n (incf ans (* (aref a b) (- c b)))\n (setf (aref a b) 0)\n )\n (format t \"~D~%\" ans)\n )\n)", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYou have a sequence A composed of N positive integers: A_{1}, A_{2}, \\cdots, A_{N}.\n\nYou will now successively do the following Q operations:\n\nIn the i-th operation, you replace every element whose value is B_{i} with C_{i}.\n\nFor each i (1 \\leq i \\leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N, Q, A_{i}, B_{i}, C_{i} \\leq 10^{5}\n\nB_{i} \\neq C_{i}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_{1} A_{2} \\cdots A_{N}\nQ\nB_{1} C_{1}\nB_{2} C_{2}\n\\vdots\nB_{Q} C_{Q}\n\nOutput\n\nPrint Q integers S_{i} to Standard Output in the following format:\n\nS_{1}\nS_{2}\n\\vdots\nS_{Q}\n\nNote that S_{i} may not fit into a 32-bit integer.\n\nSample Input 1\n\n4\n1 2 3 4\n3\n1 2\n3 4\n2 4\n\nSample Output 1\n\n11\n12\n16\n\nInitially, the sequence A is 1,2,3,4.\n\nAfter each operation, it becomes the following:\n\n2, 2, 3, 4\n\n2, 2, 4, 4\n\n4, 4, 4, 4\n\nSample Input 2\n\n4\n1 1 1 1\n3\n1 2\n2 1\n3 5\n\nSample Output 2\n\n8\n4\n4\n\nNote that the sequence A may not contain an element whose value is B_{i}.\n\nSample Input 3\n\n2\n1 2\n3\n1 100\n2 100\n100 1000\n\nSample Output 3\n\n102\n200\n2000", "sample_input": "4\n1 2 3 4\n3\n1 2\n3 4\n2 4\n"}, "reference_outputs": ["11\n12\n16\n"], "source_document_id": "p02630", "source_text": "Score : 400 points\n\nProblem Statement\n\nYou have a sequence A composed of N positive integers: A_{1}, A_{2}, \\cdots, A_{N}.\n\nYou will now successively do the following Q operations:\n\nIn the i-th operation, you replace every element whose value is B_{i} with C_{i}.\n\nFor each i (1 \\leq i \\leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N, Q, A_{i}, B_{i}, C_{i} \\leq 10^{5}\n\nB_{i} \\neq C_{i}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_{1} A_{2} \\cdots A_{N}\nQ\nB_{1} C_{1}\nB_{2} C_{2}\n\\vdots\nB_{Q} C_{Q}\n\nOutput\n\nPrint Q integers S_{i} to Standard Output in the following format:\n\nS_{1}\nS_{2}\n\\vdots\nS_{Q}\n\nNote that S_{i} may not fit into a 32-bit integer.\n\nSample Input 1\n\n4\n1 2 3 4\n3\n1 2\n3 4\n2 4\n\nSample Output 1\n\n11\n12\n16\n\nInitially, the sequence A is 1,2,3,4.\n\nAfter each operation, it becomes the following:\n\n2, 2, 3, 4\n\n2, 2, 4, 4\n\n4, 4, 4, 4\n\nSample Input 2\n\n4\n1 1 1 1\n3\n1 2\n2 1\n3 5\n\nSample Output 2\n\n8\n4\n4\n\nNote that the sequence A may not contain an element whose value is B_{i}.\n\nSample Input 3\n\n2\n1 2\n3\n1 100\n2 100\n100 1000\n\nSample Output 3\n\n102\n200\n2000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 450, "cpu_time_ms": 466, "memory_kb": 77824}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s728365263", "group_id": "codeNet:p02630", "input_text": "(let* ((n (read))\n (a (make-array '(100001) :initial-element 0))\n (s 0)\n (q 0))\n ;; read\n (loop :for _ :from 1 :to n\n :do (let ((i (read)))\n (incf s i)\n (incf (aref a i))))\n (setf q (read))\n ;;\n (loop :for i :from 1 :to q\n :do (let ((b (read))\n (c (read)))\n (incf (aref a c) (aref a b))\n (incf s (* (aref a b) (- c b)))\n (format t \"~A~%\" s)\n (setf (aref a b) 0))))\n", "language": "Lisp", "metadata": {"date": 1592791627, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02630.html", "problem_id": "p02630", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02630/input.txt", "sample_output_relpath": "derived/input_output/data/p02630/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02630/Lisp/s728365263.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s728365263", "user_id": "u608227593"}, "prompt_components": {"gold_output": "11\n12\n16\n", "input_to_evaluate": "(let* ((n (read))\n (a (make-array '(100001) :initial-element 0))\n (s 0)\n (q 0))\n ;; read\n (loop :for _ :from 1 :to n\n :do (let ((i (read)))\n (incf s i)\n (incf (aref a i))))\n (setf q (read))\n ;;\n (loop :for i :from 1 :to q\n :do (let ((b (read))\n (c (read)))\n (incf (aref a c) (aref a b))\n (incf s (* (aref a b) (- c b)))\n (format t \"~A~%\" s)\n (setf (aref a b) 0))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYou have a sequence A composed of N positive integers: A_{1}, A_{2}, \\cdots, A_{N}.\n\nYou will now successively do the following Q operations:\n\nIn the i-th operation, you replace every element whose value is B_{i} with C_{i}.\n\nFor each i (1 \\leq i \\leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N, Q, A_{i}, B_{i}, C_{i} \\leq 10^{5}\n\nB_{i} \\neq C_{i}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_{1} A_{2} \\cdots A_{N}\nQ\nB_{1} C_{1}\nB_{2} C_{2}\n\\vdots\nB_{Q} C_{Q}\n\nOutput\n\nPrint Q integers S_{i} to Standard Output in the following format:\n\nS_{1}\nS_{2}\n\\vdots\nS_{Q}\n\nNote that S_{i} may not fit into a 32-bit integer.\n\nSample Input 1\n\n4\n1 2 3 4\n3\n1 2\n3 4\n2 4\n\nSample Output 1\n\n11\n12\n16\n\nInitially, the sequence A is 1,2,3,4.\n\nAfter each operation, it becomes the following:\n\n2, 2, 3, 4\n\n2, 2, 4, 4\n\n4, 4, 4, 4\n\nSample Input 2\n\n4\n1 1 1 1\n3\n1 2\n2 1\n3 5\n\nSample Output 2\n\n8\n4\n4\n\nNote that the sequence A may not contain an element whose value is B_{i}.\n\nSample Input 3\n\n2\n1 2\n3\n1 100\n2 100\n100 1000\n\nSample Output 3\n\n102\n200\n2000", "sample_input": "4\n1 2 3 4\n3\n1 2\n3 4\n2 4\n"}, "reference_outputs": ["11\n12\n16\n"], "source_document_id": "p02630", "source_text": "Score : 400 points\n\nProblem Statement\n\nYou have a sequence A composed of N positive integers: A_{1}, A_{2}, \\cdots, A_{N}.\n\nYou will now successively do the following Q operations:\n\nIn the i-th operation, you replace every element whose value is B_{i} with C_{i}.\n\nFor each i (1 \\leq i \\leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N, Q, A_{i}, B_{i}, C_{i} \\leq 10^{5}\n\nB_{i} \\neq C_{i}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_{1} A_{2} \\cdots A_{N}\nQ\nB_{1} C_{1}\nB_{2} C_{2}\n\\vdots\nB_{Q} C_{Q}\n\nOutput\n\nPrint Q integers S_{i} to Standard Output in the following format:\n\nS_{1}\nS_{2}\n\\vdots\nS_{Q}\n\nNote that S_{i} may not fit into a 32-bit integer.\n\nSample Input 1\n\n4\n1 2 3 4\n3\n1 2\n3 4\n2 4\n\nSample Output 1\n\n11\n12\n16\n\nInitially, the sequence A is 1,2,3,4.\n\nAfter each operation, it becomes the following:\n\n2, 2, 3, 4\n\n2, 2, 4, 4\n\n4, 4, 4, 4\n\nSample Input 2\n\n4\n1 1 1 1\n3\n1 2\n2 1\n3 5\n\nSample Output 2\n\n8\n4\n4\n\nNote that the sequence A may not contain an element whose value is B_{i}.\n\nSample Input 3\n\n2\n1 2\n3\n1 100\n2 100\n100 1000\n\nSample Output 3\n\n102\n200\n2000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 497, "cpu_time_ms": 481, "memory_kb": 77852}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s466700739", "group_id": "codeNet:p02640", "input_text": "(defun main ()\n (let ((x (read))\n (y (read))\n (ans \"No\"))\n (if (and (<= 0 (/ (- y (* 2 x)) 2)) (<= 0 (- x (/ (- y (* 2 x)) 2))))\n (setf ans \"Yes\"))\n (format t \"~a~%\" ans)))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1592184895, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02640.html", "problem_id": "p02640", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02640/input.txt", "sample_output_relpath": "derived/input_output/data/p02640/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02640/Lisp/s466700739.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s466700739", "user_id": "u091381267"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun main ()\n (let ((x (read))\n (y (read))\n (ans \"No\"))\n (if (and (<= 0 (/ (- y (* 2 x)) 2)) (<= 0 (- x (/ (- y (* 2 x)) 2))))\n (setf ans \"Yes\"))\n (format t \"~a~%\" ans)))\n\n(main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs.\n\nTakahashi says: \"there are X animals in total in the garden, and they have Y legs in total.\" Determine whether there is a combination of numbers of cranes and turtles in which this statement is correct.\n\nConstraints\n\n1 \\leq X \\leq 100\n\n1 \\leq Y \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nIf there is a combination of numbers of cranes and turtles in which the statement is correct, print Yes; otherwise, print No.\n\nSample Input 1\n\n3 8\n\nSample Output 1\n\nYes\n\nThe statement \"there are 3 animals in total in the garden, and they have 8 legs in total\" is correct if there are two cranes and one turtle. Thus, there is a combination of numbers of cranes and turtles in which the statement is correct.\n\nSample Input 2\n\n2 100\n\nSample Output 2\n\nNo\n\nThere is no combination of numbers of cranes and turtles in which this statement is correct.\n\nSample Input 3\n\n1 2\n\nSample Output 3\n\nYes\n\nWe also consider the case in which there are only cranes or only turtles.", "sample_input": "3 8\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02640", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs.\n\nTakahashi says: \"there are X animals in total in the garden, and they have Y legs in total.\" Determine whether there is a combination of numbers of cranes and turtles in which this statement is correct.\n\nConstraints\n\n1 \\leq X \\leq 100\n\n1 \\leq Y \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nIf there is a combination of numbers of cranes and turtles in which the statement is correct, print Yes; otherwise, print No.\n\nSample Input 1\n\n3 8\n\nSample Output 1\n\nYes\n\nThe statement \"there are 3 animals in total in the garden, and they have 8 legs in total\" is correct if there are two cranes and one turtle. Thus, there is a combination of numbers of cranes and turtles in which the statement is correct.\n\nSample Input 2\n\n2 100\n\nSample Output 2\n\nNo\n\nThere is no combination of numbers of cranes and turtles in which this statement is correct.\n\nSample Input 3\n\n1 2\n\nSample Output 3\n\nYes\n\nWe also consider the case in which there are only cranes or only turtles.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 209, "cpu_time_ms": 16, "memory_kb": 23536}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s178512188", "group_id": "codeNet:p02640", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((x (read))\n (y (read)))\n (loop for crane from 0 to x\n for turtle = (- x crane)\n when (= (+ (* 2 crane) (* 4 turtle)) y)\n do (write-line \"Yes\")\n (return-from main))\n (write-line \"No\")))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 8\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 100\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 2\n\"\n \"Yes\n\")))\n", "language": "Lisp", "metadata": {"date": 1592182971, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02640.html", "problem_id": "p02640", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02640/input.txt", "sample_output_relpath": "derived/input_output/data/p02640/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02640/Lisp/s178512188.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s178512188", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((x (read))\n (y (read)))\n (loop for crane from 0 to x\n for turtle = (- x crane)\n when (= (+ (* 2 crane) (* 4 turtle)) y)\n do (write-line \"Yes\")\n (return-from main))\n (write-line \"No\")))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 8\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 100\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 2\n\"\n \"Yes\n\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs.\n\nTakahashi says: \"there are X animals in total in the garden, and they have Y legs in total.\" Determine whether there is a combination of numbers of cranes and turtles in which this statement is correct.\n\nConstraints\n\n1 \\leq X \\leq 100\n\n1 \\leq Y \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nIf there is a combination of numbers of cranes and turtles in which the statement is correct, print Yes; otherwise, print No.\n\nSample Input 1\n\n3 8\n\nSample Output 1\n\nYes\n\nThe statement \"there are 3 animals in total in the garden, and they have 8 legs in total\" is correct if there are two cranes and one turtle. Thus, there is a combination of numbers of cranes and turtles in which the statement is correct.\n\nSample Input 2\n\n2 100\n\nSample Output 2\n\nNo\n\nThere is no combination of numbers of cranes and turtles in which this statement is correct.\n\nSample Input 3\n\n1 2\n\nSample Output 3\n\nYes\n\nWe also consider the case in which there are only cranes or only turtles.", "sample_input": "3 8\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02640", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs.\n\nTakahashi says: \"there are X animals in total in the garden, and they have Y legs in total.\" Determine whether there is a combination of numbers of cranes and turtles in which this statement is correct.\n\nConstraints\n\n1 \\leq X \\leq 100\n\n1 \\leq Y \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nIf there is a combination of numbers of cranes and turtles in which the statement is correct, print Yes; otherwise, print No.\n\nSample Input 1\n\n3 8\n\nSample Output 1\n\nYes\n\nThe statement \"there are 3 animals in total in the garden, and they have 8 legs in total\" is correct if there are two cranes and one turtle. Thus, there is a combination of numbers of cranes and turtles in which the statement is correct.\n\nSample Input 2\n\n2 100\n\nSample Output 2\n\nNo\n\nThere is no combination of numbers of cranes and turtles in which this statement is correct.\n\nSample Input 3\n\n1 2\n\nSample Output 3\n\nYes\n\nWe also consider the case in which there are only cranes or only turtles.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3793, "cpu_time_ms": 17, "memory_kb": 23976}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s210963695", "group_id": "codeNet:p02641", "input_text": "(defun split-and-parse-integer (string)\n (loop for i = 0 then (1+ j)\n as j = (position #\\Space string :start i)\n collect (parse-integer (subseq string i j))\n while j))\n(defparameter x (read))\n(defparameter n (read))\n(if (not (= n 0))\n(defparameter lst (split-and-parse-integer (read-line)))\n(defparameter lst nil)\n )\n(defparameter ans x)\n(defparameter tmp 100)\n\n(loop for i below 100\n do (if (and lst (not (find i lst)) (> tmp (abs (- x i))))\n (progn (setf ans i)\n (setf tmp (abs (- x i))) )\n )\n )\n\n(princ ans)", "language": "Lisp", "metadata": {"date": 1592260750, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02641.html", "problem_id": "p02641", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02641/input.txt", "sample_output_relpath": "derived/input_output/data/p02641/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02641/Lisp/s210963695.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s210963695", "user_id": "u765865533"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(defun split-and-parse-integer (string)\n (loop for i = 0 then (1+ j)\n as j = (position #\\Space string :start i)\n collect (parse-integer (subseq string i j))\n while j))\n(defparameter x (read))\n(defparameter n (read))\n(if (not (= n 0))\n(defparameter lst (split-and-parse-integer (read-line)))\n(defparameter lst nil)\n )\n(defparameter ans x)\n(defparameter tmp 100)\n\n(loop for i below 100\n do (if (and lst (not (find i lst)) (> tmp (abs (- x i))))\n (progn (setf ans i)\n (setf tmp (abs (- x i))) )\n )\n )\n\n(princ ans)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven are an integer X and an integer sequence of length N: p_1, \\ldots, p_N.\n\nAmong the integers not contained in the sequence p_1, \\ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.\n\nConstraints\n\n1 \\leq X \\leq 100\n\n0 \\leq N \\leq 100\n\n1 \\leq p_i \\leq 100\n\np_1, \\ldots, p_N are all distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX N\np_1 ... p_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n6 5\n4 7 10 6 5\n\nSample Output 1\n\n8\n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.\n\nSample Input 2\n\n10 5\n4 7 10 6 5\n\nSample Output 2\n\n9\n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.\n\nSample Input 3\n\n100 0\n\nSample Output 3\n\n100\n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.", "sample_input": "6 5\n4 7 10 6 5\n"}, "reference_outputs": ["8\n"], "source_document_id": "p02641", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven are an integer X and an integer sequence of length N: p_1, \\ldots, p_N.\n\nAmong the integers not contained in the sequence p_1, \\ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.\n\nConstraints\n\n1 \\leq X \\leq 100\n\n0 \\leq N \\leq 100\n\n1 \\leq p_i \\leq 100\n\np_1, \\ldots, p_N are all distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX N\np_1 ... p_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n6 5\n4 7 10 6 5\n\nSample Output 1\n\n8\n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.\n\nSample Input 2\n\n10 5\n4 7 10 6 5\n\nSample Output 2\n\n9\n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.\n\nSample Input 3\n\n100 0\n\nSample Output 3\n\n100\n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 562, "cpu_time_ms": 15, "memory_kb": 24632}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s958099582", "group_id": "codeNet:p02641", "input_text": "(defun main(x n)\n (let ((a (make-array n :initial-element 0))\n (b 0)\n (ans T))\n\n (if (= n 0)\n (setq b x))\n \n (dotimes (i n)\n (setf (aref a i) (read))\n )\n\n (dotimes (i n)\n (if (= x (aref a i))\n (setf ans Nil))\n )\n (if (not (eq ans Nil))\n (setq b x)\n (setf ans T)\n )\n\n (if (= b 0)\n (loop named main-loop for i from 1 to 101\n do (progn \n (if (and (< 0 (- x i)) (eq ans T))\n (progn\n (setq b (- x i))\n (dotimes (j n)\n (if (= (- x i) (aref a j))\n (setf ans Nil)))\n (if (equal ans T)\n (return-from main-loop)\n (setf ans T))\n )\n )\n )\n (if (and (> 101 (+ x i)) (eq ans T))\n (progn\n (setq b (+ x i))\n (dotimes (j n)\n (if (= (+ x i) (aref a j))\n (setf ans Nil)))\n (if (equal ans T)\n (return-from main-loop)\n (setf ans T))\n )\n )\n\n )\n )\n b)\n\n)\n(format t \"~D~%\" (main (read) (read)))", "language": "Lisp", "metadata": {"date": 1592238100, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02641.html", "problem_id": "p02641", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02641/input.txt", "sample_output_relpath": "derived/input_output/data/p02641/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02641/Lisp/s958099582.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s958099582", "user_id": "u136500538"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(defun main(x n)\n (let ((a (make-array n :initial-element 0))\n (b 0)\n (ans T))\n\n (if (= n 0)\n (setq b x))\n \n (dotimes (i n)\n (setf (aref a i) (read))\n )\n\n (dotimes (i n)\n (if (= x (aref a i))\n (setf ans Nil))\n )\n (if (not (eq ans Nil))\n (setq b x)\n (setf ans T)\n )\n\n (if (= b 0)\n (loop named main-loop for i from 1 to 101\n do (progn \n (if (and (< 0 (- x i)) (eq ans T))\n (progn\n (setq b (- x i))\n (dotimes (j n)\n (if (= (- x i) (aref a j))\n (setf ans Nil)))\n (if (equal ans T)\n (return-from main-loop)\n (setf ans T))\n )\n )\n )\n (if (and (> 101 (+ x i)) (eq ans T))\n (progn\n (setq b (+ x i))\n (dotimes (j n)\n (if (= (+ x i) (aref a j))\n (setf ans Nil)))\n (if (equal ans T)\n (return-from main-loop)\n (setf ans T))\n )\n )\n\n )\n )\n b)\n\n)\n(format t \"~D~%\" (main (read) (read)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven are an integer X and an integer sequence of length N: p_1, \\ldots, p_N.\n\nAmong the integers not contained in the sequence p_1, \\ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.\n\nConstraints\n\n1 \\leq X \\leq 100\n\n0 \\leq N \\leq 100\n\n1 \\leq p_i \\leq 100\n\np_1, \\ldots, p_N are all distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX N\np_1 ... p_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n6 5\n4 7 10 6 5\n\nSample Output 1\n\n8\n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.\n\nSample Input 2\n\n10 5\n4 7 10 6 5\n\nSample Output 2\n\n9\n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.\n\nSample Input 3\n\n100 0\n\nSample Output 3\n\n100\n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.", "sample_input": "6 5\n4 7 10 6 5\n"}, "reference_outputs": ["8\n"], "source_document_id": "p02641", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven are an integer X and an integer sequence of length N: p_1, \\ldots, p_N.\n\nAmong the integers not contained in the sequence p_1, \\ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.\n\nConstraints\n\n1 \\leq X \\leq 100\n\n0 \\leq N \\leq 100\n\n1 \\leq p_i \\leq 100\n\np_1, \\ldots, p_N are all distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX N\np_1 ... p_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n6 5\n4 7 10 6 5\n\nSample Output 1\n\n8\n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.\n\nSample Input 2\n\n10 5\n4 7 10 6 5\n\nSample Output 2\n\n9\n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.\n\nSample Input 3\n\n100 0\n\nSample Output 3\n\n100\n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1418, "cpu_time_ms": 15, "memory_kb": 24464}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s017610870", "group_id": "codeNet:p02641", "input_text": "(defun main ()\n (let ((x (read))\n (n (read))\n (p)\n (ans))\n (dotimes (i n)\n (push (read) p))\n (setf ans (do ((i x (1- i))\n (j x (1+ j)))\n ((or (not (member i p)) (not (member j p))) (list i j))))\n (if (member (first ans) p)\n (second ans)\n (first ans))))\n \n\n\n\n(format t \"~a~%\" (main))\n", "language": "Lisp", "metadata": {"date": 1592188637, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02641.html", "problem_id": "p02641", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02641/input.txt", "sample_output_relpath": "derived/input_output/data/p02641/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02641/Lisp/s017610870.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s017610870", "user_id": "u091381267"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(defun main ()\n (let ((x (read))\n (n (read))\n (p)\n (ans))\n (dotimes (i n)\n (push (read) p))\n (setf ans (do ((i x (1- i))\n (j x (1+ j)))\n ((or (not (member i p)) (not (member j p))) (list i j))))\n (if (member (first ans) p)\n (second ans)\n (first ans))))\n \n\n\n\n(format t \"~a~%\" (main))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven are an integer X and an integer sequence of length N: p_1, \\ldots, p_N.\n\nAmong the integers not contained in the sequence p_1, \\ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.\n\nConstraints\n\n1 \\leq X \\leq 100\n\n0 \\leq N \\leq 100\n\n1 \\leq p_i \\leq 100\n\np_1, \\ldots, p_N are all distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX N\np_1 ... p_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n6 5\n4 7 10 6 5\n\nSample Output 1\n\n8\n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.\n\nSample Input 2\n\n10 5\n4 7 10 6 5\n\nSample Output 2\n\n9\n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.\n\nSample Input 3\n\n100 0\n\nSample Output 3\n\n100\n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.", "sample_input": "6 5\n4 7 10 6 5\n"}, "reference_outputs": ["8\n"], "source_document_id": "p02641", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven are an integer X and an integer sequence of length N: p_1, \\ldots, p_N.\n\nAmong the integers not contained in the sequence p_1, \\ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.\n\nConstraints\n\n1 \\leq X \\leq 100\n\n0 \\leq N \\leq 100\n\n1 \\leq p_i \\leq 100\n\np_1, \\ldots, p_N are all distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX N\np_1 ... p_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n6 5\n4 7 10 6 5\n\nSample Output 1\n\n8\n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.\n\nSample Input 2\n\n10 5\n4 7 10 6 5\n\nSample Output 2\n\n9\n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.\n\nSample Input 3\n\n100 0\n\nSample Output 3\n\n100\n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 371, "cpu_time_ms": 18, "memory_kb": 24340}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s045529767", "group_id": "codeNet:p02641", "input_text": "(defun split-and-parse-integer (string)\n (loop for i = 0 then (1+ j)\n as j = (position #\\Space string :start i)\n collect (parse-integer (subseq string i j))\n while j))\n(defparameter x (read))\n(defparameter n (read))\n(defparameter lst (split-and-parse-integer (read-line)))\n(defparameter ans 1)\n(defparameter tmp 100)\n\n(loop for i below 100\n do (if (and (not (find i lst)) (> tmp (abs (- x i))))\n (progn (setf ans i)\n (setf tmp (abs (- x i))) )\n )\n )\n\n(princ ans)", "language": "Lisp", "metadata": {"date": 1592188486, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02641.html", "problem_id": "p02641", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02641/input.txt", "sample_output_relpath": "derived/input_output/data/p02641/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02641/Lisp/s045529767.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s045529767", "user_id": "u765865533"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(defun split-and-parse-integer (string)\n (loop for i = 0 then (1+ j)\n as j = (position #\\Space string :start i)\n collect (parse-integer (subseq string i j))\n while j))\n(defparameter x (read))\n(defparameter n (read))\n(defparameter lst (split-and-parse-integer (read-line)))\n(defparameter ans 1)\n(defparameter tmp 100)\n\n(loop for i below 100\n do (if (and (not (find i lst)) (> tmp (abs (- x i))))\n (progn (setf ans i)\n (setf tmp (abs (- x i))) )\n )\n )\n\n(princ ans)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven are an integer X and an integer sequence of length N: p_1, \\ldots, p_N.\n\nAmong the integers not contained in the sequence p_1, \\ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.\n\nConstraints\n\n1 \\leq X \\leq 100\n\n0 \\leq N \\leq 100\n\n1 \\leq p_i \\leq 100\n\np_1, \\ldots, p_N are all distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX N\np_1 ... p_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n6 5\n4 7 10 6 5\n\nSample Output 1\n\n8\n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.\n\nSample Input 2\n\n10 5\n4 7 10 6 5\n\nSample Output 2\n\n9\n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.\n\nSample Input 3\n\n100 0\n\nSample Output 3\n\n100\n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.", "sample_input": "6 5\n4 7 10 6 5\n"}, "reference_outputs": ["8\n"], "source_document_id": "p02641", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven are an integer X and an integer sequence of length N: p_1, \\ldots, p_N.\n\nAmong the integers not contained in the sequence p_1, \\ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.\n\nConstraints\n\n1 \\leq X \\leq 100\n\n0 \\leq N \\leq 100\n\n1 \\leq p_i \\leq 100\n\np_1, \\ldots, p_N are all distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX N\np_1 ... p_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n6 5\n4 7 10 6 5\n\nSample Output 1\n\n8\n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.\n\nSample Input 2\n\n10 5\n4 7 10 6 5\n\nSample Output 2\n\n9\n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.\n\nSample Input 3\n\n100 0\n\nSample Output 3\n\n100\n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 514, "cpu_time_ms": 111, "memory_kb": 26804}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s995486267", "group_id": "codeNet:p02644", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Queue with singly linked list\n;;;\n\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type list))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Removes and returns the element at the front of QUEUE. Returns NIL if QUEUE\nis empty.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline queue-peek))\n(defun queue-peek (queue)\n (car (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(declaim (inline read-schar))\n(defun read-schar (&optional (stream *standard-input*))\n (declare #-swank (sb-kernel:ansi-stream stream)\n (inline read-byte))\n #+swank (read-char stream nil #\\Newline) ; on SLIME\n #-swank (code-char (read-byte stream nil #.(char-code #\\Newline))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #xffffffff)\n\n(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (k (read))\n (start-x (- (read) 1))\n (start-y (- (read) 1))\n (goal-x (- (read) 1))\n (goal-y (- (read) 1))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0))\n ;; 既に〇〇進んだ\n (marked (make-array (list h w 4) :element-type 'int32 :initial-element -1))\n (dists (make-array (list h w) :element-type 'uint32 :initial-element +inf+))\n ;; x . y\n (que (make-queue)))\n (declare (uint31 h w k))\n (dotimes (i h)\n (dotimes (j w (read-schar))\n (ecase (read-schar)\n (#\\@ (setf (aref plan i j) 1))\n (#\\.))))\n (enqueue (cons start-x start-y) que)\n ;; up:0, down:1, left:2, right:3\n (setf (aref dists start-x start-y) 0)\n (setf (aref marked start-x start-y 0) k\n (aref marked start-x start-y 1) k\n (aref marked start-x start-y 2) k\n (aref marked start-x start-y 3) k)\n (loop until (queue-empty-p que)\n for (x . y) of-type (uint31 . uint31) = (dequeue que)\n for dist = (aref dists x y)\n do ;; up\n ;; #>marked\n (setf (aref marked x y 0) k\n (aref marked x y 1) k\n (aref marked x y 2) k\n (aref marked x y 3) k)\n (loop for delta from 1 to k\n for new-x = (- x delta)\n while (and (>= new-x 0)\n ;; あとk-deltaだけ進めるが、既にそれ以上に進んでいたら打ち切れる\n (>= (- k delta) (aref marked new-x y 0))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 0) (- k delta))\n when (< (+ dist 1) (aref dists new-x y))\n do (setf (aref dists new-x y) (+ dist 1))\n (enqueue (cons new-x y) que))\n ;; down\n (loop for delta from 1 to k\n for new-x = (+ x delta)\n while (and (< new-x h)\n (>= (- k delta) (aref marked new-x y 1))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 1) (- k delta))\n when (< (+ dist 1) (aref dists new-x y))\n do (setf (aref dists new-x y) (+ dist 1))\n (enqueue (cons new-x y) que))\n ;; left\n (loop for delta from 1 to k\n for new-y = (- y delta)\n while (and (>= new-y 0)\n (>= (- k delta) (aref marked x new-y 2))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 2) (- k delta))\n when (< (+ dist 1) (aref dists x new-y))\n do (setf (aref dists x new-y) (+ dist 1))\n (enqueue (cons x new-y) que))\n ;; right\n (loop for delta from 1 to k\n for new-y = (+ y delta)\n while (and (< new-y w)\n (>= (- k delta) (aref marked x new-y 3))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 3) (- k delta))\n when (< (+ dist 1) (aref dists x new-y))\n do (setf (aref dists x new-y) (+ dist 1))\n (enqueue (cons x new-y) que)))\n (let ((res (aref dists goal-x goal-y)))\n (println\n (if (= res +inf+)\n -1\n res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 5 2\n3 2 3 4\n.....\n.@..@\n..@..\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 6 4\n1 1 1 6\n......\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3 1\n2 1 2 3\n.@.\n.@.\n.@.\n\"\n \"-1\n\")))\n", "language": "Lisp", "metadata": {"date": 1592188471, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02644.html", "problem_id": "p02644", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02644/input.txt", "sample_output_relpath": "derived/input_output/data/p02644/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02644/Lisp/s995486267.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s995486267", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Queue with singly linked list\n;;;\n\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type list))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Removes and returns the element at the front of QUEUE. Returns NIL if QUEUE\nis empty.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline queue-peek))\n(defun queue-peek (queue)\n (car (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(declaim (inline read-schar))\n(defun read-schar (&optional (stream *standard-input*))\n (declare #-swank (sb-kernel:ansi-stream stream)\n (inline read-byte))\n #+swank (read-char stream nil #\\Newline) ; on SLIME\n #-swank (code-char (read-byte stream nil #.(char-code #\\Newline))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #xffffffff)\n\n(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (k (read))\n (start-x (- (read) 1))\n (start-y (- (read) 1))\n (goal-x (- (read) 1))\n (goal-y (- (read) 1))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0))\n ;; 既に〇〇進んだ\n (marked (make-array (list h w 4) :element-type 'int32 :initial-element -1))\n (dists (make-array (list h w) :element-type 'uint32 :initial-element +inf+))\n ;; x . y\n (que (make-queue)))\n (declare (uint31 h w k))\n (dotimes (i h)\n (dotimes (j w (read-schar))\n (ecase (read-schar)\n (#\\@ (setf (aref plan i j) 1))\n (#\\.))))\n (enqueue (cons start-x start-y) que)\n ;; up:0, down:1, left:2, right:3\n (setf (aref dists start-x start-y) 0)\n (setf (aref marked start-x start-y 0) k\n (aref marked start-x start-y 1) k\n (aref marked start-x start-y 2) k\n (aref marked start-x start-y 3) k)\n (loop until (queue-empty-p que)\n for (x . y) of-type (uint31 . uint31) = (dequeue que)\n for dist = (aref dists x y)\n do ;; up\n ;; #>marked\n (setf (aref marked x y 0) k\n (aref marked x y 1) k\n (aref marked x y 2) k\n (aref marked x y 3) k)\n (loop for delta from 1 to k\n for new-x = (- x delta)\n while (and (>= new-x 0)\n ;; あとk-deltaだけ進めるが、既にそれ以上に進んでいたら打ち切れる\n (>= (- k delta) (aref marked new-x y 0))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 0) (- k delta))\n when (< (+ dist 1) (aref dists new-x y))\n do (setf (aref dists new-x y) (+ dist 1))\n (enqueue (cons new-x y) que))\n ;; down\n (loop for delta from 1 to k\n for new-x = (+ x delta)\n while (and (< new-x h)\n (>= (- k delta) (aref marked new-x y 1))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 1) (- k delta))\n when (< (+ dist 1) (aref dists new-x y))\n do (setf (aref dists new-x y) (+ dist 1))\n (enqueue (cons new-x y) que))\n ;; left\n (loop for delta from 1 to k\n for new-y = (- y delta)\n while (and (>= new-y 0)\n (>= (- k delta) (aref marked x new-y 2))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 2) (- k delta))\n when (< (+ dist 1) (aref dists x new-y))\n do (setf (aref dists x new-y) (+ dist 1))\n (enqueue (cons x new-y) que))\n ;; right\n (loop for delta from 1 to k\n for new-y = (+ y delta)\n while (and (< new-y w)\n (>= (- k delta) (aref marked x new-y 3))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 3) (- k delta))\n when (< (+ dist 1) (aref dists x new-y))\n do (setf (aref dists x new-y) (+ dist 1))\n (enqueue (cons x new-y) que)))\n (let ((res (aref dists goal-x goal-y)))\n (println\n (if (= res +inf+)\n -1\n res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 5 2\n3 2 3 4\n.....\n.@..@\n..@..\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 6 4\n1 1 1 6\n......\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3 1\n2 1 2 3\n.@.\n.@.\n.@.\n\"\n \"-1\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nSnuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.\n\nSome of the squares have a lotus leaf on it and cannot be entered.\nThe square (i,j) has a lotus leaf on it if c_{ij} is @, and it does not if c_{ij} is ..\n\nIn one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west.\nThe move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.\n\nFind the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2).\nIf the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.\n\nConstraints\n\n1 \\leq H,W,K \\leq 10^6\n\nH \\times W \\leq 10^6\n\n1 \\leq x_1,x_2 \\leq H\n\n1 \\leq y_1,y_2 \\leq W\n\nx_1 \\neq x_2 or y_1 \\neq y_2.\n\nc_{i,j} is . or @.\n\nc_{x_1,y_1} = .\n\nc_{x_2,y_2} = .\n\nAll numbers in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W K\nx_1 y_1 x_2 y_2\nc_{1,1}c_{1,2} .. c_{1,W}\nc_{2,1}c_{2,2} .. c_{2,W}\n:\nc_{H,1}c_{H,2} .. c_{H,W}\n\nOutput\n\nPrint the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print -1 if the travel is impossible.\n\nSample Input 1\n\n3 5 2\n3 2 3 4\n.....\n.@..@\n..@..\n\nSample Output 1\n\n5\n\nInitially, Snuke is at the square (3,2).\nHe can reach the square (3, 4) by making five strokes as follows:\n\nFrom (3, 2), go west one square to (3, 1).\n\nFrom (3, 1), go north two squares to (1, 1).\n\nFrom (1, 1), go east two squares to (1, 3).\n\nFrom (1, 3), go east one square to (1, 4).\n\nFrom (1, 4), go south two squares to (3, 4).\n\nSample Input 2\n\n1 6 4\n1 1 1 6\n......\n\nSample Output 2\n\n2\n\nSample Input 3\n\n3 3 1\n2 1 2 3\n.@.\n.@.\n.@.\n\nSample Output 3\n\n-1", "sample_input": "3 5 2\n3 2 3 4\n.....\n.@..@\n..@..\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02644", "source_text": "Score : 600 points\n\nProblem Statement\n\nSnuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.\n\nSome of the squares have a lotus leaf on it and cannot be entered.\nThe square (i,j) has a lotus leaf on it if c_{ij} is @, and it does not if c_{ij} is ..\n\nIn one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west.\nThe move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.\n\nFind the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2).\nIf the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.\n\nConstraints\n\n1 \\leq H,W,K \\leq 10^6\n\nH \\times W \\leq 10^6\n\n1 \\leq x_1,x_2 \\leq H\n\n1 \\leq y_1,y_2 \\leq W\n\nx_1 \\neq x_2 or y_1 \\neq y_2.\n\nc_{i,j} is . or @.\n\nc_{x_1,y_1} = .\n\nc_{x_2,y_2} = .\n\nAll numbers in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W K\nx_1 y_1 x_2 y_2\nc_{1,1}c_{1,2} .. c_{1,W}\nc_{2,1}c_{2,2} .. c_{2,W}\n:\nc_{H,1}c_{H,2} .. c_{H,W}\n\nOutput\n\nPrint the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print -1 if the travel is impossible.\n\nSample Input 1\n\n3 5 2\n3 2 3 4\n.....\n.@..@\n..@..\n\nSample Output 1\n\n5\n\nInitially, Snuke is at the square (3,2).\nHe can reach the square (3, 4) by making five strokes as follows:\n\nFrom (3, 2), go west one square to (3, 1).\n\nFrom (3, 1), go north two squares to (1, 1).\n\nFrom (1, 1), go east two squares to (1, 3).\n\nFrom (1, 3), go east one square to (1, 4).\n\nFrom (1, 4), go south two squares to (3, 4).\n\nSample Input 2\n\n1 6 4\n1 1 1 6\n......\n\nSample Output 2\n\n2\n\nSample Input 3\n\n3 3 1\n2 1 2 3\n.@.\n.@.\n.@.\n\nSample Output 3\n\n-1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8756, "cpu_time_ms": 3310, "memory_kb": 68496}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s587590251", "group_id": "codeNet:p02644", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Queue with singly linked list\n;;;\n\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type list))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Removes and returns the element at the front of QUEUE. Returns NIL if QUEUE\nis empty.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline queue-peek))\n(defun queue-peek (queue)\n (car (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(declaim (inline read-schar))\n(defun read-schar (&optional (stream *standard-input*))\n (declare #-swank (sb-kernel:ansi-stream stream)\n (inline read-byte))\n #+swank (read-char stream nil #\\Newline) ; on SLIME\n #-swank (code-char (read-byte stream nil #.(char-code #\\Newline))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #xffffffff)\n\n(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (k (read))\n (start-x (- (read) 1))\n (start-y (- (read) 1))\n (goal-x (- (read) 1))\n (goal-y (- (read) 1))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0))\n ;; 既に〇〇進んだ\n (marked (make-array (list h w 4) :element-type 'int32 :initial-element -1))\n (dists (make-array (list h w) :element-type 'uint32 :initial-element +inf+))\n ;; x . y\n (que (make-queue)))\n (declare (uint31 h w k))\n (dotimes (i h)\n (dotimes (j w (read-schar))\n (ecase (read-schar)\n (#\\@ (setf (aref plan i j) 1))\n (#\\.))))\n (enqueue (cons start-x start-y) que)\n ;; up:0, down:1, left:2, right:3\n (setf (aref dists start-x start-y) 0)\n (setf (aref marked start-x start-y 0) k\n (aref marked start-x start-y 1) k\n (aref marked start-x start-y 2) k\n (aref marked start-x start-y 3) k)\n (loop until (queue-empty-p que)\n for (x . y) of-type (uint31 . uint31) = (dequeue que)\n for dist = (aref dists x y)\n do ;; up\n ;; #>marked\n (setf (aref marked x y 0) k\n (aref marked x y 1) k\n (aref marked x y 2) k\n (aref marked x y 3) k)\n (loop for delta from 1 to k\n for new-x = (- x delta)\n while (and (>= new-x 0)\n ;; あとk-deltaだけ進めるが、既にそれ以上に進んでいたら打ち切れる\n (> (- k delta) (aref marked new-x y 0))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 0) (- k delta))\n when (< (+ dist 1) (aref dists new-x y))\n do (setf (aref dists new-x y) (+ dist 1))\n (enqueue (cons new-x y) que))\n ;; down\n (loop for delta from 1 to k\n for new-x = (+ x delta)\n while (and (< new-x h)\n (> (- k delta) (aref marked new-x y 1))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 1) (- k delta))\n when (< (+ dist 1) (aref dists new-x y))\n do (setf (aref dists new-x y) (+ dist 1))\n (enqueue (cons new-x y) que))\n ;; left\n (loop for delta from 1 to k\n for new-y = (- y delta)\n while (and (>= new-y 0)\n (> (- k delta) (aref marked x new-y 2))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 2) (- k delta))\n when (< (+ dist 1) (aref dists x new-y))\n do (setf (aref dists x new-y) (+ dist 1))\n (enqueue (cons x new-y) que))\n ;; right\n (loop for delta from 1 to k\n for new-y = (+ y delta)\n while (and (< new-y w)\n (> (- k delta) (aref marked x new-y 3))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 3) (- k delta))\n when (< (+ dist 1) (aref dists x new-y))\n do (setf (aref dists x new-y) (+ dist 1))\n (enqueue (cons x new-y) que)))\n (let ((res (aref dists goal-x goal-y)))\n (println\n (if (= res +inf+)\n -1\n res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 5 2\n3 2 3 4\n.....\n.@..@\n..@..\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 6 4\n1 1 1 6\n......\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3 1\n2 1 2 3\n.@.\n.@.\n.@.\n\"\n \"-1\n\")))\n", "language": "Lisp", "metadata": {"date": 1592188343, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02644.html", "problem_id": "p02644", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02644/input.txt", "sample_output_relpath": "derived/input_output/data/p02644/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02644/Lisp/s587590251.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s587590251", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Queue with singly linked list\n;;;\n\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type list))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Removes and returns the element at the front of QUEUE. Returns NIL if QUEUE\nis empty.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline queue-peek))\n(defun queue-peek (queue)\n (car (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(declaim (inline read-schar))\n(defun read-schar (&optional (stream *standard-input*))\n (declare #-swank (sb-kernel:ansi-stream stream)\n (inline read-byte))\n #+swank (read-char stream nil #\\Newline) ; on SLIME\n #-swank (code-char (read-byte stream nil #.(char-code #\\Newline))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #xffffffff)\n\n(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (k (read))\n (start-x (- (read) 1))\n (start-y (- (read) 1))\n (goal-x (- (read) 1))\n (goal-y (- (read) 1))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0))\n ;; 既に〇〇進んだ\n (marked (make-array (list h w 4) :element-type 'int32 :initial-element -1))\n (dists (make-array (list h w) :element-type 'uint32 :initial-element +inf+))\n ;; x . y\n (que (make-queue)))\n (declare (uint31 h w k))\n (dotimes (i h)\n (dotimes (j w (read-schar))\n (ecase (read-schar)\n (#\\@ (setf (aref plan i j) 1))\n (#\\.))))\n (enqueue (cons start-x start-y) que)\n ;; up:0, down:1, left:2, right:3\n (setf (aref dists start-x start-y) 0)\n (setf (aref marked start-x start-y 0) k\n (aref marked start-x start-y 1) k\n (aref marked start-x start-y 2) k\n (aref marked start-x start-y 3) k)\n (loop until (queue-empty-p que)\n for (x . y) of-type (uint31 . uint31) = (dequeue que)\n for dist = (aref dists x y)\n do ;; up\n ;; #>marked\n (setf (aref marked x y 0) k\n (aref marked x y 1) k\n (aref marked x y 2) k\n (aref marked x y 3) k)\n (loop for delta from 1 to k\n for new-x = (- x delta)\n while (and (>= new-x 0)\n ;; あとk-deltaだけ進めるが、既にそれ以上に進んでいたら打ち切れる\n (> (- k delta) (aref marked new-x y 0))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 0) (- k delta))\n when (< (+ dist 1) (aref dists new-x y))\n do (setf (aref dists new-x y) (+ dist 1))\n (enqueue (cons new-x y) que))\n ;; down\n (loop for delta from 1 to k\n for new-x = (+ x delta)\n while (and (< new-x h)\n (> (- k delta) (aref marked new-x y 1))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 1) (- k delta))\n when (< (+ dist 1) (aref dists new-x y))\n do (setf (aref dists new-x y) (+ dist 1))\n (enqueue (cons new-x y) que))\n ;; left\n (loop for delta from 1 to k\n for new-y = (- y delta)\n while (and (>= new-y 0)\n (> (- k delta) (aref marked x new-y 2))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 2) (- k delta))\n when (< (+ dist 1) (aref dists x new-y))\n do (setf (aref dists x new-y) (+ dist 1))\n (enqueue (cons x new-y) que))\n ;; right\n (loop for delta from 1 to k\n for new-y = (+ y delta)\n while (and (< new-y w)\n (> (- k delta) (aref marked x new-y 3))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 3) (- k delta))\n when (< (+ dist 1) (aref dists x new-y))\n do (setf (aref dists x new-y) (+ dist 1))\n (enqueue (cons x new-y) que)))\n (let ((res (aref dists goal-x goal-y)))\n (println\n (if (= res +inf+)\n -1\n res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 5 2\n3 2 3 4\n.....\n.@..@\n..@..\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 6 4\n1 1 1 6\n......\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3 1\n2 1 2 3\n.@.\n.@.\n.@.\n\"\n \"-1\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nSnuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.\n\nSome of the squares have a lotus leaf on it and cannot be entered.\nThe square (i,j) has a lotus leaf on it if c_{ij} is @, and it does not if c_{ij} is ..\n\nIn one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west.\nThe move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.\n\nFind the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2).\nIf the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.\n\nConstraints\n\n1 \\leq H,W,K \\leq 10^6\n\nH \\times W \\leq 10^6\n\n1 \\leq x_1,x_2 \\leq H\n\n1 \\leq y_1,y_2 \\leq W\n\nx_1 \\neq x_2 or y_1 \\neq y_2.\n\nc_{i,j} is . or @.\n\nc_{x_1,y_1} = .\n\nc_{x_2,y_2} = .\n\nAll numbers in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W K\nx_1 y_1 x_2 y_2\nc_{1,1}c_{1,2} .. c_{1,W}\nc_{2,1}c_{2,2} .. c_{2,W}\n:\nc_{H,1}c_{H,2} .. c_{H,W}\n\nOutput\n\nPrint the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print -1 if the travel is impossible.\n\nSample Input 1\n\n3 5 2\n3 2 3 4\n.....\n.@..@\n..@..\n\nSample Output 1\n\n5\n\nInitially, Snuke is at the square (3,2).\nHe can reach the square (3, 4) by making five strokes as follows:\n\nFrom (3, 2), go west one square to (3, 1).\n\nFrom (3, 1), go north two squares to (1, 1).\n\nFrom (1, 1), go east two squares to (1, 3).\n\nFrom (1, 3), go east one square to (1, 4).\n\nFrom (1, 4), go south two squares to (3, 4).\n\nSample Input 2\n\n1 6 4\n1 1 1 6\n......\n\nSample Output 2\n\n2\n\nSample Input 3\n\n3 3 1\n2 1 2 3\n.@.\n.@.\n.@.\n\nSample Output 3\n\n-1", "sample_input": "3 5 2\n3 2 3 4\n.....\n.@..@\n..@..\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02644", "source_text": "Score : 600 points\n\nProblem Statement\n\nSnuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.\n\nSome of the squares have a lotus leaf on it and cannot be entered.\nThe square (i,j) has a lotus leaf on it if c_{ij} is @, and it does not if c_{ij} is ..\n\nIn one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west.\nThe move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.\n\nFind the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2).\nIf the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.\n\nConstraints\n\n1 \\leq H,W,K \\leq 10^6\n\nH \\times W \\leq 10^6\n\n1 \\leq x_1,x_2 \\leq H\n\n1 \\leq y_1,y_2 \\leq W\n\nx_1 \\neq x_2 or y_1 \\neq y_2.\n\nc_{i,j} is . or @.\n\nc_{x_1,y_1} = .\n\nc_{x_2,y_2} = .\n\nAll numbers in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W K\nx_1 y_1 x_2 y_2\nc_{1,1}c_{1,2} .. c_{1,W}\nc_{2,1}c_{2,2} .. c_{2,W}\n:\nc_{H,1}c_{H,2} .. c_{H,W}\n\nOutput\n\nPrint the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print -1 if the travel is impossible.\n\nSample Input 1\n\n3 5 2\n3 2 3 4\n.....\n.@..@\n..@..\n\nSample Output 1\n\n5\n\nInitially, Snuke is at the square (3,2).\nHe can reach the square (3, 4) by making five strokes as follows:\n\nFrom (3, 2), go west one square to (3, 1).\n\nFrom (3, 1), go north two squares to (1, 1).\n\nFrom (1, 1), go east two squares to (1, 3).\n\nFrom (1, 3), go east one square to (1, 4).\n\nFrom (1, 4), go south two squares to (3, 4).\n\nSample Input 2\n\n1 6 4\n1 1 1 6\n......\n\nSample Output 2\n\n2\n\nSample Input 3\n\n3 3 1\n2 1 2 3\n.@.\n.@.\n.@.\n\nSample Output 3\n\n-1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8752, "cpu_time_ms": 3310, "memory_kb": 68516}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s651191507", "group_id": "codeNet:p02645", "input_text": "(princ (subseq (read-line) 0 3))\n", "language": "Lisp", "metadata": {"date": 1593308672, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02645.html", "problem_id": "p02645", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02645/input.txt", "sample_output_relpath": "derived/input_output/data/p02645/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02645/Lisp/s651191507.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s651191507", "user_id": "u526532903"}, "prompt_components": {"gold_output": "tak\n", "input_to_evaluate": "(princ (subseq (read-line) 0 3))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWhen you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters.\nYou have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.\n\nConstraints\n\n3 \\leq |S| \\leq 20\n\nS consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint your answer.\n\nSample Input 1\n\ntakahashi\n\nSample Output 1\n\ntak\n\nSample Input 2\n\nnaohiro\n\nSample Output 2\n\nnao", "sample_input": "takahashi\n"}, "reference_outputs": ["tak\n"], "source_document_id": "p02645", "source_text": "Score : 100 points\n\nProblem Statement\n\nWhen you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters.\nYou have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.\n\nConstraints\n\n3 \\leq |S| \\leq 20\n\nS consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint your answer.\n\nSample Input 1\n\ntakahashi\n\nSample Output 1\n\ntak\n\nSample Input 2\n\nnaohiro\n\nSample Output 2\n\nnao", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 33, "cpu_time_ms": 18, "memory_kb": 24292}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s144791292", "group_id": "codeNet:p02645", "input_text": "(defun main ()\n (let ((s (read-line)))\n (format t \"~a~%\" (subseq s 0 3))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1592096773, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02645.html", "problem_id": "p02645", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02645/input.txt", "sample_output_relpath": "derived/input_output/data/p02645/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02645/Lisp/s144791292.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s144791292", "user_id": "u091381267"}, "prompt_components": {"gold_output": "tak\n", "input_to_evaluate": "(defun main ()\n (let ((s (read-line)))\n (format t \"~a~%\" (subseq s 0 3))))\n\n(main)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWhen you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters.\nYou have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.\n\nConstraints\n\n3 \\leq |S| \\leq 20\n\nS consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint your answer.\n\nSample Input 1\n\ntakahashi\n\nSample Output 1\n\ntak\n\nSample Input 2\n\nnaohiro\n\nSample Output 2\n\nnao", "sample_input": "takahashi\n"}, "reference_outputs": ["tak\n"], "source_document_id": "p02645", "source_text": "Score : 100 points\n\nProblem Statement\n\nWhen you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters.\nYou have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.\n\nConstraints\n\n3 \\leq |S| \\leq 20\n\nS consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint your answer.\n\nSample Input 1\n\ntakahashi\n\nSample Output 1\n\ntak\n\nSample Input 2\n\nnaohiro\n\nSample Output 2\n\nnao", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 87, "cpu_time_ms": 14, "memory_kb": 24396}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s478503249", "group_id": "codeNet:p02647", "input_text": "(defun Lamps (n k)\n (let* ((readLamps (make-array n ))\n (dousyutuLamps (make-array `(,(1+ n)) :initial-element 0))\n (stop t)\n )\n \n (dotimes (i n) \n (setf (aref readLamps i) (read)))\n \n (loop named main-loop\n for _ below k\n do (progn \n (loop for i below n\n do (let ((l (max 0 (- i (aref readLamps i))))\n (r (min (- n 1) (+ i (aref readLamps i)))))\n (incf (aref dousyutuLamps l))\n (if (<= (1+ r) n)\n (decf (aref dousyutuLamps (1+ r)))\n )\n ) \n )\n (loop for i from 1 to n\n do (incf (aref dousyutuLamps i) (aref dousyutuLamps (- i 1)))\n )\n (loop for i below n\n do (progn\n (setf stop (and stop (= (aref dousyutuLamps i) n)))\n (setf (aref readLamps i) (aref dousyutuLamps i))\n (setf (aref dousyutuLamps i) 0)\n )\n ) \n \n (if stop\n (return-from main-loop))\n )\n )\n (loop for i below (- n 1)\n do(format t \"~A \"(aref readLamps i))\n )\n (format t \"~A~%\" (aref readLamps (- n 1))))\n \n)\n(Lamps (read) (read))", "language": "Lisp", "metadata": {"date": 1592162590, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02647.html", "problem_id": "p02647", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02647/input.txt", "sample_output_relpath": "derived/input_output/data/p02647/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02647/Lisp/s478503249.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s478503249", "user_id": "u136500538"}, "prompt_components": {"gold_output": "1 2 2 1 2\n", "input_to_evaluate": "(defun Lamps (n k)\n (let* ((readLamps (make-array n ))\n (dousyutuLamps (make-array `(,(1+ n)) :initial-element 0))\n (stop t)\n )\n \n (dotimes (i n) \n (setf (aref readLamps i) (read)))\n \n (loop named main-loop\n for _ below k\n do (progn \n (loop for i below n\n do (let ((l (max 0 (- i (aref readLamps i))))\n (r (min (- n 1) (+ i (aref readLamps i)))))\n (incf (aref dousyutuLamps l))\n (if (<= (1+ r) n)\n (decf (aref dousyutuLamps (1+ r)))\n )\n ) \n )\n (loop for i from 1 to n\n do (incf (aref dousyutuLamps i) (aref dousyutuLamps (- i 1)))\n )\n (loop for i below n\n do (progn\n (setf stop (and stop (= (aref dousyutuLamps i) n)))\n (setf (aref readLamps i) (aref dousyutuLamps i))\n (setf (aref dousyutuLamps i) 0)\n )\n ) \n \n (if stop\n (return-from main-loop))\n )\n )\n (loop for i below (- n 1)\n do(format t \"~A \"(aref readLamps i))\n )\n (format t \"~A~%\" (aref readLamps (- n 1))))\n \n)\n(Lamps (read) (read))", "problem_context": "Score : 500 points\n\nProblem Statement\n\nWe have N bulbs arranged on a number line, numbered 1 to N from left to right.\nBulb i is at coordinate i.\n\nEach bulb has a non-negative integer parameter called intensity.\nWhen there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5.\nInitially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row:\n\nFor each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i.\n\nFind the intensity of each bulb after the K operations.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq K \\leq 2 \\times 10^5\n\n0 \\leq A_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 \\ldots A_N\n\nOutput\n\nPrint the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:\n\nA{'}_1 A{'}_2 \\ldots A{'}_N\n\nSample Input 1\n\n5 1\n1 0 0 1 0\n\nSample Output 1\n\n1 2 2 1 2\n\nInitially, only Bulb 1 illuminates coordinate 1, so the intensity of Bulb 1 becomes 1 after the operation.\nSimilarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2, so the intensity of Bulb 2 becomes 2.\n\nSample Input 2\n\n5 2\n1 0 0 1 0\n\nSample Output 2\n\n3 3 4 4 3", "sample_input": "5 1\n1 0 0 1 0\n"}, "reference_outputs": ["1 2 2 1 2\n"], "source_document_id": "p02647", "source_text": "Score : 500 points\n\nProblem Statement\n\nWe have N bulbs arranged on a number line, numbered 1 to N from left to right.\nBulb i is at coordinate i.\n\nEach bulb has a non-negative integer parameter called intensity.\nWhen there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5.\nInitially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row:\n\nFor each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i.\n\nFind the intensity of each bulb after the K operations.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq K \\leq 2 \\times 10^5\n\n0 \\leq A_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 \\ldots A_N\n\nOutput\n\nPrint the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:\n\nA{'}_1 A{'}_2 \\ldots A{'}_N\n\nSample Input 1\n\n5 1\n1 0 0 1 0\n\nSample Output 1\n\n1 2 2 1 2\n\nInitially, only Bulb 1 illuminates coordinate 1, so the intensity of Bulb 1 becomes 1 after the operation.\nSimilarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2, so the intensity of Bulb 2 becomes 2.\n\nSample Input 2\n\n5 2\n1 0 0 1 0\n\nSample Output 2\n\n3 3 4 4 3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1340, "cpu_time_ms": 2207, "memory_kb": 80136}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s461089359", "group_id": "codeNet:p02647", "input_text": "(defun Lamps (n k)\n (let* ((readLamps (make-array n ))\n (dousyutuLamps (make-array (+ n 1) :initial-element 0))\n (ans \"\")\n (stop t)\n )\n\n (dotimes (i n) \n (setf (aref readLamps i) (read)))\n\n (loop :named main-loop\n :for _ :from 1 :to k\n :do (progn \n (dotimes (j n)\n (let ((l (max 0 (- j (aref readLamps j))))\n (r (min (- n 1) (+ j (aref readLamps j)))))\n (incf (aref dousyutuLamps l))\n (if (<= (+ 1 r) n)\n (decf (aref dousyutuLamps (+ 1 r)))\n )\n ) \n )\n (loop for j from 1 to n\n do (incf (aref dousyutuLamps j) (aref dousyutuLamps (- j 1)))\n )\n (dotimes (j n)\n (setf stop (and stop (= (aref dousyutuLamps j) n)))\n (setf (aref readLamps j) (aref dousyutuLamps j))\n (setf (aref dousyutuLamps j) 0)\n ) \n \n (if stop\n (return-from main-loop)\n )\n )\n )\n\n (dotimes (j n)\n (setf ans (concatenate 'string ans (write-to-string (aref readLamps j))) )\n (if (< j n)\n (setf ans (concatenate 'string ans \" \"))\n )\n )\n ans)\n \n)\n(format t \"~A~%\" (Lamps (read) (read)))", "language": "Lisp", "metadata": {"date": 1592159418, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02647.html", "problem_id": "p02647", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02647/input.txt", "sample_output_relpath": "derived/input_output/data/p02647/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02647/Lisp/s461089359.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s461089359", "user_id": "u136500538"}, "prompt_components": {"gold_output": "1 2 2 1 2\n", "input_to_evaluate": "(defun Lamps (n k)\n (let* ((readLamps (make-array n ))\n (dousyutuLamps (make-array (+ n 1) :initial-element 0))\n (ans \"\")\n (stop t)\n )\n\n (dotimes (i n) \n (setf (aref readLamps i) (read)))\n\n (loop :named main-loop\n :for _ :from 1 :to k\n :do (progn \n (dotimes (j n)\n (let ((l (max 0 (- j (aref readLamps j))))\n (r (min (- n 1) (+ j (aref readLamps j)))))\n (incf (aref dousyutuLamps l))\n (if (<= (+ 1 r) n)\n (decf (aref dousyutuLamps (+ 1 r)))\n )\n ) \n )\n (loop for j from 1 to n\n do (incf (aref dousyutuLamps j) (aref dousyutuLamps (- j 1)))\n )\n (dotimes (j n)\n (setf stop (and stop (= (aref dousyutuLamps j) n)))\n (setf (aref readLamps j) (aref dousyutuLamps j))\n (setf (aref dousyutuLamps j) 0)\n ) \n \n (if stop\n (return-from main-loop)\n )\n )\n )\n\n (dotimes (j n)\n (setf ans (concatenate 'string ans (write-to-string (aref readLamps j))) )\n (if (< j n)\n (setf ans (concatenate 'string ans \" \"))\n )\n )\n ans)\n \n)\n(format t \"~A~%\" (Lamps (read) (read)))", "problem_context": "Score : 500 points\n\nProblem Statement\n\nWe have N bulbs arranged on a number line, numbered 1 to N from left to right.\nBulb i is at coordinate i.\n\nEach bulb has a non-negative integer parameter called intensity.\nWhen there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5.\nInitially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row:\n\nFor each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i.\n\nFind the intensity of each bulb after the K operations.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq K \\leq 2 \\times 10^5\n\n0 \\leq A_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 \\ldots A_N\n\nOutput\n\nPrint the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:\n\nA{'}_1 A{'}_2 \\ldots A{'}_N\n\nSample Input 1\n\n5 1\n1 0 0 1 0\n\nSample Output 1\n\n1 2 2 1 2\n\nInitially, only Bulb 1 illuminates coordinate 1, so the intensity of Bulb 1 becomes 1 after the operation.\nSimilarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2, so the intensity of Bulb 2 becomes 2.\n\nSample Input 2\n\n5 2\n1 0 0 1 0\n\nSample Output 2\n\n3 3 4 4 3", "sample_input": "5 1\n1 0 0 1 0\n"}, "reference_outputs": ["1 2 2 1 2\n"], "source_document_id": "p02647", "source_text": "Score : 500 points\n\nProblem Statement\n\nWe have N bulbs arranged on a number line, numbered 1 to N from left to right.\nBulb i is at coordinate i.\n\nEach bulb has a non-negative integer parameter called intensity.\nWhen there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5.\nInitially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row:\n\nFor each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i.\n\nFind the intensity of each bulb after the K operations.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq K \\leq 2 \\times 10^5\n\n0 \\leq A_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 \\ldots A_N\n\nOutput\n\nPrint the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:\n\nA{'}_1 A{'}_2 \\ldots A{'}_N\n\nSample Input 1\n\n5 1\n1 0 0 1 0\n\nSample Output 1\n\n1 2 2 1 2\n\nInitially, only Bulb 1 illuminates coordinate 1, so the intensity of Bulb 1 becomes 1 after the operation.\nSimilarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2, so the intensity of Bulb 2 becomes 2.\n\nSample Input 2\n\n5 2\n1 0 0 1 0\n\nSample Output 2\n\n3 3 4 4 3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1423, "cpu_time_ms": 2208, "memory_kb": 107416}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s221662261", "group_id": "codeNet:p02647", "input_text": "(defun main ()\n (let* ((n (read))\n (k (read))\n (b (make-array `(,(1+ n)) :initial-element 0))\n (a (make-array `(,(1+ n)) :initial-element 0))\n (stop t))\n (when (<= (1- n) k)\n (loop :for i :from 1 :to (1- n)\n :do (format t \"~A \" n))\n (format t \"~A~%\" n)\n (return-from main))\n ;; read \n (loop :for i :from 1 :to n\n :do (setf (aref a i) (read)))\n ;;\n (loop :named main-loop\n :for _ :from 1 :to k\n :do (progn \n (loop :for x :from 1 :to n\n :do (let ((d (aref a x)))\n (loop :for i :from (max 1 (- x d)) :to (min n (+ x d))\n :do (incf (aref b i)))))\n (loop :for i :from 1 :to n\n :do (setf stop (and stop (= (aref a i) (aref b i))))\n :do (setf (aref a i) (aref b i))\n :do (setf (aref b i) 0))\n (if stop \n (return-from main-loop)\n (setf stop t))))\n ;;\n (when (> n 1)\n (loop :for i :from 1 :to (1- n)\n :do (format t \"~A \" (aref a i))))\n (format t \"~A~%\" (aref a n))))\n(main)\n\n", "language": "Lisp", "metadata": {"date": 1592100458, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02647.html", "problem_id": "p02647", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02647/input.txt", "sample_output_relpath": "derived/input_output/data/p02647/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02647/Lisp/s221662261.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s221662261", "user_id": "u608227593"}, "prompt_components": {"gold_output": "1 2 2 1 2\n", "input_to_evaluate": "(defun main ()\n (let* ((n (read))\n (k (read))\n (b (make-array `(,(1+ n)) :initial-element 0))\n (a (make-array `(,(1+ n)) :initial-element 0))\n (stop t))\n (when (<= (1- n) k)\n (loop :for i :from 1 :to (1- n)\n :do (format t \"~A \" n))\n (format t \"~A~%\" n)\n (return-from main))\n ;; read \n (loop :for i :from 1 :to n\n :do (setf (aref a i) (read)))\n ;;\n (loop :named main-loop\n :for _ :from 1 :to k\n :do (progn \n (loop :for x :from 1 :to n\n :do (let ((d (aref a x)))\n (loop :for i :from (max 1 (- x d)) :to (min n (+ x d))\n :do (incf (aref b i)))))\n (loop :for i :from 1 :to n\n :do (setf stop (and stop (= (aref a i) (aref b i))))\n :do (setf (aref a i) (aref b i))\n :do (setf (aref b i) 0))\n (if stop \n (return-from main-loop)\n (setf stop t))))\n ;;\n (when (> n 1)\n (loop :for i :from 1 :to (1- n)\n :do (format t \"~A \" (aref a i))))\n (format t \"~A~%\" (aref a n))))\n(main)\n\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nWe have N bulbs arranged on a number line, numbered 1 to N from left to right.\nBulb i is at coordinate i.\n\nEach bulb has a non-negative integer parameter called intensity.\nWhen there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5.\nInitially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row:\n\nFor each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i.\n\nFind the intensity of each bulb after the K operations.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq K \\leq 2 \\times 10^5\n\n0 \\leq A_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 \\ldots A_N\n\nOutput\n\nPrint the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:\n\nA{'}_1 A{'}_2 \\ldots A{'}_N\n\nSample Input 1\n\n5 1\n1 0 0 1 0\n\nSample Output 1\n\n1 2 2 1 2\n\nInitially, only Bulb 1 illuminates coordinate 1, so the intensity of Bulb 1 becomes 1 after the operation.\nSimilarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2, so the intensity of Bulb 2 becomes 2.\n\nSample Input 2\n\n5 2\n1 0 0 1 0\n\nSample Output 2\n\n3 3 4 4 3", "sample_input": "5 1\n1 0 0 1 0\n"}, "reference_outputs": ["1 2 2 1 2\n"], "source_document_id": "p02647", "source_text": "Score : 500 points\n\nProblem Statement\n\nWe have N bulbs arranged on a number line, numbered 1 to N from left to right.\nBulb i is at coordinate i.\n\nEach bulb has a non-negative integer parameter called intensity.\nWhen there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5.\nInitially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row:\n\nFor each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i.\n\nFind the intensity of each bulb after the K operations.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq K \\leq 2 \\times 10^5\n\n0 \\leq A_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 \\ldots A_N\n\nOutput\n\nPrint the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:\n\nA{'}_1 A{'}_2 \\ldots A{'}_N\n\nSample Input 1\n\n5 1\n1 0 0 1 0\n\nSample Output 1\n\n1 2 2 1 2\n\nInitially, only Bulb 1 illuminates coordinate 1, so the intensity of Bulb 1 becomes 1 after the operation.\nSimilarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2, so the intensity of Bulb 2 becomes 2.\n\nSample Input 2\n\n5 2\n1 0 0 1 0\n\nSample Output 2\n\n3 3 4 4 3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1219, "cpu_time_ms": 2208, "memory_kb": 80036}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s512916067", "group_id": "codeNet:p02648", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end)\n (declare (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-right (ng ok)\n ;; TARGET[OK] > VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (< value (the fixnum (cdr (,accessor target mid))))\n (%bisect-right ng mid)\n (%bisect-right mid ok))))))\n (assert (<= start end))\n (%bisect-right (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.array-total-size-limit)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (boundary 10)\n (vs (make-array n :element-type 'uint31 :initial-element 0))\n (ws (make-array n :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n boundary))\n (dotimes (i n)\n (setf (aref vs i) (read-fixnum)\n (aref ws i) (read-fixnum)))\n (let* ((q (read))\n (query-store (make-array n :element-type 'list :initial-element nil))\n (res (make-array q :element-type 'fixnum :initial-element 0)))\n (dotimes (i q)\n (let ((v (- (read-fixnum) 1))\n (l (read-fixnum)))\n (push (list v l i) (aref query-store v))))\n (labels ((%merge (half-vs half-ws v w)\n (declare ((simple-array uint31 (*)) half-vs half-ws)\n (uint31 v w))\n (let* ((new-vs (make-array (* 2 (length half-vs)) :element-type 'uint31))\n (new-ws (make-array (* 2 (length half-ws)) :element-type 'uint31))\n (len (length half-vs))\n (pos1 0)\n (pos2 0)\n (end 0)\n (current-w -1)\n (current-v -1))\n (declare ((simple-array uint31 (*)) new-vs new-ws)\n (uint31 pos1 pos2 end)\n (int32 current-w current-v))\n (loop (when (= pos1 len)\n (loop for pos from pos2 below len\n for v2 = (aref half-vs pos)\n for w2 = (aref half-ws pos)\n when (and (> (+ v2 v) current-v)\n (> (+ w2 w) current-w))\n do (setf (aref new-vs end) (+ v2 v)\n (aref new-ws end) (+ w2 w)\n end (+ end 1)\n current-w (+ w2 w)\n current-v (+ v2 v)))\n (return))\n (let ((v1 (aref half-vs pos1))\n (w1 (aref half-ws pos1))\n (v2 (aref half-vs pos2))\n (w2 (aref half-ws pos2)))\n (declare (uint31 v1 v2 w1 w2))\n (cond ((< w1 (+ w2 w))\n (when (and (> w1 current-w)\n (> v1 current-v))\n (setf (aref new-vs end) v1\n (aref new-ws end) w1\n end (+ end 1)\n current-w w1\n current-v v1))\n (incf pos1))\n ((> w1 (+ w2 w))\n (when (and (> (+ w2 w) current-w)\n (> (+ v2 v) current-v))\n (setf (aref new-vs end) (+ v2 v)\n (aref new-ws end) (+ w2 w)\n end (+ end 1)\n current-w (+ w2 w)\n current-v (+ v2 v)))\n (incf pos2))\n ((= w1 (+ w2 w))\n (let ((max-v (max v1 (+ v2 v))))\n (declare (uint31 max-v))\n (when (and (> w1 current-w)\n (> max-v current-v))\n (setf (aref new-vs end) max-v\n (aref new-ws end) w1\n end (+ end 1)\n current-w w1\n current-v max-v))\n (incf pos1)\n (incf pos2)))\n (t (error \"Huh?\")))))\n (values (adjust-array new-vs end)\n (adjust-array new-ws end)))))\n (sb-int:named-let recur ((i 0)\n (depth 0)\n (half-vs1 (make-array 1\n :element-type 'uint31\n :initial-element 0))\n (half-ws1 (make-array 1\n :element-type 'uint31\n :initial-element 0))\n (half-vs2 (make-array 1\n :element-type 'uint31\n :initial-element 0))\n (half-ws2 (make-array 1\n :element-type 'uint31\n :initial-element 0)))\n (declare (uint31 i depth)\n ((simple-array uint31 (*)) half-vs1 half-ws1 half-vs2 half-ws2))\n (when (>= i n) (return-from recur))\n (let ((v (aref vs i))\n (w (aref ws i)))\n (declare (uint31 v w))\n (if (< depth boundary)\n (multiple-value-bind (half-vs1 half-ws1) (%merge half-vs1 half-ws1 v w)\n (declare ((simple-array uint31 (*)) half-vs1 half-ws1))\n (loop for (q-v q-l index) of-type (uint31 uint31 uint31) in (aref query-store i)\n do (setf (aref res index)\n (loop for v across half-vs1\n for w across half-ws1\n while (<= w q-l)\n maximize v)))\n (recur (+ (* i 2) 1) (+ depth 1) half-vs1 half-ws1 half-vs2 half-ws2)\n (recur (+ (* i 2) 2) (+ depth 1) half-vs1 half-ws1 half-vs2 half-ws2))\n (multiple-value-bind (half-vs2 half-ws2) (%merge half-vs2 half-ws2 v w)\n (declare ((simple-array uint31 (*)) half-vs2 half-ws2))\n (loop\n for (q-v q-l index) of-type (uint31 uint31 uint31) in (aref query-store i)\n for max-value of-type uint31 = 0\n for pos2 = (- (length half-vs2) 1)\n do (loop for v1 across half-vs1\n for w1 across half-ws1\n while (<= w1 q-l)\n do (loop for w2 = (aref half-ws2 pos2)\n until (<= (+ w1 w2) q-l)\n do (decf pos2))\n (let ((v2 (aref half-vs2 pos2)))\n (declare (uint31 v2))\n (maxf max-value (+ v1 v2))))\n (setf (aref res index) max-value))\n (recur (+ (* i 2) 1) (+ depth 1)\n half-vs1 half-ws1 half-vs2 half-ws2)\n (recur (+ (* i 2) 2) (+ depth 1)\n half-vs1 half-ws1 half-vs2 half-ws2))))))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (map () #'println res))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (let ((n 262143))\n (format out \"~D~%\" n)\n (dotimes (_ n)\n (format out \"~D ~D~%\" (+ 1 (random 100000)) (+ 1 (random 100000))))\n (println 100000 out)\n (dotimes (_ 100000)\n (format out \"~D ~D~%\" (+ 130000 (random (- n 130000))) (+ 1 (random 100000)))))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n\"\n \"0\n3\n3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"15\n123 119\n129 120\n132 112\n126 109\n118 103\n115 109\n102 100\n130 120\n105 105\n132 115\n104 102\n107 107\n127 116\n121 104\n121 115\n8\n8 234\n9 244\n10 226\n11 227\n12 240\n13 237\n14 206\n15 227\n\"\n \"256\n255\n250\n247\n255\n259\n223\n253\n\")))\n", "language": "Lisp", "metadata": {"date": 1592110152, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02648.html", "problem_id": "p02648", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02648/input.txt", "sample_output_relpath": "derived/input_output/data/p02648/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02648/Lisp/s512916067.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s512916067", "user_id": "u352600849"}, "prompt_components": {"gold_output": "0\n3\n3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end)\n (declare (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-right (ng ok)\n ;; TARGET[OK] > VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (< value (the fixnum (cdr (,accessor target mid))))\n (%bisect-right ng mid)\n (%bisect-right mid ok))))))\n (assert (<= start end))\n (%bisect-right (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.array-total-size-limit)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (boundary 10)\n (vs (make-array n :element-type 'uint31 :initial-element 0))\n (ws (make-array n :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n boundary))\n (dotimes (i n)\n (setf (aref vs i) (read-fixnum)\n (aref ws i) (read-fixnum)))\n (let* ((q (read))\n (query-store (make-array n :element-type 'list :initial-element nil))\n (res (make-array q :element-type 'fixnum :initial-element 0)))\n (dotimes (i q)\n (let ((v (- (read-fixnum) 1))\n (l (read-fixnum)))\n (push (list v l i) (aref query-store v))))\n (labels ((%merge (half-vs half-ws v w)\n (declare ((simple-array uint31 (*)) half-vs half-ws)\n (uint31 v w))\n (let* ((new-vs (make-array (* 2 (length half-vs)) :element-type 'uint31))\n (new-ws (make-array (* 2 (length half-ws)) :element-type 'uint31))\n (len (length half-vs))\n (pos1 0)\n (pos2 0)\n (end 0)\n (current-w -1)\n (current-v -1))\n (declare ((simple-array uint31 (*)) new-vs new-ws)\n (uint31 pos1 pos2 end)\n (int32 current-w current-v))\n (loop (when (= pos1 len)\n (loop for pos from pos2 below len\n for v2 = (aref half-vs pos)\n for w2 = (aref half-ws pos)\n when (and (> (+ v2 v) current-v)\n (> (+ w2 w) current-w))\n do (setf (aref new-vs end) (+ v2 v)\n (aref new-ws end) (+ w2 w)\n end (+ end 1)\n current-w (+ w2 w)\n current-v (+ v2 v)))\n (return))\n (let ((v1 (aref half-vs pos1))\n (w1 (aref half-ws pos1))\n (v2 (aref half-vs pos2))\n (w2 (aref half-ws pos2)))\n (declare (uint31 v1 v2 w1 w2))\n (cond ((< w1 (+ w2 w))\n (when (and (> w1 current-w)\n (> v1 current-v))\n (setf (aref new-vs end) v1\n (aref new-ws end) w1\n end (+ end 1)\n current-w w1\n current-v v1))\n (incf pos1))\n ((> w1 (+ w2 w))\n (when (and (> (+ w2 w) current-w)\n (> (+ v2 v) current-v))\n (setf (aref new-vs end) (+ v2 v)\n (aref new-ws end) (+ w2 w)\n end (+ end 1)\n current-w (+ w2 w)\n current-v (+ v2 v)))\n (incf pos2))\n ((= w1 (+ w2 w))\n (let ((max-v (max v1 (+ v2 v))))\n (declare (uint31 max-v))\n (when (and (> w1 current-w)\n (> max-v current-v))\n (setf (aref new-vs end) max-v\n (aref new-ws end) w1\n end (+ end 1)\n current-w w1\n current-v max-v))\n (incf pos1)\n (incf pos2)))\n (t (error \"Huh?\")))))\n (values (adjust-array new-vs end)\n (adjust-array new-ws end)))))\n (sb-int:named-let recur ((i 0)\n (depth 0)\n (half-vs1 (make-array 1\n :element-type 'uint31\n :initial-element 0))\n (half-ws1 (make-array 1\n :element-type 'uint31\n :initial-element 0))\n (half-vs2 (make-array 1\n :element-type 'uint31\n :initial-element 0))\n (half-ws2 (make-array 1\n :element-type 'uint31\n :initial-element 0)))\n (declare (uint31 i depth)\n ((simple-array uint31 (*)) half-vs1 half-ws1 half-vs2 half-ws2))\n (when (>= i n) (return-from recur))\n (let ((v (aref vs i))\n (w (aref ws i)))\n (declare (uint31 v w))\n (if (< depth boundary)\n (multiple-value-bind (half-vs1 half-ws1) (%merge half-vs1 half-ws1 v w)\n (declare ((simple-array uint31 (*)) half-vs1 half-ws1))\n (loop for (q-v q-l index) of-type (uint31 uint31 uint31) in (aref query-store i)\n do (setf (aref res index)\n (loop for v across half-vs1\n for w across half-ws1\n while (<= w q-l)\n maximize v)))\n (recur (+ (* i 2) 1) (+ depth 1) half-vs1 half-ws1 half-vs2 half-ws2)\n (recur (+ (* i 2) 2) (+ depth 1) half-vs1 half-ws1 half-vs2 half-ws2))\n (multiple-value-bind (half-vs2 half-ws2) (%merge half-vs2 half-ws2 v w)\n (declare ((simple-array uint31 (*)) half-vs2 half-ws2))\n (loop\n for (q-v q-l index) of-type (uint31 uint31 uint31) in (aref query-store i)\n for max-value of-type uint31 = 0\n for pos2 = (- (length half-vs2) 1)\n do (loop for v1 across half-vs1\n for w1 across half-ws1\n while (<= w1 q-l)\n do (loop for w2 = (aref half-ws2 pos2)\n until (<= (+ w1 w2) q-l)\n do (decf pos2))\n (let ((v2 (aref half-vs2 pos2)))\n (declare (uint31 v2))\n (maxf max-value (+ v1 v2))))\n (setf (aref res index) max-value))\n (recur (+ (* i 2) 1) (+ depth 1)\n half-vs1 half-ws1 half-vs2 half-ws2)\n (recur (+ (* i 2) 2) (+ depth 1)\n half-vs1 half-ws1 half-vs2 half-ws2))))))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (map () #'println res))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (let ((n 262143))\n (format out \"~D~%\" n)\n (dotimes (_ n)\n (format out \"~D ~D~%\" (+ 1 (random 100000)) (+ 1 (random 100000))))\n (println 100000 out)\n (dotimes (_ 100000)\n (format out \"~D ~D~%\" (+ 130000 (random (- n 130000))) (+ 1 (random 100000)))))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n\"\n \"0\n3\n3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"15\n123 119\n129 120\n132 112\n126 109\n118 103\n115 109\n102 100\n130 120\n105 105\n132 115\n104 102\n107 107\n127 116\n121 104\n121 115\n8\n8 234\n9 244\n10 226\n11 227\n12 240\n13 237\n14 206\n15 227\n\"\n \"256\n255\n250\n247\n255\n259\n223\n253\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nWe have a rooted binary tree with N vertices, where the vertices are numbered 1 to N.\nVertex 1 is the root, and the parent of Vertex i (i \\geq 2) is Vertex \\left[ \\frac{i}{2} \\right].\n\nEach vertex has one item in it. The item in Vertex i has a value of V_i and a weight of W_i.\nNow, process the following query Q times:\n\nGiven are a vertex v of the tree and a positive integer L.\nLet us choose some (possibly none) of the items in v and the ancestors of v so that their total weight is at most L.\nFind the maximum possible total value of the chosen items.\n\nHere, Vertex u is said to be an ancestor of Vertex v when u is an indirect parent of v, that is, there exists a sequence of vertices w_1,w_2,\\ldots,w_k (k\\geq 2) where w_1=v, w_k=u, and w_{i+1} is the parent of w_i for each i.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N < 2^{18}\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq V_i \\leq 10^5\n\n1 \\leq W_i \\leq 10^5\n\nFor the values v and L given in each query, 1 \\leq v \\leq N and 1 \\leq L \\leq 10^5.\n\nInput\n\nLet v_i and L_i be the values v and L given in the i-th query.\nThen, Input is given from Standard Input in the following format:\n\nN\nV_1 W_1\n:\nV_N W_N\nQ\nv_1 L_1\n:\nv_Q L_Q\n\nOutput\n\nFor each integer i from 1 through Q,\nthe i-th line should contain the response to the i-th query.\n\nSample Input 1\n\n3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n\nSample Output 1\n\n0\n3\n3\n\nIn the first query, we are given only one choice: the item with (V, W)=(1,2). Since L = 1, we cannot actually choose it, so our response should be 0.\n\nIn the second query, we are given two choices: the items with (V, W)=(1,2) and (V, W)=(2,3). Since L = 5, we can choose both of them, so our response should be 3.\n\nSample Input 2\n\n15\n123 119\n129 120\n132 112\n126 109\n118 103\n115 109\n102 100\n130 120\n105 105\n132 115\n104 102\n107 107\n127 116\n121 104\n121 115\n8\n8 234\n9 244\n10 226\n11 227\n12 240\n13 237\n14 206\n15 227\n\nSample Output 2\n\n256\n255\n250\n247\n255\n259\n223\n253", "sample_input": "3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n"}, "reference_outputs": ["0\n3\n3\n"], "source_document_id": "p02648", "source_text": "Score : 700 points\n\nProblem Statement\n\nWe have a rooted binary tree with N vertices, where the vertices are numbered 1 to N.\nVertex 1 is the root, and the parent of Vertex i (i \\geq 2) is Vertex \\left[ \\frac{i}{2} \\right].\n\nEach vertex has one item in it. The item in Vertex i has a value of V_i and a weight of W_i.\nNow, process the following query Q times:\n\nGiven are a vertex v of the tree and a positive integer L.\nLet us choose some (possibly none) of the items in v and the ancestors of v so that their total weight is at most L.\nFind the maximum possible total value of the chosen items.\n\nHere, Vertex u is said to be an ancestor of Vertex v when u is an indirect parent of v, that is, there exists a sequence of vertices w_1,w_2,\\ldots,w_k (k\\geq 2) where w_1=v, w_k=u, and w_{i+1} is the parent of w_i for each i.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N < 2^{18}\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq V_i \\leq 10^5\n\n1 \\leq W_i \\leq 10^5\n\nFor the values v and L given in each query, 1 \\leq v \\leq N and 1 \\leq L \\leq 10^5.\n\nInput\n\nLet v_i and L_i be the values v and L given in the i-th query.\nThen, Input is given from Standard Input in the following format:\n\nN\nV_1 W_1\n:\nV_N W_N\nQ\nv_1 L_1\n:\nv_Q L_Q\n\nOutput\n\nFor each integer i from 1 through Q,\nthe i-th line should contain the response to the i-th query.\n\nSample Input 1\n\n3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n\nSample Output 1\n\n0\n3\n3\n\nIn the first query, we are given only one choice: the item with (V, W)=(1,2). Since L = 1, we cannot actually choose it, so our response should be 0.\n\nIn the second query, we are given two choices: the items with (V, W)=(1,2) and (V, W)=(2,3). Since L = 5, we can choose both of them, so our response should be 3.\n\nSample Input 2\n\n15\n123 119\n129 120\n132 112\n126 109\n118 103\n115 109\n102 100\n130 120\n105 105\n132 115\n104 102\n107 107\n127 116\n121 104\n121 115\n8\n8 234\n9 244\n10 226\n11 227\n12 240\n13 237\n14 206\n15 227\n\nSample Output 2\n\n256\n255\n250\n247\n255\n259\n223\n253", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 14085, "cpu_time_ms": 1083, "memory_kb": 91320}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s337029410", "group_id": "codeNet:p02648", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Quicksort (randomized median-of-three partitioning)\n;;;\n\n;; TODO: Consider worst case of deterministic partitioning\n;; Reference:\n;; Hannu Erkio, The worst case permutation for median-of-three quicksort\n\n(declaim (inline %median3))\n(defun %median3 (x y z order)\n (if (funcall order x y)\n (if (funcall order y z)\n y\n (if (funcall order z x)\n x\n z))\n (if (funcall order z y)\n y\n (if (funcall order x z)\n x\n z))))\n\n(declaim (inline quicksort!))\n(defun quicksort! (vector order &key (start 0) end)\n \"Destructively sorts VECTOR w.r.t. ORDER.\"\n (declare ((simple-array list (*)) vector))\n (unless end\n (setq end (length vector)))\n (assert (<= 0 start end))\n (labels\n ((recur (left right)\n (declare (fixnum left right))\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3 (aref vector l)\n (aref vector (the fixnum (+ l (random (+ 1 (- r l))))))\n (aref vector r)\n order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall order (aref vector l) pivot)\n do (incf l))\n (loop while (funcall order pivot (aref vector r))\n do (decf r))\n (when (>= l r)\n (return))\n (rotatef (aref vector l) (aref vector r))\n (incf l 1)\n (decf r 1))\n (recur left (- l 1))\n (recur (+ r 1) right)))))\n (recur start (- end 1))\n vector))\n\n(declaim (inline quicksort-by2!))\n(defun quicksort-by2! (vector order)\n \"Destructively sorts VECTOR by two elements. This function regards\neach (VECTOR[i], VECTOR[i+1]) for even i as an element, and compares only the\nfirst elements (i.e. VECTOR[i] for even i).\"\n (declare (vector vector))\n (assert (evenp (length vector)))\n (labels\n ((recur (left right)\n (declare (fixnum left right))\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3\n (aref vector l)\n (aref vector (the fixnum (+ l (logandc2 (random (+ 1 (- r l))) 1))))\n (aref vector r)\n order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall order (aref vector l) pivot)\n do (incf l 2))\n (loop while (funcall order pivot (aref vector r))\n do (decf r 2))\n (when (>= l r)\n (return))\n (rotatef (aref vector l) (aref vector r))\n (rotatef (aref vector (+ l 1)) (aref vector (+ r 1)))\n (incf l 2)\n (decf r 2))\n (recur left (- l 2))\n (recur (+ r 2) right)))))\n (recur 0 (- (length vector) 2))\n vector))\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of lower_bound() of C++ or bisect_left() of Python: Returns the\nsmallest index (or input) i that fulfills TARGET[i] >= VALUE, where '>=' is the\ncomplement of ORDER. In other words, this function returns the leftmost index at\nwhich VALUE can be inserted with keeping the order. Therefore, TARGET must be\nmonotonically non-decreasing with respect to ORDER.\n\n- This function returns END if VALUE exceeds TARGET[END-1]. \n- The range [START, END) is half-open.\n- END must be explicitly specified if TARGET is function.\n- KEY is applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-left (ng ok)\n ;; TARGET[OK] >= VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (funcall order (funcall key (,accessor target mid)) value)\n (%bisect-left mid ok)\n (%bisect-left ng mid))))))\n (assert (<= start end))\n (%bisect-left (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.most-positive-fixnum)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n\n\n(declaim (inline log2-ceil))\n(defun log2-ceil (x)\n \"Rounds up log2(x).\"\n (let ((ceil (ceiling x)))\n (declare ((integer 0) ceil))\n (integer-length (- ceil 1))))\n\n(declaim (inline log-ceil))\n(defun log-ceil (x base)\n \"Rounds up log(x).\"\n (declare (real x)\n ((integer 2) base))\n (assert (>= x 0))\n (labels ((%log ()\n (nth-value 0 (ceiling (log x base)))))\n (if (integerp x)\n (let ((y x)\n (result 0))\n (loop (when (zerop y)\n (return result))\n (multiple-value-bind (quot rem) (floor y base)\n (unless (zerop rem)\n (return (%log)))\n (setq y quot)\n (incf result))))\n (%log))))\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end)\n (declare (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-right (ng ok)\n ;; TARGET[OK] > VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (< value (the fixnum (cdr (,accessor target mid))))\n (%bisect-right ng mid)\n (%bisect-right mid ok))))))\n (assert (<= start end))\n (%bisect-right (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.array-total-size-limit)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (boundary 9)\n (vs (make-array n :element-type 'uint31 :initial-element 0))\n (ws (make-array n :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n boundary))\n (dotimes (i n)\n (setf (aref vs i) (read-fixnum)\n (aref ws i) (read-fixnum)))\n (let* ((q (read))\n (query-store (make-array n :element-type 'list :initial-element nil))\n (res (make-array q :element-type 'fixnum :initial-element 0))\n (tree (make-array (* 3 n) :element-type 'bit :initial-element 1)))\n (dotimes (i q)\n (let ((v (- (read-fixnum) 1))\n (l (read-fixnum)))\n (push (list v l i) (aref query-store v))))\n (sb-int:named-let recur ((i 0))\n (declare (uint31 i))\n (if (>= i n)\n nil\n (let ((res1 (recur (+ (* i 2) 1)))\n (res2 (recur (+ (* i 2) 2))))\n (when (or (aref query-store i)\n res1 res2)\n (setf (aref tree i) 1)))))\n (sb-int:named-let recur ((i 0)\n (depth 0)\n (half1 (list (cons 0 0)))\n (half2 (make-array 1\n :element-type 'list\n :initial-element (cons 0 0))))\n (declare (uint31 i depth)\n ((simple-array list (*)) half2))\n (when (>= i n) (return-from recur))\n (let ((v (aref vs i))\n (w (aref ws i)))\n (declare (uint31 v w))\n (if (< depth boundary)\n (let ((new-half1\n (append (loop for (v-sum . w-sum) of-type (uint62 . uint62) in half1\n collect (cons (+ v-sum v) (+ w-sum w)))\n half1)))\n (loop for (q-v q-l index) of-type (uint62 uint62 uint62) in (aref query-store i)\n do (setf (aref res index)\n (loop for (v1 . w1) of-type (uint62 . uint62) in new-half1\n when (<= w1 q-l)\n maximize v1)))\n (recur (+ (* i 2) 1) (+ depth 1) new-half1 half2)\n (recur (+ (* i 2) 2) (+ depth 1) new-half1 half2))\n (let ((new-half2 (make-array (length half2) :element-type 'list)))\n (dotimes (i (length half2))\n (destructuring-bind (v-sum . w-sum) (aref half2 i)\n (declare (uint62 v-sum w-sum))\n (setf (aref new-half2 i)\n (cons (+ v v-sum) (+ w w-sum)))))\n ;; #>new-half2\n (let* ((new-half2 (concatenate '(simple-array list (*))\n half2 new-half2)))\n (declare ((simple-array list (*)) new-half2))\n ;; #>new-half2\n ;; answer query\n ;; 各重みについて最大の価値しかいらない\n (if (aref query-store i)\n (progn\n (quicksort! new-half2\n (lambda (node1 node2)\n (let ((v1 (car node1))\n (w1 (cdr node1))\n (v2 (car node2))\n (w2 (cdr node2)))\n (declare (fixnum v1 w1 v2 w2))\n (or (< w1 w2)\n (and (= w1 w2) (> v1 v2))))))\n (let ((current-v -1)\n (current-pos 0))\n (dotimes (i (length new-half2))\n (destructuring-bind (v . w) (aref new-half2 i)\n (declare (uint62 v w))\n (when (> v current-v)\n (setq current-v v)\n (setf (aref new-half2 current-pos) (aref new-half2 i))\n (incf current-pos))))\n (setq new-half2 (adjust-array new-half2 current-pos))\n (loop for (q-v q-l index) of-type (uint62 uint62 uint62) in (aref query-store i)\n for max-value of-type fixnum = 0\n do (loop for (v1 . w1) of-type (fixnum . fixnum) in half1\n ;; 重さがl-w1以下のものを見つける\n when (<= w1 q-l)\n do (let ((idx (- (bisect-right new-half2\n (- q-l w1))\n 1)))\n (destructuring-bind (v2 . w2) (aref new-half2 idx)\n (declare (fixnum v2 w2))\n (maxf max-value (+ v1 v2)))))\n (setf (aref res index) max-value))\n (when (= 1 (aref tree (+ (* i 2) 1)))\n (recur (+ (* i 2) 1) (+ depth 1) half1 new-half2))\n (when (= 1 (aref tree (+ (* i 2) 2)))\n (recur (+ (* i 2) 2) (+ depth 1) half1 new-half2))))\n (progn\n (when (= 1 (aref tree (+ (* i 2) 1)))\n (recur (+ (* i 2) 1) (+ depth 1) half1 new-half2))\n (when (= 1 (aref tree (+ (* i 2) 2)))\n (recur (+ (* i 2) 2) (+ depth 1) half1 new-half2)))))))))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (map () #'println res))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (let ((n 262143))\n (format out \"~D~%\" n)\n (dotimes (_ n)\n (format out \"~D ~D~%\" (+ 1 (random 100000)) (+ 1 (random 100000))))\n (println 100000 out)\n (dotimes (_ 100000)\n (format out \"~D ~D~%\" (+ 1 (random n)) (+ 1 (random 100000)))))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n\"\n \"0\n3\n3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"15\n123 119\n129 120\n132 112\n126 109\n118 103\n115 109\n102 100\n130 120\n105 105\n132 115\n104 102\n107 107\n127 116\n121 104\n121 115\n8\n8 234\n9 244\n10 226\n11 227\n12 240\n13 237\n14 206\n15 227\n\"\n \"256\n255\n250\n247\n255\n259\n223\n253\n\")))\n", "language": "Lisp", "metadata": {"date": 1592103466, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02648.html", "problem_id": "p02648", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02648/input.txt", "sample_output_relpath": "derived/input_output/data/p02648/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02648/Lisp/s337029410.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s337029410", "user_id": "u352600849"}, "prompt_components": {"gold_output": "0\n3\n3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Quicksort (randomized median-of-three partitioning)\n;;;\n\n;; TODO: Consider worst case of deterministic partitioning\n;; Reference:\n;; Hannu Erkio, The worst case permutation for median-of-three quicksort\n\n(declaim (inline %median3))\n(defun %median3 (x y z order)\n (if (funcall order x y)\n (if (funcall order y z)\n y\n (if (funcall order z x)\n x\n z))\n (if (funcall order z y)\n y\n (if (funcall order x z)\n x\n z))))\n\n(declaim (inline quicksort!))\n(defun quicksort! (vector order &key (start 0) end)\n \"Destructively sorts VECTOR w.r.t. ORDER.\"\n (declare ((simple-array list (*)) vector))\n (unless end\n (setq end (length vector)))\n (assert (<= 0 start end))\n (labels\n ((recur (left right)\n (declare (fixnum left right))\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3 (aref vector l)\n (aref vector (the fixnum (+ l (random (+ 1 (- r l))))))\n (aref vector r)\n order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall order (aref vector l) pivot)\n do (incf l))\n (loop while (funcall order pivot (aref vector r))\n do (decf r))\n (when (>= l r)\n (return))\n (rotatef (aref vector l) (aref vector r))\n (incf l 1)\n (decf r 1))\n (recur left (- l 1))\n (recur (+ r 1) right)))))\n (recur start (- end 1))\n vector))\n\n(declaim (inline quicksort-by2!))\n(defun quicksort-by2! (vector order)\n \"Destructively sorts VECTOR by two elements. This function regards\neach (VECTOR[i], VECTOR[i+1]) for even i as an element, and compares only the\nfirst elements (i.e. VECTOR[i] for even i).\"\n (declare (vector vector))\n (assert (evenp (length vector)))\n (labels\n ((recur (left right)\n (declare (fixnum left right))\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3\n (aref vector l)\n (aref vector (the fixnum (+ l (logandc2 (random (+ 1 (- r l))) 1))))\n (aref vector r)\n order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall order (aref vector l) pivot)\n do (incf l 2))\n (loop while (funcall order pivot (aref vector r))\n do (decf r 2))\n (when (>= l r)\n (return))\n (rotatef (aref vector l) (aref vector r))\n (rotatef (aref vector (+ l 1)) (aref vector (+ r 1)))\n (incf l 2)\n (decf r 2))\n (recur left (- l 2))\n (recur (+ r 2) right)))))\n (recur 0 (- (length vector) 2))\n vector))\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of lower_bound() of C++ or bisect_left() of Python: Returns the\nsmallest index (or input) i that fulfills TARGET[i] >= VALUE, where '>=' is the\ncomplement of ORDER. In other words, this function returns the leftmost index at\nwhich VALUE can be inserted with keeping the order. Therefore, TARGET must be\nmonotonically non-decreasing with respect to ORDER.\n\n- This function returns END if VALUE exceeds TARGET[END-1]. \n- The range [START, END) is half-open.\n- END must be explicitly specified if TARGET is function.\n- KEY is applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-left (ng ok)\n ;; TARGET[OK] >= VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (funcall order (funcall key (,accessor target mid)) value)\n (%bisect-left mid ok)\n (%bisect-left ng mid))))))\n (assert (<= start end))\n (%bisect-left (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.most-positive-fixnum)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n\n\n(declaim (inline log2-ceil))\n(defun log2-ceil (x)\n \"Rounds up log2(x).\"\n (let ((ceil (ceiling x)))\n (declare ((integer 0) ceil))\n (integer-length (- ceil 1))))\n\n(declaim (inline log-ceil))\n(defun log-ceil (x base)\n \"Rounds up log(x).\"\n (declare (real x)\n ((integer 2) base))\n (assert (>= x 0))\n (labels ((%log ()\n (nth-value 0 (ceiling (log x base)))))\n (if (integerp x)\n (let ((y x)\n (result 0))\n (loop (when (zerop y)\n (return result))\n (multiple-value-bind (quot rem) (floor y base)\n (unless (zerop rem)\n (return (%log)))\n (setq y quot)\n (incf result))))\n (%log))))\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end)\n (declare (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-right (ng ok)\n ;; TARGET[OK] > VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (< value (the fixnum (cdr (,accessor target mid))))\n (%bisect-right ng mid)\n (%bisect-right mid ok))))))\n (assert (<= start end))\n (%bisect-right (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.array-total-size-limit)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (boundary 9)\n (vs (make-array n :element-type 'uint31 :initial-element 0))\n (ws (make-array n :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n boundary))\n (dotimes (i n)\n (setf (aref vs i) (read-fixnum)\n (aref ws i) (read-fixnum)))\n (let* ((q (read))\n (query-store (make-array n :element-type 'list :initial-element nil))\n (res (make-array q :element-type 'fixnum :initial-element 0))\n (tree (make-array (* 3 n) :element-type 'bit :initial-element 1)))\n (dotimes (i q)\n (let ((v (- (read-fixnum) 1))\n (l (read-fixnum)))\n (push (list v l i) (aref query-store v))))\n (sb-int:named-let recur ((i 0))\n (declare (uint31 i))\n (if (>= i n)\n nil\n (let ((res1 (recur (+ (* i 2) 1)))\n (res2 (recur (+ (* i 2) 2))))\n (when (or (aref query-store i)\n res1 res2)\n (setf (aref tree i) 1)))))\n (sb-int:named-let recur ((i 0)\n (depth 0)\n (half1 (list (cons 0 0)))\n (half2 (make-array 1\n :element-type 'list\n :initial-element (cons 0 0))))\n (declare (uint31 i depth)\n ((simple-array list (*)) half2))\n (when (>= i n) (return-from recur))\n (let ((v (aref vs i))\n (w (aref ws i)))\n (declare (uint31 v w))\n (if (< depth boundary)\n (let ((new-half1\n (append (loop for (v-sum . w-sum) of-type (uint62 . uint62) in half1\n collect (cons (+ v-sum v) (+ w-sum w)))\n half1)))\n (loop for (q-v q-l index) of-type (uint62 uint62 uint62) in (aref query-store i)\n do (setf (aref res index)\n (loop for (v1 . w1) of-type (uint62 . uint62) in new-half1\n when (<= w1 q-l)\n maximize v1)))\n (recur (+ (* i 2) 1) (+ depth 1) new-half1 half2)\n (recur (+ (* i 2) 2) (+ depth 1) new-half1 half2))\n (let ((new-half2 (make-array (length half2) :element-type 'list)))\n (dotimes (i (length half2))\n (destructuring-bind (v-sum . w-sum) (aref half2 i)\n (declare (uint62 v-sum w-sum))\n (setf (aref new-half2 i)\n (cons (+ v v-sum) (+ w w-sum)))))\n ;; #>new-half2\n (let* ((new-half2 (concatenate '(simple-array list (*))\n half2 new-half2)))\n (declare ((simple-array list (*)) new-half2))\n ;; #>new-half2\n ;; answer query\n ;; 各重みについて最大の価値しかいらない\n (if (aref query-store i)\n (progn\n (quicksort! new-half2\n (lambda (node1 node2)\n (let ((v1 (car node1))\n (w1 (cdr node1))\n (v2 (car node2))\n (w2 (cdr node2)))\n (declare (fixnum v1 w1 v2 w2))\n (or (< w1 w2)\n (and (= w1 w2) (> v1 v2))))))\n (let ((current-v -1)\n (current-pos 0))\n (dotimes (i (length new-half2))\n (destructuring-bind (v . w) (aref new-half2 i)\n (declare (uint62 v w))\n (when (> v current-v)\n (setq current-v v)\n (setf (aref new-half2 current-pos) (aref new-half2 i))\n (incf current-pos))))\n (setq new-half2 (adjust-array new-half2 current-pos))\n (loop for (q-v q-l index) of-type (uint62 uint62 uint62) in (aref query-store i)\n for max-value of-type fixnum = 0\n do (loop for (v1 . w1) of-type (fixnum . fixnum) in half1\n ;; 重さがl-w1以下のものを見つける\n when (<= w1 q-l)\n do (let ((idx (- (bisect-right new-half2\n (- q-l w1))\n 1)))\n (destructuring-bind (v2 . w2) (aref new-half2 idx)\n (declare (fixnum v2 w2))\n (maxf max-value (+ v1 v2)))))\n (setf (aref res index) max-value))\n (when (= 1 (aref tree (+ (* i 2) 1)))\n (recur (+ (* i 2) 1) (+ depth 1) half1 new-half2))\n (when (= 1 (aref tree (+ (* i 2) 2)))\n (recur (+ (* i 2) 2) (+ depth 1) half1 new-half2))))\n (progn\n (when (= 1 (aref tree (+ (* i 2) 1)))\n (recur (+ (* i 2) 1) (+ depth 1) half1 new-half2))\n (when (= 1 (aref tree (+ (* i 2) 2)))\n (recur (+ (* i 2) 2) (+ depth 1) half1 new-half2)))))))))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (map () #'println res))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (let ((n 262143))\n (format out \"~D~%\" n)\n (dotimes (_ n)\n (format out \"~D ~D~%\" (+ 1 (random 100000)) (+ 1 (random 100000))))\n (println 100000 out)\n (dotimes (_ 100000)\n (format out \"~D ~D~%\" (+ 1 (random n)) (+ 1 (random 100000)))))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n\"\n \"0\n3\n3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"15\n123 119\n129 120\n132 112\n126 109\n118 103\n115 109\n102 100\n130 120\n105 105\n132 115\n104 102\n107 107\n127 116\n121 104\n121 115\n8\n8 234\n9 244\n10 226\n11 227\n12 240\n13 237\n14 206\n15 227\n\"\n \"256\n255\n250\n247\n255\n259\n223\n253\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nWe have a rooted binary tree with N vertices, where the vertices are numbered 1 to N.\nVertex 1 is the root, and the parent of Vertex i (i \\geq 2) is Vertex \\left[ \\frac{i}{2} \\right].\n\nEach vertex has one item in it. The item in Vertex i has a value of V_i and a weight of W_i.\nNow, process the following query Q times:\n\nGiven are a vertex v of the tree and a positive integer L.\nLet us choose some (possibly none) of the items in v and the ancestors of v so that their total weight is at most L.\nFind the maximum possible total value of the chosen items.\n\nHere, Vertex u is said to be an ancestor of Vertex v when u is an indirect parent of v, that is, there exists a sequence of vertices w_1,w_2,\\ldots,w_k (k\\geq 2) where w_1=v, w_k=u, and w_{i+1} is the parent of w_i for each i.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N < 2^{18}\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq V_i \\leq 10^5\n\n1 \\leq W_i \\leq 10^5\n\nFor the values v and L given in each query, 1 \\leq v \\leq N and 1 \\leq L \\leq 10^5.\n\nInput\n\nLet v_i and L_i be the values v and L given in the i-th query.\nThen, Input is given from Standard Input in the following format:\n\nN\nV_1 W_1\n:\nV_N W_N\nQ\nv_1 L_1\n:\nv_Q L_Q\n\nOutput\n\nFor each integer i from 1 through Q,\nthe i-th line should contain the response to the i-th query.\n\nSample Input 1\n\n3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n\nSample Output 1\n\n0\n3\n3\n\nIn the first query, we are given only one choice: the item with (V, W)=(1,2). Since L = 1, we cannot actually choose it, so our response should be 0.\n\nIn the second query, we are given two choices: the items with (V, W)=(1,2) and (V, W)=(2,3). Since L = 5, we can choose both of them, so our response should be 3.\n\nSample Input 2\n\n15\n123 119\n129 120\n132 112\n126 109\n118 103\n115 109\n102 100\n130 120\n105 105\n132 115\n104 102\n107 107\n127 116\n121 104\n121 115\n8\n8 234\n9 244\n10 226\n11 227\n12 240\n13 237\n14 206\n15 227\n\nSample Output 2\n\n256\n255\n250\n247\n255\n259\n223\n253", "sample_input": "3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n"}, "reference_outputs": ["0\n3\n3\n"], "source_document_id": "p02648", "source_text": "Score : 700 points\n\nProblem Statement\n\nWe have a rooted binary tree with N vertices, where the vertices are numbered 1 to N.\nVertex 1 is the root, and the parent of Vertex i (i \\geq 2) is Vertex \\left[ \\frac{i}{2} \\right].\n\nEach vertex has one item in it. The item in Vertex i has a value of V_i and a weight of W_i.\nNow, process the following query Q times:\n\nGiven are a vertex v of the tree and a positive integer L.\nLet us choose some (possibly none) of the items in v and the ancestors of v so that their total weight is at most L.\nFind the maximum possible total value of the chosen items.\n\nHere, Vertex u is said to be an ancestor of Vertex v when u is an indirect parent of v, that is, there exists a sequence of vertices w_1,w_2,\\ldots,w_k (k\\geq 2) where w_1=v, w_k=u, and w_{i+1} is the parent of w_i for each i.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N < 2^{18}\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq V_i \\leq 10^5\n\n1 \\leq W_i \\leq 10^5\n\nFor the values v and L given in each query, 1 \\leq v \\leq N and 1 \\leq L \\leq 10^5.\n\nInput\n\nLet v_i and L_i be the values v and L given in the i-th query.\nThen, Input is given from Standard Input in the following format:\n\nN\nV_1 W_1\n:\nV_N W_N\nQ\nv_1 L_1\n:\nv_Q L_Q\n\nOutput\n\nFor each integer i from 1 through Q,\nthe i-th line should contain the response to the i-th query.\n\nSample Input 1\n\n3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n\nSample Output 1\n\n0\n3\n3\n\nIn the first query, we are given only one choice: the item with (V, W)=(1,2). Since L = 1, we cannot actually choose it, so our response should be 0.\n\nIn the second query, we are given two choices: the items with (V, W)=(1,2) and (V, W)=(2,3). Since L = 5, we can choose both of them, so our response should be 3.\n\nSample Input 2\n\n15\n123 119\n129 120\n132 112\n126 109\n118 103\n115 109\n102 100\n130 120\n105 105\n132 115\n104 102\n107 107\n127 116\n121 104\n121 115\n8\n8 234\n9 244\n10 226\n11 227\n12 240\n13 237\n14 206\n15 227\n\nSample Output 2\n\n256\n255\n250\n247\n255\n259\n223\n253", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 18155, "cpu_time_ms": 3310, "memory_kb": 93812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s865725782", "group_id": "codeNet:p02648", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Quicksort (randomized median-of-three partitioning)\n;;;\n\n;; TODO: Consider worst case of deterministic partitioning\n;; Reference:\n;; Hannu Erkio, The worst case permutation for median-of-three quicksort\n\n(declaim (inline %median3))\n(defun %median3 (x y z order)\n (if (funcall order x y)\n (if (funcall order y z)\n y\n (if (funcall order z x)\n x\n z))\n (if (funcall order z y)\n y\n (if (funcall order x z)\n x\n z))))\n\n(declaim (inline quicksort!))\n(defun quicksort! (vector order &key (start 0) end)\n \"Destructively sorts VECTOR w.r.t. ORDER.\"\n (declare (vector vector))\n (unless end\n (setq end (length vector)))\n (assert (<= 0 start end))\n (labels\n ((recur (left right)\n (declare (fixnum left right))\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3 (aref vector l)\n (aref vector (the fixnum (+ l (random (+ 1 (- r l))))))\n (aref vector r)\n order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall order (aref vector l) pivot)\n do (incf l))\n (loop while (funcall order pivot (aref vector r))\n do (decf r))\n (when (>= l r)\n (return))\n (rotatef (aref vector l) (aref vector r))\n (incf l 1)\n (decf r 1))\n (recur left (- l 1))\n (recur (+ r 1) right)))))\n (recur start (- end 1))\n vector))\n\n(declaim (inline quicksort-by2!))\n(defun quicksort-by2! (vector order)\n \"Destructively sorts VECTOR by two elements. This function regards\neach (VECTOR[i], VECTOR[i+1]) for even i as an element, and compares only the\nfirst elements (i.e. VECTOR[i] for even i).\"\n (declare (vector vector))\n (assert (evenp (length vector)))\n (labels\n ((recur (left right)\n (declare (fixnum left right))\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3\n (aref vector l)\n (aref vector (the fixnum (+ l (logandc2 (random (+ 1 (- r l))) 1))))\n (aref vector r)\n order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall order (aref vector l) pivot)\n do (incf l 2))\n (loop while (funcall order pivot (aref vector r))\n do (decf r 2))\n (when (>= l r)\n (return))\n (rotatef (aref vector l) (aref vector r))\n (rotatef (aref vector (+ l 1)) (aref vector (+ r 1)))\n (incf l 2)\n (decf r 2))\n (recur left (- l 2))\n (recur (+ r 2) right)))))\n (recur 0 (- (length vector) 2))\n vector))\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of lower_bound() of C++ or bisect_left() of Python: Returns the\nsmallest index (or input) i that fulfills TARGET[i] >= VALUE, where '>=' is the\ncomplement of ORDER. In other words, this function returns the leftmost index at\nwhich VALUE can be inserted with keeping the order. Therefore, TARGET must be\nmonotonically non-decreasing with respect to ORDER.\n\n- This function returns END if VALUE exceeds TARGET[END-1]. \n- The range [START, END) is half-open.\n- END must be explicitly specified if TARGET is function.\n- KEY is applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-left (ng ok)\n ;; TARGET[OK] >= VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (funcall order (funcall key (,accessor target mid)) value)\n (%bisect-left mid ok)\n (%bisect-left ng mid))))))\n (assert (<= start end))\n (%bisect-left (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.most-positive-fixnum)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n\n\n(declaim (inline log2-ceil))\n(defun log2-ceil (x)\n \"Rounds up log2(x).\"\n (let ((ceil (ceiling x)))\n (declare ((integer 0) ceil))\n (integer-length (- ceil 1))))\n\n(declaim (inline log-ceil))\n(defun log-ceil (x base)\n \"Rounds up log(x).\"\n (declare (real x)\n ((integer 2) base))\n (assert (>= x 0))\n (labels ((%log ()\n (nth-value 0 (ceiling (log x base)))))\n (if (integerp x)\n (let ((y x)\n (result 0))\n (loop (when (zerop y)\n (return result))\n (multiple-value-bind (quot rem) (floor y base)\n (unless (zerop rem)\n (return (%log)))\n (setq y quot)\n (incf result))))\n (%log))))\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (order #'<))\n (declare (function order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-right (ng ok)\n ;; TARGET[OK] > VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (funcall order value (the fixnum (cdr (,accessor target mid))))\n (%bisect-right ng mid)\n (%bisect-right mid ok))))))\n (assert (<= start end))\n (%bisect-right (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.array-total-size-limit)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (boundary (ash (log2-ceil n) -1))\n (vs (make-array n :element-type 'uint31 :initial-element 0))\n (ws (make-array n :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n boundary))\n (dotimes (i n)\n (setf (aref vs i) (read-fixnum)\n (aref ws i) (read-fixnum)))\n (let* ((q (read))\n (query-store (make-array n :element-type 'list :initial-element nil))\n (res (make-array q :element-type 'fixnum :initial-element 0))\n (tree (make-array (* 3 n) :element-type 'bit :initial-element 1)))\n (dotimes (i q)\n (let ((v (- (read-fixnum) 1))\n (l (read-fixnum)))\n (push (list v l i) (aref query-store v))))\n (sb-int:named-let recur ((i 0))\n (if (>= i n)\n nil\n (let ((res1 (recur (+ (* i 2) 1)))\n (res2 (recur (+ (* i 2) 2))))\n (when (or (aref query-store i)\n res1 res2)\n (setf (aref tree i) 1)))))\n (sb-int:named-let recur ((i 0)\n (depth 0)\n (half1 (list (cons 0 0)))\n (half2 (make-array 1\n :element-type 'list\n :initial-element (cons 0 0))))\n (declare (uint31 i depth)\n ((simple-array list (*)) half2))\n (when (>= i n) (return-from recur))\n (let ((v (aref vs i))\n (w (aref ws i)))\n (declare (uint31 v w))\n (if (< depth boundary)\n (let ((new-half1\n (append (loop for (v-sum . w-sum) of-type (uint62 . uint62) in half1\n collect (cons (+ v-sum v) (+ w-sum w)))\n half1)))\n (loop for (q-v q-l index) of-type (uint62 uint62 uint62) in (aref query-store i)\n do (setf (aref res index)\n (loop for (v1 . w1) in new-half1\n when (<= w1 q-l)\n maximize v1)))\n (recur (+ (* i 2) 1) (+ depth 1) new-half1 half2)\n (recur (+ (* i 2) 2) (+ depth 1) new-half1 half2))\n (let ((new-half2 (make-array (length half2) :element-type 'list)))\n (dotimes (i (length half2))\n (destructuring-bind (v-sum . w-sum) (aref half2 i)\n (setf (aref new-half2 i)\n (cons (+ v v-sum) (+ w w-sum)))))\n ;; #>new-half2\n (let* ((new-half2 (concatenate '(simple-array list (*))\n half2 new-half2)))\n ;; #>new-half2\n ;; answer query\n ;; 各重みについて最大の価値しかいらない\n (if (aref query-store i)\n (progn\n (quicksort! new-half2\n (lambda (node1 node2)\n (let ((v1 (car node1))\n (w1 (cdr node1))\n (v2 (car node2))\n (w2 (cdr node2)))\n (declare (fixnum v1 w1 v2 w2))\n (or (< w1 w2)\n (and (= w1 w2) (> v1 v2))))))\n (let ((current-v -1)\n (nn-half2 (make-array 0 :element-type 'list :fill-pointer 0)))\n (dotimes (i (length new-half2))\n (destructuring-bind (v . w) (aref new-half2 i)\n (when (> v current-v)\n (setq current-v v)\n (vector-push-extend (aref new-half2 i) nn-half2))))\n (let ((nn-half2 (coerce nn-half2 '(simple-array list (*)))))\n (declare ((simple-array list (*)) nn-half2))\n (loop for (q-v q-l index) of-type (uint62 uint62 uint62) in (aref query-store i)\n for max-value of-type fixnum = 0\n do (loop for (v1 . w1) of-type (fixnum . fixnum) in half1\n ;; 重さがl-w1以下のものを見つける\n when (<= w1 q-l)\n do (let ((idx (- (bisect-right nn-half2\n (- q-l w1))\n 1)))\n (destructuring-bind (v2 . w2) (aref nn-half2 idx)\n (declare (fixnum v2 w2))\n (assert (<= (+ w1 w2) q-l))\n (maxf max-value (+ v1 v2)))))\n (setf (aref res index) max-value))\n (when (= 1 (aref tree (+ (* i 2) 1)))\n (recur (+ (* i 2) 1) (+ depth 1) half1 nn-half2))\n (when (= 1 (aref tree (+ (* i 2) 2)))\n (recur (+ (* i 2) 2) (+ depth 1) half1 nn-half2)))))\n (progn\n (when (= 1 (aref tree (+ (* i 2) 1)))\n (recur (+ (* i 2) 1) (+ depth 1) half1 new-half2))\n (when (= 1 (aref tree (+ (* i 2) 2)))\n (recur (+ (* i 2) 2) (+ depth 1) half1 new-half2)))))))))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (map () #'println res))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (let ((n 262144))\n (format out \"~D~%\" n)\n (dotimes (_ n)\n (format out \"~D ~D~%\" (+ 1 (random 100000)) (+ 1 (random 100000))))\n (println 100000 out)\n (dotimes (_ 100000)\n (format out \"~D ~D~%\" (+ 1 (random n)) (+ 1 (random 100000)))))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n\"\n \"0\n3\n3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"15\n123 119\n129 120\n132 112\n126 109\n118 103\n115 109\n102 100\n130 120\n105 105\n132 115\n104 102\n107 107\n127 116\n121 104\n121 115\n8\n8 234\n9 244\n10 226\n11 227\n12 240\n13 237\n14 206\n15 227\n\"\n \"256\n255\n250\n247\n255\n259\n223\n253\n\")))\n", "language": "Lisp", "metadata": {"date": 1592102905, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02648.html", "problem_id": "p02648", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02648/input.txt", "sample_output_relpath": "derived/input_output/data/p02648/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02648/Lisp/s865725782.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s865725782", "user_id": "u352600849"}, "prompt_components": {"gold_output": "0\n3\n3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Quicksort (randomized median-of-three partitioning)\n;;;\n\n;; TODO: Consider worst case of deterministic partitioning\n;; Reference:\n;; Hannu Erkio, The worst case permutation for median-of-three quicksort\n\n(declaim (inline %median3))\n(defun %median3 (x y z order)\n (if (funcall order x y)\n (if (funcall order y z)\n y\n (if (funcall order z x)\n x\n z))\n (if (funcall order z y)\n y\n (if (funcall order x z)\n x\n z))))\n\n(declaim (inline quicksort!))\n(defun quicksort! (vector order &key (start 0) end)\n \"Destructively sorts VECTOR w.r.t. ORDER.\"\n (declare (vector vector))\n (unless end\n (setq end (length vector)))\n (assert (<= 0 start end))\n (labels\n ((recur (left right)\n (declare (fixnum left right))\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3 (aref vector l)\n (aref vector (the fixnum (+ l (random (+ 1 (- r l))))))\n (aref vector r)\n order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall order (aref vector l) pivot)\n do (incf l))\n (loop while (funcall order pivot (aref vector r))\n do (decf r))\n (when (>= l r)\n (return))\n (rotatef (aref vector l) (aref vector r))\n (incf l 1)\n (decf r 1))\n (recur left (- l 1))\n (recur (+ r 1) right)))))\n (recur start (- end 1))\n vector))\n\n(declaim (inline quicksort-by2!))\n(defun quicksort-by2! (vector order)\n \"Destructively sorts VECTOR by two elements. This function regards\neach (VECTOR[i], VECTOR[i+1]) for even i as an element, and compares only the\nfirst elements (i.e. VECTOR[i] for even i).\"\n (declare (vector vector))\n (assert (evenp (length vector)))\n (labels\n ((recur (left right)\n (declare (fixnum left right))\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3\n (aref vector l)\n (aref vector (the fixnum (+ l (logandc2 (random (+ 1 (- r l))) 1))))\n (aref vector r)\n order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall order (aref vector l) pivot)\n do (incf l 2))\n (loop while (funcall order pivot (aref vector r))\n do (decf r 2))\n (when (>= l r)\n (return))\n (rotatef (aref vector l) (aref vector r))\n (rotatef (aref vector (+ l 1)) (aref vector (+ r 1)))\n (incf l 2)\n (decf r 2))\n (recur left (- l 2))\n (recur (+ r 2) right)))))\n (recur 0 (- (length vector) 2))\n vector))\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of lower_bound() of C++ or bisect_left() of Python: Returns the\nsmallest index (or input) i that fulfills TARGET[i] >= VALUE, where '>=' is the\ncomplement of ORDER. In other words, this function returns the leftmost index at\nwhich VALUE can be inserted with keeping the order. Therefore, TARGET must be\nmonotonically non-decreasing with respect to ORDER.\n\n- This function returns END if VALUE exceeds TARGET[END-1]. \n- The range [START, END) is half-open.\n- END must be explicitly specified if TARGET is function.\n- KEY is applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-left (ng ok)\n ;; TARGET[OK] >= VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (funcall order (funcall key (,accessor target mid)) value)\n (%bisect-left mid ok)\n (%bisect-left ng mid))))))\n (assert (<= start end))\n (%bisect-left (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.most-positive-fixnum)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n\n\n(declaim (inline log2-ceil))\n(defun log2-ceil (x)\n \"Rounds up log2(x).\"\n (let ((ceil (ceiling x)))\n (declare ((integer 0) ceil))\n (integer-length (- ceil 1))))\n\n(declaim (inline log-ceil))\n(defun log-ceil (x base)\n \"Rounds up log(x).\"\n (declare (real x)\n ((integer 2) base))\n (assert (>= x 0))\n (labels ((%log ()\n (nth-value 0 (ceiling (log x base)))))\n (if (integerp x)\n (let ((y x)\n (result 0))\n (loop (when (zerop y)\n (return result))\n (multiple-value-bind (quot rem) (floor y base)\n (unless (zerop rem)\n (return (%log)))\n (setq y quot)\n (incf result))))\n (%log))))\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (order #'<))\n (declare (function order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-right (ng ok)\n ;; TARGET[OK] > VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (funcall order value (the fixnum (cdr (,accessor target mid))))\n (%bisect-right ng mid)\n (%bisect-right mid ok))))))\n (assert (<= start end))\n (%bisect-right (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.array-total-size-limit)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (boundary (ash (log2-ceil n) -1))\n (vs (make-array n :element-type 'uint31 :initial-element 0))\n (ws (make-array n :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n boundary))\n (dotimes (i n)\n (setf (aref vs i) (read-fixnum)\n (aref ws i) (read-fixnum)))\n (let* ((q (read))\n (query-store (make-array n :element-type 'list :initial-element nil))\n (res (make-array q :element-type 'fixnum :initial-element 0))\n (tree (make-array (* 3 n) :element-type 'bit :initial-element 1)))\n (dotimes (i q)\n (let ((v (- (read-fixnum) 1))\n (l (read-fixnum)))\n (push (list v l i) (aref query-store v))))\n (sb-int:named-let recur ((i 0))\n (if (>= i n)\n nil\n (let ((res1 (recur (+ (* i 2) 1)))\n (res2 (recur (+ (* i 2) 2))))\n (when (or (aref query-store i)\n res1 res2)\n (setf (aref tree i) 1)))))\n (sb-int:named-let recur ((i 0)\n (depth 0)\n (half1 (list (cons 0 0)))\n (half2 (make-array 1\n :element-type 'list\n :initial-element (cons 0 0))))\n (declare (uint31 i depth)\n ((simple-array list (*)) half2))\n (when (>= i n) (return-from recur))\n (let ((v (aref vs i))\n (w (aref ws i)))\n (declare (uint31 v w))\n (if (< depth boundary)\n (let ((new-half1\n (append (loop for (v-sum . w-sum) of-type (uint62 . uint62) in half1\n collect (cons (+ v-sum v) (+ w-sum w)))\n half1)))\n (loop for (q-v q-l index) of-type (uint62 uint62 uint62) in (aref query-store i)\n do (setf (aref res index)\n (loop for (v1 . w1) in new-half1\n when (<= w1 q-l)\n maximize v1)))\n (recur (+ (* i 2) 1) (+ depth 1) new-half1 half2)\n (recur (+ (* i 2) 2) (+ depth 1) new-half1 half2))\n (let ((new-half2 (make-array (length half2) :element-type 'list)))\n (dotimes (i (length half2))\n (destructuring-bind (v-sum . w-sum) (aref half2 i)\n (setf (aref new-half2 i)\n (cons (+ v v-sum) (+ w w-sum)))))\n ;; #>new-half2\n (let* ((new-half2 (concatenate '(simple-array list (*))\n half2 new-half2)))\n ;; #>new-half2\n ;; answer query\n ;; 各重みについて最大の価値しかいらない\n (if (aref query-store i)\n (progn\n (quicksort! new-half2\n (lambda (node1 node2)\n (let ((v1 (car node1))\n (w1 (cdr node1))\n (v2 (car node2))\n (w2 (cdr node2)))\n (declare (fixnum v1 w1 v2 w2))\n (or (< w1 w2)\n (and (= w1 w2) (> v1 v2))))))\n (let ((current-v -1)\n (nn-half2 (make-array 0 :element-type 'list :fill-pointer 0)))\n (dotimes (i (length new-half2))\n (destructuring-bind (v . w) (aref new-half2 i)\n (when (> v current-v)\n (setq current-v v)\n (vector-push-extend (aref new-half2 i) nn-half2))))\n (let ((nn-half2 (coerce nn-half2 '(simple-array list (*)))))\n (declare ((simple-array list (*)) nn-half2))\n (loop for (q-v q-l index) of-type (uint62 uint62 uint62) in (aref query-store i)\n for max-value of-type fixnum = 0\n do (loop for (v1 . w1) of-type (fixnum . fixnum) in half1\n ;; 重さがl-w1以下のものを見つける\n when (<= w1 q-l)\n do (let ((idx (- (bisect-right nn-half2\n (- q-l w1))\n 1)))\n (destructuring-bind (v2 . w2) (aref nn-half2 idx)\n (declare (fixnum v2 w2))\n (assert (<= (+ w1 w2) q-l))\n (maxf max-value (+ v1 v2)))))\n (setf (aref res index) max-value))\n (when (= 1 (aref tree (+ (* i 2) 1)))\n (recur (+ (* i 2) 1) (+ depth 1) half1 nn-half2))\n (when (= 1 (aref tree (+ (* i 2) 2)))\n (recur (+ (* i 2) 2) (+ depth 1) half1 nn-half2)))))\n (progn\n (when (= 1 (aref tree (+ (* i 2) 1)))\n (recur (+ (* i 2) 1) (+ depth 1) half1 new-half2))\n (when (= 1 (aref tree (+ (* i 2) 2)))\n (recur (+ (* i 2) 2) (+ depth 1) half1 new-half2)))))))))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (map () #'println res))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (let ((n 262144))\n (format out \"~D~%\" n)\n (dotimes (_ n)\n (format out \"~D ~D~%\" (+ 1 (random 100000)) (+ 1 (random 100000))))\n (println 100000 out)\n (dotimes (_ 100000)\n (format out \"~D ~D~%\" (+ 1 (random n)) (+ 1 (random 100000)))))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n\"\n \"0\n3\n3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"15\n123 119\n129 120\n132 112\n126 109\n118 103\n115 109\n102 100\n130 120\n105 105\n132 115\n104 102\n107 107\n127 116\n121 104\n121 115\n8\n8 234\n9 244\n10 226\n11 227\n12 240\n13 237\n14 206\n15 227\n\"\n \"256\n255\n250\n247\n255\n259\n223\n253\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nWe have a rooted binary tree with N vertices, where the vertices are numbered 1 to N.\nVertex 1 is the root, and the parent of Vertex i (i \\geq 2) is Vertex \\left[ \\frac{i}{2} \\right].\n\nEach vertex has one item in it. The item in Vertex i has a value of V_i and a weight of W_i.\nNow, process the following query Q times:\n\nGiven are a vertex v of the tree and a positive integer L.\nLet us choose some (possibly none) of the items in v and the ancestors of v so that their total weight is at most L.\nFind the maximum possible total value of the chosen items.\n\nHere, Vertex u is said to be an ancestor of Vertex v when u is an indirect parent of v, that is, there exists a sequence of vertices w_1,w_2,\\ldots,w_k (k\\geq 2) where w_1=v, w_k=u, and w_{i+1} is the parent of w_i for each i.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N < 2^{18}\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq V_i \\leq 10^5\n\n1 \\leq W_i \\leq 10^5\n\nFor the values v and L given in each query, 1 \\leq v \\leq N and 1 \\leq L \\leq 10^5.\n\nInput\n\nLet v_i and L_i be the values v and L given in the i-th query.\nThen, Input is given from Standard Input in the following format:\n\nN\nV_1 W_1\n:\nV_N W_N\nQ\nv_1 L_1\n:\nv_Q L_Q\n\nOutput\n\nFor each integer i from 1 through Q,\nthe i-th line should contain the response to the i-th query.\n\nSample Input 1\n\n3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n\nSample Output 1\n\n0\n3\n3\n\nIn the first query, we are given only one choice: the item with (V, W)=(1,2). Since L = 1, we cannot actually choose it, so our response should be 0.\n\nIn the second query, we are given two choices: the items with (V, W)=(1,2) and (V, W)=(2,3). Since L = 5, we can choose both of them, so our response should be 3.\n\nSample Input 2\n\n15\n123 119\n129 120\n132 112\n126 109\n118 103\n115 109\n102 100\n130 120\n105 105\n132 115\n104 102\n107 107\n127 116\n121 104\n121 115\n8\n8 234\n9 244\n10 226\n11 227\n12 240\n13 237\n14 206\n15 227\n\nSample Output 2\n\n256\n255\n250\n247\n255\n259\n223\n253", "sample_input": "3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n"}, "reference_outputs": ["0\n3\n3\n"], "source_document_id": "p02648", "source_text": "Score : 700 points\n\nProblem Statement\n\nWe have a rooted binary tree with N vertices, where the vertices are numbered 1 to N.\nVertex 1 is the root, and the parent of Vertex i (i \\geq 2) is Vertex \\left[ \\frac{i}{2} \\right].\n\nEach vertex has one item in it. The item in Vertex i has a value of V_i and a weight of W_i.\nNow, process the following query Q times:\n\nGiven are a vertex v of the tree and a positive integer L.\nLet us choose some (possibly none) of the items in v and the ancestors of v so that their total weight is at most L.\nFind the maximum possible total value of the chosen items.\n\nHere, Vertex u is said to be an ancestor of Vertex v when u is an indirect parent of v, that is, there exists a sequence of vertices w_1,w_2,\\ldots,w_k (k\\geq 2) where w_1=v, w_k=u, and w_{i+1} is the parent of w_i for each i.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N < 2^{18}\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq V_i \\leq 10^5\n\n1 \\leq W_i \\leq 10^5\n\nFor the values v and L given in each query, 1 \\leq v \\leq N and 1 \\leq L \\leq 10^5.\n\nInput\n\nLet v_i and L_i be the values v and L given in the i-th query.\nThen, Input is given from Standard Input in the following format:\n\nN\nV_1 W_1\n:\nV_N W_N\nQ\nv_1 L_1\n:\nv_Q L_Q\n\nOutput\n\nFor each integer i from 1 through Q,\nthe i-th line should contain the response to the i-th query.\n\nSample Input 1\n\n3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n\nSample Output 1\n\n0\n3\n3\n\nIn the first query, we are given only one choice: the item with (V, W)=(1,2). Since L = 1, we cannot actually choose it, so our response should be 0.\n\nIn the second query, we are given two choices: the items with (V, W)=(1,2) and (V, W)=(2,3). Since L = 5, we can choose both of them, so our response should be 3.\n\nSample Input 2\n\n15\n123 119\n129 120\n132 112\n126 109\n118 103\n115 109\n102 100\n130 120\n105 105\n132 115\n104 102\n107 107\n127 116\n121 104\n121 115\n8\n8 234\n9 244\n10 226\n11 227\n12 240\n13 237\n14 206\n15 227\n\nSample Output 2\n\n256\n255\n250\n247\n255\n259\n223\n253", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 18189, "cpu_time_ms": 3310, "memory_kb": 94328}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s581811712", "group_id": "codeNet:p02648", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Quicksort (randomized median-of-three partitioning)\n;;;\n\n;; TODO: Consider worst case of deterministic partitioning\n;; Reference:\n;; Hannu Erkio, The worst case permutation for median-of-three quicksort\n\n(declaim (inline %median3))\n(defun %median3 (x y z order)\n (if (funcall order x y)\n (if (funcall order y z)\n y\n (if (funcall order z x)\n x\n z))\n (if (funcall order z y)\n y\n (if (funcall order x z)\n x\n z))))\n\n(declaim (inline quicksort!))\n(defun quicksort! (vector order &key (start 0) end)\n \"Destructively sorts VECTOR w.r.t. ORDER.\"\n (declare (vector vector))\n (unless end\n (setq end (length vector)))\n (assert (<= 0 start end))\n (labels\n ((recur (left right)\n (declare (fixnum left right))\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3 (aref vector l)\n (aref vector (the fixnum (+ l (random (+ 1 (- r l))))))\n (aref vector r)\n order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall order (aref vector l) pivot)\n do (incf l))\n (loop while (funcall order pivot (aref vector r))\n do (decf r))\n (when (>= l r)\n (return))\n (rotatef (aref vector l) (aref vector r))\n (incf l 1)\n (decf r 1))\n (recur left (- l 1))\n (recur (+ r 1) right)))))\n (recur start (- end 1))\n vector))\n\n(declaim (inline quicksort-by2!))\n(defun quicksort-by2! (vector order)\n \"Destructively sorts VECTOR by two elements. This function regards\neach (VECTOR[i], VECTOR[i+1]) for even i as an element, and compares only the\nfirst elements (i.e. VECTOR[i] for even i).\"\n (declare (vector vector))\n (assert (evenp (length vector)))\n (labels\n ((recur (left right)\n (declare (fixnum left right))\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3\n (aref vector l)\n (aref vector (the fixnum (+ l (logandc2 (random (+ 1 (- r l))) 1))))\n (aref vector r)\n order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall order (aref vector l) pivot)\n do (incf l 2))\n (loop while (funcall order pivot (aref vector r))\n do (decf r 2))\n (when (>= l r)\n (return))\n (rotatef (aref vector l) (aref vector r))\n (rotatef (aref vector (+ l 1)) (aref vector (+ r 1)))\n (incf l 2)\n (decf r 2))\n (recur left (- l 2))\n (recur (+ r 2) right)))))\n (recur 0 (- (length vector) 2))\n vector))\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of lower_bound() of C++ or bisect_left() of Python: Returns the\nsmallest index (or input) i that fulfills TARGET[i] >= VALUE, where '>=' is the\ncomplement of ORDER. In other words, this function returns the leftmost index at\nwhich VALUE can be inserted with keeping the order. Therefore, TARGET must be\nmonotonically non-decreasing with respect to ORDER.\n\n- This function returns END if VALUE exceeds TARGET[END-1]. \n- The range [START, END) is half-open.\n- END must be explicitly specified if TARGET is function.\n- KEY is applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-left (ng ok)\n ;; TARGET[OK] >= VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (funcall order (funcall key (,accessor target mid)) value)\n (%bisect-left mid ok)\n (%bisect-left ng mid))))))\n (assert (<= start end))\n (%bisect-left (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.most-positive-fixnum)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n\n\n(declaim (inline log2-ceil))\n(defun log2-ceil (x)\n \"Rounds up log2(x).\"\n (let ((ceil (ceiling x)))\n (declare ((integer 0) ceil))\n (integer-length (- ceil 1))))\n\n(declaim (inline log-ceil))\n(defun log-ceil (x base)\n \"Rounds up log(x).\"\n (declare (real x)\n ((integer 2) base))\n (assert (>= x 0))\n (labels ((%log ()\n (nth-value 0 (ceiling (log x base)))))\n (if (integerp x)\n (let ((y x)\n (result 0))\n (loop (when (zerop y)\n (return result))\n (multiple-value-bind (quot rem) (floor y base)\n (unless (zerop rem)\n (return (%log)))\n (setq y quot)\n (incf result))))\n (%log))))\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (order #'<))\n (declare (function order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-right (ng ok)\n ;; TARGET[OK] > VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (funcall order value (the fixnum (cdr (,accessor target mid))))\n (%bisect-right ng mid)\n (%bisect-right mid ok))))))\n (assert (<= start end))\n (%bisect-right (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.array-total-size-limit)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (boundary (ash (log2-ceil n) -1))\n (vs (make-array n :element-type 'uint31 :initial-element 0))\n (ws (make-array n :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n boundary))\n (dotimes (i n)\n (setf (aref vs i) (read-fixnum)\n (aref ws i) (read-fixnum)))\n (let* ((q (read))\n (query-store (make-array n :element-type 'list :initial-element nil))\n (res (make-array q :element-type 'fixnum :initial-element 0)))\n (dotimes (i q)\n (let ((v (- (read-fixnum) 1))\n (l (read-fixnum)))\n (push (list v l i) (aref query-store v))))\n (sb-int:named-let recur ((i 0)\n (depth 0)\n (half1 (list (cons 0 0)))\n (half2 (make-array 1\n :element-type 'list\n :initial-element (cons 0 0))))\n (declare (uint31 i depth)\n ((simple-array list (*)) half2))\n (when (>= i n) (return-from recur))\n (let ((v (aref vs i))\n (w (aref ws i)))\n (declare (uint31 v w))\n (if (< depth boundary)\n (let ((new-half1\n (append (loop for (v-sum . w-sum) of-type (uint62 . uint62) in half1\n collect (cons (+ v-sum v) (+ w-sum w)))\n half1)))\n (loop for (q-v q-l index) of-type (uint62 uint62 uint62) in (aref query-store i)\n do (setf (aref res index)\n (loop for (v1 . w1) in new-half1\n when (<= w1 q-l)\n maximize v1)))\n (recur (+ (* i 2) 1) (+ depth 1) new-half1 half2)\n (recur (+ (* i 2) 2) (+ depth 1) new-half1 half2))\n (let ((new-half2 (make-array (length half2) :element-type 'list)))\n (dotimes (i (length half2))\n (destructuring-bind (v-sum . w-sum) (aref half2 i)\n (setf (aref new-half2 i)\n (cons (+ v v-sum) (+ w w-sum)))))\n ;; #>new-half2\n (let* ((new-half2 (concatenate '(simple-array list (*))\n half2 new-half2)))\n ;; #>new-half2\n ;; answer query\n ;; 各重みについて最大の価値しかいらない\n (if (aref query-store i)\n (progn\n (quicksort! new-half2\n (lambda (node1 node2)\n (let ((v1 (car node1))\n (w1 (cdr node1))\n (v2 (car node2))\n (w2 (cdr node2)))\n (declare (fixnum v1 w1 v2 w2))\n (or (< w1 w2)\n (and (= w1 w2) (> v1 v2))))))\n (let ((current-v -1)\n (nn-half2 (make-array 0 :element-type 'list :fill-pointer 0)))\n (dotimes (i (length new-half2))\n (destructuring-bind (v . w) (aref new-half2 i)\n (when (> v current-v)\n (setq current-v v)\n (vector-push-extend (aref new-half2 i) nn-half2))))\n (let ((nn-half2 (coerce nn-half2 '(simple-array list (*)))))\n (declare ((simple-array list (*)) nn-half2))\n (loop for (q-v q-l index) of-type (uint62 uint62 uint62) in (aref query-store i)\n for max-value of-type fixnum = 0\n do (loop for (v1 . w1) of-type (fixnum . fixnum) in half1\n ;; 重さがl-w1以下のものを見つける\n when (<= w1 q-l)\n do (let ((idx (- (bisect-right nn-half2\n (- q-l w1))\n 1)))\n (destructuring-bind (v2 . w2) (aref nn-half2 idx)\n (declare (fixnum v2 w2))\n (assert (<= (+ w1 w2) q-l))\n (maxf max-value (+ v1 v2)))))\n (setf (aref res index) max-value))\n (recur (+ (* i 2) 1) (+ depth 1) half1 nn-half2)\n (recur (+ (* i 2) 2) (+ depth 1) half1 nn-half2))))\n (progn\n (recur (+ (* i 2) 1) (+ depth 1) half1 new-half2)\n (recur (+ (* i 2) 2) (+ depth 1) half1 new-half2))))))))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (map () #'println res))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (let ((n 262144))\n (format out \"~D~%\" n)\n (dotimes (_ n)\n (format out \"~D ~D~%\" (+ 1 (random 100000)) (+ 1 (random 100000))))\n (println 100000 out)\n (dotimes (_ 100000)\n (format out \"~D ~D~%\" (+ 1 (random n)) (+ 1 (random 100000)))))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n\"\n \"0\n3\n3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"15\n123 119\n129 120\n132 112\n126 109\n118 103\n115 109\n102 100\n130 120\n105 105\n132 115\n104 102\n107 107\n127 116\n121 104\n121 115\n8\n8 234\n9 244\n10 226\n11 227\n12 240\n13 237\n14 206\n15 227\n\"\n \"256\n255\n250\n247\n255\n259\n223\n253\n\")))\n", "language": "Lisp", "metadata": {"date": 1592102465, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02648.html", "problem_id": "p02648", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02648/input.txt", "sample_output_relpath": "derived/input_output/data/p02648/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02648/Lisp/s581811712.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s581811712", "user_id": "u352600849"}, "prompt_components": {"gold_output": "0\n3\n3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Quicksort (randomized median-of-three partitioning)\n;;;\n\n;; TODO: Consider worst case of deterministic partitioning\n;; Reference:\n;; Hannu Erkio, The worst case permutation for median-of-three quicksort\n\n(declaim (inline %median3))\n(defun %median3 (x y z order)\n (if (funcall order x y)\n (if (funcall order y z)\n y\n (if (funcall order z x)\n x\n z))\n (if (funcall order z y)\n y\n (if (funcall order x z)\n x\n z))))\n\n(declaim (inline quicksort!))\n(defun quicksort! (vector order &key (start 0) end)\n \"Destructively sorts VECTOR w.r.t. ORDER.\"\n (declare (vector vector))\n (unless end\n (setq end (length vector)))\n (assert (<= 0 start end))\n (labels\n ((recur (left right)\n (declare (fixnum left right))\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3 (aref vector l)\n (aref vector (the fixnum (+ l (random (+ 1 (- r l))))))\n (aref vector r)\n order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall order (aref vector l) pivot)\n do (incf l))\n (loop while (funcall order pivot (aref vector r))\n do (decf r))\n (when (>= l r)\n (return))\n (rotatef (aref vector l) (aref vector r))\n (incf l 1)\n (decf r 1))\n (recur left (- l 1))\n (recur (+ r 1) right)))))\n (recur start (- end 1))\n vector))\n\n(declaim (inline quicksort-by2!))\n(defun quicksort-by2! (vector order)\n \"Destructively sorts VECTOR by two elements. This function regards\neach (VECTOR[i], VECTOR[i+1]) for even i as an element, and compares only the\nfirst elements (i.e. VECTOR[i] for even i).\"\n (declare (vector vector))\n (assert (evenp (length vector)))\n (labels\n ((recur (left right)\n (declare (fixnum left right))\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3\n (aref vector l)\n (aref vector (the fixnum (+ l (logandc2 (random (+ 1 (- r l))) 1))))\n (aref vector r)\n order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall order (aref vector l) pivot)\n do (incf l 2))\n (loop while (funcall order pivot (aref vector r))\n do (decf r 2))\n (when (>= l r)\n (return))\n (rotatef (aref vector l) (aref vector r))\n (rotatef (aref vector (+ l 1)) (aref vector (+ r 1)))\n (incf l 2)\n (decf r 2))\n (recur left (- l 2))\n (recur (+ r 2) right)))))\n (recur 0 (- (length vector) 2))\n vector))\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of lower_bound() of C++ or bisect_left() of Python: Returns the\nsmallest index (or input) i that fulfills TARGET[i] >= VALUE, where '>=' is the\ncomplement of ORDER. In other words, this function returns the leftmost index at\nwhich VALUE can be inserted with keeping the order. Therefore, TARGET must be\nmonotonically non-decreasing with respect to ORDER.\n\n- This function returns END if VALUE exceeds TARGET[END-1]. \n- The range [START, END) is half-open.\n- END must be explicitly specified if TARGET is function.\n- KEY is applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-left (ng ok)\n ;; TARGET[OK] >= VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (funcall order (funcall key (,accessor target mid)) value)\n (%bisect-left mid ok)\n (%bisect-left ng mid))))))\n (assert (<= start end))\n (%bisect-left (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.most-positive-fixnum)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n\n\n(declaim (inline log2-ceil))\n(defun log2-ceil (x)\n \"Rounds up log2(x).\"\n (let ((ceil (ceiling x)))\n (declare ((integer 0) ceil))\n (integer-length (- ceil 1))))\n\n(declaim (inline log-ceil))\n(defun log-ceil (x base)\n \"Rounds up log(x).\"\n (declare (real x)\n ((integer 2) base))\n (assert (>= x 0))\n (labels ((%log ()\n (nth-value 0 (ceiling (log x base)))))\n (if (integerp x)\n (let ((y x)\n (result 0))\n (loop (when (zerop y)\n (return result))\n (multiple-value-bind (quot rem) (floor y base)\n (unless (zerop rem)\n (return (%log)))\n (setq y quot)\n (incf result))))\n (%log))))\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (order #'<))\n (declare (function order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-right (ng ok)\n ;; TARGET[OK] > VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (funcall order value (the fixnum (cdr (,accessor target mid))))\n (%bisect-right ng mid)\n (%bisect-right mid ok))))))\n (assert (<= start end))\n (%bisect-right (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.array-total-size-limit)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (boundary (ash (log2-ceil n) -1))\n (vs (make-array n :element-type 'uint31 :initial-element 0))\n (ws (make-array n :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n boundary))\n (dotimes (i n)\n (setf (aref vs i) (read-fixnum)\n (aref ws i) (read-fixnum)))\n (let* ((q (read))\n (query-store (make-array n :element-type 'list :initial-element nil))\n (res (make-array q :element-type 'fixnum :initial-element 0)))\n (dotimes (i q)\n (let ((v (- (read-fixnum) 1))\n (l (read-fixnum)))\n (push (list v l i) (aref query-store v))))\n (sb-int:named-let recur ((i 0)\n (depth 0)\n (half1 (list (cons 0 0)))\n (half2 (make-array 1\n :element-type 'list\n :initial-element (cons 0 0))))\n (declare (uint31 i depth)\n ((simple-array list (*)) half2))\n (when (>= i n) (return-from recur))\n (let ((v (aref vs i))\n (w (aref ws i)))\n (declare (uint31 v w))\n (if (< depth boundary)\n (let ((new-half1\n (append (loop for (v-sum . w-sum) of-type (uint62 . uint62) in half1\n collect (cons (+ v-sum v) (+ w-sum w)))\n half1)))\n (loop for (q-v q-l index) of-type (uint62 uint62 uint62) in (aref query-store i)\n do (setf (aref res index)\n (loop for (v1 . w1) in new-half1\n when (<= w1 q-l)\n maximize v1)))\n (recur (+ (* i 2) 1) (+ depth 1) new-half1 half2)\n (recur (+ (* i 2) 2) (+ depth 1) new-half1 half2))\n (let ((new-half2 (make-array (length half2) :element-type 'list)))\n (dotimes (i (length half2))\n (destructuring-bind (v-sum . w-sum) (aref half2 i)\n (setf (aref new-half2 i)\n (cons (+ v v-sum) (+ w w-sum)))))\n ;; #>new-half2\n (let* ((new-half2 (concatenate '(simple-array list (*))\n half2 new-half2)))\n ;; #>new-half2\n ;; answer query\n ;; 各重みについて最大の価値しかいらない\n (if (aref query-store i)\n (progn\n (quicksort! new-half2\n (lambda (node1 node2)\n (let ((v1 (car node1))\n (w1 (cdr node1))\n (v2 (car node2))\n (w2 (cdr node2)))\n (declare (fixnum v1 w1 v2 w2))\n (or (< w1 w2)\n (and (= w1 w2) (> v1 v2))))))\n (let ((current-v -1)\n (nn-half2 (make-array 0 :element-type 'list :fill-pointer 0)))\n (dotimes (i (length new-half2))\n (destructuring-bind (v . w) (aref new-half2 i)\n (when (> v current-v)\n (setq current-v v)\n (vector-push-extend (aref new-half2 i) nn-half2))))\n (let ((nn-half2 (coerce nn-half2 '(simple-array list (*)))))\n (declare ((simple-array list (*)) nn-half2))\n (loop for (q-v q-l index) of-type (uint62 uint62 uint62) in (aref query-store i)\n for max-value of-type fixnum = 0\n do (loop for (v1 . w1) of-type (fixnum . fixnum) in half1\n ;; 重さがl-w1以下のものを見つける\n when (<= w1 q-l)\n do (let ((idx (- (bisect-right nn-half2\n (- q-l w1))\n 1)))\n (destructuring-bind (v2 . w2) (aref nn-half2 idx)\n (declare (fixnum v2 w2))\n (assert (<= (+ w1 w2) q-l))\n (maxf max-value (+ v1 v2)))))\n (setf (aref res index) max-value))\n (recur (+ (* i 2) 1) (+ depth 1) half1 nn-half2)\n (recur (+ (* i 2) 2) (+ depth 1) half1 nn-half2))))\n (progn\n (recur (+ (* i 2) 1) (+ depth 1) half1 new-half2)\n (recur (+ (* i 2) 2) (+ depth 1) half1 new-half2))))))))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (map () #'println res))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (let ((n 262144))\n (format out \"~D~%\" n)\n (dotimes (_ n)\n (format out \"~D ~D~%\" (+ 1 (random 100000)) (+ 1 (random 100000))))\n (println 100000 out)\n (dotimes (_ 100000)\n (format out \"~D ~D~%\" (+ 1 (random n)) (+ 1 (random 100000)))))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n\"\n \"0\n3\n3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"15\n123 119\n129 120\n132 112\n126 109\n118 103\n115 109\n102 100\n130 120\n105 105\n132 115\n104 102\n107 107\n127 116\n121 104\n121 115\n8\n8 234\n9 244\n10 226\n11 227\n12 240\n13 237\n14 206\n15 227\n\"\n \"256\n255\n250\n247\n255\n259\n223\n253\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nWe have a rooted binary tree with N vertices, where the vertices are numbered 1 to N.\nVertex 1 is the root, and the parent of Vertex i (i \\geq 2) is Vertex \\left[ \\frac{i}{2} \\right].\n\nEach vertex has one item in it. The item in Vertex i has a value of V_i and a weight of W_i.\nNow, process the following query Q times:\n\nGiven are a vertex v of the tree and a positive integer L.\nLet us choose some (possibly none) of the items in v and the ancestors of v so that their total weight is at most L.\nFind the maximum possible total value of the chosen items.\n\nHere, Vertex u is said to be an ancestor of Vertex v when u is an indirect parent of v, that is, there exists a sequence of vertices w_1,w_2,\\ldots,w_k (k\\geq 2) where w_1=v, w_k=u, and w_{i+1} is the parent of w_i for each i.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N < 2^{18}\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq V_i \\leq 10^5\n\n1 \\leq W_i \\leq 10^5\n\nFor the values v and L given in each query, 1 \\leq v \\leq N and 1 \\leq L \\leq 10^5.\n\nInput\n\nLet v_i and L_i be the values v and L given in the i-th query.\nThen, Input is given from Standard Input in the following format:\n\nN\nV_1 W_1\n:\nV_N W_N\nQ\nv_1 L_1\n:\nv_Q L_Q\n\nOutput\n\nFor each integer i from 1 through Q,\nthe i-th line should contain the response to the i-th query.\n\nSample Input 1\n\n3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n\nSample Output 1\n\n0\n3\n3\n\nIn the first query, we are given only one choice: the item with (V, W)=(1,2). Since L = 1, we cannot actually choose it, so our response should be 0.\n\nIn the second query, we are given two choices: the items with (V, W)=(1,2) and (V, W)=(2,3). Since L = 5, we can choose both of them, so our response should be 3.\n\nSample Input 2\n\n15\n123 119\n129 120\n132 112\n126 109\n118 103\n115 109\n102 100\n130 120\n105 105\n132 115\n104 102\n107 107\n127 116\n121 104\n121 115\n8\n8 234\n9 244\n10 226\n11 227\n12 240\n13 237\n14 206\n15 227\n\nSample Output 2\n\n256\n255\n250\n247\n255\n259\n223\n253", "sample_input": "3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n"}, "reference_outputs": ["0\n3\n3\n"], "source_document_id": "p02648", "source_text": "Score : 700 points\n\nProblem Statement\n\nWe have a rooted binary tree with N vertices, where the vertices are numbered 1 to N.\nVertex 1 is the root, and the parent of Vertex i (i \\geq 2) is Vertex \\left[ \\frac{i}{2} \\right].\n\nEach vertex has one item in it. The item in Vertex i has a value of V_i and a weight of W_i.\nNow, process the following query Q times:\n\nGiven are a vertex v of the tree and a positive integer L.\nLet us choose some (possibly none) of the items in v and the ancestors of v so that their total weight is at most L.\nFind the maximum possible total value of the chosen items.\n\nHere, Vertex u is said to be an ancestor of Vertex v when u is an indirect parent of v, that is, there exists a sequence of vertices w_1,w_2,\\ldots,w_k (k\\geq 2) where w_1=v, w_k=u, and w_{i+1} is the parent of w_i for each i.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N < 2^{18}\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq V_i \\leq 10^5\n\n1 \\leq W_i \\leq 10^5\n\nFor the values v and L given in each query, 1 \\leq v \\leq N and 1 \\leq L \\leq 10^5.\n\nInput\n\nLet v_i and L_i be the values v and L given in the i-th query.\nThen, Input is given from Standard Input in the following format:\n\nN\nV_1 W_1\n:\nV_N W_N\nQ\nv_1 L_1\n:\nv_Q L_Q\n\nOutput\n\nFor each integer i from 1 through Q,\nthe i-th line should contain the response to the i-th query.\n\nSample Input 1\n\n3\n1 2\n2 3\n3 4\n3\n1 1\n2 5\n3 5\n\nSample Output 1\n\n0\n3\n3\n\nIn the first query, we are given only one choice: the item with (V, W)=(1,2). Since L = 1, we cannot actually choose it, so our response should be 0.\n\nIn the second query, we are given two choices: the items with (V, W)=(1,2) and (V, W)=(2,3). Since L = 5, we can choose both of them, so our response should be 3.\n\nSample Input 2\n\n15\n123 119\n129 120\n132 112\n126 109\n118 103\n115 109\n102 100\n130 120\n105 105\n132 115\n104 102\n107 107\n127 116\n121 104\n121 115\n8\n8 234\n9 244\n10 226\n11 227\n12 240\n13 237\n14 206\n15 227\n\nSample Output 2\n\n256\n255\n250\n247\n255\n259\n223\n253", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 17533, "cpu_time_ms": 3310, "memory_kb": 94120}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s702447860", "group_id": "codeNet:p02657", "input_text": "(princ (* (read) (read)))", "language": "Lisp", "metadata": {"date": 1591191999, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02657.html", "problem_id": "p02657", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02657/input.txt", "sample_output_relpath": "derived/input_output/data/p02657/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02657/Lisp/s702447860.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s702447860", "user_id": "u606976120"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(princ (* (read) (read)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nCompute A \\times B.\n\nConstraints\n\n1 \\leq A \\leq 100\n\n1 \\leq B \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the value A \\times B as an integer.\n\nSample Input 1\n\n2 5\n\nSample Output 1\n\n10\n\nWe have 2 \\times 5 = 10.\n\nSample Input 2\n\n100 100\n\nSample Output 2\n\n10000", "sample_input": "2 5\n"}, "reference_outputs": ["10\n"], "source_document_id": "p02657", "source_text": "Score : 100 points\n\nProblem Statement\n\nCompute A \\times B.\n\nConstraints\n\n1 \\leq A \\leq 100\n\n1 \\leq B \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the value A \\times B as an integer.\n\nSample Input 1\n\n2 5\n\nSample Output 1\n\n10\n\nWe have 2 \\times 5 = 10.\n\nSample Input 2\n\n100 100\n\nSample Output 2\n\n10000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 25, "cpu_time_ms": 14, "memory_kb": 24212}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s020960049", "group_id": "codeNet:p02660", "input_text": "(defun prime-array (n) ;素数列\n (let ((arr (make-array (1+ n) :element-type 'bit :initial-element 1)))\n (setf (aref arr 0) 0)\n (setf (aref arr 1) 0)\n (loop :for q :from 1 :upto n :do(if (= 1 (aref arr q))\n (loop :for a :from (* 2 q) :upto n :by q :do(setf (aref arr a) 0))))\n arr))\n(let* ((n (read))\n (pr (prime-array (ceiling (sqrt n))))\n (stk nil))\n (loop :for k :across pr\n :for a :from 0\n :if (and (= k 1) (= 0 (mod n a)))\n :do (push (cons a (loop :for p :from 1\n :if (not (= 0 (mod n (expt a p))))\n :return (1- p))) stk))\n (if stk\n (princ (loop :for k :in stk\n :sum (loop :for a :from 1\n :for b := (* 1/2 a (1+ a))\n :if (< (cdr k) b)\n :return (1- a))))\n (princ 1)))", "language": "Lisp", "metadata": {"date": 1590976569, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02660.html", "problem_id": "p02660", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02660/input.txt", "sample_output_relpath": "derived/input_output/data/p02660/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02660/Lisp/s020960049.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s020960049", "user_id": "u610490393"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun prime-array (n) ;素数列\n (let ((arr (make-array (1+ n) :element-type 'bit :initial-element 1)))\n (setf (aref arr 0) 0)\n (setf (aref arr 1) 0)\n (loop :for q :from 1 :upto n :do(if (= 1 (aref arr q))\n (loop :for a :from (* 2 q) :upto n :by q :do(setf (aref arr a) 0))))\n arr))\n(let* ((n (read))\n (pr (prime-array (ceiling (sqrt n))))\n (stk nil))\n (loop :for k :across pr\n :for a :from 0\n :if (and (= k 1) (= 0 (mod n a)))\n :do (push (cons a (loop :for p :from 1\n :if (not (= 0 (mod n (expt a p))))\n :return (1- p))) stk))\n (if stk\n (princ (loop :for k :in stk\n :sum (loop :for a :from 1\n :for b := (* 1/2 a (1+ a))\n :if (< (cdr k) b)\n :return (1- a))))\n (princ 1)))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nGiven is a positive integer N. Consider repeatedly applying the operation below on N:\n\nFirst, choose a positive integer z satisfying all of the conditions below:\n\nz can be represented as z=p^e, where p is a prime number and e is a positive integer;\n\nz divides N;\n\nz is different from all integers chosen in previous operations.\n\nThen, replace N with N/z.\n\nFind the maximum number of times the operation can be applied.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^{12}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the maximum number of times the operation can be applied.\n\nSample Input 1\n\n24\n\nSample Output 1\n\n3\n\nWe can apply the operation three times by, for example, making the following choices:\n\nChoose z=2 (=2^1). (Now we have N=12.)\n\nChoose z=3 (=3^1). (Now we have N=4.)\n\nChoose z=4 (=2^2). (Now we have N=1.)\n\nSample Input 2\n\n1\n\nSample Output 2\n\n0\n\nWe cannot apply the operation at all.\n\nSample Input 3\n\n64\n\nSample Output 3\n\n3\n\nWe can apply the operation three times by, for example, making the following choices:\n\nChoose z=2 (=2^1). (Now we have N=32.)\n\nChoose z=4 (=2^2). (Now we have N=8.)\n\nChoose z=8 (=2^3). (Now we have N=1.)\n\nSample Input 4\n\n1000000007\n\nSample Output 4\n\n1\n\nWe can apply the operation once by, for example, making the following choice:\n\nz=1000000007 (=1000000007^1). (Now we have N=1.)\n\nSample Input 5\n\n997764507000\n\nSample Output 5\n\n7", "sample_input": "24\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02660", "source_text": "Score : 400 points\n\nProblem Statement\n\nGiven is a positive integer N. Consider repeatedly applying the operation below on N:\n\nFirst, choose a positive integer z satisfying all of the conditions below:\n\nz can be represented as z=p^e, where p is a prime number and e is a positive integer;\n\nz divides N;\n\nz is different from all integers chosen in previous operations.\n\nThen, replace N with N/z.\n\nFind the maximum number of times the operation can be applied.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^{12}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the maximum number of times the operation can be applied.\n\nSample Input 1\n\n24\n\nSample Output 1\n\n3\n\nWe can apply the operation three times by, for example, making the following choices:\n\nChoose z=2 (=2^1). (Now we have N=12.)\n\nChoose z=3 (=3^1). (Now we have N=4.)\n\nChoose z=4 (=2^2). (Now we have N=1.)\n\nSample Input 2\n\n1\n\nSample Output 2\n\n0\n\nWe cannot apply the operation at all.\n\nSample Input 3\n\n64\n\nSample Output 3\n\n3\n\nWe can apply the operation three times by, for example, making the following choices:\n\nChoose z=2 (=2^1). (Now we have N=32.)\n\nChoose z=4 (=2^2). (Now we have N=8.)\n\nChoose z=8 (=2^3). (Now we have N=1.)\n\nSample Input 4\n\n1000000007\n\nSample Output 4\n\n1\n\nWe can apply the operation once by, for example, making the following choice:\n\nz=1000000007 (=1000000007^1). (Now we have N=1.)\n\nSample Input 5\n\n997764507000\n\nSample Output 5\n\n7", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 947, "cpu_time_ms": 39, "memory_kb": 24752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s268809347", "group_id": "codeNet:p02663", "input_text": "(let ((ha (read))\n (ma (read))\n (hb (read))\n (mb (read))\n (k (read)))\n\n (format t \"~D~%\"\n (- (+ (* hb 60) mb) (+ (* ha 60) ma) k)\n )\n)", "language": "Lisp", "metadata": {"date": 1600607809, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02663.html", "problem_id": "p02663", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02663/input.txt", "sample_output_relpath": "derived/input_output/data/p02663/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02663/Lisp/s268809347.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s268809347", "user_id": "u136500538"}, "prompt_components": {"gold_output": "270\n", "input_to_evaluate": "(let ((ha (read))\n (ma (read))\n (hb (read))\n (mb (read))\n (k (read)))\n\n (format t \"~D~%\"\n (- (+ (* hb 60) mb) (+ (* ha 60) ma) k)\n )\n)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIn this problem, we use the 24-hour clock.\n\nTakahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.)\nHe has decided to study for K consecutive minutes while he is up.\nWhat is the length of the period in which he can start studying?\n\nConstraints\n\n0 \\le H_1, H_2 \\le 23\n\n0 \\le M_1, M_2 \\le 59\n\nThe time H_1 : M_1 comes before the time H_2 : M_2.\n\nK \\ge 1\n\nTakahashi is up for at least K minutes.\n\nAll values in input are integers (without leading zeros).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH_1 M_1 H_2 M_2 K\n\nOutput\n\nPrint the length of the period in which he can start studying, as an integer.\n\nSample Input 1\n\n10 0 15 0 30\n\nSample Output 1\n\n270\n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly three in the afternoon.\nIt takes 30 minutes to do the study, so he can start it in the period between ten o'clock and half-past two. The length of this period is 270 minutes, so we should print 270.\n\nSample Input 2\n\n10 0 12 0 120\n\nSample Output 2\n\n0\n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly noon. It takes 120 minutes to do the study, so he has to start it at exactly ten o'clock. Thus, we should print 0.", "sample_input": "10 0 15 0 30\n"}, "reference_outputs": ["270\n"], "source_document_id": "p02663", "source_text": "Score : 100 points\n\nProblem Statement\n\nIn this problem, we use the 24-hour clock.\n\nTakahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.)\nHe has decided to study for K consecutive minutes while he is up.\nWhat is the length of the period in which he can start studying?\n\nConstraints\n\n0 \\le H_1, H_2 \\le 23\n\n0 \\le M_1, M_2 \\le 59\n\nThe time H_1 : M_1 comes before the time H_2 : M_2.\n\nK \\ge 1\n\nTakahashi is up for at least K minutes.\n\nAll values in input are integers (without leading zeros).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH_1 M_1 H_2 M_2 K\n\nOutput\n\nPrint the length of the period in which he can start studying, as an integer.\n\nSample Input 1\n\n10 0 15 0 30\n\nSample Output 1\n\n270\n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly three in the afternoon.\nIt takes 30 minutes to do the study, so he can start it in the period between ten o'clock and half-past two. The length of this period is 270 minutes, so we should print 270.\n\nSample Input 2\n\n10 0 12 0 120\n\nSample Output 2\n\n0\n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly noon. It takes 120 minutes to do the study, so he has to start it at exactly ten o'clock. Thus, we should print 0.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 159, "cpu_time_ms": 19, "memory_kb": 24076}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s140620676", "group_id": "codeNet:p02663", "input_text": "(princ\n (let ( (h_1 (read)) (m_1 (read)) (h_2 (read)) (m_2 (read)) (k (read)) )\n (- \n (+ (* h_2 60) m_2) \n (+ (* h_1 60) m_1)\n k)))\n", "language": "Lisp", "metadata": {"date": 1593309866, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02663.html", "problem_id": "p02663", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02663/input.txt", "sample_output_relpath": "derived/input_output/data/p02663/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02663/Lisp/s140620676.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s140620676", "user_id": "u526532903"}, "prompt_components": {"gold_output": "270\n", "input_to_evaluate": "(princ\n (let ( (h_1 (read)) (m_1 (read)) (h_2 (read)) (m_2 (read)) (k (read)) )\n (- \n (+ (* h_2 60) m_2) \n (+ (* h_1 60) m_1)\n k)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIn this problem, we use the 24-hour clock.\n\nTakahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.)\nHe has decided to study for K consecutive minutes while he is up.\nWhat is the length of the period in which he can start studying?\n\nConstraints\n\n0 \\le H_1, H_2 \\le 23\n\n0 \\le M_1, M_2 \\le 59\n\nThe time H_1 : M_1 comes before the time H_2 : M_2.\n\nK \\ge 1\n\nTakahashi is up for at least K minutes.\n\nAll values in input are integers (without leading zeros).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH_1 M_1 H_2 M_2 K\n\nOutput\n\nPrint the length of the period in which he can start studying, as an integer.\n\nSample Input 1\n\n10 0 15 0 30\n\nSample Output 1\n\n270\n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly three in the afternoon.\nIt takes 30 minutes to do the study, so he can start it in the period between ten o'clock and half-past two. The length of this period is 270 minutes, so we should print 270.\n\nSample Input 2\n\n10 0 12 0 120\n\nSample Output 2\n\n0\n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly noon. It takes 120 minutes to do the study, so he has to start it at exactly ten o'clock. Thus, we should print 0.", "sample_input": "10 0 15 0 30\n"}, "reference_outputs": ["270\n"], "source_document_id": "p02663", "source_text": "Score : 100 points\n\nProblem Statement\n\nIn this problem, we use the 24-hour clock.\n\nTakahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.)\nHe has decided to study for K consecutive minutes while he is up.\nWhat is the length of the period in which he can start studying?\n\nConstraints\n\n0 \\le H_1, H_2 \\le 23\n\n0 \\le M_1, M_2 \\le 59\n\nThe time H_1 : M_1 comes before the time H_2 : M_2.\n\nK \\ge 1\n\nTakahashi is up for at least K minutes.\n\nAll values in input are integers (without leading zeros).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH_1 M_1 H_2 M_2 K\n\nOutput\n\nPrint the length of the period in which he can start studying, as an integer.\n\nSample Input 1\n\n10 0 15 0 30\n\nSample Output 1\n\n270\n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly three in the afternoon.\nIt takes 30 minutes to do the study, so he can start it in the period between ten o'clock and half-past two. The length of this period is 270 minutes, so we should print 270.\n\nSample Input 2\n\n10 0 12 0 120\n\nSample Output 2\n\n0\n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly noon. It takes 120 minutes to do the study, so he has to start it at exactly ten o'clock. Thus, we should print 0.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 140, "cpu_time_ms": 17, "memory_kb": 24148}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s776995925", "group_id": "codeNet:p02663", "input_text": "(defun main ()\n (let ((h1 (read))\n (m1 (read))\n (h2 (read))\n (m2 (read))\n (k (read))\n (ans 0))\n (setf ans (- (- (+ (* h2 60) m2) (+ (* h1 60) m1)) k))\n ans))\n\n(format t \"~a~%\" (main))\n", "language": "Lisp", "metadata": {"date": 1590888894, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02663.html", "problem_id": "p02663", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02663/input.txt", "sample_output_relpath": "derived/input_output/data/p02663/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02663/Lisp/s776995925.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s776995925", "user_id": "u091381267"}, "prompt_components": {"gold_output": "270\n", "input_to_evaluate": "(defun main ()\n (let ((h1 (read))\n (m1 (read))\n (h2 (read))\n (m2 (read))\n (k (read))\n (ans 0))\n (setf ans (- (- (+ (* h2 60) m2) (+ (* h1 60) m1)) k))\n ans))\n\n(format t \"~a~%\" (main))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIn this problem, we use the 24-hour clock.\n\nTakahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.)\nHe has decided to study for K consecutive minutes while he is up.\nWhat is the length of the period in which he can start studying?\n\nConstraints\n\n0 \\le H_1, H_2 \\le 23\n\n0 \\le M_1, M_2 \\le 59\n\nThe time H_1 : M_1 comes before the time H_2 : M_2.\n\nK \\ge 1\n\nTakahashi is up for at least K minutes.\n\nAll values in input are integers (without leading zeros).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH_1 M_1 H_2 M_2 K\n\nOutput\n\nPrint the length of the period in which he can start studying, as an integer.\n\nSample Input 1\n\n10 0 15 0 30\n\nSample Output 1\n\n270\n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly three in the afternoon.\nIt takes 30 minutes to do the study, so he can start it in the period between ten o'clock and half-past two. The length of this period is 270 minutes, so we should print 270.\n\nSample Input 2\n\n10 0 12 0 120\n\nSample Output 2\n\n0\n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly noon. It takes 120 minutes to do the study, so he has to start it at exactly ten o'clock. Thus, we should print 0.", "sample_input": "10 0 15 0 30\n"}, "reference_outputs": ["270\n"], "source_document_id": "p02663", "source_text": "Score : 100 points\n\nProblem Statement\n\nIn this problem, we use the 24-hour clock.\n\nTakahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.)\nHe has decided to study for K consecutive minutes while he is up.\nWhat is the length of the period in which he can start studying?\n\nConstraints\n\n0 \\le H_1, H_2 \\le 23\n\n0 \\le M_1, M_2 \\le 59\n\nThe time H_1 : M_1 comes before the time H_2 : M_2.\n\nK \\ge 1\n\nTakahashi is up for at least K minutes.\n\nAll values in input are integers (without leading zeros).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH_1 M_1 H_2 M_2 K\n\nOutput\n\nPrint the length of the period in which he can start studying, as an integer.\n\nSample Input 1\n\n10 0 15 0 30\n\nSample Output 1\n\n270\n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly three in the afternoon.\nIt takes 30 minutes to do the study, so he can start it in the period between ten o'clock and half-past two. The length of this period is 270 minutes, so we should print 270.\n\nSample Input 2\n\n10 0 12 0 120\n\nSample Output 2\n\n0\n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly noon. It takes 120 minutes to do the study, so he has to start it at exactly ten o'clock. Thus, we should print 0.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 228, "cpu_time_ms": 14, "memory_kb": 24284}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s324822121", "group_id": "codeNet:p02663", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((h1 (read))\n (m1 (read))\n (h2 (read))\n (m2 (read))\n (k (read)))\n (println (max 0 (- (+ (* h2 60) m2)\n (+ (* h1 60) m1)\n k)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 0 15 0 30\n\"\n \"270\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 0 12 0 120\n\"\n \"0\n\")))\n", "language": "Lisp", "metadata": {"date": 1590886895, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02663.html", "problem_id": "p02663", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02663/input.txt", "sample_output_relpath": "derived/input_output/data/p02663/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02663/Lisp/s324822121.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s324822121", "user_id": "u352600849"}, "prompt_components": {"gold_output": "270\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((h1 (read))\n (m1 (read))\n (h2 (read))\n (m2 (read))\n (k (read)))\n (println (max 0 (- (+ (* h2 60) m2)\n (+ (* h1 60) m1)\n k)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 0 15 0 30\n\"\n \"270\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 0 12 0 120\n\"\n \"0\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIn this problem, we use the 24-hour clock.\n\nTakahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.)\nHe has decided to study for K consecutive minutes while he is up.\nWhat is the length of the period in which he can start studying?\n\nConstraints\n\n0 \\le H_1, H_2 \\le 23\n\n0 \\le M_1, M_2 \\le 59\n\nThe time H_1 : M_1 comes before the time H_2 : M_2.\n\nK \\ge 1\n\nTakahashi is up for at least K minutes.\n\nAll values in input are integers (without leading zeros).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH_1 M_1 H_2 M_2 K\n\nOutput\n\nPrint the length of the period in which he can start studying, as an integer.\n\nSample Input 1\n\n10 0 15 0 30\n\nSample Output 1\n\n270\n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly three in the afternoon.\nIt takes 30 minutes to do the study, so he can start it in the period between ten o'clock and half-past two. The length of this period is 270 minutes, so we should print 270.\n\nSample Input 2\n\n10 0 12 0 120\n\nSample Output 2\n\n0\n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly noon. It takes 120 minutes to do the study, so he has to start it at exactly ten o'clock. Thus, we should print 0.", "sample_input": "10 0 15 0 30\n"}, "reference_outputs": ["270\n"], "source_document_id": "p02663", "source_text": "Score : 100 points\n\nProblem Statement\n\nIn this problem, we use the 24-hour clock.\n\nTakahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.)\nHe has decided to study for K consecutive minutes while he is up.\nWhat is the length of the period in which he can start studying?\n\nConstraints\n\n0 \\le H_1, H_2 \\le 23\n\n0 \\le M_1, M_2 \\le 59\n\nThe time H_1 : M_1 comes before the time H_2 : M_2.\n\nK \\ge 1\n\nTakahashi is up for at least K minutes.\n\nAll values in input are integers (without leading zeros).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH_1 M_1 H_2 M_2 K\n\nOutput\n\nPrint the length of the period in which he can start studying, as an integer.\n\nSample Input 1\n\n10 0 15 0 30\n\nSample Output 1\n\n270\n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly three in the afternoon.\nIt takes 30 minutes to do the study, so he can start it in the period between ten o'clock and half-past two. The length of this period is 270 minutes, so we should print 270.\n\nSample Input 2\n\n10 0 12 0 120\n\nSample Output 2\n\n0\n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly noon. It takes 120 minutes to do the study, so he has to start it at exactly ten o'clock. Thus, we should print 0.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3705, "cpu_time_ms": 15, "memory_kb": 24804}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s454111161", "group_id": "codeNet:p02665", "input_text": "(defun main ()\n (let* ((n (read))\n (a (make-array `(,(+ n 2))))\n (b (make-array `(,(1+ n))))\n (m (make-array `(,(1+ n))))\n (2^n 1)\n (ans 0))\n ; memo\n ; (log (expt 10 8) 2) => 26.575424\n ;\n ; read\n (loop :for i :from 0 :to n\n :do (setf (aref a i) (read)))\n ;\n (setf (aref m n) (aref a n))\n (loop :for i :downfrom (1- n) :to 0\n :do (setf (aref m i) (+ (aref a i) (aref m (1+ i)))))\n ; init \n (setf (aref a (1+ n)) 0)\n (when (> (aref a 0) 2^n)\n (format t \"-1~%\")\n (return-from main))\n (incf ans 2^n)\n (setf (aref b 0) (- 2^n (aref a 0)))\n (setf 2^n (* 2 1))\n ;\n (loop :for i :from 1 :to n\n :do (let* ((p (aref b (1- i)))\n (c (aref a (1+ i)))\n (_max (min (* 2 p) 2^n (aref m i)))\n (_min (ceiling (/ c 2))))\n ;(format t \"S: ~A P: ~A A: ~A M: ~A ~A~%\" ans p (aref a i) _max _min)\n ; ex. case\n (when (or (> _min _max) (> 0 (- _max (aref a i))))\n (format t \"-1~%\")\n (return-from main))\n ;\n (cond ((= i n)\n (incf ans (aref a i)))\n (t\n (incf ans _max)\n (setf (aref b i) (- _max (aref a i)))\n (setf 2^n (* 2 2^n))))))\n (format t \"~A~%\" ans)))\n(main)\n", "language": "Lisp", "metadata": {"date": 1590893626, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02665.html", "problem_id": "p02665", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02665/input.txt", "sample_output_relpath": "derived/input_output/data/p02665/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02665/Lisp/s454111161.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s454111161", "user_id": "u608227593"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(defun main ()\n (let* ((n (read))\n (a (make-array `(,(+ n 2))))\n (b (make-array `(,(1+ n))))\n (m (make-array `(,(1+ n))))\n (2^n 1)\n (ans 0))\n ; memo\n ; (log (expt 10 8) 2) => 26.575424\n ;\n ; read\n (loop :for i :from 0 :to n\n :do (setf (aref a i) (read)))\n ;\n (setf (aref m n) (aref a n))\n (loop :for i :downfrom (1- n) :to 0\n :do (setf (aref m i) (+ (aref a i) (aref m (1+ i)))))\n ; init \n (setf (aref a (1+ n)) 0)\n (when (> (aref a 0) 2^n)\n (format t \"-1~%\")\n (return-from main))\n (incf ans 2^n)\n (setf (aref b 0) (- 2^n (aref a 0)))\n (setf 2^n (* 2 1))\n ;\n (loop :for i :from 1 :to n\n :do (let* ((p (aref b (1- i)))\n (c (aref a (1+ i)))\n (_max (min (* 2 p) 2^n (aref m i)))\n (_min (ceiling (/ c 2))))\n ;(format t \"S: ~A P: ~A A: ~A M: ~A ~A~%\" ans p (aref a i) _max _min)\n ; ex. case\n (when (or (> _min _max) (> 0 (- _max (aref a i))))\n (format t \"-1~%\")\n (return-from main))\n ;\n (cond ((= i n)\n (incf ans (aref a i)))\n (t\n (incf ans _max)\n (setf (aref b i) (- _max (aref a i)))\n (setf 2^n (* 2 2^n))))))\n (format t \"~A~%\" ans)))\n(main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven is an integer sequence of length N+1: A_0, A_1, A_2, \\ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \\ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.\n\nNotes\n\nA binary tree is a rooted tree such that each vertex has at most two direct children.\n\nA leaf in a binary tree is a vertex with zero children.\n\nThe depth of a vertex v in a binary tree is the distance from the tree's root to v. (The root has the depth of 0.)\n\nThe depth of a binary tree is the maximum depth of a vertex in the tree.\n\nConstraints\n\n0 \\leq N \\leq 10^5\n\n0 \\leq A_i \\leq 10^{8} (0 \\leq i \\leq N)\n\nA_N \\geq 1\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_0 A_1 A_2 \\cdots A_N\n\nOutput\n\nPrint the answer as an integer.\n\nSample Input 1\n\n3\n0 1 1 2\n\nSample Output 1\n\n7\n\nBelow is the tree with the maximum possible number of vertices. It has seven vertices, so we should print 7.\n\nSample Input 2\n\n4\n0 0 1 0 2\n\nSample Output 2\n\n10\n\nSample Input 3\n\n2\n0 3 1\n\nSample Output 3\n\n-1\n\nSample Input 4\n\n1\n1 1\n\nSample Output 4\n\n-1\n\nSample Input 5\n\n10\n0 0 1 1 2 3 5 8 13 21 34\n\nSample Output 5\n\n264", "sample_input": "3\n0 1 1 2\n"}, "reference_outputs": ["7\n"], "source_document_id": "p02665", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven is an integer sequence of length N+1: A_0, A_1, A_2, \\ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \\ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.\n\nNotes\n\nA binary tree is a rooted tree such that each vertex has at most two direct children.\n\nA leaf in a binary tree is a vertex with zero children.\n\nThe depth of a vertex v in a binary tree is the distance from the tree's root to v. (The root has the depth of 0.)\n\nThe depth of a binary tree is the maximum depth of a vertex in the tree.\n\nConstraints\n\n0 \\leq N \\leq 10^5\n\n0 \\leq A_i \\leq 10^{8} (0 \\leq i \\leq N)\n\nA_N \\geq 1\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_0 A_1 A_2 \\cdots A_N\n\nOutput\n\nPrint the answer as an integer.\n\nSample Input 1\n\n3\n0 1 1 2\n\nSample Output 1\n\n7\n\nBelow is the tree with the maximum possible number of vertices. It has seven vertices, so we should print 7.\n\nSample Input 2\n\n4\n0 0 1 0 2\n\nSample Output 2\n\n10\n\nSample Input 3\n\n2\n0 3 1\n\nSample Output 3\n\n-1\n\nSample Input 4\n\n1\n1 1\n\nSample Output 4\n\n-1\n\nSample Input 5\n\n10\n0 0 1 1 2 3 5 8 13 21 34\n\nSample Output 5\n\n264", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1446, "cpu_time_ms": 382, "memory_kb": 102744}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s819474955", "group_id": "codeNet:p02669", "input_text": "(defvar ht (make-hash-table :test 'equal))\n\n(defun solve-upper (x A B C D)\n (cond \n ((= x 0) 0)\n (#1=(gethash x ht) #1#)\n (t (setf #1# (min (* x D)\n (+ C (* D (mod x 5))\n (solve-upper (floor x 5) A B C D))\n (+ B (* D (mod x 3))\n (solve-upper (floor x 3) A B C D))\n (+ A (* D (mod x 2))\n (solve-upper (floor x 2) A B C D))))))) \n\n(defun solve-lower (x A B C D)\n (cond \n ((= x 0) 0)\n (#1=(gethash x ht) #1#)\n (t (setf #1# (min (* x D)\n (+ C (* D (mod (- x) 5))\n (solve-upper (ceiling x 5) A B C D))\n (+ B (* D (mod (- x) 3))\n (solve-upper (ceiling x 3) A B C D))\n (+ A (* D (mod (- x) 2))\n (solve-upper (ceiling x 2) A B C D)))))))\n\n(defun solve (N A B C D)\n (let (upper lower)\n (clrhash ht)\n (setf upper (solve-upper N A B C D))\n (clrhash ht)\n (setf lower (solve-lower N A B C D))\n (princ (min lower upper))\n (terpri)))\n\n(loop repeat (read) do\n (solve (read) (read) (read) (read) (read)))\n\n", "language": "Lisp", "metadata": {"date": 1590288183, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02669.html", "problem_id": "p02669", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02669/input.txt", "sample_output_relpath": "derived/input_output/data/p02669/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02669/Lisp/s819474955.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s819474955", "user_id": "u334552723"}, "prompt_components": {"gold_output": "20\n19\n26\n3821859835\n23441258666\n", "input_to_evaluate": "(defvar ht (make-hash-table :test 'equal))\n\n(defun solve-upper (x A B C D)\n (cond \n ((= x 0) 0)\n (#1=(gethash x ht) #1#)\n (t (setf #1# (min (* x D)\n (+ C (* D (mod x 5))\n (solve-upper (floor x 5) A B C D))\n (+ B (* D (mod x 3))\n (solve-upper (floor x 3) A B C D))\n (+ A (* D (mod x 2))\n (solve-upper (floor x 2) A B C D))))))) \n\n(defun solve-lower (x A B C D)\n (cond \n ((= x 0) 0)\n (#1=(gethash x ht) #1#)\n (t (setf #1# (min (* x D)\n (+ C (* D (mod (- x) 5))\n (solve-upper (ceiling x 5) A B C D))\n (+ B (* D (mod (- x) 3))\n (solve-upper (ceiling x 3) A B C D))\n (+ A (* D (mod (- x) 2))\n (solve-upper (ceiling x 2) A B C D)))))))\n\n(defun solve (N A B C D)\n (let (upper lower)\n (clrhash ht)\n (setf upper (solve-upper N A B C D))\n (clrhash ht)\n (setf lower (solve-lower N A B C D))\n (princ (min lower upper))\n (terpri)))\n\n(loop repeat (read) do\n (solve (read) (read) (read) (read) (read)))\n\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYou start with the number 0 and you want to reach the number N.\n\nYou can change the number, paying a certain amount of coins, with the following operations:\n\nMultiply the number by 2, paying A coins.\n\nMultiply the number by 3, paying B coins.\n\nMultiply the number by 5, paying C coins.\n\nIncrease or decrease the number by 1, paying D coins.\n\nYou can perform these operations in arbitrary order and an arbitrary number of times.\n\nWhat is the minimum number of coins you need to reach N?\n\nYou have to solve T testcases.\n\nConstraints\n\n1 \\le T \\le 10\n\n1 \\le N \\le 10^{18}\n\n1 \\le A, B, C, D \\le 10^9\n\nAll numbers N, A, B, C, D are integers.\n\nInput\n\nThe input is given from Standard Input. The first line of the input is\n\nT\n\nThen, T lines follow describing the T testcases.\nEach of the T lines has the format\n\nN A B C D\n\nOutput\n\nFor each testcase, print the answer on Standard Output followed by a newline.\n\nSample Input 1\n\n5\n11 1 2 4 8\n11 1 2 2 8\n32 10 8 5 4\n29384293847243 454353412 332423423 934923490 1\n900000000000000000 332423423 454353412 934923490 987654321\n\nSample Output 1\n\n20\n19\n26\n3821859835\n23441258666\n\nFor the first testcase, a sequence of moves that achieves the minimum cost of 20 is:\n\nInitially x = 0.\n\nPay 8 to increase by 1 (x = 1).\n\nPay 1 to multiply by 2 (x = 2).\n\nPay 1 to multiply by 2 (x = 4).\n\nPay 2 to multiply by 3 (x = 12).\n\nPay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of 19 is:\n\nInitially x = 0.\n\nPay 8 to increase by 1 (x = 1).\n\nPay 1 to multiply by 2 (x = 2).\n\nPay 2 to multiply by 5 (x = 10).\n\nPay 8 to increase by 1 (x = 11).", "sample_input": "5\n11 1 2 4 8\n11 1 2 2 8\n32 10 8 5 4\n29384293847243 454353412 332423423 934923490 1\n900000000000000000 332423423 454353412 934923490 987654321\n"}, "reference_outputs": ["20\n19\n26\n3821859835\n23441258666\n"], "source_document_id": "p02669", "source_text": "Score : 400 points\n\nProblem Statement\n\nYou start with the number 0 and you want to reach the number N.\n\nYou can change the number, paying a certain amount of coins, with the following operations:\n\nMultiply the number by 2, paying A coins.\n\nMultiply the number by 3, paying B coins.\n\nMultiply the number by 5, paying C coins.\n\nIncrease or decrease the number by 1, paying D coins.\n\nYou can perform these operations in arbitrary order and an arbitrary number of times.\n\nWhat is the minimum number of coins you need to reach N?\n\nYou have to solve T testcases.\n\nConstraints\n\n1 \\le T \\le 10\n\n1 \\le N \\le 10^{18}\n\n1 \\le A, B, C, D \\le 10^9\n\nAll numbers N, A, B, C, D are integers.\n\nInput\n\nThe input is given from Standard Input. The first line of the input is\n\nT\n\nThen, T lines follow describing the T testcases.\nEach of the T lines has the format\n\nN A B C D\n\nOutput\n\nFor each testcase, print the answer on Standard Output followed by a newline.\n\nSample Input 1\n\n5\n11 1 2 4 8\n11 1 2 2 8\n32 10 8 5 4\n29384293847243 454353412 332423423 934923490 1\n900000000000000000 332423423 454353412 934923490 987654321\n\nSample Output 1\n\n20\n19\n26\n3821859835\n23441258666\n\nFor the first testcase, a sequence of moves that achieves the minimum cost of 20 is:\n\nInitially x = 0.\n\nPay 8 to increase by 1 (x = 1).\n\nPay 1 to multiply by 2 (x = 2).\n\nPay 1 to multiply by 2 (x = 4).\n\nPay 2 to multiply by 3 (x = 12).\n\nPay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of 19 is:\n\nInitially x = 0.\n\nPay 8 to increase by 1 (x = 1).\n\nPay 1 to multiply by 2 (x = 2).\n\nPay 2 to multiply by 5 (x = 10).\n\nPay 8 to increase by 1 (x = 11).", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1222, "cpu_time_ms": 44, "memory_kb": 25916}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s534906992", "group_id": "codeNet:p02670", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline shuffle!))\n(defun shuffle! (vector &optional (start 0) end)\n \"Destructively shuffles VECTOR by Fisher-Yates algorithm.\"\n (declare (vector vector)\n ((mod #.array-total-size-limit) start)\n ((or null (mod #.array-total-size-limit)) end))\n (loop for i from (- (or end (length vector)) 1) above start\n for j = (+ start (random (- (+ i 1) start)))\n do (rotatef (aref vector i) (aref vector j)))\n vector)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(declaim (inline println-matrix))\n(defun println-matrix (array &key (separator #\\ ) (key #'identity) (writer #'write) (row-start 0) row-end (col-start 0) col-end)\n \"Prints a 2-dimensional array.\"\n (declare ((array * (* *)) array)\n ((integer 0 #.most-positive-fixnum) row-start col-start))\n (let ((row-end (or row-end (array-dimension array 0)))\n (col-end (or col-end (array-dimension array 1))))\n (declare ((integer 0 #.most-positive-fixnum) row-end col-end))\n (loop for i from row-start below row-end\n do (loop for j from col-start below col-end\n unless (= j col-start)\n do (princ separator)\n do (funcall writer (funcall key (aref array i j))))\n (terpri))))\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun test (n seq)\n (let ((mat (make-array (list n n) :element-type 'uint32 :initial-element #xffffffff))\n (plan (make-array (list n n) :element-type 'bit :initial-element 0))\n (res 0))\n (labels ((%get (i j)\n ;; (dbg i j)\n (if (and (<= 0 i (- n 1))\n (<= 0 j (- n 1)))\n (aref mat i j)\n 0))\n (decode (p)\n (multiple-value-bind (quot rem) (floor (- p 1) n)\n (values quot rem))))\n (sb-int:dovector (p (reverse seq))\n (multiple-value-bind (i j) (decode p)\n (setf (aref plan i j) 1))\n (fill (array-storage-vector mat) #xffffffff)\n (dotimes (_ (* n n))\n (dotimes (i n)\n (dotimes (j n)\n (let ((res (min (%get (- i 1) j)\n (%get (+ i 1) j)\n (%get i (- j 1))\n (%get i (+ j 1)))))\n (if (= (aref plan i j) 1)\n (minf (aref mat i j) (+ res 1))\n (minf (aref mat i j) res))))))\n (multiple-value-bind (i j) (decode p)\n (setf (aref plan i j) 1)\n (incf res (- (aref mat i j) 1)))\n ;; (println-matrix mat)\n )\n res)))\n\n(defun bench (n sample)\n (loop repeat sample\n do (let ((vec (make-array (* n n) :element-type 'uint31)))\n (dotimes (i (* n n))\n (setf (aref vec i) (+ i 1)))\n (shuffle! vec)\n (assert (= (test n vec) (solve n vec))))))\n\n(defun solve (n ps)\n (declare #.OPT\n (uint16 n)\n ((simple-array uint31 (*)) ps))\n (let* (;; 0-bit: up, 1: down, 2: left, 3: right\n (dists (make-array '(500 500) :element-type 'uint8 :initial-element 0))\n (plan (make-array '(500 500) :element-type 'bit :initial-element 1))\n (que-i (make-array #.(* 500 500) :element-type 'uint16))\n (que-j (make-array #.(* 500 500) :element-type 'uint16))\n (front 0)\n (end 0)\n (res 0))\n (declare (uint16 n)\n (uint32 res front end))\n (dotimes (i (* n n))\n (setf (aref ps i) (- (aref ps i) 1)))\n (dotimes (i n)\n (dotimes (j n)\n (setf (aref dists i j)\n (min (+ i 1) (+ j 1) (- n i) (- n j)))))\n (labels ((enqueue (i j)\n (setf (aref que-i end) i\n (aref que-j end) j)\n (incf end))\n (queue-reinitialize ()\n (setq front 0 end 0))\n (visit (new-i new-j prev-dist)\n (declare (int32 new-i new-j prev-dist))\n (when (and (<= 0 new-i (- n 1))\n (<= 0 new-j (- n 1)))\n (let ((new-dist (+ prev-dist (aref plan new-i new-j))))\n (when (< new-dist (aref dists new-i new-j))\n (setf (aref dists new-i new-j) new-dist)\n (enqueue new-i new-j))))))\n (sb-int:dovector (p ps)\n (queue-reinitialize)\n (multiple-value-bind (i j) (floor p n)\n (decf (aref dists i j))\n (incf res (aref dists i j))\n (setf (aref plan i j) 0)\n (enqueue i j)\n (loop until (= front end)\n do (let* ((i (aref que-i front))\n (j (aref que-j front))\n (dist (aref dists i j)))\n (incf front)\n (visit (- i 1) j dist)\n (visit (+ i 1) j dist)\n (visit i (- j 1) dist)\n (visit i (+ j 1) dist)))))\n res)))\n\n(defun main ()\n (let* ((n (read))\n (ps (make-array (* n n) :element-type 'uint31 :initial-element 0)))\n (dotimes (i (* n n))\n (setf (aref ps i) (read-fixnum)))\n (println (solve n ps))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"500~%\")\n (let ((vec (make-array (* 500 500))))\n (dotimes (i (* 500 500))\n (setf (aref vec i) (+ i 1)))\n (shuffle! vec)\n (dotimes (i (* 500 500))\n (println (aref vec i) out)))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 3 7 9 5 4 8 6 2\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30\n\"\n \"11\n\")))\n", "language": "Lisp", "metadata": {"date": 1590301221, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02670.html", "problem_id": "p02670", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02670/input.txt", "sample_output_relpath": "derived/input_output/data/p02670/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02670/Lisp/s534906992.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s534906992", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline shuffle!))\n(defun shuffle! (vector &optional (start 0) end)\n \"Destructively shuffles VECTOR by Fisher-Yates algorithm.\"\n (declare (vector vector)\n ((mod #.array-total-size-limit) start)\n ((or null (mod #.array-total-size-limit)) end))\n (loop for i from (- (or end (length vector)) 1) above start\n for j = (+ start (random (- (+ i 1) start)))\n do (rotatef (aref vector i) (aref vector j)))\n vector)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(declaim (inline println-matrix))\n(defun println-matrix (array &key (separator #\\ ) (key #'identity) (writer #'write) (row-start 0) row-end (col-start 0) col-end)\n \"Prints a 2-dimensional array.\"\n (declare ((array * (* *)) array)\n ((integer 0 #.most-positive-fixnum) row-start col-start))\n (let ((row-end (or row-end (array-dimension array 0)))\n (col-end (or col-end (array-dimension array 1))))\n (declare ((integer 0 #.most-positive-fixnum) row-end col-end))\n (loop for i from row-start below row-end\n do (loop for j from col-start below col-end\n unless (= j col-start)\n do (princ separator)\n do (funcall writer (funcall key (aref array i j))))\n (terpri))))\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun test (n seq)\n (let ((mat (make-array (list n n) :element-type 'uint32 :initial-element #xffffffff))\n (plan (make-array (list n n) :element-type 'bit :initial-element 0))\n (res 0))\n (labels ((%get (i j)\n ;; (dbg i j)\n (if (and (<= 0 i (- n 1))\n (<= 0 j (- n 1)))\n (aref mat i j)\n 0))\n (decode (p)\n (multiple-value-bind (quot rem) (floor (- p 1) n)\n (values quot rem))))\n (sb-int:dovector (p (reverse seq))\n (multiple-value-bind (i j) (decode p)\n (setf (aref plan i j) 1))\n (fill (array-storage-vector mat) #xffffffff)\n (dotimes (_ (* n n))\n (dotimes (i n)\n (dotimes (j n)\n (let ((res (min (%get (- i 1) j)\n (%get (+ i 1) j)\n (%get i (- j 1))\n (%get i (+ j 1)))))\n (if (= (aref plan i j) 1)\n (minf (aref mat i j) (+ res 1))\n (minf (aref mat i j) res))))))\n (multiple-value-bind (i j) (decode p)\n (setf (aref plan i j) 1)\n (incf res (- (aref mat i j) 1)))\n ;; (println-matrix mat)\n )\n res)))\n\n(defun bench (n sample)\n (loop repeat sample\n do (let ((vec (make-array (* n n) :element-type 'uint31)))\n (dotimes (i (* n n))\n (setf (aref vec i) (+ i 1)))\n (shuffle! vec)\n (assert (= (test n vec) (solve n vec))))))\n\n(defun solve (n ps)\n (declare #.OPT\n (uint16 n)\n ((simple-array uint31 (*)) ps))\n (let* (;; 0-bit: up, 1: down, 2: left, 3: right\n (dists (make-array '(500 500) :element-type 'uint8 :initial-element 0))\n (plan (make-array '(500 500) :element-type 'bit :initial-element 1))\n (que-i (make-array #.(* 500 500) :element-type 'uint16))\n (que-j (make-array #.(* 500 500) :element-type 'uint16))\n (front 0)\n (end 0)\n (res 0))\n (declare (uint16 n)\n (uint32 res front end))\n (dotimes (i (* n n))\n (setf (aref ps i) (- (aref ps i) 1)))\n (dotimes (i n)\n (dotimes (j n)\n (setf (aref dists i j)\n (min (+ i 1) (+ j 1) (- n i) (- n j)))))\n (labels ((enqueue (i j)\n (setf (aref que-i end) i\n (aref que-j end) j)\n (incf end))\n (queue-reinitialize ()\n (setq front 0 end 0))\n (visit (new-i new-j prev-dist)\n (declare (int32 new-i new-j prev-dist))\n (when (and (<= 0 new-i (- n 1))\n (<= 0 new-j (- n 1)))\n (let ((new-dist (+ prev-dist (aref plan new-i new-j))))\n (when (< new-dist (aref dists new-i new-j))\n (setf (aref dists new-i new-j) new-dist)\n (enqueue new-i new-j))))))\n (sb-int:dovector (p ps)\n (queue-reinitialize)\n (multiple-value-bind (i j) (floor p n)\n (decf (aref dists i j))\n (incf res (aref dists i j))\n (setf (aref plan i j) 0)\n (enqueue i j)\n (loop until (= front end)\n do (let* ((i (aref que-i front))\n (j (aref que-j front))\n (dist (aref dists i j)))\n (incf front)\n (visit (- i 1) j dist)\n (visit (+ i 1) j dist)\n (visit i (- j 1) dist)\n (visit i (+ j 1) dist)))))\n res)))\n\n(defun main ()\n (let* ((n (read))\n (ps (make-array (* n n) :element-type 'uint31 :initial-element 0)))\n (dotimes (i (* n n))\n (setf (aref ps i) (read-fixnum)))\n (println (solve n ps))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"500~%\")\n (let ((vec (make-array (* 500 500))))\n (dotimes (i (* 500 500))\n (setf (aref vec i) (+ i 1)))\n (shuffle! vec)\n (dotimes (i (* 500 500))\n (println (aref vec i) out)))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 3 7 9 5 4 8 6 2\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30\n\"\n \"11\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nTonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\\times N square. We denote with 1, 2,\\dots, N the viewers in the first row (from left to right); with N+1, \\dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\\dots, N^2.\n\nAt the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat.\nTo exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column).\nWhile leaving the cinema, it might be that a certain viewer x goes through a seat currently occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever.\n\nCompute the number of pairs of viewers (x, y) such that y will hate x forever.\n\nConstraints\n\n2 \\le N \\le 500\n\nThe sequence P_1, P_2, \\dots, P_{N^2} is a permutation of \\{1, 2, \\dots, N^2\\}.\n\nInput\n\nThe input is given from Standard Input in the format\n\nN\nP_1 P_2 \\cdots P_{N^2}\n\nOutput\n\nIf ans is the number of pairs of viewers described in the statement, you should print on Standard Output\n\nans\n\nSample Input 1\n\n3\n1 3 7 9 5 4 8 6 2\n\nSample Output 1\n\n1\n\nBefore the end of the movie, the viewers are arranged in the cinema as follows:\n\n1 2 3\n4 5 6\n7 8 9\n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema without going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are currently seated while leaving the cinema; hence he will be hated by at least one of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2) without going through any occupied seat (actually, they can leave the cinema without going through any seat at all).\n\nSample Input 2\n\n4\n6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8\n\nSample Output 2\n\n3\n\nSample Input 3\n\n6\n11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30\n\nSample Output 3\n\n11", "sample_input": "3\n1 3 7 9 5 4 8 6 2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02670", "source_text": "Score : 700 points\n\nProblem Statement\n\nTonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\\times N square. We denote with 1, 2,\\dots, N the viewers in the first row (from left to right); with N+1, \\dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\\dots, N^2.\n\nAt the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat.\nTo exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column).\nWhile leaving the cinema, it might be that a certain viewer x goes through a seat currently occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever.\n\nCompute the number of pairs of viewers (x, y) such that y will hate x forever.\n\nConstraints\n\n2 \\le N \\le 500\n\nThe sequence P_1, P_2, \\dots, P_{N^2} is a permutation of \\{1, 2, \\dots, N^2\\}.\n\nInput\n\nThe input is given from Standard Input in the format\n\nN\nP_1 P_2 \\cdots P_{N^2}\n\nOutput\n\nIf ans is the number of pairs of viewers described in the statement, you should print on Standard Output\n\nans\n\nSample Input 1\n\n3\n1 3 7 9 5 4 8 6 2\n\nSample Output 1\n\n1\n\nBefore the end of the movie, the viewers are arranged in the cinema as follows:\n\n1 2 3\n4 5 6\n7 8 9\n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema without going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are currently seated while leaving the cinema; hence he will be hated by at least one of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2) without going through any occupied seat (actually, they can leave the cinema without going through any seat at all).\n\nSample Input 2\n\n4\n6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8\n\nSample Output 2\n\n3\n\nSample Input 3\n\n6\n11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30\n\nSample Output 3\n\n11", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10333, "cpu_time_ms": 767, "memory_kb": 27136}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s900709260", "group_id": "codeNet:p02670", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline shuffle!))\n(defun shuffle! (vector &optional (start 0) end)\n \"Destructively shuffles VECTOR by Fisher-Yates algorithm.\"\n (declare (vector vector)\n ((mod #.array-total-size-limit) start)\n ((or null (mod #.array-total-size-limit)) end))\n (loop for i from (- (or end (length vector)) 1) above start\n for j = (+ start (random (- (+ i 1) start)))\n do (rotatef (aref vector i) (aref vector j)))\n vector)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(declaim (inline println-matrix))\n(defun println-matrix (array &key (separator #\\ ) (key #'identity) (writer #'write) (row-start 0) row-end (col-start 0) col-end)\n \"Prints a 2-dimensional array.\"\n (declare ((array * (* *)) array)\n ((integer 0 #.most-positive-fixnum) row-start col-start))\n (let ((row-end (or row-end (array-dimension array 0)))\n (col-end (or col-end (array-dimension array 1))))\n (declare ((integer 0 #.most-positive-fixnum) row-end col-end))\n (loop for i from row-start below row-end\n do (loop for j from col-start below col-end\n unless (= j col-start)\n do (princ separator)\n do (funcall writer (funcall key (aref array i j))))\n (terpri))))\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun test (n seq)\n (let ((mat (make-array (list n n) :element-type 'uint32 :initial-element #xffffffff))\n (plan (make-array (list n n) :element-type 'bit :initial-element 0))\n (res 0))\n (labels ((%get (i j)\n ;; (dbg i j)\n (if (and (<= 0 i (- n 1))\n (<= 0 j (- n 1)))\n (aref mat i j)\n 0))\n (decode (p)\n (multiple-value-bind (quot rem) (floor (- p 1) n)\n (values quot rem))))\n (sb-int:dovector (p (reverse seq))\n (multiple-value-bind (i j) (decode p)\n (setf (aref plan i j) 1))\n (fill (array-storage-vector mat) #xffffffff)\n (dotimes (_ (* n n))\n (dotimes (i n)\n (dotimes (j n)\n (let ((res (min (%get (- i 1) j)\n (%get (+ i 1) j)\n (%get i (- j 1))\n (%get i (+ j 1)))))\n (if (= (aref plan i j) 1)\n (minf (aref mat i j) (+ res 1))\n (minf (aref mat i j) res))))))\n (multiple-value-bind (i j) (decode p)\n (setf (aref plan i j) 1)\n (incf res (- (aref mat i j) 1)))\n ;; (println-matrix mat)\n )\n res)))\n\n(defun bench (n sample)\n (loop repeat sample\n do (let ((vec (make-array (* n n) :element-type 'uint31)))\n (dotimes (i (* n n))\n (setf (aref vec i) (+ i 1)))\n (shuffle! vec)\n (assert (= (test n vec) (solve n vec))))))\n\n(defun solve (n ps)\n (declare #.OPT\n (uint16 n)\n ((simple-array uint31 (*)) ps))\n (let* (;; 0-bit: up, 1: down, 2: left, 3: right\n (dists (make-array '(500 500) :element-type 'uint8 :initial-element 0))\n (plan (make-array '(500 500) :element-type 'bit :initial-element 1))\n (que-i (make-array #.(* 500 500) :element-type 'uint16))\n (que-j (make-array #.(* 500 500) :element-type 'uint16))\n (front 0)\n (end 0)\n (res 0))\n (declare (uint16 n)\n (uint32 res front end))\n (dotimes (i (* n n))\n (setf (aref ps i) (- (aref ps i) 1)))\n (dotimes (i n)\n (dotimes (j n)\n (setf (aref dists i j)\n (min (+ i 1) (+ j 1) (- n i) (- n j)))))\n (labels ((enqueue (i j)\n (setf (aref que-i end) i\n (aref que-j end) j)\n (incf end))\n (dequeue ()\n (multiple-value-prog1\n (values (aref que-i front) (aref que-j front))\n (incf front)))\n (queue-reinitialize ()\n (setq front 0 end 0))\n (visit (new-i new-j prev-dist)\n (declare (int32 new-i new-j prev-dist))\n (when (and (<= 0 new-i (- n 1))\n (<= 0 new-j (- n 1)))\n (let ((new-dist (+ prev-dist (aref plan new-i new-j))))\n (when (< new-dist (aref dists new-i new-j))\n (setf (aref dists new-i new-j) new-dist)\n (enqueue new-i new-j))))))\n (sb-int:dovector (p ps)\n (queue-reinitialize)\n (multiple-value-bind (i j) (floor p n)\n (decf (aref dists i j))\n (incf res (aref dists i j))\n (setf (aref plan i j) 0)\n (enqueue i j)\n (loop until (= front end)\n do (multiple-value-bind (i j) (dequeue)\n (let ((dist (aref dists i j)))\n (visit (- i 1) j dist)\n (visit (+ i 1) j dist)\n (visit i (- j 1) dist)\n (visit i (+ j 1) dist))))))\n res)))\n\n(defun main ()\n (let* ((n (read))\n (ps (make-array (* n n) :element-type 'uint31 :initial-element 0)))\n (dotimes (i (* n n))\n (setf (aref ps i) (read-fixnum)))\n (println (solve n ps))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"500~%\")\n (let ((vec (make-array (* 500 500))))\n (dotimes (i (* 500 500))\n (setf (aref vec i) (+ i 1)))\n (shuffle! vec)\n (dotimes (i (* 500 500))\n (println (aref vec i) out)))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 3 7 9 5 4 8 6 2\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30\n\"\n \"11\n\")))\n", "language": "Lisp", "metadata": {"date": 1590301148, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02670.html", "problem_id": "p02670", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02670/input.txt", "sample_output_relpath": "derived/input_output/data/p02670/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02670/Lisp/s900709260.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s900709260", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline shuffle!))\n(defun shuffle! (vector &optional (start 0) end)\n \"Destructively shuffles VECTOR by Fisher-Yates algorithm.\"\n (declare (vector vector)\n ((mod #.array-total-size-limit) start)\n ((or null (mod #.array-total-size-limit)) end))\n (loop for i from (- (or end (length vector)) 1) above start\n for j = (+ start (random (- (+ i 1) start)))\n do (rotatef (aref vector i) (aref vector j)))\n vector)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(declaim (inline println-matrix))\n(defun println-matrix (array &key (separator #\\ ) (key #'identity) (writer #'write) (row-start 0) row-end (col-start 0) col-end)\n \"Prints a 2-dimensional array.\"\n (declare ((array * (* *)) array)\n ((integer 0 #.most-positive-fixnum) row-start col-start))\n (let ((row-end (or row-end (array-dimension array 0)))\n (col-end (or col-end (array-dimension array 1))))\n (declare ((integer 0 #.most-positive-fixnum) row-end col-end))\n (loop for i from row-start below row-end\n do (loop for j from col-start below col-end\n unless (= j col-start)\n do (princ separator)\n do (funcall writer (funcall key (aref array i j))))\n (terpri))))\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun test (n seq)\n (let ((mat (make-array (list n n) :element-type 'uint32 :initial-element #xffffffff))\n (plan (make-array (list n n) :element-type 'bit :initial-element 0))\n (res 0))\n (labels ((%get (i j)\n ;; (dbg i j)\n (if (and (<= 0 i (- n 1))\n (<= 0 j (- n 1)))\n (aref mat i j)\n 0))\n (decode (p)\n (multiple-value-bind (quot rem) (floor (- p 1) n)\n (values quot rem))))\n (sb-int:dovector (p (reverse seq))\n (multiple-value-bind (i j) (decode p)\n (setf (aref plan i j) 1))\n (fill (array-storage-vector mat) #xffffffff)\n (dotimes (_ (* n n))\n (dotimes (i n)\n (dotimes (j n)\n (let ((res (min (%get (- i 1) j)\n (%get (+ i 1) j)\n (%get i (- j 1))\n (%get i (+ j 1)))))\n (if (= (aref plan i j) 1)\n (minf (aref mat i j) (+ res 1))\n (minf (aref mat i j) res))))))\n (multiple-value-bind (i j) (decode p)\n (setf (aref plan i j) 1)\n (incf res (- (aref mat i j) 1)))\n ;; (println-matrix mat)\n )\n res)))\n\n(defun bench (n sample)\n (loop repeat sample\n do (let ((vec (make-array (* n n) :element-type 'uint31)))\n (dotimes (i (* n n))\n (setf (aref vec i) (+ i 1)))\n (shuffle! vec)\n (assert (= (test n vec) (solve n vec))))))\n\n(defun solve (n ps)\n (declare #.OPT\n (uint16 n)\n ((simple-array uint31 (*)) ps))\n (let* (;; 0-bit: up, 1: down, 2: left, 3: right\n (dists (make-array '(500 500) :element-type 'uint8 :initial-element 0))\n (plan (make-array '(500 500) :element-type 'bit :initial-element 1))\n (que-i (make-array #.(* 500 500) :element-type 'uint16))\n (que-j (make-array #.(* 500 500) :element-type 'uint16))\n (front 0)\n (end 0)\n (res 0))\n (declare (uint16 n)\n (uint32 res front end))\n (dotimes (i (* n n))\n (setf (aref ps i) (- (aref ps i) 1)))\n (dotimes (i n)\n (dotimes (j n)\n (setf (aref dists i j)\n (min (+ i 1) (+ j 1) (- n i) (- n j)))))\n (labels ((enqueue (i j)\n (setf (aref que-i end) i\n (aref que-j end) j)\n (incf end))\n (dequeue ()\n (multiple-value-prog1\n (values (aref que-i front) (aref que-j front))\n (incf front)))\n (queue-reinitialize ()\n (setq front 0 end 0))\n (visit (new-i new-j prev-dist)\n (declare (int32 new-i new-j prev-dist))\n (when (and (<= 0 new-i (- n 1))\n (<= 0 new-j (- n 1)))\n (let ((new-dist (+ prev-dist (aref plan new-i new-j))))\n (when (< new-dist (aref dists new-i new-j))\n (setf (aref dists new-i new-j) new-dist)\n (enqueue new-i new-j))))))\n (sb-int:dovector (p ps)\n (queue-reinitialize)\n (multiple-value-bind (i j) (floor p n)\n (decf (aref dists i j))\n (incf res (aref dists i j))\n (setf (aref plan i j) 0)\n (enqueue i j)\n (loop until (= front end)\n do (multiple-value-bind (i j) (dequeue)\n (let ((dist (aref dists i j)))\n (visit (- i 1) j dist)\n (visit (+ i 1) j dist)\n (visit i (- j 1) dist)\n (visit i (+ j 1) dist))))))\n res)))\n\n(defun main ()\n (let* ((n (read))\n (ps (make-array (* n n) :element-type 'uint31 :initial-element 0)))\n (dotimes (i (* n n))\n (setf (aref ps i) (read-fixnum)))\n (println (solve n ps))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"500~%\")\n (let ((vec (make-array (* 500 500))))\n (dotimes (i (* 500 500))\n (setf (aref vec i) (+ i 1)))\n (shuffle! vec)\n (dotimes (i (* 500 500))\n (println (aref vec i) out)))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 3 7 9 5 4 8 6 2\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30\n\"\n \"11\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nTonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\\times N square. We denote with 1, 2,\\dots, N the viewers in the first row (from left to right); with N+1, \\dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\\dots, N^2.\n\nAt the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat.\nTo exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column).\nWhile leaving the cinema, it might be that a certain viewer x goes through a seat currently occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever.\n\nCompute the number of pairs of viewers (x, y) such that y will hate x forever.\n\nConstraints\n\n2 \\le N \\le 500\n\nThe sequence P_1, P_2, \\dots, P_{N^2} is a permutation of \\{1, 2, \\dots, N^2\\}.\n\nInput\n\nThe input is given from Standard Input in the format\n\nN\nP_1 P_2 \\cdots P_{N^2}\n\nOutput\n\nIf ans is the number of pairs of viewers described in the statement, you should print on Standard Output\n\nans\n\nSample Input 1\n\n3\n1 3 7 9 5 4 8 6 2\n\nSample Output 1\n\n1\n\nBefore the end of the movie, the viewers are arranged in the cinema as follows:\n\n1 2 3\n4 5 6\n7 8 9\n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema without going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are currently seated while leaving the cinema; hence he will be hated by at least one of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2) without going through any occupied seat (actually, they can leave the cinema without going through any seat at all).\n\nSample Input 2\n\n4\n6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8\n\nSample Output 2\n\n3\n\nSample Input 3\n\n6\n11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30\n\nSample Output 3\n\n11", "sample_input": "3\n1 3 7 9 5 4 8 6 2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02670", "source_text": "Score : 700 points\n\nProblem Statement\n\nTonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\\times N square. We denote with 1, 2,\\dots, N the viewers in the first row (from left to right); with N+1, \\dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\\dots, N^2.\n\nAt the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat.\nTo exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column).\nWhile leaving the cinema, it might be that a certain viewer x goes through a seat currently occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever.\n\nCompute the number of pairs of viewers (x, y) such that y will hate x forever.\n\nConstraints\n\n2 \\le N \\le 500\n\nThe sequence P_1, P_2, \\dots, P_{N^2} is a permutation of \\{1, 2, \\dots, N^2\\}.\n\nInput\n\nThe input is given from Standard Input in the format\n\nN\nP_1 P_2 \\cdots P_{N^2}\n\nOutput\n\nIf ans is the number of pairs of viewers described in the statement, you should print on Standard Output\n\nans\n\nSample Input 1\n\n3\n1 3 7 9 5 4 8 6 2\n\nSample Output 1\n\n1\n\nBefore the end of the movie, the viewers are arranged in the cinema as follows:\n\n1 2 3\n4 5 6\n7 8 9\n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema without going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are currently seated while leaving the cinema; hence he will be hated by at least one of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2) without going through any occupied seat (actually, they can leave the cinema without going through any seat at all).\n\nSample Input 2\n\n4\n6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8\n\nSample Output 2\n\n3\n\nSample Input 3\n\n6\n11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30\n\nSample Output 3\n\n11", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10427, "cpu_time_ms": 767, "memory_kb": 27292}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s077739620", "group_id": "codeNet:p02676", "input_text": "(defmacro string+ (&rest str)\n `(concatenate 'string ,@str))\n\n(defun main (k str)\n (if (< (length str) k)\n str\n (string+ (subseq str 0 7) \"...\")))\n\n(princ\n (main (read) (read-line)))\n", "language": "Lisp", "metadata": {"date": 1601277138, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02676.html", "problem_id": "p02676", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02676/input.txt", "sample_output_relpath": "derived/input_output/data/p02676/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02676/Lisp/s077739620.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s077739620", "user_id": "u761519515"}, "prompt_components": {"gold_output": "nikoand...\n", "input_to_evaluate": "(defmacro string+ (&rest str)\n `(concatenate 'string ,@str))\n\n(defun main (k str)\n (if (< (length str) k)\n str\n (string+ (subseq str 0 7) \"...\")))\n\n(princ\n (main (read) (read-line)))\n", "problem_context": "Score: 200 points\n\nProblem Statement\n\nWe have a string S consisting of lowercase English letters.\n\nIf the length of S is at most K, print S without change.\n\nIf the length of S exceeds K, extract the first K characters in S, append ... to the end of them, and print the result.\n\nConstraints\n\nK is an integer between 1 and 100 (inclusive).\n\nS is a string consisting of lowercase English letters.\n\nThe length of S is between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\nS\n\nOutput\n\nPrint a string as stated in Problem Statement.\n\nSample Input 1\n\n7\nnikoandsolstice\n\nSample Output 1\n\nnikoand...\n\nnikoandsolstice has a length of 15, which exceeds K=7.\n\nWe should extract the first 7 characters in this string, append ... to the end of them, and print the result nikoand....\n\nSample Input 2\n\n40\nferelibenterhominesidquodvoluntcredunt\n\nSample Output 2\n\nferelibenterhominesidquodvoluntcredunt\n\nThe famous quote from Gaius Julius Caesar.", "sample_input": "7\nnikoandsolstice\n"}, "reference_outputs": ["nikoand...\n"], "source_document_id": "p02676", "source_text": "Score: 200 points\n\nProblem Statement\n\nWe have a string S consisting of lowercase English letters.\n\nIf the length of S is at most K, print S without change.\n\nIf the length of S exceeds K, extract the first K characters in S, append ... to the end of them, and print the result.\n\nConstraints\n\nK is an integer between 1 and 100 (inclusive).\n\nS is a string consisting of lowercase English letters.\n\nThe length of S is between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\nS\n\nOutput\n\nPrint a string as stated in Problem Statement.\n\nSample Input 1\n\n7\nnikoandsolstice\n\nSample Output 1\n\nnikoand...\n\nnikoandsolstice has a length of 15, which exceeds K=7.\n\nWe should extract the first 7 characters in this string, append ... to the end of them, and print the result nikoand....\n\nSample Input 2\n\n40\nferelibenterhominesidquodvoluntcredunt\n\nSample Output 2\n\nferelibenterhominesidquodvoluntcredunt\n\nThe famous quote from Gaius Julius Caesar.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 195, "cpu_time_ms": 19, "memory_kb": 27156}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s329833841", "group_id": "codeNet:p02676", "input_text": "(let ((k (read))\n (s (read-line)))\n (if (<= (length s) k)\n (format t \"~A~%\" s)\n (format t \"~A...~%\" (subseq s 0 k))))\n", "language": "Lisp", "metadata": {"date": 1589764032, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02676.html", "problem_id": "p02676", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02676/input.txt", "sample_output_relpath": "derived/input_output/data/p02676/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02676/Lisp/s329833841.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s329833841", "user_id": "u608227593"}, "prompt_components": {"gold_output": "nikoand...\n", "input_to_evaluate": "(let ((k (read))\n (s (read-line)))\n (if (<= (length s) k)\n (format t \"~A~%\" s)\n (format t \"~A...~%\" (subseq s 0 k))))\n", "problem_context": "Score: 200 points\n\nProblem Statement\n\nWe have a string S consisting of lowercase English letters.\n\nIf the length of S is at most K, print S without change.\n\nIf the length of S exceeds K, extract the first K characters in S, append ... to the end of them, and print the result.\n\nConstraints\n\nK is an integer between 1 and 100 (inclusive).\n\nS is a string consisting of lowercase English letters.\n\nThe length of S is between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\nS\n\nOutput\n\nPrint a string as stated in Problem Statement.\n\nSample Input 1\n\n7\nnikoandsolstice\n\nSample Output 1\n\nnikoand...\n\nnikoandsolstice has a length of 15, which exceeds K=7.\n\nWe should extract the first 7 characters in this string, append ... to the end of them, and print the result nikoand....\n\nSample Input 2\n\n40\nferelibenterhominesidquodvoluntcredunt\n\nSample Output 2\n\nferelibenterhominesidquodvoluntcredunt\n\nThe famous quote from Gaius Julius Caesar.", "sample_input": "7\nnikoandsolstice\n"}, "reference_outputs": ["nikoand...\n"], "source_document_id": "p02676", "source_text": "Score: 200 points\n\nProblem Statement\n\nWe have a string S consisting of lowercase English letters.\n\nIf the length of S is at most K, print S without change.\n\nIf the length of S exceeds K, extract the first K characters in S, append ... to the end of them, and print the result.\n\nConstraints\n\nK is an integer between 1 and 100 (inclusive).\n\nS is a string consisting of lowercase English letters.\n\nThe length of S is between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\nS\n\nOutput\n\nPrint a string as stated in Problem Statement.\n\nSample Input 1\n\n7\nnikoandsolstice\n\nSample Output 1\n\nnikoand...\n\nnikoandsolstice has a length of 15, which exceeds K=7.\n\nWe should extract the first 7 characters in this string, append ... to the end of them, and print the result nikoand....\n\nSample Input 2\n\n40\nferelibenterhominesidquodvoluntcredunt\n\nSample Output 2\n\nferelibenterhominesidquodvoluntcredunt\n\nThe famous quote from Gaius Julius Caesar.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 134, "cpu_time_ms": 13, "memory_kb": 24196}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s611369258", "group_id": "codeNet:p02676", "input_text": "(let ((k (read))\n (s (read-line)))\n (if (<= (length s) k)\n (format t \"~A\" s)\n (format t \"~A...\" (subseq s 0 k))))", "language": "Lisp", "metadata": {"date": 1589763950, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02676.html", "problem_id": "p02676", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02676/input.txt", "sample_output_relpath": "derived/input_output/data/p02676/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02676/Lisp/s611369258.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s611369258", "user_id": "u425317134"}, "prompt_components": {"gold_output": "nikoand...\n", "input_to_evaluate": "(let ((k (read))\n (s (read-line)))\n (if (<= (length s) k)\n (format t \"~A\" s)\n (format t \"~A...\" (subseq s 0 k))))", "problem_context": "Score: 200 points\n\nProblem Statement\n\nWe have a string S consisting of lowercase English letters.\n\nIf the length of S is at most K, print S without change.\n\nIf the length of S exceeds K, extract the first K characters in S, append ... to the end of them, and print the result.\n\nConstraints\n\nK is an integer between 1 and 100 (inclusive).\n\nS is a string consisting of lowercase English letters.\n\nThe length of S is between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\nS\n\nOutput\n\nPrint a string as stated in Problem Statement.\n\nSample Input 1\n\n7\nnikoandsolstice\n\nSample Output 1\n\nnikoand...\n\nnikoandsolstice has a length of 15, which exceeds K=7.\n\nWe should extract the first 7 characters in this string, append ... to the end of them, and print the result nikoand....\n\nSample Input 2\n\n40\nferelibenterhominesidquodvoluntcredunt\n\nSample Output 2\n\nferelibenterhominesidquodvoluntcredunt\n\nThe famous quote from Gaius Julius Caesar.", "sample_input": "7\nnikoandsolstice\n"}, "reference_outputs": ["nikoand...\n"], "source_document_id": "p02676", "source_text": "Score: 200 points\n\nProblem Statement\n\nWe have a string S consisting of lowercase English letters.\n\nIf the length of S is at most K, print S without change.\n\nIf the length of S exceeds K, extract the first K characters in S, append ... to the end of them, and print the result.\n\nConstraints\n\nK is an integer between 1 and 100 (inclusive).\n\nS is a string consisting of lowercase English letters.\n\nThe length of S is between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\nS\n\nOutput\n\nPrint a string as stated in Problem Statement.\n\nSample Input 1\n\n7\nnikoandsolstice\n\nSample Output 1\n\nnikoand...\n\nnikoandsolstice has a length of 15, which exceeds K=7.\n\nWe should extract the first 7 characters in this string, append ... to the end of them, and print the result nikoand....\n\nSample Input 2\n\n40\nferelibenterhominesidquodvoluntcredunt\n\nSample Output 2\n\nferelibenterhominesidquodvoluntcredunt\n\nThe famous quote from Gaius Julius Caesar.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 138, "cpu_time_ms": 15, "memory_kb": 24208}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s492679784", "group_id": "codeNet:p02677", "input_text": "(defun main ()\n (let* ((a (read))\n (b (read))\n (h (read))\n (m (read))\n (angle (- (* (* 2 pi) (+ (/ h 12) (* (/ 1 12) (/ m 60)))) (* (* 2 pi) (/ m 60))))\n (ans (sqrt (- (+ (expt a 2) (expt b 2)) (* 2 a b (cos angle))))))\n (format t \"~,20f~%\" ans)))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1589767643, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02677.html", "problem_id": "p02677", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02677/input.txt", "sample_output_relpath": "derived/input_output/data/p02677/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02677/Lisp/s492679784.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s492679784", "user_id": "u091381267"}, "prompt_components": {"gold_output": "5.00000000000000000000\n", "input_to_evaluate": "(defun main ()\n (let* ((a (read))\n (b (read))\n (h (read))\n (m (read))\n (angle (- (* (* 2 pi) (+ (/ h 12) (* (/ 1 12) (/ m 60)))) (* (* 2 pi) (/ m 60))))\n (ans (sqrt (- (+ (expt a 2) (expt b 2)) (* 2 a b (cos angle))))))\n (format t \"~,20f~%\" ans)))\n\n(main)\n", "problem_context": "Score: 300 points\n\nProblem Statement\n\nConsider an analog clock whose hour and minute hands are A and B centimeters long, respectively.\n\nAn endpoint of the hour hand and an endpoint of the minute hand are fixed at the same point, around which each hand rotates clockwise at constant angular velocity. It takes the hour and minute hands 12 hours and 1 hour to make one full rotation, respectively.\n\nAt 0 o'clock, the two hands overlap each other. H hours and M minutes later, what is the distance in centimeters between the unfixed endpoints of the hands?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A, B \\leq 1000\n\n0 \\leq H \\leq 11\n\n0 \\leq M \\leq 59\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B H M\n\nOutput\n\nPrint the answer without units. Your output will be accepted when its absolute or relative error from the correct value is at most 10^{-9}.\n\nSample Input 1\n\n3 4 9 0\n\nSample Output 1\n\n5.00000000000000000000\n\nThe two hands will be in the positions shown in the figure below, so the answer is 5 centimeters.\n\nSample Input 2\n\n3 4 10 40\n\nSample Output 2\n\n4.56425719433005567605\n\nThe two hands will be in the positions shown in the figure below. Note that each hand always rotates at constant angular velocity.", "sample_input": "3 4 9 0\n"}, "reference_outputs": ["5.00000000000000000000\n"], "source_document_id": "p02677", "source_text": "Score: 300 points\n\nProblem Statement\n\nConsider an analog clock whose hour and minute hands are A and B centimeters long, respectively.\n\nAn endpoint of the hour hand and an endpoint of the minute hand are fixed at the same point, around which each hand rotates clockwise at constant angular velocity. It takes the hour and minute hands 12 hours and 1 hour to make one full rotation, respectively.\n\nAt 0 o'clock, the two hands overlap each other. H hours and M minutes later, what is the distance in centimeters between the unfixed endpoints of the hands?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A, B \\leq 1000\n\n0 \\leq H \\leq 11\n\n0 \\leq M \\leq 59\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B H M\n\nOutput\n\nPrint the answer without units. Your output will be accepted when its absolute or relative error from the correct value is at most 10^{-9}.\n\nSample Input 1\n\n3 4 9 0\n\nSample Output 1\n\n5.00000000000000000000\n\nThe two hands will be in the positions shown in the figure below, so the answer is 5 centimeters.\n\nSample Input 2\n\n3 4 10 40\n\nSample Output 2\n\n4.56425719433005567605\n\nThe two hands will be in the positions shown in the figure below. Note that each hand always rotates at constant angular velocity.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 300, "cpu_time_ms": 16, "memory_kb": 24140}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s919163884", "group_id": "codeNet:p02678", "input_text": "#|\n------------------------------------\n Utils \n------------------------------------\n|#\n\n(in-package :cl-user)\n\n(defconstant +mod+ 1000000007)\n;(defconstant +mod+ 998244353)\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (term-char #\\Space))\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let* ((,buffer (load-time-value (make-string ,buffer-size :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n ,(if (member :swank *features*)\n `(read-char ,in nil #\\Newline) ; on SLIME\n `(code-char (read-byte ,in nil #.(char-code #\\Newline))))\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,term-char))\n (return (values ,buffer ,idx))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare (inline read-byte)\n #-swank (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (read-byte in nil 0))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))\n (return (if minus (- result) result))))))))\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n(declaim (inline read-numbers-to-list))\n(defun read-numbers-to-list (size)\n (loop repeat size collect (read-fixnum)))\n\n(declaim (inline read-numbers-to-array))\n(defun read-numbers-to-array (size)\n (let ((arr (make-array size\n :element-type 'fixnum\n :adjustable nil)))\n (declare ((array fixnum 1) arr))\n (loop for i of-type fixnum below size do\n (setf (aref arr i) (read-fixnum))\n finally\n (return arr))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (buffered-read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(declaim (inline princ-for-each-line))\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(declaim (inline unwrap))\n(defun unwrap (list)\n (the string\n (format nil \"~{~a~^ ~}\" list)))\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(defmacro maxf (place cand)\n `(setf ,place (max ,place ,cand)))\n\n(defmacro minf (place cand)\n `(setf ,place (min ,place ,cand)))\n\n(defmacro modf (place &optional (m +mod+))\n `(setf ,place (mod ,place ,m)))\n\n(defmacro alambda (parms &body body)\n `(labels ((self ,parms ,@body))\n #'self))\n\n(declaim (inline iota))\n(defun iota (count &optional (start 0) (step 1))\n (loop for i from 0 below count collect (+ start (* i step))))\n\n(declaim (inline int->lst))\n(defun int->lst (integer)\n (declare ((integer 0) integer))\n (labels ((sub (int &optional (acc nil))\n (declare ((integer 0) int)\n (list acc))\n (if (zerop int)\n acc\n (sub (floor int 10) (cons (rem int 10) acc)))))\n (sub integer)))\n\n(declaim (inline lst->int))\n(defun lst->int (list)\n (declare (list list))\n (labels ((sub (xs &optional (acc 0))\n (declare (ftype (function (list &optional (integer 0)) (integer 0)) sub))\n (declare (list xs)\n ((integer 0) acc))\n (if (null xs)\n acc\n (sub (rest xs) (+ (* acc 10)\n (rem (first xs) 10))))))\n (the fixnum\n (sub list))))\n\n(defun int->str (integer)\n (format nil \"~a\" integer))\n\n(defun str->int (str)\n (parse-integer str))\n\n(defun char->int (char)\n (declare (character char))\n (- (char-code char) #.(char-code #\\0)))\n\n(declaim (inline prime-factorize-to-list))\n(defun prime-factorize-to-list (integer)\n (declare ((integer 0) integer))\n (the list\n (if (<= integer 1)\n nil\n (loop\n while (<= (* f f) integer)\n with acc list = nil\n with f integer = 2\n do\n (if (zerop (rem integer f))\n (progn\n (push f acc)\n (setq integer (floor integer f)))\n (incf f))\n finally\n (when (/= integer 1)\n (push integer acc))\n (return (reverse acc))))))\n\n(declaim (inline prime-p))\n(defun prime-p (integer)\n (declare ((integer 1) integer))\n (if (= integer 1)\n nil\n (loop\n with f = 2\n while (<= (* f f) integer)\n do\n (when (zerop (rem integer f))\n (return nil))\n (incf f)\n finally\n (return t))))\n\n(defmacro def-memoized-function (name lambda-list &body body)\n (let ((cache (gensym))\n (val (gensym))\n (win (gensym)))\n `(let ((,cache (make-hash-table :test #'equal)))\n (defun ,name ,lambda-list\n (multiple-value-bind (,val ,win) (gethash (list ,@lambda-list) ,cache)\n (if ,win\n ,val\n (setf (gethash (list ,@lambda-list) ,cache)\n (progn\n ,@body))))))))\n\n#|\n------------------------------------\n Body \n------------------------------------\n|#\n\n(defparameter *inf* 1000000)\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (res (make-array n :initial-element -1))\n (distance (make-array n :initial-element *inf*))\n (edges (make-array n :initial-element nil)))\n (dotimes (i m)\n (let ((a (1- (read-fixnum)))\n (b (1- (read-fixnum))))\n (push a (aref edges b))\n (push b (aref edges a))))\n (labels ((dfs (pos parent &optional (cnt 0))\n (setf (aref distance pos) cnt)\n (unless (= pos 0)\n (setf (aref res pos) parent))\n (mapc (lambda (child)\n (when (> (aref distance child)\n (1+ cnt))\n (dfs child pos (1+ cnt))))\n (aref edges pos))))\n (dfs 0 -1)\n (princ \"Yes\")\n (fresh-line)\n (princ-for-each-line (map 'list #'1+ (subseq res 1)))\n (fresh-line))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1601042666, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02678.html", "problem_id": "p02678", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02678/input.txt", "sample_output_relpath": "derived/input_output/data/p02678/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02678/Lisp/s919163884.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s919163884", "user_id": "u425762225"}, "prompt_components": {"gold_output": "Yes\n1\n2\n2\n", "input_to_evaluate": "#|\n------------------------------------\n Utils \n------------------------------------\n|#\n\n(in-package :cl-user)\n\n(defconstant +mod+ 1000000007)\n;(defconstant +mod+ 998244353)\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (term-char #\\Space))\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let* ((,buffer (load-time-value (make-string ,buffer-size :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n ,(if (member :swank *features*)\n `(read-char ,in nil #\\Newline) ; on SLIME\n `(code-char (read-byte ,in nil #.(char-code #\\Newline))))\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,term-char))\n (return (values ,buffer ,idx))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare (inline read-byte)\n #-swank (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (read-byte in nil 0))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))\n (return (if minus (- result) result))))))))\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n(declaim (inline read-numbers-to-list))\n(defun read-numbers-to-list (size)\n (loop repeat size collect (read-fixnum)))\n\n(declaim (inline read-numbers-to-array))\n(defun read-numbers-to-array (size)\n (let ((arr (make-array size\n :element-type 'fixnum\n :adjustable nil)))\n (declare ((array fixnum 1) arr))\n (loop for i of-type fixnum below size do\n (setf (aref arr i) (read-fixnum))\n finally\n (return arr))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (buffered-read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(declaim (inline princ-for-each-line))\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(declaim (inline unwrap))\n(defun unwrap (list)\n (the string\n (format nil \"~{~a~^ ~}\" list)))\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(defmacro maxf (place cand)\n `(setf ,place (max ,place ,cand)))\n\n(defmacro minf (place cand)\n `(setf ,place (min ,place ,cand)))\n\n(defmacro modf (place &optional (m +mod+))\n `(setf ,place (mod ,place ,m)))\n\n(defmacro alambda (parms &body body)\n `(labels ((self ,parms ,@body))\n #'self))\n\n(declaim (inline iota))\n(defun iota (count &optional (start 0) (step 1))\n (loop for i from 0 below count collect (+ start (* i step))))\n\n(declaim (inline int->lst))\n(defun int->lst (integer)\n (declare ((integer 0) integer))\n (labels ((sub (int &optional (acc nil))\n (declare ((integer 0) int)\n (list acc))\n (if (zerop int)\n acc\n (sub (floor int 10) (cons (rem int 10) acc)))))\n (sub integer)))\n\n(declaim (inline lst->int))\n(defun lst->int (list)\n (declare (list list))\n (labels ((sub (xs &optional (acc 0))\n (declare (ftype (function (list &optional (integer 0)) (integer 0)) sub))\n (declare (list xs)\n ((integer 0) acc))\n (if (null xs)\n acc\n (sub (rest xs) (+ (* acc 10)\n (rem (first xs) 10))))))\n (the fixnum\n (sub list))))\n\n(defun int->str (integer)\n (format nil \"~a\" integer))\n\n(defun str->int (str)\n (parse-integer str))\n\n(defun char->int (char)\n (declare (character char))\n (- (char-code char) #.(char-code #\\0)))\n\n(declaim (inline prime-factorize-to-list))\n(defun prime-factorize-to-list (integer)\n (declare ((integer 0) integer))\n (the list\n (if (<= integer 1)\n nil\n (loop\n while (<= (* f f) integer)\n with acc list = nil\n with f integer = 2\n do\n (if (zerop (rem integer f))\n (progn\n (push f acc)\n (setq integer (floor integer f)))\n (incf f))\n finally\n (when (/= integer 1)\n (push integer acc))\n (return (reverse acc))))))\n\n(declaim (inline prime-p))\n(defun prime-p (integer)\n (declare ((integer 1) integer))\n (if (= integer 1)\n nil\n (loop\n with f = 2\n while (<= (* f f) integer)\n do\n (when (zerop (rem integer f))\n (return nil))\n (incf f)\n finally\n (return t))))\n\n(defmacro def-memoized-function (name lambda-list &body body)\n (let ((cache (gensym))\n (val (gensym))\n (win (gensym)))\n `(let ((,cache (make-hash-table :test #'equal)))\n (defun ,name ,lambda-list\n (multiple-value-bind (,val ,win) (gethash (list ,@lambda-list) ,cache)\n (if ,win\n ,val\n (setf (gethash (list ,@lambda-list) ,cache)\n (progn\n ,@body))))))))\n\n#|\n------------------------------------\n Body \n------------------------------------\n|#\n\n(defparameter *inf* 1000000)\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (res (make-array n :initial-element -1))\n (distance (make-array n :initial-element *inf*))\n (edges (make-array n :initial-element nil)))\n (dotimes (i m)\n (let ((a (1- (read-fixnum)))\n (b (1- (read-fixnum))))\n (push a (aref edges b))\n (push b (aref edges a))))\n (labels ((dfs (pos parent &optional (cnt 0))\n (setf (aref distance pos) cnt)\n (unless (= pos 0)\n (setf (aref res pos) parent))\n (mapc (lambda (child)\n (when (> (aref distance child)\n (1+ cnt))\n (dfs child pos (1+ cnt))))\n (aref edges pos))))\n (dfs 0 -1)\n (princ \"Yes\")\n (fresh-line)\n (princ-for-each-line (map 'list #'1+ (subseq res 1)))\n (fresh-line))))\n\n#-swank (main)\n", "problem_context": "Score: 400 points\n\nProblem Statement\n\nThere is a cave.\n\nThe cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside.\n\nIt is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage.\n\nSince it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1.\n\nIf you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.\n\nDetermine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 2 \\times 10^5\n\n1 \\leq A_i, B_i \\leq N\\ (1 \\leq i \\leq M)\n\nA_i \\neq B_i\\ (1 \\leq i \\leq M)\n\nOne can travel between any two rooms by traversing passages.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\n:\nA_M B_M\n\nOutput\n\nIf there is no way to place signposts satisfying the objective, print No.\n\nOtherwise, print N lines. The first line should contain Yes, and the i-th line (2 \\leq i \\leq N) should contain the integer representing the room indicated by the signpost in Room i.\n\nSample Input 1\n\n4 4\n1 2\n2 3\n3 4\n4 2\n\nSample Output 1\n\nYes\n1\n2\n2\n\nIf we place the signposts as described in the sample output, the following happens:\n\nStarting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n\nStarting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nStarting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\nSample Input 2\n\n6 9\n3 4\n6 1\n2 4\n5 3\n4 6\n1 5\n6 2\n4 5\n5 6\n\nSample Output 2\n\nYes\n6\n5\n5\n1\n1\n\nIf there are multiple solutions, any of them will be accepted.", "sample_input": "4 4\n1 2\n2 3\n3 4\n4 2\n"}, "reference_outputs": ["Yes\n1\n2\n2\n"], "source_document_id": "p02678", "source_text": "Score: 400 points\n\nProblem Statement\n\nThere is a cave.\n\nThe cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside.\n\nIt is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage.\n\nSince it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1.\n\nIf you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.\n\nDetermine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 2 \\times 10^5\n\n1 \\leq A_i, B_i \\leq N\\ (1 \\leq i \\leq M)\n\nA_i \\neq B_i\\ (1 \\leq i \\leq M)\n\nOne can travel between any two rooms by traversing passages.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\n:\nA_M B_M\n\nOutput\n\nIf there is no way to place signposts satisfying the objective, print No.\n\nOtherwise, print N lines. The first line should contain Yes, and the i-th line (2 \\leq i \\leq N) should contain the integer representing the room indicated by the signpost in Room i.\n\nSample Input 1\n\n4 4\n1 2\n2 3\n3 4\n4 2\n\nSample Output 1\n\nYes\n1\n2\n2\n\nIf we place the signposts as described in the sample output, the following happens:\n\nStarting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n\nStarting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nStarting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\nSample Input 2\n\n6 9\n3 4\n6 1\n2 4\n5 3\n4 6\n1 5\n6 2\n4 5\n5 6\n\nSample Output 2\n\nYes\n6\n5\n5\n1\n1\n\nIf there are multiple solutions, any of them will be accepted.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9212, "cpu_time_ms": 2206, "memory_kb": 45612}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s005543896", "group_id": "codeNet:p02679", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (table (make-hash-table :size n))\n (marked (make-hash-table :size n))\n (powers (make-array 200001 :element-type 'uint31 :initial-element 0))\n (zeros 0))\n (declare (uint31 zeros n))\n (setf (aref powers 0) 1)\n (dotimes (i (- (length powers) 1))\n (setf (aref powers (+ i 1))\n (mod* 2 (aref powers i))))\n (labels ((inc (x)\n (if (gethash x table)\n (incf (gethash x table))\n (setf (gethash x table) 1))))\n (dotimes (i n)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (cond ((and (zerop a) (zerop b))\n (incf zeros))\n ((zerop a) (inc :nan-a))\n ((zerop b) (inc :nan-b))\n (t (inc (/ b a)))))))\n (loop with res of-type uint31 = 1\n for key1 being each hash-key of table\n using (hash-value value1)\n do (let* ((key2 (case key1\n (:nan-a :nan-b)\n (:nan-b :nan-a)\n (otherwise (- (/ key1)))))\n (value2 (or (gethash key2 table) 0)))\n (unless (or (gethash key1 marked)\n (gethash key2 marked))\n (mulfmod res (mod+ (aref powers value1)\n (aref powers value2)\n -1))\n (setf (gethash key1 marked) t\n (gethash key2 marked) t)))\n finally (println (mod (+ res -1 zeros) +mod+)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2\n-1 1\n2 -1\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n3 2\n3 2\n-1 1\n2 -1\n-3 -9\n-8 12\n7 7\n8 1\n8 2\n8 4\n\"\n \"479\n\")))\n", "language": "Lisp", "metadata": {"date": 1589847265, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02679.html", "problem_id": "p02679", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02679/input.txt", "sample_output_relpath": "derived/input_output/data/p02679/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02679/Lisp/s005543896.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s005543896", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (table (make-hash-table :size n))\n (marked (make-hash-table :size n))\n (powers (make-array 200001 :element-type 'uint31 :initial-element 0))\n (zeros 0))\n (declare (uint31 zeros n))\n (setf (aref powers 0) 1)\n (dotimes (i (- (length powers) 1))\n (setf (aref powers (+ i 1))\n (mod* 2 (aref powers i))))\n (labels ((inc (x)\n (if (gethash x table)\n (incf (gethash x table))\n (setf (gethash x table) 1))))\n (dotimes (i n)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (cond ((and (zerop a) (zerop b))\n (incf zeros))\n ((zerop a) (inc :nan-a))\n ((zerop b) (inc :nan-b))\n (t (inc (/ b a)))))))\n (loop with res of-type uint31 = 1\n for key1 being each hash-key of table\n using (hash-value value1)\n do (let* ((key2 (case key1\n (:nan-a :nan-b)\n (:nan-b :nan-a)\n (otherwise (- (/ key1)))))\n (value2 (or (gethash key2 table) 0)))\n (unless (or (gethash key1 marked)\n (gethash key2 marked))\n (mulfmod res (mod+ (aref powers value1)\n (aref powers value2)\n -1))\n (setf (gethash key1 marked) t\n (gethash key2 marked) t)))\n finally (println (mod (+ res -1 zeros) +mod+)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2\n-1 1\n2 -1\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n3 2\n3 2\n-1 1\n2 -1\n-3 -9\n-8 12\n7 7\n8 1\n8 2\n8 4\n\"\n \"479\n\")))\n", "problem_context": "Score: 500 points\n\nProblem Statement\n\nWe have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively.\n\nWe will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time.\n\nThe i-th and j-th sardines (i \\neq j) are on bad terms if and only if A_i \\cdot A_j + B_i \\cdot B_j = 0.\n\nIn how many ways can we choose the set of sardines to put into the cooler? Since the count can be enormous, print it modulo 1000000007.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 2 \\times 10^5\n\n-10^{18} \\leq A_i, B_i \\leq 10^{18}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 B_1\n:\nA_N B_N\n\nOutput\n\nPrint the count modulo 1000000007.\n\nSample Input 1\n\n3\n1 2\n-1 1\n2 -1\n\nSample Output 1\n\n5\n\nThere are five ways to choose the set of sardines, as follows:\n\nThe 1-st\n\nThe 1-st and 2-nd\n\nThe 2-nd\n\nThe 2-nd and 3-rd\n\nThe 3-rd\n\nSample Input 2\n\n10\n3 2\n3 2\n-1 1\n2 -1\n-3 -9\n-8 12\n7 7\n8 1\n8 2\n8 4\n\nSample Output 2\n\n479", "sample_input": "3\n1 2\n-1 1\n2 -1\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02679", "source_text": "Score: 500 points\n\nProblem Statement\n\nWe have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively.\n\nWe will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time.\n\nThe i-th and j-th sardines (i \\neq j) are on bad terms if and only if A_i \\cdot A_j + B_i \\cdot B_j = 0.\n\nIn how many ways can we choose the set of sardines to put into the cooler? Since the count can be enormous, print it modulo 1000000007.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 2 \\times 10^5\n\n-10^{18} \\leq A_i, B_i \\leq 10^{18}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 B_1\n:\nA_N B_N\n\nOutput\n\nPrint the count modulo 1000000007.\n\nSample Input 1\n\n3\n1 2\n-1 1\n2 -1\n\nSample Output 1\n\n5\n\nThere are five ways to choose the set of sardines, as follows:\n\nThe 1-st\n\nThe 1-st and 2-nd\n\nThe 2-nd\n\nThe 2-nd and 3-rd\n\nThe 3-rd\n\nSample Input 2\n\n10\n3 2\n3 2\n-1 1\n2 -1\n-3 -9\n-8 12\n7 7\n8 1\n8 2\n8 4\n\nSample Output 2\n\n479", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7485, "cpu_time_ms": 467, "memory_kb": 89284}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s455021416", "group_id": "codeNet:p02681", "input_text": "(defun main (str1 str2)\n (princ\n (if (string= str1 (subseq str2 0 (length str1)))\n \"Yes\"\n \"No\")))\n\n(main (read-line) (read-line))\n", "language": "Lisp", "metadata": {"date": 1600897335, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02681.html", "problem_id": "p02681", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02681/input.txt", "sample_output_relpath": "derived/input_output/data/p02681/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02681/Lisp/s455021416.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s455021416", "user_id": "u761519515"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun main (str1 str2)\n (princ\n (if (string= str1 (subseq str2 0 (length str1)))\n \"Yes\"\n \"No\")))\n\n(main (read-line) (read-line))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi wants to be a member of some web service.\n\nHe tried to register himself with the ID S, which turned out to be already used by another user.\n\nThus, he decides to register using a string obtained by appending one character at the end of S as his ID.\n\nHe is now trying to register with the ID T. Determine whether this string satisfies the property above.\n\nConstraints\n\nS and T are strings consisting of lowercase English letters.\n\n1 \\leq |S| \\leq 10\n\n|T| = |S| + 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nIf T satisfies the property in Problem Statement, print Yes; otherwise, print No.\n\nSample Input 1\n\nchokudai\nchokudaiz\n\nSample Output 1\n\nYes\n\nchokudaiz can be obtained by appending z at the end of chokudai.\n\nSample Input 2\n\nsnuke\nsnekee\n\nSample Output 2\n\nNo\n\nsnekee cannot be obtained by appending one character at the end of snuke.\n\nSample Input 3\n\na\naa\n\nSample Output 3\n\nYes", "sample_input": "chokudai\nchokudaiz\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02681", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi wants to be a member of some web service.\n\nHe tried to register himself with the ID S, which turned out to be already used by another user.\n\nThus, he decides to register using a string obtained by appending one character at the end of S as his ID.\n\nHe is now trying to register with the ID T. Determine whether this string satisfies the property above.\n\nConstraints\n\nS and T are strings consisting of lowercase English letters.\n\n1 \\leq |S| \\leq 10\n\n|T| = |S| + 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nIf T satisfies the property in Problem Statement, print Yes; otherwise, print No.\n\nSample Input 1\n\nchokudai\nchokudaiz\n\nSample Output 1\n\nYes\n\nchokudaiz can be obtained by appending z at the end of chokudai.\n\nSample Input 2\n\nsnuke\nsnekee\n\nSample Output 2\n\nNo\n\nsnekee cannot be obtained by appending one character at the end of snuke.\n\nSample Input 3\n\na\naa\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 145, "cpu_time_ms": 17, "memory_kb": 23664}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s596890236", "group_id": "codeNet:p02681", "input_text": ";;(declaim (optimize (speed 0) (safety 3) (debug 3)))\n(declaim (optimize (speed 3) (safety 0) (debug 0)))\n\n(defvar s-str (read-line))\n(defvar t-str (read-line))\n\n(defvar s-len (length s-str))\n\n(format t \"~:[No~;Yes~]\" (string= s-str t-str :start1 0 :end1 s-len\n\t\t\t\t :start2 0 :end2 s-len))\n", "language": "Lisp", "metadata": {"date": 1590140874, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02681.html", "problem_id": "p02681", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02681/input.txt", "sample_output_relpath": "derived/input_output/data/p02681/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02681/Lisp/s596890236.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s596890236", "user_id": "u203134021"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": ";;(declaim (optimize (speed 0) (safety 3) (debug 3)))\n(declaim (optimize (speed 3) (safety 0) (debug 0)))\n\n(defvar s-str (read-line))\n(defvar t-str (read-line))\n\n(defvar s-len (length s-str))\n\n(format t \"~:[No~;Yes~]\" (string= s-str t-str :start1 0 :end1 s-len\n\t\t\t\t :start2 0 :end2 s-len))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi wants to be a member of some web service.\n\nHe tried to register himself with the ID S, which turned out to be already used by another user.\n\nThus, he decides to register using a string obtained by appending one character at the end of S as his ID.\n\nHe is now trying to register with the ID T. Determine whether this string satisfies the property above.\n\nConstraints\n\nS and T are strings consisting of lowercase English letters.\n\n1 \\leq |S| \\leq 10\n\n|T| = |S| + 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nIf T satisfies the property in Problem Statement, print Yes; otherwise, print No.\n\nSample Input 1\n\nchokudai\nchokudaiz\n\nSample Output 1\n\nYes\n\nchokudaiz can be obtained by appending z at the end of chokudai.\n\nSample Input 2\n\nsnuke\nsnekee\n\nSample Output 2\n\nNo\n\nsnekee cannot be obtained by appending one character at the end of snuke.\n\nSample Input 3\n\na\naa\n\nSample Output 3\n\nYes", "sample_input": "chokudai\nchokudaiz\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02681", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi wants to be a member of some web service.\n\nHe tried to register himself with the ID S, which turned out to be already used by another user.\n\nThus, he decides to register using a string obtained by appending one character at the end of S as his ID.\n\nHe is now trying to register with the ID T. Determine whether this string satisfies the property above.\n\nConstraints\n\nS and T are strings consisting of lowercase English letters.\n\n1 \\leq |S| \\leq 10\n\n|T| = |S| + 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nIf T satisfies the property in Problem Statement, print Yes; otherwise, print No.\n\nSample Input 1\n\nchokudai\nchokudaiz\n\nSample Output 1\n\nYes\n\nchokudaiz can be obtained by appending z at the end of chokudai.\n\nSample Input 2\n\nsnuke\nsnekee\n\nSample Output 2\n\nNo\n\nsnekee cannot be obtained by appending one character at the end of snuke.\n\nSample Input 3\n\na\naa\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 291, "cpu_time_ms": 14, "memory_kb": 23648}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s276065763", "group_id": "codeNet:p02681", "input_text": "(let ((s (read-line))\n (u (read-line)))\n (format t \"~A~%\"\n (if (equal (subseq u 0 (1- (length u)))\n s)\n \"Yes\"\n \"No\")))\n", "language": "Lisp", "metadata": {"date": 1589159476, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02681.html", "problem_id": "p02681", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02681/input.txt", "sample_output_relpath": "derived/input_output/data/p02681/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02681/Lisp/s276065763.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s276065763", "user_id": "u607637432"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((s (read-line))\n (u (read-line)))\n (format t \"~A~%\"\n (if (equal (subseq u 0 (1- (length u)))\n s)\n \"Yes\"\n \"No\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi wants to be a member of some web service.\n\nHe tried to register himself with the ID S, which turned out to be already used by another user.\n\nThus, he decides to register using a string obtained by appending one character at the end of S as his ID.\n\nHe is now trying to register with the ID T. Determine whether this string satisfies the property above.\n\nConstraints\n\nS and T are strings consisting of lowercase English letters.\n\n1 \\leq |S| \\leq 10\n\n|T| = |S| + 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nIf T satisfies the property in Problem Statement, print Yes; otherwise, print No.\n\nSample Input 1\n\nchokudai\nchokudaiz\n\nSample Output 1\n\nYes\n\nchokudaiz can be obtained by appending z at the end of chokudai.\n\nSample Input 2\n\nsnuke\nsnekee\n\nSample Output 2\n\nNo\n\nsnekee cannot be obtained by appending one character at the end of snuke.\n\nSample Input 3\n\na\naa\n\nSample Output 3\n\nYes", "sample_input": "chokudai\nchokudaiz\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02681", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi wants to be a member of some web service.\n\nHe tried to register himself with the ID S, which turned out to be already used by another user.\n\nThus, he decides to register using a string obtained by appending one character at the end of S as his ID.\n\nHe is now trying to register with the ID T. Determine whether this string satisfies the property above.\n\nConstraints\n\nS and T are strings consisting of lowercase English letters.\n\n1 \\leq |S| \\leq 10\n\n|T| = |S| + 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nIf T satisfies the property in Problem Statement, print Yes; otherwise, print No.\n\nSample Input 1\n\nchokudai\nchokudaiz\n\nSample Output 1\n\nYes\n\nchokudaiz can be obtained by appending z at the end of chokudai.\n\nSample Input 2\n\nsnuke\nsnekee\n\nSample Output 2\n\nNo\n\nsnekee cannot be obtained by appending one character at the end of snuke.\n\nSample Input 3\n\na\naa\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 184, "cpu_time_ms": 13, "memory_kb": 24120}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s934585933", "group_id": "codeNet:p02682", "input_text": "(defun main (a b c k)\n (declare (ignore c))\n (+ (min a k) (min 0 (- (- k a b)))))\n\n(princ (main (read) (read) (read) (read)))\n", "language": "Lisp", "metadata": {"date": 1601278318, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02682.html", "problem_id": "p02682", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02682/input.txt", "sample_output_relpath": "derived/input_output/data/p02682/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02682/Lisp/s934585933.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s934585933", "user_id": "u761519515"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun main (a b c k)\n (declare (ignore c))\n (+ (min a k) (min 0 (- (- k a b)))))\n\n(princ (main (read) (read) (read) (read)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.\n\nWe will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?\n\nConstraints\n\nAll values in input are integers.\n\n0 \\leq A, B, C\n\n1 \\leq K \\leq A + B + C \\leq 2 \\times 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C K\n\nOutput\n\nPrint the maximum possible sum of the numbers written on the cards chosen.\n\nSample Input 1\n\n2 1 1 3\n\nSample Output 1\n\n2\n\nConsider picking up two cards with 1s and one card with a 0.\nIn this case, the sum of the numbers written on the cards is 2, which is the maximum possible value.\n\nSample Input 2\n\n1 2 3 4\n\nSample Output 2\n\n0\n\nSample Input 3\n\n2000000000 0 0 2000000000\n\nSample Output 3\n\n2000000000", "sample_input": "2 1 1 3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02682", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.\n\nWe will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?\n\nConstraints\n\nAll values in input are integers.\n\n0 \\leq A, B, C\n\n1 \\leq K \\leq A + B + C \\leq 2 \\times 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C K\n\nOutput\n\nPrint the maximum possible sum of the numbers written on the cards chosen.\n\nSample Input 1\n\n2 1 1 3\n\nSample Output 1\n\n2\n\nConsider picking up two cards with 1s and one card with a 0.\nIn this case, the sum of the numbers written on the cards is 2, which is the maximum possible value.\n\nSample Input 2\n\n1 2 3 4\n\nSample Output 2\n\n0\n\nSample Input 3\n\n2000000000 0 0 2000000000\n\nSample Output 3\n\n2000000000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 128, "cpu_time_ms": 17, "memory_kb": 24328}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s519415396", "group_id": "codeNet:p02683", "input_text": ";;(declaim (optimize (speed 0) (safety 3) (debug 3)))\n(declaim (optimize (speed 3) (safety 0) (debug 0)))\n\n(declaim (type fixnum n m x))\n(defvar n (read))\n(defvar m (read))\n(defvar x (read))\n\n(defstruct book\n (price 0 :type fixnum)\n (effect (make-array m :element-type 'fixnum)\n\t :type (simple-array fixnum)))\n\n(defvar *books* (make-array n :element-type 'book))\n(dotimes (i n)\n (let ((b (make-book)))\n (setf (book-price b) (read))\n (dotimes (j m)\n (setf (aref (book-effect b) j) (read)))\n (setf (aref *books* i) b)))\n \n(defvar *t* (make-array (expt 2 n)\n\t\t\t:initial-element nil\n\t\t\t:element-type 'boolean))\n\n(defun total-price (bs)\n (declare (type fixnum bs))\n (loop for b = 1 then (ash b 1)\n\tfor bi = 0 then (1+ bi)\n\twhile (< bi n)\n\twhen (/= (logand b bs) 0) sum (book-price (aref *books* bi))))\n\n(defun bit-count (i)\n (declare (type fixnum i))\n (loop for b = 1 then (ash b 1)\n\twhile (< b (expt 2 n))\n\twhen (/= 0 (logand b i)) sum 1))\n\n(defun valid-combination (i)\n (declare (type fixnum i))\n (dotimes (mi m)\n (if (> x (loop for b = 1 then (ash b 1)\n\t\tfor bi = 0 then (1+ bi)\n\t\twhile (< b (expt 2 n))\n\t\twhen (/= 0 (logand b i))\n\t\tsum (aref (book-effect (aref *books* bi)) mi)))\n\t(return-from valid-combination nil)))\n t)\n\n(defun enum-next (i)\n (declare (type fixnum i))\n (loop for b = 1 then (ash b 1)\n\tfor o = (logior b i)\n\twhile (< b (expt 2 n))\n\twhen (/= o i) collect o))\n\n(defstruct (queue (:print-function print-queue))\n (front nil)\n (rear nil))\n\n(defun print-queue (q stream depth)\n (declare (ignore depth))\n (format stream \"#\" (queue-front q)))\n\n(declaim (inline queue-empty))\n(defun queue-empty (q)\n (declare (type queue q))\n (not (queue-front q)))\n\n(defun queue-pop (q)\n (declare (type queue q))\n (assert (and (not (queue-empty q)) \"an empty queue cannot be poped.\"))\n (let* ((front (queue-front q))\n\t (item (car front))\n\t (new-front (cdr front)))\n (declare (type cons front))\n (setf (queue-front q) new-front)\n (when (not new-front)\n (setf (queue-rear q) nil))\n item))\n\n(defun queue-push (item q)\n (declare (type queue q))\n (let ((rear (queue-rear q))\n\t(new-rear (cons item nil)))\n (if rear ; if the queue is not empty\n\t(locally\n\t (declare (type cons rear))\n\t (setf (cdr rear) new-rear)\n\t (setf (queue-rear q) new-rear))\n (progn\n\t(setf (queue-front q) new-rear)\n\t(setf (queue-rear q) new-rear)))))\n\n(defvar *q* (make-queue))\n(queue-push 0 *q*)\n\n(defvar prevn -1)\n(defvar ok-books nil)\n(loop\n (when (queue-empty *q*)\n (return))\n (let ((item (queue-pop *q*)))\n (if (> (bit-count item) prevn)\n (if ok-books\n\t (return)\n\t (psetf prevn (bit-count item) ok-books nil)))\n (when (not (aref *t* item))\n (setf (aref *t* item) t)\n (dolist (next (enum-next item))\n (queue-push next *q*))\n (when (valid-combination item)\n (push item ok-books)))))\n\n(princ (if ok-books\n\t (apply #'min (mapcar #'total-price ok-books))\n\t \"-1\"))\n\t \n", "language": "Lisp", "metadata": {"date": 1590146104, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02683.html", "problem_id": "p02683", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02683/input.txt", "sample_output_relpath": "derived/input_output/data/p02683/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02683/Lisp/s519415396.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s519415396", "user_id": "u203134021"}, "prompt_components": {"gold_output": "120\n", "input_to_evaluate": ";;(declaim (optimize (speed 0) (safety 3) (debug 3)))\n(declaim (optimize (speed 3) (safety 0) (debug 0)))\n\n(declaim (type fixnum n m x))\n(defvar n (read))\n(defvar m (read))\n(defvar x (read))\n\n(defstruct book\n (price 0 :type fixnum)\n (effect (make-array m :element-type 'fixnum)\n\t :type (simple-array fixnum)))\n\n(defvar *books* (make-array n :element-type 'book))\n(dotimes (i n)\n (let ((b (make-book)))\n (setf (book-price b) (read))\n (dotimes (j m)\n (setf (aref (book-effect b) j) (read)))\n (setf (aref *books* i) b)))\n \n(defvar *t* (make-array (expt 2 n)\n\t\t\t:initial-element nil\n\t\t\t:element-type 'boolean))\n\n(defun total-price (bs)\n (declare (type fixnum bs))\n (loop for b = 1 then (ash b 1)\n\tfor bi = 0 then (1+ bi)\n\twhile (< bi n)\n\twhen (/= (logand b bs) 0) sum (book-price (aref *books* bi))))\n\n(defun bit-count (i)\n (declare (type fixnum i))\n (loop for b = 1 then (ash b 1)\n\twhile (< b (expt 2 n))\n\twhen (/= 0 (logand b i)) sum 1))\n\n(defun valid-combination (i)\n (declare (type fixnum i))\n (dotimes (mi m)\n (if (> x (loop for b = 1 then (ash b 1)\n\t\tfor bi = 0 then (1+ bi)\n\t\twhile (< b (expt 2 n))\n\t\twhen (/= 0 (logand b i))\n\t\tsum (aref (book-effect (aref *books* bi)) mi)))\n\t(return-from valid-combination nil)))\n t)\n\n(defun enum-next (i)\n (declare (type fixnum i))\n (loop for b = 1 then (ash b 1)\n\tfor o = (logior b i)\n\twhile (< b (expt 2 n))\n\twhen (/= o i) collect o))\n\n(defstruct (queue (:print-function print-queue))\n (front nil)\n (rear nil))\n\n(defun print-queue (q stream depth)\n (declare (ignore depth))\n (format stream \"#\" (queue-front q)))\n\n(declaim (inline queue-empty))\n(defun queue-empty (q)\n (declare (type queue q))\n (not (queue-front q)))\n\n(defun queue-pop (q)\n (declare (type queue q))\n (assert (and (not (queue-empty q)) \"an empty queue cannot be poped.\"))\n (let* ((front (queue-front q))\n\t (item (car front))\n\t (new-front (cdr front)))\n (declare (type cons front))\n (setf (queue-front q) new-front)\n (when (not new-front)\n (setf (queue-rear q) nil))\n item))\n\n(defun queue-push (item q)\n (declare (type queue q))\n (let ((rear (queue-rear q))\n\t(new-rear (cons item nil)))\n (if rear ; if the queue is not empty\n\t(locally\n\t (declare (type cons rear))\n\t (setf (cdr rear) new-rear)\n\t (setf (queue-rear q) new-rear))\n (progn\n\t(setf (queue-front q) new-rear)\n\t(setf (queue-rear q) new-rear)))))\n\n(defvar *q* (make-queue))\n(queue-push 0 *q*)\n\n(defvar prevn -1)\n(defvar ok-books nil)\n(loop\n (when (queue-empty *q*)\n (return))\n (let ((item (queue-pop *q*)))\n (if (> (bit-count item) prevn)\n (if ok-books\n\t (return)\n\t (psetf prevn (bit-count item) ok-books nil)))\n (when (not (aref *t* item))\n (setf (aref *t* item) t)\n (dolist (next (enum-next item))\n (queue-push next *q*))\n (when (valid-combination item)\n (push item ok-books)))))\n\n(princ (if ok-books\n\t (apply #'min (mapcar #'total-price ok-books))\n\t \"-1\"))\n\t \n", "problem_context": "Score : 300 points\n\nProblem\n\nTakahashi, who is a novice in competitive programming, wants to learn M algorithms.\nInitially, his understanding level of each of the M algorithms is 0.\n\nTakahashi is visiting a bookstore, where he finds N books on algorithms.\nThe i-th book (1\\leq i\\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\\leq j\\leq M).\nThere is no other way to increase the understanding levels of the algorithms.\n\nTakahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.\n\nConstraints\n\nAll values in input are integers.\n\n1\\leq N, M\\leq 12\n\n1\\leq X\\leq 10^5\n\n1\\leq C_i \\leq 10^5\n\n0\\leq A_{i, j} \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M X\nC_1 A_{1,1} A_{1,2} \\cdots A_{1,M}\nC_2 A_{2,1} A_{2,2} \\cdots A_{2,M}\n\\vdots\nC_N A_{N,1} A_{N,2} \\cdots A_{N,M}\n\nOutput\n\nIf the objective is not achievable, print -1; otherwise, print the minimum amount of money needed to achieve it.\n\nSample Input 1\n\n3 3 10\n60 2 2 4\n70 8 7 9\n50 2 3 9\n\nSample Output 1\n\n120\n\nBuying the second and third books makes his understanding levels of all the algorithms 10 or higher, at the minimum cost possible.\n\nSample Input 2\n\n3 3 10\n100 3 1 4\n100 1 5 9\n100 2 6 5\n\nSample Output 2\n\n-1\n\nBuying all the books is still not enough to make his understanding levels of all the algorithms 10 or higher.\n\nSample Input 3\n\n8 5 22\n100 3 7 5 3 1\n164 4 5 2 7 8\n334 7 2 7 2 9\n234 4 7 2 8 2\n541 5 4 3 3 6\n235 4 8 6 9 7\n394 3 6 1 6 2\n872 8 4 3 7 2\n\nSample Output 3\n\n1067", "sample_input": "3 3 10\n60 2 2 4\n70 8 7 9\n50 2 3 9\n"}, "reference_outputs": ["120\n"], "source_document_id": "p02683", "source_text": "Score : 300 points\n\nProblem\n\nTakahashi, who is a novice in competitive programming, wants to learn M algorithms.\nInitially, his understanding level of each of the M algorithms is 0.\n\nTakahashi is visiting a bookstore, where he finds N books on algorithms.\nThe i-th book (1\\leq i\\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\\leq j\\leq M).\nThere is no other way to increase the understanding levels of the algorithms.\n\nTakahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.\n\nConstraints\n\nAll values in input are integers.\n\n1\\leq N, M\\leq 12\n\n1\\leq X\\leq 10^5\n\n1\\leq C_i \\leq 10^5\n\n0\\leq A_{i, j} \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M X\nC_1 A_{1,1} A_{1,2} \\cdots A_{1,M}\nC_2 A_{2,1} A_{2,2} \\cdots A_{2,M}\n\\vdots\nC_N A_{N,1} A_{N,2} \\cdots A_{N,M}\n\nOutput\n\nIf the objective is not achievable, print -1; otherwise, print the minimum amount of money needed to achieve it.\n\nSample Input 1\n\n3 3 10\n60 2 2 4\n70 8 7 9\n50 2 3 9\n\nSample Output 1\n\n120\n\nBuying the second and third books makes his understanding levels of all the algorithms 10 or higher, at the minimum cost possible.\n\nSample Input 2\n\n3 3 10\n100 3 1 4\n100 1 5 9\n100 2 6 5\n\nSample Output 2\n\n-1\n\nBuying all the books is still not enough to make his understanding levels of all the algorithms 10 or higher.\n\nSample Input 3\n\n8 5 22\n100 3 7 5 3 1\n164 4 5 2 7 8\n334 7 2 7 2 9\n234 4 7 2 8 2\n541 5 4 3 3 6\n235 4 8 6 9 7\n394 3 6 1 6 2\n872 8 4 3 7 2\n\nSample Output 3\n\n1067", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2940, "cpu_time_ms": 26, "memory_kb": 26876}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s123061576", "group_id": "codeNet:p02683", "input_text": "(defvar N (read))\n(defvar M (read))\n(defvar X (read))\n\n(defparameter arr (make-array (list N (1+ M))))\n\n(loop for i below N do\n (setf (aref arr i M) (read))\n (loop for j below M do\n (setf (aref arr i j) (read))))\n\n\n(defun solve ()\n (loop for k below (expt 2 N) with result\n do\n (setf result \n (loop for j below M\n with lst = (loop for i below N\n for B across (format nil \"~v,'0B~%\" N k)\n if (eq B #\\1) collect i)\n if (> X (or (loop for i in lst sum (aref arr i j)) 0))\n do (return nil)\n do (princ (loop for i in lst sum (aref arr i j)))\n finally (return (loop for i in lst \n sum (aref arr i M)))))\n if result minimize result))\n\n\n(defvar result (solve))\n\n(if (and result (plusp result)) (princ result) (princ \"-1\"))", "language": "Lisp", "metadata": {"date": 1589162123, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02683.html", "problem_id": "p02683", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02683/input.txt", "sample_output_relpath": "derived/input_output/data/p02683/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02683/Lisp/s123061576.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s123061576", "user_id": "u334552723"}, "prompt_components": {"gold_output": "120\n", "input_to_evaluate": "(defvar N (read))\n(defvar M (read))\n(defvar X (read))\n\n(defparameter arr (make-array (list N (1+ M))))\n\n(loop for i below N do\n (setf (aref arr i M) (read))\n (loop for j below M do\n (setf (aref arr i j) (read))))\n\n\n(defun solve ()\n (loop for k below (expt 2 N) with result\n do\n (setf result \n (loop for j below M\n with lst = (loop for i below N\n for B across (format nil \"~v,'0B~%\" N k)\n if (eq B #\\1) collect i)\n if (> X (or (loop for i in lst sum (aref arr i j)) 0))\n do (return nil)\n do (princ (loop for i in lst sum (aref arr i j)))\n finally (return (loop for i in lst \n sum (aref arr i M)))))\n if result minimize result))\n\n\n(defvar result (solve))\n\n(if (and result (plusp result)) (princ result) (princ \"-1\"))", "problem_context": "Score : 300 points\n\nProblem\n\nTakahashi, who is a novice in competitive programming, wants to learn M algorithms.\nInitially, his understanding level of each of the M algorithms is 0.\n\nTakahashi is visiting a bookstore, where he finds N books on algorithms.\nThe i-th book (1\\leq i\\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\\leq j\\leq M).\nThere is no other way to increase the understanding levels of the algorithms.\n\nTakahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.\n\nConstraints\n\nAll values in input are integers.\n\n1\\leq N, M\\leq 12\n\n1\\leq X\\leq 10^5\n\n1\\leq C_i \\leq 10^5\n\n0\\leq A_{i, j} \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M X\nC_1 A_{1,1} A_{1,2} \\cdots A_{1,M}\nC_2 A_{2,1} A_{2,2} \\cdots A_{2,M}\n\\vdots\nC_N A_{N,1} A_{N,2} \\cdots A_{N,M}\n\nOutput\n\nIf the objective is not achievable, print -1; otherwise, print the minimum amount of money needed to achieve it.\n\nSample Input 1\n\n3 3 10\n60 2 2 4\n70 8 7 9\n50 2 3 9\n\nSample Output 1\n\n120\n\nBuying the second and third books makes his understanding levels of all the algorithms 10 or higher, at the minimum cost possible.\n\nSample Input 2\n\n3 3 10\n100 3 1 4\n100 1 5 9\n100 2 6 5\n\nSample Output 2\n\n-1\n\nBuying all the books is still not enough to make his understanding levels of all the algorithms 10 or higher.\n\nSample Input 3\n\n8 5 22\n100 3 7 5 3 1\n164 4 5 2 7 8\n334 7 2 7 2 9\n234 4 7 2 8 2\n541 5 4 3 3 6\n235 4 8 6 9 7\n394 3 6 1 6 2\n872 8 4 3 7 2\n\nSample Output 3\n\n1067", "sample_input": "3 3 10\n60 2 2 4\n70 8 7 9\n50 2 3 9\n"}, "reference_outputs": ["120\n"], "source_document_id": "p02683", "source_text": "Score : 300 points\n\nProblem\n\nTakahashi, who is a novice in competitive programming, wants to learn M algorithms.\nInitially, his understanding level of each of the M algorithms is 0.\n\nTakahashi is visiting a bookstore, where he finds N books on algorithms.\nThe i-th book (1\\leq i\\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\\leq j\\leq M).\nThere is no other way to increase the understanding levels of the algorithms.\n\nTakahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.\n\nConstraints\n\nAll values in input are integers.\n\n1\\leq N, M\\leq 12\n\n1\\leq X\\leq 10^5\n\n1\\leq C_i \\leq 10^5\n\n0\\leq A_{i, j} \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M X\nC_1 A_{1,1} A_{1,2} \\cdots A_{1,M}\nC_2 A_{2,1} A_{2,2} \\cdots A_{2,M}\n\\vdots\nC_N A_{N,1} A_{N,2} \\cdots A_{N,M}\n\nOutput\n\nIf the objective is not achievable, print -1; otherwise, print the minimum amount of money needed to achieve it.\n\nSample Input 1\n\n3 3 10\n60 2 2 4\n70 8 7 9\n50 2 3 9\n\nSample Output 1\n\n120\n\nBuying the second and third books makes his understanding levels of all the algorithms 10 or higher, at the minimum cost possible.\n\nSample Input 2\n\n3 3 10\n100 3 1 4\n100 1 5 9\n100 2 6 5\n\nSample Output 2\n\n-1\n\nBuying all the books is still not enough to make his understanding levels of all the algorithms 10 or higher.\n\nSample Input 3\n\n8 5 22\n100 3 7 5 3 1\n164 4 5 2 7 8\n334 7 2 7 2 9\n234 4 7 2 8 2\n541 5 4 3 3 6\n235 4 8 6 9 7\n394 3 6 1 6 2\n872 8 4 3 7 2\n\nSample Output 3\n\n1067", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 983, "cpu_time_ms": 42, "memory_kb": 27632}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s814414158", "group_id": "codeNet:p02685", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ 998244353)\n\n(defun mapa-b (fn a b &optional (step 1))\n (do ((i a (+ i step))\n (result nil))\n ((> i b) (nreverse result))\n (push (funcall fn i) result)))\n\n(defun map0-n (fn n)\n (mapa-b fn 0 n))\n\n(defun map1-n (fn n)\n (mapa-b fn 1 n))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (is-empty char)\n do (return (concatenate 'string (nreverse result)))\n do (push char result))))\n\n(defun merge-sort (lst &optional (compare #'<))\n (let ((turn 0))\n (labels ((merge-list (a b a-length b-length)\n (cond ((zerop a-length) b)\n ((zerop b-length) a)\n ((funcall compare (car b) (car a))\n (incf turn a-length)\n (cons (car b)\n (merge-list a (cdr b) a-length (1- b-length))))\n (t\n (cons (car a)\n (merge-list (cdr a) b (1- a-length) b-length)))))\n (f (lst length)\n (if (= length 1)\n lst\n (let ((mid (ash length -1)))\n (merge-list (f (subseq lst 0 mid) mid)\n (f (subseq lst mid) (- length mid))\n mid\n (- length mid))))))\n (values (f lst (length lst)) turn))))\n\n(defun group (lst &optional (test #'eql) (key nil))\n (let ((table (make-hash-table :test test)))\n (mapc (lambda (x)\n (push x (gethash (if key (funcall key x) x) table)))\n lst)\n (loop for value being each hash-value in table\n collect value)))\n\n(defun mod+ (&rest expr)\n (reduce (lambda (x y) (mod (+ x y) +MOD+)) expr))\n(defun mod- (&rest expr)\n (reduce (lambda (x y) (mod (- x y) +MOD+)) expr))\n(defun mod* (&rest expr)\n (reduce (lambda (x y) (mod (* x y) +MOD+)) expr))\n(defun modpow (x y)\n (if (zerop y)\n 1\n (mod* (if (oddp y) x 1)\n (modpow (mod* x x) (ash y -1)))))\n(defun mod/ (&rest expr)\n (reduce (lambda (x y) (mod (mod* x (modpow y (- +MOD+ 2))) +MOD+)) expr))\n\n(dp factorial (x) (list 200005)\n (if (<= x 1)\n 1\n (mod* x (factorial (1- x)))))\n\n(loop for i from 0 to 200000 by 1000\n do (factorial i))\n\n(defun combination (a b)\n (mod/ (factorial a) (factorial b) (factorial (- a b))))\n\n(defun main (n m k)\n (let ((ans 0))\n (loop for i from (- n k) to n\n do\n (progn\n (setf ans (mod+ ans\n (mod* m\n (modpow (1- m) (1- i))\n (combination (1- n) (- n i)))))))\n ans))\n\n(let ((n (read))\n (m (read))\n (k (read)))\n (princ (main n m k)))\n", "language": "Lisp", "metadata": {"date": 1589161167, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02685.html", "problem_id": "p02685", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02685/input.txt", "sample_output_relpath": "derived/input_output/data/p02685/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02685/Lisp/s814414158.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s814414158", "user_id": "u493610446"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ 998244353)\n\n(defun mapa-b (fn a b &optional (step 1))\n (do ((i a (+ i step))\n (result nil))\n ((> i b) (nreverse result))\n (push (funcall fn i) result)))\n\n(defun map0-n (fn n)\n (mapa-b fn 0 n))\n\n(defun map1-n (fn n)\n (mapa-b fn 1 n))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (is-empty char)\n do (return (concatenate 'string (nreverse result)))\n do (push char result))))\n\n(defun merge-sort (lst &optional (compare #'<))\n (let ((turn 0))\n (labels ((merge-list (a b a-length b-length)\n (cond ((zerop a-length) b)\n ((zerop b-length) a)\n ((funcall compare (car b) (car a))\n (incf turn a-length)\n (cons (car b)\n (merge-list a (cdr b) a-length (1- b-length))))\n (t\n (cons (car a)\n (merge-list (cdr a) b (1- a-length) b-length)))))\n (f (lst length)\n (if (= length 1)\n lst\n (let ((mid (ash length -1)))\n (merge-list (f (subseq lst 0 mid) mid)\n (f (subseq lst mid) (- length mid))\n mid\n (- length mid))))))\n (values (f lst (length lst)) turn))))\n\n(defun group (lst &optional (test #'eql) (key nil))\n (let ((table (make-hash-table :test test)))\n (mapc (lambda (x)\n (push x (gethash (if key (funcall key x) x) table)))\n lst)\n (loop for value being each hash-value in table\n collect value)))\n\n(defun mod+ (&rest expr)\n (reduce (lambda (x y) (mod (+ x y) +MOD+)) expr))\n(defun mod- (&rest expr)\n (reduce (lambda (x y) (mod (- x y) +MOD+)) expr))\n(defun mod* (&rest expr)\n (reduce (lambda (x y) (mod (* x y) +MOD+)) expr))\n(defun modpow (x y)\n (if (zerop y)\n 1\n (mod* (if (oddp y) x 1)\n (modpow (mod* x x) (ash y -1)))))\n(defun mod/ (&rest expr)\n (reduce (lambda (x y) (mod (mod* x (modpow y (- +MOD+ 2))) +MOD+)) expr))\n\n(dp factorial (x) (list 200005)\n (if (<= x 1)\n 1\n (mod* x (factorial (1- x)))))\n\n(loop for i from 0 to 200000 by 1000\n do (factorial i))\n\n(defun combination (a b)\n (mod/ (factorial a) (factorial b) (factorial (- a b))))\n\n(defun main (n m k)\n (let ((ans 0))\n (loop for i from (- n k) to n\n do\n (progn\n (setf ans (mod+ ans\n (mod* m\n (modpow (1- m) (1- i))\n (combination (1- n) (- n i)))))))\n ans))\n\n(let ((n (read))\n (m (read))\n (k (read)))\n (princ (main n m k)))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere are N blocks arranged in a row. Let us paint these blocks.\n\nWe will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.\n\nFind the number of ways to paint the blocks under the following conditions:\n\nFor each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.\n\nThere may be at most K pairs of adjacent blocks that are painted in the same color.\n\nSince the count may be enormous, print it modulo 998244353.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N, M \\leq 2 \\times 10^5\n\n0 \\leq K \\leq N - 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M K\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3 2 1\n\nSample Output 1\n\n6\n\nThe following ways to paint the blocks satisfy the conditions: 112, 121, 122, 211, 212, and 221. Here, digits represent the colors of the blocks.\n\nSample Input 2\n\n100 100 0\n\nSample Output 2\n\n73074801\n\nSample Input 3\n\n60522 114575 7559\n\nSample Output 3\n\n479519525", "sample_input": "3 2 1\n"}, "reference_outputs": ["6\n"], "source_document_id": "p02685", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere are N blocks arranged in a row. Let us paint these blocks.\n\nWe will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.\n\nFind the number of ways to paint the blocks under the following conditions:\n\nFor each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.\n\nThere may be at most K pairs of adjacent blocks that are painted in the same color.\n\nSince the count may be enormous, print it modulo 998244353.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N, M \\leq 2 \\times 10^5\n\n0 \\leq K \\leq N - 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M K\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3 2 1\n\nSample Output 1\n\n6\n\nThe following ways to paint the blocks satisfy the conditions: 112, 121, 122, 211, 212, and 221. Here, digits represent the colors of the blocks.\n\nSample Input 2\n\n100 100 0\n\nSample Output 2\n\n73074801\n\nSample Input 3\n\n60522 114575 7559\n\nSample Output 3\n\n479519525", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4998, "cpu_time_ms": 1774, "memory_kb": 80280}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s636380526", "group_id": "codeNet:p02686", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun mapa-b (fn a b &optional (step 1))\n (do ((i a (+ i step))\n (result nil))\n ((> i b) (nreverse result))\n (push (funcall fn i) result)))\n\n(defun map0-n (fn n)\n (mapa-b fn 0 n))\n\n(defun map1-n (fn n)\n (mapa-b fn 1 n))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (is-empty char)\n do (return (concatenate 'string (nreverse result)))\n do (push char result))))\n\n(defun merge-sort (lst &optional (compare #'<))\n (let ((turn 0))\n (labels ((merge-list (a b a-length b-length)\n (cond ((zerop a-length) b)\n ((zerop b-length) a)\n ((funcall compare (car b) (car a))\n (incf turn a-length)\n (cons (car b)\n (merge-list a (cdr b) a-length (1- b-length))))\n (t\n (cons (car a)\n (merge-list (cdr a) b (1- a-length) b-length)))))\n (f (lst length)\n (if (= length 1)\n lst\n (let ((mid (ash length -1)))\n (merge-list (f (subseq lst 0 mid) mid)\n (f (subseq lst mid) (- length mid))\n mid\n (- length mid))))))\n (values (f lst (length lst)) turn))))\n\n(defun group (lst &optional (test #'eql) (key nil))\n (let ((table (make-hash-table :test test)))\n (mapc (lambda (x)\n (push x (gethash (if key (funcall key x) x) table)))\n lst)\n (loop for value being each hash-value in table\n collect value)))\n\n(defun parenthese (str)\n (let ((sum 0)\n (min 0))\n (loop for i across str\n do\n (progn\n (if (char= i #\\()\n (incf sum)\n (progn\n (decf sum)\n (setf min (min min sum))))))\n (cons min sum)))\n\n\n(defun main (strs)\n (let* ((nums (mapcar #'parenthese strs))\n (adder (sort (remove-if (lambda (x) (<= (cdr x) 0)) nums)\n (lambda (x y)\n (or (> (car x) (car y))\n (and (= (car x) (car y))\n (> (cdr x) (cdr y)))))))\n (subber (sort (remove-if (lambda (x) (> (cdr x) 0)) nums)\n (lambda (x y)\n (> (+ (car x) (cdr x)) (+ (car y) (cdr y))))))\n (sum 0))\n (loop for i in adder\n for val = (car i)\n for add = (cdr i)\n when (< (+ sum val) 0)\n do (return-from main nil)\n do\n (incf sum add))\n (loop for i in subber\n for val = (car i)\n for add = (cdr i)\n when (< (+ sum val) 0)\n do (return-from main nil)\n do\n (incf sum add))\n (zerop sum)))\n\n\n(princ (if (main (collect-times (read) (read-string))) \"Yes\" \"No\"))\n", "language": "Lisp", "metadata": {"date": 1589165108, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02686.html", "problem_id": "p02686", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02686/input.txt", "sample_output_relpath": "derived/input_output/data/p02686/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02686/Lisp/s636380526.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s636380526", "user_id": "u493610446"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun mapa-b (fn a b &optional (step 1))\n (do ((i a (+ i step))\n (result nil))\n ((> i b) (nreverse result))\n (push (funcall fn i) result)))\n\n(defun map0-n (fn n)\n (mapa-b fn 0 n))\n\n(defun map1-n (fn n)\n (mapa-b fn 1 n))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (is-empty char)\n do (return (concatenate 'string (nreverse result)))\n do (push char result))))\n\n(defun merge-sort (lst &optional (compare #'<))\n (let ((turn 0))\n (labels ((merge-list (a b a-length b-length)\n (cond ((zerop a-length) b)\n ((zerop b-length) a)\n ((funcall compare (car b) (car a))\n (incf turn a-length)\n (cons (car b)\n (merge-list a (cdr b) a-length (1- b-length))))\n (t\n (cons (car a)\n (merge-list (cdr a) b (1- a-length) b-length)))))\n (f (lst length)\n (if (= length 1)\n lst\n (let ((mid (ash length -1)))\n (merge-list (f (subseq lst 0 mid) mid)\n (f (subseq lst mid) (- length mid))\n mid\n (- length mid))))))\n (values (f lst (length lst)) turn))))\n\n(defun group (lst &optional (test #'eql) (key nil))\n (let ((table (make-hash-table :test test)))\n (mapc (lambda (x)\n (push x (gethash (if key (funcall key x) x) table)))\n lst)\n (loop for value being each hash-value in table\n collect value)))\n\n(defun parenthese (str)\n (let ((sum 0)\n (min 0))\n (loop for i across str\n do\n (progn\n (if (char= i #\\()\n (incf sum)\n (progn\n (decf sum)\n (setf min (min min sum))))))\n (cons min sum)))\n\n\n(defun main (strs)\n (let* ((nums (mapcar #'parenthese strs))\n (adder (sort (remove-if (lambda (x) (<= (cdr x) 0)) nums)\n (lambda (x y)\n (or (> (car x) (car y))\n (and (= (car x) (car y))\n (> (cdr x) (cdr y)))))))\n (subber (sort (remove-if (lambda (x) (> (cdr x) 0)) nums)\n (lambda (x y)\n (> (+ (car x) (cdr x)) (+ (car y) (cdr y))))))\n (sum 0))\n (loop for i in adder\n for val = (car i)\n for add = (cdr i)\n when (< (+ sum val) 0)\n do (return-from main nil)\n do\n (incf sum add))\n (loop for i in subber\n for val = (car i)\n for add = (cdr i)\n when (< (+ sum val) 0)\n do (return-from main nil)\n do\n (incf sum add))\n (zerop sum)))\n\n\n(princ (if (main (collect-times (read) (read-string))) \"Yes\" \"No\"))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nA bracket sequence is a string that is one of the following:\n\nAn empty string;\n\nThe concatenation of (, A, and ) in this order, for some bracket sequence A ;\n\nThe concatenation of A and B in this order, for some non-empty bracket sequences A and B /\n\nGiven are N strings S_i. Can a bracket sequence be formed by concatenating all the N strings in some order?\n\nConstraints\n\n1 \\leq N \\leq 10^6\n\nThe total length of the strings S_i is at most 10^6.\n\nS_i is a non-empty string consisting of ( and ).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nIf a bracket sequence can be formed by concatenating all the N strings in some order, print Yes; otherwise, print No.\n\nSample Input 1\n\n2\n)\n(()\n\nSample Output 1\n\nYes\n\nConcatenating (() and ) in this order forms a bracket sequence.\n\nSample Input 2\n\n2\n)(\n()\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n4\n((()))\n((((((\n))))))\n()()()\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n3\n(((\n)\n)\n\nSample Output 4\n\nNo", "sample_input": "2\n)\n(()\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02686", "source_text": "Score : 600 points\n\nProblem Statement\n\nA bracket sequence is a string that is one of the following:\n\nAn empty string;\n\nThe concatenation of (, A, and ) in this order, for some bracket sequence A ;\n\nThe concatenation of A and B in this order, for some non-empty bracket sequences A and B /\n\nGiven are N strings S_i. Can a bracket sequence be formed by concatenating all the N strings in some order?\n\nConstraints\n\n1 \\leq N \\leq 10^6\n\nThe total length of the strings S_i is at most 10^6.\n\nS_i is a non-empty string consisting of ( and ).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nIf a bracket sequence can be formed by concatenating all the N strings in some order, print Yes; otherwise, print No.\n\nSample Input 1\n\n2\n)\n(()\n\nSample Output 1\n\nYes\n\nConcatenating (() and ) in this order forms a bracket sequence.\n\nSample Input 2\n\n2\n)(\n()\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n4\n((()))\n((((((\n))))))\n()()()\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n3\n(((\n)\n)\n\nSample Output 4\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5225, "cpu_time_ms": 413, "memory_kb": 167056}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s925542762", "group_id": "codeNet:p02686", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun mapa-b (fn a b &optional (step 1))\n (do ((i a (+ i step))\n (result nil))\n ((> i b) (nreverse result))\n (push (funcall fn i) result)))\n\n(defun map0-n (fn n)\n (mapa-b fn 0 n))\n\n(defun map1-n (fn n)\n (mapa-b fn 1 n))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (is-empty char)\n do (return (concatenate 'string (nreverse result)))\n do (push char result))))\n\n(defun merge-sort (lst &optional (compare #'<))\n (let ((turn 0))\n (labels ((merge-list (a b a-length b-length)\n (cond ((zerop a-length) b)\n ((zerop b-length) a)\n ((funcall compare (car b) (car a))\n (incf turn a-length)\n (cons (car b)\n (merge-list a (cdr b) a-length (1- b-length))))\n (t\n (cons (car a)\n (merge-list (cdr a) b (1- a-length) b-length)))))\n (f (lst length)\n (if (= length 1)\n lst\n (let ((mid (ash length -1)))\n (merge-list (f (subseq lst 0 mid) mid)\n (f (subseq lst mid) (- length mid))\n mid\n (- length mid))))))\n (values (f lst (length lst)) turn))))\n\n(defun group (lst &optional (test #'eql) (key nil))\n (let ((table (make-hash-table :test test)))\n (mapc (lambda (x)\n (push x (gethash (if key (funcall key x) x) table)))\n lst)\n (loop for value being each hash-value in table\n collect value)))\n\n(defun parenthese (str)\n (let ((sum 0)\n (min 0))\n (loop for i across str\n do\n (progn\n (if (char= i #\\()\n (incf sum)\n (progn\n (decf sum)\n (setf min (min min sum))))))\n (cons min sum)))\n\n\n(defun main (strs)\n (let* ((nums (mapcar #'parenthese strs))\n (adder (sort (remove-if (lambda (x) (<= (cdr x) 0)) nums)\n (lambda (x y)\n (or (> (car x) (car y))\n (and (= (car x) (car y))\n (> (cdr x) (cdr y)))))))\n (subber (sort (remove-if (lambda (x) (> (cdr x) 0)) nums)\n (lambda (x y)\n (or (< (car x) (car y))\n (and (= (car x) (car y))\n (> (cdr x) (cdr y)))))))\n (sum 0))\n (loop for i in adder\n for val = (car i)\n for add = (cdr i)\n when (< (+ sum val) 0)\n do (return-from main nil)\n do\n (incf sum add))\n (loop for i in subber\n for val = (car i)\n for add = (cdr i)\n when (< (+ sum val) 0)\n do (return-from main nil)\n do\n (incf sum add))\n (zerop sum)))\n\n\n(princ (if (main (collect-times (read) (read-string))) \"Yes\" \"No\"))\n", "language": "Lisp", "metadata": {"date": 1589164800, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02686.html", "problem_id": "p02686", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02686/input.txt", "sample_output_relpath": "derived/input_output/data/p02686/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02686/Lisp/s925542762.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s925542762", "user_id": "u493610446"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun mapa-b (fn a b &optional (step 1))\n (do ((i a (+ i step))\n (result nil))\n ((> i b) (nreverse result))\n (push (funcall fn i) result)))\n\n(defun map0-n (fn n)\n (mapa-b fn 0 n))\n\n(defun map1-n (fn n)\n (mapa-b fn 1 n))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (is-empty char)\n do (return (concatenate 'string (nreverse result)))\n do (push char result))))\n\n(defun merge-sort (lst &optional (compare #'<))\n (let ((turn 0))\n (labels ((merge-list (a b a-length b-length)\n (cond ((zerop a-length) b)\n ((zerop b-length) a)\n ((funcall compare (car b) (car a))\n (incf turn a-length)\n (cons (car b)\n (merge-list a (cdr b) a-length (1- b-length))))\n (t\n (cons (car a)\n (merge-list (cdr a) b (1- a-length) b-length)))))\n (f (lst length)\n (if (= length 1)\n lst\n (let ((mid (ash length -1)))\n (merge-list (f (subseq lst 0 mid) mid)\n (f (subseq lst mid) (- length mid))\n mid\n (- length mid))))))\n (values (f lst (length lst)) turn))))\n\n(defun group (lst &optional (test #'eql) (key nil))\n (let ((table (make-hash-table :test test)))\n (mapc (lambda (x)\n (push x (gethash (if key (funcall key x) x) table)))\n lst)\n (loop for value being each hash-value in table\n collect value)))\n\n(defun parenthese (str)\n (let ((sum 0)\n (min 0))\n (loop for i across str\n do\n (progn\n (if (char= i #\\()\n (incf sum)\n (progn\n (decf sum)\n (setf min (min min sum))))))\n (cons min sum)))\n\n\n(defun main (strs)\n (let* ((nums (mapcar #'parenthese strs))\n (adder (sort (remove-if (lambda (x) (<= (cdr x) 0)) nums)\n (lambda (x y)\n (or (> (car x) (car y))\n (and (= (car x) (car y))\n (> (cdr x) (cdr y)))))))\n (subber (sort (remove-if (lambda (x) (> (cdr x) 0)) nums)\n (lambda (x y)\n (or (< (car x) (car y))\n (and (= (car x) (car y))\n (> (cdr x) (cdr y)))))))\n (sum 0))\n (loop for i in adder\n for val = (car i)\n for add = (cdr i)\n when (< (+ sum val) 0)\n do (return-from main nil)\n do\n (incf sum add))\n (loop for i in subber\n for val = (car i)\n for add = (cdr i)\n when (< (+ sum val) 0)\n do (return-from main nil)\n do\n (incf sum add))\n (zerop sum)))\n\n\n(princ (if (main (collect-times (read) (read-string))) \"Yes\" \"No\"))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nA bracket sequence is a string that is one of the following:\n\nAn empty string;\n\nThe concatenation of (, A, and ) in this order, for some bracket sequence A ;\n\nThe concatenation of A and B in this order, for some non-empty bracket sequences A and B /\n\nGiven are N strings S_i. Can a bracket sequence be formed by concatenating all the N strings in some order?\n\nConstraints\n\n1 \\leq N \\leq 10^6\n\nThe total length of the strings S_i is at most 10^6.\n\nS_i is a non-empty string consisting of ( and ).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nIf a bracket sequence can be formed by concatenating all the N strings in some order, print Yes; otherwise, print No.\n\nSample Input 1\n\n2\n)\n(()\n\nSample Output 1\n\nYes\n\nConcatenating (() and ) in this order forms a bracket sequence.\n\nSample Input 2\n\n2\n)(\n()\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n4\n((()))\n((((((\n))))))\n()()()\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n3\n(((\n)\n)\n\nSample Output 4\n\nNo", "sample_input": "2\n)\n(()\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02686", "source_text": "Score : 600 points\n\nProblem Statement\n\nA bracket sequence is a string that is one of the following:\n\nAn empty string;\n\nThe concatenation of (, A, and ) in this order, for some bracket sequence A ;\n\nThe concatenation of A and B in this order, for some non-empty bracket sequences A and B /\n\nGiven are N strings S_i. Can a bracket sequence be formed by concatenating all the N strings in some order?\n\nConstraints\n\n1 \\leq N \\leq 10^6\n\nThe total length of the strings S_i is at most 10^6.\n\nS_i is a non-empty string consisting of ( and ).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nIf a bracket sequence can be formed by concatenating all the N strings in some order, print Yes; otherwise, print No.\n\nSample Input 1\n\n2\n)\n(()\n\nSample Output 1\n\nYes\n\nConcatenating (() and ) in this order forms a bracket sequence.\n\nSample Input 2\n\n2\n)(\n()\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n4\n((()))\n((((((\n))))))\n()()()\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n3\n(((\n)\n)\n\nSample Output 4\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5315, "cpu_time_ms": 448, "memory_kb": 166944}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s656424208", "group_id": "codeNet:p02686", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun mapa-b (fn a b &optional (step 1))\n (do ((i a (+ i step))\n (result nil))\n ((> i b) (nreverse result))\n (push (funcall fn i) result)))\n\n(defun map0-n (fn n)\n (mapa-b fn 0 n))\n\n(defun map1-n (fn n)\n (mapa-b fn 1 n))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (is-empty char)\n do (return (concatenate 'string (nreverse result)))\n do (push char result))))\n\n(defun merge-sort (lst &optional (compare #'<))\n (let ((turn 0))\n (labels ((merge-list (a b a-length b-length)\n (cond ((zerop a-length) b)\n ((zerop b-length) a)\n ((funcall compare (car b) (car a))\n (incf turn a-length)\n (cons (car b)\n (merge-list a (cdr b) a-length (1- b-length))))\n (t\n (cons (car a)\n (merge-list (cdr a) b (1- a-length) b-length)))))\n (f (lst length)\n (if (= length 1)\n lst\n (let ((mid (ash length -1)))\n (merge-list (f (subseq lst 0 mid) mid)\n (f (subseq lst mid) (- length mid))\n mid\n (- length mid))))))\n (values (f lst (length lst)) turn))))\n\n(defun group (lst &optional (test #'eql) (key nil))\n (let ((table (make-hash-table :test test)))\n (mapc (lambda (x)\n (push x (gethash (if key (funcall key x) x) table)))\n lst)\n (loop for value being each hash-value in table\n collect value)))\n\n(defun parenthese (str)\n (let ((sum 0)\n (min 0))\n (loop for i across str\n do\n (progn\n (if (char= i #\\()\n (incf sum)\n (progn\n (decf sum)\n (setf min (min min sum))))))\n (cons min sum)))\n\n\n(defun main (strs)\n (let* ((nums (mapcar #'parenthese strs))\n (adder (sort (remove-if (lambda (x) (< (cdr x) 0)) nums)\n (lambda (x y)\n (or (> (car x) (car y)) (and (= (car x) (car y)) (> (cdr x) (cdr y)))))))\n (subber (sort (remove-if (lambda (x) (>= (cdr x) 0)) nums)\n (lambda (x y)\n (or (< (car x) (car y)) (and (= (car x) (car y)) (> (cdr x) (cdr y)))))))\n (sum 0))\n (loop for i in adder\n for val = (car i)\n for add = (cdr i)\n when (< (+ sum val) 0)\n do (return-from main nil)\n do\n (incf sum add))\n (loop for i in subber\n for val = (car i)\n for add = (cdr i)\n when (< (+ sum val) 0)\n do (return-from main nil)\n do\n (incf sum add))\n (zerop sum)))\n\n\n(princ (if (main (collect-times (read) (read-string))) \"Yes\" \"No\"))\n", "language": "Lisp", "metadata": {"date": 1589164228, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02686.html", "problem_id": "p02686", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02686/input.txt", "sample_output_relpath": "derived/input_output/data/p02686/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02686/Lisp/s656424208.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s656424208", "user_id": "u493610446"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun mapa-b (fn a b &optional (step 1))\n (do ((i a (+ i step))\n (result nil))\n ((> i b) (nreverse result))\n (push (funcall fn i) result)))\n\n(defun map0-n (fn n)\n (mapa-b fn 0 n))\n\n(defun map1-n (fn n)\n (mapa-b fn 1 n))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (is-empty char)\n do (return (concatenate 'string (nreverse result)))\n do (push char result))))\n\n(defun merge-sort (lst &optional (compare #'<))\n (let ((turn 0))\n (labels ((merge-list (a b a-length b-length)\n (cond ((zerop a-length) b)\n ((zerop b-length) a)\n ((funcall compare (car b) (car a))\n (incf turn a-length)\n (cons (car b)\n (merge-list a (cdr b) a-length (1- b-length))))\n (t\n (cons (car a)\n (merge-list (cdr a) b (1- a-length) b-length)))))\n (f (lst length)\n (if (= length 1)\n lst\n (let ((mid (ash length -1)))\n (merge-list (f (subseq lst 0 mid) mid)\n (f (subseq lst mid) (- length mid))\n mid\n (- length mid))))))\n (values (f lst (length lst)) turn))))\n\n(defun group (lst &optional (test #'eql) (key nil))\n (let ((table (make-hash-table :test test)))\n (mapc (lambda (x)\n (push x (gethash (if key (funcall key x) x) table)))\n lst)\n (loop for value being each hash-value in table\n collect value)))\n\n(defun parenthese (str)\n (let ((sum 0)\n (min 0))\n (loop for i across str\n do\n (progn\n (if (char= i #\\()\n (incf sum)\n (progn\n (decf sum)\n (setf min (min min sum))))))\n (cons min sum)))\n\n\n(defun main (strs)\n (let* ((nums (mapcar #'parenthese strs))\n (adder (sort (remove-if (lambda (x) (< (cdr x) 0)) nums)\n (lambda (x y)\n (or (> (car x) (car y)) (and (= (car x) (car y)) (> (cdr x) (cdr y)))))))\n (subber (sort (remove-if (lambda (x) (>= (cdr x) 0)) nums)\n (lambda (x y)\n (or (< (car x) (car y)) (and (= (car x) (car y)) (> (cdr x) (cdr y)))))))\n (sum 0))\n (loop for i in adder\n for val = (car i)\n for add = (cdr i)\n when (< (+ sum val) 0)\n do (return-from main nil)\n do\n (incf sum add))\n (loop for i in subber\n for val = (car i)\n for add = (cdr i)\n when (< (+ sum val) 0)\n do (return-from main nil)\n do\n (incf sum add))\n (zerop sum)))\n\n\n(princ (if (main (collect-times (read) (read-string))) \"Yes\" \"No\"))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nA bracket sequence is a string that is one of the following:\n\nAn empty string;\n\nThe concatenation of (, A, and ) in this order, for some bracket sequence A ;\n\nThe concatenation of A and B in this order, for some non-empty bracket sequences A and B /\n\nGiven are N strings S_i. Can a bracket sequence be formed by concatenating all the N strings in some order?\n\nConstraints\n\n1 \\leq N \\leq 10^6\n\nThe total length of the strings S_i is at most 10^6.\n\nS_i is a non-empty string consisting of ( and ).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nIf a bracket sequence can be formed by concatenating all the N strings in some order, print Yes; otherwise, print No.\n\nSample Input 1\n\n2\n)\n(()\n\nSample Output 1\n\nYes\n\nConcatenating (() and ) in this order forms a bracket sequence.\n\nSample Input 2\n\n2\n)(\n()\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n4\n((()))\n((((((\n))))))\n()()()\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n3\n(((\n)\n)\n\nSample Output 4\n\nNo", "sample_input": "2\n)\n(()\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02686", "source_text": "Score : 600 points\n\nProblem Statement\n\nA bracket sequence is a string that is one of the following:\n\nAn empty string;\n\nThe concatenation of (, A, and ) in this order, for some bracket sequence A ;\n\nThe concatenation of A and B in this order, for some non-empty bracket sequences A and B /\n\nGiven are N strings S_i. Can a bracket sequence be formed by concatenating all the N strings in some order?\n\nConstraints\n\n1 \\leq N \\leq 10^6\n\nThe total length of the strings S_i is at most 10^6.\n\nS_i is a non-empty string consisting of ( and ).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nIf a bracket sequence can be formed by concatenating all the N strings in some order, print Yes; otherwise, print No.\n\nSample Input 1\n\n2\n)\n(()\n\nSample Output 1\n\nYes\n\nConcatenating (() and ) in this order forms a bracket sequence.\n\nSample Input 2\n\n2\n)(\n()\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n4\n((()))\n((((((\n))))))\n()()()\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n3\n(((\n)\n)\n\nSample Output 4\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5191, "cpu_time_ms": 433, "memory_kb": 167056}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s519073782", "group_id": "codeNet:p02686", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun mapa-b (fn a b &optional (step 1))\n (do ((i a (+ i step))\n (result nil))\n ((> i b) (nreverse result))\n (push (funcall fn i) result)))\n\n(defun map0-n (fn n)\n (mapa-b fn 0 n))\n\n(defun map1-n (fn n)\n (mapa-b fn 1 n))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (is-empty char)\n do (return (concatenate 'string (nreverse result)))\n do (push char result))))\n\n(defun merge-sort (lst &optional (compare #'<))\n (let ((turn 0))\n (labels ((merge-list (a b a-length b-length)\n (cond ((zerop a-length) b)\n ((zerop b-length) a)\n ((funcall compare (car b) (car a))\n (incf turn a-length)\n (cons (car b)\n (merge-list a (cdr b) a-length (1- b-length))))\n (t\n (cons (car a)\n (merge-list (cdr a) b (1- a-length) b-length)))))\n (f (lst length)\n (if (= length 1)\n lst\n (let ((mid (ash length -1)))\n (merge-list (f (subseq lst 0 mid) mid)\n (f (subseq lst mid) (- length mid))\n mid\n (- length mid))))))\n (values (f lst (length lst)) turn))))\n\n(defun group (lst &optional (test #'eql) (key nil))\n (let ((table (make-hash-table :test test)))\n (mapc (lambda (x)\n (push x (gethash (if key (funcall key x) x) table)))\n lst)\n (loop for value being each hash-value in table\n collect value)))\n\n(defun parenthese (str)\n (let ((sum 0)\n (min 0))\n (loop for i across str\n do\n (progn\n (if (char= i #\\()\n (incf sum)\n (progn\n (decf sum)\n (setf min (min min sum))))))\n (cons min sum)))\n\n\n(defun main (strs)\n (let ((nums (sort (mapcar #'parenthese strs) #'> :key #'car))\n (sum 0)\n (subber 0))\n (loop for i in nums\n when (< (+ sum (car i)) 0)\n do (return-from main nil)\n do\n (progn\n (if (>= (car i) 0)\n (incf sum (cdr i))\n (incf subber (cdr i)))))\n (= sum (- 0 subber))))\n\n(princ (if (main (collect-times (read) (read-string))) \"Yes\" \"No\"))\n", "language": "Lisp", "metadata": {"date": 1589162357, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02686.html", "problem_id": "p02686", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02686/input.txt", "sample_output_relpath": "derived/input_output/data/p02686/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02686/Lisp/s519073782.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s519073782", "user_id": "u493610446"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun mapa-b (fn a b &optional (step 1))\n (do ((i a (+ i step))\n (result nil))\n ((> i b) (nreverse result))\n (push (funcall fn i) result)))\n\n(defun map0-n (fn n)\n (mapa-b fn 0 n))\n\n(defun map1-n (fn n)\n (mapa-b fn 1 n))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (is-empty char)\n do (return (concatenate 'string (nreverse result)))\n do (push char result))))\n\n(defun merge-sort (lst &optional (compare #'<))\n (let ((turn 0))\n (labels ((merge-list (a b a-length b-length)\n (cond ((zerop a-length) b)\n ((zerop b-length) a)\n ((funcall compare (car b) (car a))\n (incf turn a-length)\n (cons (car b)\n (merge-list a (cdr b) a-length (1- b-length))))\n (t\n (cons (car a)\n (merge-list (cdr a) b (1- a-length) b-length)))))\n (f (lst length)\n (if (= length 1)\n lst\n (let ((mid (ash length -1)))\n (merge-list (f (subseq lst 0 mid) mid)\n (f (subseq lst mid) (- length mid))\n mid\n (- length mid))))))\n (values (f lst (length lst)) turn))))\n\n(defun group (lst &optional (test #'eql) (key nil))\n (let ((table (make-hash-table :test test)))\n (mapc (lambda (x)\n (push x (gethash (if key (funcall key x) x) table)))\n lst)\n (loop for value being each hash-value in table\n collect value)))\n\n(defun parenthese (str)\n (let ((sum 0)\n (min 0))\n (loop for i across str\n do\n (progn\n (if (char= i #\\()\n (incf sum)\n (progn\n (decf sum)\n (setf min (min min sum))))))\n (cons min sum)))\n\n\n(defun main (strs)\n (let ((nums (sort (mapcar #'parenthese strs) #'> :key #'car))\n (sum 0)\n (subber 0))\n (loop for i in nums\n when (< (+ sum (car i)) 0)\n do (return-from main nil)\n do\n (progn\n (if (>= (car i) 0)\n (incf sum (cdr i))\n (incf subber (cdr i)))))\n (= sum (- 0 subber))))\n\n(princ (if (main (collect-times (read) (read-string))) \"Yes\" \"No\"))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nA bracket sequence is a string that is one of the following:\n\nAn empty string;\n\nThe concatenation of (, A, and ) in this order, for some bracket sequence A ;\n\nThe concatenation of A and B in this order, for some non-empty bracket sequences A and B /\n\nGiven are N strings S_i. Can a bracket sequence be formed by concatenating all the N strings in some order?\n\nConstraints\n\n1 \\leq N \\leq 10^6\n\nThe total length of the strings S_i is at most 10^6.\n\nS_i is a non-empty string consisting of ( and ).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nIf a bracket sequence can be formed by concatenating all the N strings in some order, print Yes; otherwise, print No.\n\nSample Input 1\n\n2\n)\n(()\n\nSample Output 1\n\nYes\n\nConcatenating (() and ) in this order forms a bracket sequence.\n\nSample Input 2\n\n2\n)(\n()\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n4\n((()))\n((((((\n))))))\n()()()\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n3\n(((\n)\n)\n\nSample Output 4\n\nNo", "sample_input": "2\n)\n(()\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02686", "source_text": "Score : 600 points\n\nProblem Statement\n\nA bracket sequence is a string that is one of the following:\n\nAn empty string;\n\nThe concatenation of (, A, and ) in this order, for some bracket sequence A ;\n\nThe concatenation of A and B in this order, for some non-empty bracket sequences A and B /\n\nGiven are N strings S_i. Can a bracket sequence be formed by concatenating all the N strings in some order?\n\nConstraints\n\n1 \\leq N \\leq 10^6\n\nThe total length of the strings S_i is at most 10^6.\n\nS_i is a non-empty string consisting of ( and ).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nIf a bracket sequence can be formed by concatenating all the N strings in some order, print Yes; otherwise, print No.\n\nSample Input 1\n\n2\n)\n(()\n\nSample Output 1\n\nYes\n\nConcatenating (() and ) in this order forms a bracket sequence.\n\nSample Input 2\n\n2\n)(\n()\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n4\n((()))\n((((((\n))))))\n()()()\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n3\n(((\n)\n)\n\nSample Output 4\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4693, "cpu_time_ms": 427, "memory_kb": 116880}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s587778420", "group_id": "codeNet:p02688", "input_text": "(let* ((n (read))\n (k (read))\n (sunuke (make-array `(,(1+ n)) :initial-element nil))\n (ans 0))\n ;\n (loop :for i :from 1 :to k\n :do (let ((d (read)))\n (loop :for j :from 1 :to d\n :do (let ((a (read)))\n (setf (aref sunuke a) t)))))\n (loop :for i :from 1 :to n\n :unless (aref sunuke i)\n :do (incf ans))\n (format t \"~A~%\" ans))\n", "language": "Lisp", "metadata": {"date": 1593302180, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02688.html", "problem_id": "p02688", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02688/input.txt", "sample_output_relpath": "derived/input_output/data/p02688/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02688/Lisp/s587778420.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s587778420", "user_id": "u608227593"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let* ((n (read))\n (k (read))\n (sunuke (make-array `(,(1+ n)) :initial-element nil))\n (ans 0))\n ;\n (loop :for i :from 1 :to k\n :do (let ((d (read)))\n (loop :for j :from 1 :to d\n :do (let ((a (read)))\n (setf (aref sunuke a) t)))))\n (loop :for i :from 1 :to n\n :unless (aref sunuke i)\n :do (incf ans))\n (format t \"~A~%\" ans))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nN Snukes called Snuke 1, Snuke 2, ..., Snuke N live in a town.\n\nThere are K kinds of snacks sold in this town, called Snack 1, Snack 2, ..., Snack K. The following d_i Snukes have Snack i: Snuke A_{i, 1}, A_{i, 2}, \\cdots, A_{i, {d_i}}.\n\nTakahashi will walk around this town and make mischief on the Snukes who have no snacks. How many Snukes will fall victim to Takahashi's mischief?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n1 \\leq K \\leq 100\n\n1 \\leq d_i \\leq N\n\n1 \\leq A_{i, 1} < \\cdots < A_{i, d_i} \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nd_1\nA_{1, 1} \\cdots A_{1, d_1}\n\\vdots\nd_K\nA_{K, 1} \\cdots A_{K, d_K}\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3 2\n2\n1 3\n1\n3\n\nSample Output 1\n\n1\n\nSnuke 1 has Snack 1.\n\nSnuke 2 has no snacks.\n\nSnuke 3 has Snack 1 and 2.\n\nThus, there will be one victim: Snuke 2.\n\nSample Input 2\n\n3 3\n1\n3\n1\n3\n1\n3\n\nSample Output 2\n\n2", "sample_input": "3 2\n2\n1 3\n1\n3\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02688", "source_text": "Score : 200 points\n\nProblem Statement\n\nN Snukes called Snuke 1, Snuke 2, ..., Snuke N live in a town.\n\nThere are K kinds of snacks sold in this town, called Snack 1, Snack 2, ..., Snack K. The following d_i Snukes have Snack i: Snuke A_{i, 1}, A_{i, 2}, \\cdots, A_{i, {d_i}}.\n\nTakahashi will walk around this town and make mischief on the Snukes who have no snacks. How many Snukes will fall victim to Takahashi's mischief?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n1 \\leq K \\leq 100\n\n1 \\leq d_i \\leq N\n\n1 \\leq A_{i, 1} < \\cdots < A_{i, d_i} \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nd_1\nA_{1, 1} \\cdots A_{1, d_1}\n\\vdots\nd_K\nA_{K, 1} \\cdots A_{K, d_K}\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3 2\n2\n1 3\n1\n3\n\nSample Output 1\n\n1\n\nSnuke 1 has Snack 1.\n\nSnuke 2 has no snacks.\n\nSnuke 3 has Snack 1 and 2.\n\nThus, there will be one victim: Snuke 2.\n\nSample Input 2\n\n3 3\n1\n3\n1\n3\n1\n3\n\nSample Output 2\n\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 424, "cpu_time_ms": 29, "memory_kb": 29796}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s097958611", "group_id": "codeNet:p02689", "input_text": "(let* ((n (read))\n (m (read))\n (h (make-array `(,(1+ n))))\n (g (make-array `(,(1+ n)) :initial-element t))\n (ans 0))\n ; read\n (loop :for i :from 1 :to n\n :do (setf (aref h i) (read)))\n ;\n (loop :for i :from 1 :to m\n :do (let ((a (read))\n (b (read)))\n (if (< (aref h a) (aref h b))\n (setf (aref g a) nil)\n (setf (aref g b) nil))))\n ;\n (loop :for i :from 1 :to n\n :if (aref g i)\n :do (incf ans))\n (format t \"~A~%\" ans))\n", "language": "Lisp", "metadata": {"date": 1593303077, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02689.html", "problem_id": "p02689", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02689/input.txt", "sample_output_relpath": "derived/input_output/data/p02689/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02689/Lisp/s097958611.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s097958611", "user_id": "u608227593"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (h (make-array `(,(1+ n))))\n (g (make-array `(,(1+ n)) :initial-element t))\n (ans 0))\n ; read\n (loop :for i :from 1 :to n\n :do (setf (aref h i) (read)))\n ;\n (loop :for i :from 1 :to m\n :do (let ((a (read))\n (b (read)))\n (if (< (aref h a) (aref h b))\n (setf (aref g a) nil)\n (setf (aref g b) nil))))\n ;\n (loop :for i :from 1 :to n\n :if (aref g i)\n :do (incf ans))\n (format t \"~A~%\" ans))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i.\nThere are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.\n\nObs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road.\nNote that Obs. i is also good when no observatory can be reached from Obs. i using just one road.\n\nHow many good observatories are there?\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq H_i \\leq 10^9\n\n1 \\leq A_i,B_i \\leq N\n\nA_i \\neq B_i\n\nMultiple roads may connect the same pair of observatories.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nH_1 H_2 ... H_N\nA_1 B_1\nA_2 B_2\n:\nA_M B_M\n\nOutput\n\nPrint the number of good observatories.\n\nSample Input 1\n\n4 3\n1 2 3 4\n1 3\n2 3\n2 4\n\nSample Output 1\n\n2\n\nFrom Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.\n\nFrom Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.\n\nFrom Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.\n\nFrom Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.\n\nThus, the good observatories are Obs. 3 and 4, so there are two good observatories.\n\nSample Input 2\n\n6 5\n8 6 9 1 2 1\n1 3\n4 2\n4 3\n4 6\n4 6\n\nSample Output 2\n\n3", "sample_input": "4 3\n1 2 3 4\n1 3\n2 3\n2 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02689", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i.\nThere are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.\n\nObs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road.\nNote that Obs. i is also good when no observatory can be reached from Obs. i using just one road.\n\nHow many good observatories are there?\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq H_i \\leq 10^9\n\n1 \\leq A_i,B_i \\leq N\n\nA_i \\neq B_i\n\nMultiple roads may connect the same pair of observatories.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nH_1 H_2 ... H_N\nA_1 B_1\nA_2 B_2\n:\nA_M B_M\n\nOutput\n\nPrint the number of good observatories.\n\nSample Input 1\n\n4 3\n1 2 3 4\n1 3\n2 3\n2 4\n\nSample Output 1\n\n2\n\nFrom Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.\n\nFrom Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.\n\nFrom Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.\n\nFrom Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.\n\nThus, the good observatories are Obs. 3 and 4, so there are two good observatories.\n\nSample Input 2\n\n6 5\n8 6 9 1 2 1\n1 3\n4 2\n4 3\n4 6\n4 6\n\nSample Output 2\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 541, "cpu_time_ms": 296, "memory_kb": 78828}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s521821773", "group_id": "codeNet:p02689", "input_text": "(let* ((n (read))\n (m (read))\n (h (make-array (1+ n)))\n (flags (make-array (1+ n) :initial-element t)))\n (setf (aref flags 0) nil)\n (loop for i from 1 to n\n do (setf (aref h i) (read)))\n (loop for i from 1 to m\n do (let ((a (read))\n (b (read)))\n (when (>= (aref h a)\n (aref h b))\n (setf (aref flags b) nil))\n (when (>= (aref h b)\n (aref h a))\n (setf (aref flags a) nil))))\n (format t \"~A~%\" (count t flags)))", "language": "Lisp", "metadata": {"date": 1588557680, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02689.html", "problem_id": "p02689", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02689/input.txt", "sample_output_relpath": "derived/input_output/data/p02689/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02689/Lisp/s521821773.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s521821773", "user_id": "u607637432"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (h (make-array (1+ n)))\n (flags (make-array (1+ n) :initial-element t)))\n (setf (aref flags 0) nil)\n (loop for i from 1 to n\n do (setf (aref h i) (read)))\n (loop for i from 1 to m\n do (let ((a (read))\n (b (read)))\n (when (>= (aref h a)\n (aref h b))\n (setf (aref flags b) nil))\n (when (>= (aref h b)\n (aref h a))\n (setf (aref flags a) nil))))\n (format t \"~A~%\" (count t flags)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i.\nThere are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.\n\nObs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road.\nNote that Obs. i is also good when no observatory can be reached from Obs. i using just one road.\n\nHow many good observatories are there?\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq H_i \\leq 10^9\n\n1 \\leq A_i,B_i \\leq N\n\nA_i \\neq B_i\n\nMultiple roads may connect the same pair of observatories.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nH_1 H_2 ... H_N\nA_1 B_1\nA_2 B_2\n:\nA_M B_M\n\nOutput\n\nPrint the number of good observatories.\n\nSample Input 1\n\n4 3\n1 2 3 4\n1 3\n2 3\n2 4\n\nSample Output 1\n\n2\n\nFrom Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.\n\nFrom Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.\n\nFrom Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.\n\nFrom Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.\n\nThus, the good observatories are Obs. 3 and 4, so there are two good observatories.\n\nSample Input 2\n\n6 5\n8 6 9 1 2 1\n1 3\n4 2\n4 3\n4 6\n4 6\n\nSample Output 2\n\n3", "sample_input": "4 3\n1 2 3 4\n1 3\n2 3\n2 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02689", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i.\nThere are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.\n\nObs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road.\nNote that Obs. i is also good when no observatory can be reached from Obs. i using just one road.\n\nHow many good observatories are there?\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq H_i \\leq 10^9\n\n1 \\leq A_i,B_i \\leq N\n\nA_i \\neq B_i\n\nMultiple roads may connect the same pair of observatories.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nH_1 H_2 ... H_N\nA_1 B_1\nA_2 B_2\n:\nA_M B_M\n\nOutput\n\nPrint the number of good observatories.\n\nSample Input 1\n\n4 3\n1 2 3 4\n1 3\n2 3\n2 4\n\nSample Output 1\n\n2\n\nFrom Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.\n\nFrom Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.\n\nFrom Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.\n\nFrom Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.\n\nThus, the good observatories are Obs. 3 and 4, so there are two good observatories.\n\nSample Input 2\n\n6 5\n8 6 9 1 2 1\n1 3\n4 2\n4 3\n4 6\n4 6\n\nSample Output 2\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 554, "cpu_time_ms": 305, "memory_kb": 78776}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s460318701", "group_id": "codeNet:p02693", "input_text": ";;(declaim (optimize (speed 0) (safety 3) (debug 3)))\n#+sbcl (declaim (sb-ext:unmuffle-conditions sb-ext:compiler-note))\n(declaim (optimize (speed 3) (safety 0) (debug 0)))\n\n(defvar k (read))\n(defvar min-d (read))\n(defvar max-d (read))\n\n(format t \"~:[NG~;OK~]\" (<= (ceiling min-d k) ;; min multiple of k ge min-d\n\t\t\t (floor max-d k))) ;; max mutiple of k le max-d\n", "language": "Lisp", "metadata": {"date": 1590235570, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02693.html", "problem_id": "p02693", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02693/input.txt", "sample_output_relpath": "derived/input_output/data/p02693/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02693/Lisp/s460318701.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s460318701", "user_id": "u203134021"}, "prompt_components": {"gold_output": "OK\n", "input_to_evaluate": ";;(declaim (optimize (speed 0) (safety 3) (debug 3)))\n#+sbcl (declaim (sb-ext:unmuffle-conditions sb-ext:compiler-note))\n(declaim (optimize (speed 3) (safety 0) (debug 0)))\n\n(defvar k (read))\n(defvar min-d (read))\n(defvar max-d (read))\n\n(format t \"~:[NG~;OK~]\" (<= (ceiling min-d k) ;; min multiple of k ge min-d\n\t\t\t (floor max-d k))) ;; max mutiple of k le max-d\n", "problem_context": "Score: 100 points\n\nProblem Statement\n\nTakahashi the Jumbo will practice golf.\n\nHis objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive).\n\nIf he can achieve the objective, print OK; if he cannot, print NG.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A \\leq B \\leq 1000\n\n1 \\leq K \\leq 1000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\nA B\n\nOutput\n\nIf he can achieve the objective, print OK; if he cannot, print NG.\n\nSample Input 1\n\n7\n500 600\n\nSample Output 1\n\nOK\n\nAmong the multiples of 7, for example, 567 lies between 500 and 600.\n\nSample Input 2\n\n4\n5 7\n\nSample Output 2\n\nNG\n\nNo multiple of 4 lies between 5 and 7.\n\nSample Input 3\n\n1\n11 11\n\nSample Output 3\n\nOK", "sample_input": "7\n500 600\n"}, "reference_outputs": ["OK\n"], "source_document_id": "p02693", "source_text": "Score: 100 points\n\nProblem Statement\n\nTakahashi the Jumbo will practice golf.\n\nHis objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive).\n\nIf he can achieve the objective, print OK; if he cannot, print NG.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A \\leq B \\leq 1000\n\n1 \\leq K \\leq 1000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\nA B\n\nOutput\n\nIf he can achieve the objective, print OK; if he cannot, print NG.\n\nSample Input 1\n\n7\n500 600\n\nSample Output 1\n\nOK\n\nAmong the multiples of 7, for example, 567 lies between 500 and 600.\n\nSample Input 2\n\n4\n5 7\n\nSample Output 2\n\nNG\n\nNo multiple of 4 lies between 5 and 7.\n\nSample Input 3\n\n1\n11 11\n\nSample Output 3\n\nOK", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 367, "cpu_time_ms": 17, "memory_kb": 23516}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s742655805", "group_id": "codeNet:p02693", "input_text": "(let ((K (read))\n (A (read))\n (B (read))))\n(princ (if (<= A (* (floor (/ B K)) K)) \"OK\" \"NG\"))\n", "language": "Lisp", "metadata": {"date": 1588475604, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02693.html", "problem_id": "p02693", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02693/input.txt", "sample_output_relpath": "derived/input_output/data/p02693/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02693/Lisp/s742655805.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s742655805", "user_id": "u631655863"}, "prompt_components": {"gold_output": "OK\n", "input_to_evaluate": "(let ((K (read))\n (A (read))\n (B (read))))\n(princ (if (<= A (* (floor (/ B K)) K)) \"OK\" \"NG\"))\n", "problem_context": "Score: 100 points\n\nProblem Statement\n\nTakahashi the Jumbo will practice golf.\n\nHis objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive).\n\nIf he can achieve the objective, print OK; if he cannot, print NG.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A \\leq B \\leq 1000\n\n1 \\leq K \\leq 1000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\nA B\n\nOutput\n\nIf he can achieve the objective, print OK; if he cannot, print NG.\n\nSample Input 1\n\n7\n500 600\n\nSample Output 1\n\nOK\n\nAmong the multiples of 7, for example, 567 lies between 500 and 600.\n\nSample Input 2\n\n4\n5 7\n\nSample Output 2\n\nNG\n\nNo multiple of 4 lies between 5 and 7.\n\nSample Input 3\n\n1\n11 11\n\nSample Output 3\n\nOK", "sample_input": "7\n500 600\n"}, "reference_outputs": ["OK\n"], "source_document_id": "p02693", "source_text": "Score: 100 points\n\nProblem Statement\n\nTakahashi the Jumbo will practice golf.\n\nHis objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive).\n\nIf he can achieve the objective, print OK; if he cannot, print NG.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A \\leq B \\leq 1000\n\n1 \\leq K \\leq 1000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\nA B\n\nOutput\n\nIf he can achieve the objective, print OK; if he cannot, print NG.\n\nSample Input 1\n\n7\n500 600\n\nSample Output 1\n\nOK\n\nAmong the multiples of 7, for example, 567 lies between 500 and 600.\n\nSample Input 2\n\n4\n5 7\n\nSample Output 2\n\nNG\n\nNo multiple of 4 lies between 5 and 7.\n\nSample Input 3\n\n1\n11 11\n\nSample Output 3\n\nOK", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 105, "cpu_time_ms": 105, "memory_kb": 26500}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s763699600", "group_id": "codeNet:p02693", "input_text": "(defun solve (K A B)\n (if (= A B)\n (if (= (mod A K) 0)\n \"OK\"\n \"NO\")\n (if (< 0 (- (ceiling (/ B K)) (ceiling (/ A K))))\n \"OK\"\n \"NO\")))\n\n(princ (solve 4 5 7))\n", "language": "Lisp", "metadata": {"date": 1588472726, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02693.html", "problem_id": "p02693", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02693/input.txt", "sample_output_relpath": "derived/input_output/data/p02693/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02693/Lisp/s763699600.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s763699600", "user_id": "u631655863"}, "prompt_components": {"gold_output": "OK\n", "input_to_evaluate": "(defun solve (K A B)\n (if (= A B)\n (if (= (mod A K) 0)\n \"OK\"\n \"NO\")\n (if (< 0 (- (ceiling (/ B K)) (ceiling (/ A K))))\n \"OK\"\n \"NO\")))\n\n(princ (solve 4 5 7))\n", "problem_context": "Score: 100 points\n\nProblem Statement\n\nTakahashi the Jumbo will practice golf.\n\nHis objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive).\n\nIf he can achieve the objective, print OK; if he cannot, print NG.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A \\leq B \\leq 1000\n\n1 \\leq K \\leq 1000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\nA B\n\nOutput\n\nIf he can achieve the objective, print OK; if he cannot, print NG.\n\nSample Input 1\n\n7\n500 600\n\nSample Output 1\n\nOK\n\nAmong the multiples of 7, for example, 567 lies between 500 and 600.\n\nSample Input 2\n\n4\n5 7\n\nSample Output 2\n\nNG\n\nNo multiple of 4 lies between 5 and 7.\n\nSample Input 3\n\n1\n11 11\n\nSample Output 3\n\nOK", "sample_input": "7\n500 600\n"}, "reference_outputs": ["OK\n"], "source_document_id": "p02693", "source_text": "Score: 100 points\n\nProblem Statement\n\nTakahashi the Jumbo will practice golf.\n\nHis objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive).\n\nIf he can achieve the objective, print OK; if he cannot, print NG.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A \\leq B \\leq 1000\n\n1 \\leq K \\leq 1000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\nA B\n\nOutput\n\nIf he can achieve the objective, print OK; if he cannot, print NG.\n\nSample Input 1\n\n7\n500 600\n\nSample Output 1\n\nOK\n\nAmong the multiples of 7, for example, 567 lies between 500 and 600.\n\nSample Input 2\n\n4\n5 7\n\nSample Output 2\n\nNG\n\nNo multiple of 4 lies between 5 and 7.\n\nSample Input 3\n\n1\n11 11\n\nSample Output 3\n\nOK", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 204, "cpu_time_ms": 17, "memory_kb": 24372}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s848311587", "group_id": "codeNet:p02694", "input_text": ";;(declaim (optimize (speed 0) (safety 3) (debug 3)))\n#+sbcl (declaim (sb-ext:unmuffle-conditions sb-ext:compiler-note))\n(declaim (optimize (speed 3) (safety 0) (debug 0)))\n\n(declaim (type fixnum *x*))\n(defvar *x* (read))\n\n;; 100 * 1.01^n > x\n;; 1.01^n > x/100\n;; n log(1.01) > log(x/100)\n;; n = ceiling(log(x/100) / log(1.01))\n\n;; x = 10^18 then n = ceiling(16/log(1.01)) = 3703, acceptable\n\n(princ (let ((x 100)\n\t (i 0))\n\t (loop\n\t (if (>= x *x*)\n\t (return i)\n\t (psetf i (1+ i) x (floor (* x 101/100)))))))\n\n\n", "language": "Lisp", "metadata": {"date": 1590236118, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02694.html", "problem_id": "p02694", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02694/input.txt", "sample_output_relpath": "derived/input_output/data/p02694/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02694/Lisp/s848311587.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s848311587", "user_id": "u203134021"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";;(declaim (optimize (speed 0) (safety 3) (debug 3)))\n#+sbcl (declaim (sb-ext:unmuffle-conditions sb-ext:compiler-note))\n(declaim (optimize (speed 3) (safety 0) (debug 0)))\n\n(declaim (type fixnum *x*))\n(defvar *x* (read))\n\n;; 100 * 1.01^n > x\n;; 1.01^n > x/100\n;; n log(1.01) > log(x/100)\n;; n = ceiling(log(x/100) / log(1.01))\n\n;; x = 10^18 then n = ceiling(16/log(1.01)) = 3703, acceptable\n\n(princ (let ((x 100)\n\t (i 0))\n\t (loop\n\t (if (>= x *x*)\n\t (return i)\n\t (psetf i (1+ i) x (floor (* x 101/100)))))))\n\n\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.\n\nThe bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)\n\nAssuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?\n\nConstraints\n\n101 \\le X \\le 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the number of years it takes for Takahashi's balance to reach X yen or above for the first time.\n\nSample Input 1\n\n103\n\nSample Output 1\n\n3\n\nThe balance after one year is 101 yen.\n\nThe balance after two years is 102 yen.\n\nThe balance after three years is 103 yen.\n\nThus, it takes three years for the balance to reach 103 yen or above.\n\nSample Input 2\n\n1000000000000000000\n\nSample Output 2\n\n3760\n\nSample Input 3\n\n1333333333\n\nSample Output 3\n\n1706", "sample_input": "103\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02694", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.\n\nThe bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)\n\nAssuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?\n\nConstraints\n\n101 \\le X \\le 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the number of years it takes for Takahashi's balance to reach X yen or above for the first time.\n\nSample Input 1\n\n103\n\nSample Output 1\n\n3\n\nThe balance after one year is 101 yen.\n\nThe balance after two years is 102 yen.\n\nThe balance after three years is 103 yen.\n\nThus, it takes three years for the balance to reach 103 yen or above.\n\nSample Input 2\n\n1000000000000000000\n\nSample Output 2\n\n3760\n\nSample Input 3\n\n1333333333\n\nSample Output 3\n\n1706", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 523, "cpu_time_ms": 15, "memory_kb": 24852}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s933984472", "group_id": "codeNet:p02694", "input_text": "(let ((x (read)))\n (loop :for i :from 1\n :for y := (floor (* (if (= 1 i) 100 y) 1.01))\n :do (if (<= x y)\n (progn \n (format t \"~A~%\" i)\n (return)))))\n", "language": "Lisp", "metadata": {"date": 1588469653, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02694.html", "problem_id": "p02694", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02694/input.txt", "sample_output_relpath": "derived/input_output/data/p02694/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02694/Lisp/s933984472.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s933984472", "user_id": "u608227593"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((x (read)))\n (loop :for i :from 1\n :for y := (floor (* (if (= 1 i) 100 y) 1.01))\n :do (if (<= x y)\n (progn \n (format t \"~A~%\" i)\n (return)))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.\n\nThe bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)\n\nAssuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?\n\nConstraints\n\n101 \\le X \\le 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the number of years it takes for Takahashi's balance to reach X yen or above for the first time.\n\nSample Input 1\n\n103\n\nSample Output 1\n\n3\n\nThe balance after one year is 101 yen.\n\nThe balance after two years is 102 yen.\n\nThe balance after three years is 103 yen.\n\nThus, it takes three years for the balance to reach 103 yen or above.\n\nSample Input 2\n\n1000000000000000000\n\nSample Output 2\n\n3760\n\nSample Input 3\n\n1333333333\n\nSample Output 3\n\n1706", "sample_input": "103\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02694", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.\n\nThe bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)\n\nAssuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?\n\nConstraints\n\n101 \\le X \\le 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the number of years it takes for Takahashi's balance to reach X yen or above for the first time.\n\nSample Input 1\n\n103\n\nSample Output 1\n\n3\n\nThe balance after one year is 101 yen.\n\nThe balance after two years is 102 yen.\n\nThe balance after three years is 103 yen.\n\nThus, it takes three years for the balance to reach 103 yen or above.\n\nSample Input 2\n\n1000000000000000000\n\nSample Output 2\n\n3760\n\nSample Input 3\n\n1333333333\n\nSample Output 3\n\n1706", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 213, "cpu_time_ms": 14, "memory_kb": 24592}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s162367838", "group_id": "codeNet:p02694", "input_text": "(let ((x (read)))\n (loop :for i :from 0\n :for y := (floor (* (if (= 0 i) 100 y) 1.01))\n :while (< y x)\n :finally (format t \"~A~%\" (1+ i))))\n", "language": "Lisp", "metadata": {"date": 1588469273, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02694.html", "problem_id": "p02694", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02694/input.txt", "sample_output_relpath": "derived/input_output/data/p02694/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02694/Lisp/s162367838.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s162367838", "user_id": "u608227593"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((x (read)))\n (loop :for i :from 0\n :for y := (floor (* (if (= 0 i) 100 y) 1.01))\n :while (< y x)\n :finally (format t \"~A~%\" (1+ i))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.\n\nThe bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)\n\nAssuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?\n\nConstraints\n\n101 \\le X \\le 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the number of years it takes for Takahashi's balance to reach X yen or above for the first time.\n\nSample Input 1\n\n103\n\nSample Output 1\n\n3\n\nThe balance after one year is 101 yen.\n\nThe balance after two years is 102 yen.\n\nThe balance after three years is 103 yen.\n\nThus, it takes three years for the balance to reach 103 yen or above.\n\nSample Input 2\n\n1000000000000000000\n\nSample Output 2\n\n3760\n\nSample Input 3\n\n1333333333\n\nSample Output 3\n\n1706", "sample_input": "103\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02694", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.\n\nThe bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)\n\nAssuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?\n\nConstraints\n\n101 \\le X \\le 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the number of years it takes for Takahashi's balance to reach X yen or above for the first time.\n\nSample Input 1\n\n103\n\nSample Output 1\n\n3\n\nThe balance after one year is 101 yen.\n\nThe balance after two years is 102 yen.\n\nThe balance after three years is 103 yen.\n\nThus, it takes three years for the balance to reach 103 yen or above.\n\nSample Input 2\n\n1000000000000000000\n\nSample Output 2\n\n3760\n\nSample Input 3\n\n1333333333\n\nSample Output 3\n\n1706", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 162, "cpu_time_ms": 16, "memory_kb": 24536}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s374613944", "group_id": "codeNet:p02696", "input_text": "(defun ev (a b x)\n (- (floor (/ (* a x) b)) (* a (floor (/ x b)))))\n\n(let ((a (read))\n (b (read))\n (n (read)))\n (if(>= n (1- b))\n (format t \"~A~%\" (1- (min a b)))\n (format t \"~A~%\" (ev a b n))))\n", "language": "Lisp", "metadata": {"date": 1594061722, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02696.html", "problem_id": "p02696", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02696/input.txt", "sample_output_relpath": "derived/input_output/data/p02696/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02696/Lisp/s374613944.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s374613944", "user_id": "u608227593"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun ev (a b x)\n (- (floor (/ (* a x) b)) (* a (floor (/ x b)))))\n\n(let ((a (read))\n (b (read))\n (n (read)))\n (if(>= n (1- b))\n (format t \"~A~%\" (1- (min a b)))\n (format t \"~A~%\" (ev a b n))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nGiven are integers A, B, and N.\n\nFind the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.\n\nHere floor(t) denotes the greatest integer not greater than the real number t.\n\nConstraints\n\n1 ≤ A ≤ 10^{6}\n\n1 ≤ B ≤ 10^{12}\n\n1 ≤ N ≤ 10^{12}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B N\n\nOutput\n\nPrint the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N, as an integer.\n\nSample Input 1\n\n5 7 4\n\nSample Output 1\n\n2\n\nWhen x=3, floor(Ax/B)-A×floor(x/B) = floor(15/7) - 5×floor(3/7) = 2. This is the maximum value possible.\n\nSample Input 2\n\n11 10 9\n\nSample Output 2\n\n9", "sample_input": "5 7 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02696", "source_text": "Score : 400 points\n\nProblem Statement\n\nGiven are integers A, B, and N.\n\nFind the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.\n\nHere floor(t) denotes the greatest integer not greater than the real number t.\n\nConstraints\n\n1 ≤ A ≤ 10^{6}\n\n1 ≤ B ≤ 10^{12}\n\n1 ≤ N ≤ 10^{12}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B N\n\nOutput\n\nPrint the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N, as an integer.\n\nSample Input 1\n\n5 7 4\n\nSample Output 1\n\n2\n\nWhen x=3, floor(Ax/B)-A×floor(x/B) = floor(15/7) - 5×floor(3/7) = 2. This is the maximum value possible.\n\nSample Input 2\n\n11 10 9\n\nSample Output 2\n\n9", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 215, "cpu_time_ms": 21, "memory_kb": 24552}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s938841684", "group_id": "codeNet:p02696", "input_text": "(defun calc (x a b n)\n (- (floor (/ (* a x) b))\n (* a (floor (/ x b)))))\n\n(let ((a (read))\n (b (read))\n (n (read)))\n (format t \"~A\" (if (<= b n)\n (calc (1- b) a b n)\n (calc n a b n))))\n", "language": "Lisp", "metadata": {"date": 1588472390, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02696.html", "problem_id": "p02696", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02696/input.txt", "sample_output_relpath": "derived/input_output/data/p02696/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02696/Lisp/s938841684.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s938841684", "user_id": "u425317134"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun calc (x a b n)\n (- (floor (/ (* a x) b))\n (* a (floor (/ x b)))))\n\n(let ((a (read))\n (b (read))\n (n (read)))\n (format t \"~A\" (if (<= b n)\n (calc (1- b) a b n)\n (calc n a b n))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nGiven are integers A, B, and N.\n\nFind the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.\n\nHere floor(t) denotes the greatest integer not greater than the real number t.\n\nConstraints\n\n1 ≤ A ≤ 10^{6}\n\n1 ≤ B ≤ 10^{12}\n\n1 ≤ N ≤ 10^{12}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B N\n\nOutput\n\nPrint the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N, as an integer.\n\nSample Input 1\n\n5 7 4\n\nSample Output 1\n\n2\n\nWhen x=3, floor(Ax/B)-A×floor(x/B) = floor(15/7) - 5×floor(3/7) = 2. This is the maximum value possible.\n\nSample Input 2\n\n11 10 9\n\nSample Output 2\n\n9", "sample_input": "5 7 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02696", "source_text": "Score : 400 points\n\nProblem Statement\n\nGiven are integers A, B, and N.\n\nFind the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.\n\nHere floor(t) denotes the greatest integer not greater than the real number t.\n\nConstraints\n\n1 ≤ A ≤ 10^{6}\n\n1 ≤ B ≤ 10^{12}\n\n1 ≤ N ≤ 10^{12}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B N\n\nOutput\n\nPrint the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N, as an integer.\n\nSample Input 1\n\n5 7 4\n\nSample Output 1\n\n2\n\nWhen x=3, floor(Ax/B)-A×floor(x/B) = floor(15/7) - 5×floor(3/7) = 2. This is the maximum value possible.\n\nSample Input 2\n\n11 10 9\n\nSample Output 2\n\n9", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 250, "cpu_time_ms": 14, "memory_kb": 24340}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s122508101", "group_id": "codeNet:p02696", "input_text": "(defun calc (x a b n)\n (- (floor (/ (* a x) b))\n (* a (floor (/ x b)))))\n\n(let ((a (read))\n (b (read))\n (n (read)))\n (format t \"~A\" (if (< b n)\n (calc (1- b) a b n)\n (calc n a b n))))", "language": "Lisp", "metadata": {"date": 1588471783, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02696.html", "problem_id": "p02696", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02696/input.txt", "sample_output_relpath": "derived/input_output/data/p02696/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02696/Lisp/s122508101.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s122508101", "user_id": "u425317134"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun calc (x a b n)\n (- (floor (/ (* a x) b))\n (* a (floor (/ x b)))))\n\n(let ((a (read))\n (b (read))\n (n (read)))\n (format t \"~A\" (if (< b n)\n (calc (1- b) a b n)\n (calc n a b n))))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nGiven are integers A, B, and N.\n\nFind the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.\n\nHere floor(t) denotes the greatest integer not greater than the real number t.\n\nConstraints\n\n1 ≤ A ≤ 10^{6}\n\n1 ≤ B ≤ 10^{12}\n\n1 ≤ N ≤ 10^{12}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B N\n\nOutput\n\nPrint the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N, as an integer.\n\nSample Input 1\n\n5 7 4\n\nSample Output 1\n\n2\n\nWhen x=3, floor(Ax/B)-A×floor(x/B) = floor(15/7) - 5×floor(3/7) = 2. This is the maximum value possible.\n\nSample Input 2\n\n11 10 9\n\nSample Output 2\n\n9", "sample_input": "5 7 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02696", "source_text": "Score : 400 points\n\nProblem Statement\n\nGiven are integers A, B, and N.\n\nFind the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.\n\nHere floor(t) denotes the greatest integer not greater than the real number t.\n\nConstraints\n\n1 ≤ A ≤ 10^{6}\n\n1 ≤ B ≤ 10^{12}\n\n1 ≤ N ≤ 10^{12}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B N\n\nOutput\n\nPrint the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N, as an integer.\n\nSample Input 1\n\n5 7 4\n\nSample Output 1\n\n2\n\nWhen x=3, floor(Ax/B)-A×floor(x/B) = floor(15/7) - 5×floor(3/7) = 2. This is the maximum value possible.\n\nSample Input 2\n\n11 10 9\n\nSample Output 2\n\n9", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 248, "cpu_time_ms": 15, "memory_kb": 24304}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s896863707", "group_id": "codeNet:p02696", "input_text": "(let ((a (read))\n (b (read))\n (n (read))\n (c 0))\n (loop :for x :from 1 :to n\n :for d := (- (floor (/ (* a x) b))\n (* a (floor (/ x b))))\n :do (if (< c d)\n (setf c d)))\n (format t \"~A~%\" c))\n", "language": "Lisp", "metadata": {"date": 1588471471, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02696.html", "problem_id": "p02696", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02696/input.txt", "sample_output_relpath": "derived/input_output/data/p02696/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02696/Lisp/s896863707.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s896863707", "user_id": "u608227593"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (n (read))\n (c 0))\n (loop :for x :from 1 :to n\n :for d := (- (floor (/ (* a x) b))\n (* a (floor (/ x b))))\n :do (if (< c d)\n (setf c d)))\n (format t \"~A~%\" c))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nGiven are integers A, B, and N.\n\nFind the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.\n\nHere floor(t) denotes the greatest integer not greater than the real number t.\n\nConstraints\n\n1 ≤ A ≤ 10^{6}\n\n1 ≤ B ≤ 10^{12}\n\n1 ≤ N ≤ 10^{12}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B N\n\nOutput\n\nPrint the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N, as an integer.\n\nSample Input 1\n\n5 7 4\n\nSample Output 1\n\n2\n\nWhen x=3, floor(Ax/B)-A×floor(x/B) = floor(15/7) - 5×floor(3/7) = 2. This is the maximum value possible.\n\nSample Input 2\n\n11 10 9\n\nSample Output 2\n\n9", "sample_input": "5 7 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02696", "source_text": "Score : 400 points\n\nProblem Statement\n\nGiven are integers A, B, and N.\n\nFind the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.\n\nHere floor(t) denotes the greatest integer not greater than the real number t.\n\nConstraints\n\n1 ≤ A ≤ 10^{6}\n\n1 ≤ B ≤ 10^{12}\n\n1 ≤ N ≤ 10^{12}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B N\n\nOutput\n\nPrint the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N, as an integer.\n\nSample Input 1\n\n5 7 4\n\nSample Output 1\n\n2\n\nWhen x=3, floor(Ax/B)-A×floor(x/B) = floor(15/7) - 5×floor(3/7) = 2. This is the maximum value possible.\n\nSample Input 2\n\n11 10 9\n\nSample Output 2\n\n9", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 256, "cpu_time_ms": 2207, "memory_kb": 76624}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s968950166", "group_id": "codeNet:p02696", "input_text": "(let ((A (read))\n (B (read))\n (N (read)))\n (princ (floor (* A (min (1- B) N))\n B)))", "language": "Lisp", "metadata": {"date": 1588470022, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02696.html", "problem_id": "p02696", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02696/input.txt", "sample_output_relpath": "derived/input_output/data/p02696/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02696/Lisp/s968950166.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s968950166", "user_id": "u334552723"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((A (read))\n (B (read))\n (N (read)))\n (princ (floor (* A (min (1- B) N))\n B)))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nGiven are integers A, B, and N.\n\nFind the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.\n\nHere floor(t) denotes the greatest integer not greater than the real number t.\n\nConstraints\n\n1 ≤ A ≤ 10^{6}\n\n1 ≤ B ≤ 10^{12}\n\n1 ≤ N ≤ 10^{12}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B N\n\nOutput\n\nPrint the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N, as an integer.\n\nSample Input 1\n\n5 7 4\n\nSample Output 1\n\n2\n\nWhen x=3, floor(Ax/B)-A×floor(x/B) = floor(15/7) - 5×floor(3/7) = 2. This is the maximum value possible.\n\nSample Input 2\n\n11 10 9\n\nSample Output 2\n\n9", "sample_input": "5 7 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02696", "source_text": "Score : 400 points\n\nProblem Statement\n\nGiven are integers A, B, and N.\n\nFind the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.\n\nHere floor(t) denotes the greatest integer not greater than the real number t.\n\nConstraints\n\n1 ≤ A ≤ 10^{6}\n\n1 ≤ B ≤ 10^{12}\n\n1 ≤ N ≤ 10^{12}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B N\n\nOutput\n\nPrint the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N, as an integer.\n\nSample Input 1\n\n5 7 4\n\nSample Output 1\n\n2\n\nWhen x=3, floor(Ax/B)-A×floor(x/B) = floor(15/7) - 5×floor(3/7) = 2. This is the maximum value possible.\n\nSample Input 2\n\n11 10 9\n\nSample Output 2\n\n9", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 115, "cpu_time_ms": 16, "memory_kb": 24132}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s516597360", "group_id": "codeNet:p02697", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun test (n pairs)\n (let ((dp (make-array n :element-type 'uint32))\n (mat (make-array (list n n) :element-type 'bit :initial-element 0)))\n (dotimes (i n)\n (setf (aref dp i) (+ i 1)))\n (dotimes (_ n)\n #>mat\n (loop for (x . y) across pairs\n do (assert (zerop (aref mat (- x 1) (- y 1))))\n (setf (aref mat (- x 1) (- y 1)) 1\n (aref mat (- y 1) (- x 1)) 1))\n (loop for (x . y) across pairs\n for i below n\n do (setf (aref pairs i)\n (cons (if (zerop (- x 1)) n (- x 1))\n (if (zerop (- y 1)) n (- y 1)))))\n #>pairs)))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (table (make-hash-table :test #'eq)))\n (assert (<= m (floor n 2)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (cond\n ((and (= n 4) (= m 1))\n (write-line \"2 3\"))\n ((oddp n)\n (loop for i from 1 to m\n do (format t \"~D ~D~%\" i (+ 1 (- n i)))))\n ((and (evenp n) (= (+ 2 (* 2 m)) n))\n ;; (error \"Huh?\")\n ;; (error \"Huh?\")\n (loop with j = n\n for i from 1 to m\n do (loop (unless (or (gethash (abs (- j i)) table)\n (gethash (- n (abs (- j i))) table)\n (= (ash n -1) (abs (- j i))))\n (return))\n (decf j))\n (setf (gethash (abs (- j i)) table) t\n (gethash (- n (abs (- j i))) table) t)\n #>(sb-impl::%hash-table-alist table)\n (format t \"~D ~D~%\" i j)\n (decf j)))\n (t\n (loop for i from 1 to m\n do (format t \"~D ~D~%\" i (+ 1 (- n i))))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 1\n\"\n \"2 3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7 3\n\"\n \"1 6\n2 5\n3 4\n\")))\n", "language": "Lisp", "metadata": {"date": 1588475016, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02697.html", "problem_id": "p02697", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02697/input.txt", "sample_output_relpath": "derived/input_output/data/p02697/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02697/Lisp/s516597360.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s516597360", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2 3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun test (n pairs)\n (let ((dp (make-array n :element-type 'uint32))\n (mat (make-array (list n n) :element-type 'bit :initial-element 0)))\n (dotimes (i n)\n (setf (aref dp i) (+ i 1)))\n (dotimes (_ n)\n #>mat\n (loop for (x . y) across pairs\n do (assert (zerop (aref mat (- x 1) (- y 1))))\n (setf (aref mat (- x 1) (- y 1)) 1\n (aref mat (- y 1) (- x 1)) 1))\n (loop for (x . y) across pairs\n for i below n\n do (setf (aref pairs i)\n (cons (if (zerop (- x 1)) n (- x 1))\n (if (zerop (- y 1)) n (- y 1)))))\n #>pairs)))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (table (make-hash-table :test #'eq)))\n (assert (<= m (floor n 2)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (cond\n ((and (= n 4) (= m 1))\n (write-line \"2 3\"))\n ((oddp n)\n (loop for i from 1 to m\n do (format t \"~D ~D~%\" i (+ 1 (- n i)))))\n ((and (evenp n) (= (+ 2 (* 2 m)) n))\n ;; (error \"Huh?\")\n ;; (error \"Huh?\")\n (loop with j = n\n for i from 1 to m\n do (loop (unless (or (gethash (abs (- j i)) table)\n (gethash (- n (abs (- j i))) table)\n (= (ash n -1) (abs (- j i))))\n (return))\n (decf j))\n (setf (gethash (abs (- j i)) table) t\n (gethash (- n (abs (- j i))) table) t)\n #>(sb-impl::%hash-table-alist table)\n (format t \"~D ~D~%\" i j)\n (decf j)))\n (t\n (loop for i from 1 to m\n do (format t \"~D ~D~%\" i (+ 1 (- n i))))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 1\n\"\n \"2 3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7 3\n\"\n \"1 6\n2 5\n3 4\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nYou are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.)\nN players will participate in this competition, and they are given distinct integers from 1 through N.\nThe arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive).\nYou cannot assign the same integer to multiple playing fields.\nThe competition consists of N rounds, each of which proceeds as follows:\n\nFor each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.\n\nThen, each player adds 1 to its integer. If it becomes N+1, change it to 1.\n\nYou want to ensure that no player fights the same opponent more than once during the N rounds.\nPrint an assignment of integers to the playing fields satisfying this condition.\nIt can be proved that such an assignment always exists under the constraints given.\n\nConstraints\n\n1 \\leq M\n\nM \\times 2 +1 \\leq N \\leq 200000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nPrint M lines in the format below.\nThe i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.\n\na_1 b_1\na_2 b_2\n:\na_M b_M\n\nSample Input 1\n\n4 1\n\nSample Output 1\n\n2 3\n\nLet us call the four players A, B, C, and D, and assume that they are initially given the integers 1, 2, 3, and 4, respectively.\n\nThe 1-st round is fought by B and C, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 2, 3, 4, and 1, respectively.\n\nThe 2-nd round is fought by A and B, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 3, 4, 1, and 2, respectively.\n\nThe 3-rd round is fought by D and A, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 4, 1, 2, and 3, respectively.\n\nThe 4-th round is fought by C and D, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 1, 2, 3, and 4, respectively.\n\nNo player fights the same opponent more than once during the four rounds, so this solution will be accepted.\n\nSample Input 2\n\n7 3\n\nSample Output 2\n\n1 6\n2 5\n3 4", "sample_input": "4 1\n"}, "reference_outputs": ["2 3\n"], "source_document_id": "p02697", "source_text": "Score : 500 points\n\nProblem Statement\n\nYou are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.)\nN players will participate in this competition, and they are given distinct integers from 1 through N.\nThe arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive).\nYou cannot assign the same integer to multiple playing fields.\nThe competition consists of N rounds, each of which proceeds as follows:\n\nFor each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.\n\nThen, each player adds 1 to its integer. If it becomes N+1, change it to 1.\n\nYou want to ensure that no player fights the same opponent more than once during the N rounds.\nPrint an assignment of integers to the playing fields satisfying this condition.\nIt can be proved that such an assignment always exists under the constraints given.\n\nConstraints\n\n1 \\leq M\n\nM \\times 2 +1 \\leq N \\leq 200000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nPrint M lines in the format below.\nThe i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.\n\na_1 b_1\na_2 b_2\n:\na_M b_M\n\nSample Input 1\n\n4 1\n\nSample Output 1\n\n2 3\n\nLet us call the four players A, B, C, and D, and assume that they are initially given the integers 1, 2, 3, and 4, respectively.\n\nThe 1-st round is fought by B and C, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 2, 3, 4, and 1, respectively.\n\nThe 2-nd round is fought by A and B, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 3, 4, 1, and 2, respectively.\n\nThe 3-rd round is fought by D and A, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 4, 1, 2, and 3, respectively.\n\nThe 4-th round is fought by C and D, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 1, 2, 3, and 4, respectively.\n\nNo player fights the same opponent more than once during the four rounds, so this solution will be accepted.\n\nSample Input 2\n\n7 3\n\nSample Output 2\n\n1 6\n2 5\n3 4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5352, "cpu_time_ms": 2208, "memory_kb": 90488}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s200972506", "group_id": "codeNet:p02697", "input_text": "(defun calc (n m)\n (loop for i from 0 below m\n collect (list (- (floor (/ n 2)) i)\n (+ (floor (/ n 2)) i 1))))\n\n\n(let ((n (read))\n (m (read)))\n (loop for i in (calc n m)\n do (format t \"~A ~A~&\" (car i) (cadr i))))", "language": "Lisp", "metadata": {"date": 1588473118, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02697.html", "problem_id": "p02697", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02697/input.txt", "sample_output_relpath": "derived/input_output/data/p02697/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02697/Lisp/s200972506.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s200972506", "user_id": "u425317134"}, "prompt_components": {"gold_output": "2 3\n", "input_to_evaluate": "(defun calc (n m)\n (loop for i from 0 below m\n collect (list (- (floor (/ n 2)) i)\n (+ (floor (/ n 2)) i 1))))\n\n\n(let ((n (read))\n (m (read)))\n (loop for i in (calc n m)\n do (format t \"~A ~A~&\" (car i) (cadr i))))", "problem_context": "Score : 500 points\n\nProblem Statement\n\nYou are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.)\nN players will participate in this competition, and they are given distinct integers from 1 through N.\nThe arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive).\nYou cannot assign the same integer to multiple playing fields.\nThe competition consists of N rounds, each of which proceeds as follows:\n\nFor each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.\n\nThen, each player adds 1 to its integer. If it becomes N+1, change it to 1.\n\nYou want to ensure that no player fights the same opponent more than once during the N rounds.\nPrint an assignment of integers to the playing fields satisfying this condition.\nIt can be proved that such an assignment always exists under the constraints given.\n\nConstraints\n\n1 \\leq M\n\nM \\times 2 +1 \\leq N \\leq 200000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nPrint M lines in the format below.\nThe i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.\n\na_1 b_1\na_2 b_2\n:\na_M b_M\n\nSample Input 1\n\n4 1\n\nSample Output 1\n\n2 3\n\nLet us call the four players A, B, C, and D, and assume that they are initially given the integers 1, 2, 3, and 4, respectively.\n\nThe 1-st round is fought by B and C, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 2, 3, 4, and 1, respectively.\n\nThe 2-nd round is fought by A and B, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 3, 4, 1, and 2, respectively.\n\nThe 3-rd round is fought by D and A, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 4, 1, 2, and 3, respectively.\n\nThe 4-th round is fought by C and D, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 1, 2, 3, and 4, respectively.\n\nNo player fights the same opponent more than once during the four rounds, so this solution will be accepted.\n\nSample Input 2\n\n7 3\n\nSample Output 2\n\n1 6\n2 5\n3 4", "sample_input": "4 1\n"}, "reference_outputs": ["2 3\n"], "source_document_id": "p02697", "source_text": "Score : 500 points\n\nProblem Statement\n\nYou are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.)\nN players will participate in this competition, and they are given distinct integers from 1 through N.\nThe arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive).\nYou cannot assign the same integer to multiple playing fields.\nThe competition consists of N rounds, each of which proceeds as follows:\n\nFor each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.\n\nThen, each player adds 1 to its integer. If it becomes N+1, change it to 1.\n\nYou want to ensure that no player fights the same opponent more than once during the N rounds.\nPrint an assignment of integers to the playing fields satisfying this condition.\nIt can be proved that such an assignment always exists under the constraints given.\n\nConstraints\n\n1 \\leq M\n\nM \\times 2 +1 \\leq N \\leq 200000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nPrint M lines in the format below.\nThe i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.\n\na_1 b_1\na_2 b_2\n:\na_M b_M\n\nSample Input 1\n\n4 1\n\nSample Output 1\n\n2 3\n\nLet us call the four players A, B, C, and D, and assume that they are initially given the integers 1, 2, 3, and 4, respectively.\n\nThe 1-st round is fought by B and C, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 2, 3, 4, and 1, respectively.\n\nThe 2-nd round is fought by A and B, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 3, 4, 1, and 2, respectively.\n\nThe 3-rd round is fought by D and A, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 4, 1, 2, and 3, respectively.\n\nThe 4-th round is fought by C and D, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 1, 2, 3, and 4, respectively.\n\nNo player fights the same opponent more than once during the four rounds, so this solution will be accepted.\n\nSample Input 2\n\n7 3\n\nSample Output 2\n\n1 6\n2 5\n3 4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 261, "cpu_time_ms": 213, "memory_kb": 39720}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s476754781", "group_id": "codeNet:p02699", "input_text": "(print \n (if (<= (read) (read)) \"unsafe\" \"safe\") )\n", "language": "Lisp", "metadata": {"date": 1593385199, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02699.html", "problem_id": "p02699", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02699/input.txt", "sample_output_relpath": "derived/input_output/data/p02699/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02699/Lisp/s476754781.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s476754781", "user_id": "u526532903"}, "prompt_components": {"gold_output": "unsafe\n", "input_to_evaluate": "(print \n (if (<= (read) (read)) \"unsafe\" \"safe\") )\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are S sheep and W wolves.\n\nIf the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep.\n\nIf the wolves will attack the sheep, print unsafe; otherwise, print safe.\n\nConstraints\n\n1 \\leq S \\leq 100\n\n1 \\leq W \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS W\n\nOutput\n\nIf the wolves will attack the sheep, print unsafe; otherwise, print safe.\n\nSample Input 1\n\n4 5\n\nSample Output 1\n\nunsafe\n\nThere are four sheep and five wolves. The number of wolves is not less than that of sheep, so they will attack them.\n\nSample Input 2\n\n100 2\n\nSample Output 2\n\nsafe\n\nMany a sheep drive away two wolves.\n\nSample Input 3\n\n10 10\n\nSample Output 3\n\nunsafe", "sample_input": "4 5\n"}, "reference_outputs": ["unsafe\n"], "source_document_id": "p02699", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are S sheep and W wolves.\n\nIf the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep.\n\nIf the wolves will attack the sheep, print unsafe; otherwise, print safe.\n\nConstraints\n\n1 \\leq S \\leq 100\n\n1 \\leq W \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS W\n\nOutput\n\nIf the wolves will attack the sheep, print unsafe; otherwise, print safe.\n\nSample Input 1\n\n4 5\n\nSample Output 1\n\nunsafe\n\nThere are four sheep and five wolves. The number of wolves is not less than that of sheep, so they will attack them.\n\nSample Input 2\n\n100 2\n\nSample Output 2\n\nsafe\n\nMany a sheep drive away two wolves.\n\nSample Input 3\n\n10 10\n\nSample Output 3\n\nunsafe", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 52, "cpu_time_ms": 21, "memory_kb": 24256}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s233320035", "group_id": "codeNet:p02699", "input_text": "(defun f (n)\n (- (char-code n) 48))\n\n(defun ff (lst)\n (let* ((n (reverse lst)))\n (loop :for k :from 0\n :for j :in n\n :sum (* j (expt 10 k)))))\n\n(let* ((len (map 'list #'f (concatenate 'list (read-line))))\n (ln (1- (length len))))\n (princ (loop :for k :from 0 :upto (- ln 3)\n :sum (loop :for x :from (+ k 3) :upto ln\n :for y := (subseq len k (1+ x))\n :count (= 0 (mod (ff y) 2019))))))\n", "language": "Lisp", "metadata": {"date": 1587953983, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02699.html", "problem_id": "p02699", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02699/input.txt", "sample_output_relpath": "derived/input_output/data/p02699/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02699/Lisp/s233320035.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s233320035", "user_id": "u610490393"}, "prompt_components": {"gold_output": "unsafe\n", "input_to_evaluate": "(defun f (n)\n (- (char-code n) 48))\n\n(defun ff (lst)\n (let* ((n (reverse lst)))\n (loop :for k :from 0\n :for j :in n\n :sum (* j (expt 10 k)))))\n\n(let* ((len (map 'list #'f (concatenate 'list (read-line))))\n (ln (1- (length len))))\n (princ (loop :for k :from 0 :upto (- ln 3)\n :sum (loop :for x :from (+ k 3) :upto ln\n :for y := (subseq len k (1+ x))\n :count (= 0 (mod (ff y) 2019))))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are S sheep and W wolves.\n\nIf the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep.\n\nIf the wolves will attack the sheep, print unsafe; otherwise, print safe.\n\nConstraints\n\n1 \\leq S \\leq 100\n\n1 \\leq W \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS W\n\nOutput\n\nIf the wolves will attack the sheep, print unsafe; otherwise, print safe.\n\nSample Input 1\n\n4 5\n\nSample Output 1\n\nunsafe\n\nThere are four sheep and five wolves. The number of wolves is not less than that of sheep, so they will attack them.\n\nSample Input 2\n\n100 2\n\nSample Output 2\n\nsafe\n\nMany a sheep drive away two wolves.\n\nSample Input 3\n\n10 10\n\nSample Output 3\n\nunsafe", "sample_input": "4 5\n"}, "reference_outputs": ["unsafe\n"], "source_document_id": "p02699", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are S sheep and W wolves.\n\nIf the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep.\n\nIf the wolves will attack the sheep, print unsafe; otherwise, print safe.\n\nConstraints\n\n1 \\leq S \\leq 100\n\n1 \\leq W \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS W\n\nOutput\n\nIf the wolves will attack the sheep, print unsafe; otherwise, print safe.\n\nSample Input 1\n\n4 5\n\nSample Output 1\n\nunsafe\n\nThere are four sheep and five wolves. The number of wolves is not less than that of sheep, so they will attack them.\n\nSample Input 2\n\n100 2\n\nSample Output 2\n\nsafe\n\nMany a sheep drive away two wolves.\n\nSample Input 3\n\n10 10\n\nSample Output 3\n\nunsafe", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 479, "cpu_time_ms": 14, "memory_kb": 24632}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s424754673", "group_id": "codeNet:p02699", "input_text": "(if (<= (read) (read))\n (princ \"unsafe\")\n (princ \"safe\")\n )", "language": "Lisp", "metadata": {"date": 1587949273, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02699.html", "problem_id": "p02699", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02699/input.txt", "sample_output_relpath": "derived/input_output/data/p02699/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02699/Lisp/s424754673.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s424754673", "user_id": "u334552723"}, "prompt_components": {"gold_output": "unsafe\n", "input_to_evaluate": "(if (<= (read) (read))\n (princ \"unsafe\")\n (princ \"safe\")\n )", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are S sheep and W wolves.\n\nIf the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep.\n\nIf the wolves will attack the sheep, print unsafe; otherwise, print safe.\n\nConstraints\n\n1 \\leq S \\leq 100\n\n1 \\leq W \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS W\n\nOutput\n\nIf the wolves will attack the sheep, print unsafe; otherwise, print safe.\n\nSample Input 1\n\n4 5\n\nSample Output 1\n\nunsafe\n\nThere are four sheep and five wolves. The number of wolves is not less than that of sheep, so they will attack them.\n\nSample Input 2\n\n100 2\n\nSample Output 2\n\nsafe\n\nMany a sheep drive away two wolves.\n\nSample Input 3\n\n10 10\n\nSample Output 3\n\nunsafe", "sample_input": "4 5\n"}, "reference_outputs": ["unsafe\n"], "source_document_id": "p02699", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are S sheep and W wolves.\n\nIf the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep.\n\nIf the wolves will attack the sheep, print unsafe; otherwise, print safe.\n\nConstraints\n\n1 \\leq S \\leq 100\n\n1 \\leq W \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS W\n\nOutput\n\nIf the wolves will attack the sheep, print unsafe; otherwise, print safe.\n\nSample Input 1\n\n4 5\n\nSample Output 1\n\nunsafe\n\nThere are four sheep and five wolves. The number of wolves is not less than that of sheep, so they will attack them.\n\nSample Input 2\n\n100 2\n\nSample Output 2\n\nsafe\n\nMany a sheep drive away two wolves.\n\nSample Input 3\n\n10 10\n\nSample Output 3\n\nunsafe", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 68, "cpu_time_ms": 15, "memory_kb": 24144}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s087659460", "group_id": "codeNet:p02701", "input_text": "(princ (length (remove-duplicates (sort (loop for i below (read) collect (read)) 'string<) :test #'equal)))", "language": "Lisp", "metadata": {"date": 1587956292, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02701.html", "problem_id": "p02701", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02701/input.txt", "sample_output_relpath": "derived/input_output/data/p02701/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02701/Lisp/s087659460.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s087659460", "user_id": "u631655863"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(princ (length (remove-duplicates (sort (loop for i below (read) collect (read)) 'string<) :test #'equal)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou drew lottery N times. In the i-th draw, you got an item of the kind represented by a string S_i.\n\nHow many kinds of items did you get?\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\nS_i consists of lowercase English letters and has a length between 1 and 10 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nPrint the number of kinds of items you got.\n\nSample Input 1\n\n3\napple\norange\napple\n\nSample Output 1\n\n2\n\nYou got two kinds of items: apple and orange.\n\nSample Input 2\n\n5\ngrape\ngrape\ngrape\ngrape\ngrape\n\nSample Output 2\n\n1\n\nSample Input 3\n\n4\naaaa\na\naaa\naa\n\nSample Output 3\n\n4", "sample_input": "3\napple\norange\napple\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02701", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou drew lottery N times. In the i-th draw, you got an item of the kind represented by a string S_i.\n\nHow many kinds of items did you get?\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\nS_i consists of lowercase English letters and has a length between 1 and 10 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nPrint the number of kinds of items you got.\n\nSample Input 1\n\n3\napple\norange\napple\n\nSample Output 1\n\n2\n\nYou got two kinds of items: apple and orange.\n\nSample Input 2\n\n5\ngrape\ngrape\ngrape\ngrape\ngrape\n\nSample Output 2\n\n1\n\nSample Input 3\n\n4\naaaa\na\naaa\naa\n\nSample Output 3\n\n4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 107, "cpu_time_ms": 781, "memory_kb": 92752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s439044768", "group_id": "codeNet:p02701", "input_text": "(defun compressor (function lst) ;圧縮関数 collectorよりはちょっと早い\n (cond ((not lst) nil)\n ((not (cdr lst)) (list (cons (car lst) 1)))\n (t\n (let* ((ll (mapcar function lst (cdr lst)))\n (mem 0)\n (lf nil))\n (mapcar (lambda (k)\n (if (not k) (push mem lf))\n (incf mem)) ll)\n (push (1- (length lst)) lf)\n (setf lf (reverse lf))\n (mapcar #'cons\n (mapcar (lambda (k) (elt lst k)) lf)\n (cons (car lf) (mapcar (lambda (a b)\n (abs (- a b))) lf (cdr lf))))))))\n(let* ((n (read))\n (m (loop :repeat n :collect (read-line))))\n (princ (length (compressor #'string= (sort m #'string<)))))\n", "language": "Lisp", "metadata": {"date": 1587949710, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02701.html", "problem_id": "p02701", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02701/input.txt", "sample_output_relpath": "derived/input_output/data/p02701/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02701/Lisp/s439044768.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s439044768", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun compressor (function lst) ;圧縮関数 collectorよりはちょっと早い\n (cond ((not lst) nil)\n ((not (cdr lst)) (list (cons (car lst) 1)))\n (t\n (let* ((ll (mapcar function lst (cdr lst)))\n (mem 0)\n (lf nil))\n (mapcar (lambda (k)\n (if (not k) (push mem lf))\n (incf mem)) ll)\n (push (1- (length lst)) lf)\n (setf lf (reverse lf))\n (mapcar #'cons\n (mapcar (lambda (k) (elt lst k)) lf)\n (cons (car lf) (mapcar (lambda (a b)\n (abs (- a b))) lf (cdr lf))))))))\n(let* ((n (read))\n (m (loop :repeat n :collect (read-line))))\n (princ (length (compressor #'string= (sort m #'string<)))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou drew lottery N times. In the i-th draw, you got an item of the kind represented by a string S_i.\n\nHow many kinds of items did you get?\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\nS_i consists of lowercase English letters and has a length between 1 and 10 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nPrint the number of kinds of items you got.\n\nSample Input 1\n\n3\napple\norange\napple\n\nSample Output 1\n\n2\n\nYou got two kinds of items: apple and orange.\n\nSample Input 2\n\n5\ngrape\ngrape\ngrape\ngrape\ngrape\n\nSample Output 2\n\n1\n\nSample Input 3\n\n4\naaaa\na\naaa\naa\n\nSample Output 3\n\n4", "sample_input": "3\napple\norange\napple\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02701", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou drew lottery N times. In the i-th draw, you got an item of the kind represented by a string S_i.\n\nHow many kinds of items did you get?\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\nS_i consists of lowercase English letters and has a length between 1 and 10 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nPrint the number of kinds of items you got.\n\nSample Input 1\n\n3\napple\norange\napple\n\nSample Output 1\n\n2\n\nYou got two kinds of items: apple and orange.\n\nSample Input 2\n\n5\ngrape\ngrape\ngrape\ngrape\ngrape\n\nSample Output 2\n\n1\n\nSample Input 3\n\n4\naaaa\na\naaa\naa\n\nSample Output 3\n\n4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 809, "cpu_time_ms": 2207, "memory_kb": 88368}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s580408871", "group_id": "codeNet:p02706", "input_text": "(let* ((n (read)) \n (m (read)) \n (a (loop repeat m sum (read)))) \n (format t \"~A~%\" \n (if (< (- n a) 0) \n -1 \n (- n a)))) \n", "language": "Lisp", "metadata": {"date": 1587347456, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02706.html", "problem_id": "p02706", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02706/input.txt", "sample_output_relpath": "derived/input_output/data/p02706/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02706/Lisp/s580408871.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s580408871", "user_id": "u607637432"}, "prompt_components": {"gold_output": "30\n", "input_to_evaluate": "(let* ((n (read)) \n (m (read)) \n (a (loop repeat m sum (read)))) \n (format t \"~A~%\" \n (if (< (- n a) 0) \n -1 \n (- n a)))) \n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi has N days of summer vacation.\n\nHis teacher gave him M summer assignments. It will take A_i days for him to do the i-th assignment.\n\nHe cannot do multiple assignments on the same day, or hang out on a day he does an assignment.\n\nWhat is the maximum number of days Takahashi can hang out during the vacation if he finishes all the assignments during this vacation?\n\nIf Takahashi cannot finish all the assignments during the vacation, print -1 instead.\n\nConstraints\n\n1 \\leq N \\leq 10^6\n\n1 \\leq M \\leq 10^4\n\n1 \\leq A_i \\leq 10^4\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 ... A_M\n\nOutput\n\nPrint the maximum number of days Takahashi can hang out during the vacation, or -1.\n\nSample Input 1\n\n41 2\n5 6\n\nSample Output 1\n\n30\n\nFor example, he can do the first assignment on the first 5 days, hang out on the next 30 days, and do the second assignment on the last 6 days of the vacation. In this way, he can safely spend 30 days hanging out.\n\nSample Input 2\n\n10 2\n5 6\n\nSample Output 2\n\n-1\n\nHe cannot finish his assignments.\n\nSample Input 3\n\n11 2\n5 6\n\nSample Output 3\n\n0\n\nHe can finish his assignments, but he will have no time to hang out.\n\nSample Input 4\n\n314 15\n9 26 5 35 8 9 79 3 23 8 46 2 6 43 3\n\nSample Output 4\n\n9", "sample_input": "41 2\n5 6\n"}, "reference_outputs": ["30\n"], "source_document_id": "p02706", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi has N days of summer vacation.\n\nHis teacher gave him M summer assignments. It will take A_i days for him to do the i-th assignment.\n\nHe cannot do multiple assignments on the same day, or hang out on a day he does an assignment.\n\nWhat is the maximum number of days Takahashi can hang out during the vacation if he finishes all the assignments during this vacation?\n\nIf Takahashi cannot finish all the assignments during the vacation, print -1 instead.\n\nConstraints\n\n1 \\leq N \\leq 10^6\n\n1 \\leq M \\leq 10^4\n\n1 \\leq A_i \\leq 10^4\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 ... A_M\n\nOutput\n\nPrint the maximum number of days Takahashi can hang out during the vacation, or -1.\n\nSample Input 1\n\n41 2\n5 6\n\nSample Output 1\n\n30\n\nFor example, he can do the first assignment on the first 5 days, hang out on the next 30 days, and do the second assignment on the last 6 days of the vacation. In this way, he can safely spend 30 days hanging out.\n\nSample Input 2\n\n10 2\n5 6\n\nSample Output 2\n\n-1\n\nHe cannot finish his assignments.\n\nSample Input 3\n\n11 2\n5 6\n\nSample Output 3\n\n0\n\nHe can finish his assignments, but he will have no time to hang out.\n\nSample Input 4\n\n314 15\n9 26 5 35 8 9 79 3 23 8 46 2 6 43 3\n\nSample Output 4\n\n9", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 367, "cpu_time_ms": 23, "memory_kb": 29660}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s983579483", "group_id": "codeNet:p02707", "input_text": "(let* ((n (read))\n (a (make-array (1+ n))))\n (loop repeat (- n 1)\n do (incf (aref a (read))))\n (loop\n for i from 1 to n \n do (format t \"~A~%\"(aref a i)))) \n", "language": "Lisp", "metadata": {"date": 1587349364, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02707.html", "problem_id": "p02707", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02707/input.txt", "sample_output_relpath": "derived/input_output/data/p02707/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02707/Lisp/s983579483.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s983579483", "user_id": "u607637432"}, "prompt_components": {"gold_output": "2\n2\n0\n0\n0\n", "input_to_evaluate": "(let* ((n (read))\n (a (make-array (1+ n))))\n (loop repeat (- n 1)\n do (incf (aref a (read))))\n (loop\n for i from 1 to n \n do (format t \"~A~%\"(aref a i)))) \n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nA company has N members, who are assigned ID numbers 1, ..., N.\n\nEvery member, except the member numbered 1, has exactly one immediate boss with a smaller ID number.\n\nWhen a person X is the immediate boss of a person Y, the person Y is said to be an immediate subordinate of the person X.\n\nYou are given the information that the immediate boss of the member numbered i is the member numbered A_i. For each member, find how many immediate subordinates it has.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i < i\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_2 ... A_N\n\nOutput\n\nFor each of the members numbered 1, 2, ..., N, print the number of immediate subordinates it has, in its own line.\n\nSample Input 1\n\n5\n1 1 2 2\n\nSample Output 1\n\n2\n2\n0\n0\n0\n\nThe member numbered 1 has two immediate subordinates: the members numbered 2 and 3.\n\nThe member numbered 2 has two immediate subordinates: the members numbered 4 and 5.\n\nThe members numbered 3, 4, and 5 do not have immediate subordinates.\n\nSample Input 2\n\n10\n1 1 1 1 1 1 1 1 1\n\nSample Output 2\n\n9\n0\n0\n0\n0\n0\n0\n0\n0\n0\n\nSample Input 3\n\n7\n1 2 3 4 5 6\n\nSample Output 3\n\n1\n1\n1\n1\n1\n1\n0", "sample_input": "5\n1 1 2 2\n"}, "reference_outputs": ["2\n2\n0\n0\n0\n"], "source_document_id": "p02707", "source_text": "Score : 300 points\n\nProblem Statement\n\nA company has N members, who are assigned ID numbers 1, ..., N.\n\nEvery member, except the member numbered 1, has exactly one immediate boss with a smaller ID number.\n\nWhen a person X is the immediate boss of a person Y, the person Y is said to be an immediate subordinate of the person X.\n\nYou are given the information that the immediate boss of the member numbered i is the member numbered A_i. For each member, find how many immediate subordinates it has.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i < i\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_2 ... A_N\n\nOutput\n\nFor each of the members numbered 1, 2, ..., N, print the number of immediate subordinates it has, in its own line.\n\nSample Input 1\n\n5\n1 1 2 2\n\nSample Output 1\n\n2\n2\n0\n0\n0\n\nThe member numbered 1 has two immediate subordinates: the members numbered 2 and 3.\n\nThe member numbered 2 has two immediate subordinates: the members numbered 4 and 5.\n\nThe members numbered 3, 4, and 5 do not have immediate subordinates.\n\nSample Input 2\n\n10\n1 1 1 1 1 1 1 1 1\n\nSample Output 2\n\n9\n0\n0\n0\n0\n0\n0\n0\n0\n0\n\nSample Input 3\n\n7\n1 2 3 4 5 6\n\nSample Output 3\n\n1\n1\n1\n1\n1\n1\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 177, "cpu_time_ms": 465, "memory_kb": 78580}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s217451567", "group_id": "codeNet:p02707", "input_text": "(let ((N (read)))\n (defvar arr (make-array (1+ N) :initial-element 0))\n (loop repeat (1- N) do (incf (aref arr (read))))\n (loop for x from 1 to N do \n (princ (aref arr x))\n (terpri)))", "language": "Lisp", "metadata": {"date": 1587345429, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02707.html", "problem_id": "p02707", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02707/input.txt", "sample_output_relpath": "derived/input_output/data/p02707/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02707/Lisp/s217451567.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s217451567", "user_id": "u334552723"}, "prompt_components": {"gold_output": "2\n2\n0\n0\n0\n", "input_to_evaluate": "(let ((N (read)))\n (defvar arr (make-array (1+ N) :initial-element 0))\n (loop repeat (1- N) do (incf (aref arr (read))))\n (loop for x from 1 to N do \n (princ (aref arr x))\n (terpri)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nA company has N members, who are assigned ID numbers 1, ..., N.\n\nEvery member, except the member numbered 1, has exactly one immediate boss with a smaller ID number.\n\nWhen a person X is the immediate boss of a person Y, the person Y is said to be an immediate subordinate of the person X.\n\nYou are given the information that the immediate boss of the member numbered i is the member numbered A_i. For each member, find how many immediate subordinates it has.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i < i\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_2 ... A_N\n\nOutput\n\nFor each of the members numbered 1, 2, ..., N, print the number of immediate subordinates it has, in its own line.\n\nSample Input 1\n\n5\n1 1 2 2\n\nSample Output 1\n\n2\n2\n0\n0\n0\n\nThe member numbered 1 has two immediate subordinates: the members numbered 2 and 3.\n\nThe member numbered 2 has two immediate subordinates: the members numbered 4 and 5.\n\nThe members numbered 3, 4, and 5 do not have immediate subordinates.\n\nSample Input 2\n\n10\n1 1 1 1 1 1 1 1 1\n\nSample Output 2\n\n9\n0\n0\n0\n0\n0\n0\n0\n0\n0\n\nSample Input 3\n\n7\n1 2 3 4 5 6\n\nSample Output 3\n\n1\n1\n1\n1\n1\n1\n0", "sample_input": "5\n1 1 2 2\n"}, "reference_outputs": ["2\n2\n0\n0\n0\n"], "source_document_id": "p02707", "source_text": "Score : 300 points\n\nProblem Statement\n\nA company has N members, who are assigned ID numbers 1, ..., N.\n\nEvery member, except the member numbered 1, has exactly one immediate boss with a smaller ID number.\n\nWhen a person X is the immediate boss of a person Y, the person Y is said to be an immediate subordinate of the person X.\n\nYou are given the information that the immediate boss of the member numbered i is the member numbered A_i. For each member, find how many immediate subordinates it has.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i < i\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_2 ... A_N\n\nOutput\n\nFor each of the members numbered 1, 2, ..., N, print the number of immediate subordinates it has, in its own line.\n\nSample Input 1\n\n5\n1 1 2 2\n\nSample Output 1\n\n2\n2\n0\n0\n0\n\nThe member numbered 1 has two immediate subordinates: the members numbered 2 and 3.\n\nThe member numbered 2 has two immediate subordinates: the members numbered 4 and 5.\n\nThe members numbered 3, 4, and 5 do not have immediate subordinates.\n\nSample Input 2\n\n10\n1 1 1 1 1 1 1 1 1\n\nSample Output 2\n\n9\n0\n0\n0\n0\n0\n0\n0\n0\n0\n\nSample Input 3\n\n7\n1 2 3 4 5 6\n\nSample Output 3\n\n1\n1\n1\n1\n1\n1\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 215, "cpu_time_ms": 471, "memory_kb": 78516}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s427246856", "group_id": "codeNet:p02709", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"256MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dpline (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defmacro dphash (name args &body expr)\n `(let ((table (make-hash-table :test #'equal)))\n (defun ,name ,args \n (or (gethash (list ,@args) table)\n (setf (gethash (list ,@args) table)\n (progn \n ,@expr))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun range-0-n (n &optional (step 1))\n (loop for i from 0 below n by step collect i))\n\n(defun range-1-n (n &optional (step 1))\n (loop for i from 1 below n by step collect i))\n\n(defun range-a-b (a b &optional (step 1))\n (loop for i from a below b by step collect i))\n\n(defun map-0-n (function n &optional (step 1))\n (mapcar function (range-0-n n step)))\n\n(defun map-1-n (function n &optional (step 1))\n (mapcar function (range-1-n n step)))\n\n(defun map-a-b (function a b &optional (step 1))\n (mapcar function (range-a-b a b step)))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (and result (is-empty char))\n do (return (concatenate 'string (nreverse result)))\n when (null (is-empty char))\n do (push char result))))\n\n(defun merge-sort (lst &optional (compare #'<))\n (let ((turn 0))\n (labels ((merge-list (a b a-length b-length)\n (cond ((zerop a-length) b)\n ((zerop b-length) a)\n ((funcall compare (car b) (car a))\n (incf turn a-length)\n (cons (car b)\n (merge-list a (cdr b) a-length (1- b-length))))\n (t\n (cons (car a)\n (merge-list (cdr a) b (1- a-length) b-length)))))\n (f (lst length)\n (if (= length 1)\n lst\n (let ((mid (ash length -1)))\n (merge-list (f (subseq lst 0 mid) mid)\n (f (subseq lst mid) (- length mid))\n mid\n (- length mid))))))\n (values (f lst (length lst)) turn))))\n\n(defun group (lst &optional (test #'eql) (key nil))\n (let ((table (make-hash-table :test test)))\n (mapc (lambda (x)\n (push x (gethash (if key (funcall key x) x) table)))\n lst)\n (loop for value being each hash-value in table\n collect value)))\n\n(defun nearby (&rest args)\n (let ((current (subseq args 0 (ash (length args) -1)))\n (validator (subseq args (ash (length args) -1)))\n (res nil))\n (labels ((check ()\n (every (lambda (x y) (and (<= 0 x) (< x y)))\n current validator))\n (f (lst)\n (unless lst (return-from f))\n (let ((x (car lst)))\n (setf (car lst) (1+ x))\n (when (check) (push (copy-list current) res))\n (setf (car lst) (1- x))\n (when (check) (push (copy-list current) res))\n (setf (car lst) x))\n (f (cdr lst))))\n (f current)\n res)))\n\n(defun main (line)\n (let ((points (coerce (sort (loop for i in line\n for j from 1\n collect (cons i j))\n #'>\n :key #'car)\n 'vector))\n (n (length line)))\n (dpline func (l r) (list (+ n 10) (+ n 10))\n (if (<= l r)\n (let ((point (car (aref points (+ l (- n r 1)))))\n (pos (cdr (aref points (+ l (- n r 1))))))\n (max (+ (* (abs (- l pos)) point)\n (func (1+ l) r))\n (+ (* (abs (- r pos)) point)\n (func l (1- r)))))\n 0))\n (func 1 n)))\n\n#-swank\n(princ (main (read-times (read))))\n", "language": "Lisp", "metadata": {"date": 1591190903, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02709.html", "problem_id": "p02709", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02709/input.txt", "sample_output_relpath": "derived/input_output/data/p02709/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02709/Lisp/s427246856.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s427246856", "user_id": "u493610446"}, "prompt_components": {"gold_output": "20\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"256MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dpline (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defmacro dphash (name args &body expr)\n `(let ((table (make-hash-table :test #'equal)))\n (defun ,name ,args \n (or (gethash (list ,@args) table)\n (setf (gethash (list ,@args) table)\n (progn \n ,@expr))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun range-0-n (n &optional (step 1))\n (loop for i from 0 below n by step collect i))\n\n(defun range-1-n (n &optional (step 1))\n (loop for i from 1 below n by step collect i))\n\n(defun range-a-b (a b &optional (step 1))\n (loop for i from a below b by step collect i))\n\n(defun map-0-n (function n &optional (step 1))\n (mapcar function (range-0-n n step)))\n\n(defun map-1-n (function n &optional (step 1))\n (mapcar function (range-1-n n step)))\n\n(defun map-a-b (function a b &optional (step 1))\n (mapcar function (range-a-b a b step)))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (and result (is-empty char))\n do (return (concatenate 'string (nreverse result)))\n when (null (is-empty char))\n do (push char result))))\n\n(defun merge-sort (lst &optional (compare #'<))\n (let ((turn 0))\n (labels ((merge-list (a b a-length b-length)\n (cond ((zerop a-length) b)\n ((zerop b-length) a)\n ((funcall compare (car b) (car a))\n (incf turn a-length)\n (cons (car b)\n (merge-list a (cdr b) a-length (1- b-length))))\n (t\n (cons (car a)\n (merge-list (cdr a) b (1- a-length) b-length)))))\n (f (lst length)\n (if (= length 1)\n lst\n (let ((mid (ash length -1)))\n (merge-list (f (subseq lst 0 mid) mid)\n (f (subseq lst mid) (- length mid))\n mid\n (- length mid))))))\n (values (f lst (length lst)) turn))))\n\n(defun group (lst &optional (test #'eql) (key nil))\n (let ((table (make-hash-table :test test)))\n (mapc (lambda (x)\n (push x (gethash (if key (funcall key x) x) table)))\n lst)\n (loop for value being each hash-value in table\n collect value)))\n\n(defun nearby (&rest args)\n (let ((current (subseq args 0 (ash (length args) -1)))\n (validator (subseq args (ash (length args) -1)))\n (res nil))\n (labels ((check ()\n (every (lambda (x y) (and (<= 0 x) (< x y)))\n current validator))\n (f (lst)\n (unless lst (return-from f))\n (let ((x (car lst)))\n (setf (car lst) (1+ x))\n (when (check) (push (copy-list current) res))\n (setf (car lst) (1- x))\n (when (check) (push (copy-list current) res))\n (setf (car lst) x))\n (f (cdr lst))))\n (f current)\n res)))\n\n(defun main (line)\n (let ((points (coerce (sort (loop for i in line\n for j from 1\n collect (cons i j))\n #'>\n :key #'car)\n 'vector))\n (n (length line)))\n (dpline func (l r) (list (+ n 10) (+ n 10))\n (if (<= l r)\n (let ((point (car (aref points (+ l (- n r 1)))))\n (pos (cdr (aref points (+ l (- n r 1))))))\n (max (+ (* (abs (- l pos)) point)\n (func (1+ l) r))\n (+ (* (abs (- r pos)) point)\n (func l (1- r)))))\n 0))\n (func 1 n)))\n\n#-swank\n(princ (main (read-times (read))))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i.\n\nYou can rearrange these children just one time in any order you like.\n\nWhen a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \\times |x-y| happiness points.\n\nFind the maximum total happiness points the children can earn.\n\nConstraints\n\n2 \\leq N \\leq 2000\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum total happiness points the children can earn.\n\nSample Input 1\n\n4\n1 3 4 2\n\nSample Output 1\n\n20\n\nIf we move the 1-st child from the left to the 3-rd position from the left, the 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and the 4-th child to the 2-nd position, the children earns 1 \\times |1-3|+3 \\times |2-4|+4 \\times |3-1|+2 \\times |4-2|=20 happiness points in total.\n\nSample Input 2\n\n6\n5 5 6 1 1 1\n\nSample Output 2\n\n58\n\nSample Input 3\n\n6\n8 6 9 1 2 1\n\nSample Output 3\n\n85", "sample_input": "4\n1 3 4 2\n"}, "reference_outputs": ["20\n"], "source_document_id": "p02709", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i.\n\nYou can rearrange these children just one time in any order you like.\n\nWhen a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \\times |x-y| happiness points.\n\nFind the maximum total happiness points the children can earn.\n\nConstraints\n\n2 \\leq N \\leq 2000\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum total happiness points the children can earn.\n\nSample Input 1\n\n4\n1 3 4 2\n\nSample Output 1\n\n20\n\nIf we move the 1-st child from the left to the 3-rd position from the left, the 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and the 4-th child to the 2-nd position, the children earns 1 \\times |1-3|+3 \\times |2-4|+4 \\times |3-1|+2 \\times |4-2|=20 happiness points in total.\n\nSample Input 2\n\n6\n5 5 6 1 1 1\n\nSample Output 2\n\n58\n\nSample Input 3\n\n6\n8 6 9 1 2 1\n\nSample Output 3\n\n85", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6557, "cpu_time_ms": 136, "memory_kb": 58532}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s345555269", "group_id": "codeNet:p02712", "input_text": "(princ\n(loop \n for x from 1 to (read)\n if (and (zerop (mod x 3))\n\t (zerop (mod x 5)))\n sum x))", "language": "Lisp", "metadata": {"date": 1586740181, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02712.html", "problem_id": "p02712", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02712/input.txt", "sample_output_relpath": "derived/input_output/data/p02712/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02712/Lisp/s345555269.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s345555269", "user_id": "u334552723"}, "prompt_components": {"gold_output": "60\n", "input_to_evaluate": "(princ\n(loop \n for x from 1 to (read)\n if (and (zerop (mod x 3))\n\t (zerop (mod x 5)))\n sum x))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nLet us define the FizzBuzz sequence a_1,a_2,... as follows:\n\nIf both 3 and 5 divides i, a_i=\\mbox{FizzBuzz}.\n\nIf the above does not hold but 3 divides i, a_i=\\mbox{Fizz}.\n\nIf none of the above holds but 5 divides i, a_i=\\mbox{Buzz}.\n\nIf none of the above holds, a_i=i.\n\nFind the sum of all numbers among the first N terms of the FizzBuzz sequence.\n\nConstraints\n\n1 \\leq N \\leq 10^6\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the sum of all numbers among the first N terms of the FizzBuzz sequence.\n\nSample Input 1\n\n15\n\nSample Output 1\n\n60\n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\nSample Input 2\n\n1000000\n\nSample Output 2\n\n266666333332\n\nWatch out for overflow.", "sample_input": "15\n"}, "reference_outputs": ["60\n"], "source_document_id": "p02712", "source_text": "Score : 200 points\n\nProblem Statement\n\nLet us define the FizzBuzz sequence a_1,a_2,... as follows:\n\nIf both 3 and 5 divides i, a_i=\\mbox{FizzBuzz}.\n\nIf the above does not hold but 3 divides i, a_i=\\mbox{Fizz}.\n\nIf none of the above holds but 5 divides i, a_i=\\mbox{Buzz}.\n\nIf none of the above holds, a_i=i.\n\nFind the sum of all numbers among the first N terms of the FizzBuzz sequence.\n\nConstraints\n\n1 \\leq N \\leq 10^6\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the sum of all numbers among the first N terms of the FizzBuzz sequence.\n\nSample Input 1\n\n15\n\nSample Output 1\n\n60\n\nThe first 15 terms of the FizzBuzz sequence are:\n\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}\n\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.\n\nSample Input 2\n\n1000000\n\nSample Output 2\n\n266666333332\n\nWatch out for overflow.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 102, "cpu_time_ms": 35, "memory_kb": 24400}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s375306571", "group_id": "codeNet:p02715", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; TODO: more efficient handling when modulus is (unsigned-byte 31) or\n;; (unsigned-byte 32)\n(declaim (inline mod-power))\n(defun mod-power (base power modulus)\n \"BASE := integer\nPOWER, MODULUS := non-negative fixnum\"\n (declare ((integer 0 #.most-positive-fixnum) modulus power)\n (integer base))\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) x p)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (cond ((zerop p) (mod 1 modulus))\n ((evenp p) (recur (mod (* x x) modulus) (ash p -1)))\n (t (mod (* x (recur x (- p 1))) modulus)))))\n (recur (mod base modulus) power)))\n\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n;;;\n;;; Fast Zeta/Moebius transforms w.r.t. divisor or multiple in O(nloglog(n)).\n;;;\n\n(declaim (inline divisor-transform!))\n(defun divisor-transform! (vector &optional (op+ #'+) (handle-zero t))\n \"Sets each VECTOR[i] to the sum of VECTOR[d] for all the divisors d of i in\nO(nloglog(n)). Ignores VECTOR[0] when HANDLE-ZERO is NIL.\"\n (declare (vector vector))\n (let* ((n (length vector))\n (sieve (make-array n :element-type 'bit :initial-element 1)))\n (when handle-zero\n (loop for i from 1 below n\n do (setf (aref vector 0)\n (funcall op+ (aref vector 0) (aref vector i)))))\n (loop for p from 2 below n\n when (= 1 (sbit sieve p))\n do (loop for k from 1 below (ceiling n p)\n for pmult of-type fixnum = (* k p)\n do (setf (sbit sieve pmult) 0)\n (setf (aref vector pmult)\n (funcall op+ (aref vector pmult) (aref vector k)))))\n vector))\n\n(declaim (inline inverse-divisor-transform!))\n(defun inverse-divisor-transform! (vector &optional (op- #'-) (handle-zero t))\n \"Does the inverse transform of DIVISOR-TRANSFORM! in O(nloglog(n)). Ignores\nVECTOR[0] when HANDLE-ZERO is NIL.\"\n (declare (vector vector))\n (let* ((n (length vector))\n (sieve (make-array n :element-type 'bit :initial-element 1)))\n (loop for p from 2 below n\n when (= 1 (sbit sieve p))\n do (loop for k from (- (ceiling n p) 1) downto 1\n for pmult of-type fixnum = (* k p)\n do (setf (sbit sieve pmult) 0)\n (setf (aref vector pmult)\n (funcall op- (aref vector pmult) (aref vector k)))))\n (when handle-zero\n (loop for i from 1 below n\n do (setf (aref vector 0)\n (funcall op- (aref vector 0) (aref vector i)))))\n vector))\n\n(declaim (inline multiple-transform!))\n(defun multiple-transform! (vector &optional (op+ #'+) (handle-zero t))\n \"Sets each VECTOR[i] to the sum of VECTOR[m] for all the multiples m of i in\nO(nloglog(n)). (To be precise, all the multiples smaller than the length of\nVECTOR.) Ignores VECTOR[0] when HANDLE-ZERO is NIL.\"\n (declare (vector vector))\n (let* ((n (length vector))\n (sieve (make-array n :element-type 'bit :initial-element 1)))\n (loop for p from 2 below n\n when (= 1 (sbit sieve p))\n do (loop for k from (- (ceiling n p) 1) downto 1\n for pmult of-type fixnum = (* k p)\n do (setf (sbit sieve pmult) 0)\n (setf (aref vector k)\n (funcall op+ (aref vector k) (aref vector pmult)))))\n (when handle-zero\n (loop for i from 1 below n\n do (setf (aref vector i)\n (funcall op+ (aref vector 0) (aref vector i)))))\n vector))\n\n(declaim (inline inverse-multiple-transform!))\n(defun inverse-multiple-transform! (vector &optional (op- #'-) (handle-zero t))\n \"Does the inverse transform of MULTIPLE-TRANSFORM!. Ignores VECTOR[0] when\nHANDLE-ZERO is NIL.\"\n (declare (vector vector))\n (let* ((n (length vector))\n (sieve (make-array n :element-type 'bit :initial-element 1)))\n (when handle-zero\n (loop for i from 1 below n\n do (setf (aref vector i)\n (funcall op- (aref vector i) (aref vector 0)))))\n (loop for p from 2 below n\n when (= 1 (sbit sieve p))\n do (loop for k from 1 below (ceiling n p)\n for pmult of-type fixnum = (* k p)\n do (setf (sbit sieve pmult) 0)\n (setf (aref vector k)\n (funcall op- (aref vector k) (aref vector pmult)))))\n vector))\n\n;;;\n;;; (Slower) Zeta/Moebius transforms w.r.t. divisor or multiple in O(nlog(n))\n;;;\n\n#|\n(declaim (inline divisor-transform!))\n(defun divisor-transform! (vector &optional (op+ #'+) (handle-zero t))\n \"Sets each VECTOR[i] to the sum of VECTOR[d] for all the divisors d of i in\nO(nlog(n)).\"\n (declare (vector vector))\n (let ((n (length vector)))\n (when handle-zero\n (loop for i from 1 below n\n do (setf (aref vector 0)\n (funcall op+ (aref vector 0) (aref vector i)))))\n (loop for i from (- (ceiling n 2) 1) downto 1\n do (loop for j from (+ i i) below n by i\n do (setf (aref vector j)\n (funcall op+ (aref vector i) (aref vector j)))))\n vector))\n\n(declaim (inline inverse-divisor-transform!))\n(defun inverse-divisor-transform! (vector &optional (op- #'-) (handle-zero t))\n \"Does the inverse transform of DIVISOR-TRANSFORM! in O(nlog(n)).\"\n (declare (vector vector))\n (let ((n (length vector)))\n (loop for i from 1 below (ceiling n 2)\n do (loop for j from (+ i i) below n by i\n do (setf (aref vector j)\n (funcall op- (aref vector j) (aref vector i)))))\n (when handle-zero\n (loop for i from 1 below n\n do (setf (aref vector 0)\n (funcall op- (aref vector 0) (aref vector i)))))\n vector))\n\n\n(declaim (inline multiple-transform!))\n(defun multiple-transform! (vector &optional (op+ #'+) (handle-zero t))\n \"Sets each VECTOR[i] to the sum of VECTOR[m] for all the multiples m of i in\nO(nlog(n)). (To be precise, all the multiples smaller than the length of\nVECTOR.)\"\n (declare (vector vector))\n (let ((n (length vector)))\n (loop for i from 1 below (ceiling n 2)\n do (loop for j from (+ i i) below n by i\n do (setf (aref vector i)\n (funcall op+ (aref vector i) (aref vector j)))))\n (when handle-zero\n (loop for i from 1 below n\n do (setf (aref vector i)\n (funcall op+ (aref vector 0) (aref vector i)))))\n vector))\n\n\n(declaim (inline inverse-multiple-transform!))\n(defun inverse-multiple-transform! (vector &optional (op- #'-) (handle-zero t))\n \"Does the inverse transform of MULTIPLE-TRANSFORM! in O(nlog(n)).\"\n (declare (vector vector))\n (let ((n (length vector)))\n (when handle-zero\n (loop for i from 1 below n\n do (setf (aref vector i)\n (funcall op- (aref vector i) (aref vector 0)))))\n (loop for i from (- (ceiling n 2) 1) downto 1\n do (loop for j from (+ i i) below n by i\n do (setf (aref vector i)\n (funcall op- (aref vector i) (aref vector j)))))\n vector))\n;|#\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (dp (make-array (+ k 1) :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n k))\n (loop for x from 1 to k\n do (setf (aref dp x) (mod-power (floor k x) n +mod+)))\n (inverse-multiple-transform! dp\n (lambda (x y)\n (declare (uint31 x y))\n (mod+ x (the uint31 (- +mod+ y))))\n nil)\n (let ((res 0))\n (declare (uint62 res))\n (loop for x from 1 to k\n do (incf res (mod* x (aref dp x))))\n (println (mod res +mod+)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 2\n\"\n \"9\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 200\n\"\n \"10813692\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"100000 100000\n\"\n \"742202979\n\")))\n", "language": "Lisp", "metadata": {"date": 1586743974, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02715.html", "problem_id": "p02715", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02715/input.txt", "sample_output_relpath": "derived/input_output/data/p02715/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02715/Lisp/s375306571.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s375306571", "user_id": "u352600849"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; TODO: more efficient handling when modulus is (unsigned-byte 31) or\n;; (unsigned-byte 32)\n(declaim (inline mod-power))\n(defun mod-power (base power modulus)\n \"BASE := integer\nPOWER, MODULUS := non-negative fixnum\"\n (declare ((integer 0 #.most-positive-fixnum) modulus power)\n (integer base))\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) x p)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (cond ((zerop p) (mod 1 modulus))\n ((evenp p) (recur (mod (* x x) modulus) (ash p -1)))\n (t (mod (* x (recur x (- p 1))) modulus)))))\n (recur (mod base modulus) power)))\n\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n;;;\n;;; Fast Zeta/Moebius transforms w.r.t. divisor or multiple in O(nloglog(n)).\n;;;\n\n(declaim (inline divisor-transform!))\n(defun divisor-transform! (vector &optional (op+ #'+) (handle-zero t))\n \"Sets each VECTOR[i] to the sum of VECTOR[d] for all the divisors d of i in\nO(nloglog(n)). Ignores VECTOR[0] when HANDLE-ZERO is NIL.\"\n (declare (vector vector))\n (let* ((n (length vector))\n (sieve (make-array n :element-type 'bit :initial-element 1)))\n (when handle-zero\n (loop for i from 1 below n\n do (setf (aref vector 0)\n (funcall op+ (aref vector 0) (aref vector i)))))\n (loop for p from 2 below n\n when (= 1 (sbit sieve p))\n do (loop for k from 1 below (ceiling n p)\n for pmult of-type fixnum = (* k p)\n do (setf (sbit sieve pmult) 0)\n (setf (aref vector pmult)\n (funcall op+ (aref vector pmult) (aref vector k)))))\n vector))\n\n(declaim (inline inverse-divisor-transform!))\n(defun inverse-divisor-transform! (vector &optional (op- #'-) (handle-zero t))\n \"Does the inverse transform of DIVISOR-TRANSFORM! in O(nloglog(n)). Ignores\nVECTOR[0] when HANDLE-ZERO is NIL.\"\n (declare (vector vector))\n (let* ((n (length vector))\n (sieve (make-array n :element-type 'bit :initial-element 1)))\n (loop for p from 2 below n\n when (= 1 (sbit sieve p))\n do (loop for k from (- (ceiling n p) 1) downto 1\n for pmult of-type fixnum = (* k p)\n do (setf (sbit sieve pmult) 0)\n (setf (aref vector pmult)\n (funcall op- (aref vector pmult) (aref vector k)))))\n (when handle-zero\n (loop for i from 1 below n\n do (setf (aref vector 0)\n (funcall op- (aref vector 0) (aref vector i)))))\n vector))\n\n(declaim (inline multiple-transform!))\n(defun multiple-transform! (vector &optional (op+ #'+) (handle-zero t))\n \"Sets each VECTOR[i] to the sum of VECTOR[m] for all the multiples m of i in\nO(nloglog(n)). (To be precise, all the multiples smaller than the length of\nVECTOR.) Ignores VECTOR[0] when HANDLE-ZERO is NIL.\"\n (declare (vector vector))\n (let* ((n (length vector))\n (sieve (make-array n :element-type 'bit :initial-element 1)))\n (loop for p from 2 below n\n when (= 1 (sbit sieve p))\n do (loop for k from (- (ceiling n p) 1) downto 1\n for pmult of-type fixnum = (* k p)\n do (setf (sbit sieve pmult) 0)\n (setf (aref vector k)\n (funcall op+ (aref vector k) (aref vector pmult)))))\n (when handle-zero\n (loop for i from 1 below n\n do (setf (aref vector i)\n (funcall op+ (aref vector 0) (aref vector i)))))\n vector))\n\n(declaim (inline inverse-multiple-transform!))\n(defun inverse-multiple-transform! (vector &optional (op- #'-) (handle-zero t))\n \"Does the inverse transform of MULTIPLE-TRANSFORM!. Ignores VECTOR[0] when\nHANDLE-ZERO is NIL.\"\n (declare (vector vector))\n (let* ((n (length vector))\n (sieve (make-array n :element-type 'bit :initial-element 1)))\n (when handle-zero\n (loop for i from 1 below n\n do (setf (aref vector i)\n (funcall op- (aref vector i) (aref vector 0)))))\n (loop for p from 2 below n\n when (= 1 (sbit sieve p))\n do (loop for k from 1 below (ceiling n p)\n for pmult of-type fixnum = (* k p)\n do (setf (sbit sieve pmult) 0)\n (setf (aref vector k)\n (funcall op- (aref vector k) (aref vector pmult)))))\n vector))\n\n;;;\n;;; (Slower) Zeta/Moebius transforms w.r.t. divisor or multiple in O(nlog(n))\n;;;\n\n#|\n(declaim (inline divisor-transform!))\n(defun divisor-transform! (vector &optional (op+ #'+) (handle-zero t))\n \"Sets each VECTOR[i] to the sum of VECTOR[d] for all the divisors d of i in\nO(nlog(n)).\"\n (declare (vector vector))\n (let ((n (length vector)))\n (when handle-zero\n (loop for i from 1 below n\n do (setf (aref vector 0)\n (funcall op+ (aref vector 0) (aref vector i)))))\n (loop for i from (- (ceiling n 2) 1) downto 1\n do (loop for j from (+ i i) below n by i\n do (setf (aref vector j)\n (funcall op+ (aref vector i) (aref vector j)))))\n vector))\n\n(declaim (inline inverse-divisor-transform!))\n(defun inverse-divisor-transform! (vector &optional (op- #'-) (handle-zero t))\n \"Does the inverse transform of DIVISOR-TRANSFORM! in O(nlog(n)).\"\n (declare (vector vector))\n (let ((n (length vector)))\n (loop for i from 1 below (ceiling n 2)\n do (loop for j from (+ i i) below n by i\n do (setf (aref vector j)\n (funcall op- (aref vector j) (aref vector i)))))\n (when handle-zero\n (loop for i from 1 below n\n do (setf (aref vector 0)\n (funcall op- (aref vector 0) (aref vector i)))))\n vector))\n\n\n(declaim (inline multiple-transform!))\n(defun multiple-transform! (vector &optional (op+ #'+) (handle-zero t))\n \"Sets each VECTOR[i] to the sum of VECTOR[m] for all the multiples m of i in\nO(nlog(n)). (To be precise, all the multiples smaller than the length of\nVECTOR.)\"\n (declare (vector vector))\n (let ((n (length vector)))\n (loop for i from 1 below (ceiling n 2)\n do (loop for j from (+ i i) below n by i\n do (setf (aref vector i)\n (funcall op+ (aref vector i) (aref vector j)))))\n (when handle-zero\n (loop for i from 1 below n\n do (setf (aref vector i)\n (funcall op+ (aref vector 0) (aref vector i)))))\n vector))\n\n\n(declaim (inline inverse-multiple-transform!))\n(defun inverse-multiple-transform! (vector &optional (op- #'-) (handle-zero t))\n \"Does the inverse transform of MULTIPLE-TRANSFORM! in O(nlog(n)).\"\n (declare (vector vector))\n (let ((n (length vector)))\n (when handle-zero\n (loop for i from 1 below n\n do (setf (aref vector i)\n (funcall op- (aref vector i) (aref vector 0)))))\n (loop for i from (- (ceiling n 2) 1) downto 1\n do (loop for j from (+ i i) below n by i\n do (setf (aref vector i)\n (funcall op- (aref vector i) (aref vector j)))))\n vector))\n;|#\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (dp (make-array (+ k 1) :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n k))\n (loop for x from 1 to k\n do (setf (aref dp x) (mod-power (floor k x) n +mod+)))\n (inverse-multiple-transform! dp\n (lambda (x y)\n (declare (uint31 x y))\n (mod+ x (the uint31 (- +mod+ y))))\n nil)\n (let ((res 0))\n (declare (uint62 res))\n (loop for x from 1 to k\n do (incf res (mod* x (aref dp x))))\n (println (mod res +mod+)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 2\n\"\n \"9\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 200\n\"\n \"10813692\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"100000 100000\n\"\n \"742202979\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nConsider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive).\n\nThere are K^N such sequences. Find the sum of \\gcd(A_1, ..., A_N) over all of them.\n\nSince this sum can be enormous, print the value modulo (10^9+7).\n\nHere \\gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq K \\leq 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the sum of \\gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7).\n\nSample Input 1\n\n3 2\n\nSample Output 1\n\n9\n\n\\gcd(1,1,1)+\\gcd(1,1,2)+\\gcd(1,2,1)+\\gcd(1,2,2)\n+\\gcd(2,1,1)+\\gcd(2,1,2)+\\gcd(2,2,1)+\\gcd(2,2,2)\n=1+1+1+1+1+1+1+2=9\n\nThus, the answer is 9.\n\nSample Input 2\n\n3 200\n\nSample Output 2\n\n10813692\n\nSample Input 3\n\n100000 100000\n\nSample Output 3\n\n742202979\n\nBe sure to print the sum modulo (10^9+7).", "sample_input": "3 2\n"}, "reference_outputs": ["9\n"], "source_document_id": "p02715", "source_text": "Score : 500 points\n\nProblem Statement\n\nConsider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive).\n\nThere are K^N such sequences. Find the sum of \\gcd(A_1, ..., A_N) over all of them.\n\nSince this sum can be enormous, print the value modulo (10^9+7).\n\nHere \\gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq K \\leq 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the sum of \\gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7).\n\nSample Input 1\n\n3 2\n\nSample Output 1\n\n9\n\n\\gcd(1,1,1)+\\gcd(1,1,2)+\\gcd(1,2,1)+\\gcd(1,2,2)\n+\\gcd(2,1,1)+\\gcd(2,1,2)+\\gcd(2,2,1)+\\gcd(2,2,2)\n=1+1+1+1+1+1+1+2=9\n\nThus, the answer is 9.\n\nSample Input 2\n\n3 200\n\nSample Output 2\n\n10813692\n\nSample Input 3\n\n100000 100000\n\nSample Output 3\n\n742202979\n\nBe sure to print the sum modulo (10^9+7).", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 12656, "cpu_time_ms": 54, "memory_kb": 25304}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s133302884", "group_id": "codeNet:p02719", "input_text": ";; C - Replacing Integer\n\n(defun solve (n k)\n \"「nを|n-k|に置き換える」ことを繰り返したときのnの最小値\"\n (let ((m (mod n k))) ; kずつ減らしていくとmになる\n (min m (- k m))))\n\n(let ((n (read))\n (k (read)))\n (princ (solve n k)))\n", "language": "Lisp", "metadata": {"date": 1586097476, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02719.html", "problem_id": "p02719", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02719/input.txt", "sample_output_relpath": "derived/input_output/data/p02719/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02719/Lisp/s133302884.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s133302884", "user_id": "u227020436"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": ";; C - Replacing Integer\n\n(defun solve (n k)\n \"「nを|n-k|に置き換える」ことを繰り返したときのnの最小値\"\n (let ((m (mod n k))) ; kずつ減らしていくとmになる\n (min m (- k m))))\n\n(let ((n (read))\n (k (read)))\n (princ (solve n k)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven any integer x, Aoki can do the operation below.\n\nOperation: Replace x with the absolute difference of x and K.\n\nYou are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.\n\nConstraints\n\n0 ≤ N ≤ 10^{18}\n\n1 ≤ K ≤ 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the minimum possible value taken by N after Aoki does the operation zero or more times.\n\nSample Input 1\n\n7 4\n\nSample Output 1\n\n1\n\nInitially, N=7.\n\nAfter one operation, N becomes |7-4| = 3.\n\nAfter two operations, N becomes |3-4| = 1, which is the minimum value taken by N.\n\nSample Input 2\n\n2 6\n\nSample Output 2\n\n2\n\nN=2 after zero operations is the minimum.\n\nSample Input 3\n\n1000000000000000000 1\n\nSample Output 3\n\n0", "sample_input": "7 4\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02719", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven any integer x, Aoki can do the operation below.\n\nOperation: Replace x with the absolute difference of x and K.\n\nYou are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.\n\nConstraints\n\n0 ≤ N ≤ 10^{18}\n\n1 ≤ K ≤ 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the minimum possible value taken by N after Aoki does the operation zero or more times.\n\nSample Input 1\n\n7 4\n\nSample Output 1\n\n1\n\nInitially, N=7.\n\nAfter one operation, N becomes |7-4| = 3.\n\nAfter two operations, N becomes |3-4| = 1, which is the minimum value taken by N.\n\nSample Input 2\n\n2 6\n\nSample Output 2\n\n2\n\nN=2 after zero operations is the minimum.\n\nSample Input 3\n\n1000000000000000000 1\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 274, "cpu_time_ms": 15, "memory_kb": 3816}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s136179897", "group_id": "codeNet:p02720", "input_text": ";; D - Lunlun Number\n\n(defparameter *max-n-digits* 10) ; 最大桁数 (入力例4を参照)\n\n(defun next-lunlun (lun &optional (i 0))\n \"i桁目以降を次のルンルン数に更新. lunは最下位桁から順に格納.\"\n (cond ((null (aref lun i))\n (setf (aref lun i) 1))\n ((or (>= (aref lun i) 9) ; i桁目が9\n (and (aref lun (1+ i)) ; i桁目がi+1桁目より大きい\n (> (aref lun i) (aref lun (1+ i)))))\n (next-lunlun lun (1+ i))\n (setf (aref lun i) (max 0 (1- (aref lun (1+ i))))))\n (t ; 桁上がりなし\n (incf (aref lun i)))))\n\n(defun lunlun-to-int (lun)\n \"配列lun (先頭が最下位桁) を整数に変換\"\n (loop for x across lun\n for i from 0\n for acc = x then (if x (+ acc (* (expt 10 i) x)) acc)\n finally (return acc)))\n\n(defun lunlun (k)\n \"k番目のルンルン数\"\n (let ((lun (make-array (1+ *max-n-digits*) :initial-element nil)))\n ; lunは最下位桁から順に格納.\n (setf (aref lun 0) 0) ; 最下位桁を0に初期化\n (loop repeat k do (next-lunlun lun)\n finally (return (lunlun-to-int lun)))))\n\n(let ((k (read)))\n (princ (lunlun k)))\n", "language": "Lisp", "metadata": {"date": 1586099810, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02720.html", "problem_id": "p02720", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02720/input.txt", "sample_output_relpath": "derived/input_output/data/p02720/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02720/Lisp/s136179897.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s136179897", "user_id": "u227020436"}, "prompt_components": {"gold_output": "23\n", "input_to_evaluate": ";; D - Lunlun Number\n\n(defparameter *max-n-digits* 10) ; 最大桁数 (入力例4を参照)\n\n(defun next-lunlun (lun &optional (i 0))\n \"i桁目以降を次のルンルン数に更新. lunは最下位桁から順に格納.\"\n (cond ((null (aref lun i))\n (setf (aref lun i) 1))\n ((or (>= (aref lun i) 9) ; i桁目が9\n (and (aref lun (1+ i)) ; i桁目がi+1桁目より大きい\n (> (aref lun i) (aref lun (1+ i)))))\n (next-lunlun lun (1+ i))\n (setf (aref lun i) (max 0 (1- (aref lun (1+ i))))))\n (t ; 桁上がりなし\n (incf (aref lun i)))))\n\n(defun lunlun-to-int (lun)\n \"配列lun (先頭が最下位桁) を整数に変換\"\n (loop for x across lun\n for i from 0\n for acc = x then (if x (+ acc (* (expt 10 i) x)) acc)\n finally (return acc)))\n\n(defun lunlun (k)\n \"k番目のルンルン数\"\n (let ((lun (make-array (1+ *max-n-digits*) :initial-element nil)))\n ; lunは最下位桁から順に格納.\n (setf (aref lun 0) 0) ; 最下位桁を0に初期化\n (loop repeat k do (next-lunlun lun)\n finally (return (lunlun-to-int lun)))))\n\n(let ((k (read)))\n (princ (lunlun k)))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nA positive integer X is said to be a lunlun number if and only if the following condition is satisfied:\n\nIn the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.\n\nFor example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.\n\nYou are given a positive integer K. Find the K-th smallest lunlun number.\n\nConstraints\n\n1 \\leq K \\leq 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n15\n\nSample Output 1\n\n23\n\nWe will list the 15 smallest lunlun numbers in ascending order:\n\n1,\n2,\n3,\n4,\n5,\n6,\n7,\n8,\n9,\n10,\n11,\n12,\n21,\n22,\n23.\n\nThus, the answer is 23.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n1\n\nSample Input 3\n\n13\n\nSample Output 3\n\n21\n\nSample Input 4\n\n100000\n\nSample Output 4\n\n3234566667\n\nNote that the answer may not fit into the 32-bit signed integer type.", "sample_input": "15\n"}, "reference_outputs": ["23\n"], "source_document_id": "p02720", "source_text": "Score : 400 points\n\nProblem Statement\n\nA positive integer X is said to be a lunlun number if and only if the following condition is satisfied:\n\nIn the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.\n\nFor example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.\n\nYou are given a positive integer K. Find the K-th smallest lunlun number.\n\nConstraints\n\n1 \\leq K \\leq 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n15\n\nSample Output 1\n\n23\n\nWe will list the 15 smallest lunlun numbers in ascending order:\n\n1,\n2,\n3,\n4,\n5,\n6,\n7,\n8,\n9,\n10,\n11,\n12,\n21,\n22,\n23.\n\nThus, the answer is 23.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n1\n\nSample Input 3\n\n13\n\nSample Output 3\n\n21\n\nSample Input 4\n\n100000\n\nSample Output 4\n\n3234566667\n\nNote that the answer may not fit into the 32-bit signed integer type.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1197, "cpu_time_ms": 47, "memory_kb": 7648}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s466725567", "group_id": "codeNet:p02720", "input_text": "(defun lunlunp (n)\n (let* ((str (write-to-string n))\n (seq (loop :as i\n :across str\n :collect (digit-char-p i)))\n (len (length seq)))\n (zerop (loop :as i\n :in seq\n :as j\n :in (cdr seq)\n :when (< 1 (abs (- i j)))\n :count i))))\n\n(defun nth-p-number (n c next)\n (cond \n ((and (lunlunp next) (= n c))\n next)\n ((lunlunp next) \n (nth-p-number n (+ c 1) (+ next 1)))\n (t\n (nth-p-number n c (+ next 1)))))\n\n(let ((k (read)))\n (princ (nth-p-number k 1 1)))\n", "language": "Lisp", "metadata": {"date": 1586051858, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02720.html", "problem_id": "p02720", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02720/input.txt", "sample_output_relpath": "derived/input_output/data/p02720/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02720/Lisp/s466725567.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s466725567", "user_id": "u606976120"}, "prompt_components": {"gold_output": "23\n", "input_to_evaluate": "(defun lunlunp (n)\n (let* ((str (write-to-string n))\n (seq (loop :as i\n :across str\n :collect (digit-char-p i)))\n (len (length seq)))\n (zerop (loop :as i\n :in seq\n :as j\n :in (cdr seq)\n :when (< 1 (abs (- i j)))\n :count i))))\n\n(defun nth-p-number (n c next)\n (cond \n ((and (lunlunp next) (= n c))\n next)\n ((lunlunp next) \n (nth-p-number n (+ c 1) (+ next 1)))\n (t\n (nth-p-number n c (+ next 1)))))\n\n(let ((k (read)))\n (princ (nth-p-number k 1 1)))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nA positive integer X is said to be a lunlun number if and only if the following condition is satisfied:\n\nIn the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.\n\nFor example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.\n\nYou are given a positive integer K. Find the K-th smallest lunlun number.\n\nConstraints\n\n1 \\leq K \\leq 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n15\n\nSample Output 1\n\n23\n\nWe will list the 15 smallest lunlun numbers in ascending order:\n\n1,\n2,\n3,\n4,\n5,\n6,\n7,\n8,\n9,\n10,\n11,\n12,\n21,\n22,\n23.\n\nThus, the answer is 23.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n1\n\nSample Input 3\n\n13\n\nSample Output 3\n\n21\n\nSample Input 4\n\n100000\n\nSample Output 4\n\n3234566667\n\nNote that the answer may not fit into the 32-bit signed integer type.", "sample_input": "15\n"}, "reference_outputs": ["23\n"], "source_document_id": "p02720", "source_text": "Score : 400 points\n\nProblem Statement\n\nA positive integer X is said to be a lunlun number if and only if the following condition is satisfied:\n\nIn the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.\n\nFor example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.\n\nYou are given a positive integer K. Find the K-th smallest lunlun number.\n\nConstraints\n\n1 \\leq K \\leq 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n15\n\nSample Output 1\n\n23\n\nWe will list the 15 smallest lunlun numbers in ascending order:\n\n1,\n2,\n3,\n4,\n5,\n6,\n7,\n8,\n9,\n10,\n11,\n12,\n21,\n22,\n23.\n\nThus, the answer is 23.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n1\n\nSample Input 3\n\n13\n\nSample Output 3\n\n21\n\nSample Input 4\n\n100000\n\nSample Output 4\n\n3234566667\n\nNote that the answer may not fit into the 32-bit signed integer type.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 612, "cpu_time_ms": 2105, "memory_kb": 59880}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s126387048", "group_id": "codeNet:p02721", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (c (read))\n (s (coerce (read-line) 'simple-base-string))\n (dp1 (make-array (+ n 1) :element-type 'uint32))\n (dp2 (make-array (+ n 1) :element-type 'uint32)))\n (declare (uint31 n k c))\n (let ((prev #x-80000000)\n (count 0))\n (declare (fixnum prev count))\n (loop for i below n\n when (and (char= #\\o (aref s i))\n (> i (+ prev c)))\n do (incf count)\n (setf (aref dp1 count) i)\n (setq prev i)))\n (let ((prev #x7fffffff)\n (count (+ k 1)))\n (declare (fixnum prev count))\n (loop for i from (- n 1) downto 0\n when (and (char= #\\o (aref s i))\n (< i (- prev c)))\n do (decf count)\n (when (>= count 0)\n (setf (aref dp2 count) i))\n (setq prev i)))\n (with-buffered-stdout\n (loop for i from 1 to k\n when (= (aref dp1 i) (aref dp2 i))\n do (println (+ 1 (aref dp1 i)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (or (sequence:emptyp s)\n (eql (uiop:last-char s) #\\Linefeed))\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"11 3 2\nooxxxoxxxoo\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 2 3\nooxoo\n\"\n \"1\n5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 1 0\nooooo\n\"\n \"\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"16 4 3\nooxxoxoxxxoxoxxo\n\"\n \"11\n16\n\")))\n", "language": "Lisp", "metadata": {"date": 1586075603, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02721.html", "problem_id": "p02721", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02721/input.txt", "sample_output_relpath": "derived/input_output/data/p02721/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02721/Lisp/s126387048.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s126387048", "user_id": "u352600849"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (c (read))\n (s (coerce (read-line) 'simple-base-string))\n (dp1 (make-array (+ n 1) :element-type 'uint32))\n (dp2 (make-array (+ n 1) :element-type 'uint32)))\n (declare (uint31 n k c))\n (let ((prev #x-80000000)\n (count 0))\n (declare (fixnum prev count))\n (loop for i below n\n when (and (char= #\\o (aref s i))\n (> i (+ prev c)))\n do (incf count)\n (setf (aref dp1 count) i)\n (setq prev i)))\n (let ((prev #x7fffffff)\n (count (+ k 1)))\n (declare (fixnum prev count))\n (loop for i from (- n 1) downto 0\n when (and (char= #\\o (aref s i))\n (< i (- prev c)))\n do (decf count)\n (when (>= count 0)\n (setf (aref dp2 count) i))\n (setq prev i)))\n (with-buffered-stdout\n (loop for i from 1 to k\n when (= (aref dp1 i) (aref dp2 i))\n do (println (+ 1 (aref dp1 i)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (or (sequence:emptyp s)\n (eql (uiop:last-char s) #\\Linefeed))\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"11 3 2\nooxxxoxxxoo\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 2 3\nooxoo\n\"\n \"1\n5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 1 0\nooooo\n\"\n \"\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"16 4 3\nooxxoxoxxxoxoxxo\n\"\n \"11\n16\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nTakahashi has decided to work on K days of his choice from the N days starting with tomorrow.\n\nYou are given an integer C and a string S. Takahashi will choose his workdays as follows:\n\nAfter working for a day, he will refrain from working on the subsequent C days.\n\nIf the i-th character of S is x, he will not work on Day i, where Day 1 is tomorrow, Day 2 is the day after tomorrow, and so on.\n\nFind all days on which Takahashi is bound to work.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq K \\leq N\n\n0 \\leq C \\leq N\n\nThe length of S is N.\n\nEach character of S is o or x.\n\nTakahashi can choose his workdays so that the conditions in Problem Statement are satisfied.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K C\nS\n\nOutput\n\nPrint all days on which Takahashi is bound to work in ascending order, one per line.\n\nSample Input 1\n\n11 3 2\nooxxxoxxxoo\n\nSample Output 1\n\n6\n\nTakahashi is going to work on 3 days out of the 11 days. After working for a day, he will refrain from working on the subsequent 2 days.\n\nThere are four possible choices for his workdays: Day 1,6,10, Day 1,6,11, Day 2,6,10, and Day 2,6,11.\n\nThus, he is bound to work on Day 6.\n\nSample Input 2\n\n5 2 3\nooxoo\n\nSample Output 2\n\n1\n5\n\nThere is only one possible choice for his workdays: Day 1,5.\n\nSample Input 3\n\n5 1 0\nooooo\n\nSample Output 3\n\nThere may be no days on which he is bound to work.\n\nSample Input 4\n\n16 4 3\nooxxoxoxxxoxoxxo\n\nSample Output 4\n\n11\n16", "sample_input": "11 3 2\nooxxxoxxxoo\n"}, "reference_outputs": ["6\n"], "source_document_id": "p02721", "source_text": "Score : 500 points\n\nProblem Statement\n\nTakahashi has decided to work on K days of his choice from the N days starting with tomorrow.\n\nYou are given an integer C and a string S. Takahashi will choose his workdays as follows:\n\nAfter working for a day, he will refrain from working on the subsequent C days.\n\nIf the i-th character of S is x, he will not work on Day i, where Day 1 is tomorrow, Day 2 is the day after tomorrow, and so on.\n\nFind all days on which Takahashi is bound to work.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq K \\leq N\n\n0 \\leq C \\leq N\n\nThe length of S is N.\n\nEach character of S is o or x.\n\nTakahashi can choose his workdays so that the conditions in Problem Statement are satisfied.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K C\nS\n\nOutput\n\nPrint all days on which Takahashi is bound to work in ascending order, one per line.\n\nSample Input 1\n\n11 3 2\nooxxxoxxxoo\n\nSample Output 1\n\n6\n\nTakahashi is going to work on 3 days out of the 11 days. After working for a day, he will refrain from working on the subsequent 2 days.\n\nThere are four possible choices for his workdays: Day 1,6,10, Day 1,6,11, Day 2,6,10, and Day 2,6,11.\n\nThus, he is bound to work on Day 6.\n\nSample Input 2\n\n5 2 3\nooxoo\n\nSample Output 2\n\n1\n5\n\nThere is only one possible choice for his workdays: Day 1,5.\n\nSample Input 3\n\n5 1 0\nooooo\n\nSample Output 3\n\nThere may be no days on which he is bound to work.\n\nSample Input 4\n\n16 4 3\nooxxoxoxxxoxoxxo\n\nSample Output 4\n\n11\n16", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5489, "cpu_time_ms": 260, "memory_kb": 30820}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s680905238", "group_id": "codeNet:p02722", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values (vector (integer 0 #.most-positive-fixnum)) &optional))\n enum-divisors))\n(defun enum-divisors (x)\n \"Enumerates all the divisors of X in O(sqrt(X)) time. Note that the resultant\nvector is NOT sorted.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) x))\n (let* ((sqrt (isqrt x))\n (result (make-array (isqrt sqrt) ; FIXME: currently set the initial size to x^1/4\n :element-type '(integer 0 #.most-positive-fixnum)\n :fill-pointer 0)))\n (loop for i from 1 to sqrt\n do (multiple-value-bind (quot rem) (floor x i)\n (when (zerop rem)\n (vector-push-extend i result)\n (unless (= i quot)\n (vector-push-extend quot result)))))\n result))\n\n;; Below is a variant that returns a sorted list.\n(defun enum-ascending-divisors (n)\n \"Returns the ascending list of all the divisors of N.\"\n (declare (optimize (speed 3))\n ((integer 1 #.most-positive-fixnum) n))\n (if (= n 1)\n (list 1)\n (let* ((sqrt (isqrt n))\n (result (list 1)))\n (labels ((%enum (i first-half second-half)\n (declare ((integer 1 #.most-positive-fixnum) i))\n (cond ((or (< i sqrt)\n (and (= i sqrt) (/= (* sqrt sqrt) n)))\n (multiple-value-bind (quot rem) (floor n i)\n (if (zerop rem)\n (progn\n (setf (cdr first-half) (list i))\n (setf second-half (cons quot second-half))\n (%enum (1+ i) (cdr first-half) second-half))\n (%enum (1+ i) first-half second-half))))\n ((= i sqrt) ; N is a square number here\n (setf (cdr first-half) (cons i second-half)))\n (t ; (> i sqrt)\n (setf (cdr first-half) second-half)))))\n (%enum 2 result (list n))\n result))))\n\n(declaim (ftype (function * (values (simple-array list (*)) &optional))\n make-divisors-table))\n(defun make-divisors-table (sup)\n \"Returns a vector of length SUP whose each cell, vector[X], is the ascending\nlist of every divisor of X. Note that vector[0] = NIL.\"\n (declare ((integer 0 #.most-positive-fixnum) sup)\n #+sbcl (sb-ext:muffle-conditions style-warning))\n (let ((result (make-array sup :element-type 'list))\n (tails (make-array sup :element-type 'list))) ; stores the last cons cell\n (declare (optimize (speed 3) (safety 0)))\n (loop for i from 1 below sup\n for cell = (list 1)\n do (setf (aref result i) cell\n (aref tails i) cell))\n (when (>= sup 1)\n (setf (aref result 0) nil))\n (loop for divisor from 2 below sup\n do (loop for number from divisor below sup by divisor\n do (setf (cdr (aref tails number)) (list divisor)\n (aref tails number) (cdr (aref tails number)))))\n result))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (table (make-hash-table :test #'eq))\n (divisors-1 (enum-divisors (- n 1)))\n (divisors (enum-divisors n)))\n (sb-int:dovector (d divisors-1)\n (unless (= 1 d)\n (setf (gethash d table) t)))\n (sb-int:dovector (d divisors)\n (unless (= 1 d)\n (let ((value n))\n (loop (multiple-value-bind (quot rem) (floor value d)\n (cond ((zerop rem)\n (setq value quot))\n ((= rem 1)\n (setf (gethash d table) t)\n (return))\n (t (return))))))))\n (println (hash-table-count table))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3141\n\"\n \"13\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"314159265358\n\"\n \"9\n\")))\n", "language": "Lisp", "metadata": {"date": 1586070149, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02722.html", "problem_id": "p02722", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02722/input.txt", "sample_output_relpath": "derived/input_output/data/p02722/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02722/Lisp/s680905238.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s680905238", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values (vector (integer 0 #.most-positive-fixnum)) &optional))\n enum-divisors))\n(defun enum-divisors (x)\n \"Enumerates all the divisors of X in O(sqrt(X)) time. Note that the resultant\nvector is NOT sorted.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) x))\n (let* ((sqrt (isqrt x))\n (result (make-array (isqrt sqrt) ; FIXME: currently set the initial size to x^1/4\n :element-type '(integer 0 #.most-positive-fixnum)\n :fill-pointer 0)))\n (loop for i from 1 to sqrt\n do (multiple-value-bind (quot rem) (floor x i)\n (when (zerop rem)\n (vector-push-extend i result)\n (unless (= i quot)\n (vector-push-extend quot result)))))\n result))\n\n;; Below is a variant that returns a sorted list.\n(defun enum-ascending-divisors (n)\n \"Returns the ascending list of all the divisors of N.\"\n (declare (optimize (speed 3))\n ((integer 1 #.most-positive-fixnum) n))\n (if (= n 1)\n (list 1)\n (let* ((sqrt (isqrt n))\n (result (list 1)))\n (labels ((%enum (i first-half second-half)\n (declare ((integer 1 #.most-positive-fixnum) i))\n (cond ((or (< i sqrt)\n (and (= i sqrt) (/= (* sqrt sqrt) n)))\n (multiple-value-bind (quot rem) (floor n i)\n (if (zerop rem)\n (progn\n (setf (cdr first-half) (list i))\n (setf second-half (cons quot second-half))\n (%enum (1+ i) (cdr first-half) second-half))\n (%enum (1+ i) first-half second-half))))\n ((= i sqrt) ; N is a square number here\n (setf (cdr first-half) (cons i second-half)))\n (t ; (> i sqrt)\n (setf (cdr first-half) second-half)))))\n (%enum 2 result (list n))\n result))))\n\n(declaim (ftype (function * (values (simple-array list (*)) &optional))\n make-divisors-table))\n(defun make-divisors-table (sup)\n \"Returns a vector of length SUP whose each cell, vector[X], is the ascending\nlist of every divisor of X. Note that vector[0] = NIL.\"\n (declare ((integer 0 #.most-positive-fixnum) sup)\n #+sbcl (sb-ext:muffle-conditions style-warning))\n (let ((result (make-array sup :element-type 'list))\n (tails (make-array sup :element-type 'list))) ; stores the last cons cell\n (declare (optimize (speed 3) (safety 0)))\n (loop for i from 1 below sup\n for cell = (list 1)\n do (setf (aref result i) cell\n (aref tails i) cell))\n (when (>= sup 1)\n (setf (aref result 0) nil))\n (loop for divisor from 2 below sup\n do (loop for number from divisor below sup by divisor\n do (setf (cdr (aref tails number)) (list divisor)\n (aref tails number) (cdr (aref tails number)))))\n result))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (table (make-hash-table :test #'eq))\n (divisors-1 (enum-divisors (- n 1)))\n (divisors (enum-divisors n)))\n (sb-int:dovector (d divisors-1)\n (unless (= 1 d)\n (setf (gethash d table) t)))\n (sb-int:dovector (d divisors)\n (unless (= 1 d)\n (let ((value n))\n (loop (multiple-value-bind (quot rem) (floor value d)\n (cond ((zerop rem)\n (setq value quot))\n ((= rem 1)\n (setf (gethash d table) t)\n (return))\n (t (return))))))))\n (println (hash-table-count table))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3141\n\"\n \"13\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"314159265358\n\"\n \"9\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven is a positive integer N.\n\nWe will choose an integer K between 2 and N (inclusive), then we will repeat the operation below until N becomes less than K.\n\nOperation: if K divides N, replace N with N/K; otherwise, replace N with N-K.\n\nIn how many choices of K will N become 1 in the end?\n\nConstraints\n\n2 \\leq N \\leq 10^{12}\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the number of choices of K in which N becomes 1 in the end.\n\nSample Input 1\n\n6\n\nSample Output 1\n\n3\n\nThere are three choices of K in which N becomes 1 in the end: 2, 5, and 6.\n\nIn each of these choices, N will change as follows:\n\nWhen K=2: 6 \\to 3 \\to 1\n\nWhen K=5: 6 \\to 1\n\nWhen K=6: 6 \\to 1\n\nSample Input 2\n\n3141\n\nSample Output 2\n\n13\n\nSample Input 3\n\n314159265358\n\nSample Output 3\n\n9", "sample_input": "6\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02722", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven is a positive integer N.\n\nWe will choose an integer K between 2 and N (inclusive), then we will repeat the operation below until N becomes less than K.\n\nOperation: if K divides N, replace N with N/K; otherwise, replace N with N-K.\n\nIn how many choices of K will N become 1 in the end?\n\nConstraints\n\n2 \\leq N \\leq 10^{12}\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the number of choices of K in which N becomes 1 in the end.\n\nSample Input 1\n\n6\n\nSample Output 1\n\n3\n\nThere are three choices of K in which N becomes 1 in the end: 2, 5, and 6.\n\nIn each of these choices, N will change as follows:\n\nWhen K=2: 6 \\to 3 \\to 1\n\nWhen K=5: 6 \\to 1\n\nWhen K=6: 6 \\to 1\n\nSample Input 2\n\n3141\n\nSample Output 2\n\n13\n\nSample Input 3\n\n314159265358\n\nSample Output 3\n\n9", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7467, "cpu_time_ms": 100, "memory_kb": 14564}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s173208692", "group_id": "codeNet:p02723", "input_text": "(let ((s (read-line)))\n (if (and (char= (char s 2) (char s 3))\n (char= (char s 4) (char s 5)))\n (format t \"Yes~%\")\n (format t \"No~%\")))\n", "language": "Lisp", "metadata": {"date": 1593626425, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02723.html", "problem_id": "p02723", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02723/input.txt", "sample_output_relpath": "derived/input_output/data/p02723/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02723/Lisp/s173208692.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s173208692", "user_id": "u608227593"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((s (read-line)))\n (if (and (char= (char s 2) (char s 3))\n (char= (char s 4) (char s 5)))\n (format t \"Yes~%\")\n (format t \"No~%\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nA string of length 6 consisting of lowercase English letters is said to be coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th and 6-th characters are also equal.\n\nGiven a string S, determine whether it is coffee-like.\n\nConstraints\n\nS is a string of length 6 consisting of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S is coffee-like, print Yes; otherwise, print No.\n\nSample Input 1\n\nsippuu\n\nSample Output 1\n\nYes\n\nIn sippuu, the 3-rd and 4-th characters are equal, and the 5-th and 6-th characters are also equal.\n\nSample Input 2\n\niphone\n\nSample Output 2\n\nNo\n\nSample Input 3\n\ncoffee\n\nSample Output 3\n\nYes", "sample_input": "sippuu\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02723", "source_text": "Score : 100 points\n\nProblem Statement\n\nA string of length 6 consisting of lowercase English letters is said to be coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th and 6-th characters are also equal.\n\nGiven a string S, determine whether it is coffee-like.\n\nConstraints\n\nS is a string of length 6 consisting of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S is coffee-like, print Yes; otherwise, print No.\n\nSample Input 1\n\nsippuu\n\nSample Output 1\n\nYes\n\nIn sippuu, the 3-rd and 4-th characters are equal, and the 5-th and 6-th characters are also equal.\n\nSample Input 2\n\niphone\n\nSample Output 2\n\nNo\n\nSample Input 3\n\ncoffee\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 157, "cpu_time_ms": 17, "memory_kb": 23232}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s950755592", "group_id": "codeNet:p02724", "input_text": "(let* ((n (read)))\n (multiple-value-bind (a b) (floor n 500)\n (princ (+ (* 1000 a) (* (floor b 5) 5)))))", "language": "Lisp", "metadata": {"date": 1585443809, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02724.html", "problem_id": "p02724", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02724/input.txt", "sample_output_relpath": "derived/input_output/data/p02724/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02724/Lisp/s950755592.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s950755592", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2020\n", "input_to_evaluate": "(let* ((n (read)))\n (multiple-value-bind (a b) (floor n 500)\n (princ (+ (* 1000 a) (* (floor b 5) 5)))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi loves gold coins. He gains 1000 happiness points for each 500-yen coin he has and gains 5 happiness points for each 5-yen coin he has. (Yen is the currency of Japan.)\n\nTakahashi has X yen. If he exchanges his money so that he will gain the most happiness points, how many happiness points will he earn?\n\n(We assume that there are six kinds of coins available: 500-yen, 100-yen, 50-yen, 10-yen, 5-yen, and 1-yen coins.)\n\nConstraints\n\n0 \\leq X \\leq 10^9\n\nX is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the maximum number of happiness points that can be earned.\n\nSample Input 1\n\n1024\n\nSample Output 1\n\n2020\n\nBy exchanging his money so that he gets two 500-yen coins and four 5-yen coins, he gains 2020 happiness points, which is the maximum number of happiness points that can be earned.\n\nSample Input 2\n\n0\n\nSample Output 2\n\n0\n\nHe is penniless - or yenless.\n\nSample Input 3\n\n1000000000\n\nSample Output 3\n\n2000000000\n\nHe is a billionaire - in yen.", "sample_input": "1024\n"}, "reference_outputs": ["2020\n"], "source_document_id": "p02724", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi loves gold coins. He gains 1000 happiness points for each 500-yen coin he has and gains 5 happiness points for each 5-yen coin he has. (Yen is the currency of Japan.)\n\nTakahashi has X yen. If he exchanges his money so that he will gain the most happiness points, how many happiness points will he earn?\n\n(We assume that there are six kinds of coins available: 500-yen, 100-yen, 50-yen, 10-yen, 5-yen, and 1-yen coins.)\n\nConstraints\n\n0 \\leq X \\leq 10^9\n\nX is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the maximum number of happiness points that can be earned.\n\nSample Input 1\n\n1024\n\nSample Output 1\n\n2020\n\nBy exchanging his money so that he gets two 500-yen coins and four 5-yen coins, he gains 2020 happiness points, which is the maximum number of happiness points that can be earned.\n\nSample Input 2\n\n0\n\nSample Output 2\n\n0\n\nHe is penniless - or yenless.\n\nSample Input 3\n\n1000000000\n\nSample Output 3\n\n2000000000\n\nHe is a billionaire - in yen.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 108, "cpu_time_ms": 383, "memory_kb": 13032}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s490669311", "group_id": "codeNet:p02725", "input_text": "(let* ((len (read))\n (n (read))\n (arr (make-array n\n :initial-contents\n (loop repeat n\n collect (read))))\n (lst (loop for i below (1- n)\n collect (- (aref arr (1+ i))\n (aref arr i)))))\n (format t \"~A\" (- len (apply #'max lst))))", "language": "Lisp", "metadata": {"date": 1587957272, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02725.html", "problem_id": "p02725", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02725/input.txt", "sample_output_relpath": "derived/input_output/data/p02725/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02725/Lisp/s490669311.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s490669311", "user_id": "u425317134"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(let* ((len (read))\n (n (read))\n (arr (make-array n\n :initial-contents\n (loop repeat n\n collect (read))))\n (lst (loop for i below (1- n)\n collect (- (aref arr (1+ i))\n (aref arr i)))))\n (format t \"~A\" (- len (apply #'max lst))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere is a circular pond with a perimeter of K meters, and N houses around them.\n\nThe i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.\n\nWhen traveling between these houses, you can only go around the pond.\n\nFind the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.\n\nConstraints\n\n2 \\leq K \\leq 10^6\n\n2 \\leq N \\leq 2 \\times 10^5\n\n0 \\leq A_1 < ... < A_N < K\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK N\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.\n\nSample Input 1\n\n20 3\n5 10 15\n\nSample Output 1\n\n10\n\nIf you start at the 1-st house and go to the 2-nd and 3-rd houses in this order, the total distance traveled will be 10.\n\nSample Input 2\n\n20 3\n0 5 15\n\nSample Output 2\n\n10\n\nIf you start at the 2-nd house and go to the 1-st and 3-rd houses in this order, the total distance traveled will be 10.", "sample_input": "20 3\n5 10 15\n"}, "reference_outputs": ["10\n"], "source_document_id": "p02725", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere is a circular pond with a perimeter of K meters, and N houses around them.\n\nThe i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.\n\nWhen traveling between these houses, you can only go around the pond.\n\nFind the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.\n\nConstraints\n\n2 \\leq K \\leq 10^6\n\n2 \\leq N \\leq 2 \\times 10^5\n\n0 \\leq A_1 < ... < A_N < K\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK N\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.\n\nSample Input 1\n\n20 3\n5 10 15\n\nSample Output 1\n\n10\n\nIf you start at the 1-st house and go to the 2-nd and 3-rd houses in this order, the total distance traveled will be 10.\n\nSample Input 2\n\n20 3\n0 5 15\n\nSample Output 2\n\n10\n\nIf you start at the 2-nd house and go to the 1-st and 3-rd houses in this order, the total distance traveled will be 10.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 371, "cpu_time_ms": 463, "memory_kb": 65252}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s659165807", "group_id": "codeNet:p02725", "input_text": "(defun split (input stack-string output-list)\n (let ((chara (car input)))\n (case chara\n ((nil) (append output-list (list stack-string)))\n (#\\space (split (cdr input)\n '()\n (append output-list (list stack-string))))\n (otherwise (split (cdr input)\n (concatenate 'string stack-string (list chara))\n output-list)))))\n\n(defun input-to-list (input)\n (mapcar #'parse-integer (split (concatenate 'list input)\n '()\n '())))\n\n(defvar kn (input-to-list (read-line)))\n(defvar a (input-to-list (read-line)))\n\n#| (defun submax (lst)\n (labels ((inner (lst candidate)\n (if (cdr lst)\n (let ((challenger (- (cadr lst) (car lst))))\n (if (< candidate challenger)\n (inner (cdr lst) challenger)\n (inner (cdr lst) candidate)))\n candidate)))\n (inner lst 0))) |#\n\n(defun submax (lst)\n (labels ((inner (lst candidate)\n (if (cdr lst)\n (inner (cdr lst)\n (let ((challenger (- (cadr lst) (car lst))))\n (if (< candidate challenger)\n challenger\n candidate)))\n candidate)))\n (inner lst 0)))\n\n(princ (- (car kn) (submax (append a\n (list (+ (car kn) (car a)))))))\n", "language": "Lisp", "metadata": {"date": 1585452801, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02725.html", "problem_id": "p02725", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02725/input.txt", "sample_output_relpath": "derived/input_output/data/p02725/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02725/Lisp/s659165807.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s659165807", "user_id": "u250100102"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(defun split (input stack-string output-list)\n (let ((chara (car input)))\n (case chara\n ((nil) (append output-list (list stack-string)))\n (#\\space (split (cdr input)\n '()\n (append output-list (list stack-string))))\n (otherwise (split (cdr input)\n (concatenate 'string stack-string (list chara))\n output-list)))))\n\n(defun input-to-list (input)\n (mapcar #'parse-integer (split (concatenate 'list input)\n '()\n '())))\n\n(defvar kn (input-to-list (read-line)))\n(defvar a (input-to-list (read-line)))\n\n#| (defun submax (lst)\n (labels ((inner (lst candidate)\n (if (cdr lst)\n (let ((challenger (- (cadr lst) (car lst))))\n (if (< candidate challenger)\n (inner (cdr lst) challenger)\n (inner (cdr lst) candidate)))\n candidate)))\n (inner lst 0))) |#\n\n(defun submax (lst)\n (labels ((inner (lst candidate)\n (if (cdr lst)\n (inner (cdr lst)\n (let ((challenger (- (cadr lst) (car lst))))\n (if (< candidate challenger)\n challenger\n candidate)))\n candidate)))\n (inner lst 0)))\n\n(princ (- (car kn) (submax (append a\n (list (+ (car kn) (car a)))))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere is a circular pond with a perimeter of K meters, and N houses around them.\n\nThe i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.\n\nWhen traveling between these houses, you can only go around the pond.\n\nFind the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.\n\nConstraints\n\n2 \\leq K \\leq 10^6\n\n2 \\leq N \\leq 2 \\times 10^5\n\n0 \\leq A_1 < ... < A_N < K\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK N\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.\n\nSample Input 1\n\n20 3\n5 10 15\n\nSample Output 1\n\n10\n\nIf you start at the 1-st house and go to the 2-nd and 3-rd houses in this order, the total distance traveled will be 10.\n\nSample Input 2\n\n20 3\n0 5 15\n\nSample Output 2\n\n10\n\nIf you start at the 2-nd house and go to the 1-st and 3-rd houses in this order, the total distance traveled will be 10.", "sample_input": "20 3\n5 10 15\n"}, "reference_outputs": ["10\n"], "source_document_id": "p02725", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere is a circular pond with a perimeter of K meters, and N houses around them.\n\nThe i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.\n\nWhen traveling between these houses, you can only go around the pond.\n\nFind the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.\n\nConstraints\n\n2 \\leq K \\leq 10^6\n\n2 \\leq N \\leq 2 \\times 10^5\n\n0 \\leq A_1 < ... < A_N < K\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK N\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.\n\nSample Input 1\n\n20 3\n5 10 15\n\nSample Output 1\n\n10\n\nIf you start at the 1-st house and go to the 2-nd and 3-rd houses in this order, the total distance traveled will be 10.\n\nSample Input 2\n\n20 3\n0 5 15\n\nSample Output 2\n\n10\n\nIf you start at the 2-nd house and go to the 1-st and 3-rd houses in this order, the total distance traveled will be 10.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1603, "cpu_time_ms": 2106, "memory_kb": 98568}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s976745601", "group_id": "codeNet:p02725", "input_text": "(defun split (input stack-string output-list)\n (let ((chara (car input)))\n (case chara\n ((nil) (append output-list (list stack-string)))\n (#\\space (split (cdr input)\n '()\n (append output-list (list stack-string))))\n (otherwise (split (cdr input)\n (concatenate 'string stack-string (list chara))\n output-list)))))\n\n(defun input-to-list (input)\n (mapcar #'parse-integer (split (concatenate 'list input)\n '()\n '())))\n\n(defvar kn (input-to-list (read-line)))\n(defvar a (input-to-list (read-line)))\n\n(defun submax (lst)\n (labels ((inner (lst candidate)\n (if (cdr lst)\n (inner (cdr lst)\n (let ((challenger (- (cadr lst) (car lst))))\n (if (< candidate challenger)\n challenger\n candidate)))\n candidate)))\n (max (inner lst 0)\n (- (+ (car kn) (car a))\n (nth (1- (cadr kn)) a)))))\n\n(princ (- k (submax a)))\n", "language": "Lisp", "metadata": {"date": 1585452092, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02725.html", "problem_id": "p02725", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02725/input.txt", "sample_output_relpath": "derived/input_output/data/p02725/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02725/Lisp/s976745601.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s976745601", "user_id": "u250100102"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(defun split (input stack-string output-list)\n (let ((chara (car input)))\n (case chara\n ((nil) (append output-list (list stack-string)))\n (#\\space (split (cdr input)\n '()\n (append output-list (list stack-string))))\n (otherwise (split (cdr input)\n (concatenate 'string stack-string (list chara))\n output-list)))))\n\n(defun input-to-list (input)\n (mapcar #'parse-integer (split (concatenate 'list input)\n '()\n '())))\n\n(defvar kn (input-to-list (read-line)))\n(defvar a (input-to-list (read-line)))\n\n(defun submax (lst)\n (labels ((inner (lst candidate)\n (if (cdr lst)\n (inner (cdr lst)\n (let ((challenger (- (cadr lst) (car lst))))\n (if (< candidate challenger)\n challenger\n candidate)))\n candidate)))\n (max (inner lst 0)\n (- (+ (car kn) (car a))\n (nth (1- (cadr kn)) a)))))\n\n(princ (- k (submax a)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere is a circular pond with a perimeter of K meters, and N houses around them.\n\nThe i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.\n\nWhen traveling between these houses, you can only go around the pond.\n\nFind the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.\n\nConstraints\n\n2 \\leq K \\leq 10^6\n\n2 \\leq N \\leq 2 \\times 10^5\n\n0 \\leq A_1 < ... < A_N < K\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK N\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.\n\nSample Input 1\n\n20 3\n5 10 15\n\nSample Output 1\n\n10\n\nIf you start at the 1-st house and go to the 2-nd and 3-rd houses in this order, the total distance traveled will be 10.\n\nSample Input 2\n\n20 3\n0 5 15\n\nSample Output 2\n\n10\n\nIf you start at the 2-nd house and go to the 1-st and 3-rd houses in this order, the total distance traveled will be 10.", "sample_input": "20 3\n5 10 15\n"}, "reference_outputs": ["10\n"], "source_document_id": "p02725", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere is a circular pond with a perimeter of K meters, and N houses around them.\n\nThe i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.\n\nWhen traveling between these houses, you can only go around the pond.\n\nFind the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.\n\nConstraints\n\n2 \\leq K \\leq 10^6\n\n2 \\leq N \\leq 2 \\times 10^5\n\n0 \\leq A_1 < ... < A_N < K\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK N\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.\n\nSample Input 1\n\n20 3\n5 10 15\n\nSample Output 1\n\n10\n\nIf you start at the 1-st house and go to the 2-nd and 3-rd houses in this order, the total distance traveled will be 10.\n\nSample Input 2\n\n20 3\n0 5 15\n\nSample Output 2\n\n10\n\nIf you start at the 2-nd house and go to the 1-st and 3-rd houses in this order, the total distance traveled will be 10.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1222, "cpu_time_ms": 2106, "memory_kb": 98568}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s820472296", "group_id": "codeNet:p02725", "input_text": "(let* ((n (read))\n (m (read))\n (lst (let* ((ll (loop :repeat m :collect (read))))\n (concatenate 'list ll (list (+ (car (last ll)) (car ll) (- n (car (last ll))))))))\n (lst-d (mapcar #'- (cdr lst) lst)))\n (princ (- n (reduce #'max lst-d))))", "language": "Lisp", "metadata": {"date": 1585444394, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02725.html", "problem_id": "p02725", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02725/input.txt", "sample_output_relpath": "derived/input_output/data/p02725/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02725/Lisp/s820472296.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s820472296", "user_id": "u610490393"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (lst (let* ((ll (loop :repeat m :collect (read))))\n (concatenate 'list ll (list (+ (car (last ll)) (car ll) (- n (car (last ll))))))))\n (lst-d (mapcar #'- (cdr lst) lst)))\n (princ (- n (reduce #'max lst-d))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere is a circular pond with a perimeter of K meters, and N houses around them.\n\nThe i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.\n\nWhen traveling between these houses, you can only go around the pond.\n\nFind the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.\n\nConstraints\n\n2 \\leq K \\leq 10^6\n\n2 \\leq N \\leq 2 \\times 10^5\n\n0 \\leq A_1 < ... < A_N < K\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK N\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.\n\nSample Input 1\n\n20 3\n5 10 15\n\nSample Output 1\n\n10\n\nIf you start at the 1-st house and go to the 2-nd and 3-rd houses in this order, the total distance traveled will be 10.\n\nSample Input 2\n\n20 3\n0 5 15\n\nSample Output 2\n\n10\n\nIf you start at the 2-nd house and go to the 1-st and 3-rd houses in this order, the total distance traveled will be 10.", "sample_input": "20 3\n5 10 15\n"}, "reference_outputs": ["10\n"], "source_document_id": "p02725", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere is a circular pond with a perimeter of K meters, and N houses around them.\n\nThe i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.\n\nWhen traveling between these houses, you can only go around the pond.\n\nFind the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.\n\nConstraints\n\n2 \\leq K \\leq 10^6\n\n2 \\leq N \\leq 2 \\times 10^5\n\n0 \\leq A_1 < ... < A_N < K\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK N\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.\n\nSample Input 1\n\n20 3\n5 10 15\n\nSample Output 1\n\n10\n\nIf you start at the 1-st house and go to the 2-nd and 3-rd houses in this order, the total distance traveled will be 10.\n\nSample Input 2\n\n20 3\n0 5 15\n\nSample Output 2\n\n10\n\nIf you start at the 2-nd house and go to the 1-st and 3-rd houses in this order, the total distance traveled will be 10.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 271, "cpu_time_ms": 553, "memory_kb": 69220}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s671615898", "group_id": "codeNet:p02726", "input_text": "(let* ((n (read))\n (x (read))\n (y (read))\n (ans (make-array (list n))))\n (loop :for i :from 1 :to (1- n)\n :do (loop :for j :from (1+ i) :to n\n :do (let ((d (min (+ (min (abs (- i x)) (abs (- i y)))\n (min (abs (- j x)) (abs (- j y)))\n 1)\n (- j i))))\n (incf (aref ans d)))))\n (loop :for d :from 1 :to (1- n)\n :do (format t \"~A~%\" (aref ans d))))\n", "language": "Lisp", "metadata": {"date": 1599686679, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02726.html", "problem_id": "p02726", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02726/input.txt", "sample_output_relpath": "derived/input_output/data/p02726/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02726/Lisp/s671615898.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s671615898", "user_id": "u608227593"}, "prompt_components": {"gold_output": "5\n4\n1\n0\n", "input_to_evaluate": "(let* ((n (read))\n (x (read))\n (y (read))\n (ans (make-array (list n))))\n (loop :for i :from 1 :to (1- n)\n :do (loop :for j :from (1+ i) :to n\n :do (let ((d (min (+ (min (abs (- i x)) (abs (- i y)))\n (min (abs (- j x)) (abs (- j y)))\n 1)\n (- j i))))\n (incf (aref ans d)))))\n (loop :for d :from 1 :to (1- n)\n :do (format t \"~A~%\" (aref ans d))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have an undirected graph G with N vertices numbered 1 to N and N edges as follows:\n\nFor each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.\n\nThere is an edge between Vertex X and Vertex Y.\n\nFor each k=1,2,...,N-1, solve the problem below:\n\nFind the number of pairs of integers (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j in G is k.\n\nConstraints\n\n3 \\leq N \\leq 2 \\times 10^3\n\n1 \\leq X,Y \\leq N\n\nX+1 < Y\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X Y\n\nOutput\n\nFor each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.\n\nSample Input 1\n\n5 2 4\n\nSample Output 1\n\n5\n4\n1\n0\n\nThe graph in this input is as follows:\n\nThere are five pairs (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j is 1: (1,2)\\,,(2,3)\\,,(2,4)\\,,(3,4)\\,,(4,5).\n\nThere are four pairs (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j is 2: (1,3)\\,,(1,4)\\,,(2,5)\\,,(3,5).\n\nThere is one pair (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j is 3: (1,5).\n\nThere are no pairs (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j is 4.\n\nSample Input 2\n\n3 1 3\n\nSample Output 2\n\n3\n0\n\nThe graph in this input is as follows:\n\nSample Input 3\n\n7 3 7\n\nSample Output 3\n\n7\n8\n4\n2\n0\n0\n\nSample Input 4\n\n10 4 8\n\nSample Output 4\n\n10\n12\n10\n8\n4\n1\n0\n0\n0", "sample_input": "5 2 4\n"}, "reference_outputs": ["5\n4\n1\n0\n"], "source_document_id": "p02726", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have an undirected graph G with N vertices numbered 1 to N and N edges as follows:\n\nFor each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.\n\nThere is an edge between Vertex X and Vertex Y.\n\nFor each k=1,2,...,N-1, solve the problem below:\n\nFind the number of pairs of integers (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j in G is k.\n\nConstraints\n\n3 \\leq N \\leq 2 \\times 10^3\n\n1 \\leq X,Y \\leq N\n\nX+1 < Y\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X Y\n\nOutput\n\nFor each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.\n\nSample Input 1\n\n5 2 4\n\nSample Output 1\n\n5\n4\n1\n0\n\nThe graph in this input is as follows:\n\nThere are five pairs (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j is 1: (1,2)\\,,(2,3)\\,,(2,4)\\,,(3,4)\\,,(4,5).\n\nThere are four pairs (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j is 2: (1,3)\\,,(1,4)\\,,(2,5)\\,,(3,5).\n\nThere is one pair (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j is 3: (1,5).\n\nThere are no pairs (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j is 4.\n\nSample Input 2\n\n3 1 3\n\nSample Output 2\n\n3\n0\n\nThe graph in this input is as follows:\n\nSample Input 3\n\n7 3 7\n\nSample Output 3\n\n7\n8\n4\n2\n0\n0\n\nSample Input 4\n\n10 4 8\n\nSample Output 4\n\n10\n12\n10\n8\n4\n1\n0\n0\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 529, "cpu_time_ms": 84, "memory_kb": 24520}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s617494771", "group_id": "codeNet:p02726", "input_text": "(let* ((n (read))\n (m (cons (read) (read)))\n (ans (make-array (1- n) :element-type 'fixnum :initial-element 0)))\n (loop :for to :from 2 :upto n\n :do(loop :for fr :from 1 :upto (1- to)\n :do (incf (aref ans\n (1- (min (- to fr)\n (+ (abs (- (car m) fr)) 1 (abs (- (cdr m) to)))))))))\n (loop :for k :across ans\n :do(format t \"~A~%\" k)))", "language": "Lisp", "metadata": {"date": 1591098120, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02726.html", "problem_id": "p02726", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02726/input.txt", "sample_output_relpath": "derived/input_output/data/p02726/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02726/Lisp/s617494771.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s617494771", "user_id": "u610490393"}, "prompt_components": {"gold_output": "5\n4\n1\n0\n", "input_to_evaluate": "(let* ((n (read))\n (m (cons (read) (read)))\n (ans (make-array (1- n) :element-type 'fixnum :initial-element 0)))\n (loop :for to :from 2 :upto n\n :do(loop :for fr :from 1 :upto (1- to)\n :do (incf (aref ans\n (1- (min (- to fr)\n (+ (abs (- (car m) fr)) 1 (abs (- (cdr m) to)))))))))\n (loop :for k :across ans\n :do(format t \"~A~%\" k)))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have an undirected graph G with N vertices numbered 1 to N and N edges as follows:\n\nFor each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.\n\nThere is an edge between Vertex X and Vertex Y.\n\nFor each k=1,2,...,N-1, solve the problem below:\n\nFind the number of pairs of integers (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j in G is k.\n\nConstraints\n\n3 \\leq N \\leq 2 \\times 10^3\n\n1 \\leq X,Y \\leq N\n\nX+1 < Y\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X Y\n\nOutput\n\nFor each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.\n\nSample Input 1\n\n5 2 4\n\nSample Output 1\n\n5\n4\n1\n0\n\nThe graph in this input is as follows:\n\nThere are five pairs (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j is 1: (1,2)\\,,(2,3)\\,,(2,4)\\,,(3,4)\\,,(4,5).\n\nThere are four pairs (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j is 2: (1,3)\\,,(1,4)\\,,(2,5)\\,,(3,5).\n\nThere is one pair (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j is 3: (1,5).\n\nThere are no pairs (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j is 4.\n\nSample Input 2\n\n3 1 3\n\nSample Output 2\n\n3\n0\n\nThe graph in this input is as follows:\n\nSample Input 3\n\n7 3 7\n\nSample Output 3\n\n7\n8\n4\n2\n0\n0\n\nSample Input 4\n\n10 4 8\n\nSample Output 4\n\n10\n12\n10\n8\n4\n1\n0\n0\n0", "sample_input": "5 2 4\n"}, "reference_outputs": ["5\n4\n1\n0\n"], "source_document_id": "p02726", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have an undirected graph G with N vertices numbered 1 to N and N edges as follows:\n\nFor each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.\n\nThere is an edge between Vertex X and Vertex Y.\n\nFor each k=1,2,...,N-1, solve the problem below:\n\nFind the number of pairs of integers (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j in G is k.\n\nConstraints\n\n3 \\leq N \\leq 2 \\times 10^3\n\n1 \\leq X,Y \\leq N\n\nX+1 < Y\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X Y\n\nOutput\n\nFor each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.\n\nSample Input 1\n\n5 2 4\n\nSample Output 1\n\n5\n4\n1\n0\n\nThe graph in this input is as follows:\n\nThere are five pairs (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j is 1: (1,2)\\,,(2,3)\\,,(2,4)\\,,(3,4)\\,,(4,5).\n\nThere are four pairs (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j is 2: (1,3)\\,,(1,4)\\,,(2,5)\\,,(3,5).\n\nThere is one pair (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j is 3: (1,5).\n\nThere are no pairs (i,j) (1 \\leq i < j \\leq N) such that the shortest distance between Vertex i and Vertex j is 4.\n\nSample Input 2\n\n3 1 3\n\nSample Output 2\n\n3\n0\n\nThe graph in this input is as follows:\n\nSample Input 3\n\n7 3 7\n\nSample Output 3\n\n7\n8\n4\n2\n0\n0\n\nSample Input 4\n\n10 4 8\n\nSample Output 4\n\n10\n12\n10\n8\n4\n1\n0\n0\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 448, "cpu_time_ms": 147, "memory_kb": 17380}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s423872686", "group_id": "codeNet:p02728", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\n\n;; TODO: non-global handling\n\n(defconstant +binom-size+ 510000)\n(defconstant +binom-mod+ #.(+ (expt 10 9) 7))\n\n(declaim ((simple-array (unsigned-byte 32) (*)) *fact* *fact-inv* *inv*))\n(defparameter *fact* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of factorials\")\n(defparameter *fact-inv* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of inverses of factorials\")\n(defparameter *inv* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of inverses of non-negative integers\")\n\n(defun initialize-binom ()\n (declare (optimize (speed 3) (safety 0)))\n (setf (aref *fact* 0) 1\n (aref *fact* 1) 1\n (aref *fact-inv* 0) 1\n (aref *fact-inv* 1) 1\n (aref *inv* 1) 1)\n (loop for i from 2 below +binom-size+\n do (setf (aref *fact* i) (mod (* i (aref *fact* (- i 1))) +binom-mod+)\n (aref *inv* i) (- +binom-mod+\n (mod (* (aref *inv* (rem +binom-mod+ i))\n (floor +binom-mod+ i))\n +binom-mod+))\n (aref *fact-inv* i) (mod (* (aref *inv* i)\n (aref *fact-inv* (- i 1)))\n +binom-mod+))))\n\n(initialize-binom)\n\n(declaim (inline binom))\n(defun binom (n k)\n \"Returns nCk.\"\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (mod (* (aref *fact* n)\n (mod (* (aref *fact-inv* k) (aref *fact-inv* (- n k))) +binom-mod+))\n +binom-mod+)))\n\n(declaim (inline perm))\n(defun perm (n k)\n \"Returns nPk.\"\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (mod (* (aref *fact* n) (aref *fact-inv* (- n k))) +binom-mod+)))\n\n;; TODO: compiler macro or source-transform\n(declaim (inline multinomial))\n(defun multinomial (&rest ks)\n \"Returns the multinomial coefficient K!/k_1!k_2!...k_n! for K = k_1 + k_2 +\n... + k_n. K must be equal to or smaller than\nMOST-POSITIVE-FIXNUM. (multinomial) returns 1.\"\n (let ((sum 0)\n (result 1))\n (declare ((integer 0 #.most-positive-fixnum) result sum))\n (dolist (k ks)\n (incf sum k)\n (setq result\n (mod (* result (aref *fact-inv* k)) +binom-mod+)))\n (mod (* result (aref *fact* sum)) +binom-mod+)))\n\n;;;\n;;; Memoization macro\n;;;\n\n;;\n;; Basic usage:\n;;\n;; (with-cache (:hash-table :test #'equal :key #'cons)\n;; (defun add (a b)\n;; (+ a b)))\n;; This function caches the returned values for already passed combinations of\n;; arguments. In this case ADD stores the key (CONS A B) and the returned value\n;; to a hash-table when (ADD A B) is evaluated for the first time. ADD returns\n;; the stored value when it is called with the same arguments (w.r.t. EQUAL)\n;; again.\n;;\n;; The storage for cache can be hash-table or array. Let's see an example for\n;; array:\n;; (with-cache (:array (10 20 30) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c) ... ))\n;; This form stores the value of FOO in an array created by (make-array (list 10\n;; 20 30) :initial-element -1 :element-type 'fixnum). Note that INITIAL-ELEMENT\n;; must always be given here as it is used as the flag expressing `not yet\n;; stored'. (Therefore INITIAL-ELEMENT should be a value FOO never takes.)\n;;\n;; If you want to ignore some arguments, you can put `*' in dimensions:\n;; (with-cache (:array (10 10 * 10) :initial-element -1)\n;; (defun foo (a b c d) ...)) ; then C is ignored when querying or storing cache\n;;\n;; Available definition forms in WITH-CACHE are DEFUN, LABELS, FLET, and\n;; SB-INT:NAMED-LET.\n;;\n;; You can trace the memoized function by :TRACE option:\n;; (with-cache (:array (10 10) :initial-element -1 :trace t)\n;; (defun foo (x y) ...))\n;; Then FOO is traced as with CL:TRACE.\n;;\n\n;; TODO & NOTE: Currently a memoized function is not enclosed with a block of\n;; the function name.\n\n;; FIXME: *RECURSION-DEPTH* should be included within the macro.\n(declaim (type (integer 0 #.most-positive-fixnum) *recursion-depth*))\n(defparameter *recursion-depth* 0)\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun %enclose-with-trace (fname args form)\n (let ((value (gensym)))\n `(progn\n (format t \"~&~A~A: (~A ~{~A~^ ~}) =>\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args))\n (let ((,value (let ((*recursion-depth* (1+ *recursion-depth*)))\n ,form)))\n (format t \"~&~A~A: (~A ~{~A~^ ~}) => ~A\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args)\n ,value)\n ,value))))\n\n (defun %extract-declarations (body)\n (remove-if-not (lambda (form) (and (consp form) (eql 'declare (car form))))\n body))\n\n (defun %parse-cache-form (cache-specifier)\n (let ((cache-type (car cache-specifier))\n (cache-attribs (cdr cache-specifier)))\n (assert (member cache-type '(:hash-table :array)))\n (let* ((dims-with-* (when (eql cache-type :array) (first cache-attribs)))\n (dims (remove '* dims-with-*))\n (rank (length dims))\n (rest-attribs (ecase cache-type\n (:hash-table cache-attribs)\n (:array (cdr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (trace-p (prog1 (getf rest-attribs :trace) (remf rest-attribs :trace)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array (list ,@dims) ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym \"CACHE\"))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels\n ((make-cache-querier (cache-type name args)\n (let ((res (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key '#'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (assert (= (length args) (length dims-with-*)))\n (let ((memoized-args (loop for dimension in dims-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value))))))))\n (if trace-p\n (%enclose-with-trace name args res)\n res)))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n ;; TODO: portable fill\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name)))))\n (values cache cache-form cache-type name-alias\n #'make-reset-name\n #'make-reset-form\n #'make-cache-querier)))))))\n\n(defmacro with-cache ((cache-type &rest cache-attribs) def-form)\n \"CACHE-TYPE := :HASH-TABLE | :ARRAY.\nDEF-FORM := definition form with DEFUN, LABELS, FLET, or SB-INT:NAMED-LET.\"\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form\n make-cache-querier)\n (%parse-cache-form (cons cache-type cache-attribs))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (defun ,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (defun ,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form)\n ((,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args)))\n ,@(cdr definitions))\n (declare (ignorable #',(funcall make-reset-name name)))\n ,@labels-body)))))\n ((nlet #+sbcl sb-int:named-let)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form) ,name ,bindings\n ,@(%extract-declarations body)\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))))))\n\n(defmacro with-caches (cache-specs def-form)\n \"DEF-FORM := definition form by LABELS or FLET.\n\n (with-caches (cache-spec1 cache-spec2)\n (labels ((f (x) ...) (g (y) ...))))\nis equivalent to the line up of\n (with-cache cache-spec1 (labels ((f (x) ...))))\nand\n (with-cache cache-spec2 (labels ((g (y) ...))))\n\nThis macro will be useful to do mutual recursion between memoized local\nfunctions.\"\n (assert (member (car def-form) '(labels flet)))\n (let (cache-symbol-list cache-form-list cache-type-list name-alias-list make-reset-name-list make-reset-form-list make-cache-querier-list)\n (dolist (cache-spec (reverse cache-specs))\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form make-cache-querier)\n (%parse-cache-form cache-spec)\n (push cache-symbol cache-symbol-list)\n (push cache-form cache-form-list)\n (push cache-type cache-type-list)\n (push name-alias name-alias-list)\n (push make-reset-name make-reset-name-list)\n (push make-reset-form make-reset-form-list)\n (push make-cache-querier make-cache-querier-list)))\n (labels ((def-name (def) (first def))\n (def-args (def) (second def))\n (def-body (def) (cddr def)))\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n `(let ,(loop for cache-symbol in cache-symbol-list\n for cache-form in cache-form-list\n collect `(,cache-symbol ,cache-form))\n (,(car def-form)\n (,@(loop for def in definitions\n for cache-type in cache-type-list\n for make-reset-name in make-reset-name-list\n for make-reset-form in make-reset-form-list\n collect `(,(funcall make-reset-name (def-name def)) ()\n ,(funcall make-reset-form cache-type)))\n ,@(loop for def in definitions\n for cache-type in cache-type-list\n for name-alias in name-alias-list\n for make-cache-querier in make-cache-querier-list\n collect `(,(def-name def) ,(def-args def)\n ,@(%extract-declarations (def-body def))\n (labels ((,name-alias ,(def-args def) ,@(def-body def)))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type (def-name def) (def-args def))))))\n (declare (ignorable ,@(loop for def in definitions\n for make-reset-name in make-reset-name-list\n collect `#',(funcall make-reset-name\n (def-name def)))))\n ,@labels-body))))))\n\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (sizes (make-array n :element-type 'uint32 :initial-element 0))\n (res (make-array n :element-type 'uint32 :initial-element 0)))\n (declare (uint31 n))\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (sb-int:named-let dfs ((v 0) (parent -1))\n (let ((res 1))\n (declare (uint32 res))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (incf res (dfs child v))))\n (setf (aref sizes v) res)))\n (with-cache (:hash-table :size (* 3 n)\n :test #'equal\n :key #'cons)\n (labels ((subtree-number (parent top)\n (declare (uint32 parent top)\n (values uint31 &optional))\n (dbg parent top)\n (let ((res 1)\n (sum 0))\n (declare (uint31 res sum))\n (dolist (neighbor (aref graph top))\n (declare (uint32 neighbor))\n (unless (= neighbor parent)\n (setq res (mod* res (subtree-number top neighbor)))\n (let ((size (aref sizes neighbor)))\n (setq res (mod* res (aref *fact-inv* size)))\n (incf sum size))))\n (mod* res (aref *fact* sum)))))\n (sb-int:named-let dfs ((v 0) (parent -1))\n (setf (aref res v) (subtree-number n v))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (let* ((total (aref sizes v))\n (total-child (- total (aref sizes child))))\n (incf (aref sizes child) total-child)\n (setf (aref sizes v) total-child)\n (dfs child v)\n (setf (aref sizes v) total)\n (decf (aref sizes child) total-child)))))\n (with-buffered-stdout\n (loop for x across res\n do (println x)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2\n1 3\n\"\n \"2\n1\n1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 2\n\"\n \"1\n1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n1 2\n2 3\n3 4\n3 5\n\"\n \"2\n8\n12\n3\n3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n1 2\n2 3\n3 4\n3 5\n3 6\n6 7\n6 8\n\"\n \"40\n280\n840\n120\n120\n504\n72\n72\n\")))\n", "language": "Lisp", "metadata": {"date": 1585448817, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02728.html", "problem_id": "p02728", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02728/input.txt", "sample_output_relpath": "derived/input_output/data/p02728/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02728/Lisp/s423872686.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s423872686", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n1\n1\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\n\n;; TODO: non-global handling\n\n(defconstant +binom-size+ 510000)\n(defconstant +binom-mod+ #.(+ (expt 10 9) 7))\n\n(declaim ((simple-array (unsigned-byte 32) (*)) *fact* *fact-inv* *inv*))\n(defparameter *fact* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of factorials\")\n(defparameter *fact-inv* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of inverses of factorials\")\n(defparameter *inv* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of inverses of non-negative integers\")\n\n(defun initialize-binom ()\n (declare (optimize (speed 3) (safety 0)))\n (setf (aref *fact* 0) 1\n (aref *fact* 1) 1\n (aref *fact-inv* 0) 1\n (aref *fact-inv* 1) 1\n (aref *inv* 1) 1)\n (loop for i from 2 below +binom-size+\n do (setf (aref *fact* i) (mod (* i (aref *fact* (- i 1))) +binom-mod+)\n (aref *inv* i) (- +binom-mod+\n (mod (* (aref *inv* (rem +binom-mod+ i))\n (floor +binom-mod+ i))\n +binom-mod+))\n (aref *fact-inv* i) (mod (* (aref *inv* i)\n (aref *fact-inv* (- i 1)))\n +binom-mod+))))\n\n(initialize-binom)\n\n(declaim (inline binom))\n(defun binom (n k)\n \"Returns nCk.\"\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (mod (* (aref *fact* n)\n (mod (* (aref *fact-inv* k) (aref *fact-inv* (- n k))) +binom-mod+))\n +binom-mod+)))\n\n(declaim (inline perm))\n(defun perm (n k)\n \"Returns nPk.\"\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (mod (* (aref *fact* n) (aref *fact-inv* (- n k))) +binom-mod+)))\n\n;; TODO: compiler macro or source-transform\n(declaim (inline multinomial))\n(defun multinomial (&rest ks)\n \"Returns the multinomial coefficient K!/k_1!k_2!...k_n! for K = k_1 + k_2 +\n... + k_n. K must be equal to or smaller than\nMOST-POSITIVE-FIXNUM. (multinomial) returns 1.\"\n (let ((sum 0)\n (result 1))\n (declare ((integer 0 #.most-positive-fixnum) result sum))\n (dolist (k ks)\n (incf sum k)\n (setq result\n (mod (* result (aref *fact-inv* k)) +binom-mod+)))\n (mod (* result (aref *fact* sum)) +binom-mod+)))\n\n;;;\n;;; Memoization macro\n;;;\n\n;;\n;; Basic usage:\n;;\n;; (with-cache (:hash-table :test #'equal :key #'cons)\n;; (defun add (a b)\n;; (+ a b)))\n;; This function caches the returned values for already passed combinations of\n;; arguments. In this case ADD stores the key (CONS A B) and the returned value\n;; to a hash-table when (ADD A B) is evaluated for the first time. ADD returns\n;; the stored value when it is called with the same arguments (w.r.t. EQUAL)\n;; again.\n;;\n;; The storage for cache can be hash-table or array. Let's see an example for\n;; array:\n;; (with-cache (:array (10 20 30) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c) ... ))\n;; This form stores the value of FOO in an array created by (make-array (list 10\n;; 20 30) :initial-element -1 :element-type 'fixnum). Note that INITIAL-ELEMENT\n;; must always be given here as it is used as the flag expressing `not yet\n;; stored'. (Therefore INITIAL-ELEMENT should be a value FOO never takes.)\n;;\n;; If you want to ignore some arguments, you can put `*' in dimensions:\n;; (with-cache (:array (10 10 * 10) :initial-element -1)\n;; (defun foo (a b c d) ...)) ; then C is ignored when querying or storing cache\n;;\n;; Available definition forms in WITH-CACHE are DEFUN, LABELS, FLET, and\n;; SB-INT:NAMED-LET.\n;;\n;; You can trace the memoized function by :TRACE option:\n;; (with-cache (:array (10 10) :initial-element -1 :trace t)\n;; (defun foo (x y) ...))\n;; Then FOO is traced as with CL:TRACE.\n;;\n\n;; TODO & NOTE: Currently a memoized function is not enclosed with a block of\n;; the function name.\n\n;; FIXME: *RECURSION-DEPTH* should be included within the macro.\n(declaim (type (integer 0 #.most-positive-fixnum) *recursion-depth*))\n(defparameter *recursion-depth* 0)\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun %enclose-with-trace (fname args form)\n (let ((value (gensym)))\n `(progn\n (format t \"~&~A~A: (~A ~{~A~^ ~}) =>\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args))\n (let ((,value (let ((*recursion-depth* (1+ *recursion-depth*)))\n ,form)))\n (format t \"~&~A~A: (~A ~{~A~^ ~}) => ~A\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args)\n ,value)\n ,value))))\n\n (defun %extract-declarations (body)\n (remove-if-not (lambda (form) (and (consp form) (eql 'declare (car form))))\n body))\n\n (defun %parse-cache-form (cache-specifier)\n (let ((cache-type (car cache-specifier))\n (cache-attribs (cdr cache-specifier)))\n (assert (member cache-type '(:hash-table :array)))\n (let* ((dims-with-* (when (eql cache-type :array) (first cache-attribs)))\n (dims (remove '* dims-with-*))\n (rank (length dims))\n (rest-attribs (ecase cache-type\n (:hash-table cache-attribs)\n (:array (cdr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (trace-p (prog1 (getf rest-attribs :trace) (remf rest-attribs :trace)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array (list ,@dims) ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym \"CACHE\"))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels\n ((make-cache-querier (cache-type name args)\n (let ((res (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key '#'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (assert (= (length args) (length dims-with-*)))\n (let ((memoized-args (loop for dimension in dims-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value))))))))\n (if trace-p\n (%enclose-with-trace name args res)\n res)))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n ;; TODO: portable fill\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name)))))\n (values cache cache-form cache-type name-alias\n #'make-reset-name\n #'make-reset-form\n #'make-cache-querier)))))))\n\n(defmacro with-cache ((cache-type &rest cache-attribs) def-form)\n \"CACHE-TYPE := :HASH-TABLE | :ARRAY.\nDEF-FORM := definition form with DEFUN, LABELS, FLET, or SB-INT:NAMED-LET.\"\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form\n make-cache-querier)\n (%parse-cache-form (cons cache-type cache-attribs))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (defun ,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (defun ,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form)\n ((,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args)))\n ,@(cdr definitions))\n (declare (ignorable #',(funcall make-reset-name name)))\n ,@labels-body)))))\n ((nlet #+sbcl sb-int:named-let)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form) ,name ,bindings\n ,@(%extract-declarations body)\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))))))\n\n(defmacro with-caches (cache-specs def-form)\n \"DEF-FORM := definition form by LABELS or FLET.\n\n (with-caches (cache-spec1 cache-spec2)\n (labels ((f (x) ...) (g (y) ...))))\nis equivalent to the line up of\n (with-cache cache-spec1 (labels ((f (x) ...))))\nand\n (with-cache cache-spec2 (labels ((g (y) ...))))\n\nThis macro will be useful to do mutual recursion between memoized local\nfunctions.\"\n (assert (member (car def-form) '(labels flet)))\n (let (cache-symbol-list cache-form-list cache-type-list name-alias-list make-reset-name-list make-reset-form-list make-cache-querier-list)\n (dolist (cache-spec (reverse cache-specs))\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form make-cache-querier)\n (%parse-cache-form cache-spec)\n (push cache-symbol cache-symbol-list)\n (push cache-form cache-form-list)\n (push cache-type cache-type-list)\n (push name-alias name-alias-list)\n (push make-reset-name make-reset-name-list)\n (push make-reset-form make-reset-form-list)\n (push make-cache-querier make-cache-querier-list)))\n (labels ((def-name (def) (first def))\n (def-args (def) (second def))\n (def-body (def) (cddr def)))\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n `(let ,(loop for cache-symbol in cache-symbol-list\n for cache-form in cache-form-list\n collect `(,cache-symbol ,cache-form))\n (,(car def-form)\n (,@(loop for def in definitions\n for cache-type in cache-type-list\n for make-reset-name in make-reset-name-list\n for make-reset-form in make-reset-form-list\n collect `(,(funcall make-reset-name (def-name def)) ()\n ,(funcall make-reset-form cache-type)))\n ,@(loop for def in definitions\n for cache-type in cache-type-list\n for name-alias in name-alias-list\n for make-cache-querier in make-cache-querier-list\n collect `(,(def-name def) ,(def-args def)\n ,@(%extract-declarations (def-body def))\n (labels ((,name-alias ,(def-args def) ,@(def-body def)))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type (def-name def) (def-args def))))))\n (declare (ignorable ,@(loop for def in definitions\n for make-reset-name in make-reset-name-list\n collect `#',(funcall make-reset-name\n (def-name def)))))\n ,@labels-body))))))\n\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (sizes (make-array n :element-type 'uint32 :initial-element 0))\n (res (make-array n :element-type 'uint32 :initial-element 0)))\n (declare (uint31 n))\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (sb-int:named-let dfs ((v 0) (parent -1))\n (let ((res 1))\n (declare (uint32 res))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (incf res (dfs child v))))\n (setf (aref sizes v) res)))\n (with-cache (:hash-table :size (* 3 n)\n :test #'equal\n :key #'cons)\n (labels ((subtree-number (parent top)\n (declare (uint32 parent top)\n (values uint31 &optional))\n (dbg parent top)\n (let ((res 1)\n (sum 0))\n (declare (uint31 res sum))\n (dolist (neighbor (aref graph top))\n (declare (uint32 neighbor))\n (unless (= neighbor parent)\n (setq res (mod* res (subtree-number top neighbor)))\n (let ((size (aref sizes neighbor)))\n (setq res (mod* res (aref *fact-inv* size)))\n (incf sum size))))\n (mod* res (aref *fact* sum)))))\n (sb-int:named-let dfs ((v 0) (parent -1))\n (setf (aref res v) (subtree-number n v))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (let* ((total (aref sizes v))\n (total-child (- total (aref sizes child))))\n (incf (aref sizes child) total-child)\n (setf (aref sizes v) total-child)\n (dfs child v)\n (setf (aref sizes v) total)\n (decf (aref sizes child) total-child)))))\n (with-buffered-stdout\n (loop for x across res\n do (println x)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2\n1 3\n\"\n \"2\n1\n1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 2\n\"\n \"1\n1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n1 2\n2 3\n3 4\n3 5\n\"\n \"2\n8\n12\n3\n3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n1 2\n2 3\n3 4\n3 5\n3 6\n6 7\n6 8\n\"\n \"40\n280\n840\n120\n120\n504\n72\n72\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nWe have a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and b_i.\nFor each k=1, ..., N, solve the problem below:\n\nConsider writing a number on each vertex in the tree in the following manner:\n\nFirst, write 1 on Vertex k.\n\nThen, for each of the numbers 2, ..., N in this order, write the number on the vertex chosen as follows:\n\nChoose a vertex that still does not have a number written on it and is adjacent to a vertex with a number already written on it. If there are multiple such vertices, choose one of them at random.\n\nFind the number of ways in which we can write the numbers on the vertices, modulo (10^9+7).\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq a_i,b_i \\leq N\n\nThe given graph is a tree.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 b_1\n:\na_{N-1} b_{N-1}\n\nOutput\n\nFor each k=1, 2, ..., N in this order, print a line containing the answer to the problem.\n\nSample Input 1\n\n3\n1 2\n1 3\n\nSample Output 1\n\n2\n1\n1\n\nThe graph in this input is as follows:\n\nFor k=1, there are two ways in which we can write the numbers on the vertices, as follows:\n\nWriting 1, 2, 3 on Vertex 1, 2, 3, respectively\n\nWriting 1, 3, 2 on Vertex 1, 2, 3, respectively\n\nSample Input 2\n\n2\n1 2\n\nSample Output 2\n\n1\n1\n\nThe graph in this input is as follows:\n\nSample Input 3\n\n5\n1 2\n2 3\n3 4\n3 5\n\nSample Output 3\n\n2\n8\n12\n3\n3\n\nThe graph in this input is as follows:\n\nSample Input 4\n\n8\n1 2\n2 3\n3 4\n3 5\n3 6\n6 7\n6 8\n\nSample Output 4\n\n40\n280\n840\n120\n120\n504\n72\n72\n\nThe graph in this input is as follows:", "sample_input": "3\n1 2\n1 3\n"}, "reference_outputs": ["2\n1\n1\n"], "source_document_id": "p02728", "source_text": "Score : 600 points\n\nProblem Statement\n\nWe have a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and b_i.\nFor each k=1, ..., N, solve the problem below:\n\nConsider writing a number on each vertex in the tree in the following manner:\n\nFirst, write 1 on Vertex k.\n\nThen, for each of the numbers 2, ..., N in this order, write the number on the vertex chosen as follows:\n\nChoose a vertex that still does not have a number written on it and is adjacent to a vertex with a number already written on it. If there are multiple such vertices, choose one of them at random.\n\nFind the number of ways in which we can write the numbers on the vertices, modulo (10^9+7).\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq a_i,b_i \\leq N\n\nThe given graph is a tree.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 b_1\n:\na_{N-1} b_{N-1}\n\nOutput\n\nFor each k=1, 2, ..., N in this order, print a line containing the answer to the problem.\n\nSample Input 1\n\n3\n1 2\n1 3\n\nSample Output 1\n\n2\n1\n1\n\nThe graph in this input is as follows:\n\nFor k=1, there are two ways in which we can write the numbers on the vertices, as follows:\n\nWriting 1, 2, 3 on Vertex 1, 2, 3, respectively\n\nWriting 1, 3, 2 on Vertex 1, 2, 3, respectively\n\nSample Input 2\n\n2\n1 2\n\nSample Output 2\n\n1\n1\n\nThe graph in this input is as follows:\n\nSample Input 3\n\n5\n1 2\n2 3\n3 4\n3 5\n\nSample Output 3\n\n2\n8\n12\n3\n3\n\nThe graph in this input is as follows:\n\nSample Input 4\n\n8\n1 2\n2 3\n3 4\n3 5\n3 6\n6 7\n6 8\n\nSample Output 4\n\n40\n280\n840\n120\n120\n504\n72\n72\n\nThe graph in this input is as follows:", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 23576, "cpu_time_ms": 3164, "memory_kb": 113848}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s457058362", "group_id": "codeNet:p02731", "input_text": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n\n(defun f(l)\n (let ((ll (/ l 3)))\n (* ll ll ll)))\n(let ((line (parse-integer (read-line nil nil))))\n (format t \"~A~%\" (f line)))\n", "language": "Lisp", "metadata": {"date": 1584928155, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02731.html", "problem_id": "p02731", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02731/input.txt", "sample_output_relpath": "derived/input_output/data/p02731/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02731/Lisp/s457058362.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s457058362", "user_id": "u254205055"}, "prompt_components": {"gold_output": "1.000000000000\n", "input_to_evaluate": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n\n(defun f(l)\n (let ((ll (/ l 3)))\n (* ll ll ll)))\n(let ((line (parse-integer (read-line nil nil))))\n (format t \"~A~%\" (f line)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven is a positive integer L.\nFind the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.\n\nConstraints\n\n1 ≤ L ≤ 1000\n\nL is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL\n\nOutput\n\nPrint the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.\nYour output is considered correct if its absolute or relative error from our answer is at most 10^{-6}.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n1.000000000000\n\nFor example, a rectangular cuboid whose dimensions are 0.8, 1, and 1.2 has a volume of 0.96.\n\nOn the other hand, if the dimensions are 1, 1, and 1, the volume of the rectangular cuboid is 1, which is greater.\n\nSample Input 2\n\n999\n\nSample Output 2\n\n36926037.000000000000", "sample_input": "3\n"}, "reference_outputs": ["1.000000000000\n"], "source_document_id": "p02731", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven is a positive integer L.\nFind the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.\n\nConstraints\n\n1 ≤ L ≤ 1000\n\nL is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL\n\nOutput\n\nPrint the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.\nYour output is considered correct if its absolute or relative error from our answer is at most 10^{-6}.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n1.000000000000\n\nFor example, a rectangular cuboid whose dimensions are 0.8, 1, and 1.2 has a volume of 0.96.\n\nOn the other hand, if the dimensions are 1, 1, and 1, the volume of the rectangular cuboid is 1, which is greater.\n\nSample Input 2\n\n999\n\nSample Output 2\n\n36926037.000000000000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 382, "cpu_time_ms": 125, "memory_kb": 13024}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s004354841", "group_id": "codeNet:p02731", "input_text": "(format t \"~F\" (expt (/ (read) 3) 3))", "language": "Lisp", "metadata": {"date": 1584926426, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02731.html", "problem_id": "p02731", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02731/input.txt", "sample_output_relpath": "derived/input_output/data/p02731/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02731/Lisp/s004354841.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s004354841", "user_id": "u334552723"}, "prompt_components": {"gold_output": "1.000000000000\n", "input_to_evaluate": "(format t \"~F\" (expt (/ (read) 3) 3))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven is a positive integer L.\nFind the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.\n\nConstraints\n\n1 ≤ L ≤ 1000\n\nL is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL\n\nOutput\n\nPrint the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.\nYour output is considered correct if its absolute or relative error from our answer is at most 10^{-6}.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n1.000000000000\n\nFor example, a rectangular cuboid whose dimensions are 0.8, 1, and 1.2 has a volume of 0.96.\n\nOn the other hand, if the dimensions are 1, 1, and 1, the volume of the rectangular cuboid is 1, which is greater.\n\nSample Input 2\n\n999\n\nSample Output 2\n\n36926037.000000000000", "sample_input": "3\n"}, "reference_outputs": ["1.000000000000\n"], "source_document_id": "p02731", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven is a positive integer L.\nFind the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.\n\nConstraints\n\n1 ≤ L ≤ 1000\n\nL is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL\n\nOutput\n\nPrint the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.\nYour output is considered correct if its absolute or relative error from our answer is at most 10^{-6}.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n1.000000000000\n\nFor example, a rectangular cuboid whose dimensions are 0.8, 1, and 1.2 has a volume of 0.96.\n\nOn the other hand, if the dimensions are 1, 1, and 1, the volume of the rectangular cuboid is 1, which is greater.\n\nSample Input 2\n\n999\n\nSample Output 2\n\n36926037.000000000000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 37, "cpu_time_ms": 19, "memory_kb": 3936}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s016628929", "group_id": "codeNet:p02731", "input_text": "(format t \"~,100f\" (coerce (expt (/ (read) 3) 3) 'double-float))", "language": "Lisp", "metadata": {"date": 1584926091, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02731.html", "problem_id": "p02731", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02731/input.txt", "sample_output_relpath": "derived/input_output/data/p02731/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02731/Lisp/s016628929.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s016628929", "user_id": "u610490393"}, "prompt_components": {"gold_output": "1.000000000000\n", "input_to_evaluate": "(format t \"~,100f\" (coerce (expt (/ (read) 3) 3) 'double-float))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven is a positive integer L.\nFind the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.\n\nConstraints\n\n1 ≤ L ≤ 1000\n\nL is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL\n\nOutput\n\nPrint the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.\nYour output is considered correct if its absolute or relative error from our answer is at most 10^{-6}.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n1.000000000000\n\nFor example, a rectangular cuboid whose dimensions are 0.8, 1, and 1.2 has a volume of 0.96.\n\nOn the other hand, if the dimensions are 1, 1, and 1, the volume of the rectangular cuboid is 1, which is greater.\n\nSample Input 2\n\n999\n\nSample Output 2\n\n36926037.000000000000", "sample_input": "3\n"}, "reference_outputs": ["1.000000000000\n"], "source_document_id": "p02731", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven is a positive integer L.\nFind the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.\n\nConstraints\n\n1 ≤ L ≤ 1000\n\nL is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL\n\nOutput\n\nPrint the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.\nYour output is considered correct if its absolute or relative error from our answer is at most 10^{-6}.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n1.000000000000\n\nFor example, a rectangular cuboid whose dimensions are 0.8, 1, and 1.2 has a volume of 0.96.\n\nOn the other hand, if the dimensions are 1, 1, and 1, the volume of the rectangular cuboid is 1, which is greater.\n\nSample Input 2\n\n999\n\nSample Output 2\n\n36926037.000000000000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 64, "cpu_time_ms": 20, "memory_kb": 4072}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s293575422", "group_id": "codeNet:p02731", "input_text": "(princ (coerce (expt (/ (read) 3) 3) 'double-float))", "language": "Lisp", "metadata": {"date": 1584925970, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02731.html", "problem_id": "p02731", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02731/input.txt", "sample_output_relpath": "derived/input_output/data/p02731/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02731/Lisp/s293575422.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s293575422", "user_id": "u610490393"}, "prompt_components": {"gold_output": "1.000000000000\n", "input_to_evaluate": "(princ (coerce (expt (/ (read) 3) 3) 'double-float))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven is a positive integer L.\nFind the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.\n\nConstraints\n\n1 ≤ L ≤ 1000\n\nL is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL\n\nOutput\n\nPrint the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.\nYour output is considered correct if its absolute or relative error from our answer is at most 10^{-6}.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n1.000000000000\n\nFor example, a rectangular cuboid whose dimensions are 0.8, 1, and 1.2 has a volume of 0.96.\n\nOn the other hand, if the dimensions are 1, 1, and 1, the volume of the rectangular cuboid is 1, which is greater.\n\nSample Input 2\n\n999\n\nSample Output 2\n\n36926037.000000000000", "sample_input": "3\n"}, "reference_outputs": ["1.000000000000\n"], "source_document_id": "p02731", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven is a positive integer L.\nFind the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.\n\nConstraints\n\n1 ≤ L ≤ 1000\n\nL is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL\n\nOutput\n\nPrint the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.\nYour output is considered correct if its absolute or relative error from our answer is at most 10^{-6}.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n1.000000000000\n\nFor example, a rectangular cuboid whose dimensions are 0.8, 1, and 1.2 has a volume of 0.96.\n\nOn the other hand, if the dimensions are 1, 1, and 1, the volume of the rectangular cuboid is 1, which is greater.\n\nSample Input 2\n\n999\n\nSample Output 2\n\n36926037.000000000000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 52, "cpu_time_ms": 19, "memory_kb": 3944}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s407539969", "group_id": "codeNet:p02732", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n (dp (make-array (+ n 1) :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum))\n (incf (aref dp (aref as i))))\n (let ((base (loop for val across dp\n sum (ash (* val (- val 1)) -1) of-type uint62)))\n (with-buffered-stdout\n (dotimes (i n)\n (let* ((a (aref as i))\n (num (aref dp a)))\n (println (+ base\n (- (ash (* num (- num 1)) -1))\n (ash (* (- num 1) (- num 2)) -1)))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n1 1 2 1 2\n\"\n \"2\n2\n3\n2\n3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 2 3 4\n\"\n \"0\n0\n0\n0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n3 3 3 3 3\n\"\n \"6\n6\n6\n6\n6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n1 2 1 4 2 1 4 1\n\"\n \"5\n7\n5\n7\n7\n5\n7\n5\n\")))\n", "language": "Lisp", "metadata": {"date": 1584933547, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02732.html", "problem_id": "p02732", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02732/input.txt", "sample_output_relpath": "derived/input_output/data/p02732/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02732/Lisp/s407539969.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s407539969", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n2\n3\n2\n3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n (dp (make-array (+ n 1) :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum))\n (incf (aref dp (aref as i))))\n (let ((base (loop for val across dp\n sum (ash (* val (- val 1)) -1) of-type uint62)))\n (with-buffered-stdout\n (dotimes (i n)\n (let* ((a (aref as i))\n (num (aref dp a)))\n (println (+ base\n (- (ash (* num (- num 1)) -1))\n (ash (* (- num 1) (- num 2)) -1)))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n1 1 2 1 2\n\"\n \"2\n2\n3\n2\n3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 2 3 4\n\"\n \"0\n0\n0\n0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n3 3 3 3 3\n\"\n \"6\n6\n6\n6\n6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n1 2 1 4 2 1 4 1\n\"\n \"5\n7\n5\n7\n7\n5\n7\n5\n\")))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have N balls. The i-th ball has an integer A_i written on it.\n\nFor each k=1, 2, ..., N, solve the following problem and print the answer.\n\nFind the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.\n\nConstraints\n\n3 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq N\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nFor each k=1,2,...,N, print a line containing the answer.\n\nSample Input 1\n\n5\n1 1 2 1 2\n\nSample Output 1\n\n2\n2\n3\n2\n3\n\nConsider the case k=1 for example. The numbers written on the remaining balls are 1,2,1,2.\n\nFrom these balls, there are two ways to choose two distinct balls so that the integers written on them are equal.\n\nThus, the answer for k=1 is 2.\n\nSample Input 2\n\n4\n1 2 3 4\n\nSample Output 2\n\n0\n0\n0\n0\n\nNo two balls have equal numbers written on them.\n\nSample Input 3\n\n5\n3 3 3 3 3\n\nSample Output 3\n\n6\n6\n6\n6\n6\n\nAny two balls have equal numbers written on them.\n\nSample Input 4\n\n8\n1 2 1 4 2 1 4 1\n\nSample Output 4\n\n5\n7\n5\n7\n7\n5\n7\n5", "sample_input": "5\n1 1 2 1 2\n"}, "reference_outputs": ["2\n2\n3\n2\n3\n"], "source_document_id": "p02732", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have N balls. The i-th ball has an integer A_i written on it.\n\nFor each k=1, 2, ..., N, solve the following problem and print the answer.\n\nFind the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.\n\nConstraints\n\n3 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq N\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nFor each k=1,2,...,N, print a line containing the answer.\n\nSample Input 1\n\n5\n1 1 2 1 2\n\nSample Output 1\n\n2\n2\n3\n2\n3\n\nConsider the case k=1 for example. The numbers written on the remaining balls are 1,2,1,2.\n\nFrom these balls, there are two ways to choose two distinct balls so that the integers written on them are equal.\n\nThus, the answer for k=1 is 2.\n\nSample Input 2\n\n4\n1 2 3 4\n\nSample Output 2\n\n0\n0\n0\n0\n\nNo two balls have equal numbers written on them.\n\nSample Input 3\n\n5\n3 3 3 3 3\n\nSample Output 3\n\n6\n6\n6\n6\n6\n\nAny two balls have equal numbers written on them.\n\nSample Input 4\n\n8\n1 2 1 4 2 1 4 1\n\nSample Output 4\n\n5\n7\n5\n7\n7\n5\n7\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5994, "cpu_time_ms": 834, "memory_kb": 41312}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s018324134", "group_id": "codeNet:p02733", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((h (read))\n (w (read))\n (k (read))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0))\n (res #xffffffff))\n (dotimes (i h)\n (let ((line (read-line)))\n (dotimes (j w)\n (when (char= (aref line j) #\\1)\n (setf (aref plan i j) 1)))))\n #>plan\n (dotimes (bits (ash 1 h))\n (block outer\n (when (oddp bits)\n (let ((sums (make-array 10 :element-type 'uint32 :initial-element 0))\n (bin-count 1))\n (dotimes (j w)\n (let ((bin 0))\n (dotimes (i h)\n (when (logbitp i bits)\n (setq bin i))\n (when (= 1 (aref plan i j))\n (dbg i j bin)\n (incf (aref sums bin)))))\n (when (loop for x across sums thereis (> x k))\n (dbg bits j sums)\n (incf bin-count)\n (fill sums 0)\n (let ((bin 0))\n (dotimes (i h)\n (when (logbitp i bits)\n (setq bin i))\n (when (= 1 (aref plan i j))\n (incf (aref sums bin)))))\n (when (loop for x across sums thereis (> x k))\n (return-from outer))))\n (dbg bits (+ (logcount bits) bin-count -2))\n (minf res (+ (logcount bits) bin-count -2))))))\n (println res)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 5 4\n11100\n10001\n00111\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 5 8\n11100\n10001\n00111\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 10 4\n1110010010\n1000101110\n0011101001\n1101000111\n\"\n \"3\n\")))\n", "language": "Lisp", "metadata": {"date": 1584926934, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02733.html", "problem_id": "p02733", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02733/input.txt", "sample_output_relpath": "derived/input_output/data/p02733/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02733/Lisp/s018324134.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s018324134", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((h (read))\n (w (read))\n (k (read))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0))\n (res #xffffffff))\n (dotimes (i h)\n (let ((line (read-line)))\n (dotimes (j w)\n (when (char= (aref line j) #\\1)\n (setf (aref plan i j) 1)))))\n #>plan\n (dotimes (bits (ash 1 h))\n (block outer\n (when (oddp bits)\n (let ((sums (make-array 10 :element-type 'uint32 :initial-element 0))\n (bin-count 1))\n (dotimes (j w)\n (let ((bin 0))\n (dotimes (i h)\n (when (logbitp i bits)\n (setq bin i))\n (when (= 1 (aref plan i j))\n (dbg i j bin)\n (incf (aref sums bin)))))\n (when (loop for x across sums thereis (> x k))\n (dbg bits j sums)\n (incf bin-count)\n (fill sums 0)\n (let ((bin 0))\n (dotimes (i h)\n (when (logbitp i bits)\n (setq bin i))\n (when (= 1 (aref plan i j))\n (incf (aref sums bin)))))\n (when (loop for x across sums thereis (> x k))\n (return-from outer))))\n (dbg bits (+ (logcount bits) bin-count -2))\n (minf res (+ (logcount bits) bin-count -2))))))\n (println res)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 5 4\n11100\n10001\n00111\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 5 8\n11100\n10001\n00111\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 10 4\n1110010010\n1000101110\n0011101001\n1101000111\n\"\n \"3\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nWe have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares.\n\nThe square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is 0, and white if S_{i,j} is 1.\n\nWe will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar.\n\nHow many times do we need to cut the bar so that every block after the cuts has K or less white squares?\n\nConstraints\n\n1 \\leq H \\leq 10\n\n1 \\leq W \\leq 1000\n\n1 \\leq K \\leq H \\times W\n\nS_{i,j} is 0 or 1.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W K\nS_{1,1}S_{1,2}...S_{1,W}\n:\nS_{H,1}S_{H,2}...S_{H,W}\n\nOutput\n\nPrint the number of minimum times the bar needs to be cut so that every block after the cuts has K or less white squares.\n\nSample Input 1\n\n3 5 4\n11100\n10001\n00111\n\nSample Output 1\n\n2\n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and 4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the right.\n\nSample Input 2\n\n3 5 8\n11100\n10001\n00111\n\nSample Output 2\n\n0\n\nNo cut is needed.\n\nSample Input 3\n\n4 10 4\n1110010010\n1000101110\n0011101001\n1101000111\n\nSample Output 3\n\n3", "sample_input": "3 5 4\n11100\n10001\n00111\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02733", "source_text": "Score : 500 points\n\nProblem Statement\n\nWe have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares.\n\nThe square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is 0, and white if S_{i,j} is 1.\n\nWe will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar.\n\nHow many times do we need to cut the bar so that every block after the cuts has K or less white squares?\n\nConstraints\n\n1 \\leq H \\leq 10\n\n1 \\leq W \\leq 1000\n\n1 \\leq K \\leq H \\times W\n\nS_{i,j} is 0 or 1.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W K\nS_{1,1}S_{1,2}...S_{1,W}\n:\nS_{H,1}S_{H,2}...S_{H,W}\n\nOutput\n\nPrint the number of minimum times the bar needs to be cut so that every block after the cuts has K or less white squares.\n\nSample Input 1\n\n3 5 4\n11100\n10001\n00111\n\nSample Output 1\n\n2\n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and 4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the right.\n\nSample Input 2\n\n3 5 8\n11100\n10001\n00111\n\nSample Output 2\n\n0\n\nNo cut is needed.\n\nSample Input 3\n\n4 10 4\n1110010010\n1000101110\n0011101001\n1101000111\n\nSample Output 3\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5346, "cpu_time_ms": 238, "memory_kb": 20192}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s902714829", "group_id": "codeNet:p02734", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n (dp (make-array (+ n 1) :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum))\n (incf (aref dp (aref as i))))\n (let ((base (loop for val across dp\n sum (ash (* val (- val 1)) -1))))\n (with-buffered-stdout\n (dotimes (i n)\n (let* ((a (aref as i))\n (num (aref dp a)))\n (println (+ base\n (- (ash (* num (- num 1)) -1))\n (ash (* (- num 1) (- num 2)) -1)))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n1 1 2 1 2\n\"\n \"2\n2\n3\n2\n3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 2 3 4\n\"\n \"0\n0\n0\n0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n3 3 3 3 3\n\"\n \"6\n6\n6\n6\n6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n1 2 1 4 2 1 4 1\n\"\n \"5\n7\n5\n7\n7\n5\n7\n5\n\")))\n", "language": "Lisp", "metadata": {"date": 1584929045, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02734.html", "problem_id": "p02734", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02734/input.txt", "sample_output_relpath": "derived/input_output/data/p02734/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02734/Lisp/s902714829.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s902714829", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n (dp (make-array (+ n 1) :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum))\n (incf (aref dp (aref as i))))\n (let ((base (loop for val across dp\n sum (ash (* val (- val 1)) -1))))\n (with-buffered-stdout\n (dotimes (i n)\n (let* ((a (aref as i))\n (num (aref dp a)))\n (println (+ base\n (- (ash (* num (- num 1)) -1))\n (ash (* (- num 1) (- num 2)) -1)))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n1 1 2 1 2\n\"\n \"2\n2\n3\n2\n3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 2 3 4\n\"\n \"0\n0\n0\n0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n3 3 3 3 3\n\"\n \"6\n6\n6\n6\n6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n1 2 1 4 2 1 4 1\n\"\n \"5\n7\n5\n7\n7\n5\n7\n5\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven are a sequence of N integers A_1, A_2, \\ldots, A_N and a positive integer S.\n\nFor a pair of integers (L, R) such that 1\\leq L \\leq R \\leq N, let us define f(L, R) as follows:\n\nf(L, R) is the number of sequences of integers (x_1, x_2, \\ldots , x_k) such that L \\leq x_1 < x_2 < \\cdots < x_k \\leq R and A_{x_1}+A_{x_2}+\\cdots +A_{x_k} = S.\n\nFind the sum of f(L, R) over all pairs of integers (L, R) such that 1\\leq L \\leq R\\leq N. Since this sum can be enormous, print it modulo 998244353.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 3000\n\n1 \\leq S \\leq 3000\n\n1 \\leq A_i \\leq 3000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN S\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the sum of f(L, R), modulo 998244353.\n\nSample Input 1\n\n3 4\n2 2 4\n\nSample Output 1\n\n5\n\nThe value of f(L, R) for each pair is as follows, for a total of 5.\n\nf(1,1) = 0\n\nf(1,2) = 1 (for the sequence (1, 2))\n\nf(1,3) = 2 (for (1, 2) and (3))\n\nf(2,2) = 0\n\nf(2,3) = 1 (for (3))\n\nf(3,3) = 1 (for (3))\n\nSample Input 2\n\n5 8\n9 9 9 9 9\n\nSample Output 2\n\n0\n\nSample Input 3\n\n10 10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 3\n\n152", "sample_input": "3 4\n2 2 4\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02734", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are a sequence of N integers A_1, A_2, \\ldots, A_N and a positive integer S.\n\nFor a pair of integers (L, R) such that 1\\leq L \\leq R \\leq N, let us define f(L, R) as follows:\n\nf(L, R) is the number of sequences of integers (x_1, x_2, \\ldots , x_k) such that L \\leq x_1 < x_2 < \\cdots < x_k \\leq R and A_{x_1}+A_{x_2}+\\cdots +A_{x_k} = S.\n\nFind the sum of f(L, R) over all pairs of integers (L, R) such that 1\\leq L \\leq R\\leq N. Since this sum can be enormous, print it modulo 998244353.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 3000\n\n1 \\leq S \\leq 3000\n\n1 \\leq A_i \\leq 3000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN S\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the sum of f(L, R), modulo 998244353.\n\nSample Input 1\n\n3 4\n2 2 4\n\nSample Output 1\n\n5\n\nThe value of f(L, R) for each pair is as follows, for a total of 5.\n\nf(1,1) = 0\n\nf(1,2) = 1 (for the sequence (1, 2))\n\nf(1,3) = 2 (for (1, 2) and (3))\n\nf(2,2) = 0\n\nf(2,3) = 1 (for (3))\n\nf(3,3) = 1 (for (3))\n\nSample Input 2\n\n5 8\n9 9 9 9 9\n\nSample Output 2\n\n0\n\nSample Input 3\n\n10 10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 3\n\n152", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5979, "cpu_time_ms": 101, "memory_kb": 14180}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s636614506", "group_id": "codeNet:p02734", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 998244353)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun main ()\n (let* ((n (read))\n (s (read))\n (as (make-array n :element-type 'uint32))\n (dp (make-array (list (+ n 1) 11) :element-type 'uint32 :initial-element 0))\n (res 0))\n (dotimes (i n)\n (setf (aref as i) (read)))\n (dotimes (x n)\n #>dp\n (let ((a (aref as x)))\n (dotimes (y s)\n (setf (aref dp (+ x 1) y) (aref dp x y)))\n (incfmod (aref dp (+ x 1) a) (+ x 1))\n (dotimes (y (+ s 1))\n (when (> (+ y a) s)\n (return))\n (incfmod (aref dp (+ x 1) (+ y a))\n (aref dp x y)))\n (incfmod res #>(mod* (- n x) (aref dp (+ x 1) s)))))\n #>dp\n (println res)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 4\n2 2 4\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 8\n9 9 9 9 9\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 10\n3 1 4 1 5 9 2 6 5 3\n\"\n \"152\n\")))\n", "language": "Lisp", "metadata": {"date": 1584928550, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02734.html", "problem_id": "p02734", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02734/input.txt", "sample_output_relpath": "derived/input_output/data/p02734/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02734/Lisp/s636614506.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s636614506", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 998244353)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun main ()\n (let* ((n (read))\n (s (read))\n (as (make-array n :element-type 'uint32))\n (dp (make-array (list (+ n 1) 11) :element-type 'uint32 :initial-element 0))\n (res 0))\n (dotimes (i n)\n (setf (aref as i) (read)))\n (dotimes (x n)\n #>dp\n (let ((a (aref as x)))\n (dotimes (y s)\n (setf (aref dp (+ x 1) y) (aref dp x y)))\n (incfmod (aref dp (+ x 1) a) (+ x 1))\n (dotimes (y (+ s 1))\n (when (> (+ y a) s)\n (return))\n (incfmod (aref dp (+ x 1) (+ y a))\n (aref dp x y)))\n (incfmod res #>(mod* (- n x) (aref dp (+ x 1) s)))))\n #>dp\n (println res)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 4\n2 2 4\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 8\n9 9 9 9 9\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 10\n3 1 4 1 5 9 2 6 5 3\n\"\n \"152\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven are a sequence of N integers A_1, A_2, \\ldots, A_N and a positive integer S.\n\nFor a pair of integers (L, R) such that 1\\leq L \\leq R \\leq N, let us define f(L, R) as follows:\n\nf(L, R) is the number of sequences of integers (x_1, x_2, \\ldots , x_k) such that L \\leq x_1 < x_2 < \\cdots < x_k \\leq R and A_{x_1}+A_{x_2}+\\cdots +A_{x_k} = S.\n\nFind the sum of f(L, R) over all pairs of integers (L, R) such that 1\\leq L \\leq R\\leq N. Since this sum can be enormous, print it modulo 998244353.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 3000\n\n1 \\leq S \\leq 3000\n\n1 \\leq A_i \\leq 3000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN S\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the sum of f(L, R), modulo 998244353.\n\nSample Input 1\n\n3 4\n2 2 4\n\nSample Output 1\n\n5\n\nThe value of f(L, R) for each pair is as follows, for a total of 5.\n\nf(1,1) = 0\n\nf(1,2) = 1 (for the sequence (1, 2))\n\nf(1,3) = 2 (for (1, 2) and (3))\n\nf(2,2) = 0\n\nf(2,3) = 1 (for (3))\n\nf(3,3) = 1 (for (3))\n\nSample Input 2\n\n5 8\n9 9 9 9 9\n\nSample Output 2\n\n0\n\nSample Input 3\n\n10 10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 3\n\n152", "sample_input": "3 4\n2 2 4\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02734", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are a sequence of N integers A_1, A_2, \\ldots, A_N and a positive integer S.\n\nFor a pair of integers (L, R) such that 1\\leq L \\leq R \\leq N, let us define f(L, R) as follows:\n\nf(L, R) is the number of sequences of integers (x_1, x_2, \\ldots , x_k) such that L \\leq x_1 < x_2 < \\cdots < x_k \\leq R and A_{x_1}+A_{x_2}+\\cdots +A_{x_k} = S.\n\nFind the sum of f(L, R) over all pairs of integers (L, R) such that 1\\leq L \\leq R\\leq N. Since this sum can be enormous, print it modulo 998244353.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 3000\n\n1 \\leq S \\leq 3000\n\n1 \\leq A_i \\leq 3000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN S\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the sum of f(L, R), modulo 998244353.\n\nSample Input 1\n\n3 4\n2 2 4\n\nSample Output 1\n\n5\n\nThe value of f(L, R) for each pair is as follows, for a total of 5.\n\nf(1,1) = 0\n\nf(1,2) = 1 (for the sequence (1, 2))\n\nf(1,3) = 2 (for (1, 2) and (3))\n\nf(2,2) = 0\n\nf(2,3) = 1 (for (3))\n\nf(3,3) = 1 (for (3))\n\nSample Input 2\n\n5 8\n9 9 9 9 9\n\nSample Output 2\n\n0\n\nSample Input 3\n\n10 10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 3\n\n152", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5481, "cpu_time_ms": 564, "memory_kb": 28904}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s949400217", "group_id": "codeNet:p02736", "input_text": "(defvar N (read))\n\n(defun abskaisa (old &optional new)\n (if (null (cdr old))\n (nreverse new)\n (abskaisa (cdr old) (cons (abs (- (cadr old) (car old))) new))))\n\n(defun solve-stupid ()\n (let ((a (mapcar #'digit-char-p (concatenate 'list (read-line)))))\n (dotimes (x (1- N))\n (setf a (abskaisa a))\n )\n (princ (car a))\n )\n )\n\n(defun cunning-solve ()\n (let* ((str (read-line))\n\t (hd (mapcar #'digit-char-p (concatenate 'list (subseq str 0 4))))\n\t (tl (mapcar #'digit-char-p (concatenate 'list (subseq str (- N 4)))))\n\t (hdb (abskaisa (abskaisa hd)))\n\t )\n (princ (list hdb tl))))\n\n(solve-stupid)", "language": "Lisp", "metadata": {"date": 1584845027, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02736.html", "problem_id": "p02736", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02736/input.txt", "sample_output_relpath": "derived/input_output/data/p02736/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02736/Lisp/s949400217.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s949400217", "user_id": "u334552723"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defvar N (read))\n\n(defun abskaisa (old &optional new)\n (if (null (cdr old))\n (nreverse new)\n (abskaisa (cdr old) (cons (abs (- (cadr old) (car old))) new))))\n\n(defun solve-stupid ()\n (let ((a (mapcar #'digit-char-p (concatenate 'list (read-line)))))\n (dotimes (x (1- N))\n (setf a (abskaisa a))\n )\n (princ (car a))\n )\n )\n\n(defun cunning-solve ()\n (let* ((str (read-line))\n\t (hd (mapcar #'digit-char-p (concatenate 'list (subseq str 0 4))))\n\t (tl (mapcar #'digit-char-p (concatenate 'list (subseq str (- N 4)))))\n\t (hdb (abskaisa (abskaisa hd)))\n\t )\n (princ (list hdb tl))))\n\n(solve-stupid)", "problem_context": "Score : 700 points\n\nProblem Statement\n\nGiven is a sequence of N digits a_1a_2\\ldots a_N, where each element is 1, 2, or 3.\nLet x_{i,j} defined as follows:\n\nx_{1,j} := a_j \\quad (1 \\leq j \\leq N)\n\nx_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \\quad (2 \\leq i \\leq N and 1 \\leq j \\leq N+1-i)\n\nFind x_{N,1}.\n\nConstraints\n\n2 \\leq N \\leq 10^6\n\na_i = 1,2,3 (1 \\leq i \\leq N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1a_2\\ldotsa_N\n\nOutput\n\nPrint x_{N,1}.\n\nSample Input 1\n\n4\n1231\n\nSample Output 1\n\n1\n\nx_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.\n\nx_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.\n\nx_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.\n\nFinally, x_{4,1} = |0-1| = 1, so the answer is 1.\n\nSample Input 2\n\n10\n2311312312\n\nSample Output 2\n\n0", "sample_input": "4\n1231\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02736", "source_text": "Score : 700 points\n\nProblem Statement\n\nGiven is a sequence of N digits a_1a_2\\ldots a_N, where each element is 1, 2, or 3.\nLet x_{i,j} defined as follows:\n\nx_{1,j} := a_j \\quad (1 \\leq j \\leq N)\n\nx_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \\quad (2 \\leq i \\leq N and 1 \\leq j \\leq N+1-i)\n\nFind x_{N,1}.\n\nConstraints\n\n2 \\leq N \\leq 10^6\n\na_i = 1,2,3 (1 \\leq i \\leq N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1a_2\\ldotsa_N\n\nOutput\n\nPrint x_{N,1}.\n\nSample Input 1\n\n4\n1231\n\nSample Output 1\n\n1\n\nx_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.\n\nx_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.\n\nx_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.\n\nFinally, x_{4,1} = |0-1| = 1, so the answer is 1.\n\nSample Input 2\n\n10\n2311312312\n\nSample Output 2\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 623, "cpu_time_ms": 2110, "memory_kb": 270760}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s841185036", "group_id": "codeNet:p02736", "input_text": "(defun main ()\n (let* ((n (read))\n (vec (make-array n :initial-element 0)))\n (dotimes (i n)\n (setf (svref vec i)\n (- (char-code (read-char)) 48)))\n (princ (f n vec))))\n\n(defun f (n vec)\n (let ((cache (make-hash-table :test #'equal)))\n (labels ((x (i j)\n (declare (optimize (speed 3))\n (type fixnum i j))\n (or (identity (gethash (cons i j) cache))\n (setf (gethash (cons i j) cache)\n (if (<= i 0)\n (svref vec j)\n (abs (the fixnum (- (the fixnum (x (1- i) j))\n (the fixnum (x (1- i) (1+ j)))))))))))\n (x (1- n) 0))))\n\n(main)", "language": "Lisp", "metadata": {"date": 1584844668, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02736.html", "problem_id": "p02736", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02736/input.txt", "sample_output_relpath": "derived/input_output/data/p02736/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02736/Lisp/s841185036.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s841185036", "user_id": "u956039157"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun main ()\n (let* ((n (read))\n (vec (make-array n :initial-element 0)))\n (dotimes (i n)\n (setf (svref vec i)\n (- (char-code (read-char)) 48)))\n (princ (f n vec))))\n\n(defun f (n vec)\n (let ((cache (make-hash-table :test #'equal)))\n (labels ((x (i j)\n (declare (optimize (speed 3))\n (type fixnum i j))\n (or (identity (gethash (cons i j) cache))\n (setf (gethash (cons i j) cache)\n (if (<= i 0)\n (svref vec j)\n (abs (the fixnum (- (the fixnum (x (1- i) j))\n (the fixnum (x (1- i) (1+ j)))))))))))\n (x (1- n) 0))))\n\n(main)", "problem_context": "Score : 700 points\n\nProblem Statement\n\nGiven is a sequence of N digits a_1a_2\\ldots a_N, where each element is 1, 2, or 3.\nLet x_{i,j} defined as follows:\n\nx_{1,j} := a_j \\quad (1 \\leq j \\leq N)\n\nx_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \\quad (2 \\leq i \\leq N and 1 \\leq j \\leq N+1-i)\n\nFind x_{N,1}.\n\nConstraints\n\n2 \\leq N \\leq 10^6\n\na_i = 1,2,3 (1 \\leq i \\leq N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1a_2\\ldotsa_N\n\nOutput\n\nPrint x_{N,1}.\n\nSample Input 1\n\n4\n1231\n\nSample Output 1\n\n1\n\nx_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.\n\nx_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.\n\nx_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.\n\nFinally, x_{4,1} = |0-1| = 1, so the answer is 1.\n\nSample Input 2\n\n10\n2311312312\n\nSample Output 2\n\n0", "sample_input": "4\n1231\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02736", "source_text": "Score : 700 points\n\nProblem Statement\n\nGiven is a sequence of N digits a_1a_2\\ldots a_N, where each element is 1, 2, or 3.\nLet x_{i,j} defined as follows:\n\nx_{1,j} := a_j \\quad (1 \\leq j \\leq N)\n\nx_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \\quad (2 \\leq i \\leq N and 1 \\leq j \\leq N+1-i)\n\nFind x_{N,1}.\n\nConstraints\n\n2 \\leq N \\leq 10^6\n\na_i = 1,2,3 (1 \\leq i \\leq N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1a_2\\ldotsa_N\n\nOutput\n\nPrint x_{N,1}.\n\nSample Input 1\n\n4\n1231\n\nSample Output 1\n\n1\n\nx_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.\n\nx_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.\n\nx_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.\n\nFinally, x_{4,1} = |0-1| = 1, so the answer is 1.\n\nSample Input 2\n\n10\n2311312312\n\nSample Output 2\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 758, "cpu_time_ms": 339, "memory_kb": 46304}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s527099671", "group_id": "codeNet:p02745", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun solve (a b c)\n (declare #.OPT\n (simple-base-string a b c))\n (let ((len-a (length a))\n (len-b (length b))\n (len-c (length c))\n (ab (make-string 4000 :element-type 'base-char))\n (min #xffffffff))\n (declare (uint32 len-a len-b len-c min))\n (dotimes (init1 (+ len-a 1))\n (block outer\n (loop for i from init1 below len-a\n for j from 0 below len-b\n unless (or (char= (aref a i) (aref b j))\n (char= (aref a i) #\\?)\n (char= (aref b j) #\\?))\n do (return-from outer)\n finally\n (let ((len-ab (max len-a (+ init1 len-b))))\n (dotimes (i len-a)\n (setf (aref ab i) (aref a i)))\n (loop for j below len-b\n for i = (+ j init1)\n do (cond ((>= i len-a)\n (setf (aref ab i) (aref b j)))\n ((char= #\\? (aref a i) (aref b j))\n (setf (aref ab i) #\\?))\n ((char= #\\? (aref a i))\n (setf (aref ab i) (aref b j)))\n ((char= #\\? (aref b j))\n (setf (aref ab i) (aref a i)))\n (t\n (setf (aref ab i) (aref b j)))))\n (dotimes (init2 (+ len-ab 1))\n (when (>= (max len-ab (+ init2 len-c)) min)\n (return))\n (block inner\n (loop for i from init2 below len-ab\n for j from 0 below len-c\n unless (or (char= (aref ab i) (aref c j))\n (char= (aref ab i) #\\?)\n (char= (aref c j) #\\?))\n do (return-from inner)\n finally (setq min (min min (max len-ab (+ init2 len-c)))))))))))\n min))\n\n(defun main ()\n (let* ((a (coerce (read-line) 'simple-base-string))\n (b (coerce (read-line) 'simple-base-string))\n (c (coerce (read-line) 'simple-base-string)))\n ;; (solve b a c)\n (println\n (min (solve a b c)\n (solve a c b)\n (solve b c a)\n (solve b a c)\n (solve c a b)\n (solve c b a)))\n ))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"a?c\nder\ncod\n\"\n \"7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"atcoder\natcoder\n???????\n\"\n \"7\n\")))\n", "language": "Lisp", "metadata": {"date": 1584246301, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02745.html", "problem_id": "p02745", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02745/input.txt", "sample_output_relpath": "derived/input_output/data/p02745/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02745/Lisp/s527099671.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s527099671", "user_id": "u352600849"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun solve (a b c)\n (declare #.OPT\n (simple-base-string a b c))\n (let ((len-a (length a))\n (len-b (length b))\n (len-c (length c))\n (ab (make-string 4000 :element-type 'base-char))\n (min #xffffffff))\n (declare (uint32 len-a len-b len-c min))\n (dotimes (init1 (+ len-a 1))\n (block outer\n (loop for i from init1 below len-a\n for j from 0 below len-b\n unless (or (char= (aref a i) (aref b j))\n (char= (aref a i) #\\?)\n (char= (aref b j) #\\?))\n do (return-from outer)\n finally\n (let ((len-ab (max len-a (+ init1 len-b))))\n (dotimes (i len-a)\n (setf (aref ab i) (aref a i)))\n (loop for j below len-b\n for i = (+ j init1)\n do (cond ((>= i len-a)\n (setf (aref ab i) (aref b j)))\n ((char= #\\? (aref a i) (aref b j))\n (setf (aref ab i) #\\?))\n ((char= #\\? (aref a i))\n (setf (aref ab i) (aref b j)))\n ((char= #\\? (aref b j))\n (setf (aref ab i) (aref a i)))\n (t\n (setf (aref ab i) (aref b j)))))\n (dotimes (init2 (+ len-ab 1))\n (when (>= (max len-ab (+ init2 len-c)) min)\n (return))\n (block inner\n (loop for i from init2 below len-ab\n for j from 0 below len-c\n unless (or (char= (aref ab i) (aref c j))\n (char= (aref ab i) #\\?)\n (char= (aref c j) #\\?))\n do (return-from inner)\n finally (setq min (min min (max len-ab (+ init2 len-c)))))))))))\n min))\n\n(defun main ()\n (let* ((a (coerce (read-line) 'simple-base-string))\n (b (coerce (read-line) 'simple-base-string))\n (c (coerce (read-line) 'simple-base-string)))\n ;; (solve b a c)\n (println\n (min (solve a b c)\n (solve a c b)\n (solve b c a)\n (solve b a c)\n (solve c a b)\n (solve c b a)))\n ))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"a?c\nder\ncod\n\"\n \"7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"atcoder\natcoder\n???????\n\"\n \"7\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nSnuke has a string s.\nFrom this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows:\n\nChoose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with ?s.\n\nFor example, if s is mississippi, we can choose the substring ssissip and replace its 1-st and 3-rd characters with ? to obtain ?s?ssip.\n\nYou are given the strings a, b, and c.\nFind the minimum possible length of s.\n\nConstraints\n\n1 \\leq |a|, |b|, |c| \\leq 2000\n\na, b, and c consists of lowercase English letters and ?s.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na\nb\nc\n\nOutput\n\nPrint the minimum possible length of s.\n\nSample Input 1\n\na?c\nder\ncod\n\nSample Output 1\n\n7\n\nFor example, s could be atcoder.\n\nSample Input 2\n\natcoder\natcoder\n???????\n\nSample Output 2\n\n7\n\na, b, and c may not be distinct.", "sample_input": "a?c\nder\ncod\n"}, "reference_outputs": ["7\n"], "source_document_id": "p02745", "source_text": "Score : 500 points\n\nProblem Statement\n\nSnuke has a string s.\nFrom this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows:\n\nChoose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with ?s.\n\nFor example, if s is mississippi, we can choose the substring ssissip and replace its 1-st and 3-rd characters with ? to obtain ?s?ssip.\n\nYou are given the strings a, b, and c.\nFind the minimum possible length of s.\n\nConstraints\n\n1 \\leq |a|, |b|, |c| \\leq 2000\n\na, b, and c consists of lowercase English letters and ?s.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na\nb\nc\n\nOutput\n\nPrint the minimum possible length of s.\n\nSample Input 1\n\na?c\nder\ncod\n\nSample Output 1\n\n7\n\nFor example, s could be atcoder.\n\nSample Input 2\n\natcoder\natcoder\n???????\n\nSample Output 2\n\n7\n\na, b, and c may not be distinct.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6020, "cpu_time_ms": 1971, "memory_kb": 24288}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s195590247", "group_id": "codeNet:p02745", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun solve (a b c)\n (declare #.OPT\n (simple-base-string a b c))\n (let ((len-a (length a))\n (len-b (length b))\n (len-c (length c))\n (min #xffffffff))\n (declare (uint32 len-a len-b len-c min))\n (dotimes (init1 (+ len-a 1))\n (block outer\n (loop for i from init1 below len-a\n for j from 0 below len-b\n unless (or (char= (aref a i) (aref b j))\n (char= (aref a i) #\\?)\n (char= (aref b j) #\\?))\n do (return-from outer)\n finally\n (let ((ab (make-string (+ init1 len-b) :element-type 'base-char)))\n (dotimes (i init1)\n (setf (aref ab i) (aref a i)))\n (loop for j below len-b\n for i = (+ j init1)\n do (cond ((>= i len-a)\n (setf (aref ab i) (aref b j)))\n ((char= #\\? (aref a i) (aref b j))\n (setf (aref ab i) #\\?))\n ((char= #\\? (aref a i))\n (setf (aref ab i) (aref b j)))\n ((char= #\\? (aref b j))\n (setf (aref ab i) (aref a i)))\n (t\n ;; (assert (char= (aref a i) (aref b j)))\n (setf (aref ab i) (aref b j)))))\n (let ((len-ab (length ab)))\n (dotimes (init2 (+ len-ab 1))\n (block inner\n (loop for i from init2 below len-ab\n for j from 0 below len-c\n unless (or (char= (aref ab i) (aref c j))\n (char= (aref ab i) #\\?)\n (char= (aref c j) #\\?))\n do (return-from inner)\n finally (setq min (min min (+ init2 len-c)))))))))))\n min))\n\n(defun main ()\n (let* ((a (coerce (read-line) 'simple-base-string))\n (b (coerce (read-line) 'simple-base-string))\n (c (coerce (read-line) 'simple-base-string)))\n ;; (solve c a b)\n (println\n (min (solve a b c)\n (solve a c b)\n #>(solve b c a)\n #>(solve b a c)\n #>(solve c a b)\n #>(solve c b a)))\n ))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"a?c\nder\ncod\n\"\n \"7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"atcoder\natcoder\n???????\n\"\n \"7\n\")))\n", "language": "Lisp", "metadata": {"date": 1584236337, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02745.html", "problem_id": "p02745", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02745/input.txt", "sample_output_relpath": "derived/input_output/data/p02745/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02745/Lisp/s195590247.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s195590247", "user_id": "u352600849"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun solve (a b c)\n (declare #.OPT\n (simple-base-string a b c))\n (let ((len-a (length a))\n (len-b (length b))\n (len-c (length c))\n (min #xffffffff))\n (declare (uint32 len-a len-b len-c min))\n (dotimes (init1 (+ len-a 1))\n (block outer\n (loop for i from init1 below len-a\n for j from 0 below len-b\n unless (or (char= (aref a i) (aref b j))\n (char= (aref a i) #\\?)\n (char= (aref b j) #\\?))\n do (return-from outer)\n finally\n (let ((ab (make-string (+ init1 len-b) :element-type 'base-char)))\n (dotimes (i init1)\n (setf (aref ab i) (aref a i)))\n (loop for j below len-b\n for i = (+ j init1)\n do (cond ((>= i len-a)\n (setf (aref ab i) (aref b j)))\n ((char= #\\? (aref a i) (aref b j))\n (setf (aref ab i) #\\?))\n ((char= #\\? (aref a i))\n (setf (aref ab i) (aref b j)))\n ((char= #\\? (aref b j))\n (setf (aref ab i) (aref a i)))\n (t\n ;; (assert (char= (aref a i) (aref b j)))\n (setf (aref ab i) (aref b j)))))\n (let ((len-ab (length ab)))\n (dotimes (init2 (+ len-ab 1))\n (block inner\n (loop for i from init2 below len-ab\n for j from 0 below len-c\n unless (or (char= (aref ab i) (aref c j))\n (char= (aref ab i) #\\?)\n (char= (aref c j) #\\?))\n do (return-from inner)\n finally (setq min (min min (+ init2 len-c)))))))))))\n min))\n\n(defun main ()\n (let* ((a (coerce (read-line) 'simple-base-string))\n (b (coerce (read-line) 'simple-base-string))\n (c (coerce (read-line) 'simple-base-string)))\n ;; (solve c a b)\n (println\n (min (solve a b c)\n (solve a c b)\n #>(solve b c a)\n #>(solve b a c)\n #>(solve c a b)\n #>(solve c b a)))\n ))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"a?c\nder\ncod\n\"\n \"7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"atcoder\natcoder\n???????\n\"\n \"7\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nSnuke has a string s.\nFrom this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows:\n\nChoose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with ?s.\n\nFor example, if s is mississippi, we can choose the substring ssissip and replace its 1-st and 3-rd characters with ? to obtain ?s?ssip.\n\nYou are given the strings a, b, and c.\nFind the minimum possible length of s.\n\nConstraints\n\n1 \\leq |a|, |b|, |c| \\leq 2000\n\na, b, and c consists of lowercase English letters and ?s.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na\nb\nc\n\nOutput\n\nPrint the minimum possible length of s.\n\nSample Input 1\n\na?c\nder\ncod\n\nSample Output 1\n\n7\n\nFor example, s could be atcoder.\n\nSample Input 2\n\natcoder\natcoder\n???????\n\nSample Output 2\n\n7\n\na, b, and c may not be distinct.", "sample_input": "a?c\nder\ncod\n"}, "reference_outputs": ["7\n"], "source_document_id": "p02745", "source_text": "Score : 500 points\n\nProblem Statement\n\nSnuke has a string s.\nFrom this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows:\n\nChoose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with ?s.\n\nFor example, if s is mississippi, we can choose the substring ssissip and replace its 1-st and 3-rd characters with ? to obtain ?s?ssip.\n\nYou are given the strings a, b, and c.\nFind the minimum possible length of s.\n\nConstraints\n\n1 \\leq |a|, |b|, |c| \\leq 2000\n\na, b, and c consists of lowercase English letters and ?s.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na\nb\nc\n\nOutput\n\nPrint the minimum possible length of s.\n\nSample Input 1\n\na?c\nder\ncod\n\nSample Output 1\n\n7\n\nFor example, s could be atcoder.\n\nSample Input 2\n\natcoder\natcoder\n???????\n\nSample Output 2\n\n7\n\na, b, and c may not be distinct.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6026, "cpu_time_ms": 2104, "memory_kb": 24416}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s133826707", "group_id": "codeNet:p02746", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun encode (x)\n (let ((res (make-array 31 :element-type 'uint8)))\n (dotimes (i 31)\n (multiple-value-bind (quot rem) (floor x 3)\n (setf (aref res i) rem\n x quot)))\n res))\n\n(defun decode (x)\n (let ((base 1)\n (res 0))\n (dotimes (i 31)\n (incf res (* base (aref x i)))\n (setq base (* base 3)))\n res))\n\n(defun main ()\n (let* ((q (read)))\n (dotimes (_ q)\n (let* ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1))\n (c (- (read-fixnum) 1))\n (d (- (read-fixnum) 1))\n (as (encode a))\n (bs (encode b))\n (cs (encode c))\n (ds (encode d))\n (depth (max (loop for i from 30 downto -1\n do (when (or (= -1 i)\n (/= (aref as i) (aref cs i)))\n (return i)))\n (loop for i from 30 downto -1\n do (when (or (= -1 i)\n (/= (aref bs i) (aref ds i)))\n (return i))))))\n (loop for i from 30 above depth\n do (setf (aref as i) 0\n (aref bs i) 0\n (aref cs i) 0\n (aref ds i) 0))\n ; (dbg as bs cs ds)\n (let* ((a (decode as))\n (b (decode bs))\n (c (decode cs))\n (d (decode ds))\n (base (expt 3 depth))\n (aseg (floor a base))\n (bseg (floor b base))\n (cseg (floor c base))\n (dseg (floor d base)))\n (dbg a b c d)\n (dbg aseg bseg cseg dseg)\n (let ((res (+ (abs (- a c)) (abs (- b d)))))\n #>res\n (cond ((or (and (= aseg 1) (= bseg 0) (= cseg 1) (= dseg 2))\n (and (= aseg 1) (= bseg 2) (= cseg 1) (= dseg 0)))\n (assert (and (>= a base) (>= c base)))\n (incf res (min #>(* 2 (- (min a c) (- base 1)))\n #>(* 2 (- (* 2 base) (max a c))))))\n ((or (and (= aseg 0) (= bseg 1) (= cseg 2) (= dseg 1))\n (and (= aseg 2) (= bseg 1) (= cseg 0) (= dseg 1)))\n (assert (and (>= b base) (>= d base)))\n (incf res (min (* 2 (- (min b d) (- base 1)))\n (* 2 (- (* 2 base) (max b d))))))\n (t))\n (println res)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n4 2 7 4\n9 9 1 9\n\"\n \"5\n8\n\")))\n", "language": "Lisp", "metadata": {"date": 1584239833, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02746.html", "problem_id": "p02746", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02746/input.txt", "sample_output_relpath": "derived/input_output/data/p02746/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02746/Lisp/s133826707.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s133826707", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n8\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun encode (x)\n (let ((res (make-array 31 :element-type 'uint8)))\n (dotimes (i 31)\n (multiple-value-bind (quot rem) (floor x 3)\n (setf (aref res i) rem\n x quot)))\n res))\n\n(defun decode (x)\n (let ((base 1)\n (res 0))\n (dotimes (i 31)\n (incf res (* base (aref x i)))\n (setq base (* base 3)))\n res))\n\n(defun main ()\n (let* ((q (read)))\n (dotimes (_ q)\n (let* ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1))\n (c (- (read-fixnum) 1))\n (d (- (read-fixnum) 1))\n (as (encode a))\n (bs (encode b))\n (cs (encode c))\n (ds (encode d))\n (depth (max (loop for i from 30 downto -1\n do (when (or (= -1 i)\n (/= (aref as i) (aref cs i)))\n (return i)))\n (loop for i from 30 downto -1\n do (when (or (= -1 i)\n (/= (aref bs i) (aref ds i)))\n (return i))))))\n (loop for i from 30 above depth\n do (setf (aref as i) 0\n (aref bs i) 0\n (aref cs i) 0\n (aref ds i) 0))\n ; (dbg as bs cs ds)\n (let* ((a (decode as))\n (b (decode bs))\n (c (decode cs))\n (d (decode ds))\n (base (expt 3 depth))\n (aseg (floor a base))\n (bseg (floor b base))\n (cseg (floor c base))\n (dseg (floor d base)))\n (dbg a b c d)\n (dbg aseg bseg cseg dseg)\n (let ((res (+ (abs (- a c)) (abs (- b d)))))\n #>res\n (cond ((or (and (= aseg 1) (= bseg 0) (= cseg 1) (= dseg 2))\n (and (= aseg 1) (= bseg 2) (= cseg 1) (= dseg 0)))\n (assert (and (>= a base) (>= c base)))\n (incf res (min #>(* 2 (- (min a c) (- base 1)))\n #>(* 2 (- (* 2 base) (max a c))))))\n ((or (and (= aseg 0) (= bseg 1) (= cseg 2) (= dseg 1))\n (and (= aseg 2) (= bseg 1) (= cseg 0) (= dseg 1)))\n (assert (and (>= b base) (>= d base)))\n (incf res (min (* 2 (- (min b d) (- base 1)))\n (* 2 (- (* 2 base) (max b d))))))\n (t))\n (println res)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n4 2 7 4\n9 9 1 9\n\"\n \"5\n8\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nFor a non-negative integer K, we define a fractal of level K as follows:\n\nA fractal of level 0 is a grid with just one white square.\n\nWhen K > 0, a fractal of level K is a 3^K \\times 3^K grid. If we divide this grid into nine 3^{K-1} \\times 3^{K-1} subgrids:\n\nThe central subgrid consists of only black squares.\n\nEach of the other eight subgrids is a fractal of level K-1.\n\nFor example, a fractal of level 2 is as follows:\n\nIn a fractal of level 30, let (r, c) denote the square at the r-th row from the top and the c-th column from the left.\n\nYou are given Q quadruples of integers (a_i, b_i, c_i, d_i).\nFor each quadruple, find the distance from (a_i, b_i) to (c_i, d_i).\n\nHere the distance from (a, b) to (c, d) is the minimum integer n that satisfies the following condition:\n\nThere exists a sequence of white squares (x_0, y_0), \\ldots, (x_n, y_n) satisfying the following conditions:\n\n(x_0, y_0) = (a, b)\n\n(x_n, y_n) = (c, d)\n\nFor every i (0 \\leq i \\leq n-1), (x_i, y_i) and (x_{i+1}, y_{i+1}) share a side.\n\nConstraints\n\n1 \\leq Q \\leq 10000\n\n1 \\leq a_i, b_i, c_i, d_i \\leq 3^{30}\n\n(a_i, b_i) \\neq (c_i, d_i)\n\n(a_i, b_i) and (c_i, d_i) are white squares.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nQ\na_1 \\ b_1 \\ c_1 \\ d_1\n:\na_Q \\ b_Q \\ c_Q \\ d_Q\n\nOutput\n\nPrint Q lines.\nThe i-th line should contain the distance from (a_i, b_i) to (c_i, d_i).\n\nSample Input 1\n\n2\n4 2 7 4\n9 9 1 9\n\nSample Output 1\n\n5\n8", "sample_input": "2\n4 2 7 4\n9 9 1 9\n"}, "reference_outputs": ["5\n8\n"], "source_document_id": "p02746", "source_text": "Score : 600 points\n\nProblem Statement\n\nFor a non-negative integer K, we define a fractal of level K as follows:\n\nA fractal of level 0 is a grid with just one white square.\n\nWhen K > 0, a fractal of level K is a 3^K \\times 3^K grid. If we divide this grid into nine 3^{K-1} \\times 3^{K-1} subgrids:\n\nThe central subgrid consists of only black squares.\n\nEach of the other eight subgrids is a fractal of level K-1.\n\nFor example, a fractal of level 2 is as follows:\n\nIn a fractal of level 30, let (r, c) denote the square at the r-th row from the top and the c-th column from the left.\n\nYou are given Q quadruples of integers (a_i, b_i, c_i, d_i).\nFor each quadruple, find the distance from (a_i, b_i) to (c_i, d_i).\n\nHere the distance from (a, b) to (c, d) is the minimum integer n that satisfies the following condition:\n\nThere exists a sequence of white squares (x_0, y_0), \\ldots, (x_n, y_n) satisfying the following conditions:\n\n(x_0, y_0) = (a, b)\n\n(x_n, y_n) = (c, d)\n\nFor every i (0 \\leq i \\leq n-1), (x_i, y_i) and (x_{i+1}, y_{i+1}) share a side.\n\nConstraints\n\n1 \\leq Q \\leq 10000\n\n1 \\leq a_i, b_i, c_i, d_i \\leq 3^{30}\n\n(a_i, b_i) \\neq (c_i, d_i)\n\n(a_i, b_i) and (c_i, d_i) are white squares.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nQ\na_1 \\ b_1 \\ c_1 \\ d_1\n:\na_Q \\ b_Q \\ c_Q \\ d_Q\n\nOutput\n\nPrint Q lines.\nThe i-th line should contain the distance from (a_i, b_i) to (c_i, d_i).\n\nSample Input 1\n\n2\n4 2 7 4\n9 9 1 9\n\nSample Output 1\n\n5\n8", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7167, "cpu_time_ms": 357, "memory_kb": 35044}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s043943351", "group_id": "codeNet:p02748", "input_text": "(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare (inline read-byte)\n #-swank (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (read-byte in nil 0))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n\t (let* ((byte (%read-byte)))\n\t (if (<= 48 byte 57)\n\t (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))\n\t (return (if minus (- result) result))))))))\n\n(defun main ()\n (let* ((a-num (read))\n\t (b-num (read))\n\t (m-num (read))\n\t (a-price (make-array a-num))\n\t (b-price (make-array b-num))\n\t (price 100000))\n (dotimes (n a-num)\n (setf (aref a-price n) (read-fixnum)))\n (dotimes (n b-num)\n (setf (aref b-price n) (read-fixnum)))\n (dotimes (i m-num)\n (let* ((a-disc-idx (read-fixnum))\n\t (b-disc-idx (read-fixnum))\n\t (disc-price (read-fixnum))\n\t (result (- (+ (aref a-price (1- a-disc-idx)) (aref b-price (1- b-disc-idx))) disc-price)))\n\t(if (< result price) \n\t (setq price result))))\n (setq a-price (sort a-price #'<))\n (setq b-price (sort b-price #'<))\n (if (< (+ (aref a-price 0) (aref b-price 0)) price)\n\t(setq price (+ (aref a-price 0) (aref b-price 0))))\n (format t \"~a~%\" price)))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1583721058, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02748.html", "problem_id": "p02748", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02748/input.txt", "sample_output_relpath": "derived/input_output/data/p02748/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02748/Lisp/s043943351.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s043943351", "user_id": "u238424961"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare (inline read-byte)\n #-swank (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (read-byte in nil 0))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n\t (let* ((byte (%read-byte)))\n\t (if (<= 48 byte 57)\n\t (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))\n\t (return (if minus (- result) result))))))))\n\n(defun main ()\n (let* ((a-num (read))\n\t (b-num (read))\n\t (m-num (read))\n\t (a-price (make-array a-num))\n\t (b-price (make-array b-num))\n\t (price 100000))\n (dotimes (n a-num)\n (setf (aref a-price n) (read-fixnum)))\n (dotimes (n b-num)\n (setf (aref b-price n) (read-fixnum)))\n (dotimes (i m-num)\n (let* ((a-disc-idx (read-fixnum))\n\t (b-disc-idx (read-fixnum))\n\t (disc-price (read-fixnum))\n\t (result (- (+ (aref a-price (1- a-disc-idx)) (aref b-price (1- b-disc-idx))) disc-price)))\n\t(if (< result price) \n\t (setq price result))))\n (setq a-price (sort a-price #'<))\n (setq b-price (sort b-price #'<))\n (if (< (+ (aref a-price 0) (aref b-price 0)) price)\n\t(setq price (+ (aref a-price 0) (aref b-price 0))))\n (format t \"~a~%\" price)))\n\n(main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are visiting a large electronics store to buy a refrigerator and a microwave.\n\nThe store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \\le i \\le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \\le j \\le B ) is sold at b_j yen.\n\nYou have M discount tickets. With the i-th ticket ( 1 \\le i \\le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time.\n\nYou are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\le A \\le 10^5\n\n1 \\le B \\le 10^5\n\n1 \\le M \\le 10^5\n\n1 \\le a_i , b_i , c_i \\le 10^5\n\n1 \\le x_i \\le A\n\n1 \\le y_i \\le B\n\nc_i \\le a_{x_i} + b_{y_i}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B M\na_1 a_2 ... a_A\nb_1 b_2 ... b_B\nx_1 y_1 c_1\n\\vdots\nx_M y_M c_M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n2 3 1\n3 3\n3 3 3\n1 2 1\n\nSample Output 1\n\n5\n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for 3+3-1=5 yen.\n\nSample Input 2\n\n1 1 2\n10\n10\n1 1 5\n1 1 10\n\nSample Output 2\n\n10\n\nNote that you cannot use more than one ticket at a time.\n\nSample Input 3\n\n2 2 1\n3 5\n3 5\n2 2 2\n\nSample Output 3\n\n6\n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is the minimum amount to pay in this case.\nNote that using a ticket is optional.", "sample_input": "2 3 1\n3 3\n3 3 3\n1 2 1\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02748", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are visiting a large electronics store to buy a refrigerator and a microwave.\n\nThe store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \\le i \\le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \\le j \\le B ) is sold at b_j yen.\n\nYou have M discount tickets. With the i-th ticket ( 1 \\le i \\le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time.\n\nYou are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\le A \\le 10^5\n\n1 \\le B \\le 10^5\n\n1 \\le M \\le 10^5\n\n1 \\le a_i , b_i , c_i \\le 10^5\n\n1 \\le x_i \\le A\n\n1 \\le y_i \\le B\n\nc_i \\le a_{x_i} + b_{y_i}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B M\na_1 a_2 ... a_A\nb_1 b_2 ... b_B\nx_1 y_1 c_1\n\\vdots\nx_M y_M c_M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n2 3 1\n3 3\n3 3 3\n1 2 1\n\nSample Output 1\n\n5\n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for 3+3-1=5 yen.\n\nSample Input 2\n\n1 1 2\n10\n10\n1 1 5\n1 1 10\n\nSample Output 2\n\n10\n\nNote that you cannot use more than one ticket at a time.\n\nSample Input 3\n\n2 2 1\n3 5\n3 5\n2 2 2\n\nSample Output 3\n\n6\n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is the minimum amount to pay in this case.\nNote that using a ticket is optional.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1873, "cpu_time_ms": 193, "memory_kb": 22628}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s814156303", "group_id": "codeNet:p02748", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((a (read))\n (b (read))\n (m (read))\n (as (make-array a :element-type 'uint32))\n (bs (make-array b :element-type 'uint32)))\n (dotimes (i a)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i b)\n (setf (aref bs i) (read-fixnum)))\n (let ((res (+ (reduce #'min as)\n (reduce #'min bs))))\n (dotimes (i m)\n (let ((x (- (read-fixnum) 1))\n (y (- (read-fixnum) 1))\n (c (read-fixnum)))\n (minf res (- (+ (aref as x)\n (aref bs y))\n c))))\n (println res))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 3 1\n3 3\n3 3 3\n1 2 1\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 1 2\n10\n10\n1 1 5\n1 1 10\n\"\n \"10\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 2 1\n3 5\n3 5\n2 2 2\n\"\n \"6\n\")))\n", "language": "Lisp", "metadata": {"date": 1583715860, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02748.html", "problem_id": "p02748", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02748/input.txt", "sample_output_relpath": "derived/input_output/data/p02748/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02748/Lisp/s814156303.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s814156303", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((a (read))\n (b (read))\n (m (read))\n (as (make-array a :element-type 'uint32))\n (bs (make-array b :element-type 'uint32)))\n (dotimes (i a)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i b)\n (setf (aref bs i) (read-fixnum)))\n (let ((res (+ (reduce #'min as)\n (reduce #'min bs))))\n (dotimes (i m)\n (let ((x (- (read-fixnum) 1))\n (y (- (read-fixnum) 1))\n (c (read-fixnum)))\n (minf res (- (+ (aref as x)\n (aref bs y))\n c))))\n (println res))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 3 1\n3 3\n3 3 3\n1 2 1\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 1 2\n10\n10\n1 1 5\n1 1 10\n\"\n \"10\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 2 1\n3 5\n3 5\n2 2 2\n\"\n \"6\n\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are visiting a large electronics store to buy a refrigerator and a microwave.\n\nThe store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \\le i \\le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \\le j \\le B ) is sold at b_j yen.\n\nYou have M discount tickets. With the i-th ticket ( 1 \\le i \\le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time.\n\nYou are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\le A \\le 10^5\n\n1 \\le B \\le 10^5\n\n1 \\le M \\le 10^5\n\n1 \\le a_i , b_i , c_i \\le 10^5\n\n1 \\le x_i \\le A\n\n1 \\le y_i \\le B\n\nc_i \\le a_{x_i} + b_{y_i}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B M\na_1 a_2 ... a_A\nb_1 b_2 ... b_B\nx_1 y_1 c_1\n\\vdots\nx_M y_M c_M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n2 3 1\n3 3\n3 3 3\n1 2 1\n\nSample Output 1\n\n5\n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for 3+3-1=5 yen.\n\nSample Input 2\n\n1 1 2\n10\n10\n1 1 5\n1 1 10\n\nSample Output 2\n\n10\n\nNote that you cannot use more than one ticket at a time.\n\nSample Input 3\n\n2 2 1\n3 5\n3 5\n2 2 2\n\nSample Output 3\n\n6\n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is the minimum amount to pay in this case.\nNote that using a ticket is optional.", "sample_input": "2 3 1\n3 3\n3 3 3\n1 2 1\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02748", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are visiting a large electronics store to buy a refrigerator and a microwave.\n\nThe store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \\le i \\le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \\le j \\le B ) is sold at b_j yen.\n\nYou have M discount tickets. With the i-th ticket ( 1 \\le i \\le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time.\n\nYou are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\le A \\le 10^5\n\n1 \\le B \\le 10^5\n\n1 \\le M \\le 10^5\n\n1 \\le a_i , b_i , c_i \\le 10^5\n\n1 \\le x_i \\le A\n\n1 \\le y_i \\le B\n\nc_i \\le a_{x_i} + b_{y_i}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B M\na_1 a_2 ... a_A\nb_1 b_2 ... b_B\nx_1 y_1 c_1\n\\vdots\nx_M y_M c_M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n2 3 1\n3 3\n3 3 3\n1 2 1\n\nSample Output 1\n\n5\n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for 3+3-1=5 yen.\n\nSample Input 2\n\n1 1 2\n10\n10\n1 1 5\n1 1 10\n\nSample Output 2\n\n10\n\nNote that you cannot use more than one ticket at a time.\n\nSample Input 3\n\n2 2 1\n3 5\n3 5\n2 2 2\n\nSample Output 3\n\n6\n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is the minimum amount to pay in this case.\nNote that using a ticket is optional.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5659, "cpu_time_ms": 471, "memory_kb": 28520}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s587866216", "group_id": "codeNet:p02750", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #x7fffffff)\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (limit (read))\n (bs (make-array n :element-type 'uint32 :fill-pointer 0))\n (abs (make-array n :element-type '(cons uint31 uint31) :fill-pointer 0)))\n (declare (uint31 n limit))\n (dotimes (i n)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (if (zerop a)\n (vector-push (+ b 1) bs)\n (vector-push (cons a b) abs))))\n (setq bs (sort bs #'<))\n (setq abs (sort abs\n (lambda (node1 node2)\n (let ((a1 (car node1))\n (b1 (cdr node1))\n (a2 (car node2))\n (b2 (cdr node2)))\n (declare (uint31 a1 b1 a2 b2))\n (<= (* a2 (+ b1 1)) (* a1 (+ b2 1)))))))\n (let* ((n1 (length abs))\n (n2 (length bs))\n (cumuls (make-array (+ n2 1) :element-type 'uint31 :initial-element 0))\n (dp (make-array '(200001 31) :element-type 'uint31 :initial-element +inf+)))\n (setf (aref dp 0 0) 0)\n (dotimes (i n2)\n (setf (aref cumuls (+ i 1))\n (min +inf+ (+ (aref cumuls i) (aref bs i)))))\n (dotimes (x n1)\n (destructuring-bind (a . b) (aref abs x)\n (declare (uint31 a b))\n (dotimes (y 31)\n (minf (aref dp (+ x 1) y) (aref dp x y))\n (when (< y 30)\n (minf (aref dp (+ x 1) (+ y 1))\n (+ b (* (+ a 1) (+ (aref dp x y) 1))))))))\n (let ((res 0))\n (declare (uint31 res))\n (loop for y from 30 downto 0\n for pos = n2\n do (loop for x from n1 downto 0\n do (loop until (or (<= (+ (aref dp x y) (aref cumuls pos)) limit)\n (zerop pos))\n do (decf pos))\n (when (<= (+ (aref dp x y) (aref cumuls pos)) limit)\n (maxf res (+ y pos)))))\n (println res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 7\n2 0\n3 2\n0 3\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 3\n0 3\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 21600\n2 14\n3 22\n1 3\n1 10\n1 9\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7 57\n0 25\n3 10\n2 4\n5 15\n3 22\n2 14\n1 15\n\"\n \"3\n\")))\n", "language": "Lisp", "metadata": {"date": 1585802929, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02750.html", "problem_id": "p02750", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02750/input.txt", "sample_output_relpath": "derived/input_output/data/p02750/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02750/Lisp/s587866216.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s587866216", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #x7fffffff)\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (limit (read))\n (bs (make-array n :element-type 'uint32 :fill-pointer 0))\n (abs (make-array n :element-type '(cons uint31 uint31) :fill-pointer 0)))\n (declare (uint31 n limit))\n (dotimes (i n)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (if (zerop a)\n (vector-push (+ b 1) bs)\n (vector-push (cons a b) abs))))\n (setq bs (sort bs #'<))\n (setq abs (sort abs\n (lambda (node1 node2)\n (let ((a1 (car node1))\n (b1 (cdr node1))\n (a2 (car node2))\n (b2 (cdr node2)))\n (declare (uint31 a1 b1 a2 b2))\n (<= (* a2 (+ b1 1)) (* a1 (+ b2 1)))))))\n (let* ((n1 (length abs))\n (n2 (length bs))\n (cumuls (make-array (+ n2 1) :element-type 'uint31 :initial-element 0))\n (dp (make-array '(200001 31) :element-type 'uint31 :initial-element +inf+)))\n (setf (aref dp 0 0) 0)\n (dotimes (i n2)\n (setf (aref cumuls (+ i 1))\n (min +inf+ (+ (aref cumuls i) (aref bs i)))))\n (dotimes (x n1)\n (destructuring-bind (a . b) (aref abs x)\n (declare (uint31 a b))\n (dotimes (y 31)\n (minf (aref dp (+ x 1) y) (aref dp x y))\n (when (< y 30)\n (minf (aref dp (+ x 1) (+ y 1))\n (+ b (* (+ a 1) (+ (aref dp x y) 1))))))))\n (let ((res 0))\n (declare (uint31 res))\n (loop for y from 30 downto 0\n for pos = n2\n do (loop for x from n1 downto 0\n do (loop until (or (<= (+ (aref dp x y) (aref cumuls pos)) limit)\n (zerop pos))\n do (decf pos))\n (when (<= (+ (aref dp x y) (aref cumuls pos)) limit)\n (maxf res (+ y pos)))))\n (println res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 7\n2 0\n3 2\n0 3\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 3\n0 3\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 21600\n2 14\n3 22\n1 3\n1 10\n1 9\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7 57\n0 25\n3 10\n2 4\n5 15\n3 22\n2 14\n1 15\n\"\n \"3\n\")))\n", "problem_context": "Score : 800 points\n\nProblem Statement\n\nThere are N stores called Store 1, Store 2, \\cdots, Store N. Takahashi, who is at his house at time 0, is planning to visit some of these stores.\n\nIt takes Takahashi one unit of time to travel from his house to one of the stores, or between any two stores.\n\nIf Takahashi reaches Store i at time t, he can do shopping there after standing in a queue for a_i \\times t + b_i units of time. (We assume that it takes no time other than waiting.)\n\nAll the stores close at time T + 0.5. If Takahashi is standing in a queue for some store then, he cannot do shopping there.\n\nTakahashi does not do shopping more than once in the same store.\n\nFind the maximum number of times he can do shopping before time T + 0.5.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 2 \\times 10^5\n\n0 \\leq a_i \\leq 10^9\n\n0 \\leq b_i \\leq 10^9\n\n0 \\leq T \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN T\na_1 b_1\na_2 b_2\n\\vdots\na_N b_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3 7\n2 0\n3 2\n0 3\n\nSample Output 1\n\n2\n\nHere is one possible way to visit stores:\n\nFrom time 0 to time 1: in 1 unit of time, he travels from his house to Store 1.\n\nFrom time 1 to time 3: for 2 units of time, he stands in a queue for Store 1 to do shopping.\n\nFrom time 3 to time 4: in 1 unit of time, he travels from Store 1 to Store 3.\n\nFrom time 4 to time 7: for 3 units of time, he stands in a queue for Store 3 to do shopping.\n\nIn this way, he can do shopping twice before time 7.5.\n\nSample Input 2\n\n1 3\n0 3\n\nSample Output 2\n\n0\n\nSample Input 3\n\n5 21600\n2 14\n3 22\n1 3\n1 10\n1 9\n\nSample Output 3\n\n5\n\nSample Input 4\n\n7 57\n0 25\n3 10\n2 4\n5 15\n3 22\n2 14\n1 15\n\nSample Output 4\n\n3", "sample_input": "3 7\n2 0\n3 2\n0 3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02750", "source_text": "Score : 800 points\n\nProblem Statement\n\nThere are N stores called Store 1, Store 2, \\cdots, Store N. Takahashi, who is at his house at time 0, is planning to visit some of these stores.\n\nIt takes Takahashi one unit of time to travel from his house to one of the stores, or between any two stores.\n\nIf Takahashi reaches Store i at time t, he can do shopping there after standing in a queue for a_i \\times t + b_i units of time. (We assume that it takes no time other than waiting.)\n\nAll the stores close at time T + 0.5. If Takahashi is standing in a queue for some store then, he cannot do shopping there.\n\nTakahashi does not do shopping more than once in the same store.\n\nFind the maximum number of times he can do shopping before time T + 0.5.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 2 \\times 10^5\n\n0 \\leq a_i \\leq 10^9\n\n0 \\leq b_i \\leq 10^9\n\n0 \\leq T \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN T\na_1 b_1\na_2 b_2\n\\vdots\na_N b_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3 7\n2 0\n3 2\n0 3\n\nSample Output 1\n\n2\n\nHere is one possible way to visit stores:\n\nFrom time 0 to time 1: in 1 unit of time, he travels from his house to Store 1.\n\nFrom time 1 to time 3: for 2 units of time, he stands in a queue for Store 1 to do shopping.\n\nFrom time 3 to time 4: in 1 unit of time, he travels from Store 1 to Store 3.\n\nFrom time 4 to time 7: for 3 units of time, he stands in a queue for Store 3 to do shopping.\n\nIn this way, he can do shopping twice before time 7.5.\n\nSample Input 2\n\n1 3\n0 3\n\nSample Output 2\n\n0\n\nSample Input 3\n\n5 21600\n2 14\n3 22\n1 3\n1 10\n1 9\n\nSample Output 3\n\n5\n\nSample Input 4\n\n7 57\n0 25\n3 10\n2 4\n5 15\n3 22\n2 14\n1 15\n\nSample Output 4\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7236, "cpu_time_ms": 421, "memory_kb": 74340}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s639021207", "group_id": "codeNet:p02750", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare (inline sort))\n (let* ((n (read))\n (limit (read))\n (bs (make-array n :element-type 'uint32 :fill-pointer 0))\n (abs (make-array n :element-type '(cons uint31 uint31) :fill-pointer 0)))\n (dotimes (i n)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (if (zerop a)\n (vector-push (+ b 1) bs)\n (vector-push (cons a b) abs))))\n (setq abs (sort abs\n (lambda (node1 node2)\n (let ((a1 (car node1))\n (b1 (cdr node1))\n (a2 (car node2))\n (b2 (cdr node2)))\n (declare (uint31 a1 b1 a2 b2))\n (<= (* a2 (+ b1 1)) (* a1 (+ b2 1)))))))\n (let* ((n1 (length abs))\n (n2 (length bs))\n (cumuls (make-array (+ n2 1) :element-type 'uint62 :initial-element 0))\n (dp (make-array (list (+ n1 1) 31)\n :element-type 'uint62\n :initial-element most-positive-fixnum)))\n (setf (aref dp 0 0) 0)\n (dotimes (i n2)\n (setf (aref cumuls (+ i 1))\n (+ (aref cumuls i) (aref bs i))))\n (dotimes (x n1)\n (destructuring-bind (a . b) (aref abs x)\n (declare (uint31 a b))\n (dotimes (y 31)\n (minf (aref dp (+ x 1) y) (aref dp x y))\n (when (< y 30)\n (minf (aref dp (+ x 1) (+ y 1))\n (+ b (* (+ a 1) (+ (aref dp x y) 1))))))))\n #>dp\n #>bs\n #>cumuls\n (let ((res 0))\n (loop for y from 30 downto 0\n for pos = n2\n do (loop for x from n1 downto 0\n do (loop until (or (<= (+ (aref dp x y) (aref cumuls pos)) limit)\n (zerop pos))\n do (decf pos))\n (when (<= (+ (aref dp x y) (aref cumuls pos)) limit)\n (maxf res (+ y pos)))))\n (println res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 7\n2 0\n3 2\n0 3\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 3\n0 3\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 21600\n2 14\n3 22\n1 3\n1 10\n1 9\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7 57\n0 25\n3 10\n2 4\n5 15\n3 22\n2 14\n1 15\n\"\n \"3\n\")))\n", "language": "Lisp", "metadata": {"date": 1585802592, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02750.html", "problem_id": "p02750", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02750/input.txt", "sample_output_relpath": "derived/input_output/data/p02750/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02750/Lisp/s639021207.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s639021207", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare (inline sort))\n (let* ((n (read))\n (limit (read))\n (bs (make-array n :element-type 'uint32 :fill-pointer 0))\n (abs (make-array n :element-type '(cons uint31 uint31) :fill-pointer 0)))\n (dotimes (i n)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (if (zerop a)\n (vector-push (+ b 1) bs)\n (vector-push (cons a b) abs))))\n (setq abs (sort abs\n (lambda (node1 node2)\n (let ((a1 (car node1))\n (b1 (cdr node1))\n (a2 (car node2))\n (b2 (cdr node2)))\n (declare (uint31 a1 b1 a2 b2))\n (<= (* a2 (+ b1 1)) (* a1 (+ b2 1)))))))\n (let* ((n1 (length abs))\n (n2 (length bs))\n (cumuls (make-array (+ n2 1) :element-type 'uint62 :initial-element 0))\n (dp (make-array (list (+ n1 1) 31)\n :element-type 'uint62\n :initial-element most-positive-fixnum)))\n (setf (aref dp 0 0) 0)\n (dotimes (i n2)\n (setf (aref cumuls (+ i 1))\n (+ (aref cumuls i) (aref bs i))))\n (dotimes (x n1)\n (destructuring-bind (a . b) (aref abs x)\n (declare (uint31 a b))\n (dotimes (y 31)\n (minf (aref dp (+ x 1) y) (aref dp x y))\n (when (< y 30)\n (minf (aref dp (+ x 1) (+ y 1))\n (+ b (* (+ a 1) (+ (aref dp x y) 1))))))))\n #>dp\n #>bs\n #>cumuls\n (let ((res 0))\n (loop for y from 30 downto 0\n for pos = n2\n do (loop for x from n1 downto 0\n do (loop until (or (<= (+ (aref dp x y) (aref cumuls pos)) limit)\n (zerop pos))\n do (decf pos))\n (when (<= (+ (aref dp x y) (aref cumuls pos)) limit)\n (maxf res (+ y pos)))))\n (println res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 7\n2 0\n3 2\n0 3\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 3\n0 3\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 21600\n2 14\n3 22\n1 3\n1 10\n1 9\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7 57\n0 25\n3 10\n2 4\n5 15\n3 22\n2 14\n1 15\n\"\n \"3\n\")))\n", "problem_context": "Score : 800 points\n\nProblem Statement\n\nThere are N stores called Store 1, Store 2, \\cdots, Store N. Takahashi, who is at his house at time 0, is planning to visit some of these stores.\n\nIt takes Takahashi one unit of time to travel from his house to one of the stores, or between any two stores.\n\nIf Takahashi reaches Store i at time t, he can do shopping there after standing in a queue for a_i \\times t + b_i units of time. (We assume that it takes no time other than waiting.)\n\nAll the stores close at time T + 0.5. If Takahashi is standing in a queue for some store then, he cannot do shopping there.\n\nTakahashi does not do shopping more than once in the same store.\n\nFind the maximum number of times he can do shopping before time T + 0.5.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 2 \\times 10^5\n\n0 \\leq a_i \\leq 10^9\n\n0 \\leq b_i \\leq 10^9\n\n0 \\leq T \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN T\na_1 b_1\na_2 b_2\n\\vdots\na_N b_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3 7\n2 0\n3 2\n0 3\n\nSample Output 1\n\n2\n\nHere is one possible way to visit stores:\n\nFrom time 0 to time 1: in 1 unit of time, he travels from his house to Store 1.\n\nFrom time 1 to time 3: for 2 units of time, he stands in a queue for Store 1 to do shopping.\n\nFrom time 3 to time 4: in 1 unit of time, he travels from Store 1 to Store 3.\n\nFrom time 4 to time 7: for 3 units of time, he stands in a queue for Store 3 to do shopping.\n\nIn this way, he can do shopping twice before time 7.5.\n\nSample Input 2\n\n1 3\n0 3\n\nSample Output 2\n\n0\n\nSample Input 3\n\n5 21600\n2 14\n3 22\n1 3\n1 10\n1 9\n\nSample Output 3\n\n5\n\nSample Input 4\n\n7 57\n0 25\n3 10\n2 4\n5 15\n3 22\n2 14\n1 15\n\nSample Output 4\n\n3", "sample_input": "3 7\n2 0\n3 2\n0 3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02750", "source_text": "Score : 800 points\n\nProblem Statement\n\nThere are N stores called Store 1, Store 2, \\cdots, Store N. Takahashi, who is at his house at time 0, is planning to visit some of these stores.\n\nIt takes Takahashi one unit of time to travel from his house to one of the stores, or between any two stores.\n\nIf Takahashi reaches Store i at time t, he can do shopping there after standing in a queue for a_i \\times t + b_i units of time. (We assume that it takes no time other than waiting.)\n\nAll the stores close at time T + 0.5. If Takahashi is standing in a queue for some store then, he cannot do shopping there.\n\nTakahashi does not do shopping more than once in the same store.\n\nFind the maximum number of times he can do shopping before time T + 0.5.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 2 \\times 10^5\n\n0 \\leq a_i \\leq 10^9\n\n0 \\leq b_i \\leq 10^9\n\n0 \\leq T \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN T\na_1 b_1\na_2 b_2\n\\vdots\na_N b_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3 7\n2 0\n3 2\n0 3\n\nSample Output 1\n\n2\n\nHere is one possible way to visit stores:\n\nFrom time 0 to time 1: in 1 unit of time, he travels from his house to Store 1.\n\nFrom time 1 to time 3: for 2 units of time, he stands in a queue for Store 1 to do shopping.\n\nFrom time 3 to time 4: in 1 unit of time, he travels from Store 1 to Store 3.\n\nFrom time 4 to time 7: for 3 units of time, he stands in a queue for Store 3 to do shopping.\n\nIn this way, he can do shopping twice before time 7.5.\n\nSample Input 2\n\n1 3\n0 3\n\nSample Output 2\n\n0\n\nSample Input 3\n\n5 21600\n2 14\n3 22\n1 3\n1 10\n1 9\n\nSample Output 3\n\n5\n\nSample Input 4\n\n7 57\n0 25\n3 10\n2 4\n5 15\n3 22\n2 14\n1 15\n\nSample Output 4\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7197, "cpu_time_ms": 1032, "memory_kb": 115332}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s858205148", "group_id": "codeNet:p02754", "input_text": "(let* ((N (read))\n (A (read))\n (B (read)))\n (if (= A 0)\n (princ 0)\n (let ((ans (* (/ N (+ A B)) A))\n (remainder (mod N (+ A B))))\n (princ (floor (+ ans (if (< remainder A) remainder A)))))))\n", "language": "Lisp", "metadata": {"date": 1583761086, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02754.html", "problem_id": "p02754", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02754/input.txt", "sample_output_relpath": "derived/input_output/data/p02754/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02754/Lisp/s858205148.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s858205148", "user_id": "u631655863"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let* ((N (read))\n (A (read))\n (B (read)))\n (if (= A 0)\n (princ 0)\n (let ((ans (* (/ N (+ A B)) A))\n (remainder (mod N (+ A B))))\n (princ (floor (+ ans (if (< remainder A) remainder A)))))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi has many red balls and blue balls. Now, he will place them in a row.\n\nInitially, there is no ball placed.\n\nTakahashi, who is very patient, will do the following operation 10^{100} times:\n\nPlace A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.\n\nHow many blue balls will be there among the first N balls in the row of balls made this way?\n\nConstraints\n\n1 \\leq N \\leq 10^{18}\n\nA, B \\geq 0\n\n0 < A + B \\leq 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint the number of blue balls that will be there among the first N balls in the row of balls.\n\nSample Input 1\n\n8 3 4\n\nSample Output 1\n\n4\n\nLet b denote a blue ball, and r denote a red ball. The first eight balls in the row will be bbbrrrrb, among which there are four blue balls.\n\nSample Input 2\n\n8 0 4\n\nSample Output 2\n\n0\n\nHe placed only red balls from the beginning.\n\nSample Input 3\n\n6 2 4\n\nSample Output 3\n\n2\n\nAmong bbrrrr, there are two blue balls.", "sample_input": "8 3 4\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02754", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi has many red balls and blue balls. Now, he will place them in a row.\n\nInitially, there is no ball placed.\n\nTakahashi, who is very patient, will do the following operation 10^{100} times:\n\nPlace A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.\n\nHow many blue balls will be there among the first N balls in the row of balls made this way?\n\nConstraints\n\n1 \\leq N \\leq 10^{18}\n\nA, B \\geq 0\n\n0 < A + B \\leq 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint the number of blue balls that will be there among the first N balls in the row of balls.\n\nSample Input 1\n\n8 3 4\n\nSample Output 1\n\n4\n\nLet b denote a blue ball, and r denote a red ball. The first eight balls in the row will be bbbrrrrb, among which there are four blue balls.\n\nSample Input 2\n\n8 0 4\n\nSample Output 2\n\n0\n\nHe placed only red balls from the beginning.\n\nSample Input 3\n\n6 2 4\n\nSample Output 3\n\n2\n\nAmong bbrrrr, there are two blue balls.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 235, "cpu_time_ms": 150, "memory_kb": 13416}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s347146512", "group_id": "codeNet:p02754", "input_text": "(let* ((N (read))\n (A (read))\n (tmp (+ A (read)))\n (ans (/ (float N) tmp))\n (remainder (mod (float N) tmp)))\n (if (= A 0)\n (princ 0)\n (princ (+ ans (floor (if (< remainder A) remainder A))))))\n", "language": "Lisp", "metadata": {"date": 1583723785, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02754.html", "problem_id": "p02754", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02754/input.txt", "sample_output_relpath": "derived/input_output/data/p02754/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02754/Lisp/s347146512.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s347146512", "user_id": "u631655863"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let* ((N (read))\n (A (read))\n (tmp (+ A (read)))\n (ans (/ (float N) tmp))\n (remainder (mod (float N) tmp)))\n (if (= A 0)\n (princ 0)\n (princ (+ ans (floor (if (< remainder A) remainder A))))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi has many red balls and blue balls. Now, he will place them in a row.\n\nInitially, there is no ball placed.\n\nTakahashi, who is very patient, will do the following operation 10^{100} times:\n\nPlace A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.\n\nHow many blue balls will be there among the first N balls in the row of balls made this way?\n\nConstraints\n\n1 \\leq N \\leq 10^{18}\n\nA, B \\geq 0\n\n0 < A + B \\leq 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint the number of blue balls that will be there among the first N balls in the row of balls.\n\nSample Input 1\n\n8 3 4\n\nSample Output 1\n\n4\n\nLet b denote a blue ball, and r denote a red ball. The first eight balls in the row will be bbbrrrrb, among which there are four blue balls.\n\nSample Input 2\n\n8 0 4\n\nSample Output 2\n\n0\n\nHe placed only red balls from the beginning.\n\nSample Input 3\n\n6 2 4\n\nSample Output 3\n\n2\n\nAmong bbrrrr, there are two blue balls.", "sample_input": "8 3 4\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02754", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi has many red balls and blue balls. Now, he will place them in a row.\n\nInitially, there is no ball placed.\n\nTakahashi, who is very patient, will do the following operation 10^{100} times:\n\nPlace A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.\n\nHow many blue balls will be there among the first N balls in the row of balls made this way?\n\nConstraints\n\n1 \\leq N \\leq 10^{18}\n\nA, B \\geq 0\n\n0 < A + B \\leq 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint the number of blue balls that will be there among the first N balls in the row of balls.\n\nSample Input 1\n\n8 3 4\n\nSample Output 1\n\n4\n\nLet b denote a blue ball, and r denote a red ball. The first eight balls in the row will be bbbrrrrb, among which there are four blue balls.\n\nSample Input 2\n\n8 0 4\n\nSample Output 2\n\n0\n\nHe placed only red balls from the beginning.\n\nSample Input 3\n\n6 2 4\n\nSample Output 3\n\n2\n\nAmong bbrrrr, there are two blue balls.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 233, "cpu_time_ms": 132, "memory_kb": 13928}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s484474252", "group_id": "codeNet:p02754", "input_text": "(format t \"~d~%\"\n\t(loop with n = (read)\n\t with a = (read)\n\t with b = (read)\n\t repeat (expt 10 100)\n\t sum a into i\n\t sum a into r\n\t thereis (and (< n i)\n\t\t\t(- r (- i n)))\n\t sum b into i\n\t thereis (and (< n i) r)))", "language": "Lisp", "metadata": {"date": 1583689510, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02754.html", "problem_id": "p02754", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02754/input.txt", "sample_output_relpath": "derived/input_output/data/p02754/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02754/Lisp/s484474252.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s484474252", "user_id": "u320993798"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(format t \"~d~%\"\n\t(loop with n = (read)\n\t with a = (read)\n\t with b = (read)\n\t repeat (expt 10 100)\n\t sum a into i\n\t sum a into r\n\t thereis (and (< n i)\n\t\t\t(- r (- i n)))\n\t sum b into i\n\t thereis (and (< n i) r)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi has many red balls and blue balls. Now, he will place them in a row.\n\nInitially, there is no ball placed.\n\nTakahashi, who is very patient, will do the following operation 10^{100} times:\n\nPlace A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.\n\nHow many blue balls will be there among the first N balls in the row of balls made this way?\n\nConstraints\n\n1 \\leq N \\leq 10^{18}\n\nA, B \\geq 0\n\n0 < A + B \\leq 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint the number of blue balls that will be there among the first N balls in the row of balls.\n\nSample Input 1\n\n8 3 4\n\nSample Output 1\n\n4\n\nLet b denote a blue ball, and r denote a red ball. The first eight balls in the row will be bbbrrrrb, among which there are four blue balls.\n\nSample Input 2\n\n8 0 4\n\nSample Output 2\n\n0\n\nHe placed only red balls from the beginning.\n\nSample Input 3\n\n6 2 4\n\nSample Output 3\n\n2\n\nAmong bbrrrr, there are two blue balls.", "sample_input": "8 3 4\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02754", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi has many red balls and blue balls. Now, he will place them in a row.\n\nInitially, there is no ball placed.\n\nTakahashi, who is very patient, will do the following operation 10^{100} times:\n\nPlace A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.\n\nHow many blue balls will be there among the first N balls in the row of balls made this way?\n\nConstraints\n\n1 \\leq N \\leq 10^{18}\n\nA, B \\geq 0\n\n0 < A + B \\leq 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint the number of blue balls that will be there among the first N balls in the row of balls.\n\nSample Input 1\n\n8 3 4\n\nSample Output 1\n\n4\n\nLet b denote a blue ball, and r denote a red ball. The first eight balls in the row will be bbbrrrrb, among which there are four blue balls.\n\nSample Input 2\n\n8 0 4\n\nSample Output 2\n\n0\n\nHe placed only red balls from the beginning.\n\nSample Input 3\n\n6 2 4\n\nSample Output 3\n\n2\n\nAmong bbrrrr, there are two blue balls.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 228, "cpu_time_ms": 2105, "memory_kb": 59748}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s436002936", "group_id": "codeNet:p02754", "input_text": "(defun count-balls ()\n (let ((n (read))\n (b (read))\n (r (read))\n (ans 0))\n (setf ans (+ (* b (floor n (+ b r))) (min b (rem n (+ b r)))))\n ans))\n \n(format t \"~d~%\" (count-balls))", "language": "Lisp", "metadata": {"date": 1583641221, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02754.html", "problem_id": "p02754", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02754/input.txt", "sample_output_relpath": "derived/input_output/data/p02754/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02754/Lisp/s436002936.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s436002936", "user_id": "u091381267"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun count-balls ()\n (let ((n (read))\n (b (read))\n (r (read))\n (ans 0))\n (setf ans (+ (* b (floor n (+ b r))) (min b (rem n (+ b r)))))\n ans))\n \n(format t \"~d~%\" (count-balls))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi has many red balls and blue balls. Now, he will place them in a row.\n\nInitially, there is no ball placed.\n\nTakahashi, who is very patient, will do the following operation 10^{100} times:\n\nPlace A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.\n\nHow many blue balls will be there among the first N balls in the row of balls made this way?\n\nConstraints\n\n1 \\leq N \\leq 10^{18}\n\nA, B \\geq 0\n\n0 < A + B \\leq 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint the number of blue balls that will be there among the first N balls in the row of balls.\n\nSample Input 1\n\n8 3 4\n\nSample Output 1\n\n4\n\nLet b denote a blue ball, and r denote a red ball. The first eight balls in the row will be bbbrrrrb, among which there are four blue balls.\n\nSample Input 2\n\n8 0 4\n\nSample Output 2\n\n0\n\nHe placed only red balls from the beginning.\n\nSample Input 3\n\n6 2 4\n\nSample Output 3\n\n2\n\nAmong bbrrrr, there are two blue balls.", "sample_input": "8 3 4\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02754", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi has many red balls and blue balls. Now, he will place them in a row.\n\nInitially, there is no ball placed.\n\nTakahashi, who is very patient, will do the following operation 10^{100} times:\n\nPlace A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.\n\nHow many blue balls will be there among the first N balls in the row of balls made this way?\n\nConstraints\n\n1 \\leq N \\leq 10^{18}\n\nA, B \\geq 0\n\n0 < A + B \\leq 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint the number of blue balls that will be there among the first N balls in the row of balls.\n\nSample Input 1\n\n8 3 4\n\nSample Output 1\n\n4\n\nLet b denote a blue ball, and r denote a red ball. The first eight balls in the row will be bbbrrrrb, among which there are four blue balls.\n\nSample Input 2\n\n8 0 4\n\nSample Output 2\n\n0\n\nHe placed only red balls from the beginning.\n\nSample Input 3\n\n6 2 4\n\nSample Output 3\n\n2\n\nAmong bbrrrr, there are two blue balls.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 210, "cpu_time_ms": 140, "memory_kb": 13160}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s130347103", "group_id": "codeNet:p02754", "input_text": "(defun solve (n a b)\n (multiple-value-bind (div quot)\n (truncate n (+ a b))\n (+ (* div a)\n (if (< (- quot a) 0)\n quot\n a))))\n\n#-swank\n(let* ((n (read))\n (a (read))\n (b (read)))\n (format t \"~A~%\" (solve n a b)))\n", "language": "Lisp", "metadata": {"date": 1583633325, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02754.html", "problem_id": "p02754", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02754/input.txt", "sample_output_relpath": "derived/input_output/data/p02754/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02754/Lisp/s130347103.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s130347103", "user_id": "u202886318"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun solve (n a b)\n (multiple-value-bind (div quot)\n (truncate n (+ a b))\n (+ (* div a)\n (if (< (- quot a) 0)\n quot\n a))))\n\n#-swank\n(let* ((n (read))\n (a (read))\n (b (read)))\n (format t \"~A~%\" (solve n a b)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi has many red balls and blue balls. Now, he will place them in a row.\n\nInitially, there is no ball placed.\n\nTakahashi, who is very patient, will do the following operation 10^{100} times:\n\nPlace A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.\n\nHow many blue balls will be there among the first N balls in the row of balls made this way?\n\nConstraints\n\n1 \\leq N \\leq 10^{18}\n\nA, B \\geq 0\n\n0 < A + B \\leq 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint the number of blue balls that will be there among the first N balls in the row of balls.\n\nSample Input 1\n\n8 3 4\n\nSample Output 1\n\n4\n\nLet b denote a blue ball, and r denote a red ball. The first eight balls in the row will be bbbrrrrb, among which there are four blue balls.\n\nSample Input 2\n\n8 0 4\n\nSample Output 2\n\n0\n\nHe placed only red balls from the beginning.\n\nSample Input 3\n\n6 2 4\n\nSample Output 3\n\n2\n\nAmong bbrrrr, there are two blue balls.", "sample_input": "8 3 4\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02754", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi has many red balls and blue balls. Now, he will place them in a row.\n\nInitially, there is no ball placed.\n\nTakahashi, who is very patient, will do the following operation 10^{100} times:\n\nPlace A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.\n\nHow many blue balls will be there among the first N balls in the row of balls made this way?\n\nConstraints\n\n1 \\leq N \\leq 10^{18}\n\nA, B \\geq 0\n\n0 < A + B \\leq 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint the number of blue balls that will be there among the first N balls in the row of balls.\n\nSample Input 1\n\n8 3 4\n\nSample Output 1\n\n4\n\nLet b denote a blue ball, and r denote a red ball. The first eight balls in the row will be bbbrrrrb, among which there are four blue balls.\n\nSample Input 2\n\n8 0 4\n\nSample Output 2\n\n0\n\nHe placed only red balls from the beginning.\n\nSample Input 3\n\n6 2 4\n\nSample Output 3\n\n2\n\nAmong bbrrrr, there are two blue balls.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 259, "cpu_time_ms": 358, "memory_kb": 12392}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s566690812", "group_id": "codeNet:p02755", "input_text": "(let* ((a (read))\n (b (read))\n (c (find-if (lambda (x) (find x (loop for i upfrom (floor b 0.1) repeat 9 collect i)))\n\t\t (loop for i upfrom (floor a 0.08) repeat 12 collect i))))\n (format t \"~:[-1~;~d~]~%\" (and (= a (floor (* c 0.08))) (= b (floor (* c 0.1)))) c))", "language": "Lisp", "metadata": {"date": 1583691401, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02755.html", "problem_id": "p02755", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02755/input.txt", "sample_output_relpath": "derived/input_output/data/p02755/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02755/Lisp/s566690812.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s566690812", "user_id": "u320993798"}, "prompt_components": {"gold_output": "25\n", "input_to_evaluate": "(let* ((a (read))\n (b (read))\n (c (find-if (lambda (x) (find x (loop for i upfrom (floor b 0.1) repeat 9 collect i)))\n\t\t (loop for i upfrom (floor a 0.08) repeat 12 collect i))))\n (format t \"~:[-1~;~d~]~%\" (and (= a (floor (* c 0.08))) (= b (floor (* c 0.1)))) c))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nFind the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.)\n\nHere, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer.\n\nIf multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print -1.\n\nConstraints\n\n1 \\leq A \\leq B \\leq 100\n\nA and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nIf there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print -1.\n\nSample Input 1\n\n2 2\n\nSample Output 1\n\n25\n\nIf the price of a product before tax is 25 yen, the amount of consumption tax levied on it is:\n\nWhen the consumption tax rate is 8 percent: \\lfloor 25 \\times 0.08 \\rfloor = \\lfloor 2 \\rfloor = 2 yen.\n\nWhen the consumption tax rate is 10 percent: \\lfloor 25 \\times 0.1 \\rfloor = \\lfloor 2.5 \\rfloor = 2 yen.\n\nThus, the price of 25 yen satisfies the condition. There are other possible prices, such as 26 yen, but print the minimum such price, 25.\n\nSample Input 2\n\n8 10\n\nSample Output 2\n\n100\n\nIf the price of a product before tax is 100 yen, the amount of consumption tax levied on it is:\n\nWhen the consumption tax rate is 8 percent: \\lfloor 100 \\times 0.08 \\rfloor = 8 yen.\n\nWhen the consumption tax rate is 10 percent: \\lfloor 100 \\times 0.1 \\rfloor = 10 yen.\n\nSample Input 3\n\n19 99\n\nSample Output 3\n\n-1\n\nThere is no price before tax satisfying this condition, so print -1.", "sample_input": "2 2\n"}, "reference_outputs": ["25\n"], "source_document_id": "p02755", "source_text": "Score : 300 points\n\nProblem Statement\n\nFind the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.)\n\nHere, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer.\n\nIf multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print -1.\n\nConstraints\n\n1 \\leq A \\leq B \\leq 100\n\nA and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nIf there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print -1.\n\nSample Input 1\n\n2 2\n\nSample Output 1\n\n25\n\nIf the price of a product before tax is 25 yen, the amount of consumption tax levied on it is:\n\nWhen the consumption tax rate is 8 percent: \\lfloor 25 \\times 0.08 \\rfloor = \\lfloor 2 \\rfloor = 2 yen.\n\nWhen the consumption tax rate is 10 percent: \\lfloor 25 \\times 0.1 \\rfloor = \\lfloor 2.5 \\rfloor = 2 yen.\n\nThus, the price of 25 yen satisfies the condition. There are other possible prices, such as 26 yen, but print the minimum such price, 25.\n\nSample Input 2\n\n8 10\n\nSample Output 2\n\n100\n\nIf the price of a product before tax is 100 yen, the amount of consumption tax levied on it is:\n\nWhen the consumption tax rate is 8 percent: \\lfloor 100 \\times 0.08 \\rfloor = 8 yen.\n\nWhen the consumption tax rate is 10 percent: \\lfloor 100 \\times 0.1 \\rfloor = 10 yen.\n\nSample Input 3\n\n19 99\n\nSample Output 3\n\n-1\n\nThere is no price before tax satisfying this condition, so print -1.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 279, "cpu_time_ms": 56, "memory_kb": 9188}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s921157481", "group_id": "codeNet:p02756", "input_text": "(let* ((s (read-line))\n (q (read))\n (head nil)\n (tail nil)\n (rev 0))\n (loop :for i :from 1 :to q\n :for x := (read)\n :if (= x 1)\n :do (progn\n (incf rev))\n :else\n :do (let ((f (read))\n (c (read-char)))\n (cond ((and (evenp rev) (= f 1))\n (push c head))\n ((and (evenp rev) (= f 2))\n (push c tail))\n ((and (oddp rev) (= f 1))\n (push c tail))\n (t\n (push c head)))))\n (when (oddp rev)\n (rotatef head tail)\n (setf s (reverse s)))\n (loop :for c :in head :do (format t \"~A\" c))\n (format t \"~A\" s)\n (loop :for c :in (reverse tail) :do (format t \"~A\" c))\n (format t \"~%\"))\n", "language": "Lisp", "metadata": {"date": 1594955712, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02756.html", "problem_id": "p02756", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02756/input.txt", "sample_output_relpath": "derived/input_output/data/p02756/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02756/Lisp/s921157481.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s921157481", "user_id": "u608227593"}, "prompt_components": {"gold_output": "cpa\n", "input_to_evaluate": "(let* ((s (read-line))\n (q (read))\n (head nil)\n (tail nil)\n (rev 0))\n (loop :for i :from 1 :to q\n :for x := (read)\n :if (= x 1)\n :do (progn\n (incf rev))\n :else\n :do (let ((f (read))\n (c (read-char)))\n (cond ((and (evenp rev) (= f 1))\n (push c head))\n ((and (evenp rev) (= f 2))\n (push c tail))\n ((and (oddp rev) (= f 1))\n (push c tail))\n (t\n (push c head)))))\n (when (oddp rev)\n (rotatef head tail)\n (setf s (reverse s)))\n (loop :for c :in head :do (format t \"~A\" c))\n (format t \"~A\" s)\n (loop :for c :in (reverse tail) :do (format t \"~A\" c))\n (format t \"~%\"))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nTakahashi has a string S consisting of lowercase English letters.\n\nStarting with this string, he will produce a new one in the procedure given as follows.\n\nThe procedure consists of Q operations. In Operation i (1 \\leq i \\leq Q), an integer T_i is provided, which means the following:\n\nIf T_i = 1: reverse the string S.\n\nIf T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.\n\nIf F_i = 1 : Add C_i to the beginning of the string S.\n\nIf F_i = 2 : Add C_i to the end of the string S.\n\nHelp Takahashi by finding the final string that results from the procedure.\n\nConstraints\n\n1 \\leq |S| \\leq 10^5\n\nS consists of lowercase English letters.\n\n1 \\leq Q \\leq 2 \\times 10^5\n\nT_i = 1 or 2.\n\nF_i = 1 or 2, if provided.\n\nC_i is a lowercase English letter, if provided.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nQ\nQuery_1\n:\nQuery_Q\n\nIn the 3-rd through the (Q+2)-th lines, Query_i is one of the following:\n\n1\n\nwhich means T_i = 1, and:\n\n2 F_i C_i\n\nwhich means T_i = 2.\n\nOutput\n\nPrint the resulting string.\n\nSample Input 1\n\na\n4\n2 1 p\n1\n2 2 c\n1\n\nSample Output 1\n\ncpa\n\nThere will be Q = 4 operations. Initially, S is a.\n\nOperation 1: Add p at the beginning of S. S becomes pa.\n\nOperation 2: Reverse S. S becomes ap.\n\nOperation 3: Add c at the end of S. S becomes apc.\n\nOperation 4: Reverse S. S becomes cpa.\n\nThus, the resulting string is cpa.\n\nSample Input 2\n\na\n6\n2 2 a\n2 1 b\n1\n2 2 c\n1\n1\n\nSample Output 2\n\naabc\n\nThere will be Q = 6 operations. Initially, S is a.\n\nOperation 1: S becomes aa.\n\nOperation 2: S becomes baa.\n\nOperation 3: S becomes aab.\n\nOperation 4: S becomes aabc.\n\nOperation 5: S becomes cbaa.\n\nOperation 6: S becomes aabc.\n\nThus, the resulting string is aabc.\n\nSample Input 3\n\ny\n1\n2 1 x\n\nSample Output 3\n\nxy", "sample_input": "a\n4\n2 1 p\n1\n2 2 c\n1\n"}, "reference_outputs": ["cpa\n"], "source_document_id": "p02756", "source_text": "Score : 400 points\n\nProblem Statement\n\nTakahashi has a string S consisting of lowercase English letters.\n\nStarting with this string, he will produce a new one in the procedure given as follows.\n\nThe procedure consists of Q operations. In Operation i (1 \\leq i \\leq Q), an integer T_i is provided, which means the following:\n\nIf T_i = 1: reverse the string S.\n\nIf T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.\n\nIf F_i = 1 : Add C_i to the beginning of the string S.\n\nIf F_i = 2 : Add C_i to the end of the string S.\n\nHelp Takahashi by finding the final string that results from the procedure.\n\nConstraints\n\n1 \\leq |S| \\leq 10^5\n\nS consists of lowercase English letters.\n\n1 \\leq Q \\leq 2 \\times 10^5\n\nT_i = 1 or 2.\n\nF_i = 1 or 2, if provided.\n\nC_i is a lowercase English letter, if provided.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nQ\nQuery_1\n:\nQuery_Q\n\nIn the 3-rd through the (Q+2)-th lines, Query_i is one of the following:\n\n1\n\nwhich means T_i = 1, and:\n\n2 F_i C_i\n\nwhich means T_i = 2.\n\nOutput\n\nPrint the resulting string.\n\nSample Input 1\n\na\n4\n2 1 p\n1\n2 2 c\n1\n\nSample Output 1\n\ncpa\n\nThere will be Q = 4 operations. Initially, S is a.\n\nOperation 1: Add p at the beginning of S. S becomes pa.\n\nOperation 2: Reverse S. S becomes ap.\n\nOperation 3: Add c at the end of S. S becomes apc.\n\nOperation 4: Reverse S. S becomes cpa.\n\nThus, the resulting string is cpa.\n\nSample Input 2\n\na\n6\n2 2 a\n2 1 b\n1\n2 2 c\n1\n1\n\nSample Output 2\n\naabc\n\nThere will be Q = 6 operations. Initially, S is a.\n\nOperation 1: S becomes aa.\n\nOperation 2: S becomes baa.\n\nOperation 3: S becomes aab.\n\nOperation 4: S becomes aabc.\n\nOperation 5: S becomes cbaa.\n\nOperation 6: S becomes aabc.\n\nThus, the resulting string is aabc.\n\nSample Input 3\n\ny\n1\n2 1 x\n\nSample Output 3\n\nxy", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 812, "cpu_time_ms": 261, "memory_kb": 80752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s475924853", "group_id": "codeNet:p02756", "input_text": "(defvar char-list \n (loop :as char \n :across (read-line)\n :collect char))\n(defvar tale (last char-list))\n(defvar qs (read))\n(defvar reversep nil)\n\n(defun enqueue (N)\n (rplacd tale (list N))\n (setf tale (cdr tale)))\n\n(defun add-char (end-p char)\n (if (or (and reversep end-p)\n (and (null reversep)\n (null end-p)))\n (push char char-list)\n (enqueue char)))\n\n(defun do-query (q)\n (case q\n (1 (setf reversep (not reversep)))\n (2 (add-char (= 2 (read)) (read-char)))))\n\n (loop :repeat qs :do (do-query (read)))\n (format t \"~{~A~^~}\" (if reversep (reverse char-list) char-list))", "language": "Lisp", "metadata": {"date": 1586723511, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02756.html", "problem_id": "p02756", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02756/input.txt", "sample_output_relpath": "derived/input_output/data/p02756/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02756/Lisp/s475924853.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s475924853", "user_id": "u606976120"}, "prompt_components": {"gold_output": "cpa\n", "input_to_evaluate": "(defvar char-list \n (loop :as char \n :across (read-line)\n :collect char))\n(defvar tale (last char-list))\n(defvar qs (read))\n(defvar reversep nil)\n\n(defun enqueue (N)\n (rplacd tale (list N))\n (setf tale (cdr tale)))\n\n(defun add-char (end-p char)\n (if (or (and reversep end-p)\n (and (null reversep)\n (null end-p)))\n (push char char-list)\n (enqueue char)))\n\n(defun do-query (q)\n (case q\n (1 (setf reversep (not reversep)))\n (2 (add-char (= 2 (read)) (read-char)))))\n\n (loop :repeat qs :do (do-query (read)))\n (format t \"~{~A~^~}\" (if reversep (reverse char-list) char-list))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nTakahashi has a string S consisting of lowercase English letters.\n\nStarting with this string, he will produce a new one in the procedure given as follows.\n\nThe procedure consists of Q operations. In Operation i (1 \\leq i \\leq Q), an integer T_i is provided, which means the following:\n\nIf T_i = 1: reverse the string S.\n\nIf T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.\n\nIf F_i = 1 : Add C_i to the beginning of the string S.\n\nIf F_i = 2 : Add C_i to the end of the string S.\n\nHelp Takahashi by finding the final string that results from the procedure.\n\nConstraints\n\n1 \\leq |S| \\leq 10^5\n\nS consists of lowercase English letters.\n\n1 \\leq Q \\leq 2 \\times 10^5\n\nT_i = 1 or 2.\n\nF_i = 1 or 2, if provided.\n\nC_i is a lowercase English letter, if provided.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nQ\nQuery_1\n:\nQuery_Q\n\nIn the 3-rd through the (Q+2)-th lines, Query_i is one of the following:\n\n1\n\nwhich means T_i = 1, and:\n\n2 F_i C_i\n\nwhich means T_i = 2.\n\nOutput\n\nPrint the resulting string.\n\nSample Input 1\n\na\n4\n2 1 p\n1\n2 2 c\n1\n\nSample Output 1\n\ncpa\n\nThere will be Q = 4 operations. Initially, S is a.\n\nOperation 1: Add p at the beginning of S. S becomes pa.\n\nOperation 2: Reverse S. S becomes ap.\n\nOperation 3: Add c at the end of S. S becomes apc.\n\nOperation 4: Reverse S. S becomes cpa.\n\nThus, the resulting string is cpa.\n\nSample Input 2\n\na\n6\n2 2 a\n2 1 b\n1\n2 2 c\n1\n1\n\nSample Output 2\n\naabc\n\nThere will be Q = 6 operations. Initially, S is a.\n\nOperation 1: S becomes aa.\n\nOperation 2: S becomes baa.\n\nOperation 3: S becomes aab.\n\nOperation 4: S becomes aabc.\n\nOperation 5: S becomes cbaa.\n\nOperation 6: S becomes aabc.\n\nThus, the resulting string is aabc.\n\nSample Input 3\n\ny\n1\n2 1 x\n\nSample Output 3\n\nxy", "sample_input": "a\n4\n2 1 p\n1\n2 2 c\n1\n"}, "reference_outputs": ["cpa\n"], "source_document_id": "p02756", "source_text": "Score : 400 points\n\nProblem Statement\n\nTakahashi has a string S consisting of lowercase English letters.\n\nStarting with this string, he will produce a new one in the procedure given as follows.\n\nThe procedure consists of Q operations. In Operation i (1 \\leq i \\leq Q), an integer T_i is provided, which means the following:\n\nIf T_i = 1: reverse the string S.\n\nIf T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.\n\nIf F_i = 1 : Add C_i to the beginning of the string S.\n\nIf F_i = 2 : Add C_i to the end of the string S.\n\nHelp Takahashi by finding the final string that results from the procedure.\n\nConstraints\n\n1 \\leq |S| \\leq 10^5\n\nS consists of lowercase English letters.\n\n1 \\leq Q \\leq 2 \\times 10^5\n\nT_i = 1 or 2.\n\nF_i = 1 or 2, if provided.\n\nC_i is a lowercase English letter, if provided.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nQ\nQuery_1\n:\nQuery_Q\n\nIn the 3-rd through the (Q+2)-th lines, Query_i is one of the following:\n\n1\n\nwhich means T_i = 1, and:\n\n2 F_i C_i\n\nwhich means T_i = 2.\n\nOutput\n\nPrint the resulting string.\n\nSample Input 1\n\na\n4\n2 1 p\n1\n2 2 c\n1\n\nSample Output 1\n\ncpa\n\nThere will be Q = 4 operations. Initially, S is a.\n\nOperation 1: Add p at the beginning of S. S becomes pa.\n\nOperation 2: Reverse S. S becomes ap.\n\nOperation 3: Add c at the end of S. S becomes apc.\n\nOperation 4: Reverse S. S becomes cpa.\n\nThus, the resulting string is cpa.\n\nSample Input 2\n\na\n6\n2 2 a\n2 1 b\n1\n2 2 c\n1\n1\n\nSample Output 2\n\naabc\n\nThere will be Q = 6 operations. Initially, S is a.\n\nOperation 1: S becomes aa.\n\nOperation 2: S becomes baa.\n\nOperation 3: S becomes aab.\n\nOperation 4: S becomes aabc.\n\nOperation 5: S becomes cbaa.\n\nOperation 6: S becomes aabc.\n\nThus, the resulting string is aabc.\n\nSample Input 3\n\ny\n1\n2 1 x\n\nSample Output 3\n\nxy", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 649, "cpu_time_ms": 628, "memory_kb": 66176}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s698518110", "group_id": "codeNet:p02756", "input_text": "(defvar char-list (list (read-line)))\n(defvar tale (last char-list))\n(defvar qs (read))\n(defvar reversep nil)\n\n(defun enqueue (N)\n (rplacd tale (list N))\n (setf tale (cdr tale)))\n\n(defun add-char (end-p char)\n (if (or (and reversep end-p)\n (and (null reversep)\n (null end-p)))\n (push char char-list)\n (enqueue char)))\n\n(defun do-query (q)\n (case q\n (1 (setf reversep (not reversep)))\n (2 (add-char (= 2 (read)) (read-char)))))\n\n (loop :repeat qs :do (do-query (read)))\n (format t \"~{~A~^~}\" (if reversep (reverse char-list) char-list))", "language": "Lisp", "metadata": {"date": 1586723213, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02756.html", "problem_id": "p02756", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02756/input.txt", "sample_output_relpath": "derived/input_output/data/p02756/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02756/Lisp/s698518110.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s698518110", "user_id": "u606976120"}, "prompt_components": {"gold_output": "cpa\n", "input_to_evaluate": "(defvar char-list (list (read-line)))\n(defvar tale (last char-list))\n(defvar qs (read))\n(defvar reversep nil)\n\n(defun enqueue (N)\n (rplacd tale (list N))\n (setf tale (cdr tale)))\n\n(defun add-char (end-p char)\n (if (or (and reversep end-p)\n (and (null reversep)\n (null end-p)))\n (push char char-list)\n (enqueue char)))\n\n(defun do-query (q)\n (case q\n (1 (setf reversep (not reversep)))\n (2 (add-char (= 2 (read)) (read-char)))))\n\n (loop :repeat qs :do (do-query (read)))\n (format t \"~{~A~^~}\" (if reversep (reverse char-list) char-list))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nTakahashi has a string S consisting of lowercase English letters.\n\nStarting with this string, he will produce a new one in the procedure given as follows.\n\nThe procedure consists of Q operations. In Operation i (1 \\leq i \\leq Q), an integer T_i is provided, which means the following:\n\nIf T_i = 1: reverse the string S.\n\nIf T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.\n\nIf F_i = 1 : Add C_i to the beginning of the string S.\n\nIf F_i = 2 : Add C_i to the end of the string S.\n\nHelp Takahashi by finding the final string that results from the procedure.\n\nConstraints\n\n1 \\leq |S| \\leq 10^5\n\nS consists of lowercase English letters.\n\n1 \\leq Q \\leq 2 \\times 10^5\n\nT_i = 1 or 2.\n\nF_i = 1 or 2, if provided.\n\nC_i is a lowercase English letter, if provided.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nQ\nQuery_1\n:\nQuery_Q\n\nIn the 3-rd through the (Q+2)-th lines, Query_i is one of the following:\n\n1\n\nwhich means T_i = 1, and:\n\n2 F_i C_i\n\nwhich means T_i = 2.\n\nOutput\n\nPrint the resulting string.\n\nSample Input 1\n\na\n4\n2 1 p\n1\n2 2 c\n1\n\nSample Output 1\n\ncpa\n\nThere will be Q = 4 operations. Initially, S is a.\n\nOperation 1: Add p at the beginning of S. S becomes pa.\n\nOperation 2: Reverse S. S becomes ap.\n\nOperation 3: Add c at the end of S. S becomes apc.\n\nOperation 4: Reverse S. S becomes cpa.\n\nThus, the resulting string is cpa.\n\nSample Input 2\n\na\n6\n2 2 a\n2 1 b\n1\n2 2 c\n1\n1\n\nSample Output 2\n\naabc\n\nThere will be Q = 6 operations. Initially, S is a.\n\nOperation 1: S becomes aa.\n\nOperation 2: S becomes baa.\n\nOperation 3: S becomes aab.\n\nOperation 4: S becomes aabc.\n\nOperation 5: S becomes cbaa.\n\nOperation 6: S becomes aabc.\n\nThus, the resulting string is aabc.\n\nSample Input 3\n\ny\n1\n2 1 x\n\nSample Output 3\n\nxy", "sample_input": "a\n4\n2 1 p\n1\n2 2 c\n1\n"}, "reference_outputs": ["cpa\n"], "source_document_id": "p02756", "source_text": "Score : 400 points\n\nProblem Statement\n\nTakahashi has a string S consisting of lowercase English letters.\n\nStarting with this string, he will produce a new one in the procedure given as follows.\n\nThe procedure consists of Q operations. In Operation i (1 \\leq i \\leq Q), an integer T_i is provided, which means the following:\n\nIf T_i = 1: reverse the string S.\n\nIf T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.\n\nIf F_i = 1 : Add C_i to the beginning of the string S.\n\nIf F_i = 2 : Add C_i to the end of the string S.\n\nHelp Takahashi by finding the final string that results from the procedure.\n\nConstraints\n\n1 \\leq |S| \\leq 10^5\n\nS consists of lowercase English letters.\n\n1 \\leq Q \\leq 2 \\times 10^5\n\nT_i = 1 or 2.\n\nF_i = 1 or 2, if provided.\n\nC_i is a lowercase English letter, if provided.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nQ\nQuery_1\n:\nQuery_Q\n\nIn the 3-rd through the (Q+2)-th lines, Query_i is one of the following:\n\n1\n\nwhich means T_i = 1, and:\n\n2 F_i C_i\n\nwhich means T_i = 2.\n\nOutput\n\nPrint the resulting string.\n\nSample Input 1\n\na\n4\n2 1 p\n1\n2 2 c\n1\n\nSample Output 1\n\ncpa\n\nThere will be Q = 4 operations. Initially, S is a.\n\nOperation 1: Add p at the beginning of S. S becomes pa.\n\nOperation 2: Reverse S. S becomes ap.\n\nOperation 3: Add c at the end of S. S becomes apc.\n\nOperation 4: Reverse S. S becomes cpa.\n\nThus, the resulting string is cpa.\n\nSample Input 2\n\na\n6\n2 2 a\n2 1 b\n1\n2 2 c\n1\n1\n\nSample Output 2\n\naabc\n\nThere will be Q = 6 operations. Initially, S is a.\n\nOperation 1: S becomes aa.\n\nOperation 2: S becomes baa.\n\nOperation 3: S becomes aab.\n\nOperation 4: S becomes aabc.\n\nOperation 5: S becomes cbaa.\n\nOperation 6: S becomes aabc.\n\nThus, the resulting string is aabc.\n\nSample Input 3\n\ny\n1\n2 1 x\n\nSample Output 3\n\nxy", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 580, "cpu_time_ms": 586, "memory_kb": 62148}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s366502602", "group_id": "codeNet:p02756", "input_text": "(let* ((s (read-line))\n (size 400000)\n (buf (make-array size))\n (q (read))\n (parity nil)\n (head (- size 1))\n (len (length s))\n (tail len))\n (loop for i from 0 below (length s)\n do (setf (aref buf i) (aref s i)))\n\n (loop repeat q\n for query = (read)\n do (if (= query 1)\n (setf parity (not parity))\n (let ((f (read))\n (c (read-char)))\n (incf len)\n (if (xor (= f 1) parity)\n (progn\n (setf (aref buf head) c)\n (decf head))\n (progn\n (setf (aref buf tail) c)\n (incf tail))))))\n\n (if parity\n (loop repeat len\n for i downfrom (- tail 1)\n do (format t \"~a\" (aref buf (mod (+ i size) size))))\n (loop repeat len\n for i from (+ head 1)\n do (format t \"~a\" (aref buf (mod i size)))))\n (terpri))\n", "language": "Lisp", "metadata": {"date": 1583635880, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02756.html", "problem_id": "p02756", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02756/input.txt", "sample_output_relpath": "derived/input_output/data/p02756/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02756/Lisp/s366502602.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s366502602", "user_id": "u690263481"}, "prompt_components": {"gold_output": "cpa\n", "input_to_evaluate": "(let* ((s (read-line))\n (size 400000)\n (buf (make-array size))\n (q (read))\n (parity nil)\n (head (- size 1))\n (len (length s))\n (tail len))\n (loop for i from 0 below (length s)\n do (setf (aref buf i) (aref s i)))\n\n (loop repeat q\n for query = (read)\n do (if (= query 1)\n (setf parity (not parity))\n (let ((f (read))\n (c (read-char)))\n (incf len)\n (if (xor (= f 1) parity)\n (progn\n (setf (aref buf head) c)\n (decf head))\n (progn\n (setf (aref buf tail) c)\n (incf tail))))))\n\n (if parity\n (loop repeat len\n for i downfrom (- tail 1)\n do (format t \"~a\" (aref buf (mod (+ i size) size))))\n (loop repeat len\n for i from (+ head 1)\n do (format t \"~a\" (aref buf (mod i size)))))\n (terpri))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nTakahashi has a string S consisting of lowercase English letters.\n\nStarting with this string, he will produce a new one in the procedure given as follows.\n\nThe procedure consists of Q operations. In Operation i (1 \\leq i \\leq Q), an integer T_i is provided, which means the following:\n\nIf T_i = 1: reverse the string S.\n\nIf T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.\n\nIf F_i = 1 : Add C_i to the beginning of the string S.\n\nIf F_i = 2 : Add C_i to the end of the string S.\n\nHelp Takahashi by finding the final string that results from the procedure.\n\nConstraints\n\n1 \\leq |S| \\leq 10^5\n\nS consists of lowercase English letters.\n\n1 \\leq Q \\leq 2 \\times 10^5\n\nT_i = 1 or 2.\n\nF_i = 1 or 2, if provided.\n\nC_i is a lowercase English letter, if provided.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nQ\nQuery_1\n:\nQuery_Q\n\nIn the 3-rd through the (Q+2)-th lines, Query_i is one of the following:\n\n1\n\nwhich means T_i = 1, and:\n\n2 F_i C_i\n\nwhich means T_i = 2.\n\nOutput\n\nPrint the resulting string.\n\nSample Input 1\n\na\n4\n2 1 p\n1\n2 2 c\n1\n\nSample Output 1\n\ncpa\n\nThere will be Q = 4 operations. Initially, S is a.\n\nOperation 1: Add p at the beginning of S. S becomes pa.\n\nOperation 2: Reverse S. S becomes ap.\n\nOperation 3: Add c at the end of S. S becomes apc.\n\nOperation 4: Reverse S. S becomes cpa.\n\nThus, the resulting string is cpa.\n\nSample Input 2\n\na\n6\n2 2 a\n2 1 b\n1\n2 2 c\n1\n1\n\nSample Output 2\n\naabc\n\nThere will be Q = 6 operations. Initially, S is a.\n\nOperation 1: S becomes aa.\n\nOperation 2: S becomes baa.\n\nOperation 3: S becomes aab.\n\nOperation 4: S becomes aabc.\n\nOperation 5: S becomes cbaa.\n\nOperation 6: S becomes aabc.\n\nThus, the resulting string is aabc.\n\nSample Input 3\n\ny\n1\n2 1 x\n\nSample Output 3\n\nxy", "sample_input": "a\n4\n2 1 p\n1\n2 2 c\n1\n"}, "reference_outputs": ["cpa\n"], "source_document_id": "p02756", "source_text": "Score : 400 points\n\nProblem Statement\n\nTakahashi has a string S consisting of lowercase English letters.\n\nStarting with this string, he will produce a new one in the procedure given as follows.\n\nThe procedure consists of Q operations. In Operation i (1 \\leq i \\leq Q), an integer T_i is provided, which means the following:\n\nIf T_i = 1: reverse the string S.\n\nIf T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.\n\nIf F_i = 1 : Add C_i to the beginning of the string S.\n\nIf F_i = 2 : Add C_i to the end of the string S.\n\nHelp Takahashi by finding the final string that results from the procedure.\n\nConstraints\n\n1 \\leq |S| \\leq 10^5\n\nS consists of lowercase English letters.\n\n1 \\leq Q \\leq 2 \\times 10^5\n\nT_i = 1 or 2.\n\nF_i = 1 or 2, if provided.\n\nC_i is a lowercase English letter, if provided.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nQ\nQuery_1\n:\nQuery_Q\n\nIn the 3-rd through the (Q+2)-th lines, Query_i is one of the following:\n\n1\n\nwhich means T_i = 1, and:\n\n2 F_i C_i\n\nwhich means T_i = 2.\n\nOutput\n\nPrint the resulting string.\n\nSample Input 1\n\na\n4\n2 1 p\n1\n2 2 c\n1\n\nSample Output 1\n\ncpa\n\nThere will be Q = 4 operations. Initially, S is a.\n\nOperation 1: Add p at the beginning of S. S becomes pa.\n\nOperation 2: Reverse S. S becomes ap.\n\nOperation 3: Add c at the end of S. S becomes apc.\n\nOperation 4: Reverse S. S becomes cpa.\n\nThus, the resulting string is cpa.\n\nSample Input 2\n\na\n6\n2 2 a\n2 1 b\n1\n2 2 c\n1\n1\n\nSample Output 2\n\naabc\n\nThere will be Q = 6 operations. Initially, S is a.\n\nOperation 1: S becomes aa.\n\nOperation 2: S becomes baa.\n\nOperation 3: S becomes aab.\n\nOperation 4: S becomes aabc.\n\nOperation 5: S becomes cbaa.\n\nOperation 6: S becomes aabc.\n\nThus, the resulting string is aabc.\n\nSample Input 3\n\ny\n1\n2 1 x\n\nSample Output 3\n\nxy", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1010, "cpu_time_ms": 197, "memory_kb": 23012}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s545314408", "group_id": "codeNet:p02756", "input_text": "(defun xor (a b) ;xor\n (not (equal a b)))\n(let* ((n (read-line))\n (lst (loop :repeat (read) :collect (if (= 1 (read))\n (list 1 nil nil)\n (list 2 (read) (read-char)))))\n (reverse nil)\n (from-stack nil)\n (to-stack nil))\n (loop :for (x y z) :in lst\n :do (if (= x 1)\n (setf reverse (not reverse))\n (if (xor reverse (= 1 y))\n (push z from-stack)\n (push z to-stack))))\n (princ (if reverse\n (reverse (concatenate 'string from-stack n (reverse to-stack)))\n (concatenate 'string from-stack n (reverse to-stack)))))\n", "language": "Lisp", "metadata": {"date": 1583635458, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02756.html", "problem_id": "p02756", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02756/input.txt", "sample_output_relpath": "derived/input_output/data/p02756/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02756/Lisp/s545314408.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s545314408", "user_id": "u610490393"}, "prompt_components": {"gold_output": "cpa\n", "input_to_evaluate": "(defun xor (a b) ;xor\n (not (equal a b)))\n(let* ((n (read-line))\n (lst (loop :repeat (read) :collect (if (= 1 (read))\n (list 1 nil nil)\n (list 2 (read) (read-char)))))\n (reverse nil)\n (from-stack nil)\n (to-stack nil))\n (loop :for (x y z) :in lst\n :do (if (= x 1)\n (setf reverse (not reverse))\n (if (xor reverse (= 1 y))\n (push z from-stack)\n (push z to-stack))))\n (princ (if reverse\n (reverse (concatenate 'string from-stack n (reverse to-stack)))\n (concatenate 'string from-stack n (reverse to-stack)))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nTakahashi has a string S consisting of lowercase English letters.\n\nStarting with this string, he will produce a new one in the procedure given as follows.\n\nThe procedure consists of Q operations. In Operation i (1 \\leq i \\leq Q), an integer T_i is provided, which means the following:\n\nIf T_i = 1: reverse the string S.\n\nIf T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.\n\nIf F_i = 1 : Add C_i to the beginning of the string S.\n\nIf F_i = 2 : Add C_i to the end of the string S.\n\nHelp Takahashi by finding the final string that results from the procedure.\n\nConstraints\n\n1 \\leq |S| \\leq 10^5\n\nS consists of lowercase English letters.\n\n1 \\leq Q \\leq 2 \\times 10^5\n\nT_i = 1 or 2.\n\nF_i = 1 or 2, if provided.\n\nC_i is a lowercase English letter, if provided.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nQ\nQuery_1\n:\nQuery_Q\n\nIn the 3-rd through the (Q+2)-th lines, Query_i is one of the following:\n\n1\n\nwhich means T_i = 1, and:\n\n2 F_i C_i\n\nwhich means T_i = 2.\n\nOutput\n\nPrint the resulting string.\n\nSample Input 1\n\na\n4\n2 1 p\n1\n2 2 c\n1\n\nSample Output 1\n\ncpa\n\nThere will be Q = 4 operations. Initially, S is a.\n\nOperation 1: Add p at the beginning of S. S becomes pa.\n\nOperation 2: Reverse S. S becomes ap.\n\nOperation 3: Add c at the end of S. S becomes apc.\n\nOperation 4: Reverse S. S becomes cpa.\n\nThus, the resulting string is cpa.\n\nSample Input 2\n\na\n6\n2 2 a\n2 1 b\n1\n2 2 c\n1\n1\n\nSample Output 2\n\naabc\n\nThere will be Q = 6 operations. Initially, S is a.\n\nOperation 1: S becomes aa.\n\nOperation 2: S becomes baa.\n\nOperation 3: S becomes aab.\n\nOperation 4: S becomes aabc.\n\nOperation 5: S becomes cbaa.\n\nOperation 6: S becomes aabc.\n\nThus, the resulting string is aabc.\n\nSample Input 3\n\ny\n1\n2 1 x\n\nSample Output 3\n\nxy", "sample_input": "a\n4\n2 1 p\n1\n2 2 c\n1\n"}, "reference_outputs": ["cpa\n"], "source_document_id": "p02756", "source_text": "Score : 400 points\n\nProblem Statement\n\nTakahashi has a string S consisting of lowercase English letters.\n\nStarting with this string, he will produce a new one in the procedure given as follows.\n\nThe procedure consists of Q operations. In Operation i (1 \\leq i \\leq Q), an integer T_i is provided, which means the following:\n\nIf T_i = 1: reverse the string S.\n\nIf T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.\n\nIf F_i = 1 : Add C_i to the beginning of the string S.\n\nIf F_i = 2 : Add C_i to the end of the string S.\n\nHelp Takahashi by finding the final string that results from the procedure.\n\nConstraints\n\n1 \\leq |S| \\leq 10^5\n\nS consists of lowercase English letters.\n\n1 \\leq Q \\leq 2 \\times 10^5\n\nT_i = 1 or 2.\n\nF_i = 1 or 2, if provided.\n\nC_i is a lowercase English letter, if provided.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nQ\nQuery_1\n:\nQuery_Q\n\nIn the 3-rd through the (Q+2)-th lines, Query_i is one of the following:\n\n1\n\nwhich means T_i = 1, and:\n\n2 F_i C_i\n\nwhich means T_i = 2.\n\nOutput\n\nPrint the resulting string.\n\nSample Input 1\n\na\n4\n2 1 p\n1\n2 2 c\n1\n\nSample Output 1\n\ncpa\n\nThere will be Q = 4 operations. Initially, S is a.\n\nOperation 1: Add p at the beginning of S. S becomes pa.\n\nOperation 2: Reverse S. S becomes ap.\n\nOperation 3: Add c at the end of S. S becomes apc.\n\nOperation 4: Reverse S. S becomes cpa.\n\nThus, the resulting string is cpa.\n\nSample Input 2\n\na\n6\n2 2 a\n2 1 b\n1\n2 2 c\n1\n1\n\nSample Output 2\n\naabc\n\nThere will be Q = 6 operations. Initially, S is a.\n\nOperation 1: S becomes aa.\n\nOperation 2: S becomes baa.\n\nOperation 3: S becomes aab.\n\nOperation 4: S becomes aabc.\n\nOperation 5: S becomes cbaa.\n\nOperation 6: S becomes aabc.\n\nThus, the resulting string is aabc.\n\nSample Input 3\n\ny\n1\n2 1 x\n\nSample Output 3\n\nxy", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 722, "cpu_time_ms": 560, "memory_kb": 72292}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s825245330", "group_id": "codeNet:p02757", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; TODO: more efficient handling when modulus is (unsigned-byte 31) or\n;; (unsigned-byte 32)\n(declaim (inline mod-power))\n(defun mod-power (base power modulus)\n \"BASE := integer\nPOWER, MODULUS := non-negative fixnum\"\n (declare ((integer 0 #.most-positive-fixnum) modulus power)\n (integer base))\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) x p)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (cond ((zerop p) 1)\n ((evenp p) (recur (mod (* x x) modulus) (ash p -1)))\n (t (mod (* x (recur x (- p 1))) modulus)))))\n (recur (mod base modulus) power)))\n\n;;;\n;;; Modular arithmetic\n;;;\n\n;; Blankinship algorithm\n;; Reference: https://topcoder-g-hatena-ne-jp.jag-icpc.org/spaghetti_source/20130126/ (Japanese)\n(declaim (ftype (function * (values fixnum fixnum &optional)) %ext-gcd))\n(defun %ext-gcd (a b)\n (declare (optimize (speed 3) (safety 0))\n (fixnum a b))\n (let ((y 1)\n (x 0)\n (u 1)\n (v 0))\n (declare (fixnum y x u v))\n (loop (when (zerop a)\n (return (values x y)))\n (let ((q (floor b a)))\n (decf x (the fixnum (* q u)))\n (rotatef x u)\n (decf y (the fixnum (* q v)))\n (rotatef y v)\n (decf b (the fixnum (* q a)))\n (rotatef b a)))))\n\n;; Simple recursive version. A bit slower but more comprehensible.\n;; https://cp-algorithms.com/algebra/extended-euclid-algorithm.html (English)\n;; https://drken1215.hatenablog.com/entry/2018/06/08/210000 (Japanese)\n;; (defun %ext-gcd (a b)\n;; (declare (optimize (speed 3) (safety 0))\n;; (fixnum a b))\n;; (if (zerop b)\n;; (values 1 0)\n;; (multiple-value-bind (p q) (floor a b) ; a = pb + q\n;; (multiple-value-bind (v u) (%ext-gcd b q)\n;; (declare (fixnum u v))\n;; (values u (the fixnum (- v (the fixnum (* p u)))))))))\n\n;; TODO: deal with bignums\n(declaim (inline ext-gcd))\n(defun ext-gcd (a b)\n \"Returns two integers X and Y which satisfy AX + BY = gcd(A, B).\"\n (declare ((integer #.(- most-positive-fixnum) #.most-positive-fixnum) a b))\n (if (>= a 0)\n (if (>= b 0)\n (%ext-gcd a b)\n (multiple-value-bind (x y) (%ext-gcd a (- b))\n (declare (fixnum x y))\n (values x (- y))))\n (if (>= b 0)\n (multiple-value-bind (x y) (%ext-gcd (- a) b)\n (declare (fixnum x y))\n (values (- x) y))\n (multiple-value-bind (x y) (%ext-gcd (- a) (- b))\n (declare (fixnum x y))\n (values (- x) (- y))))))\n\n(declaim (inline mod-inverse)\n (ftype (function * (values (mod #.most-positive-fixnum) &optional)) mod-inverse))\n\n;; (defun mod-inverse (a modulus)\n;; \"Solves ax ≡ 1 mod m. A and M must be coprime.\"\n;; (declare (integer a)\n;; ((integer 1 #.most-positive-fixnum) modulus))\n;; (mod (%ext-gcd (mod a modulus) modulus) modulus))\n\n;; FIXME: Perhaps no advantage in efficiency? Then I should use the above simple\n;; code.\n(defun mod-inverse (a modulus)\n \"Solves ax ≡ 1 mod m. A and M must be coprime.\"\n (declare ((integer 1 #.most-positive-fixnum) modulus))\n (let ((a (mod a modulus))\n (b modulus)\n (u 1)\n (v 0))\n (declare (fixnum a b u v))\n (loop until (zerop b)\n for quot = (floor a b)\n do (decf a (the fixnum (* quot b)))\n (rotatef a b)\n (decf u (the fixnum (* quot v)))\n (rotatef u v))\n (setq u (mod u modulus))\n (if (< u 0)\n (+ u modulus)\n u)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun solve2 (n s)\n (let ((res 0))\n (dotimes (i n)\n (let ((d (aref s i)))\n (when (evenp d)\n (incf res (+ i 1)))))\n res))\n\n(defun solve5 (n s)\n (let ((res 0))\n (dotimes (i n)\n (let ((d (aref s i)))\n (when (or (= d 0) (= d 5))\n (incf res (+ i 1)))))\n res))\n\n(defun main ()\n (let* ((n (read))\n (p (read))\n (original-s (read-line))\n (s (make-array n :element-type 'uint8))\n (table (make-array p :element-type 'uint62 :initial-element 0))\n (powers (make-array (+ n 1) :element-type 'uint32 :initial-element 1)))\n (dotimes (i n)\n (setf (aref powers (+ i 1))\n (mod (* 10 (aref powers i)) p)))\n (dotimes (i n)\n (setf (aref s i) (- (char-code (aref original-s i)) 48)))\n (when (= p 2)\n (println (solve2 n s))\n (return-from main))\n (when (= p 5)\n (println (solve5 n s))\n (return-from main))\n (setf (aref table 0) 1)\n (let ((sum 0)\n (res 0))\n (loop for x from 1 to n\n for d = (aref s (- x 1))\n do (setq sum (mod (+ (* 10 sum) d) p))\n (let ((sum/10 (mod (* sum (mod-inverse (aref powers x) p)) p)))\n (incf res (aref table sum/10))\n (incf (aref table sum/10))))\n (println res))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 3\n3543\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 2\n2020\n\"\n \"10\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"20 11\n33883322005544116655\n\"\n \"68\n\")))\n", "language": "Lisp", "metadata": {"date": 1583637259, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02757.html", "problem_id": "p02757", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02757/input.txt", "sample_output_relpath": "derived/input_output/data/p02757/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02757/Lisp/s825245330.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s825245330", "user_id": "u352600849"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; TODO: more efficient handling when modulus is (unsigned-byte 31) or\n;; (unsigned-byte 32)\n(declaim (inline mod-power))\n(defun mod-power (base power modulus)\n \"BASE := integer\nPOWER, MODULUS := non-negative fixnum\"\n (declare ((integer 0 #.most-positive-fixnum) modulus power)\n (integer base))\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) x p)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (cond ((zerop p) 1)\n ((evenp p) (recur (mod (* x x) modulus) (ash p -1)))\n (t (mod (* x (recur x (- p 1))) modulus)))))\n (recur (mod base modulus) power)))\n\n;;;\n;;; Modular arithmetic\n;;;\n\n;; Blankinship algorithm\n;; Reference: https://topcoder-g-hatena-ne-jp.jag-icpc.org/spaghetti_source/20130126/ (Japanese)\n(declaim (ftype (function * (values fixnum fixnum &optional)) %ext-gcd))\n(defun %ext-gcd (a b)\n (declare (optimize (speed 3) (safety 0))\n (fixnum a b))\n (let ((y 1)\n (x 0)\n (u 1)\n (v 0))\n (declare (fixnum y x u v))\n (loop (when (zerop a)\n (return (values x y)))\n (let ((q (floor b a)))\n (decf x (the fixnum (* q u)))\n (rotatef x u)\n (decf y (the fixnum (* q v)))\n (rotatef y v)\n (decf b (the fixnum (* q a)))\n (rotatef b a)))))\n\n;; Simple recursive version. A bit slower but more comprehensible.\n;; https://cp-algorithms.com/algebra/extended-euclid-algorithm.html (English)\n;; https://drken1215.hatenablog.com/entry/2018/06/08/210000 (Japanese)\n;; (defun %ext-gcd (a b)\n;; (declare (optimize (speed 3) (safety 0))\n;; (fixnum a b))\n;; (if (zerop b)\n;; (values 1 0)\n;; (multiple-value-bind (p q) (floor a b) ; a = pb + q\n;; (multiple-value-bind (v u) (%ext-gcd b q)\n;; (declare (fixnum u v))\n;; (values u (the fixnum (- v (the fixnum (* p u)))))))))\n\n;; TODO: deal with bignums\n(declaim (inline ext-gcd))\n(defun ext-gcd (a b)\n \"Returns two integers X and Y which satisfy AX + BY = gcd(A, B).\"\n (declare ((integer #.(- most-positive-fixnum) #.most-positive-fixnum) a b))\n (if (>= a 0)\n (if (>= b 0)\n (%ext-gcd a b)\n (multiple-value-bind (x y) (%ext-gcd a (- b))\n (declare (fixnum x y))\n (values x (- y))))\n (if (>= b 0)\n (multiple-value-bind (x y) (%ext-gcd (- a) b)\n (declare (fixnum x y))\n (values (- x) y))\n (multiple-value-bind (x y) (%ext-gcd (- a) (- b))\n (declare (fixnum x y))\n (values (- x) (- y))))))\n\n(declaim (inline mod-inverse)\n (ftype (function * (values (mod #.most-positive-fixnum) &optional)) mod-inverse))\n\n;; (defun mod-inverse (a modulus)\n;; \"Solves ax ≡ 1 mod m. A and M must be coprime.\"\n;; (declare (integer a)\n;; ((integer 1 #.most-positive-fixnum) modulus))\n;; (mod (%ext-gcd (mod a modulus) modulus) modulus))\n\n;; FIXME: Perhaps no advantage in efficiency? Then I should use the above simple\n;; code.\n(defun mod-inverse (a modulus)\n \"Solves ax ≡ 1 mod m. A and M must be coprime.\"\n (declare ((integer 1 #.most-positive-fixnum) modulus))\n (let ((a (mod a modulus))\n (b modulus)\n (u 1)\n (v 0))\n (declare (fixnum a b u v))\n (loop until (zerop b)\n for quot = (floor a b)\n do (decf a (the fixnum (* quot b)))\n (rotatef a b)\n (decf u (the fixnum (* quot v)))\n (rotatef u v))\n (setq u (mod u modulus))\n (if (< u 0)\n (+ u modulus)\n u)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun solve2 (n s)\n (let ((res 0))\n (dotimes (i n)\n (let ((d (aref s i)))\n (when (evenp d)\n (incf res (+ i 1)))))\n res))\n\n(defun solve5 (n s)\n (let ((res 0))\n (dotimes (i n)\n (let ((d (aref s i)))\n (when (or (= d 0) (= d 5))\n (incf res (+ i 1)))))\n res))\n\n(defun main ()\n (let* ((n (read))\n (p (read))\n (original-s (read-line))\n (s (make-array n :element-type 'uint8))\n (table (make-array p :element-type 'uint62 :initial-element 0))\n (powers (make-array (+ n 1) :element-type 'uint32 :initial-element 1)))\n (dotimes (i n)\n (setf (aref powers (+ i 1))\n (mod (* 10 (aref powers i)) p)))\n (dotimes (i n)\n (setf (aref s i) (- (char-code (aref original-s i)) 48)))\n (when (= p 2)\n (println (solve2 n s))\n (return-from main))\n (when (= p 5)\n (println (solve5 n s))\n (return-from main))\n (setf (aref table 0) 1)\n (let ((sum 0)\n (res 0))\n (loop for x from 1 to n\n for d = (aref s (- x 1))\n do (setq sum (mod (+ (* 10 sum) d) p))\n (let ((sum/10 (mod (* sum (mod-inverse (aref powers x) p)) p)))\n (incf res (aref table sum/10))\n (incf (aref table sum/10))))\n (println res))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 3\n3543\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 2\n2020\n\"\n \"10\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"20 11\n33883322005544116655\n\"\n \"68\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nTakahashi has a string S of length N consisting of digits from 0 through 9.\n\nHe loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S - there are N \\times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten.\n\nHere substrings starting with a 0 also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers.\n\nCompute this count to help Takahashi.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nS consists of digits.\n\n|S| = N\n\n2 \\leq P \\leq 10000\n\nP is a prime number.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN P\nS\n\nOutput\n\nPrint the number of non-empty (contiguous) substrings of S that are divisible by P when regarded as an integer written in base ten.\n\nSample Input 1\n\n4 3\n3543\n\nSample Output 1\n\n6\n\nHere S = 3543. There are ten non-empty (contiguous) substrings of S:\n\n3: divisible by 3.\n\n35: not divisible by 3.\n\n354: divisible by 3.\n\n3543: divisible by 3.\n\n5: not divisible by 3.\n\n54: divisible by 3.\n\n543: divisible by 3.\n\n4: not divisible by 3.\n\n43: not divisible by 3.\n\n3: divisible by 3.\n\nSix of these are divisible by 3, so print 6.\n\nSample Input 2\n\n4 2\n2020\n\nSample Output 2\n\n10\n\nHere S = 2020. There are ten non-empty (contiguous) substrings of S, all of which are divisible by 2, so print 10.\n\nNote that substrings beginning with a 0 also count.\n\nSample Input 3\n\n20 11\n33883322005544116655\n\nSample Output 3\n\n68", "sample_input": "4 3\n3543\n"}, "reference_outputs": ["6\n"], "source_document_id": "p02757", "source_text": "Score : 500 points\n\nProblem Statement\n\nTakahashi has a string S of length N consisting of digits from 0 through 9.\n\nHe loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S - there are N \\times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten.\n\nHere substrings starting with a 0 also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers.\n\nCompute this count to help Takahashi.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nS consists of digits.\n\n|S| = N\n\n2 \\leq P \\leq 10000\n\nP is a prime number.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN P\nS\n\nOutput\n\nPrint the number of non-empty (contiguous) substrings of S that are divisible by P when regarded as an integer written in base ten.\n\nSample Input 1\n\n4 3\n3543\n\nSample Output 1\n\n6\n\nHere S = 3543. There are ten non-empty (contiguous) substrings of S:\n\n3: divisible by 3.\n\n35: not divisible by 3.\n\n354: divisible by 3.\n\n3543: divisible by 3.\n\n5: not divisible by 3.\n\n54: divisible by 3.\n\n543: divisible by 3.\n\n4: not divisible by 3.\n\n43: not divisible by 3.\n\n3: divisible by 3.\n\nSix of these are divisible by 3, so print 6.\n\nSample Input 2\n\n4 2\n2020\n\nSample Output 2\n\n10\n\nHere S = 2020. There are ten non-empty (contiguous) substrings of S, all of which are divisible by 2, so print 10.\n\nNote that substrings beginning with a 0 also count.\n\nSample Input 3\n\n20 11\n33883322005544116655\n\nSample Output 3\n\n68", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8541, "cpu_time_ms": 291, "memory_kb": 49640}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s847851084", "group_id": "codeNet:p02758", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n;;;\n;;; Memoization macro\n;;;\n\n;;\n;; Basic usage:\n;;\n;; (with-cache (:hash-table :test #'equal :key #'cons)\n;; (defun add (a b)\n;; (+ a b)))\n;; This function caches the returned values for already passed combinations of\n;; arguments. In this case ADD stores the key (CONS A B) and the returned value\n;; to a hash-table when (ADD A B) is evaluated for the first time. ADD returns\n;; the stored value when it is called with the same arguments (w.r.t. EQUAL)\n;; again.\n;;\n;; The storage for cache can be hash-table or array. Let's see an example for\n;; array:\n;; (with-cache (:array (10 20 30) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c) ... ))\n;; This form stores the value of FOO in an array created by (make-array (list 10\n;; 20 30) :initial-element -1 :element-type 'fixnum). Note that INITIAL-ELEMENT\n;; must always be given here as it is used as the flag expressing `not yet\n;; stored'. (Therefore INITIAL-ELEMENT should be a value FOO never takes.)\n;;\n;; If you want to ignore some arguments, you can put `*' in dimensions:\n;; (with-cache (:array (10 10 * 10) :initial-element -1)\n;; (defun foo (a b c d) ...)) ; then C is ignored when querying or storing cache\n;;\n;; Available definition forms in WITH-CACHE are DEFUN, LABELS, FLET, and\n;; SB-INT:NAMED-LET.\n;;\n;; You can trace the memoized function by :TRACE option:\n;; (with-cache (:array (10 10) :initial-element -1 :trace t)\n;; (defun foo (x y) ...))\n;; Then FOO is traced as with CL:TRACE.\n;;\n\n;; TODO & NOTE: Currently a memoized function is not enclosed with a block of\n;; the function name.\n\n;; FIXME: *RECURSION-DEPTH* should be included within the macro.\n(declaim (type (integer 0 #.most-positive-fixnum) *recursion-depth*))\n(defparameter *recursion-depth* 0)\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun %enclose-with-trace (fname args form)\n (let ((value (gensym)))\n `(progn\n (format t \"~&~A~A: (~A ~{~A~^ ~}) =>\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args))\n (let ((,value (let ((*recursion-depth* (1+ *recursion-depth*)))\n ,form)))\n (format t \"~&~A~A: (~A ~{~A~^ ~}) => ~A\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args)\n ,value)\n ,value))))\n\n (defun %extract-declarations (body)\n (remove-if-not (lambda (form) (and (consp form) (eql 'declare (car form))))\n body))\n\n (defun %parse-cache-form (cache-specifier)\n (let ((cache-type (car cache-specifier))\n (cache-attribs (cdr cache-specifier)))\n (assert (member cache-type '(:hash-table :array)))\n (let* ((dims-with-* (when (eql cache-type :array) (first cache-attribs)))\n (dims (remove '* dims-with-*))\n (rank (length dims))\n (rest-attribs (ecase cache-type\n (:hash-table cache-attribs)\n (:array (cdr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (trace-p (prog1 (getf rest-attribs :trace) (remf rest-attribs :trace)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array (list ,@dims) ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym \"CACHE\"))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels\n ((make-cache-querier (cache-type name args)\n (let ((res (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key '#'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (assert (= (length args) (length dims-with-*)))\n (let ((memoized-args (loop for dimension in dims-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value))))))))\n (if trace-p\n (%enclose-with-trace name args res)\n res)))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n ;; TODO: portable fill\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name)))))\n (values cache cache-form cache-type name-alias\n #'make-reset-name\n #'make-reset-form\n #'make-cache-querier)))))))\n\n(defmacro with-cache ((cache-type &rest cache-attribs) def-form)\n \"CACHE-TYPE := :HASH-TABLE | :ARRAY.\nDEF-FORM := definition form with DEFUN, LABELS, FLET, or SB-INT:NAMED-LET.\"\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form\n make-cache-querier)\n (%parse-cache-form (cons cache-type cache-attribs))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (defun ,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (defun ,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form)\n ((,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args)))\n ,@(cdr definitions))\n (declare (ignorable #',(funcall make-reset-name name)))\n ,@labels-body)))))\n ((nlet #+sbcl sb-int:named-let)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form) ,name ,bindings\n ,@(%extract-declarations body)\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))))))\n\n(defmacro with-caches (cache-specs def-form)\n \"DEF-FORM := definition form by LABELS or FLET.\n\n (with-caches (cache-spec1 cache-spec2)\n (labels ((f (x) ...) (g (y) ...))))\nis equivalent to the line up of\n (with-cache cache-spec1 (labels ((f (x) ...))))\nand\n (with-cache cache-spec2 (labels ((g (y) ...))))\n\nThis macro will be useful to do mutual recursion between memoized local\nfunctions.\"\n (assert (member (car def-form) '(labels flet)))\n (let (cache-symbol-list cache-form-list cache-type-list name-alias-list make-reset-name-list make-reset-form-list make-cache-querier-list)\n (dolist (cache-spec (reverse cache-specs))\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form make-cache-querier)\n (%parse-cache-form cache-spec)\n (push cache-symbol cache-symbol-list)\n (push cache-form cache-form-list)\n (push cache-type cache-type-list)\n (push name-alias name-alias-list)\n (push make-reset-name make-reset-name-list)\n (push make-reset-form make-reset-form-list)\n (push make-cache-querier make-cache-querier-list)))\n (labels ((def-name (def) (first def))\n (def-args (def) (second def))\n (def-body (def) (cddr def)))\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n `(let ,(loop for cache-symbol in cache-symbol-list\n for cache-form in cache-form-list\n collect `(,cache-symbol ,cache-form))\n (,(car def-form)\n (,@(loop for def in definitions\n for cache-type in cache-type-list\n for make-reset-name in make-reset-name-list\n for make-reset-form in make-reset-form-list\n collect `(,(funcall make-reset-name (def-name def)) ()\n ,(funcall make-reset-form cache-type)))\n ,@(loop for def in definitions\n for cache-type in cache-type-list\n for name-alias in name-alias-list\n for make-cache-querier in make-cache-querier-list\n collect `(,(def-name def) ,(def-args def)\n ,@(%extract-declarations (def-body def))\n (labels ((,name-alias ,(def-args def) ,@(def-body def)))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type (def-name def) (def-args def))))))\n (declare (ignorable ,@(loop for def in definitions\n for make-reset-name in make-reset-name-list\n collect `#',(funcall make-reset-name\n (def-name def)))))\n ,@labels-body))))))\n\n\n;;;\n;;; Sort multiple vectors\n;;;\n\n;; Note: Not randomized; the worst case time complexity is O(n^2).\n\n(declaim (inline %median3))\n(defun %median3 (x y z order)\n (if (funcall order x y)\n (if (funcall order y z)\n y\n (if (funcall order z x)\n x\n z))\n (if (funcall order z y)\n y\n (if (funcall order x z)\n x\n z))))\n\n(defun parallel-sort! (vector order &rest vectors)\n \"Destructively sorts VECTOR w.r.t. ORDER and applies the same permutation to\nall the vectors in VECTORS.\"\n (declare (vector vector))\n (labels\n ((recur (left right)\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3 (aref vector l)\n (aref vector (ash (+ l r) -1))\n (aref vector r)\n order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall order (aref vector l) pivot)\n do (incf l 1))\n (loop while (funcall order pivot (aref vector r))\n do (decf r 1))\n (when (>= l r)\n (return))\n (rotatef (aref vector l) (aref vector r))\n (dolist (v vectors)\n (rotatef (aref v l) (aref v r)))\n (incf l 1)\n (decf r 1))\n (recur left (- l 1))\n (recur (+ r 1) right)))))\n (recur 0 (- (length vector) 1))\n vector))\n\n#+sbcl\n(sb-c:define-source-transform parallel-sort! (vector order &rest vectors)\n (let ((vec (gensym))\n (vecs (loop for _ in vectors collect (gensym))))\n `(let ((,vec ,vector)\n ,@(loop for v in vectors\n for sym in vecs\n collect `(,sym ,v)))\n (labels\n ((recur (left right)\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3 (aref ,vec l)\n (aref ,vec (ash (+ l r) -1))\n (aref ,vec r)\n ,order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall ,order (aref ,vec l) pivot)\n do (incf l 1))\n (loop while (funcall ,order pivot (aref ,vec r))\n do (decf r 1))\n (when (>= l r)\n (return))\n (rotatef (aref ,vec l) (aref ,vec r))\n ,@(loop for sym in vecs\n collect `(rotatef (aref ,sym l) (aref ,sym r)))\n (incf l 1)\n (decf r 1))\n (recur left (- l 1))\n (recur (+ r 1) right)))))\n (recur 0 (- (length ,vec) 1))\n ,vec))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 998244353)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ most-positive-fixnum)\n(define-mod-operations +mod+)\n\n(defun main ()\n (let* ((n (read))\n (xs (make-array (+ n 1) :element-type 'fixnum :initial-element +inf+))\n (ds (make-array n :element-type 'uint32)))\n (declare (uint31 n))\n (dotimes (i n)\n (let ((x (read-fixnum))\n (d (read-fixnum)))\n (setf (aref xs i) x\n (aref ds i) d)))\n (parallel-sort! xs #'< ds)\n (dbg xs ds)\n (with-caches ((:array (200001) :element-type 'uint32 :initial-element #xffffffff)\n (:array (200001) :element-type 'uint32 :initial-element #xffffffff))\n (labels ((get-farthest (v)\n (let ((x (aref xs v))\n (d (aref ds v))\n (next-x (aref xs (+ v 1))))\n (loop (when (>= next-x (+ x d))\n (return v))\n (setq v (get-farthest (+ v 1))\n next-x (aref xs (+ v 1))))))\n (dp (v)\n (let ((res 1)\n (sup (get-farthest v))\n (next (+ v 1)))\n (declare (uint31 res))\n (loop (when (> next sup)\n (return))\n (mulfmod res (dp next))\n (setq next (+ 1 (get-farthest next))))\n (mod+ res 1))))\n (let ((res 1)\n (pos 0))\n (declare (uint31 res))\n (loop (when (>= pos n)\n (return))\n (mulfmod res (dp pos))\n (setq pos (+ 1 (get-farthest pos))))\n (println res))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 5\n3 3\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n6 5\n-1 10\n3 3\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n7 10\n-10 3\n4 3\n-4 3\n\"\n \"16\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"20\n-8 1\n26 4\n0 5\n9 1\n19 4\n22 20\n28 27\n11 8\n-3 20\n-25 17\n10 4\n-18 27\n24 28\n-11 19\n2 27\n-2 18\n-1 12\n-24 29\n31 29\n29 7\n\"\n \"110\n\")))\n", "language": "Lisp", "metadata": {"date": 1583807787, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02758.html", "problem_id": "p02758", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02758/input.txt", "sample_output_relpath": "derived/input_output/data/p02758/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02758/Lisp/s847851084.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s847851084", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n;;;\n;;; Memoization macro\n;;;\n\n;;\n;; Basic usage:\n;;\n;; (with-cache (:hash-table :test #'equal :key #'cons)\n;; (defun add (a b)\n;; (+ a b)))\n;; This function caches the returned values for already passed combinations of\n;; arguments. In this case ADD stores the key (CONS A B) and the returned value\n;; to a hash-table when (ADD A B) is evaluated for the first time. ADD returns\n;; the stored value when it is called with the same arguments (w.r.t. EQUAL)\n;; again.\n;;\n;; The storage for cache can be hash-table or array. Let's see an example for\n;; array:\n;; (with-cache (:array (10 20 30) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c) ... ))\n;; This form stores the value of FOO in an array created by (make-array (list 10\n;; 20 30) :initial-element -1 :element-type 'fixnum). Note that INITIAL-ELEMENT\n;; must always be given here as it is used as the flag expressing `not yet\n;; stored'. (Therefore INITIAL-ELEMENT should be a value FOO never takes.)\n;;\n;; If you want to ignore some arguments, you can put `*' in dimensions:\n;; (with-cache (:array (10 10 * 10) :initial-element -1)\n;; (defun foo (a b c d) ...)) ; then C is ignored when querying or storing cache\n;;\n;; Available definition forms in WITH-CACHE are DEFUN, LABELS, FLET, and\n;; SB-INT:NAMED-LET.\n;;\n;; You can trace the memoized function by :TRACE option:\n;; (with-cache (:array (10 10) :initial-element -1 :trace t)\n;; (defun foo (x y) ...))\n;; Then FOO is traced as with CL:TRACE.\n;;\n\n;; TODO & NOTE: Currently a memoized function is not enclosed with a block of\n;; the function name.\n\n;; FIXME: *RECURSION-DEPTH* should be included within the macro.\n(declaim (type (integer 0 #.most-positive-fixnum) *recursion-depth*))\n(defparameter *recursion-depth* 0)\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun %enclose-with-trace (fname args form)\n (let ((value (gensym)))\n `(progn\n (format t \"~&~A~A: (~A ~{~A~^ ~}) =>\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args))\n (let ((,value (let ((*recursion-depth* (1+ *recursion-depth*)))\n ,form)))\n (format t \"~&~A~A: (~A ~{~A~^ ~}) => ~A\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args)\n ,value)\n ,value))))\n\n (defun %extract-declarations (body)\n (remove-if-not (lambda (form) (and (consp form) (eql 'declare (car form))))\n body))\n\n (defun %parse-cache-form (cache-specifier)\n (let ((cache-type (car cache-specifier))\n (cache-attribs (cdr cache-specifier)))\n (assert (member cache-type '(:hash-table :array)))\n (let* ((dims-with-* (when (eql cache-type :array) (first cache-attribs)))\n (dims (remove '* dims-with-*))\n (rank (length dims))\n (rest-attribs (ecase cache-type\n (:hash-table cache-attribs)\n (:array (cdr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (trace-p (prog1 (getf rest-attribs :trace) (remf rest-attribs :trace)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array (list ,@dims) ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym \"CACHE\"))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels\n ((make-cache-querier (cache-type name args)\n (let ((res (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key '#'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (assert (= (length args) (length dims-with-*)))\n (let ((memoized-args (loop for dimension in dims-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value))))))))\n (if trace-p\n (%enclose-with-trace name args res)\n res)))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n ;; TODO: portable fill\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name)))))\n (values cache cache-form cache-type name-alias\n #'make-reset-name\n #'make-reset-form\n #'make-cache-querier)))))))\n\n(defmacro with-cache ((cache-type &rest cache-attribs) def-form)\n \"CACHE-TYPE := :HASH-TABLE | :ARRAY.\nDEF-FORM := definition form with DEFUN, LABELS, FLET, or SB-INT:NAMED-LET.\"\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form\n make-cache-querier)\n (%parse-cache-form (cons cache-type cache-attribs))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (defun ,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (defun ,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form)\n ((,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args)))\n ,@(cdr definitions))\n (declare (ignorable #',(funcall make-reset-name name)))\n ,@labels-body)))))\n ((nlet #+sbcl sb-int:named-let)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form) ,name ,bindings\n ,@(%extract-declarations body)\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))))))\n\n(defmacro with-caches (cache-specs def-form)\n \"DEF-FORM := definition form by LABELS or FLET.\n\n (with-caches (cache-spec1 cache-spec2)\n (labels ((f (x) ...) (g (y) ...))))\nis equivalent to the line up of\n (with-cache cache-spec1 (labels ((f (x) ...))))\nand\n (with-cache cache-spec2 (labels ((g (y) ...))))\n\nThis macro will be useful to do mutual recursion between memoized local\nfunctions.\"\n (assert (member (car def-form) '(labels flet)))\n (let (cache-symbol-list cache-form-list cache-type-list name-alias-list make-reset-name-list make-reset-form-list make-cache-querier-list)\n (dolist (cache-spec (reverse cache-specs))\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form make-cache-querier)\n (%parse-cache-form cache-spec)\n (push cache-symbol cache-symbol-list)\n (push cache-form cache-form-list)\n (push cache-type cache-type-list)\n (push name-alias name-alias-list)\n (push make-reset-name make-reset-name-list)\n (push make-reset-form make-reset-form-list)\n (push make-cache-querier make-cache-querier-list)))\n (labels ((def-name (def) (first def))\n (def-args (def) (second def))\n (def-body (def) (cddr def)))\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n `(let ,(loop for cache-symbol in cache-symbol-list\n for cache-form in cache-form-list\n collect `(,cache-symbol ,cache-form))\n (,(car def-form)\n (,@(loop for def in definitions\n for cache-type in cache-type-list\n for make-reset-name in make-reset-name-list\n for make-reset-form in make-reset-form-list\n collect `(,(funcall make-reset-name (def-name def)) ()\n ,(funcall make-reset-form cache-type)))\n ,@(loop for def in definitions\n for cache-type in cache-type-list\n for name-alias in name-alias-list\n for make-cache-querier in make-cache-querier-list\n collect `(,(def-name def) ,(def-args def)\n ,@(%extract-declarations (def-body def))\n (labels ((,name-alias ,(def-args def) ,@(def-body def)))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type (def-name def) (def-args def))))))\n (declare (ignorable ,@(loop for def in definitions\n for make-reset-name in make-reset-name-list\n collect `#',(funcall make-reset-name\n (def-name def)))))\n ,@labels-body))))))\n\n\n;;;\n;;; Sort multiple vectors\n;;;\n\n;; Note: Not randomized; the worst case time complexity is O(n^2).\n\n(declaim (inline %median3))\n(defun %median3 (x y z order)\n (if (funcall order x y)\n (if (funcall order y z)\n y\n (if (funcall order z x)\n x\n z))\n (if (funcall order z y)\n y\n (if (funcall order x z)\n x\n z))))\n\n(defun parallel-sort! (vector order &rest vectors)\n \"Destructively sorts VECTOR w.r.t. ORDER and applies the same permutation to\nall the vectors in VECTORS.\"\n (declare (vector vector))\n (labels\n ((recur (left right)\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3 (aref vector l)\n (aref vector (ash (+ l r) -1))\n (aref vector r)\n order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall order (aref vector l) pivot)\n do (incf l 1))\n (loop while (funcall order pivot (aref vector r))\n do (decf r 1))\n (when (>= l r)\n (return))\n (rotatef (aref vector l) (aref vector r))\n (dolist (v vectors)\n (rotatef (aref v l) (aref v r)))\n (incf l 1)\n (decf r 1))\n (recur left (- l 1))\n (recur (+ r 1) right)))))\n (recur 0 (- (length vector) 1))\n vector))\n\n#+sbcl\n(sb-c:define-source-transform parallel-sort! (vector order &rest vectors)\n (let ((vec (gensym))\n (vecs (loop for _ in vectors collect (gensym))))\n `(let ((,vec ,vector)\n ,@(loop for v in vectors\n for sym in vecs\n collect `(,sym ,v)))\n (labels\n ((recur (left right)\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3 (aref ,vec l)\n (aref ,vec (ash (+ l r) -1))\n (aref ,vec r)\n ,order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall ,order (aref ,vec l) pivot)\n do (incf l 1))\n (loop while (funcall ,order pivot (aref ,vec r))\n do (decf r 1))\n (when (>= l r)\n (return))\n (rotatef (aref ,vec l) (aref ,vec r))\n ,@(loop for sym in vecs\n collect `(rotatef (aref ,sym l) (aref ,sym r)))\n (incf l 1)\n (decf r 1))\n (recur left (- l 1))\n (recur (+ r 1) right)))))\n (recur 0 (- (length ,vec) 1))\n ,vec))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 998244353)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ most-positive-fixnum)\n(define-mod-operations +mod+)\n\n(defun main ()\n (let* ((n (read))\n (xs (make-array (+ n 1) :element-type 'fixnum :initial-element +inf+))\n (ds (make-array n :element-type 'uint32)))\n (declare (uint31 n))\n (dotimes (i n)\n (let ((x (read-fixnum))\n (d (read-fixnum)))\n (setf (aref xs i) x\n (aref ds i) d)))\n (parallel-sort! xs #'< ds)\n (dbg xs ds)\n (with-caches ((:array (200001) :element-type 'uint32 :initial-element #xffffffff)\n (:array (200001) :element-type 'uint32 :initial-element #xffffffff))\n (labels ((get-farthest (v)\n (let ((x (aref xs v))\n (d (aref ds v))\n (next-x (aref xs (+ v 1))))\n (loop (when (>= next-x (+ x d))\n (return v))\n (setq v (get-farthest (+ v 1))\n next-x (aref xs (+ v 1))))))\n (dp (v)\n (let ((res 1)\n (sup (get-farthest v))\n (next (+ v 1)))\n (declare (uint31 res))\n (loop (when (> next sup)\n (return))\n (mulfmod res (dp next))\n (setq next (+ 1 (get-farthest next))))\n (mod+ res 1))))\n (let ((res 1)\n (pos 0))\n (declare (uint31 res))\n (loop (when (>= pos n)\n (return))\n (mulfmod res (dp pos))\n (setq pos (+ 1 (get-farthest pos))))\n (println res))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 5\n3 3\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n6 5\n-1 10\n3 3\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n7 10\n-10 3\n4 3\n-4 3\n\"\n \"16\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"20\n-8 1\n26 4\n0 5\n9 1\n19 4\n22 20\n28 27\n11 8\n-3 20\n-25 17\n10 4\n-18 27\n24 28\n-11 19\n2 27\n-2 18\n-1 12\n-24 29\n31 29\n29 7\n\"\n \"110\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere are N robots numbered 1 to N placed on a number line. Robot i is placed at coordinate X_i. When activated, it will travel the distance of D_i in the positive direction, and then it will be removed from the number line. All the robots move at the same speed, and their sizes are ignorable.\n\nTakahashi, who is a mischievous boy, can do the following operation any number of times (possibly zero) as long as there is a robot remaining on the number line.\n\nChoose a robot and activate it. This operation cannot be done when there is a robot moving.\n\nWhile Robot i is moving, if it touches another robot j that is remaining in the range [X_i, X_i + D_i) on the number line, Robot j also gets activated and starts moving. This process is repeated recursively.\n\nHow many possible sets of robots remaining on the number line are there after Takahashi does the operation some number of times? Compute this count modulo 998244353, since it can be enormous.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n-10^9 \\leq X_i \\leq 10^9\n\n1 \\leq D_i \\leq 10^9\n\nX_i \\neq X_j (i \\neq j)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nX_1 D_1\n:\nX_N D_N\n\nOutput\n\nPrint the number of possible sets of robots remaining on the number line, modulo 998244353.\n\nSample Input 1\n\n2\n1 5\n3 3\n\nSample Output 1\n\n3\n\nThere are three possible sets of robots remaining on the number line: \\{1, 2\\}, \\{1\\}, and \\{\\}.\n\nThese can be achieved as follows:\n\nIf Takahashi activates nothing, the robots \\{1, 2\\} will remain.\n\nIf Takahashi activates Robot 1, it will activate Robot 2 while moving, after which there will be no robots on the number line. This state can also be reached by activating Robot 2 and then Robot 1.\n\nIf Takahashi activates Robot 2 and finishes doing the operation, the robot \\{1\\} will remain.\n\nSample Input 2\n\n3\n6 5\n-1 10\n3 3\n\nSample Output 2\n\n5\n\nThere are five possible sets of robots remaining on the number line: \\{1, 2, 3\\}, \\{1, 2\\}, \\{2\\}, \\{2, 3\\}, and \\{\\}.\n\nSample Input 3\n\n4\n7 10\n-10 3\n4 3\n-4 3\n\nSample Output 3\n\n16\n\nNone of the robots influences others.\n\nSample Input 4\n\n20\n-8 1\n26 4\n0 5\n9 1\n19 4\n22 20\n28 27\n11 8\n-3 20\n-25 17\n10 4\n-18 27\n24 28\n-11 19\n2 27\n-2 18\n-1 12\n-24 29\n31 29\n29 7\n\nSample Output 4\n\n110\n\nRemember to print the count modulo 998244353.", "sample_input": "2\n1 5\n3 3\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02758", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere are N robots numbered 1 to N placed on a number line. Robot i is placed at coordinate X_i. When activated, it will travel the distance of D_i in the positive direction, and then it will be removed from the number line. All the robots move at the same speed, and their sizes are ignorable.\n\nTakahashi, who is a mischievous boy, can do the following operation any number of times (possibly zero) as long as there is a robot remaining on the number line.\n\nChoose a robot and activate it. This operation cannot be done when there is a robot moving.\n\nWhile Robot i is moving, if it touches another robot j that is remaining in the range [X_i, X_i + D_i) on the number line, Robot j also gets activated and starts moving. This process is repeated recursively.\n\nHow many possible sets of robots remaining on the number line are there after Takahashi does the operation some number of times? Compute this count modulo 998244353, since it can be enormous.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n-10^9 \\leq X_i \\leq 10^9\n\n1 \\leq D_i \\leq 10^9\n\nX_i \\neq X_j (i \\neq j)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nX_1 D_1\n:\nX_N D_N\n\nOutput\n\nPrint the number of possible sets of robots remaining on the number line, modulo 998244353.\n\nSample Input 1\n\n2\n1 5\n3 3\n\nSample Output 1\n\n3\n\nThere are three possible sets of robots remaining on the number line: \\{1, 2\\}, \\{1\\}, and \\{\\}.\n\nThese can be achieved as follows:\n\nIf Takahashi activates nothing, the robots \\{1, 2\\} will remain.\n\nIf Takahashi activates Robot 1, it will activate Robot 2 while moving, after which there will be no robots on the number line. This state can also be reached by activating Robot 2 and then Robot 1.\n\nIf Takahashi activates Robot 2 and finishes doing the operation, the robot \\{1\\} will remain.\n\nSample Input 2\n\n3\n6 5\n-1 10\n3 3\n\nSample Output 2\n\n5\n\nThere are five possible sets of robots remaining on the number line: \\{1, 2, 3\\}, \\{1, 2\\}, \\{2\\}, \\{2, 3\\}, and \\{\\}.\n\nSample Input 3\n\n4\n7 10\n-10 3\n4 3\n-4 3\n\nSample Output 3\n\n16\n\nNone of the robots influences others.\n\nSample Input 4\n\n20\n-8 1\n26 4\n0 5\n9 1\n19 4\n22 20\n28 27\n11 8\n-3 20\n-25 17\n10 4\n-18 27\n24 28\n-11 19\n2 27\n-2 18\n-1 12\n-24 29\n31 29\n29 7\n\nSample Output 4\n\n110\n\nRemember to print the count modulo 998244353.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 23172, "cpu_time_ms": 588, "memory_kb": 68664}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s829855149", "group_id": "codeNet:p02759", "input_text": "(defun solve (N)\n (ceiling N 2))\n\n\n(let ((N (read-line)))\n (format t \"~A~%\" (solve (N))))", "language": "Lisp", "metadata": {"date": 1588521639, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02759.html", "problem_id": "p02759", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02759/input.txt", "sample_output_relpath": "derived/input_output/data/p02759/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02759/Lisp/s829855149.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s829855149", "user_id": "u425762225"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun solve (N)\n (ceiling N 2))\n\n\n(let ((N (read-line)))\n (format t \"~A~%\" (solve (N))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper.\n\nAt least how many sheets of paper does he need?\n\nConstraints\n\nN is an integer.\n\n1 \\leq N \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n5\n\nSample Output 1\n\n3\n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the 2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3 sheets of paper.\n\nSample Input 2\n\n2\n\nSample Output 2\n\n1\n\nSample Input 3\n\n100\n\nSample Output 3\n\n50", "sample_input": "5\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02759", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper.\n\nAt least how many sheets of paper does he need?\n\nConstraints\n\nN is an integer.\n\n1 \\leq N \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n5\n\nSample Output 1\n\n3\n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the 2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3 sheets of paper.\n\nSample Input 2\n\n2\n\nSample Output 2\n\n1\n\nSample Input 3\n\n100\n\nSample Output 3\n\n50", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 91, "cpu_time_ms": 142, "memory_kb": 14432}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s969117446", "group_id": "codeNet:p02759", "input_text": "(princ (ceiling (read) 2))", "language": "Lisp", "metadata": {"date": 1585396771, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02759.html", "problem_id": "p02759", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02759/input.txt", "sample_output_relpath": "derived/input_output/data/p02759/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02759/Lisp/s969117446.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s969117446", "user_id": "u334552723"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(princ (ceiling (read) 2))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper.\n\nAt least how many sheets of paper does he need?\n\nConstraints\n\nN is an integer.\n\n1 \\leq N \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n5\n\nSample Output 1\n\n3\n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the 2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3 sheets of paper.\n\nSample Input 2\n\n2\n\nSample Output 2\n\n1\n\nSample Input 3\n\n100\n\nSample Output 3\n\n50", "sample_input": "5\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02759", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper.\n\nAt least how many sheets of paper does he need?\n\nConstraints\n\nN is an integer.\n\n1 \\leq N \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n5\n\nSample Output 1\n\n3\n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the 2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3 sheets of paper.\n\nSample Input 2\n\n2\n\nSample Output 2\n\n1\n\nSample Input 3\n\n100\n\nSample Output 3\n\n50", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 26, "cpu_time_ms": 21, "memory_kb": 3812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s767835830", "group_id": "codeNet:p02759", "input_text": "(defun duplex-printing ()\n (let ((n (read)))\n (multiple-value-bind (ans x) (floor n 2)\n (format t \"~D~%\" (+ ans x)))))\n\n(duplex-printing)", "language": "Lisp", "metadata": {"date": 1583116250, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02759.html", "problem_id": "p02759", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02759/input.txt", "sample_output_relpath": "derived/input_output/data/p02759/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02759/Lisp/s767835830.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s767835830", "user_id": "u091381267"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun duplex-printing ()\n (let ((n (read)))\n (multiple-value-bind (ans x) (floor n 2)\n (format t \"~D~%\" (+ ans x)))))\n\n(duplex-printing)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper.\n\nAt least how many sheets of paper does he need?\n\nConstraints\n\nN is an integer.\n\n1 \\leq N \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n5\n\nSample Output 1\n\n3\n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the 2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3 sheets of paper.\n\nSample Input 2\n\n2\n\nSample Output 2\n\n1\n\nSample Input 3\n\n100\n\nSample Output 3\n\n50", "sample_input": "5\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02759", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper.\n\nAt least how many sheets of paper does he need?\n\nConstraints\n\nN is an integer.\n\n1 \\leq N \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n5\n\nSample Output 1\n\n3\n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the 2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3 sheets of paper.\n\nSample Input 2\n\n2\n\nSample Output 2\n\n1\n\nSample Input 3\n\n100\n\nSample Output 3\n\n50", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 146, "cpu_time_ms": 134, "memory_kb": 13284}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s998810400", "group_id": "codeNet:p02766", "input_text": "(defun d (n k acc)\n (if (= n 0)\n (1- acc)\n (d (- n (mod n (expt k acc))) k (1+ acc))))\n\n(let ((n (read))\n (k (read)))\n (format t \"~A~%\" (d n k 1)))\n", "language": "Lisp", "metadata": {"date": 1593645310, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02766.html", "problem_id": "p02766", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02766/input.txt", "sample_output_relpath": "derived/input_output/data/p02766/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02766/Lisp/s998810400.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s998810400", "user_id": "u608227593"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun d (n k acc)\n (if (= n 0)\n (1- acc)\n (d (- n (mod n (expt k acc))) k (1+ acc))))\n\n(let ((n (read))\n (k (read)))\n (format t \"~A~%\" (d n k 1)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven is an integer N. Find the number of digits that N has in base K.\n\nNotes\n\nFor information on base-K representation, see Positional notation - Wikipedia.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^9\n\n2 \\leq K \\leq 10\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the number of digits that N has in base K.\n\nSample Input 1\n\n11 2\n\nSample Output 1\n\n4\n\nIn binary, 11 is represented as 1011.\n\nSample Input 2\n\n1010101 10\n\nSample Output 2\n\n7\n\nSample Input 3\n\n314159265 3\n\nSample Output 3\n\n18", "sample_input": "11 2\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02766", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven is an integer N. Find the number of digits that N has in base K.\n\nNotes\n\nFor information on base-K representation, see Positional notation - Wikipedia.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^9\n\n2 \\leq K \\leq 10\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the number of digits that N has in base K.\n\nSample Input 1\n\n11 2\n\nSample Output 1\n\n4\n\nIn binary, 11 is represented as 1011.\n\nSample Input 2\n\n1010101 10\n\nSample Output 2\n\n7\n\nSample Input 3\n\n314159265 3\n\nSample Output 3\n\n18", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 165, "cpu_time_ms": 18, "memory_kb": 24212}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s749665424", "group_id": "codeNet:p02766", "input_text": "(defun solve (n k)\n (let ((*print-base* k))\n (length (prin1-to-string n))))\n\n#-swank\n(let* ((n (read))\n (k (read)))\n (format t \"~A~%\" (solve n k)))\n", "language": "Lisp", "metadata": {"date": 1588452582, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02766.html", "problem_id": "p02766", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02766/input.txt", "sample_output_relpath": "derived/input_output/data/p02766/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02766/Lisp/s749665424.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s749665424", "user_id": "u425762225"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun solve (n k)\n (let ((*print-base* k))\n (length (prin1-to-string n))))\n\n#-swank\n(let* ((n (read))\n (k (read)))\n (format t \"~A~%\" (solve n k)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven is an integer N. Find the number of digits that N has in base K.\n\nNotes\n\nFor information on base-K representation, see Positional notation - Wikipedia.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^9\n\n2 \\leq K \\leq 10\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the number of digits that N has in base K.\n\nSample Input 1\n\n11 2\n\nSample Output 1\n\n4\n\nIn binary, 11 is represented as 1011.\n\nSample Input 2\n\n1010101 10\n\nSample Output 2\n\n7\n\nSample Input 3\n\n314159265 3\n\nSample Output 3\n\n18", "sample_input": "11 2\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02766", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven is an integer N. Find the number of digits that N has in base K.\n\nNotes\n\nFor information on base-K representation, see Positional notation - Wikipedia.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^9\n\n2 \\leq K \\leq 10\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the number of digits that N has in base K.\n\nSample Input 1\n\n11 2\n\nSample Output 1\n\n4\n\nIn binary, 11 is represented as 1011.\n\nSample Input 2\n\n1010101 10\n\nSample Output 2\n\n7\n\nSample Input 3\n\n314159265 3\n\nSample Output 3\n\n18", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 159, "cpu_time_ms": 135, "memory_kb": 11876}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s009144122", "group_id": "codeNet:p02766", "input_text": "(defun solve (n k)\n (do ((i n (floor i k))\n (j 0 (1+ j)))\n ((= i 0) j)))\n\n#-swank\n(let* ((n (read))\n (k (read)))\n (format t \"~A~%\" (solve n k)))\n", "language": "Lisp", "metadata": {"date": 1582430898, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02766.html", "problem_id": "p02766", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02766/input.txt", "sample_output_relpath": "derived/input_output/data/p02766/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02766/Lisp/s009144122.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s009144122", "user_id": "u202886318"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun solve (n k)\n (do ((i n (floor i k))\n (j 0 (1+ j)))\n ((= i 0) j)))\n\n#-swank\n(let* ((n (read))\n (k (read)))\n (format t \"~A~%\" (solve n k)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven is an integer N. Find the number of digits that N has in base K.\n\nNotes\n\nFor information on base-K representation, see Positional notation - Wikipedia.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^9\n\n2 \\leq K \\leq 10\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the number of digits that N has in base K.\n\nSample Input 1\n\n11 2\n\nSample Output 1\n\n4\n\nIn binary, 11 is represented as 1011.\n\nSample Input 2\n\n1010101 10\n\nSample Output 2\n\n7\n\nSample Input 3\n\n314159265 3\n\nSample Output 3\n\n18", "sample_input": "11 2\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02766", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven is an integer N. Find the number of digits that N has in base K.\n\nNotes\n\nFor information on base-K representation, see Positional notation - Wikipedia.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^9\n\n2 \\leq K \\leq 10\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the number of digits that N has in base K.\n\nSample Input 1\n\n11 2\n\nSample Output 1\n\n4\n\nIn binary, 11 is represented as 1011.\n\nSample Input 2\n\n1010101 10\n\nSample Output 2\n\n7\n\nSample Input 3\n\n314159265 3\n\nSample Output 3\n\n18", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 164, "cpu_time_ms": 193, "memory_kb": 13536}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s764752072", "group_id": "codeNet:p02766", "input_text": "(defun solve (n k)\n (let ((*print-base* k))\n (length (prin1-to-string n))))\n\n#-swank\n(let* ((n (read))\n (k (read)))\n (format t \"~A~%\" (solve n k)))\n", "language": "Lisp", "metadata": {"date": 1582423436, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02766.html", "problem_id": "p02766", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02766/input.txt", "sample_output_relpath": "derived/input_output/data/p02766/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02766/Lisp/s764752072.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s764752072", "user_id": "u202886318"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun solve (n k)\n (let ((*print-base* k))\n (length (prin1-to-string n))))\n\n#-swank\n(let* ((n (read))\n (k (read)))\n (format t \"~A~%\" (solve n k)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven is an integer N. Find the number of digits that N has in base K.\n\nNotes\n\nFor information on base-K representation, see Positional notation - Wikipedia.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^9\n\n2 \\leq K \\leq 10\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the number of digits that N has in base K.\n\nSample Input 1\n\n11 2\n\nSample Output 1\n\n4\n\nIn binary, 11 is represented as 1011.\n\nSample Input 2\n\n1010101 10\n\nSample Output 2\n\n7\n\nSample Input 3\n\n314159265 3\n\nSample Output 3\n\n18", "sample_input": "11 2\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02766", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven is an integer N. Find the number of digits that N has in base K.\n\nNotes\n\nFor information on base-K representation, see Positional notation - Wikipedia.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^9\n\n2 \\leq K \\leq 10\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the number of digits that N has in base K.\n\nSample Input 1\n\n11 2\n\nSample Output 1\n\n4\n\nIn binary, 11 is represented as 1011.\n\nSample Input 2\n\n1010101 10\n\nSample Output 2\n\n7\n\nSample Input 3\n\n314159265 3\n\nSample Output 3\n\n18", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 159, "cpu_time_ms": 131, "memory_kb": 11876}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s981789635", "group_id": "codeNet:p02766", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(defparameter *hash-memo* (make-hash-table :test #'equal))\n\n(defmacro dp (&body func)\n `(let* ((f (quote func))\n (num (gethash f *hash-memo*)))\n (if num\n num\n (setf (gethash f *hash-memo*) ,func))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defun func (a b)\n (if (zerop a)\n 0\n (+ 1 (func (floor a b) b))))\n\n(princ (func (read) (read)))\n", "language": "Lisp", "metadata": {"date": 1582423413, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02766.html", "problem_id": "p02766", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02766/input.txt", "sample_output_relpath": "derived/input_output/data/p02766/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02766/Lisp/s981789635.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s981789635", "user_id": "u493610446"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(defparameter *hash-memo* (make-hash-table :test #'equal))\n\n(defmacro dp (&body func)\n `(let* ((f (quote func))\n (num (gethash f *hash-memo*)))\n (if num\n num\n (setf (gethash f *hash-memo*) ,func))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defun func (a b)\n (if (zerop a)\n 0\n (+ 1 (func (floor a b) b))))\n\n(princ (func (read) (read)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven is an integer N. Find the number of digits that N has in base K.\n\nNotes\n\nFor information on base-K representation, see Positional notation - Wikipedia.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^9\n\n2 \\leq K \\leq 10\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the number of digits that N has in base K.\n\nSample Input 1\n\n11 2\n\nSample Output 1\n\n4\n\nIn binary, 11 is represented as 1011.\n\nSample Input 2\n\n1010101 10\n\nSample Output 2\n\n7\n\nSample Input 3\n\n314159265 3\n\nSample Output 3\n\n18", "sample_input": "11 2\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02766", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven is an integer N. Find the number of digits that N has in base K.\n\nNotes\n\nFor information on base-K representation, see Positional notation - Wikipedia.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^9\n\n2 \\leq K \\leq 10\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the number of digits that N has in base K.\n\nSample Input 1\n\n11 2\n\nSample Output 1\n\n4\n\nIn binary, 11 is represented as 1011.\n\nSample Input 2\n\n1010101 10\n\nSample Output 2\n\n7\n\nSample Input 3\n\n314159265 3\n\nSample Output 3\n\n18", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 965, "cpu_time_ms": 312, "memory_kb": 16184}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s153209128", "group_id": "codeNet:p02769", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defparameter *factorial-dp* (make-array 400001 :initial-element nil))\n\n(defparameter *mod* (+ (expt 10 9) 7))\n\n(defun factorial (x)\n (if (<= x 1) 1\n (if (aref *factorial-dp* x)\n (aref *factorial-dp* x)\n (setf (aref *factorial-dp* x) (mod* x (factorial (1- x)))))))\n\n(defun mod+ (&rest body)\n (reduce (lambda (a b) (mod (+ a b) *mod*)) body))\n(defun mod- (&rest body)\n (reduce (lambda (a b) (mod (- a b) *mod*)) body))\n(defun mod* (&rest body)\n (reduce (lambda (a b) (mod (* a b) *mod*)) body))\n(defun modpow (x y)\n (if (zerop y) 1\n (mod* (if (oddp y) x 1)\n (modpow (mod* x x) (ash y -1)))))\n(defun modinv (x)\n (modpow x (- *mod* 2)))\n(defun mod/ (&rest body)\n (reduce (lambda (a b) (mod* a (modinv b))) body))\n\n(defun combination (a b)\n (mod/ (factorial a) (factorial b) (factorial (- a b))))\n\n(let* ((n (read))\n (k (read))\n (ans (combination (1- (* n 2)) n)))\n (loop for zeros from (1+ k) below n\n do\n (setf ans (mod- ans \n (mod* \n (combination n zeros) \n (combination (1- n) (- n zeros 1))))))\n (princ ans))\n\n\n", "language": "Lisp", "metadata": {"date": 1582405970, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02769.html", "problem_id": "p02769", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02769/input.txt", "sample_output_relpath": "derived/input_output/data/p02769/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02769/Lisp/s153209128.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s153209128", "user_id": "u493610446"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defparameter *factorial-dp* (make-array 400001 :initial-element nil))\n\n(defparameter *mod* (+ (expt 10 9) 7))\n\n(defun factorial (x)\n (if (<= x 1) 1\n (if (aref *factorial-dp* x)\n (aref *factorial-dp* x)\n (setf (aref *factorial-dp* x) (mod* x (factorial (1- x)))))))\n\n(defun mod+ (&rest body)\n (reduce (lambda (a b) (mod (+ a b) *mod*)) body))\n(defun mod- (&rest body)\n (reduce (lambda (a b) (mod (- a b) *mod*)) body))\n(defun mod* (&rest body)\n (reduce (lambda (a b) (mod (* a b) *mod*)) body))\n(defun modpow (x y)\n (if (zerop y) 1\n (mod* (if (oddp y) x 1)\n (modpow (mod* x x) (ash y -1)))))\n(defun modinv (x)\n (modpow x (- *mod* 2)))\n(defun mod/ (&rest body)\n (reduce (lambda (a b) (mod* a (modinv b))) body))\n\n(defun combination (a b)\n (mod/ (factorial a) (factorial b) (factorial (- a b))))\n\n(let* ((n (read))\n (k (read))\n (ans (combination (1- (* n 2)) n)))\n (loop for zeros from (1+ k) below n\n do\n (setf ans (mod- ans \n (mod* \n (combination n zeros) \n (combination (1- n) (- n zeros 1))))))\n (princ ans))\n\n\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere is a building with n rooms, numbered 1 to n.\n\nWe can move from any room to any other room in the building.\n\nLet us call the following event a move: a person in some room i goes to another room j~ (i \\neq j).\n\nInitially, there was one person in each room in the building.\n\nAfter that, we know that there were exactly k moves happened up to now.\n\nWe are interested in the number of people in each of the n rooms now. How many combinations of numbers of people in the n rooms are possible?\n\nFind the count modulo (10^9 + 7).\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq n \\leq 2 \\times 10^5\n\n2 \\leq k \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn k\n\nOutput\n\nPrint the number of possible combinations of numbers of people in the n rooms now, modulo (10^9 + 7).\n\nSample Input 1\n\n3 2\n\nSample Output 1\n\n10\n\nLet c_1, c_2, and c_3 be the number of people in Room 1, 2, and 3 now, respectively. There are 10 possible combination of (c_1, c_2, c_3):\n\n(0, 0, 3)\n\n(0, 1, 2)\n\n(0, 2, 1)\n\n(0, 3, 0)\n\n(1, 0, 2)\n\n(1, 1, 1)\n\n(1, 2, 0)\n\n(2, 0, 1)\n\n(2, 1, 0)\n\n(3, 0, 0)\n\nFor example, (c_1, c_2, c_3) will be (0, 1, 2) if the person in Room 1 goes to Room 2 and then one of the persons in Room 2 goes to Room 3.\n\nSample Input 2\n\n200000 1000000000\n\nSample Output 2\n\n607923868\n\nPrint the count modulo (10^9 + 7).\n\nSample Input 3\n\n15 6\n\nSample Output 3\n\n22583772", "sample_input": "3 2\n"}, "reference_outputs": ["10\n"], "source_document_id": "p02769", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere is a building with n rooms, numbered 1 to n.\n\nWe can move from any room to any other room in the building.\n\nLet us call the following event a move: a person in some room i goes to another room j~ (i \\neq j).\n\nInitially, there was one person in each room in the building.\n\nAfter that, we know that there were exactly k moves happened up to now.\n\nWe are interested in the number of people in each of the n rooms now. How many combinations of numbers of people in the n rooms are possible?\n\nFind the count modulo (10^9 + 7).\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq n \\leq 2 \\times 10^5\n\n2 \\leq k \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn k\n\nOutput\n\nPrint the number of possible combinations of numbers of people in the n rooms now, modulo (10^9 + 7).\n\nSample Input 1\n\n3 2\n\nSample Output 1\n\n10\n\nLet c_1, c_2, and c_3 be the number of people in Room 1, 2, and 3 now, respectively. There are 10 possible combination of (c_1, c_2, c_3):\n\n(0, 0, 3)\n\n(0, 1, 2)\n\n(0, 2, 1)\n\n(0, 3, 0)\n\n(1, 0, 2)\n\n(1, 1, 1)\n\n(1, 2, 0)\n\n(2, 0, 1)\n\n(2, 1, 0)\n\n(3, 0, 0)\n\nFor example, (c_1, c_2, c_3) will be (0, 1, 2) if the person in Room 1 goes to Room 2 and then one of the persons in Room 2 goes to Room 3.\n\nSample Input 2\n\n200000 1000000000\n\nSample Output 2\n\n607923868\n\nPrint the count modulo (10^9 + 7).\n\nSample Input 3\n\n15 6\n\nSample Output 3\n\n22583772", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1798, "cpu_time_ms": 2112, "memory_kb": 76856}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s208542475", "group_id": "codeNet:p02771", "input_text": "(defun main ()\n (let* ((a (read)) (b (read)) (c (read)) (cnt 0))\n (when (= a b) (incf cnt))\n (when (= a c) (incf cnt))\n (when (= b c) (incf cnt))\n (write-line (if (= cnt 2) \"Yes\" \"No\"))))\n", "language": "Lisp", "metadata": {"date": 1600651691, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02771.html", "problem_id": "p02771", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02771/input.txt", "sample_output_relpath": "derived/input_output/data/p02771/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02771/Lisp/s208542475.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s208542475", "user_id": "u562319622"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun main ()\n (let* ((a (read)) (b (read)) (c (read)) (cnt 0))\n (when (= a b) (incf cnt))\n (when (= a c) (incf cnt))\n (when (= b c) (incf cnt))\n (write-line (if (= cnt 2) \"Yes\" \"No\"))))\n", "problem_context": "Score: 100 points\n\nProblem Statement\n\nA triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers.\n\nYou will be given three integers A, B, and C. If this triple is poor, print Yes; otherwise, print No.\n\nConstraints\n\nA, B, and C are all integers between 1 and 9 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf the given triple is poor, print Yes; otherwise, print No.\n\nSample Input 1\n\n5 7 5\n\nSample Output 1\n\nYes\n\nA and C are equal, but B is different from those two numbers, so this triple is poor.\n\nSample Input 2\n\n4 4 4\n\nSample Output 2\n\nNo\n\nA, B, and C are all equal, so this triple is not poor.\n\nSample Input 3\n\n4 9 6\n\nSample Output 3\n\nNo\n\nSample Input 4\n\n3 3 4\n\nSample Output 4\n\nYes", "sample_input": "5 7 5\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02771", "source_text": "Score: 100 points\n\nProblem Statement\n\nA triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers.\n\nYou will be given three integers A, B, and C. If this triple is poor, print Yes; otherwise, print No.\n\nConstraints\n\nA, B, and C are all integers between 1 and 9 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf the given triple is poor, print Yes; otherwise, print No.\n\nSample Input 1\n\n5 7 5\n\nSample Output 1\n\nYes\n\nA and C are equal, but B is different from those two numbers, so this triple is poor.\n\nSample Input 2\n\n4 4 4\n\nSample Output 2\n\nNo\n\nA, B, and C are all equal, so this triple is not poor.\n\nSample Input 3\n\n4 9 6\n\nSample Output 3\n\nNo\n\nSample Input 4\n\n3 3 4\n\nSample Output 4\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 201, "cpu_time_ms": 20, "memory_kb": 23532}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s752498646", "group_id": "codeNet:p02771", "input_text": "(let* ((a (read))\n (b (read))\n (c (read))\n (result (length (remove-duplicats (list a b c)))))\n (princ (if (or (= result 1) (= result 3))\n \"No\"\n \"Yes\")))\n", "language": "Lisp", "metadata": {"date": 1581890834, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02771.html", "problem_id": "p02771", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02771/input.txt", "sample_output_relpath": "derived/input_output/data/p02771/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02771/Lisp/s752498646.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s752498646", "user_id": "u631655863"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let* ((a (read))\n (b (read))\n (c (read))\n (result (length (remove-duplicats (list a b c)))))\n (princ (if (or (= result 1) (= result 3))\n \"No\"\n \"Yes\")))\n", "problem_context": "Score: 100 points\n\nProblem Statement\n\nA triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers.\n\nYou will be given three integers A, B, and C. If this triple is poor, print Yes; otherwise, print No.\n\nConstraints\n\nA, B, and C are all integers between 1 and 9 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf the given triple is poor, print Yes; otherwise, print No.\n\nSample Input 1\n\n5 7 5\n\nSample Output 1\n\nYes\n\nA and C are equal, but B is different from those two numbers, so this triple is poor.\n\nSample Input 2\n\n4 4 4\n\nSample Output 2\n\nNo\n\nA, B, and C are all equal, so this triple is not poor.\n\nSample Input 3\n\n4 9 6\n\nSample Output 3\n\nNo\n\nSample Input 4\n\n3 3 4\n\nSample Output 4\n\nYes", "sample_input": "5 7 5\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02771", "source_text": "Score: 100 points\n\nProblem Statement\n\nA triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers.\n\nYou will be given three integers A, B, and C. If this triple is poor, print Yes; otherwise, print No.\n\nConstraints\n\nA, B, and C are all integers between 1 and 9 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf the given triple is poor, print Yes; otherwise, print No.\n\nSample Input 1\n\n5 7 5\n\nSample Output 1\n\nYes\n\nA and C are equal, but B is different from those two numbers, so this triple is poor.\n\nSample Input 2\n\n4 4 4\n\nSample Output 2\n\nNo\n\nA, B, and C are all equal, so this triple is not poor.\n\nSample Input 3\n\n4 9 6\n\nSample Output 3\n\nNo\n\nSample Input 4\n\n3 3 4\n\nSample Output 4\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 196, "cpu_time_ms": 147, "memory_kb": 11872}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s727357561", "group_id": "codeNet:p02771", "input_text": "(let ((result (length (remove-duplicates (list (read) (read) (read)) :test #'=))))\n (princ (if (or (= result 1) (= result 2))\n \"Yes\"\n \"No\")))\n\n\n", "language": "Lisp", "metadata": {"date": 1581890615, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02771.html", "problem_id": "p02771", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02771/input.txt", "sample_output_relpath": "derived/input_output/data/p02771/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02771/Lisp/s727357561.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s727357561", "user_id": "u631655863"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((result (length (remove-duplicates (list (read) (read) (read)) :test #'=))))\n (princ (if (or (= result 1) (= result 2))\n \"Yes\"\n \"No\")))\n\n\n", "problem_context": "Score: 100 points\n\nProblem Statement\n\nA triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers.\n\nYou will be given three integers A, B, and C. If this triple is poor, print Yes; otherwise, print No.\n\nConstraints\n\nA, B, and C are all integers between 1 and 9 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf the given triple is poor, print Yes; otherwise, print No.\n\nSample Input 1\n\n5 7 5\n\nSample Output 1\n\nYes\n\nA and C are equal, but B is different from those two numbers, so this triple is poor.\n\nSample Input 2\n\n4 4 4\n\nSample Output 2\n\nNo\n\nA, B, and C are all equal, so this triple is not poor.\n\nSample Input 3\n\n4 9 6\n\nSample Output 3\n\nNo\n\nSample Input 4\n\n3 3 4\n\nSample Output 4\n\nYes", "sample_input": "5 7 5\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02771", "source_text": "Score: 100 points\n\nProblem Statement\n\nA triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers.\n\nYou will be given three integers A, B, and C. If this triple is poor, print Yes; otherwise, print No.\n\nConstraints\n\nA, B, and C are all integers between 1 and 9 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf the given triple is poor, print Yes; otherwise, print No.\n\nSample Input 1\n\n5 7 5\n\nSample Output 1\n\nYes\n\nA and C are equal, but B is different from those two numbers, so this triple is poor.\n\nSample Input 2\n\n4 4 4\n\nSample Output 2\n\nNo\n\nA, B, and C are all equal, so this triple is not poor.\n\nSample Input 3\n\n4 9 6\n\nSample Output 3\n\nNo\n\nSample Input 4\n\n3 3 4\n\nSample Output 4\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 169, "cpu_time_ms": 77, "memory_kb": 9444}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s223872654", "group_id": "codeNet:p02771", "input_text": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n\n(defun f(a b c)\n (if (or (and (= a b)\n (not (= b c)))\n (and (= b c)\n (not (= a b)))\n (and (= a c)\n (not (= b c)))\n )\n \"Yes\"\n \"No\"))\n(let* ((line (mapcar #'parse-integer (splitat #\\space (read-line nil nil)))))\n (format t \"~A~%\" (f (car line) (cadr line) (caddr line))))\n", "language": "Lisp", "metadata": {"date": 1581883581, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02771.html", "problem_id": "p02771", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02771/input.txt", "sample_output_relpath": "derived/input_output/data/p02771/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02771/Lisp/s223872654.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s223872654", "user_id": "u254205055"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n\n(defun f(a b c)\n (if (or (and (= a b)\n (not (= b c)))\n (and (= b c)\n (not (= a b)))\n (and (= a c)\n (not (= b c)))\n )\n \"Yes\"\n \"No\"))\n(let* ((line (mapcar #'parse-integer (splitat #\\space (read-line nil nil)))))\n (format t \"~A~%\" (f (car line) (cadr line) (caddr line))))\n", "problem_context": "Score: 100 points\n\nProblem Statement\n\nA triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers.\n\nYou will be given three integers A, B, and C. If this triple is poor, print Yes; otherwise, print No.\n\nConstraints\n\nA, B, and C are all integers between 1 and 9 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf the given triple is poor, print Yes; otherwise, print No.\n\nSample Input 1\n\n5 7 5\n\nSample Output 1\n\nYes\n\nA and C are equal, but B is different from those two numbers, so this triple is poor.\n\nSample Input 2\n\n4 4 4\n\nSample Output 2\n\nNo\n\nA, B, and C are all equal, so this triple is not poor.\n\nSample Input 3\n\n4 9 6\n\nSample Output 3\n\nNo\n\nSample Input 4\n\n3 3 4\n\nSample Output 4\n\nYes", "sample_input": "5 7 5\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02771", "source_text": "Score: 100 points\n\nProblem Statement\n\nA triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers.\n\nYou will be given three integers A, B, and C. If this triple is poor, print Yes; otherwise, print No.\n\nConstraints\n\nA, B, and C are all integers between 1 and 9 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf the given triple is poor, print Yes; otherwise, print No.\n\nSample Input 1\n\n5 7 5\n\nSample Output 1\n\nYes\n\nA and C are equal, but B is different from those two numbers, so this triple is poor.\n\nSample Input 2\n\n4 4 4\n\nSample Output 2\n\nNo\n\nA, B, and C are all equal, so this triple is not poor.\n\nSample Input 3\n\n4 9 6\n\nSample Output 3\n\nNo\n\nSample Input 4\n\n3 3 4\n\nSample Output 4\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 596, "cpu_time_ms": 136, "memory_kb": 12264}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s960060956", "group_id": "codeNet:p02772", "input_text": "(defun split (delimiter target-string)\n (let ((delimiter-position (search delimiter target-string))\n (delimiter-size (length delimiter)))\n (if delimiter-position\n (cons (subseq target-string 0 delimiter-position)\n (split delimiter (subseq target-string (+ delimiter-position delimiter-size))))\n (list target-string))))\n\n(defun is-approved-paper (n)\n (or (oddp n)\n (zerop (mod n 3))\n (zerop (mod n 5))))\n\n(defun my-and (l)\n (and (car l)\n (if (cdr l)\n (my-and (cdr l))\n T)))\n\n(defun is-approved (l)\n (if (my-and l)\n \"APPROVED\"\n \"DENIED\"))\n \n(let* ((n (read))\n (papers-str (read-line))\n (papers (mapcar #'parse-integer (split \" \" papers-str))))\n (princ (is-approved (mapcar #'is-approved-paper papers))))", "language": "Lisp", "metadata": {"date": 1584648078, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02772.html", "problem_id": "p02772", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02772/input.txt", "sample_output_relpath": "derived/input_output/data/p02772/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02772/Lisp/s960060956.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s960060956", "user_id": "u606976120"}, "prompt_components": {"gold_output": "APPROVED\n", "input_to_evaluate": "(defun split (delimiter target-string)\n (let ((delimiter-position (search delimiter target-string))\n (delimiter-size (length delimiter)))\n (if delimiter-position\n (cons (subseq target-string 0 delimiter-position)\n (split delimiter (subseq target-string (+ delimiter-position delimiter-size))))\n (list target-string))))\n\n(defun is-approved-paper (n)\n (or (oddp n)\n (zerop (mod n 3))\n (zerop (mod n 5))))\n\n(defun my-and (l)\n (and (car l)\n (if (cdr l)\n (my-and (cdr l))\n T)))\n\n(defun is-approved (l)\n (if (my-and l)\n \"APPROVED\"\n \"DENIED\"))\n \n(let* ((n (read))\n (papers-str (read-line))\n (papers (mapcar #'parse-integer (split \" \" papers-str))))\n (princ (is-approved (mapcar #'is-approved-paper papers))))", "problem_context": "Score: 200 points\n\nProblem Statement\n\nYou are an immigration officer in the Kingdom of AtCoder. The document carried by an immigrant has some number of integers written on it, and you need to check whether they meet certain criteria.\n\nAccording to the regulation, the immigrant should be allowed entry to the kingdom if and only if the following condition is satisfied:\n\nAll even numbers written on the document are divisible by 3 or 5.\n\nIf the immigrant should be allowed entry according to the regulation, output APPROVED; otherwise, print DENIED.\n\nNotes\n\nThe condition in the statement can be rephrased as \"If x is an even number written on the document, x is divisible by 3 or 5\".\nHere \"if\" and \"or\" are logical terms.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n1 \\leq A_i \\leq 1000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 \\dots A_N\n\nOutput\n\nIf the immigrant should be allowed entry according to the regulation, print APPROVED; otherwise, print DENIED.\n\nSample Input 1\n\n5\n6 7 9 10 31\n\nSample Output 1\n\nAPPROVED\n\nThe even numbers written on the document are 6 and 10.\n\nAll of them are divisible by 3 or 5, so the immigrant should be allowed entry.\n\nSample Input 2\n\n3\n28 27 24\n\nSample Output 2\n\nDENIED\n\n28 violates the condition, so the immigrant should not be allowed entry.", "sample_input": "5\n6 7 9 10 31\n"}, "reference_outputs": ["APPROVED\n"], "source_document_id": "p02772", "source_text": "Score: 200 points\n\nProblem Statement\n\nYou are an immigration officer in the Kingdom of AtCoder. The document carried by an immigrant has some number of integers written on it, and you need to check whether they meet certain criteria.\n\nAccording to the regulation, the immigrant should be allowed entry to the kingdom if and only if the following condition is satisfied:\n\nAll even numbers written on the document are divisible by 3 or 5.\n\nIf the immigrant should be allowed entry according to the regulation, output APPROVED; otherwise, print DENIED.\n\nNotes\n\nThe condition in the statement can be rephrased as \"If x is an even number written on the document, x is divisible by 3 or 5\".\nHere \"if\" and \"or\" are logical terms.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n1 \\leq A_i \\leq 1000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 \\dots A_N\n\nOutput\n\nIf the immigrant should be allowed entry according to the regulation, print APPROVED; otherwise, print DENIED.\n\nSample Input 1\n\n5\n6 7 9 10 31\n\nSample Output 1\n\nAPPROVED\n\nThe even numbers written on the document are 6 and 10.\n\nAll of them are divisible by 3 or 5, so the immigrant should be allowed entry.\n\nSample Input 2\n\n3\n28 27 24\n\nSample Output 2\n\nDENIED\n\n28 violates the condition, so the immigrant should not be allowed entry.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 800, "cpu_time_ms": 21, "memory_kb": 6504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s689447498", "group_id": "codeNet:p02773", "input_text": "(defvar alist nil)\n\n(let ((ht (make-hash-table)))\n (mapc (lambda (x)\n (if #1=(gethash x ht)\n (incf #1#)\n (setf #1# 1) ))\n (loop :repeat (read) :collect (read)) )\n (maphash (lambda (k v) (push (cons k v) alist)) ht)\n ;(princ alist) \n )\n\n(defvar alist-max \n (reduce (lambda (x y) (max x (cdr y)))\n alist :initial-value 0) )\n\n(setq alist (remove-if-not \n (lambda (x) (= (cdr x) alist-max))\n alist))\n\n(setq alist\n (sort (mapcar \n (lambda (x) (string-downcase (car x)))\n alist)\n #'string<))\n\n(format t \"~{~A~^~%~}\" alist)\n", "language": "Lisp", "metadata": {"date": 1585259994, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02773.html", "problem_id": "p02773", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02773/input.txt", "sample_output_relpath": "derived/input_output/data/p02773/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02773/Lisp/s689447498.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s689447498", "user_id": "u334552723"}, "prompt_components": {"gold_output": "beet\nvet\n", "input_to_evaluate": "(defvar alist nil)\n\n(let ((ht (make-hash-table)))\n (mapc (lambda (x)\n (if #1=(gethash x ht)\n (incf #1#)\n (setf #1# 1) ))\n (loop :repeat (read) :collect (read)) )\n (maphash (lambda (k v) (push (cons k v) alist)) ht)\n ;(princ alist) \n )\n\n(defvar alist-max \n (reduce (lambda (x y) (max x (cdr y)))\n alist :initial-value 0) )\n\n(setq alist (remove-if-not \n (lambda (x) (= (cdr x) alist-max))\n alist))\n\n(setq alist\n (sort (mapcar \n (lambda (x) (string-downcase (car x)))\n alist)\n #'string<))\n\n(format t \"~{~A~^~%~}\" alist)\n", "problem_context": "Score: 300 points\n\nProblem Statement\n\nWe have N voting papers. The i-th vote (1 \\leq i \\leq N) has the string S_i written on it.\n\nPrint all strings that are written on the most number of votes, in lexicographical order.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nS_i (1 \\leq i \\leq N) are strings consisting of lowercase English letters.\n\nThe length of S_i (1 \\leq i \\leq N) is between 1 and 10 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nPrint all strings in question in lexicographical order.\n\nSample Input 1\n\n7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n\nSample Output 1\n\nbeet\nvet\n\nbeet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.\n\nSample Input 2\n\n8\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\n\nSample Output 2\n\nbuffalo\n\nSample Input 3\n\n7\nbass\nbass\nkick\nkick\nbass\nkick\nkick\n\nSample Output 3\n\nkick\n\nSample Input 4\n\n4\nushi\ntapu\nnichia\nkun\n\nSample Output 4\n\nkun\nnichia\ntapu\nushi", "sample_input": "7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n"}, "reference_outputs": ["beet\nvet\n"], "source_document_id": "p02773", "source_text": "Score: 300 points\n\nProblem Statement\n\nWe have N voting papers. The i-th vote (1 \\leq i \\leq N) has the string S_i written on it.\n\nPrint all strings that are written on the most number of votes, in lexicographical order.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nS_i (1 \\leq i \\leq N) are strings consisting of lowercase English letters.\n\nThe length of S_i (1 \\leq i \\leq N) is between 1 and 10 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nPrint all strings in question in lexicographical order.\n\nSample Input 1\n\n7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n\nSample Output 1\n\nbeet\nvet\n\nbeet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.\n\nSample Input 2\n\n8\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\n\nSample Output 2\n\nbuffalo\n\nSample Input 3\n\n7\nbass\nbass\nkick\nkick\nbass\nkick\nkick\n\nSample Output 3\n\nkick\n\nSample Input 4\n\n4\nushi\ntapu\nnichia\nkun\n\nSample Output 4\n\nkun\nnichia\ntapu\nushi", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 679, "cpu_time_ms": 1739, "memory_kb": 106472}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s054332515", "group_id": "codeNet:p02773", "input_text": "(defun extr (in &optional (out nil) (m (cdar in)))\n (if (/= m (cdar in)) out\n (extr (cdr in) (cons (caar in) out) m)))\n\n(defun read-record(N ht)\n (dotimes (x N)\n (let ((str (read)))\n (let ((h (gethash str ht)))\n\t(setf (gethash str ht) (if h (1+ h) 1))))))\n\n(defun ht2alist (table)\n (let ((alist nil))\n (maphash (lambda (k v) (push (cons k v) alist))\n\t table)\n alist))\n\n\n(let ((ht (make-hash-table :test #'equal)) alist)\n (read-record (read) ht)\n (setq alist (extr (sort (ht2alist ht) #'> :key #'cdr)))\n (format t \"~{~A~^~%~}\" (mapcar 'string-downcase (sort alist #'string<))))\n", "language": "Lisp", "metadata": {"date": 1584314158, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02773.html", "problem_id": "p02773", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02773/input.txt", "sample_output_relpath": "derived/input_output/data/p02773/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02773/Lisp/s054332515.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s054332515", "user_id": "u334552723"}, "prompt_components": {"gold_output": "beet\nvet\n", "input_to_evaluate": "(defun extr (in &optional (out nil) (m (cdar in)))\n (if (/= m (cdar in)) out\n (extr (cdr in) (cons (caar in) out) m)))\n\n(defun read-record(N ht)\n (dotimes (x N)\n (let ((str (read)))\n (let ((h (gethash str ht)))\n\t(setf (gethash str ht) (if h (1+ h) 1))))))\n\n(defun ht2alist (table)\n (let ((alist nil))\n (maphash (lambda (k v) (push (cons k v) alist))\n\t table)\n alist))\n\n\n(let ((ht (make-hash-table :test #'equal)) alist)\n (read-record (read) ht)\n (setq alist (extr (sort (ht2alist ht) #'> :key #'cdr)))\n (format t \"~{~A~^~%~}\" (mapcar 'string-downcase (sort alist #'string<))))\n", "problem_context": "Score: 300 points\n\nProblem Statement\n\nWe have N voting papers. The i-th vote (1 \\leq i \\leq N) has the string S_i written on it.\n\nPrint all strings that are written on the most number of votes, in lexicographical order.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nS_i (1 \\leq i \\leq N) are strings consisting of lowercase English letters.\n\nThe length of S_i (1 \\leq i \\leq N) is between 1 and 10 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nPrint all strings in question in lexicographical order.\n\nSample Input 1\n\n7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n\nSample Output 1\n\nbeet\nvet\n\nbeet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.\n\nSample Input 2\n\n8\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\n\nSample Output 2\n\nbuffalo\n\nSample Input 3\n\n7\nbass\nbass\nkick\nkick\nbass\nkick\nkick\n\nSample Output 3\n\nkick\n\nSample Input 4\n\n4\nushi\ntapu\nnichia\nkun\n\nSample Output 4\n\nkun\nnichia\ntapu\nushi", "sample_input": "7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n"}, "reference_outputs": ["beet\nvet\n"], "source_document_id": "p02773", "source_text": "Score: 300 points\n\nProblem Statement\n\nWe have N voting papers. The i-th vote (1 \\leq i \\leq N) has the string S_i written on it.\n\nPrint all strings that are written on the most number of votes, in lexicographical order.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nS_i (1 \\leq i \\leq N) are strings consisting of lowercase English letters.\n\nThe length of S_i (1 \\leq i \\leq N) is between 1 and 10 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nPrint all strings in question in lexicographical order.\n\nSample Input 1\n\n7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n\nSample Output 1\n\nbeet\nvet\n\nbeet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.\n\nSample Input 2\n\n8\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\n\nSample Output 2\n\nbuffalo\n\nSample Input 3\n\n7\nbass\nbass\nkick\nkick\nbass\nkick\nkick\n\nSample Output 3\n\nkick\n\nSample Input 4\n\n4\nushi\ntapu\nnichia\nkun\n\nSample Output 4\n\nkun\nnichia\ntapu\nushi", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 604, "cpu_time_ms": 1235, "memory_kb": 119396}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s408896486", "group_id": "codeNet:p02773", "input_text": "\n(defun cul-max-cnt (names)\n (let ((max-cnt 0)\n (cur-cnt 0)\n (last-name \"\"))\n (mapc (lambda (name)\n (if (string= name last-name)\n (incf cur-cnt)\n (progn\n (setf last-name name)\n (setf max-cnt (max max-cnt (setf cur-cnt 1)))))\n (setf max-cnt (max max-cnt cur-cnt)))\n names)\n max-cnt)) \n\n(defun collect-answer (names max-cnt)\n (let ((cur-cnt 0)\n (last-name \"\")\n (answers (list)))\n (mapc (lambda (name)\n (if (string= name last-name)\n (incf cur-cnt)\n (progn\n (setf cur-cnt 1)\n (setf last-name name)))\n (when (= max-cnt cur-cnt)\n (push name answers)))\n names)\n answers))\n\n(let* ((n (read))\n (names (sort (loop repeat n collect (read-line)) #'string<))\n (answers (sort (collect-answer names (cul-max-cnt names)) #'string<)))\n (loop for i in answers do\n (format t \"~a~%\" i)))\n", "language": "Lisp", "metadata": {"date": 1582474979, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02773.html", "problem_id": "p02773", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02773/input.txt", "sample_output_relpath": "derived/input_output/data/p02773/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02773/Lisp/s408896486.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s408896486", "user_id": "u493610446"}, "prompt_components": {"gold_output": "beet\nvet\n", "input_to_evaluate": "\n(defun cul-max-cnt (names)\n (let ((max-cnt 0)\n (cur-cnt 0)\n (last-name \"\"))\n (mapc (lambda (name)\n (if (string= name last-name)\n (incf cur-cnt)\n (progn\n (setf last-name name)\n (setf max-cnt (max max-cnt (setf cur-cnt 1)))))\n (setf max-cnt (max max-cnt cur-cnt)))\n names)\n max-cnt)) \n\n(defun collect-answer (names max-cnt)\n (let ((cur-cnt 0)\n (last-name \"\")\n (answers (list)))\n (mapc (lambda (name)\n (if (string= name last-name)\n (incf cur-cnt)\n (progn\n (setf cur-cnt 1)\n (setf last-name name)))\n (when (= max-cnt cur-cnt)\n (push name answers)))\n names)\n answers))\n\n(let* ((n (read))\n (names (sort (loop repeat n collect (read-line)) #'string<))\n (answers (sort (collect-answer names (cul-max-cnt names)) #'string<)))\n (loop for i in answers do\n (format t \"~a~%\" i)))\n", "problem_context": "Score: 300 points\n\nProblem Statement\n\nWe have N voting papers. The i-th vote (1 \\leq i \\leq N) has the string S_i written on it.\n\nPrint all strings that are written on the most number of votes, in lexicographical order.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nS_i (1 \\leq i \\leq N) are strings consisting of lowercase English letters.\n\nThe length of S_i (1 \\leq i \\leq N) is between 1 and 10 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nPrint all strings in question in lexicographical order.\n\nSample Input 1\n\n7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n\nSample Output 1\n\nbeet\nvet\n\nbeet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.\n\nSample Input 2\n\n8\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\n\nSample Output 2\n\nbuffalo\n\nSample Input 3\n\n7\nbass\nbass\nkick\nkick\nbass\nkick\nkick\n\nSample Output 3\n\nkick\n\nSample Input 4\n\n4\nushi\ntapu\nnichia\nkun\n\nSample Output 4\n\nkun\nnichia\ntapu\nushi", "sample_input": "7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n"}, "reference_outputs": ["beet\nvet\n"], "source_document_id": "p02773", "source_text": "Score: 300 points\n\nProblem Statement\n\nWe have N voting papers. The i-th vote (1 \\leq i \\leq N) has the string S_i written on it.\n\nPrint all strings that are written on the most number of votes, in lexicographical order.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nS_i (1 \\leq i \\leq N) are strings consisting of lowercase English letters.\n\nThe length of S_i (1 \\leq i \\leq N) is between 1 and 10 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nPrint all strings in question in lexicographical order.\n\nSample Input 1\n\n7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n\nSample Output 1\n\nbeet\nvet\n\nbeet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.\n\nSample Input 2\n\n8\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\n\nSample Output 2\n\nbuffalo\n\nSample Input 3\n\n7\nbass\nbass\nkick\nkick\nbass\nkick\nkick\n\nSample Output 3\n\nkick\n\nSample Input 4\n\n4\nushi\ntapu\nnichia\nkun\n\nSample Output 4\n\nkun\nnichia\ntapu\nushi", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1034, "cpu_time_ms": 1027, "memory_kb": 69732}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s523328858", "group_id": "codeNet:p02773", "input_text": "(let* ((n (parse-integer (read-line nil nil)))\n (ht (make-hash-table :test #'equal))\n (maxvalue 1))\n (dotimes (i n)\n (let ((line (read-line nil nil)))\n (if (gethash line ht)\n (let ((newvalue (incf (gethash line ht))))\n (when (< maxvalue newvalue)\n (setq maxvalue newvalue)))\n (setf (gethash line ht) 1))))\n (let ((result nil))\n (maphash (lambda(key val)\n (when (= val maxvalue)\n (setq result (cons key result)))) ht)\n (sort result #'string<)\n (mapcar (lambda(a) (format t \"~A~%\" a)) result)))\n", "language": "Lisp", "metadata": {"date": 1581885703, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02773.html", "problem_id": "p02773", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02773/input.txt", "sample_output_relpath": "derived/input_output/data/p02773/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02773/Lisp/s523328858.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s523328858", "user_id": "u254205055"}, "prompt_components": {"gold_output": "beet\nvet\n", "input_to_evaluate": "(let* ((n (parse-integer (read-line nil nil)))\n (ht (make-hash-table :test #'equal))\n (maxvalue 1))\n (dotimes (i n)\n (let ((line (read-line nil nil)))\n (if (gethash line ht)\n (let ((newvalue (incf (gethash line ht))))\n (when (< maxvalue newvalue)\n (setq maxvalue newvalue)))\n (setf (gethash line ht) 1))))\n (let ((result nil))\n (maphash (lambda(key val)\n (when (= val maxvalue)\n (setq result (cons key result)))) ht)\n (sort result #'string<)\n (mapcar (lambda(a) (format t \"~A~%\" a)) result)))\n", "problem_context": "Score: 300 points\n\nProblem Statement\n\nWe have N voting papers. The i-th vote (1 \\leq i \\leq N) has the string S_i written on it.\n\nPrint all strings that are written on the most number of votes, in lexicographical order.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nS_i (1 \\leq i \\leq N) are strings consisting of lowercase English letters.\n\nThe length of S_i (1 \\leq i \\leq N) is between 1 and 10 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nPrint all strings in question in lexicographical order.\n\nSample Input 1\n\n7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n\nSample Output 1\n\nbeet\nvet\n\nbeet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.\n\nSample Input 2\n\n8\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\n\nSample Output 2\n\nbuffalo\n\nSample Input 3\n\n7\nbass\nbass\nkick\nkick\nbass\nkick\nkick\n\nSample Output 3\n\nkick\n\nSample Input 4\n\n4\nushi\ntapu\nnichia\nkun\n\nSample Output 4\n\nkun\nnichia\ntapu\nushi", "sample_input": "7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n"}, "reference_outputs": ["beet\nvet\n"], "source_document_id": "p02773", "source_text": "Score: 300 points\n\nProblem Statement\n\nWe have N voting papers. The i-th vote (1 \\leq i \\leq N) has the string S_i written on it.\n\nPrint all strings that are written on the most number of votes, in lexicographical order.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nS_i (1 \\leq i \\leq N) are strings consisting of lowercase English letters.\n\nThe length of S_i (1 \\leq i \\leq N) is between 1 and 10 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nPrint all strings in question in lexicographical order.\n\nSample Input 1\n\n7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n\nSample Output 1\n\nbeet\nvet\n\nbeet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.\n\nSample Input 2\n\n8\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\n\nSample Output 2\n\nbuffalo\n\nSample Input 3\n\n7\nbass\nbass\nkick\nkick\nbass\nkick\nkick\n\nSample Output 3\n\nkick\n\nSample Input 4\n\n4\nushi\ntapu\nnichia\nkun\n\nSample Output 4\n\nkun\nnichia\ntapu\nushi", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 588, "cpu_time_ms": 987, "memory_kb": 68836}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s005982008", "group_id": "codeNet:p02773", "input_text": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n\n(let* ((n (parse-integer (read-line nil nil)))\n (ht (make-hash-table :test #'equal))\n (maxvalue 0))\n (dotimes (i n)\n (let ((line (read-line nil nil)))\n (if (gethash line ht)\n (let ((newvalue (incf (gethash line ht))))\n (when (< maxvalue newvalue)\n (setq maxvalue newvalue)))\n (setf (gethash line ht) 1))))\n (maphash (lambda(key val)\n (when (= val maxvalue)\n (format t \"~A~%\" key))) ht))\n", "language": "Lisp", "metadata": {"date": 1581885087, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02773.html", "problem_id": "p02773", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02773/input.txt", "sample_output_relpath": "derived/input_output/data/p02773/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02773/Lisp/s005982008.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s005982008", "user_id": "u254205055"}, "prompt_components": {"gold_output": "beet\nvet\n", "input_to_evaluate": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n\n(let* ((n (parse-integer (read-line nil nil)))\n (ht (make-hash-table :test #'equal))\n (maxvalue 0))\n (dotimes (i n)\n (let ((line (read-line nil nil)))\n (if (gethash line ht)\n (let ((newvalue (incf (gethash line ht))))\n (when (< maxvalue newvalue)\n (setq maxvalue newvalue)))\n (setf (gethash line ht) 1))))\n (maphash (lambda(key val)\n (when (= val maxvalue)\n (format t \"~A~%\" key))) ht))\n", "problem_context": "Score: 300 points\n\nProblem Statement\n\nWe have N voting papers. The i-th vote (1 \\leq i \\leq N) has the string S_i written on it.\n\nPrint all strings that are written on the most number of votes, in lexicographical order.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nS_i (1 \\leq i \\leq N) are strings consisting of lowercase English letters.\n\nThe length of S_i (1 \\leq i \\leq N) is between 1 and 10 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nPrint all strings in question in lexicographical order.\n\nSample Input 1\n\n7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n\nSample Output 1\n\nbeet\nvet\n\nbeet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.\n\nSample Input 2\n\n8\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\n\nSample Output 2\n\nbuffalo\n\nSample Input 3\n\n7\nbass\nbass\nkick\nkick\nbass\nkick\nkick\n\nSample Output 3\n\nkick\n\nSample Input 4\n\n4\nushi\ntapu\nnichia\nkun\n\nSample Output 4\n\nkun\nnichia\ntapu\nushi", "sample_input": "7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n"}, "reference_outputs": ["beet\nvet\n"], "source_document_id": "p02773", "source_text": "Score: 300 points\n\nProblem Statement\n\nWe have N voting papers. The i-th vote (1 \\leq i \\leq N) has the string S_i written on it.\n\nPrint all strings that are written on the most number of votes, in lexicographical order.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nS_i (1 \\leq i \\leq N) are strings consisting of lowercase English letters.\n\nThe length of S_i (1 \\leq i \\leq N) is between 1 and 10 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\n:\nS_N\n\nOutput\n\nPrint all strings in question in lexicographical order.\n\nSample Input 1\n\n7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n\nSample Output 1\n\nbeet\nvet\n\nbeet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.\n\nSample Input 2\n\n8\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\n\nSample Output 2\n\nbuffalo\n\nSample Input 3\n\n7\nbass\nbass\nkick\nkick\nbass\nkick\nkick\n\nSample Output 3\n\nkick\n\nSample Input 4\n\n4\nushi\ntapu\nnichia\nkun\n\nSample Output 4\n\nkun\nnichia\ntapu\nushi", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 718, "cpu_time_ms": 377, "memory_kb": 63848}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s642598565", "group_id": "codeNet:p02777", "input_text": " (let ((x (read)) \n (y (read))\n (a (read))\n (b (read))\n (u (read)))\n (if (eq u x)\n (format t \"~d ~d~%\" (- a 1) b)\n (format t \"~d ~d~%\" a (- b 1))))", "language": "Lisp", "metadata": {"date": 1581279341, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02777.html", "problem_id": "p02777", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02777/input.txt", "sample_output_relpath": "derived/input_output/data/p02777/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02777/Lisp/s642598565.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s642598565", "user_id": "u690263481"}, "prompt_components": {"gold_output": "2 4\n", "input_to_evaluate": " (let ((x (read)) \n (y (read))\n (a (read))\n (b (read))\n (u (read)))\n (if (eq u x)\n (format t \"~d ~d~%\" (- a 1) b)\n (format t \"~d ~d~%\" a (- b 1))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe have A balls with the string S written on each of them and B balls with the string T written on each of them.\n\nFrom these balls, Takahashi chooses one with the string U written on it and throws it away.\n\nFind the number of balls with the string S and balls with the string T that we have now.\n\nConstraints\n\nS, T, and U are strings consisting of lowercase English letters.\n\nThe lengths of S and T are each between 1 and 10 (inclusive).\n\nS \\not= T\n\nS=U or T=U.\n\n1 \\leq A,B \\leq 10\n\nA and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS T\nA B\nU\n\nOutput\n\nPrint the answer, with space in between.\n\nSample Input 1\n\nred blue\n3 4\nred\n\nSample Output 1\n\n2 4\n\nTakahashi chose a ball with red written on it and threw it away.\nNow we have two balls with the string S and four balls with the string T.\n\nSample Input 2\n\nred blue\n5 5\nblue\n\nSample Output 2\n\n5 4\n\nTakahashi chose a ball with blue written on it and threw it away.\nNow we have five balls with the string S and four balls with the string T.", "sample_input": "red blue\n3 4\nred\n"}, "reference_outputs": ["2 4\n"], "source_document_id": "p02777", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe have A balls with the string S written on each of them and B balls with the string T written on each of them.\n\nFrom these balls, Takahashi chooses one with the string U written on it and throws it away.\n\nFind the number of balls with the string S and balls with the string T that we have now.\n\nConstraints\n\nS, T, and U are strings consisting of lowercase English letters.\n\nThe lengths of S and T are each between 1 and 10 (inclusive).\n\nS \\not= T\n\nS=U or T=U.\n\n1 \\leq A,B \\leq 10\n\nA and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS T\nA B\nU\n\nOutput\n\nPrint the answer, with space in between.\n\nSample Input 1\n\nred blue\n3 4\nred\n\nSample Output 1\n\n2 4\n\nTakahashi chose a ball with red written on it and threw it away.\nNow we have two balls with the string S and four balls with the string T.\n\nSample Input 2\n\nred blue\n5 5\nblue\n\nSample Output 2\n\n5 4\n\nTakahashi chose a ball with blue written on it and threw it away.\nNow we have five balls with the string S and four balls with the string T.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 209, "cpu_time_ms": 109, "memory_kb": 11876}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s329419285", "group_id": "codeNet:p02777", "input_text": "(let* ((n (read-string))\n (m (cons (read) (read)))\n (f (read-line)))\n (format t \"~A ~A\" (if (string= f (first n))\n (1- (car m)) (car m))\n (if (string= f (second n))\n (1- (cdr m)) (cdr m))))", "language": "Lisp", "metadata": {"date": 1581278888, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02777.html", "problem_id": "p02777", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02777/input.txt", "sample_output_relpath": "derived/input_output/data/p02777/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02777/Lisp/s329419285.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s329419285", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2 4\n", "input_to_evaluate": "(let* ((n (read-string))\n (m (cons (read) (read)))\n (f (read-line)))\n (format t \"~A ~A\" (if (string= f (first n))\n (1- (car m)) (car m))\n (if (string= f (second n))\n (1- (cdr m)) (cdr m))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe have A balls with the string S written on each of them and B balls with the string T written on each of them.\n\nFrom these balls, Takahashi chooses one with the string U written on it and throws it away.\n\nFind the number of balls with the string S and balls with the string T that we have now.\n\nConstraints\n\nS, T, and U are strings consisting of lowercase English letters.\n\nThe lengths of S and T are each between 1 and 10 (inclusive).\n\nS \\not= T\n\nS=U or T=U.\n\n1 \\leq A,B \\leq 10\n\nA and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS T\nA B\nU\n\nOutput\n\nPrint the answer, with space in between.\n\nSample Input 1\n\nred blue\n3 4\nred\n\nSample Output 1\n\n2 4\n\nTakahashi chose a ball with red written on it and threw it away.\nNow we have two balls with the string S and four balls with the string T.\n\nSample Input 2\n\nred blue\n5 5\nblue\n\nSample Output 2\n\n5 4\n\nTakahashi chose a ball with blue written on it and threw it away.\nNow we have five balls with the string S and four balls with the string T.", "sample_input": "red blue\n3 4\nred\n"}, "reference_outputs": ["2 4\n"], "source_document_id": "p02777", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe have A balls with the string S written on each of them and B balls with the string T written on each of them.\n\nFrom these balls, Takahashi chooses one with the string U written on it and throws it away.\n\nFind the number of balls with the string S and balls with the string T that we have now.\n\nConstraints\n\nS, T, and U are strings consisting of lowercase English letters.\n\nThe lengths of S and T are each between 1 and 10 (inclusive).\n\nS \\not= T\n\nS=U or T=U.\n\n1 \\leq A,B \\leq 10\n\nA and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS T\nA B\nU\n\nOutput\n\nPrint the answer, with space in between.\n\nSample Input 1\n\nred blue\n3 4\nred\n\nSample Output 1\n\n2 4\n\nTakahashi chose a ball with red written on it and threw it away.\nNow we have two balls with the string S and four balls with the string T.\n\nSample Input 2\n\nred blue\n5 5\nblue\n\nSample Output 2\n\n5 4\n\nTakahashi chose a ball with blue written on it and threw it away.\nNow we have five balls with the string S and four balls with the string T.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 247, "cpu_time_ms": 174, "memory_kb": 13664}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s549258334", "group_id": "codeNet:p02777", "input_text": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n\n(defun f(h a)\n (ceiling (/ h a)))\n(let* ((line0 (splitat #\\space (read-line nil nil)))\n (s (car line0))\n (tt (cadr line0))\n (line1 (mapcar #'parse-integer (splitat #\\space (read-line nil nil))))\n (a (car line1))\n (b (cadr line1))\n (u (read-line nil nil))\n )\n (format t \"~A ~A~%\" (if (string= u s) (1- a) a) (if (string= u tt) (1- b) b)))\n", "language": "Lisp", "metadata": {"date": 1581278797, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02777.html", "problem_id": "p02777", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02777/input.txt", "sample_output_relpath": "derived/input_output/data/p02777/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02777/Lisp/s549258334.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s549258334", "user_id": "u254205055"}, "prompt_components": {"gold_output": "2 4\n", "input_to_evaluate": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n\n(defun f(h a)\n (ceiling (/ h a)))\n(let* ((line0 (splitat #\\space (read-line nil nil)))\n (s (car line0))\n (tt (cadr line0))\n (line1 (mapcar #'parse-integer (splitat #\\space (read-line nil nil))))\n (a (car line1))\n (b (cadr line1))\n (u (read-line nil nil))\n )\n (format t \"~A ~A~%\" (if (string= u s) (1- a) a) (if (string= u tt) (1- b) b)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe have A balls with the string S written on each of them and B balls with the string T written on each of them.\n\nFrom these balls, Takahashi chooses one with the string U written on it and throws it away.\n\nFind the number of balls with the string S and balls with the string T that we have now.\n\nConstraints\n\nS, T, and U are strings consisting of lowercase English letters.\n\nThe lengths of S and T are each between 1 and 10 (inclusive).\n\nS \\not= T\n\nS=U or T=U.\n\n1 \\leq A,B \\leq 10\n\nA and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS T\nA B\nU\n\nOutput\n\nPrint the answer, with space in between.\n\nSample Input 1\n\nred blue\n3 4\nred\n\nSample Output 1\n\n2 4\n\nTakahashi chose a ball with red written on it and threw it away.\nNow we have two balls with the string S and four balls with the string T.\n\nSample Input 2\n\nred blue\n5 5\nblue\n\nSample Output 2\n\n5 4\n\nTakahashi chose a ball with blue written on it and threw it away.\nNow we have five balls with the string S and four balls with the string T.", "sample_input": "red blue\n3 4\nred\n"}, "reference_outputs": ["2 4\n"], "source_document_id": "p02777", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe have A balls with the string S written on each of them and B balls with the string T written on each of them.\n\nFrom these balls, Takahashi chooses one with the string U written on it and throws it away.\n\nFind the number of balls with the string S and balls with the string T that we have now.\n\nConstraints\n\nS, T, and U are strings consisting of lowercase English letters.\n\nThe lengths of S and T are each between 1 and 10 (inclusive).\n\nS \\not= T\n\nS=U or T=U.\n\n1 \\leq A,B \\leq 10\n\nA and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS T\nA B\nU\n\nOutput\n\nPrint the answer, with space in between.\n\nSample Input 1\n\nred blue\n3 4\nred\n\nSample Output 1\n\n2 4\n\nTakahashi chose a ball with red written on it and threw it away.\nNow we have two balls with the string S and four balls with the string T.\n\nSample Input 2\n\nred blue\n5 5\nblue\n\nSample Output 2\n\n5 4\n\nTakahashi chose a ball with blue written on it and threw it away.\nNow we have five balls with the string S and four balls with the string T.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 631, "cpu_time_ms": 249, "memory_kb": 16484}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s931853799", "group_id": "codeNet:p02777", "input_text": "(defun solve (balls1 balls2 a b u)\n (if (equal u balls1)\n (list (1- a) b)\n (list a (1- b))))\n\n#-swank\n(let* ((balls (read-line))\n (a (read))\n (b (read))\n (u (read-line))\n (balls1 (subseq balls 0 (position #\\Space balls)))\n (balls2 (subseq balls (1+ (position #\\Space balls)))))\n (format t \"~{~A~^ ~}~%\" (solve balls1 balls2 a b u)))\n", "language": "Lisp", "metadata": {"date": 1581278584, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02777.html", "problem_id": "p02777", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02777/input.txt", "sample_output_relpath": "derived/input_output/data/p02777/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02777/Lisp/s931853799.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s931853799", "user_id": "u202886318"}, "prompt_components": {"gold_output": "2 4\n", "input_to_evaluate": "(defun solve (balls1 balls2 a b u)\n (if (equal u balls1)\n (list (1- a) b)\n (list a (1- b))))\n\n#-swank\n(let* ((balls (read-line))\n (a (read))\n (b (read))\n (u (read-line))\n (balls1 (subseq balls 0 (position #\\Space balls)))\n (balls2 (subseq balls (1+ (position #\\Space balls)))))\n (format t \"~{~A~^ ~}~%\" (solve balls1 balls2 a b u)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe have A balls with the string S written on each of them and B balls with the string T written on each of them.\n\nFrom these balls, Takahashi chooses one with the string U written on it and throws it away.\n\nFind the number of balls with the string S and balls with the string T that we have now.\n\nConstraints\n\nS, T, and U are strings consisting of lowercase English letters.\n\nThe lengths of S and T are each between 1 and 10 (inclusive).\n\nS \\not= T\n\nS=U or T=U.\n\n1 \\leq A,B \\leq 10\n\nA and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS T\nA B\nU\n\nOutput\n\nPrint the answer, with space in between.\n\nSample Input 1\n\nred blue\n3 4\nred\n\nSample Output 1\n\n2 4\n\nTakahashi chose a ball with red written on it and threw it away.\nNow we have two balls with the string S and four balls with the string T.\n\nSample Input 2\n\nred blue\n5 5\nblue\n\nSample Output 2\n\n5 4\n\nTakahashi chose a ball with blue written on it and threw it away.\nNow we have five balls with the string S and four balls with the string T.", "sample_input": "red blue\n3 4\nred\n"}, "reference_outputs": ["2 4\n"], "source_document_id": "p02777", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe have A balls with the string S written on each of them and B balls with the string T written on each of them.\n\nFrom these balls, Takahashi chooses one with the string U written on it and throws it away.\n\nFind the number of balls with the string S and balls with the string T that we have now.\n\nConstraints\n\nS, T, and U are strings consisting of lowercase English letters.\n\nThe lengths of S and T are each between 1 and 10 (inclusive).\n\nS \\not= T\n\nS=U or T=U.\n\n1 \\leq A,B \\leq 10\n\nA and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS T\nA B\nU\n\nOutput\n\nPrint the answer, with space in between.\n\nSample Input 1\n\nred blue\n3 4\nred\n\nSample Output 1\n\n2 4\n\nTakahashi chose a ball with red written on it and threw it away.\nNow we have two balls with the string S and four balls with the string T.\n\nSample Input 2\n\nred blue\n5 5\nblue\n\nSample Output 2\n\n5 4\n\nTakahashi chose a ball with blue written on it and threw it away.\nNow we have five balls with the string S and four balls with the string T.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 375, "cpu_time_ms": 235, "memory_kb": 12900}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s122019468", "group_id": "codeNet:p02778", "input_text": "(format t \"~V@{~A~:*~}\" (length (read-line)) \"x\")", "language": "Lisp", "metadata": {"date": 1584834516, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02778.html", "problem_id": "p02778", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02778/input.txt", "sample_output_relpath": "derived/input_output/data/p02778/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02778/Lisp/s122019468.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s122019468", "user_id": "u334552723"}, "prompt_components": {"gold_output": "xxxxxxx\n", "input_to_evaluate": "(format t \"~V@{~A~:*~}\" (length (read-line)) \"x\")", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven is a string S. Replace every character in S with x and print the result.\n\nConstraints\n\nS is a string consisting of lowercase English letters.\n\nThe length of S is between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nReplace every character in S with x and print the result.\n\nSample Input 1\n\nsardine\n\nSample Output 1\n\nxxxxxxx\n\nReplacing every character in S with x results in xxxxxxx.\n\nSample Input 2\n\nxxxx\n\nSample Output 2\n\nxxxx\n\nSample Input 3\n\ngone\n\nSample Output 3\n\nxxxx", "sample_input": "sardine\n"}, "reference_outputs": ["xxxxxxx\n"], "source_document_id": "p02778", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven is a string S. Replace every character in S with x and print the result.\n\nConstraints\n\nS is a string consisting of lowercase English letters.\n\nThe length of S is between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nReplace every character in S with x and print the result.\n\nSample Input 1\n\nsardine\n\nSample Output 1\n\nxxxxxxx\n\nReplacing every character in S with x results in xxxxxxx.\n\nSample Input 2\n\nxxxx\n\nSample Output 2\n\nxxxx\n\nSample Input 3\n\ngone\n\nSample Output 3\n\nxxxx", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 49, "cpu_time_ms": 18, "memory_kb": 3688}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s210631970", "group_id": "codeNet:p02779", "input_text": "(let* ((n (read))\n (m (remove-duplicates (loop :repeat n :collect (read)))))\n (if (= (length m) n)\n (princ \"YES\")\n (princ \"NO\")))", "language": "Lisp", "metadata": {"date": 1581279168, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02779.html", "problem_id": "p02779", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02779/input.txt", "sample_output_relpath": "derived/input_output/data/p02779/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02779/Lisp/s210631970.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s210631970", "user_id": "u610490393"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(let* ((n (read))\n (m (remove-duplicates (loop :repeat n :collect (read)))))\n (if (= (length m) n)\n (princ \"YES\")\n (princ \"NO\")))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven is a sequence of integers A_1, A_2, ..., A_N.\nIf its elements are pairwise distinct, print YES; otherwise, print NO.\n\nConstraints\n\n2 ≤ N ≤ 200000\n\n1 ≤ A_i ≤ 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 ... A_N\n\nOutput\n\nIf the elements of the sequence are pairwise distinct, print YES; otherwise, print NO.\n\nSample Input 1\n\n5\n2 6 1 4 5\n\nSample Output 1\n\nYES\n\nThe elements are pairwise distinct.\n\nSample Input 2\n\n6\n4 1 3 1 6 2\n\nSample Output 2\n\nNO\n\nThe second and fourth elements are identical.\n\nSample Input 3\n\n2\n10000000 10000000\n\nSample Output 3\n\nNO", "sample_input": "5\n2 6 1 4 5\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p02779", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven is a sequence of integers A_1, A_2, ..., A_N.\nIf its elements are pairwise distinct, print YES; otherwise, print NO.\n\nConstraints\n\n2 ≤ N ≤ 200000\n\n1 ≤ A_i ≤ 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 ... A_N\n\nOutput\n\nIf the elements of the sequence are pairwise distinct, print YES; otherwise, print NO.\n\nSample Input 1\n\n5\n2 6 1 4 5\n\nSample Output 1\n\nYES\n\nThe elements are pairwise distinct.\n\nSample Input 2\n\n6\n4 1 3 1 6 2\n\nSample Output 2\n\nNO\n\nThe second and fourth elements are identical.\n\nSample Input 3\n\n2\n10000000 10000000\n\nSample Output 3\n\nNO", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 146, "cpu_time_ms": 572, "memory_kb": 61792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s849255608", "group_id": "codeNet:p02779", "input_text": "(defun solve (n a)\n (let ((hash (make-hash-table)))\n (loop for x in a\n if (gethash x hash)\n do (return \"NO\")\n else\n do (setf (gethash x hash) t)\n finally (return \"YES\"))))\n\n#-swank\n(let* ((n (read))\n (a (loop repeat n collect (read))))\n (format t \"~A~%\" (solve n a)))\n", "language": "Lisp", "metadata": {"date": 1581278739, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02779.html", "problem_id": "p02779", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02779/input.txt", "sample_output_relpath": "derived/input_output/data/p02779/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02779/Lisp/s849255608.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s849255608", "user_id": "u202886318"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(defun solve (n a)\n (let ((hash (make-hash-table)))\n (loop for x in a\n if (gethash x hash)\n do (return \"NO\")\n else\n do (setf (gethash x hash) t)\n finally (return \"YES\"))))\n\n#-swank\n(let* ((n (read))\n (a (loop repeat n collect (read))))\n (format t \"~A~%\" (solve n a)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven is a sequence of integers A_1, A_2, ..., A_N.\nIf its elements are pairwise distinct, print YES; otherwise, print NO.\n\nConstraints\n\n2 ≤ N ≤ 200000\n\n1 ≤ A_i ≤ 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 ... A_N\n\nOutput\n\nIf the elements of the sequence are pairwise distinct, print YES; otherwise, print NO.\n\nSample Input 1\n\n5\n2 6 1 4 5\n\nSample Output 1\n\nYES\n\nThe elements are pairwise distinct.\n\nSample Input 2\n\n6\n4 1 3 1 6 2\n\nSample Output 2\n\nNO\n\nThe second and fourth elements are identical.\n\nSample Input 3\n\n2\n10000000 10000000\n\nSample Output 3\n\nNO", "sample_input": "5\n2 6 1 4 5\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p02779", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven is a sequence of integers A_1, A_2, ..., A_N.\nIf its elements are pairwise distinct, print YES; otherwise, print NO.\n\nConstraints\n\n2 ≤ N ≤ 200000\n\n1 ≤ A_i ≤ 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 ... A_N\n\nOutput\n\nIf the elements of the sequence are pairwise distinct, print YES; otherwise, print NO.\n\nSample Input 1\n\n5\n2 6 1 4 5\n\nSample Output 1\n\nYES\n\nThe elements are pairwise distinct.\n\nSample Input 2\n\n6\n4 1 3 1 6 2\n\nSample Output 2\n\nNO\n\nThe second and fourth elements are identical.\n\nSample Input 3\n\n2\n10000000 10000000\n\nSample Output 3\n\nNO", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 324, "cpu_time_ms": 586, "memory_kb": 61928}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s256261911", "group_id": "codeNet:p02783", "input_text": "(let ((h (read))\n (a (read)))\n (princ\n (ceiling h a)))\n", "language": "Lisp", "metadata": {"date": 1588938985, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02783.html", "problem_id": "p02783", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02783/input.txt", "sample_output_relpath": "derived/input_output/data/p02783/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02783/Lisp/s256261911.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s256261911", "user_id": "u425762225"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((h (read))\n (a (read)))\n (princ\n (ceiling h a)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nServal is fighting with a monster.\n\nThe health of the monster is H.\n\nIn one attack, Serval can decrease the monster's health by A.\nThere is no other way to decrease the monster's health.\n\nServal wins when the monster's health becomes 0 or below.\n\nFind the number of attacks Serval needs to make before winning.\n\nConstraints\n\n1 \\leq H \\leq 10^4\n\n1 \\leq A \\leq 10^4\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH A\n\nOutput\n\nPrint the number of attacks Serval needs to make before winning.\n\nSample Input 1\n\n10 4\n\nSample Output 1\n\n3\n\nAfter one attack, the monster's health will be 6.\n\nAfter two attacks, the monster's health will be 2.\n\nAfter three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\nSample Input 2\n\n1 10000\n\nSample Output 2\n\n1\n\nSample Input 3\n\n10000 1\n\nSample Output 3\n\n10000", "sample_input": "10 4\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02783", "source_text": "Score : 100 points\n\nProblem Statement\n\nServal is fighting with a monster.\n\nThe health of the monster is H.\n\nIn one attack, Serval can decrease the monster's health by A.\nThere is no other way to decrease the monster's health.\n\nServal wins when the monster's health becomes 0 or below.\n\nFind the number of attacks Serval needs to make before winning.\n\nConstraints\n\n1 \\leq H \\leq 10^4\n\n1 \\leq A \\leq 10^4\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH A\n\nOutput\n\nPrint the number of attacks Serval needs to make before winning.\n\nSample Input 1\n\n10 4\n\nSample Output 1\n\n3\n\nAfter one attack, the monster's health will be 6.\n\nAfter two attacks, the monster's health will be 2.\n\nAfter three attacks, the monster's health will be -2.\n\nThus, Serval needs to make three attacks to win.\n\nSample Input 2\n\n1 10000\n\nSample Output 2\n\n1\n\nSample Input 3\n\n10000 1\n\nSample Output 3\n\n10000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 69, "cpu_time_ms": 12, "memory_kb": 3560}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s029455474", "group_id": "codeNet:p02784", "input_text": "(defun read-and-sum (n)\n (loop :repeat n\n :sum (read)))\n\n(let* ((enemy-hp (read))\n (n (read))\n (deathblow-damages (read-and-sum n)))\n (if (<= enemy-hp (apply #'+ deathblow-damages))\n (princ \"Yes\")\n (princ \"No\")))\n ", "language": "Lisp", "metadata": {"date": 1585605080, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02784.html", "problem_id": "p02784", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02784/input.txt", "sample_output_relpath": "derived/input_output/data/p02784/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02784/Lisp/s029455474.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s029455474", "user_id": "u606976120"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun read-and-sum (n)\n (loop :repeat n\n :sum (read)))\n\n(let* ((enemy-hp (read))\n (n (read))\n (deathblow-damages (read-and-sum n)))\n (if (<= enemy-hp (apply #'+ deathblow-damages))\n (princ \"Yes\")\n (princ \"No\")))\n ", "problem_context": "Score : 200 points\n\nProblem Statement\n\nRaccoon is fighting with a monster.\n\nThe health of the monster is H.\n\nRaccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i.\nThere is no other way to decrease the monster's health.\n\nRaccoon wins when the monster's health becomes 0 or below.\n\nIf Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.\n\nConstraints\n\n1 \\leq H \\leq 10^9\n\n1 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^4\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH N\nA_1 A_2 ... A_N\n\nOutput\n\nIf Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.\n\nSample Input 1\n\n10 3\n4 5 6\n\nSample Output 1\n\nYes\n\nThe monster's health will become 0 or below after, for example, using the second and third moves.\n\nSample Input 2\n\n20 3\n4 5 6\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n210 5\n31 41 59 26 53\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n211 5\n31 41 59 26 53\n\nSample Output 4\n\nNo", "sample_input": "10 3\n4 5 6\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02784", "source_text": "Score : 200 points\n\nProblem Statement\n\nRaccoon is fighting with a monster.\n\nThe health of the monster is H.\n\nRaccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i.\nThere is no other way to decrease the monster's health.\n\nRaccoon wins when the monster's health becomes 0 or below.\n\nIf Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.\n\nConstraints\n\n1 \\leq H \\leq 10^9\n\n1 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^4\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH N\nA_1 A_2 ... A_N\n\nOutput\n\nIf Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.\n\nSample Input 1\n\n10 3\n4 5 6\n\nSample Output 1\n\nYes\n\nThe monster's health will become 0 or below after, for example, using the second and third moves.\n\nSample Input 2\n\n20 3\n4 5 6\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n210 5\n31 41 59 26 53\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n211 5\n31 41 59 26 53\n\nSample Output 4\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 246, "cpu_time_ms": 195, "memory_kb": 57828}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s262949151", "group_id": "codeNet:p02784", "input_text": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n\n(defun f(h ai)\n (<= h (reduce #'+ ai)))\n(let* ((line0 (mapcar #'read-from-string (splitat #\\space (read-line nil nil))))\n (line2 (mapcar #'read-from-string (splitat #\\space (read-line nil nil))))\n (line1 (make-array (length line2) :initial-contents line2)))\n (format t \"~A~%\" (if (f (car line0) line1) \"Yes\" \"No\")))\n", "language": "Lisp", "metadata": {"date": 1580072203, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02784.html", "problem_id": "p02784", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02784/input.txt", "sample_output_relpath": "derived/input_output/data/p02784/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02784/Lisp/s262949151.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s262949151", "user_id": "u254205055"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n\n(defun f(h ai)\n (<= h (reduce #'+ ai)))\n(let* ((line0 (mapcar #'read-from-string (splitat #\\space (read-line nil nil))))\n (line2 (mapcar #'read-from-string (splitat #\\space (read-line nil nil))))\n (line1 (make-array (length line2) :initial-contents line2)))\n (format t \"~A~%\" (if (f (car line0) line1) \"Yes\" \"No\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nRaccoon is fighting with a monster.\n\nThe health of the monster is H.\n\nRaccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i.\nThere is no other way to decrease the monster's health.\n\nRaccoon wins when the monster's health becomes 0 or below.\n\nIf Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.\n\nConstraints\n\n1 \\leq H \\leq 10^9\n\n1 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^4\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH N\nA_1 A_2 ... A_N\n\nOutput\n\nIf Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.\n\nSample Input 1\n\n10 3\n4 5 6\n\nSample Output 1\n\nYes\n\nThe monster's health will become 0 or below after, for example, using the second and third moves.\n\nSample Input 2\n\n20 3\n4 5 6\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n210 5\n31 41 59 26 53\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n211 5\n31 41 59 26 53\n\nSample Output 4\n\nNo", "sample_input": "10 3\n4 5 6\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02784", "source_text": "Score : 200 points\n\nProblem Statement\n\nRaccoon is fighting with a monster.\n\nThe health of the monster is H.\n\nRaccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i.\nThere is no other way to decrease the monster's health.\n\nRaccoon wins when the monster's health becomes 0 or below.\n\nIf Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.\n\nConstraints\n\n1 \\leq H \\leq 10^9\n\n1 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^4\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH N\nA_1 A_2 ... A_N\n\nOutput\n\nIf Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.\n\nSample Input 1\n\n10 3\n4 5 6\n\nSample Output 1\n\nYes\n\nThe monster's health will become 0 or below after, for example, using the second and third moves.\n\nSample Input 2\n\n20 3\n4 5 6\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n210 5\n31 41 59 26 53\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n211 5\n31 41 59 26 53\n\nSample Output 4\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 577, "cpu_time_ms": 2105, "memory_kb": 95860}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s009463386", "group_id": "codeNet:p02784", "input_text": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n\n(defun f(h ai)\n (<= h (reduce #'+ ai)))\n(let ((line0 (mapcar #'read-from-string (splitat #\\space (read-line nil nil))))\n (line1 (map 'array #'identity (mapcar #'read-from-string (splitat #\\space (read-line nil nil))))))\n (format t \"~A~%\" (if (f (car line0) line1) \"Yes\" \"No\")))\n", "language": "Lisp", "metadata": {"date": 1580071691, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02784.html", "problem_id": "p02784", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02784/input.txt", "sample_output_relpath": "derived/input_output/data/p02784/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02784/Lisp/s009463386.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s009463386", "user_id": "u254205055"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n\n(defun f(h ai)\n (<= h (reduce #'+ ai)))\n(let ((line0 (mapcar #'read-from-string (splitat #\\space (read-line nil nil))))\n (line1 (map 'array #'identity (mapcar #'read-from-string (splitat #\\space (read-line nil nil))))))\n (format t \"~A~%\" (if (f (car line0) line1) \"Yes\" \"No\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nRaccoon is fighting with a monster.\n\nThe health of the monster is H.\n\nRaccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i.\nThere is no other way to decrease the monster's health.\n\nRaccoon wins when the monster's health becomes 0 or below.\n\nIf Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.\n\nConstraints\n\n1 \\leq H \\leq 10^9\n\n1 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^4\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH N\nA_1 A_2 ... A_N\n\nOutput\n\nIf Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.\n\nSample Input 1\n\n10 3\n4 5 6\n\nSample Output 1\n\nYes\n\nThe monster's health will become 0 or below after, for example, using the second and third moves.\n\nSample Input 2\n\n20 3\n4 5 6\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n210 5\n31 41 59 26 53\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n211 5\n31 41 59 26 53\n\nSample Output 4\n\nNo", "sample_input": "10 3\n4 5 6\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02784", "source_text": "Score : 200 points\n\nProblem Statement\n\nRaccoon is fighting with a monster.\n\nThe health of the monster is H.\n\nRaccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i.\nThere is no other way to decrease the monster's health.\n\nRaccoon wins when the monster's health becomes 0 or below.\n\nIf Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.\n\nConstraints\n\n1 \\leq H \\leq 10^9\n\n1 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^4\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH N\nA_1 A_2 ... A_N\n\nOutput\n\nIf Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.\n\nSample Input 1\n\n10 3\n4 5 6\n\nSample Output 1\n\nYes\n\nThe monster's health will become 0 or below after, for example, using the second and third moves.\n\nSample Input 2\n\n20 3\n4 5 6\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n210 5\n31 41 59 26 53\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n211 5\n31 41 59 26 53\n\nSample Output 4\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 534, "cpu_time_ms": 2105, "memory_kb": 94360}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s066056204", "group_id": "codeNet:p02784", "input_text": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n\n(defun f(h ai)\n (<= h (reduce #'+ ai)))\n(let ((line0 (mapcar #'parse-integer (splitat #\\space (read-line nil nil))))\n (line1 (map 'array #'identity (mapcar #'parse-integer (splitat #\\space (read-line nil nil))))))\n (format t \"~A~%\" (if (f (car line0) line1) \"Yes\" \"No\")))\n", "language": "Lisp", "metadata": {"date": 1580070772, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02784.html", "problem_id": "p02784", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02784/input.txt", "sample_output_relpath": "derived/input_output/data/p02784/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02784/Lisp/s066056204.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s066056204", "user_id": "u254205055"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n\n(defun f(h ai)\n (<= h (reduce #'+ ai)))\n(let ((line0 (mapcar #'parse-integer (splitat #\\space (read-line nil nil))))\n (line1 (map 'array #'identity (mapcar #'parse-integer (splitat #\\space (read-line nil nil))))))\n (format t \"~A~%\" (if (f (car line0) line1) \"Yes\" \"No\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nRaccoon is fighting with a monster.\n\nThe health of the monster is H.\n\nRaccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i.\nThere is no other way to decrease the monster's health.\n\nRaccoon wins when the monster's health becomes 0 or below.\n\nIf Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.\n\nConstraints\n\n1 \\leq H \\leq 10^9\n\n1 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^4\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH N\nA_1 A_2 ... A_N\n\nOutput\n\nIf Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.\n\nSample Input 1\n\n10 3\n4 5 6\n\nSample Output 1\n\nYes\n\nThe monster's health will become 0 or below after, for example, using the second and third moves.\n\nSample Input 2\n\n20 3\n4 5 6\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n210 5\n31 41 59 26 53\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n211 5\n31 41 59 26 53\n\nSample Output 4\n\nNo", "sample_input": "10 3\n4 5 6\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02784", "source_text": "Score : 200 points\n\nProblem Statement\n\nRaccoon is fighting with a monster.\n\nThe health of the monster is H.\n\nRaccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i.\nThere is no other way to decrease the monster's health.\n\nRaccoon wins when the monster's health becomes 0 or below.\n\nIf Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.\n\nConstraints\n\n1 \\leq H \\leq 10^9\n\n1 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^4\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH N\nA_1 A_2 ... A_N\n\nOutput\n\nIf Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.\n\nSample Input 1\n\n10 3\n4 5 6\n\nSample Output 1\n\nYes\n\nThe monster's health will become 0 or below after, for example, using the second and third moves.\n\nSample Input 2\n\n20 3\n4 5 6\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n210 5\n31 41 59 26 53\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n211 5\n31 41 59 26 53\n\nSample Output 4\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 528, "cpu_time_ms": 2105, "memory_kb": 94296}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s560981049", "group_id": "codeNet:p02785", "input_text": "(defun create-data ()\n (let ((n (read))\n (k (read))\n (h))\n (dotimes (i n)\n (push (read) h))\n (sort (copy-list h) #'>)\n (values n k h)))\n\n(defun fennec-vs-monster (n k h)\n (dotimes (i k) \n (pop h) \n (if (null h) \n (return))) \n (loop for i in h \n sum i)) \n\n\n(multiple-value-bind (n k h) (create-data)\n (format t \"~D~%\" (fennec-vs-monster n k h)))\n\n", "language": "Lisp", "metadata": {"date": 1580725703, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02785.html", "problem_id": "p02785", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02785/input.txt", "sample_output_relpath": "derived/input_output/data/p02785/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02785/Lisp/s560981049.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s560981049", "user_id": "u091381267"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defun create-data ()\n (let ((n (read))\n (k (read))\n (h))\n (dotimes (i n)\n (push (read) h))\n (sort (copy-list h) #'>)\n (values n k h)))\n\n(defun fennec-vs-monster (n k h)\n (dotimes (i k) \n (pop h) \n (if (null h) \n (return))) \n (loop for i in h \n sum i)) \n\n\n(multiple-value-bind (n k h) (create-data)\n (format t \"~D~%\" (fennec-vs-monster n k h)))\n\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nFennec is fighting with N monsters.\n\nThe health of the i-th monster is H_i.\n\nFennec can do the following two actions:\n\nAttack: Fennec chooses one monster. That monster's health will decrease by 1.\n\nSpecial Move: Fennec chooses one monster. That monster's health will become 0.\n\nThere is no way other than Attack and Special Move to decrease the monsters' health.\n\nFennec wins when all the monsters' healths become 0 or below.\n\nFind the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n0 \\leq K \\leq 2 \\times 10^5\n\n1 \\leq H_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nH_1 ... H_N\n\nOutput\n\nPrint the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.\n\nSample Input 1\n\n3 1\n4 1 5\n\nSample Output 1\n\n5\n\nBy using Special Move on the third monster, and doing Attack four times on the first monster and once on the second monster, Fennec can win with five Attacks.\n\nSample Input 2\n\n8 9\n7 9 3 2 3 8 4 6\n\nSample Output 2\n\n0\n\nShe can use Special Move on all the monsters.\n\nSample Input 3\n\n3 0\n1000000000 1000000000 1000000000\n\nSample Output 3\n\n3000000000\n\nWatch out for overflow.", "sample_input": "3 1\n4 1 5\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02785", "source_text": "Score : 300 points\n\nProblem Statement\n\nFennec is fighting with N monsters.\n\nThe health of the i-th monster is H_i.\n\nFennec can do the following two actions:\n\nAttack: Fennec chooses one monster. That monster's health will decrease by 1.\n\nSpecial Move: Fennec chooses one monster. That monster's health will become 0.\n\nThere is no way other than Attack and Special Move to decrease the monsters' health.\n\nFennec wins when all the monsters' healths become 0 or below.\n\nFind the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n0 \\leq K \\leq 2 \\times 10^5\n\n1 \\leq H_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nH_1 ... H_N\n\nOutput\n\nPrint the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.\n\nSample Input 1\n\n3 1\n4 1 5\n\nSample Output 1\n\n5\n\nBy using Special Move on the third monster, and doing Attack four times on the first monster and once on the second monster, Fennec can win with five Attacks.\n\nSample Input 2\n\n8 9\n7 9 3 2 3 8 4 6\n\nSample Output 2\n\n0\n\nShe can use Special Move on all the monsters.\n\nSample Input 3\n\n3 0\n1000000000 1000000000 1000000000\n\nSample Output 3\n\n3000000000\n\nWatch out for overflow.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 398, "cpu_time_ms": 618, "memory_kb": 61792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s474405118", "group_id": "codeNet:p02785", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n\t:unix-status\n\t(process-exit-code\n\t (run-program *runtime-pathname*\n\t\t\t\t `(\"--control-stack-size\" \"128MB\"\n\t\t\t\t\t \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n\t\t\t\t\t \"--eval\" \"(push :child-sbcl *features*)\"\n\t\t\t\t\t \"--script\" ,(namestring *load-pathname*))\n\t\t\t\t :output t :error t :input t))))\n\n\n(let* ((n (read))\n\t (k (read))\n\t (h (concatenate 'vector (sort (loop repeat n collect (read)) #'<))))\n (princ (loop for i below (- n k) sum (aref h i))))\n", "language": "Lisp", "metadata": {"date": 1580069263, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02785.html", "problem_id": "p02785", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02785/input.txt", "sample_output_relpath": "derived/input_output/data/p02785/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02785/Lisp/s474405118.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s474405118", "user_id": "u493610446"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n\t:unix-status\n\t(process-exit-code\n\t (run-program *runtime-pathname*\n\t\t\t\t `(\"--control-stack-size\" \"128MB\"\n\t\t\t\t\t \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n\t\t\t\t\t \"--eval\" \"(push :child-sbcl *features*)\"\n\t\t\t\t\t \"--script\" ,(namestring *load-pathname*))\n\t\t\t\t :output t :error t :input t))))\n\n\n(let* ((n (read))\n\t (k (read))\n\t (h (concatenate 'vector (sort (loop repeat n collect (read)) #'<))))\n (princ (loop for i below (- n k) sum (aref h i))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nFennec is fighting with N monsters.\n\nThe health of the i-th monster is H_i.\n\nFennec can do the following two actions:\n\nAttack: Fennec chooses one monster. That monster's health will decrease by 1.\n\nSpecial Move: Fennec chooses one monster. That monster's health will become 0.\n\nThere is no way other than Attack and Special Move to decrease the monsters' health.\n\nFennec wins when all the monsters' healths become 0 or below.\n\nFind the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n0 \\leq K \\leq 2 \\times 10^5\n\n1 \\leq H_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nH_1 ... H_N\n\nOutput\n\nPrint the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.\n\nSample Input 1\n\n3 1\n4 1 5\n\nSample Output 1\n\n5\n\nBy using Special Move on the third monster, and doing Attack four times on the first monster and once on the second monster, Fennec can win with five Attacks.\n\nSample Input 2\n\n8 9\n7 9 3 2 3 8 4 6\n\nSample Output 2\n\n0\n\nShe can use Special Move on all the monsters.\n\nSample Input 3\n\n3 0\n1000000000 1000000000 1000000000\n\nSample Output 3\n\n3000000000\n\nWatch out for overflow.", "sample_input": "3 1\n4 1 5\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02785", "source_text": "Score : 300 points\n\nProblem Statement\n\nFennec is fighting with N monsters.\n\nThe health of the i-th monster is H_i.\n\nFennec can do the following two actions:\n\nAttack: Fennec chooses one monster. That monster's health will decrease by 1.\n\nSpecial Move: Fennec chooses one monster. That monster's health will become 0.\n\nThere is no way other than Attack and Special Move to decrease the monsters' health.\n\nFennec wins when all the monsters' healths become 0 or below.\n\nFind the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n0 \\leq K \\leq 2 \\times 10^5\n\n1 \\leq H_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nH_1 ... H_N\n\nOutput\n\nPrint the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.\n\nSample Input 1\n\n3 1\n4 1 5\n\nSample Output 1\n\n5\n\nBy using Special Move on the third monster, and doing Attack four times on the first monster and once on the second monster, Fennec can win with five Attacks.\n\nSample Input 2\n\n8 9\n7 9 3 2 3 8 4 6\n\nSample Output 2\n\n0\n\nShe can use Special Move on all the monsters.\n\nSample Input 3\n\n3 0\n1000000000 1000000000 1000000000\n\nSample Output 3\n\n3000000000\n\nWatch out for overflow.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 542, "cpu_time_ms": 644, "memory_kb": 64564}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s641470392", "group_id": "codeNet:p02786", "input_text": "(defun solve (h)\n (if (= h 1)\n 1\n (1+ (* 2 (solve (floor h 2))))))\n\n#-swank\n(let* ((h (read)))\n (format t \"~A~%\" (solve h)))\n", "language": "Lisp", "metadata": {"date": 1580079243, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02786.html", "problem_id": "p02786", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02786/input.txt", "sample_output_relpath": "derived/input_output/data/p02786/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02786/Lisp/s641470392.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s641470392", "user_id": "u202886318"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun solve (h)\n (if (= h 1)\n 1\n (1+ (* 2 (solve (floor h 2))))))\n\n#-swank\n(let* ((h (read)))\n (format t \"~A~%\" (solve h)))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nCaracal is fighting with a monster.\n\nThe health of the monster is H.\n\nCaracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:\n\nIf the monster's health is 1, it drops to 0.\n\nIf the monster's health, X, is greater than 1, that monster disappears. Then, two new monsters appear, each with the health of \\lfloor X/2 \\rfloor.\n\n(\\lfloor r \\rfloor denotes the greatest integer not exceeding r.)\n\nCaracal wins when the healths of all existing monsters become 0 or below.\n\nFind the minimum number of attacks Caracal needs to make before winning.\n\nConstraints\n\n1 \\leq H \\leq 10^{12}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH\n\nOutput\n\nFind the minimum number of attacks Caracal needs to make before winning.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n3\n\nWhen Caracal attacks the initial monster, it disappears, and two monsters appear, each with the health of 1.\n\nThen, Caracal can attack each of these new monsters once and win with a total of three attacks.\n\nSample Input 2\n\n4\n\nSample Output 2\n\n7\n\nSample Input 3\n\n1000000000000\n\nSample Output 3\n\n1099511627775", "sample_input": "2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02786", "source_text": "Score : 400 points\n\nProblem Statement\n\nCaracal is fighting with a monster.\n\nThe health of the monster is H.\n\nCaracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:\n\nIf the monster's health is 1, it drops to 0.\n\nIf the monster's health, X, is greater than 1, that monster disappears. Then, two new monsters appear, each with the health of \\lfloor X/2 \\rfloor.\n\n(\\lfloor r \\rfloor denotes the greatest integer not exceeding r.)\n\nCaracal wins when the healths of all existing monsters become 0 or below.\n\nFind the minimum number of attacks Caracal needs to make before winning.\n\nConstraints\n\n1 \\leq H \\leq 10^{12}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH\n\nOutput\n\nFind the minimum number of attacks Caracal needs to make before winning.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n3\n\nWhen Caracal attacks the initial monster, it disappears, and two monsters appear, each with the health of 1.\n\nThen, Caracal can attack each of these new monsters once and win with a total of three attacks.\n\nSample Input 2\n\n4\n\nSample Output 2\n\n7\n\nSample Input 3\n\n1000000000000\n\nSample Output 3\n\n1099511627775", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 137, "cpu_time_ms": 23, "memory_kb": 4580}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s300360738", "group_id": "codeNet:p02790", "input_text": "(defun comparing-strings (a b)\n (if (<= a b)\n (dotimes (i b) \n (prin1 a))\n (dotimes (i a) \n (prin1 b)))) \n\n(format t \"~A~%\" (comparing-strings (read) (read))) \n\n", "language": "Lisp", "metadata": {"date": 1580932172, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02790.html", "problem_id": "p02790", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02790/input.txt", "sample_output_relpath": "derived/input_output/data/p02790/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02790/Lisp/s300360738.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s300360738", "user_id": "u091381267"}, "prompt_components": {"gold_output": "3333\n", "input_to_evaluate": "(defun comparing-strings (a b)\n (if (<= a b)\n (dotimes (i b) \n (prin1 a))\n (dotimes (i a) \n (prin1 b)))) \n\n(format t \"~A~%\" (comparing-strings (read) (read))) \n\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller?\n\nConstraints\n\n1 \\leq a \\leq 9\n\n1 \\leq b \\leq 9\n\na and b are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nPrint the lexicographically smaller of the two strings. (If the two strings are equal, print one of them.)\n\nSample Input 1\n\n4 3\n\nSample Output 1\n\n3333\n\nWe have two strings 444 and 3333. Between them, 3333 is the lexicographically smaller.\n\nSample Input 2\n\n7 7\n\nSample Output 2\n\n7777777", "sample_input": "4 3\n"}, "reference_outputs": ["3333\n"], "source_document_id": "p02790", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller?\n\nConstraints\n\n1 \\leq a \\leq 9\n\n1 \\leq b \\leq 9\n\na and b are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nPrint the lexicographically smaller of the two strings. (If the two strings are equal, print one of them.)\n\nSample Input 1\n\n4 3\n\nSample Output 1\n\n3333\n\nWe have two strings 444 and 3333. Between them, 3333 is the lexicographically smaller.\n\nSample Input 2\n\n7 7\n\nSample Output 2\n\n7777777", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 186, "cpu_time_ms": 63, "memory_kb": 5732}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s234612655", "group_id": "codeNet:p02790", "input_text": "(let* ((ls (read-from-string (concatenate 'string \"(\" (read-line) \")\")))\n (mx (apply #'max ls))\n (mn (apply #'min ls)))\n (princ (make-string mx :initial-element (char (prin1-to-string mn) 0))))\n", "language": "Lisp", "metadata": {"date": 1579469301, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02790.html", "problem_id": "p02790", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02790/input.txt", "sample_output_relpath": "derived/input_output/data/p02790/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02790/Lisp/s234612655.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s234612655", "user_id": "u245103825"}, "prompt_components": {"gold_output": "3333\n", "input_to_evaluate": "(let* ((ls (read-from-string (concatenate 'string \"(\" (read-line) \")\")))\n (mx (apply #'max ls))\n (mn (apply #'min ls)))\n (princ (make-string mx :initial-element (char (prin1-to-string mn) 0))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller?\n\nConstraints\n\n1 \\leq a \\leq 9\n\n1 \\leq b \\leq 9\n\na and b are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nPrint the lexicographically smaller of the two strings. (If the two strings are equal, print one of them.)\n\nSample Input 1\n\n4 3\n\nSample Output 1\n\n3333\n\nWe have two strings 444 and 3333. Between them, 3333 is the lexicographically smaller.\n\nSample Input 2\n\n7 7\n\nSample Output 2\n\n7777777", "sample_input": "4 3\n"}, "reference_outputs": ["3333\n"], "source_document_id": "p02790", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller?\n\nConstraints\n\n1 \\leq a \\leq 9\n\n1 \\leq b \\leq 9\n\na and b are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nPrint the lexicographically smaller of the two strings. (If the two strings are equal, print one of them.)\n\nSample Input 1\n\n4 3\n\nSample Output 1\n\n3333\n\nWe have two strings 444 and 3333. Between them, 3333 is the lexicographically smaller.\n\nSample Input 2\n\n7 7\n\nSample Output 2\n\n7777777", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 207, "cpu_time_ms": 166, "memory_kb": 17640}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s195827568", "group_id": "codeNet:p02790", "input_text": "(let ((a (read))\n (b (read)))\n (loop repeat (max a b)\n do (format t \"~A\" (min a b))))\n", "language": "Lisp", "metadata": {"date": 1579463848, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02790.html", "problem_id": "p02790", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02790/input.txt", "sample_output_relpath": "derived/input_output/data/p02790/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02790/Lisp/s195827568.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s195827568", "user_id": "u425317134"}, "prompt_components": {"gold_output": "3333\n", "input_to_evaluate": "(let ((a (read))\n (b (read)))\n (loop repeat (max a b)\n do (format t \"~A\" (min a b))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller?\n\nConstraints\n\n1 \\leq a \\leq 9\n\n1 \\leq b \\leq 9\n\na and b are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nPrint the lexicographically smaller of the two strings. (If the two strings are equal, print one of them.)\n\nSample Input 1\n\n4 3\n\nSample Output 1\n\n3333\n\nWe have two strings 444 and 3333. Between them, 3333 is the lexicographically smaller.\n\nSample Input 2\n\n7 7\n\nSample Output 2\n\n7777777", "sample_input": "4 3\n"}, "reference_outputs": ["3333\n"], "source_document_id": "p02790", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller?\n\nConstraints\n\n1 \\leq a \\leq 9\n\n1 \\leq b \\leq 9\n\na and b are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nPrint the lexicographically smaller of the two strings. (If the two strings are equal, print one of them.)\n\nSample Input 1\n\n4 3\n\nSample Output 1\n\n3333\n\nWe have two strings 444 and 3333. Between them, 3333 is the lexicographically smaller.\n\nSample Input 2\n\n7 7\n\nSample Output 2\n\n7777777", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 105, "cpu_time_ms": 44, "memory_kb": 5728}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s884407860", "group_id": "codeNet:p02791", "input_text": "(defun low-elements (n p)\n (let ((ans 0) \n (min n)) \n (dotimes (i n) \n (when (<= (nth i p) min)\n (setf min (nth i p)) \n (incf ans)))\n ans)) \n\n\n(defun create-data ()\n (let ((n (read))\n (p))\n (dotimes (i n)\n (push (read) p))\n (values n p))) \n\n(multiple-value-bind (n p) (create-data) \n (format t \"~D~%\" (low-elements n p))) \n\n", "language": "Lisp", "metadata": {"date": 1580979068, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02791.html", "problem_id": "p02791", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02791/input.txt", "sample_output_relpath": "derived/input_output/data/p02791/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02791/Lisp/s884407860.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s884407860", "user_id": "u091381267"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun low-elements (n p)\n (let ((ans 0) \n (min n)) \n (dotimes (i n) \n (when (<= (nth i p) min)\n (setf min (nth i p)) \n (incf ans)))\n ans)) \n\n\n(defun create-data ()\n (let ((n (read))\n (p))\n (dotimes (i n)\n (push (read) p))\n (values n p))) \n\n(multiple-value-bind (n p) (create-data) \n (format t \"~D~%\" (low-elements n p))) \n\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven is a permutation P_1, \\ldots, P_N of 1, \\ldots, N.\nFind the number of integers i (1 \\leq i \\leq N) that satisfy the following condition:\n\nFor any integer j (1 \\leq j \\leq i), P_i \\leq P_j.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nP_1, \\ldots, P_N is a permutation of 1, \\ldots, N.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 ... P_N\n\nOutput\n\nPrint the number of integers i that satisfy the condition.\n\nSample Input 1\n\n5\n4 2 5 1 3\n\nSample Output 1\n\n3\n\ni=1, 2, and 4 satisfy the condition, but i=3 does not - for example, P_i > P_j holds for j = 1.\n\nSimilarly, i=5 does not satisfy the condition, either. Thus, there are three integers that satisfy the condition.\n\nSample Input 2\n\n4\n4 3 2 1\n\nSample Output 2\n\n4\n\nAll integers i (1 \\leq i \\leq N) satisfy the condition.\n\nSample Input 3\n\n6\n1 2 3 4 5 6\n\nSample Output 3\n\n1\n\nOnly i=1 satisfies the condition.\n\nSample Input 4\n\n8\n5 7 4 2 6 8 1 3\n\nSample Output 4\n\n4\n\nSample Input 5\n\n1\n1\n\nSample Output 5\n\n1", "sample_input": "5\n4 2 5 1 3\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02791", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven is a permutation P_1, \\ldots, P_N of 1, \\ldots, N.\nFind the number of integers i (1 \\leq i \\leq N) that satisfy the following condition:\n\nFor any integer j (1 \\leq j \\leq i), P_i \\leq P_j.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nP_1, \\ldots, P_N is a permutation of 1, \\ldots, N.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 ... P_N\n\nOutput\n\nPrint the number of integers i that satisfy the condition.\n\nSample Input 1\n\n5\n4 2 5 1 3\n\nSample Output 1\n\n3\n\ni=1, 2, and 4 satisfy the condition, but i=3 does not - for example, P_i > P_j holds for j = 1.\n\nSimilarly, i=5 does not satisfy the condition, either. Thus, there are three integers that satisfy the condition.\n\nSample Input 2\n\n4\n4 3 2 1\n\nSample Output 2\n\n4\n\nAll integers i (1 \\leq i \\leq N) satisfy the condition.\n\nSample Input 3\n\n6\n1 2 3 4 5 6\n\nSample Output 3\n\n1\n\nOnly i=1 satisfies the condition.\n\nSample Input 4\n\n8\n5 7 4 2 6 8 1 3\n\nSample Output 4\n\n4\n\nSample Input 5\n\n1\n1\n\nSample Output 5\n\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 377, "cpu_time_ms": 2104, "memory_kb": 59752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s374049000", "group_id": "codeNet:p02791", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n(defparameter N (read))\n(defparameter lst \n (make-array N \n :initial-contents \n (loop repeat N collect (read))))\n\n(defun drop (lst)\n (loop with c = 1\n with tmp = (aref lst 0)\n for i from 1 below N\n do (if (> (aref lst (1- i))\n (aref lst i))\n (progn\n (incf c)\n (setf tmp (aref lst i))))\n finally (return c)))\n\n(defun answer (n lst)\n (if (= n 1)\n 1\n (drop lst)))\n\n(format t \"~A\" (answer N lst))\n", "language": "Lisp", "metadata": {"date": 1579469213, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02791.html", "problem_id": "p02791", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02791/input.txt", "sample_output_relpath": "derived/input_output/data/p02791/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02791/Lisp/s374049000.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s374049000", "user_id": "u425317134"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n(defparameter N (read))\n(defparameter lst \n (make-array N \n :initial-contents \n (loop repeat N collect (read))))\n\n(defun drop (lst)\n (loop with c = 1\n with tmp = (aref lst 0)\n for i from 1 below N\n do (if (> (aref lst (1- i))\n (aref lst i))\n (progn\n (incf c)\n (setf tmp (aref lst i))))\n finally (return c)))\n\n(defun answer (n lst)\n (if (= n 1)\n 1\n (drop lst)))\n\n(format t \"~A\" (answer N lst))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven is a permutation P_1, \\ldots, P_N of 1, \\ldots, N.\nFind the number of integers i (1 \\leq i \\leq N) that satisfy the following condition:\n\nFor any integer j (1 \\leq j \\leq i), P_i \\leq P_j.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nP_1, \\ldots, P_N is a permutation of 1, \\ldots, N.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 ... P_N\n\nOutput\n\nPrint the number of integers i that satisfy the condition.\n\nSample Input 1\n\n5\n4 2 5 1 3\n\nSample Output 1\n\n3\n\ni=1, 2, and 4 satisfy the condition, but i=3 does not - for example, P_i > P_j holds for j = 1.\n\nSimilarly, i=5 does not satisfy the condition, either. Thus, there are three integers that satisfy the condition.\n\nSample Input 2\n\n4\n4 3 2 1\n\nSample Output 2\n\n4\n\nAll integers i (1 \\leq i \\leq N) satisfy the condition.\n\nSample Input 3\n\n6\n1 2 3 4 5 6\n\nSample Output 3\n\n1\n\nOnly i=1 satisfies the condition.\n\nSample Input 4\n\n8\n5 7 4 2 6 8 1 3\n\nSample Output 4\n\n4\n\nSample Input 5\n\n1\n1\n\nSample Output 5\n\n1", "sample_input": "5\n4 2 5 1 3\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02791", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven is a permutation P_1, \\ldots, P_N of 1, \\ldots, N.\nFind the number of integers i (1 \\leq i \\leq N) that satisfy the following condition:\n\nFor any integer j (1 \\leq j \\leq i), P_i \\leq P_j.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nP_1, \\ldots, P_N is a permutation of 1, \\ldots, N.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 ... P_N\n\nOutput\n\nPrint the number of integers i that satisfy the condition.\n\nSample Input 1\n\n5\n4 2 5 1 3\n\nSample Output 1\n\n3\n\ni=1, 2, and 4 satisfy the condition, but i=3 does not - for example, P_i > P_j holds for j = 1.\n\nSimilarly, i=5 does not satisfy the condition, either. Thus, there are three integers that satisfy the condition.\n\nSample Input 2\n\n4\n4 3 2 1\n\nSample Output 2\n\n4\n\nAll integers i (1 \\leq i \\leq N) satisfy the condition.\n\nSample Input 3\n\n6\n1 2 3 4 5 6\n\nSample Output 3\n\n1\n\nOnly i=1 satisfies the condition.\n\nSample Input 4\n\n8\n5 7 4 2 6 8 1 3\n\nSample Output 4\n\n4\n\nSample Input 5\n\n1\n1\n\nSample Output 5\n\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 970, "cpu_time_ms": 485, "memory_kb": 62524}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s715874964", "group_id": "codeNet:p02791", "input_text": "(defun get-input-array (n)\n (let ((rst (make-array n)))\n (dotimes (i n)\n (setf (aref rst i) (read)))\n rst))\n\n(defun main (n)\n (let ((rst 0)\n (temp 0)\n (input-array (get-input-array n)))\n (loop for x from 0 to (- n 1)\n for num = (aref input-array x)\n if (or (= temp 0) (>= temp num))\n do (loop for y from 0 to x\n if (< (aref input-array y) num) do (return)\n finally (incf rst))\n if (< temp num) do (setf temp num)\n )\n rst))\n\n\n(format t \"~A~%\" (main (read)))\n", "language": "Lisp", "metadata": {"date": 1579466694, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02791.html", "problem_id": "p02791", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02791/input.txt", "sample_output_relpath": "derived/input_output/data/p02791/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02791/Lisp/s715874964.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s715874964", "user_id": "u237057875"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun get-input-array (n)\n (let ((rst (make-array n)))\n (dotimes (i n)\n (setf (aref rst i) (read)))\n rst))\n\n(defun main (n)\n (let ((rst 0)\n (temp 0)\n (input-array (get-input-array n)))\n (loop for x from 0 to (- n 1)\n for num = (aref input-array x)\n if (or (= temp 0) (>= temp num))\n do (loop for y from 0 to x\n if (< (aref input-array y) num) do (return)\n finally (incf rst))\n if (< temp num) do (setf temp num)\n )\n rst))\n\n\n(format t \"~A~%\" (main (read)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven is a permutation P_1, \\ldots, P_N of 1, \\ldots, N.\nFind the number of integers i (1 \\leq i \\leq N) that satisfy the following condition:\n\nFor any integer j (1 \\leq j \\leq i), P_i \\leq P_j.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nP_1, \\ldots, P_N is a permutation of 1, \\ldots, N.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 ... P_N\n\nOutput\n\nPrint the number of integers i that satisfy the condition.\n\nSample Input 1\n\n5\n4 2 5 1 3\n\nSample Output 1\n\n3\n\ni=1, 2, and 4 satisfy the condition, but i=3 does not - for example, P_i > P_j holds for j = 1.\n\nSimilarly, i=5 does not satisfy the condition, either. Thus, there are three integers that satisfy the condition.\n\nSample Input 2\n\n4\n4 3 2 1\n\nSample Output 2\n\n4\n\nAll integers i (1 \\leq i \\leq N) satisfy the condition.\n\nSample Input 3\n\n6\n1 2 3 4 5 6\n\nSample Output 3\n\n1\n\nOnly i=1 satisfies the condition.\n\nSample Input 4\n\n8\n5 7 4 2 6 8 1 3\n\nSample Output 4\n\n4\n\nSample Input 5\n\n1\n1\n\nSample Output 5\n\n1", "sample_input": "5\n4 2 5 1 3\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02791", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven is a permutation P_1, \\ldots, P_N of 1, \\ldots, N.\nFind the number of integers i (1 \\leq i \\leq N) that satisfy the following condition:\n\nFor any integer j (1 \\leq j \\leq i), P_i \\leq P_j.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\nP_1, \\ldots, P_N is a permutation of 1, \\ldots, N.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 ... P_N\n\nOutput\n\nPrint the number of integers i that satisfy the condition.\n\nSample Input 1\n\n5\n4 2 5 1 3\n\nSample Output 1\n\n3\n\ni=1, 2, and 4 satisfy the condition, but i=3 does not - for example, P_i > P_j holds for j = 1.\n\nSimilarly, i=5 does not satisfy the condition, either. Thus, there are three integers that satisfy the condition.\n\nSample Input 2\n\n4\n4 3 2 1\n\nSample Output 2\n\n4\n\nAll integers i (1 \\leq i \\leq N) satisfy the condition.\n\nSample Input 3\n\n6\n1 2 3 4 5 6\n\nSample Output 3\n\n1\n\nOnly i=1 satisfies the condition.\n\nSample Input 4\n\n8\n5 7 4 2 6 8 1 3\n\nSample Output 4\n\n4\n\nSample Input 5\n\n1\n1\n\nSample Output 5\n\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 571, "cpu_time_ms": 2105, "memory_kb": 61732}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s723952502", "group_id": "codeNet:p02793", "input_text": ";; E - Flatten\n\n(defun main ()\n (let* ((n (read))\n (a (loop repeat n collect (read))))\n (princ (solve a))))\n\n(defparameter *modulus* (+ (expt 10 9) 7))\n\n(defun solve (a)\n (mod (* (apply #'lcm a) (loop for x in a sum (/ 1 x))) *modulus*))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1582323984, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02793.html", "problem_id": "p02793", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02793/input.txt", "sample_output_relpath": "derived/input_output/data/p02793/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02793/Lisp/s723952502.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s723952502", "user_id": "u227020436"}, "prompt_components": {"gold_output": "13\n", "input_to_evaluate": ";; E - Flatten\n\n(defun main ()\n (let* ((n (read))\n (a (loop repeat n collect (read))))\n (princ (solve a))))\n\n(defparameter *modulus* (+ (expt 10 9) 7))\n\n(defun solve (a)\n (mod (* (apply #'lcm a) (loop for x in a sum (/ 1 x))) *modulus*))\n\n(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nGiven are N positive integers A_1,...,A_N.\n\nConsider positive integers B_1, ..., B_N that satisfy the following condition.\n\nCondition: For any i, j such that 1 \\leq i < j \\leq N, A_i B_i = A_j B_j holds.\n\nFind the minimum possible value of B_1 + ... + B_N for such B_1,...,B_N.\n\nSince the answer can be enormous, print the sum modulo (10^9 +7).\n\nConstraints\n\n1 \\leq N \\leq 10^4\n\n1 \\leq A_i \\leq 10^6\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 ... A_N\n\nOutput\n\nPrint the minimum possible value of B_1 + ... + B_N for B_1,...,B_N that satisfy the condition, modulo (10^9 +7).\n\nSample Input 1\n\n3\n2 3 4\n\nSample Output 1\n\n13\n\nLet B_1=6, B_2=4, and B_3=3, and the condition will be satisfied.\n\nSample Input 2\n\n5\n12 12 12 12 12\n\nSample Output 2\n\n5\n\nWe can let all B_i be 1.\n\nSample Input 3\n\n3\n1000000 999999 999998\n\nSample Output 3\n\n996989508\n\nPrint the sum modulo (10^9+7).", "sample_input": "3\n2 3 4\n"}, "reference_outputs": ["13\n"], "source_document_id": "p02793", "source_text": "Score : 500 points\n\nProblem Statement\n\nGiven are N positive integers A_1,...,A_N.\n\nConsider positive integers B_1, ..., B_N that satisfy the following condition.\n\nCondition: For any i, j such that 1 \\leq i < j \\leq N, A_i B_i = A_j B_j holds.\n\nFind the minimum possible value of B_1 + ... + B_N for such B_1,...,B_N.\n\nSince the answer can be enormous, print the sum modulo (10^9 +7).\n\nConstraints\n\n1 \\leq N \\leq 10^4\n\n1 \\leq A_i \\leq 10^6\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 ... A_N\n\nOutput\n\nPrint the minimum possible value of B_1 + ... + B_N for B_1,...,B_N that satisfy the condition, modulo (10^9 +7).\n\nSample Input 1\n\n3\n2 3 4\n\nSample Output 1\n\n13\n\nLet B_1=6, B_2=4, and B_3=3, and the condition will be satisfied.\n\nSample Input 2\n\n5\n12 12 12 12 12\n\nSample Output 2\n\n5\n\nWe can let all B_i be 1.\n\nSample Input 3\n\n3\n1000000 999999 999998\n\nSample Output 3\n\n996989508\n\nPrint the sum modulo (10^9+7).", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 259, "cpu_time_ms": 1481, "memory_kb": 100832}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s060251577", "group_id": "codeNet:p02793", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\n\n;; TODO: non-global handling\n\n(defconstant +binom-size+ 1000001)\n(defconstant +binom-mod+ #.(+ (expt 10 9) 7))\n\n(declaim ((simple-array (unsigned-byte 31) (*)) *fact* *fact-inv* *inv*))\n(defparameter *fact* (make-array +binom-size+ :element-type '(unsigned-byte 31))\n \"table of factorials\")\n(defparameter *fact-inv* (make-array +binom-size+ :element-type '(unsigned-byte 31))\n \"table of inverses of factorials\")\n(defparameter *inv* (make-array +binom-size+ :element-type '(unsigned-byte 31))\n \"table of inverses of non-negative integers\")\n\n(defun initialize-binom ()\n (declare (optimize (speed 3) (safety 0)))\n (setf (aref *fact* 0) 1\n (aref *fact* 1) 1\n (aref *fact-inv* 0) 1\n (aref *fact-inv* 1) 1\n (aref *inv* 1) 1)\n (loop for i from 2 below +binom-size+\n do (setf (aref *fact* i) (mod (* i (aref *fact* (- i 1))) +binom-mod+)\n (aref *inv* i) (- +binom-mod+\n (mod (* (aref *inv* (rem +binom-mod+ i))\n (floor +binom-mod+ i))\n +binom-mod+))\n (aref *fact-inv* i) (mod (* (aref *inv* i)\n (aref *fact-inv* (- i 1)))\n +binom-mod+))))\n\n(initialize-binom)\n\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(declaim (ftype (function * (values simple-bit-vector &optional)) make-prime-table))\n(defun make-prime-table (sup)\n \"Returns a simple-bit-vector of length SUP, whose (0-based) i-th bit is 1 if i\nis prime and 0 otherwise.\n\nExample: (make-prime-table 10) => #*0011010100\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-array sup :element-type 'bit :initial-element 0))\n (sup/64 (ceiling sup 64)))\n ;; special treatment for p = 2\n (dotimes (i sup/64)\n (setf (sb-kernel:%vector-raw-bits table i) #xAAAAAAAAAAAAAAAA))\n (setf (sbit table 1) 0\n (sbit table 2) 1)\n ;; p >= 3\n (loop for p from 3 to (+ 1 (isqrt (- sup 1))) by 2\n when (= 1 (sbit table p))\n do (loop for composite from (* p p) below sup by p\n do (setf (sbit table composite) 0)))\n table))\n\n;; FIXME: Currently the element type of the resultant vector is (UNSIGNED-BYTE 62).\n(declaim (ftype (function * (values (simple-array (integer 0 #.most-positive-fixnum) (*))\n simple-bit-vector\n &optional))\n make-prime-sequence))\n(defun make-prime-sequence (sup)\n \"Returns the ascending sequence of primes smaller than SUP.\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-prime-table sup)))\n (let* ((length (count 1 table))\n (result (make-array length :element-type '(integer 0 #.most-positive-fixnum)))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) length))\n (loop for x below sup\n when (= 1 (sbit table x))\n do (setf (aref result index) x)\n (incf index))\n (values result table))))\n\n(defstruct (prime-data (:constructor %make-prime-data (seq table)))\n (seq nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n (table nil :type simple-bit-vector))\n\n(defun make-prime-data (sup)\n (multiple-value-call #'%make-prime-data (make-prime-sequence sup)))\n\n(declaim (inline factorize)\n (ftype (function * (values list &optional)) factorize))\n(defun factorize (x prime-data)\n \"Returns the associative list of prime factors of X, which is composed\nof ( . ). E.g. (factorize 100 ) => '((2 . 2) (5\n. 5)).\n\n- Any numbers beyond the range of PRIME-DATA are regarded as prime.\n- The returned list is in descending order w.r.t. prime factors.\"\n (declare (integer x))\n (setq x (abs x))\n (when (<= x 1)\n (return-from factorize nil))\n (let ((prime-seq (prime-data-seq prime-data))\n result)\n (loop for prime of-type unsigned-byte across prime-seq\n do (when (= x 1)\n (return-from factorize result))\n (loop for exponent of-type (integer 0 #.most-positive-fixnum) from 0\n do (multiple-value-bind (quot rem) (floor x prime)\n (if (zerop rem)\n (setf x quot)\n (progn\n (when (> exponent 0)\n (push (cons prime exponent) result))\n (loop-finish))))))\n (if (= x 1)\n result\n (cons (cons x 1) result))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (pdata (make-prime-data 10000))\n (as (make-array n :element-type 'uint31))\n (lcm-table (make-hash-table)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum))\n (dolist (node (factorize (aref as i) pdata))\n (let ((prime (car node))\n (exp (cdr node)))\n (if (gethash prime lcm-table)\n (maxf (gethash prime lcm-table) exp)\n (setf (gethash prime lcm-table) exp)))))\n (let ((lcm 1))\n (declare (uint31 lcm))\n (maphash (lambda (prime exp)\n (declare (uint31 prime exp))\n (dotimes (_ exp)\n (mulfmod lcm prime)))\n lcm-table)\n (let ((res 0))\n (declare (uint62 res))\n (loop for a across as\n do (incf res (mod* lcm (aref *inv* a))))\n (println (mod res +mod+))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n2 3 4\n\"\n \"13\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n12 12 12 12 12\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1000000 999999 999998\n\"\n \"996989508\n\")))\n", "language": "Lisp", "metadata": {"date": 1579473947, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02793.html", "problem_id": "p02793", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02793/input.txt", "sample_output_relpath": "derived/input_output/data/p02793/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02793/Lisp/s060251577.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s060251577", "user_id": "u352600849"}, "prompt_components": {"gold_output": "13\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\n\n;; TODO: non-global handling\n\n(defconstant +binom-size+ 1000001)\n(defconstant +binom-mod+ #.(+ (expt 10 9) 7))\n\n(declaim ((simple-array (unsigned-byte 31) (*)) *fact* *fact-inv* *inv*))\n(defparameter *fact* (make-array +binom-size+ :element-type '(unsigned-byte 31))\n \"table of factorials\")\n(defparameter *fact-inv* (make-array +binom-size+ :element-type '(unsigned-byte 31))\n \"table of inverses of factorials\")\n(defparameter *inv* (make-array +binom-size+ :element-type '(unsigned-byte 31))\n \"table of inverses of non-negative integers\")\n\n(defun initialize-binom ()\n (declare (optimize (speed 3) (safety 0)))\n (setf (aref *fact* 0) 1\n (aref *fact* 1) 1\n (aref *fact-inv* 0) 1\n (aref *fact-inv* 1) 1\n (aref *inv* 1) 1)\n (loop for i from 2 below +binom-size+\n do (setf (aref *fact* i) (mod (* i (aref *fact* (- i 1))) +binom-mod+)\n (aref *inv* i) (- +binom-mod+\n (mod (* (aref *inv* (rem +binom-mod+ i))\n (floor +binom-mod+ i))\n +binom-mod+))\n (aref *fact-inv* i) (mod (* (aref *inv* i)\n (aref *fact-inv* (- i 1)))\n +binom-mod+))))\n\n(initialize-binom)\n\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(declaim (ftype (function * (values simple-bit-vector &optional)) make-prime-table))\n(defun make-prime-table (sup)\n \"Returns a simple-bit-vector of length SUP, whose (0-based) i-th bit is 1 if i\nis prime and 0 otherwise.\n\nExample: (make-prime-table 10) => #*0011010100\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-array sup :element-type 'bit :initial-element 0))\n (sup/64 (ceiling sup 64)))\n ;; special treatment for p = 2\n (dotimes (i sup/64)\n (setf (sb-kernel:%vector-raw-bits table i) #xAAAAAAAAAAAAAAAA))\n (setf (sbit table 1) 0\n (sbit table 2) 1)\n ;; p >= 3\n (loop for p from 3 to (+ 1 (isqrt (- sup 1))) by 2\n when (= 1 (sbit table p))\n do (loop for composite from (* p p) below sup by p\n do (setf (sbit table composite) 0)))\n table))\n\n;; FIXME: Currently the element type of the resultant vector is (UNSIGNED-BYTE 62).\n(declaim (ftype (function * (values (simple-array (integer 0 #.most-positive-fixnum) (*))\n simple-bit-vector\n &optional))\n make-prime-sequence))\n(defun make-prime-sequence (sup)\n \"Returns the ascending sequence of primes smaller than SUP.\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-prime-table sup)))\n (let* ((length (count 1 table))\n (result (make-array length :element-type '(integer 0 #.most-positive-fixnum)))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) length))\n (loop for x below sup\n when (= 1 (sbit table x))\n do (setf (aref result index) x)\n (incf index))\n (values result table))))\n\n(defstruct (prime-data (:constructor %make-prime-data (seq table)))\n (seq nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n (table nil :type simple-bit-vector))\n\n(defun make-prime-data (sup)\n (multiple-value-call #'%make-prime-data (make-prime-sequence sup)))\n\n(declaim (inline factorize)\n (ftype (function * (values list &optional)) factorize))\n(defun factorize (x prime-data)\n \"Returns the associative list of prime factors of X, which is composed\nof ( . ). E.g. (factorize 100 ) => '((2 . 2) (5\n. 5)).\n\n- Any numbers beyond the range of PRIME-DATA are regarded as prime.\n- The returned list is in descending order w.r.t. prime factors.\"\n (declare (integer x))\n (setq x (abs x))\n (when (<= x 1)\n (return-from factorize nil))\n (let ((prime-seq (prime-data-seq prime-data))\n result)\n (loop for prime of-type unsigned-byte across prime-seq\n do (when (= x 1)\n (return-from factorize result))\n (loop for exponent of-type (integer 0 #.most-positive-fixnum) from 0\n do (multiple-value-bind (quot rem) (floor x prime)\n (if (zerop rem)\n (setf x quot)\n (progn\n (when (> exponent 0)\n (push (cons prime exponent) result))\n (loop-finish))))))\n (if (= x 1)\n result\n (cons (cons x 1) result))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (pdata (make-prime-data 10000))\n (as (make-array n :element-type 'uint31))\n (lcm-table (make-hash-table)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum))\n (dolist (node (factorize (aref as i) pdata))\n (let ((prime (car node))\n (exp (cdr node)))\n (if (gethash prime lcm-table)\n (maxf (gethash prime lcm-table) exp)\n (setf (gethash prime lcm-table) exp)))))\n (let ((lcm 1))\n (declare (uint31 lcm))\n (maphash (lambda (prime exp)\n (declare (uint31 prime exp))\n (dotimes (_ exp)\n (mulfmod lcm prime)))\n lcm-table)\n (let ((res 0))\n (declare (uint62 res))\n (loop for a across as\n do (incf res (mod* lcm (aref *inv* a))))\n (println (mod res +mod+))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n2 3 4\n\"\n \"13\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n12 12 12 12 12\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1000000 999999 999998\n\"\n \"996989508\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nGiven are N positive integers A_1,...,A_N.\n\nConsider positive integers B_1, ..., B_N that satisfy the following condition.\n\nCondition: For any i, j such that 1 \\leq i < j \\leq N, A_i B_i = A_j B_j holds.\n\nFind the minimum possible value of B_1 + ... + B_N for such B_1,...,B_N.\n\nSince the answer can be enormous, print the sum modulo (10^9 +7).\n\nConstraints\n\n1 \\leq N \\leq 10^4\n\n1 \\leq A_i \\leq 10^6\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 ... A_N\n\nOutput\n\nPrint the minimum possible value of B_1 + ... + B_N for B_1,...,B_N that satisfy the condition, modulo (10^9 +7).\n\nSample Input 1\n\n3\n2 3 4\n\nSample Output 1\n\n13\n\nLet B_1=6, B_2=4, and B_3=3, and the condition will be satisfied.\n\nSample Input 2\n\n5\n12 12 12 12 12\n\nSample Output 2\n\n5\n\nWe can let all B_i be 1.\n\nSample Input 3\n\n3\n1000000 999999 999998\n\nSample Output 3\n\n996989508\n\nPrint the sum modulo (10^9+7).", "sample_input": "3\n2 3 4\n"}, "reference_outputs": ["13\n"], "source_document_id": "p02793", "source_text": "Score : 500 points\n\nProblem Statement\n\nGiven are N positive integers A_1,...,A_N.\n\nConsider positive integers B_1, ..., B_N that satisfy the following condition.\n\nCondition: For any i, j such that 1 \\leq i < j \\leq N, A_i B_i = A_j B_j holds.\n\nFind the minimum possible value of B_1 + ... + B_N for such B_1,...,B_N.\n\nSince the answer can be enormous, print the sum modulo (10^9 +7).\n\nConstraints\n\n1 \\leq N \\leq 10^4\n\n1 \\leq A_i \\leq 10^6\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 ... A_N\n\nOutput\n\nPrint the minimum possible value of B_1 + ... + B_N for B_1,...,B_N that satisfy the condition, modulo (10^9 +7).\n\nSample Input 1\n\n3\n2 3 4\n\nSample Output 1\n\n13\n\nLet B_1=6, B_2=4, and B_3=3, and the condition will be satisfied.\n\nSample Input 2\n\n5\n12 12 12 12 12\n\nSample Output 2\n\n5\n\nWe can let all B_i be 1.\n\nSample Input 3\n\n3\n1000000 999999 999998\n\nSample Output 3\n\n996989508\n\nPrint the sum modulo (10^9+7).", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11813, "cpu_time_ms": 463, "memory_kb": 56676}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s741938748", "group_id": "codeNet:p02793", "input_text": "(defparameter N (read))\n(defparameter lst\n (loop repeat N collect (read)))\n(defparameter const (+ 7 (expt 10 9)))\n\n(defun calc (lst)\n (let ((l (apply #'lcm lst)))\n (mod (apply #'+\n (mapcar #'(lambda (x) (mod (/ l x) const))\n lst))\n const)))\n\n(format t \"~A\" (calc lst))", "language": "Lisp", "metadata": {"date": 1579467805, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02793.html", "problem_id": "p02793", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02793/input.txt", "sample_output_relpath": "derived/input_output/data/p02793/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02793/Lisp/s741938748.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s741938748", "user_id": "u425317134"}, "prompt_components": {"gold_output": "13\n", "input_to_evaluate": "(defparameter N (read))\n(defparameter lst\n (loop repeat N collect (read)))\n(defparameter const (+ 7 (expt 10 9)))\n\n(defun calc (lst)\n (let ((l (apply #'lcm lst)))\n (mod (apply #'+\n (mapcar #'(lambda (x) (mod (/ l x) const))\n lst))\n const)))\n\n(format t \"~A\" (calc lst))", "problem_context": "Score : 500 points\n\nProblem Statement\n\nGiven are N positive integers A_1,...,A_N.\n\nConsider positive integers B_1, ..., B_N that satisfy the following condition.\n\nCondition: For any i, j such that 1 \\leq i < j \\leq N, A_i B_i = A_j B_j holds.\n\nFind the minimum possible value of B_1 + ... + B_N for such B_1,...,B_N.\n\nSince the answer can be enormous, print the sum modulo (10^9 +7).\n\nConstraints\n\n1 \\leq N \\leq 10^4\n\n1 \\leq A_i \\leq 10^6\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 ... A_N\n\nOutput\n\nPrint the minimum possible value of B_1 + ... + B_N for B_1,...,B_N that satisfy the condition, modulo (10^9 +7).\n\nSample Input 1\n\n3\n2 3 4\n\nSample Output 1\n\n13\n\nLet B_1=6, B_2=4, and B_3=3, and the condition will be satisfied.\n\nSample Input 2\n\n5\n12 12 12 12 12\n\nSample Output 2\n\n5\n\nWe can let all B_i be 1.\n\nSample Input 3\n\n3\n1000000 999999 999998\n\nSample Output 3\n\n996989508\n\nPrint the sum modulo (10^9+7).", "sample_input": "3\n2 3 4\n"}, "reference_outputs": ["13\n"], "source_document_id": "p02793", "source_text": "Score : 500 points\n\nProblem Statement\n\nGiven are N positive integers A_1,...,A_N.\n\nConsider positive integers B_1, ..., B_N that satisfy the following condition.\n\nCondition: For any i, j such that 1 \\leq i < j \\leq N, A_i B_i = A_j B_j holds.\n\nFind the minimum possible value of B_1 + ... + B_N for such B_1,...,B_N.\n\nSince the answer can be enormous, print the sum modulo (10^9 +7).\n\nConstraints\n\n1 \\leq N \\leq 10^4\n\n1 \\leq A_i \\leq 10^6\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 ... A_N\n\nOutput\n\nPrint the minimum possible value of B_1 + ... + B_N for B_1,...,B_N that satisfy the condition, modulo (10^9 +7).\n\nSample Input 1\n\n3\n2 3 4\n\nSample Output 1\n\n13\n\nLet B_1=6, B_2=4, and B_3=3, and the condition will be satisfied.\n\nSample Input 2\n\n5\n12 12 12 12 12\n\nSample Output 2\n\n5\n\nWe can let all B_i be 1.\n\nSample Input 3\n\n3\n1000000 999999 999998\n\nSample Output 3\n\n996989508\n\nPrint the sum modulo (10^9+7).", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 331, "cpu_time_ms": 2105, "memory_kb": 94564}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s829522700", "group_id": "codeNet:p02794", "input_text": ";; F - Tree and Constraints\n\n(defun main ()\n (let* ((n (read))\n (ab (loop repeat (1- n) collect (cons (read) (read))))\n (m (read))\n (uv (loop repeat m collect (cons (read) (read)))))\n (princ (solve n ab m uv))))\n\n(defun make-adjacency-list (n edges)\n (let ((adj (make-array n :initial-element nil)))\n (loop for i from 0\n for edge in edges\n for a = (1- (car edge))\n for b = (1- (cdr edge))\n do (setf (aref adj a) (cons (cons b i) (aref adj a)))\n (setf (aref adj b) (cons (cons a i) (aref adj b))))\n adj))\n\n(defun find-paths (m uv n adj)\n (labels ((dfs (u v parent)\n (if (eql u v)\n (empty-set (1- n))\n (loop for (a . i) in (aref adj u)\n for p = (and (not (eql a parent))\n (dfs a v u))\n when p do (set-add p i)\n (return p)))))\n (loop for (u . v) in uv\n collect (dfs (1- u) (1- v) nil))))\n\n(defun coloring (n paths union sign)\n (if paths\n (+ (coloring n (cdr paths) union sign)\n (coloring n (cdr paths) (set-union union (car paths)) (- sign)))\n (* sign (ash 1 (- (1- n) (count-set-elem union))))))\n\n(defun solve (n ab m uv)\n (let* ((adj (make-adjacency-list n ab))\n (paths (find-paths m uv n adj)))\n (coloring n paths (empty-set (1- n)) 1)))\n\n;; set operations\n\n(defun empty-set (n-elem)\n (make-array n-elem :element-type 'bit :initial-element 0))\n\n(defun set-add (set elem)\n (setf (aref set elem) 1))\n\n(defun set-union (set1 set2)\n (loop with result = (make-array (array-dimension set1 0) :element-type 'bit)\n for b1 across set1\n for b2 across set2\n for i from 0\n do (setf (aref result i) (logior b1 b2))\n finally (return result)))\n\n(defun count-set-elem (set)\n (count 1 set))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1582448596, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02794.html", "problem_id": "p02794", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02794/input.txt", "sample_output_relpath": "derived/input_output/data/p02794/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02794/Lisp/s829522700.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s829522700", "user_id": "u227020436"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; F - Tree and Constraints\n\n(defun main ()\n (let* ((n (read))\n (ab (loop repeat (1- n) collect (cons (read) (read))))\n (m (read))\n (uv (loop repeat m collect (cons (read) (read)))))\n (princ (solve n ab m uv))))\n\n(defun make-adjacency-list (n edges)\n (let ((adj (make-array n :initial-element nil)))\n (loop for i from 0\n for edge in edges\n for a = (1- (car edge))\n for b = (1- (cdr edge))\n do (setf (aref adj a) (cons (cons b i) (aref adj a)))\n (setf (aref adj b) (cons (cons a i) (aref adj b))))\n adj))\n\n(defun find-paths (m uv n adj)\n (labels ((dfs (u v parent)\n (if (eql u v)\n (empty-set (1- n))\n (loop for (a . i) in (aref adj u)\n for p = (and (not (eql a parent))\n (dfs a v u))\n when p do (set-add p i)\n (return p)))))\n (loop for (u . v) in uv\n collect (dfs (1- u) (1- v) nil))))\n\n(defun coloring (n paths union sign)\n (if paths\n (+ (coloring n (cdr paths) union sign)\n (coloring n (cdr paths) (set-union union (car paths)) (- sign)))\n (* sign (ash 1 (- (1- n) (count-set-elem union))))))\n\n(defun solve (n ab m uv)\n (let* ((adj (make-adjacency-list n ab))\n (paths (find-paths m uv n adj)))\n (coloring n paths (empty-set (1- n)) 1)))\n\n;; set operations\n\n(defun empty-set (n-elem)\n (make-array n-elem :element-type 'bit :initial-element 0))\n\n(defun set-add (set elem)\n (setf (aref set elem) 1))\n\n(defun set-union (set1 set2)\n (loop with result = (make-array (array-dimension set1 0) :element-type 'bit)\n for b1 across set1\n for b2 across set2\n for i from 0\n do (setf (aref result i) (logior b1 b2))\n finally (return result)))\n\n(defun count-set-elem (set)\n (count 1 set))\n\n(main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nWe have a tree with N vertices numbered 1 to N.\nThe i-th edge in this tree connects Vertex a_i and Vertex b_i.\n\nConsider painting each of these edges white or black. There are 2^{N-1} such ways to paint the edges. Among them, how many satisfy all of the following M restrictions?\n\nThe i-th (1 \\leq i \\leq M) restriction is represented by two integers u_i and v_i, which mean that the path connecting Vertex u_i and Vertex v_i must contain at least one edge painted black.\n\nConstraints\n\n2 \\leq N \\leq 50\n\n1 \\leq a_i,b_i \\leq N\n\nThe graph given in input is a tree.\n\n1 \\leq M \\leq \\min(20,\\frac{N(N-1)}{2})\n\n1 \\leq u_i < v_i \\leq N\n\nIf i \\not= j, either u_i \\not=u_j or v_i\\not=v_j\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 b_1\n:\na_{N-1} b_{N-1}\nM\nu_1 v_1\n:\nu_M v_M\n\nOutput\n\nPrint the number of ways to paint the edges that satisfy all of the M conditions.\n\nSample Input 1\n\n3\n1 2\n2 3\n1\n1 3\n\nSample Output 1\n\n3\n\nThe tree in this input is shown below:\n\nAll of the M restrictions will be satisfied if Edge 1 and 2 are respectively painted (white, black), (black, white), or (black, black), so the answer is 3.\n\nSample Input 2\n\n2\n1 2\n1\n1 2\n\nSample Output 2\n\n1\n\nThe tree in this input is shown below:\n\nAll of the M restrictions will be satisfied only if Edge 1 is painted black, so the answer is 1.\n\nSample Input 3\n\n5\n1 2\n3 2\n3 4\n5 3\n3\n1 3\n2 4\n2 5\n\nSample Output 3\n\n9\n\nThe tree in this input is shown below:\n\nSample Input 4\n\n8\n1 2\n2 3\n4 3\n2 5\n6 3\n6 7\n8 6\n5\n2 7\n3 5\n1 6\n2 8\n7 8\n\nSample Output 4\n\n62\n\nThe tree in this input is shown below:", "sample_input": "3\n1 2\n2 3\n1\n1 3\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02794", "source_text": "Score : 600 points\n\nProblem Statement\n\nWe have a tree with N vertices numbered 1 to N.\nThe i-th edge in this tree connects Vertex a_i and Vertex b_i.\n\nConsider painting each of these edges white or black. There are 2^{N-1} such ways to paint the edges. Among them, how many satisfy all of the following M restrictions?\n\nThe i-th (1 \\leq i \\leq M) restriction is represented by two integers u_i and v_i, which mean that the path connecting Vertex u_i and Vertex v_i must contain at least one edge painted black.\n\nConstraints\n\n2 \\leq N \\leq 50\n\n1 \\leq a_i,b_i \\leq N\n\nThe graph given in input is a tree.\n\n1 \\leq M \\leq \\min(20,\\frac{N(N-1)}{2})\n\n1 \\leq u_i < v_i \\leq N\n\nIf i \\not= j, either u_i \\not=u_j or v_i\\not=v_j\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 b_1\n:\na_{N-1} b_{N-1}\nM\nu_1 v_1\n:\nu_M v_M\n\nOutput\n\nPrint the number of ways to paint the edges that satisfy all of the M conditions.\n\nSample Input 1\n\n3\n1 2\n2 3\n1\n1 3\n\nSample Output 1\n\n3\n\nThe tree in this input is shown below:\n\nAll of the M restrictions will be satisfied if Edge 1 and 2 are respectively painted (white, black), (black, white), or (black, black), so the answer is 3.\n\nSample Input 2\n\n2\n1 2\n1\n1 2\n\nSample Output 2\n\n1\n\nThe tree in this input is shown below:\n\nAll of the M restrictions will be satisfied only if Edge 1 is painted black, so the answer is 1.\n\nSample Input 3\n\n5\n1 2\n3 2\n3 4\n5 3\n3\n1 3\n2 4\n2 5\n\nSample Output 3\n\n9\n\nThe tree in this input is shown below:\n\nSample Input 4\n\n8\n1 2\n2 3\n4 3\n2 5\n6 3\n6 7\n8 6\n5\n2 7\n3 5\n1 6\n2 8\n7 8\n\nSample Output 4\n\n62\n\nThe tree in this input is shown below:", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1903, "cpu_time_ms": 1858, "memory_kb": 69476}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s494754321", "group_id": "codeNet:p02796", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defun convert (x r)\n (list (- x r) (+ x r)))\n\n(defparameter N (parse-integer (read-line)))\n(defparameter robots\n (make-array (list N 2)\n :initial-contents\n (sort (loop for i from 0 below N\n collect (apply #'convert\n (mapcar #'parse-integer\n (split \" \" (read-line)))))\n #'< :key #'car)))\n\n(defun hoge (lst)\n (loop with count = N\n for i from 1 below N\n do (if (> (aref lst (1- i) 1)\n (aref lst i 0))\n (progn (decf count)\n (incf i)))\n finally (return count)))\n\n(format t \"~A\" (hoge robots))\n", "language": "Lisp", "metadata": {"date": 1579383139, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02796.html", "problem_id": "p02796", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02796/input.txt", "sample_output_relpath": "derived/input_output/data/p02796/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02796/Lisp/s494754321.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s494754321", "user_id": "u425317134"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defun convert (x r)\n (list (- x r) (+ x r)))\n\n(defparameter N (parse-integer (read-line)))\n(defparameter robots\n (make-array (list N 2)\n :initial-contents\n (sort (loop for i from 0 below N\n collect (apply #'convert\n (mapcar #'parse-integer\n (split \" \" (read-line)))))\n #'< :key #'car)))\n\n(defun hoge (lst)\n (loop with count = N\n for i from 1 below N\n do (if (> (aref lst (1- i) 1)\n (aref lst i 0))\n (progn (decf count)\n (incf i)))\n finally (return count)))\n\n(format t \"~A\" (hoge robots))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nIn a factory, there are N robots placed on a number line.\nRobot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.\n\nWe want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect.\nHere, for each i (1 \\leq i \\leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.\n\nFind the maximum number of robots that we can keep.\n\nConstraints\n\n1 \\leq N \\leq 100,000\n\n0 \\leq X_i \\leq 10^9 (1 \\leq i \\leq N)\n\n1 \\leq L_i \\leq 10^9 (1 \\leq i \\leq N)\n\nIf i \\neq j, X_i \\neq X_j.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nX_1 L_1\nX_2 L_2\n\\vdots\nX_N L_N\n\nOutput\n\nPrint the maximum number of robots that we can keep.\n\nSample Input 1\n\n4\n2 4\n4 3\n9 3\n100 5\n\nSample Output 1\n\n3\n\nBy removing Robot 2, we can keep the other three robots.\n\nSample Input 2\n\n2\n8 20\n1 10\n\nSample Output 2\n\n1\n\nSample Input 3\n\n5\n10 1\n2 1\n4 1\n6 1\n8 1\n\nSample Output 3\n\n5", "sample_input": "4\n2 4\n4 3\n9 3\n100 5\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02796", "source_text": "Score : 200 points\n\nProblem Statement\n\nIn a factory, there are N robots placed on a number line.\nRobot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.\n\nWe want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect.\nHere, for each i (1 \\leq i \\leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.\n\nFind the maximum number of robots that we can keep.\n\nConstraints\n\n1 \\leq N \\leq 100,000\n\n0 \\leq X_i \\leq 10^9 (1 \\leq i \\leq N)\n\n1 \\leq L_i \\leq 10^9 (1 \\leq i \\leq N)\n\nIf i \\neq j, X_i \\neq X_j.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nX_1 L_1\nX_2 L_2\n\\vdots\nX_N L_N\n\nOutput\n\nPrint the maximum number of robots that we can keep.\n\nSample Input 1\n\n4\n2 4\n4 3\n9 3\n100 5\n\nSample Output 1\n\n3\n\nBy removing Robot 2, we can keep the other three robots.\n\nSample Input 2\n\n2\n8 20\n1 10\n\nSample Output 2\n\n1\n\nSample Input 3\n\n5\n10 1\n2 1\n4 1\n6 1\n8 1\n\nSample Output 3\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1347, "cpu_time_ms": 547, "memory_kb": 73912}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s379204871", "group_id": "codeNet:p02801", "input_text": "(let ((c (read-char)))\n (format t \"~A~%\" (code-char (1+ (char-code c)))))\n", "language": "Lisp", "metadata": {"date": 1593679550, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02801.html", "problem_id": "p02801", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02801/input.txt", "sample_output_relpath": "derived/input_output/data/p02801/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02801/Lisp/s379204871.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s379204871", "user_id": "u608227593"}, "prompt_components": {"gold_output": "b\n", "input_to_evaluate": "(let ((c (read-char)))\n (format t \"~A~%\" (code-char (1+ (char-code c)))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nGiven is a lowercase English letter C that is not z. Print the letter that follows C in alphabetical order.\n\nConstraints\n\nC is a lowercase English letter that is not z.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nC\n\nOutput\n\nPrint the letter that follows C in alphabetical order.\n\nSample Input 1\n\na\n\nSample Output 1\n\nb\n\na is followed by b.\n\nSample Input 2\n\ny\n\nSample Output 2\n\nz\n\ny is followed by z.", "sample_input": "a\n"}, "reference_outputs": ["b\n"], "source_document_id": "p02801", "source_text": "Score : 100 points\n\nProblem Statement\n\nGiven is a lowercase English letter C that is not z. Print the letter that follows C in alphabetical order.\n\nConstraints\n\nC is a lowercase English letter that is not z.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nC\n\nOutput\n\nPrint the letter that follows C in alphabetical order.\n\nSample Input 1\n\na\n\nSample Output 1\n\nb\n\na is followed by b.\n\nSample Input 2\n\ny\n\nSample Output 2\n\nz\n\ny is followed by z.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 75, "cpu_time_ms": 17, "memory_kb": 24052}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s949116492", "group_id": "codeNet:p02801", "input_text": "(defun next-alphabet ()\n (let ((n (read-char))\n (i))\n (setf i (char-code n))\n (format t \"~c~%\" (code-char (1+ i))))) \n\n(next-alphabet) \n", "language": "Lisp", "metadata": {"date": 1581020234, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02801.html", "problem_id": "p02801", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02801/input.txt", "sample_output_relpath": "derived/input_output/data/p02801/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02801/Lisp/s949116492.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s949116492", "user_id": "u091381267"}, "prompt_components": {"gold_output": "b\n", "input_to_evaluate": "(defun next-alphabet ()\n (let ((n (read-char))\n (i))\n (setf i (char-code n))\n (format t \"~c~%\" (code-char (1+ i))))) \n\n(next-alphabet) \n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nGiven is a lowercase English letter C that is not z. Print the letter that follows C in alphabetical order.\n\nConstraints\n\nC is a lowercase English letter that is not z.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nC\n\nOutput\n\nPrint the letter that follows C in alphabetical order.\n\nSample Input 1\n\na\n\nSample Output 1\n\nb\n\na is followed by b.\n\nSample Input 2\n\ny\n\nSample Output 2\n\nz\n\ny is followed by z.", "sample_input": "a\n"}, "reference_outputs": ["b\n"], "source_document_id": "p02801", "source_text": "Score : 100 points\n\nProblem Statement\n\nGiven is a lowercase English letter C that is not z. Print the letter that follows C in alphabetical order.\n\nConstraints\n\nC is a lowercase English letter that is not z.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nC\n\nOutput\n\nPrint the letter that follows C in alphabetical order.\n\nSample Input 1\n\na\n\nSample Output 1\n\nb\n\na is followed by b.\n\nSample Input 2\n\ny\n\nSample Output 2\n\nz\n\ny is followed by z.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 150, "cpu_time_ms": 98, "memory_kb": 11748}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s533837723", "group_id": "codeNet:p02802", "input_text": "(let* ((n (read))\n (m (read))\n (a (make-array (list n 2) :initial-element 0))\n (ac 0)\n (wa 0))\n\n (loop for i below m do\n (let ((p (- (read) 1))\n (s (read)))\n (if (string= s \"WA\")\n (if (= (aref a p 1) 0)\n (incf (aref a p 0)))\n (incf (aref a p 1)))))\n\n (loop for i below n do\n (if (>= (aref a i 1) 1)\n (progn\n (incf ac)\n (if (>= (aref a i 0) 1)\n (incf wa (aref a i 0))))))\n (format t \"~D ~D~%\" ac wa)\n)", "language": "Lisp", "metadata": {"date": 1599057362, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02802.html", "problem_id": "p02802", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02802/input.txt", "sample_output_relpath": "derived/input_output/data/p02802/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02802/Lisp/s533837723.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s533837723", "user_id": "u136500538"}, "prompt_components": {"gold_output": "2 2\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (a (make-array (list n 2) :initial-element 0))\n (ac 0)\n (wa 0))\n\n (loop for i below m do\n (let ((p (- (read) 1))\n (s (read)))\n (if (string= s \"WA\")\n (if (= (aref a p 1) 0)\n (incf (aref a p 0)))\n (incf (aref a p 1)))))\n\n (loop for i below n do\n (if (>= (aref a i 1) 1)\n (progn\n (incf ac)\n (if (>= (aref a i 0) 1)\n (incf wa (aref a i 0))))))\n (format t \"~D ~D~%\" ac wa)\n)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi participated in a contest on AtCoder.\n\nThe contest had N problems.\n\nTakahashi made M submissions during the contest.\n\nThe i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).\n\nThe number of Takahashi's correct answers is the number of problems on which he received an AC once or more.\n\nThe number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.\n\nFind the numbers of Takahashi's correct answers and penalties.\n\nConstraints\n\nN, M, and p_i are integers.\n\n1 \\leq N \\leq 10^5\n\n0 \\leq M \\leq 10^5\n\n1 \\leq p_i \\leq N\n\nS_i is AC or WA.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\np_1 S_1\n:\np_M S_M\n\nOutput\n\nPrint the number of Takahashi's correct answers and the number of Takahashi's penalties.\n\nSample Input 1\n\n2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n\nSample Output 1\n\n2 2\n\nIn his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.\n\nIn his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.\n\nThus, he has two correct answers and two penalties.\n\nSample Input 2\n\n100000 3\n7777 AC\n7777 AC\n7777 AC\n\nSample Output 2\n\n1 0\n\nNote that it is pointless to get an AC more than once on the same problem.\n\nSample Input 3\n\n6 0\n\nSample Output 3\n\n0 0", "sample_input": "2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n"}, "reference_outputs": ["2 2\n"], "source_document_id": "p02802", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi participated in a contest on AtCoder.\n\nThe contest had N problems.\n\nTakahashi made M submissions during the contest.\n\nThe i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).\n\nThe number of Takahashi's correct answers is the number of problems on which he received an AC once or more.\n\nThe number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.\n\nFind the numbers of Takahashi's correct answers and penalties.\n\nConstraints\n\nN, M, and p_i are integers.\n\n1 \\leq N \\leq 10^5\n\n0 \\leq M \\leq 10^5\n\n1 \\leq p_i \\leq N\n\nS_i is AC or WA.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\np_1 S_1\n:\np_M S_M\n\nOutput\n\nPrint the number of Takahashi's correct answers and the number of Takahashi's penalties.\n\nSample Input 1\n\n2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n\nSample Output 1\n\n2 2\n\nIn his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.\n\nIn his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.\n\nThus, he has two correct answers and two penalties.\n\nSample Input 2\n\n100000 3\n7777 AC\n7777 AC\n7777 AC\n\nSample Output 2\n\n1 0\n\nNote that it is pointless to get an AC more than once on the same problem.\n\nSample Input 3\n\n6 0\n\nSample Output 3\n\n0 0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 566, "cpu_time_ms": 180, "memory_kb": 78540}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s434823854", "group_id": "codeNet:p02802", "input_text": "(defun create-data ()\n (let* ((n (read)) \n (m (read)) \n (p (make-array (1+ n) :initial-element 0))\n (s (make-array (1+ n) :initial-element 0))\n (buff1) \n (buff2)) \n (dotimes (i m) \n (setf buff1 (read))\n (setf buff2 (read))\n (if (and (string-equal buff2 \"AC\")(= 0 (aref p buff1)))\n (incf (aref p buff1))\n (if (and (string-equal buff2 \"WA\") (= 0 (aref p buff1)))\n (incf (aref s buff1)))))\n (dotimes (i n) \n (if (and (= 0 (aref p i)) (/= 0 (aref s i)))\n (setf (aref s i) 0)))\n (values n p s))) \n\n\n(defun welcome-to-atcoder (n p s)\n (let ((ans1 0) \n (ans2 0)) \n (dotimes (i (1+ n))\n (setf ans1 (+ ans1 (aref p i)))\n (setf ans2 (+ ans2 (aref s i))))\n (values ans1 ans2)))\n\n(multiple-value-bind (ans1 ans2)(multiple-value-bind (n p s) (create-data)\n (welcome-to-atcoder n p s))\n (format t \"~D ~D~%\" ans1 ans2))\n\n", "language": "Lisp", "metadata": {"date": 1581198203, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02802.html", "problem_id": "p02802", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02802/input.txt", "sample_output_relpath": "derived/input_output/data/p02802/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02802/Lisp/s434823854.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s434823854", "user_id": "u091381267"}, "prompt_components": {"gold_output": "2 2\n", "input_to_evaluate": "(defun create-data ()\n (let* ((n (read)) \n (m (read)) \n (p (make-array (1+ n) :initial-element 0))\n (s (make-array (1+ n) :initial-element 0))\n (buff1) \n (buff2)) \n (dotimes (i m) \n (setf buff1 (read))\n (setf buff2 (read))\n (if (and (string-equal buff2 \"AC\")(= 0 (aref p buff1)))\n (incf (aref p buff1))\n (if (and (string-equal buff2 \"WA\") (= 0 (aref p buff1)))\n (incf (aref s buff1)))))\n (dotimes (i n) \n (if (and (= 0 (aref p i)) (/= 0 (aref s i)))\n (setf (aref s i) 0)))\n (values n p s))) \n\n\n(defun welcome-to-atcoder (n p s)\n (let ((ans1 0) \n (ans2 0)) \n (dotimes (i (1+ n))\n (setf ans1 (+ ans1 (aref p i)))\n (setf ans2 (+ ans2 (aref s i))))\n (values ans1 ans2)))\n\n(multiple-value-bind (ans1 ans2)(multiple-value-bind (n p s) (create-data)\n (welcome-to-atcoder n p s))\n (format t \"~D ~D~%\" ans1 ans2))\n\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi participated in a contest on AtCoder.\n\nThe contest had N problems.\n\nTakahashi made M submissions during the contest.\n\nThe i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).\n\nThe number of Takahashi's correct answers is the number of problems on which he received an AC once or more.\n\nThe number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.\n\nFind the numbers of Takahashi's correct answers and penalties.\n\nConstraints\n\nN, M, and p_i are integers.\n\n1 \\leq N \\leq 10^5\n\n0 \\leq M \\leq 10^5\n\n1 \\leq p_i \\leq N\n\nS_i is AC or WA.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\np_1 S_1\n:\np_M S_M\n\nOutput\n\nPrint the number of Takahashi's correct answers and the number of Takahashi's penalties.\n\nSample Input 1\n\n2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n\nSample Output 1\n\n2 2\n\nIn his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.\n\nIn his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.\n\nThus, he has two correct answers and two penalties.\n\nSample Input 2\n\n100000 3\n7777 AC\n7777 AC\n7777 AC\n\nSample Output 2\n\n1 0\n\nNote that it is pointless to get an AC more than once on the same problem.\n\nSample Input 3\n\n6 0\n\nSample Output 3\n\n0 0", "sample_input": "2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n"}, "reference_outputs": ["2 2\n"], "source_document_id": "p02802", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi participated in a contest on AtCoder.\n\nThe contest had N problems.\n\nTakahashi made M submissions during the contest.\n\nThe i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).\n\nThe number of Takahashi's correct answers is the number of problems on which he received an AC once or more.\n\nThe number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.\n\nFind the numbers of Takahashi's correct answers and penalties.\n\nConstraints\n\nN, M, and p_i are integers.\n\n1 \\leq N \\leq 10^5\n\n0 \\leq M \\leq 10^5\n\n1 \\leq p_i \\leq N\n\nS_i is AC or WA.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\np_1 S_1\n:\np_M S_M\n\nOutput\n\nPrint the number of Takahashi's correct answers and the number of Takahashi's penalties.\n\nSample Input 1\n\n2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n\nSample Output 1\n\n2 2\n\nIn his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.\n\nIn his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.\n\nThus, he has two correct answers and two penalties.\n\nSample Input 2\n\n100000 3\n7777 AC\n7777 AC\n7777 AC\n\nSample Output 2\n\n1 0\n\nNote that it is pointless to get an AC more than once on the same problem.\n\nSample Input 3\n\n6 0\n\nSample Output 3\n\n0 0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 942, "cpu_time_ms": 370, "memory_kb": 59748}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s954516031", "group_id": "codeNet:p02802", "input_text": "(defun create-data ()\n (let* ((n (read))\n (m (read))\n (p (make-array (1+ n) :initial-element 0))\n (s (make-array (1+ n) :initial-element 0))\n (buff1)\n (buff2))\n (dotimes (i m)\n (setf buff1 (read))\n (setf buff2 (read))\n (if (and (string-equal buff2 \"AC\")(= 0 (aref p buff1)))\n (incf (aref p buff1))\n (if (and (string-equal buff2 \"WA\") (= 0 (aref p buff1)))\n (incf (aref s buff1)))))\n (dotimes (i m)\n (if (and (= 0 (aref p i)) (/= 0 (aref s i)))\n (setf (aref s i) 0))) \n (values n p s)))\n\n\n(defun welcome-to-atcoder (n p s)\n (let ((ans1 0)\n (ans2 0))\n (dotimes (i (1+ n))\n (setf ans1 (+ ans1 (aref p i)))\n (setf ans2 (+ ans2 (aref s i))))\n (values ans1 ans2)))\n\n(multiple-value-bind (ans1 ans2)(multiple-value-bind (n p s) (create-data)\n (welcome-to-atcoder n p s))\n (format t \"~D ~D~%\" ans1 ans2))\n", "language": "Lisp", "metadata": {"date": 1581196986, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02802.html", "problem_id": "p02802", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02802/input.txt", "sample_output_relpath": "derived/input_output/data/p02802/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02802/Lisp/s954516031.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s954516031", "user_id": "u091381267"}, "prompt_components": {"gold_output": "2 2\n", "input_to_evaluate": "(defun create-data ()\n (let* ((n (read))\n (m (read))\n (p (make-array (1+ n) :initial-element 0))\n (s (make-array (1+ n) :initial-element 0))\n (buff1)\n (buff2))\n (dotimes (i m)\n (setf buff1 (read))\n (setf buff2 (read))\n (if (and (string-equal buff2 \"AC\")(= 0 (aref p buff1)))\n (incf (aref p buff1))\n (if (and (string-equal buff2 \"WA\") (= 0 (aref p buff1)))\n (incf (aref s buff1)))))\n (dotimes (i m)\n (if (and (= 0 (aref p i)) (/= 0 (aref s i)))\n (setf (aref s i) 0))) \n (values n p s)))\n\n\n(defun welcome-to-atcoder (n p s)\n (let ((ans1 0)\n (ans2 0))\n (dotimes (i (1+ n))\n (setf ans1 (+ ans1 (aref p i)))\n (setf ans2 (+ ans2 (aref s i))))\n (values ans1 ans2)))\n\n(multiple-value-bind (ans1 ans2)(multiple-value-bind (n p s) (create-data)\n (welcome-to-atcoder n p s))\n (format t \"~D ~D~%\" ans1 ans2))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi participated in a contest on AtCoder.\n\nThe contest had N problems.\n\nTakahashi made M submissions during the contest.\n\nThe i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).\n\nThe number of Takahashi's correct answers is the number of problems on which he received an AC once or more.\n\nThe number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.\n\nFind the numbers of Takahashi's correct answers and penalties.\n\nConstraints\n\nN, M, and p_i are integers.\n\n1 \\leq N \\leq 10^5\n\n0 \\leq M \\leq 10^5\n\n1 \\leq p_i \\leq N\n\nS_i is AC or WA.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\np_1 S_1\n:\np_M S_M\n\nOutput\n\nPrint the number of Takahashi's correct answers and the number of Takahashi's penalties.\n\nSample Input 1\n\n2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n\nSample Output 1\n\n2 2\n\nIn his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.\n\nIn his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.\n\nThus, he has two correct answers and two penalties.\n\nSample Input 2\n\n100000 3\n7777 AC\n7777 AC\n7777 AC\n\nSample Output 2\n\n1 0\n\nNote that it is pointless to get an AC more than once on the same problem.\n\nSample Input 3\n\n6 0\n\nSample Output 3\n\n0 0", "sample_input": "2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n"}, "reference_outputs": ["2 2\n"], "source_document_id": "p02802", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi participated in a contest on AtCoder.\n\nThe contest had N problems.\n\nTakahashi made M submissions during the contest.\n\nThe i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).\n\nThe number of Takahashi's correct answers is the number of problems on which he received an AC once or more.\n\nThe number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.\n\nFind the numbers of Takahashi's correct answers and penalties.\n\nConstraints\n\nN, M, and p_i are integers.\n\n1 \\leq N \\leq 10^5\n\n0 \\leq M \\leq 10^5\n\n1 \\leq p_i \\leq N\n\nS_i is AC or WA.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\np_1 S_1\n:\np_M S_M\n\nOutput\n\nPrint the number of Takahashi's correct answers and the number of Takahashi's penalties.\n\nSample Input 1\n\n2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n\nSample Output 1\n\n2 2\n\nIn his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.\n\nIn his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.\n\nThus, he has two correct answers and two penalties.\n\nSample Input 2\n\n100000 3\n7777 AC\n7777 AC\n7777 AC\n\nSample Output 2\n\n1 0\n\nNote that it is pointless to get an AC more than once on the same problem.\n\nSample Input 3\n\n6 0\n\nSample Output 3\n\n0 0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 933, "cpu_time_ms": 379, "memory_kb": 59880}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s321176595", "group_id": "codeNet:p02802", "input_text": "(defun create-data ()\n (let* ((n (read))\n (m (read))\n (p (make-array (1+ n) :initial-element 0))\n (s (make-array (1+ n) :initial-element 0))\n (buff1)\n (buff2)) \n (dotimes (i m)\n (setf buff1 (read))\n (setf buff2 (read))\n (if (and (string-equal buff2 \"AC\")(= 0 (aref p buff1)))\n (incf (aref p buff1))\n (if (and (string-equal buff2 \"WA\") (= 0 (aref p buff1)))\n (incf (aref s buff1)))))\n (values n p s)))\n\n\n(defun welcome-to-atcoder (n p s)\n (let ((ans1 0)\n (ans2 0))\n (dotimes (i (1+ n))\n (setf ans1 (+ ans1 (aref p i)))\n (setf ans2 (+ ans2 (aref s i))))\n (values ans1 ans2)))\n\n(multiple-value-bind (ans1 ans2)(multiple-value-bind (n p s) (create-data)\n (welcome-to-atcoder n p s))\n (format t \"~D ~D~%\" ans1 ans2)) \n\n", "language": "Lisp", "metadata": {"date": 1581195359, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02802.html", "problem_id": "p02802", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02802/input.txt", "sample_output_relpath": "derived/input_output/data/p02802/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02802/Lisp/s321176595.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s321176595", "user_id": "u091381267"}, "prompt_components": {"gold_output": "2 2\n", "input_to_evaluate": "(defun create-data ()\n (let* ((n (read))\n (m (read))\n (p (make-array (1+ n) :initial-element 0))\n (s (make-array (1+ n) :initial-element 0))\n (buff1)\n (buff2)) \n (dotimes (i m)\n (setf buff1 (read))\n (setf buff2 (read))\n (if (and (string-equal buff2 \"AC\")(= 0 (aref p buff1)))\n (incf (aref p buff1))\n (if (and (string-equal buff2 \"WA\") (= 0 (aref p buff1)))\n (incf (aref s buff1)))))\n (values n p s)))\n\n\n(defun welcome-to-atcoder (n p s)\n (let ((ans1 0)\n (ans2 0))\n (dotimes (i (1+ n))\n (setf ans1 (+ ans1 (aref p i)))\n (setf ans2 (+ ans2 (aref s i))))\n (values ans1 ans2)))\n\n(multiple-value-bind (ans1 ans2)(multiple-value-bind (n p s) (create-data)\n (welcome-to-atcoder n p s))\n (format t \"~D ~D~%\" ans1 ans2)) \n\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi participated in a contest on AtCoder.\n\nThe contest had N problems.\n\nTakahashi made M submissions during the contest.\n\nThe i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).\n\nThe number of Takahashi's correct answers is the number of problems on which he received an AC once or more.\n\nThe number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.\n\nFind the numbers of Takahashi's correct answers and penalties.\n\nConstraints\n\nN, M, and p_i are integers.\n\n1 \\leq N \\leq 10^5\n\n0 \\leq M \\leq 10^5\n\n1 \\leq p_i \\leq N\n\nS_i is AC or WA.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\np_1 S_1\n:\np_M S_M\n\nOutput\n\nPrint the number of Takahashi's correct answers and the number of Takahashi's penalties.\n\nSample Input 1\n\n2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n\nSample Output 1\n\n2 2\n\nIn his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.\n\nIn his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.\n\nThus, he has two correct answers and two penalties.\n\nSample Input 2\n\n100000 3\n7777 AC\n7777 AC\n7777 AC\n\nSample Output 2\n\n1 0\n\nNote that it is pointless to get an AC more than once on the same problem.\n\nSample Input 3\n\n6 0\n\nSample Output 3\n\n0 0", "sample_input": "2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n"}, "reference_outputs": ["2 2\n"], "source_document_id": "p02802", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi participated in a contest on AtCoder.\n\nThe contest had N problems.\n\nTakahashi made M submissions during the contest.\n\nThe i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).\n\nThe number of Takahashi's correct answers is the number of problems on which he received an AC once or more.\n\nThe number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.\n\nFind the numbers of Takahashi's correct answers and penalties.\n\nConstraints\n\nN, M, and p_i are integers.\n\n1 \\leq N \\leq 10^5\n\n0 \\leq M \\leq 10^5\n\n1 \\leq p_i \\leq N\n\nS_i is AC or WA.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\np_1 S_1\n:\np_M S_M\n\nOutput\n\nPrint the number of Takahashi's correct answers and the number of Takahashi's penalties.\n\nSample Input 1\n\n2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n\nSample Output 1\n\n2 2\n\nIn his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.\n\nIn his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.\n\nThus, he has two correct answers and two penalties.\n\nSample Input 2\n\n100000 3\n7777 AC\n7777 AC\n7777 AC\n\nSample Output 2\n\n1 0\n\nNote that it is pointless to get an AC more than once on the same problem.\n\nSample Input 3\n\n6 0\n\nSample Output 3\n\n0 0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 833, "cpu_time_ms": 362, "memory_kb": 59752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s986339544", "group_id": "codeNet:p02802", "input_text": ";; C - Welcome to AtCoder\n\n(defun main ()\n (let* ((n (read)) ; 問題数\n (m (read)) ; 提出数\n (p-s (loop repeat m collect\n (cons (read-fixnum) (read))))) ; 問題番号と結果\n (format t \"~{~a~^ ~}~%\" (solve n m p-s))))\n\n(defun solve (n m p-s-lst)\n \"正答数とペナルティ数のリストを返す\"\n (let ((wa-count (make-array n :initial-element 0)) ; 各問の誤答数\n (ac-p (make-array n :initial-element nil))) ; 正答したか\n (loop for p-s in p-s-lst\n for p = (1- (car p-s))\n for s = (cdr p-s)\n when (and (eq s 'WA) (not (aref ac-p p)))\n do (incf (aref wa-count p)) end\n when (eq s 'AC)\n do (setf (aref ac-p p) t) end)\n (list (loop for a across ac-p count a)\n (loop for w across wa-count sum w))))\n\n(defun read-fixnum (&optional (in *standard-input*))\n \"readより速い非負整数専用read (整数間に空白または改行1個に限る)\n cf. https://qiita.com/sansaqua/items/0b6417cb541047e29da4\"\n (loop with acc = 0\n for byte = (read-byte in)\n if (<= 48 byte 57)\n do (setf acc (+ (* acc 10) (- byte 48)))\n else return acc))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1580573856, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02802.html", "problem_id": "p02802", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02802/input.txt", "sample_output_relpath": "derived/input_output/data/p02802/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02802/Lisp/s986339544.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s986339544", "user_id": "u227020436"}, "prompt_components": {"gold_output": "2 2\n", "input_to_evaluate": ";; C - Welcome to AtCoder\n\n(defun main ()\n (let* ((n (read)) ; 問題数\n (m (read)) ; 提出数\n (p-s (loop repeat m collect\n (cons (read-fixnum) (read))))) ; 問題番号と結果\n (format t \"~{~a~^ ~}~%\" (solve n m p-s))))\n\n(defun solve (n m p-s-lst)\n \"正答数とペナルティ数のリストを返す\"\n (let ((wa-count (make-array n :initial-element 0)) ; 各問の誤答数\n (ac-p (make-array n :initial-element nil))) ; 正答したか\n (loop for p-s in p-s-lst\n for p = (1- (car p-s))\n for s = (cdr p-s)\n when (and (eq s 'WA) (not (aref ac-p p)))\n do (incf (aref wa-count p)) end\n when (eq s 'AC)\n do (setf (aref ac-p p) t) end)\n (list (loop for a across ac-p count a)\n (loop for w across wa-count sum w))))\n\n(defun read-fixnum (&optional (in *standard-input*))\n \"readより速い非負整数専用read (整数間に空白または改行1個に限る)\n cf. https://qiita.com/sansaqua/items/0b6417cb541047e29da4\"\n (loop with acc = 0\n for byte = (read-byte in)\n if (<= 48 byte 57)\n do (setf acc (+ (* acc 10) (- byte 48)))\n else return acc))\n\n(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi participated in a contest on AtCoder.\n\nThe contest had N problems.\n\nTakahashi made M submissions during the contest.\n\nThe i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).\n\nThe number of Takahashi's correct answers is the number of problems on which he received an AC once or more.\n\nThe number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.\n\nFind the numbers of Takahashi's correct answers and penalties.\n\nConstraints\n\nN, M, and p_i are integers.\n\n1 \\leq N \\leq 10^5\n\n0 \\leq M \\leq 10^5\n\n1 \\leq p_i \\leq N\n\nS_i is AC or WA.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\np_1 S_1\n:\np_M S_M\n\nOutput\n\nPrint the number of Takahashi's correct answers and the number of Takahashi's penalties.\n\nSample Input 1\n\n2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n\nSample Output 1\n\n2 2\n\nIn his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.\n\nIn his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.\n\nThus, he has two correct answers and two penalties.\n\nSample Input 2\n\n100000 3\n7777 AC\n7777 AC\n7777 AC\n\nSample Output 2\n\n1 0\n\nNote that it is pointless to get an AC more than once on the same problem.\n\nSample Input 3\n\n6 0\n\nSample Output 3\n\n0 0", "sample_input": "2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n"}, "reference_outputs": ["2 2\n"], "source_document_id": "p02802", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi participated in a contest on AtCoder.\n\nThe contest had N problems.\n\nTakahashi made M submissions during the contest.\n\nThe i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).\n\nThe number of Takahashi's correct answers is the number of problems on which he received an AC once or more.\n\nThe number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.\n\nFind the numbers of Takahashi's correct answers and penalties.\n\nConstraints\n\nN, M, and p_i are integers.\n\n1 \\leq N \\leq 10^5\n\n0 \\leq M \\leq 10^5\n\n1 \\leq p_i \\leq N\n\nS_i is AC or WA.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\np_1 S_1\n:\np_M S_M\n\nOutput\n\nPrint the number of Takahashi's correct answers and the number of Takahashi's penalties.\n\nSample Input 1\n\n2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n\nSample Output 1\n\n2 2\n\nIn his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.\n\nIn his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.\n\nThus, he has two correct answers and two penalties.\n\nSample Input 2\n\n100000 3\n7777 AC\n7777 AC\n7777 AC\n\nSample Output 2\n\n1 0\n\nNote that it is pointless to get an AC more than once on the same problem.\n\nSample Input 3\n\n6 0\n\nSample Output 3\n\n0 0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1217, "cpu_time_ms": 217, "memory_kb": 61928}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s182700396", "group_id": "codeNet:p02802", "input_text": "(defvar N (read))\n(defvar M (read))\n(defvar ac 0)\n(defvar wa 0)\n(defvar exist-ac-count (list nil))\n(defvar exist-wa-count (list nil))\n\n(defun calc ()\n (let ((No (read))\n (Ans (read)))\n (cond ((string= Ans \"AC\")\n (unless (find No exist-ac-count)\n (when (find No exist-wa-count)\n (incf wa))\n (incf ac)\n (push No exist-ac-count)))\n ((string= Ans \"WA\")\n (unless (find No exist-wa-count)\n (push No exist-wa-count))\n (when (find No exist-ac-count)\n (incf wa))))\n (decf M)\n (if (= M 0)\n (format t \"~D ~D~%\" ac wa)\n (calc))))\n\n(if (= M 0)\n (format t \"0 0~%\")\n (calc))\n", "language": "Lisp", "metadata": {"date": 1578942550, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02802.html", "problem_id": "p02802", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02802/input.txt", "sample_output_relpath": "derived/input_output/data/p02802/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02802/Lisp/s182700396.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s182700396", "user_id": "u631655863"}, "prompt_components": {"gold_output": "2 2\n", "input_to_evaluate": "(defvar N (read))\n(defvar M (read))\n(defvar ac 0)\n(defvar wa 0)\n(defvar exist-ac-count (list nil))\n(defvar exist-wa-count (list nil))\n\n(defun calc ()\n (let ((No (read))\n (Ans (read)))\n (cond ((string= Ans \"AC\")\n (unless (find No exist-ac-count)\n (when (find No exist-wa-count)\n (incf wa))\n (incf ac)\n (push No exist-ac-count)))\n ((string= Ans \"WA\")\n (unless (find No exist-wa-count)\n (push No exist-wa-count))\n (when (find No exist-ac-count)\n (incf wa))))\n (decf M)\n (if (= M 0)\n (format t \"~D ~D~%\" ac wa)\n (calc))))\n\n(if (= M 0)\n (format t \"0 0~%\")\n (calc))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi participated in a contest on AtCoder.\n\nThe contest had N problems.\n\nTakahashi made M submissions during the contest.\n\nThe i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).\n\nThe number of Takahashi's correct answers is the number of problems on which he received an AC once or more.\n\nThe number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.\n\nFind the numbers of Takahashi's correct answers and penalties.\n\nConstraints\n\nN, M, and p_i are integers.\n\n1 \\leq N \\leq 10^5\n\n0 \\leq M \\leq 10^5\n\n1 \\leq p_i \\leq N\n\nS_i is AC or WA.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\np_1 S_1\n:\np_M S_M\n\nOutput\n\nPrint the number of Takahashi's correct answers and the number of Takahashi's penalties.\n\nSample Input 1\n\n2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n\nSample Output 1\n\n2 2\n\nIn his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.\n\nIn his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.\n\nThus, he has two correct answers and two penalties.\n\nSample Input 2\n\n100000 3\n7777 AC\n7777 AC\n7777 AC\n\nSample Output 2\n\n1 0\n\nNote that it is pointless to get an AC more than once on the same problem.\n\nSample Input 3\n\n6 0\n\nSample Output 3\n\n0 0", "sample_input": "2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n"}, "reference_outputs": ["2 2\n"], "source_document_id": "p02802", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi participated in a contest on AtCoder.\n\nThe contest had N problems.\n\nTakahashi made M submissions during the contest.\n\nThe i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).\n\nThe number of Takahashi's correct answers is the number of problems on which he received an AC once or more.\n\nThe number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.\n\nFind the numbers of Takahashi's correct answers and penalties.\n\nConstraints\n\nN, M, and p_i are integers.\n\n1 \\leq N \\leq 10^5\n\n0 \\leq M \\leq 10^5\n\n1 \\leq p_i \\leq N\n\nS_i is AC or WA.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\np_1 S_1\n:\np_M S_M\n\nOutput\n\nPrint the number of Takahashi's correct answers and the number of Takahashi's penalties.\n\nSample Input 1\n\n2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n\nSample Output 1\n\n2 2\n\nIn his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.\n\nIn his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.\n\nThus, he has two correct answers and two penalties.\n\nSample Input 2\n\n100000 3\n7777 AC\n7777 AC\n7777 AC\n\nSample Output 2\n\n1 0\n\nNote that it is pointless to get an AC more than once on the same problem.\n\nSample Input 3\n\n6 0\n\nSample Output 3\n\n0 0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 710, "cpu_time_ms": 2104, "memory_kb": 57704}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s939779234", "group_id": "codeNet:p02802", "input_text": "(defun calc (l max-count)\n (let ((No (1- (read)))\n (Ans (read)))\n (cond ((= max-count 1)\n (let ((AC 0)\n (WA 0))\n (dolist (x l)\n (when (> (car x) 0)\n (if (> (cdr x) 0)\n (progn\n (incf AC)\n (incf WA))\n (incf AC))))\n (return-from calc (cons AC WA))))\n ((string= Ans \"AC\")\n (incf (car (nth No l))))\n ((string= Ans \"WA\")\n (incf (cdr (nth No l)))))\n (calc l (decf max-count))))\n\n(let ((N (read))\n (M (read)))\n (if (= M 0)\n (format t \"0 0~%\")\n (let* ((ans (loop repeat N\n collect (cons 0 0)))\n (result (calc ans M)))\n (format t \"~A ~A~%\" (car result) (cdr result)))))\n", "language": "Lisp", "metadata": {"date": 1578937510, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02802.html", "problem_id": "p02802", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02802/input.txt", "sample_output_relpath": "derived/input_output/data/p02802/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02802/Lisp/s939779234.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s939779234", "user_id": "u631655863"}, "prompt_components": {"gold_output": "2 2\n", "input_to_evaluate": "(defun calc (l max-count)\n (let ((No (1- (read)))\n (Ans (read)))\n (cond ((= max-count 1)\n (let ((AC 0)\n (WA 0))\n (dolist (x l)\n (when (> (car x) 0)\n (if (> (cdr x) 0)\n (progn\n (incf AC)\n (incf WA))\n (incf AC))))\n (return-from calc (cons AC WA))))\n ((string= Ans \"AC\")\n (incf (car (nth No l))))\n ((string= Ans \"WA\")\n (incf (cdr (nth No l)))))\n (calc l (decf max-count))))\n\n(let ((N (read))\n (M (read)))\n (if (= M 0)\n (format t \"0 0~%\")\n (let* ((ans (loop repeat N\n collect (cons 0 0)))\n (result (calc ans M)))\n (format t \"~A ~A~%\" (car result) (cdr result)))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi participated in a contest on AtCoder.\n\nThe contest had N problems.\n\nTakahashi made M submissions during the contest.\n\nThe i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).\n\nThe number of Takahashi's correct answers is the number of problems on which he received an AC once or more.\n\nThe number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.\n\nFind the numbers of Takahashi's correct answers and penalties.\n\nConstraints\n\nN, M, and p_i are integers.\n\n1 \\leq N \\leq 10^5\n\n0 \\leq M \\leq 10^5\n\n1 \\leq p_i \\leq N\n\nS_i is AC or WA.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\np_1 S_1\n:\np_M S_M\n\nOutput\n\nPrint the number of Takahashi's correct answers and the number of Takahashi's penalties.\n\nSample Input 1\n\n2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n\nSample Output 1\n\n2 2\n\nIn his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.\n\nIn his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.\n\nThus, he has two correct answers and two penalties.\n\nSample Input 2\n\n100000 3\n7777 AC\n7777 AC\n7777 AC\n\nSample Output 2\n\n1 0\n\nNote that it is pointless to get an AC more than once on the same problem.\n\nSample Input 3\n\n6 0\n\nSample Output 3\n\n0 0", "sample_input": "2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n"}, "reference_outputs": ["2 2\n"], "source_document_id": "p02802", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi participated in a contest on AtCoder.\n\nThe contest had N problems.\n\nTakahashi made M submissions during the contest.\n\nThe i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).\n\nThe number of Takahashi's correct answers is the number of problems on which he received an AC once or more.\n\nThe number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.\n\nFind the numbers of Takahashi's correct answers and penalties.\n\nConstraints\n\nN, M, and p_i are integers.\n\n1 \\leq N \\leq 10^5\n\n0 \\leq M \\leq 10^5\n\n1 \\leq p_i \\leq N\n\nS_i is AC or WA.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\np_1 S_1\n:\np_M S_M\n\nOutput\n\nPrint the number of Takahashi's correct answers and the number of Takahashi's penalties.\n\nSample Input 1\n\n2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n\nSample Output 1\n\n2 2\n\nIn his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.\n\nIn his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.\n\nThus, he has two correct answers and two penalties.\n\nSample Input 2\n\n100000 3\n7777 AC\n7777 AC\n7777 AC\n\nSample Output 2\n\n1 0\n\nNote that it is pointless to get an AC more than once on the same problem.\n\nSample Input 3\n\n6 0\n\nSample Output 3\n\n0 0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 834, "cpu_time_ms": 2105, "memory_kb": 61800}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s336391085", "group_id": "codeNet:p02803", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Queue with singly linked list\n;;;\n\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Removes and returns the element at the front of QUEUE. Returns NIL if QUEUE\nis empty.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline queue-peek))\n(defun queue-peek (queue)\n (car (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #xffffffff)\n\n(defun calc-longest (plan init-y init-x)\n (declare #.OPT\n (uint8 init-y init-x)\n ((simple-array bit (* *)) plan))\n (destructuring-bind (h w) (array-dimensions plan)\n (declare (uint8 h w))\n (let ((que (make-queue))\n (dists (make-array (list h w) :element-type 'uint32 :initial-element +inf+)))\n (labels ((visit (y x new-dist)\n (when (and (<= 0 y (- h 1))\n (<= 0 x (- w 1))\n (= +inf+ (aref dists y x))\n (zerop (aref plan y x)))\n (setf (aref dists y x) new-dist)\n (enqueue (cons y x) que))))\n (visit init-y init-x 0)\n (loop until (queue-empty-p que)\n for (y . x) = (dequeue que)\n for dist = (aref dists y x)\n do (visit (- y 1) x (+ 1 dist))\n (visit (+ y 1) x (+ 1 dist))\n (visit y (- x 1) (+ 1 dist))\n (visit y (+ x 1) (+ 1 dist)))\n (loop for d across (array-storage-vector dists)\n when (< d +inf+)\n maximize d)))))\n\n(defun main ()\n (let* ((h (read))\n (w (read))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0)))\n (declare (uint8 h w))\n (dotimes (i h)\n (let ((line (read-line)))\n (dotimes (j w)\n (when (char= #\\# (aref line j))\n (setf (aref plan i j) 1)))))\n (let ((res 0))\n (dotimes (y h)\n (dotimes (x w)\n (when (zerop (aref plan y x))\n (setq res (max res (calc-longest plan y x))))))\n (println res))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n...\n...\n...\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 5\n...#.\n.#.#.\n.#...\n\"\n \"10\n\")))\n", "language": "Lisp", "metadata": {"date": 1578890498, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02803.html", "problem_id": "p02803", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02803/input.txt", "sample_output_relpath": "derived/input_output/data/p02803/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02803/Lisp/s336391085.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s336391085", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Queue with singly linked list\n;;;\n\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Removes and returns the element at the front of QUEUE. Returns NIL if QUEUE\nis empty.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline queue-peek))\n(defun queue-peek (queue)\n (car (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #xffffffff)\n\n(defun calc-longest (plan init-y init-x)\n (declare #.OPT\n (uint8 init-y init-x)\n ((simple-array bit (* *)) plan))\n (destructuring-bind (h w) (array-dimensions plan)\n (declare (uint8 h w))\n (let ((que (make-queue))\n (dists (make-array (list h w) :element-type 'uint32 :initial-element +inf+)))\n (labels ((visit (y x new-dist)\n (when (and (<= 0 y (- h 1))\n (<= 0 x (- w 1))\n (= +inf+ (aref dists y x))\n (zerop (aref plan y x)))\n (setf (aref dists y x) new-dist)\n (enqueue (cons y x) que))))\n (visit init-y init-x 0)\n (loop until (queue-empty-p que)\n for (y . x) = (dequeue que)\n for dist = (aref dists y x)\n do (visit (- y 1) x (+ 1 dist))\n (visit (+ y 1) x (+ 1 dist))\n (visit y (- x 1) (+ 1 dist))\n (visit y (+ x 1) (+ 1 dist)))\n (loop for d across (array-storage-vector dists)\n when (< d +inf+)\n maximize d)))))\n\n(defun main ()\n (let* ((h (read))\n (w (read))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0)))\n (declare (uint8 h w))\n (dotimes (i h)\n (let ((line (read-line)))\n (dotimes (j w)\n (when (char= #\\# (aref line j))\n (setf (aref plan i j) 1)))))\n (let ((res 0))\n (dotimes (y h)\n (dotimes (x w)\n (when (zerop (aref plan y x))\n (setq res (max res (calc-longest plan y x))))))\n (println res))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n...\n...\n...\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 5\n...#.\n.#.#.\n.#...\n\"\n \"10\n\")))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nTakahashi has a maze, which is a grid of H \\times W squares with H horizontal rows and W vertical columns.\n\nThe square at the i-th row from the top and the j-th column is a \"wall\" square if S_{ij} is #, and a \"road\" square if S_{ij} is ..\n\nFrom a road square, you can move to a horizontally or vertically adjacent road square.\n\nYou cannot move out of the maze, move to a wall square, or move diagonally.\n\nTakahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.\n\nAoki will then travel from the starting square to the goal square, in the minimum number of moves required.\n\nIn this situation, find the maximum possible number of moves Aoki has to make.\n\nConstraints\n\n1 \\leq H,W \\leq 20\n\nS_{ij} is . or #.\n\nS contains at least two occurrences of ..\n\nAny road square can be reached from any road square in zero or more moves.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nS_{11}...S_{1W}\n:\nS_{H1}...S_{HW}\n\nOutput\n\nPrint the maximum possible number of moves Aoki has to make.\n\nSample Input 1\n\n3 3\n...\n...\n...\n\nSample Output 1\n\n4\n\nIf Takahashi chooses the top-left square as the starting square and the bottom-right square as the goal square, Aoki has to make four moves.\n\nSample Input 2\n\n3 5\n...#.\n.#.#.\n.#...\n\nSample Output 2\n\n10\n\nIf Takahashi chooses the bottom-left square as the starting square and the top-right square as the goal square, Aoki has to make ten moves.", "sample_input": "3 3\n...\n...\n...\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02803", "source_text": "Score : 400 points\n\nProblem Statement\n\nTakahashi has a maze, which is a grid of H \\times W squares with H horizontal rows and W vertical columns.\n\nThe square at the i-th row from the top and the j-th column is a \"wall\" square if S_{ij} is #, and a \"road\" square if S_{ij} is ..\n\nFrom a road square, you can move to a horizontally or vertically adjacent road square.\n\nYou cannot move out of the maze, move to a wall square, or move diagonally.\n\nTakahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.\n\nAoki will then travel from the starting square to the goal square, in the minimum number of moves required.\n\nIn this situation, find the maximum possible number of moves Aoki has to make.\n\nConstraints\n\n1 \\leq H,W \\leq 20\n\nS_{ij} is . or #.\n\nS contains at least two occurrences of ..\n\nAny road square can be reached from any road square in zero or more moves.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nS_{11}...S_{1W}\n:\nS_{H1}...S_{HW}\n\nOutput\n\nPrint the maximum possible number of moves Aoki has to make.\n\nSample Input 1\n\n3 3\n...\n...\n...\n\nSample Output 1\n\n4\n\nIf Takahashi chooses the top-left square as the starting square and the bottom-right square as the goal square, Aoki has to make four moves.\n\nSample Input 2\n\n3 5\n...#.\n.#.#.\n.#...\n\nSample Output 2\n\n10\n\nIf Takahashi chooses the bottom-left square as the starting square and the top-right square as the goal square, Aoki has to make ten moves.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6551, "cpu_time_ms": 247, "memory_kb": 29536}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s596791397", "group_id": "codeNet:p02803", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline warshall-floyd!))\n(defun warshall-floyd! (matrix)\n (let ((n (array-dimension matrix 0)))\n (dotimes (k n)\n (let ((base-k (array-row-major-index matrix k 0)))\n (dotimes (i n)\n (let ((base-i (array-row-major-index matrix i 0)))\n (dotimes (j n)\n (setf (row-major-aref matrix (+ base-i j))\n (min (row-major-aref matrix (+ base-i j))\n (+ (row-major-aref matrix (+ base-i k))\n (row-major-aref matrix (+ base-k j)))))))))))\n matrix)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #xffffffff)\n(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0))\n (mat (make-array (list (* h w) (* h w))\n :element-type 'uint32\n :initial-element +inf+)))\n (declare (uint8 h w))\n (dotimes (i h)\n (let ((line (read-line)))\n (dotimes (j w)\n (when (char= #\\# (aref line j))\n (setf (aref plan i j) 1)))))\n (labels ((encode (y x)\n (+ x (* y w)))\n (connect (y1 x1 y2 x2)\n (when (and (<= 0 y2 (- h 1))\n (<= 0 x2 (- w 1))\n (zerop (aref plan y2 x2)))\n (let ((v1 (encode y1 x1))\n (v2 (encode y2 x2)))\n (setf (aref mat v1 v2) 1)))))\n (dotimes (i h)\n (dotimes (j w)\n (when (zerop (aref plan i j))\n (setf (aref mat (encode i j) (encode i j)) 0)\n (connect i j (- i 1) j)\n (connect i j (+ i 1) j)\n (connect i j i (- j 1))\n (connect i j i (+ j 1)))))\n (warshall-floyd! mat)\n (let ((res 0))\n (declare (uint31 res))\n (dotimes (y1 h)\n (dotimes (x1 w)\n (dotimes (y2 h)\n (dotimes (x2 w)\n (when (and (zerop (aref plan y1 x1))\n (zerop (aref plan y2 x2)))\n (let ((dist (aref mat (encode y1 x1) (encode y2 x2))))\n (when (< dist +inf+)\n (setq res (max res dist)))))))))\n (println res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n...\n...\n...\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 5\n...#.\n.#.#.\n.#...\n\"\n \"10\n\")))\n", "language": "Lisp", "metadata": {"date": 1578887359, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02803.html", "problem_id": "p02803", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02803/input.txt", "sample_output_relpath": "derived/input_output/data/p02803/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02803/Lisp/s596791397.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s596791397", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline warshall-floyd!))\n(defun warshall-floyd! (matrix)\n (let ((n (array-dimension matrix 0)))\n (dotimes (k n)\n (let ((base-k (array-row-major-index matrix k 0)))\n (dotimes (i n)\n (let ((base-i (array-row-major-index matrix i 0)))\n (dotimes (j n)\n (setf (row-major-aref matrix (+ base-i j))\n (min (row-major-aref matrix (+ base-i j))\n (+ (row-major-aref matrix (+ base-i k))\n (row-major-aref matrix (+ base-k j)))))))))))\n matrix)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #xffffffff)\n(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0))\n (mat (make-array (list (* h w) (* h w))\n :element-type 'uint32\n :initial-element +inf+)))\n (declare (uint8 h w))\n (dotimes (i h)\n (let ((line (read-line)))\n (dotimes (j w)\n (when (char= #\\# (aref line j))\n (setf (aref plan i j) 1)))))\n (labels ((encode (y x)\n (+ x (* y w)))\n (connect (y1 x1 y2 x2)\n (when (and (<= 0 y2 (- h 1))\n (<= 0 x2 (- w 1))\n (zerop (aref plan y2 x2)))\n (let ((v1 (encode y1 x1))\n (v2 (encode y2 x2)))\n (setf (aref mat v1 v2) 1)))))\n (dotimes (i h)\n (dotimes (j w)\n (when (zerop (aref plan i j))\n (setf (aref mat (encode i j) (encode i j)) 0)\n (connect i j (- i 1) j)\n (connect i j (+ i 1) j)\n (connect i j i (- j 1))\n (connect i j i (+ j 1)))))\n (warshall-floyd! mat)\n (let ((res 0))\n (declare (uint31 res))\n (dotimes (y1 h)\n (dotimes (x1 w)\n (dotimes (y2 h)\n (dotimes (x2 w)\n (when (and (zerop (aref plan y1 x1))\n (zerop (aref plan y2 x2)))\n (let ((dist (aref mat (encode y1 x1) (encode y2 x2))))\n (when (< dist +inf+)\n (setq res (max res dist)))))))))\n (println res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n...\n...\n...\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 5\n...#.\n.#.#.\n.#...\n\"\n \"10\n\")))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nTakahashi has a maze, which is a grid of H \\times W squares with H horizontal rows and W vertical columns.\n\nThe square at the i-th row from the top and the j-th column is a \"wall\" square if S_{ij} is #, and a \"road\" square if S_{ij} is ..\n\nFrom a road square, you can move to a horizontally or vertically adjacent road square.\n\nYou cannot move out of the maze, move to a wall square, or move diagonally.\n\nTakahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.\n\nAoki will then travel from the starting square to the goal square, in the minimum number of moves required.\n\nIn this situation, find the maximum possible number of moves Aoki has to make.\n\nConstraints\n\n1 \\leq H,W \\leq 20\n\nS_{ij} is . or #.\n\nS contains at least two occurrences of ..\n\nAny road square can be reached from any road square in zero or more moves.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nS_{11}...S_{1W}\n:\nS_{H1}...S_{HW}\n\nOutput\n\nPrint the maximum possible number of moves Aoki has to make.\n\nSample Input 1\n\n3 3\n...\n...\n...\n\nSample Output 1\n\n4\n\nIf Takahashi chooses the top-left square as the starting square and the bottom-right square as the goal square, Aoki has to make four moves.\n\nSample Input 2\n\n3 5\n...#.\n.#.#.\n.#...\n\nSample Output 2\n\n10\n\nIf Takahashi chooses the bottom-left square as the starting square and the top-right square as the goal square, Aoki has to make ten moves.", "sample_input": "3 3\n...\n...\n...\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02803", "source_text": "Score : 400 points\n\nProblem Statement\n\nTakahashi has a maze, which is a grid of H \\times W squares with H horizontal rows and W vertical columns.\n\nThe square at the i-th row from the top and the j-th column is a \"wall\" square if S_{ij} is #, and a \"road\" square if S_{ij} is ..\n\nFrom a road square, you can move to a horizontally or vertically adjacent road square.\n\nYou cannot move out of the maze, move to a wall square, or move diagonally.\n\nTakahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.\n\nAoki will then travel from the starting square to the goal square, in the minimum number of moves required.\n\nIn this situation, find the maximum possible number of moves Aoki has to make.\n\nConstraints\n\n1 \\leq H,W \\leq 20\n\nS_{ij} is . or #.\n\nS contains at least two occurrences of ..\n\nAny road square can be reached from any road square in zero or more moves.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nS_{11}...S_{1W}\n:\nS_{H1}...S_{HW}\n\nOutput\n\nPrint the maximum possible number of moves Aoki has to make.\n\nSample Input 1\n\n3 3\n...\n...\n...\n\nSample Output 1\n\n4\n\nIf Takahashi chooses the top-left square as the starting square and the bottom-right square as the goal square, Aoki has to make four moves.\n\nSample Input 2\n\n3 5\n...#.\n.#.#.\n.#...\n\nSample Output 2\n\n10\n\nIf Takahashi chooses the bottom-left square as the starting square and the top-right square as the goal square, Aoki has to make ten moves.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5906, "cpu_time_ms": 427, "memory_kb": 28384}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s567565096", "group_id": "codeNet:p02805", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n\n;; http://www.ambrsoft.com/trigocalc/circle3d.htm\n;; FIXME: more sane handling of degeneracy\n(declaim (inline calc-circumcenter))\n(defun calc-circumcenter (p1 p2 p3)\n \"Returns the center of circumcirlce if it exists, otherwise returns NIL.\"\n (declare (complex p1 p2 p3))\n (let* ((x1 (realpart p1))\n (y1 (imagpart p1))\n (x2 (realpart p2))\n (y2 (imagpart p2))\n (x3 (realpart p3))\n (y3 (imagpart p3))\n (a (+ (* x1 (- y2 y3))\n (- (* y1 (- x2 x3)))\n (* x2 y3)\n (- (* x3 y2))))\n (b (+ (* (+ (* x1 x1) (* y1 y1)) (- y3 y2))\n (* (+ (* x2 x2) (* y2 y2)) (- y1 y3))\n (* (+ (* x3 x3) (* y3 y3)) (- y2 y1))))\n (c (+ (* (+ (* x1 x1) (* y1 y1)) (- x2 x3))\n (* (+ (* x2 x2) (* y2 y2)) (- x3 x1))\n (* (+ (* x3 x3) (* y3 y3)) (- x1 x2)))))\n (handler-bind ((error (lambda (c)\n (declare (ignore c))\n (return-from calc-circumcenter nil))))\n (complex (- (/ b (* 2 a)))\n (- (/ c (* 2 a)))))))\n\n(defun mini-disc-with-2-points (points end q1 q2 eps)\n \"Returns the smallest circle that contains points, q1 and q2 (contains q1 and\nq2 at the perimeter).\"\n (declare (complex q1 q2)\n (double-float eps)\n ((integer 0 #.most-positive-fixnum) end))\n (let* ((center (* 0.5d0 (+ q1 q2)))\n (radius (abs (- q1 center))))\n (declare (complex center)\n (double-float radius))\n (dotimes (i end)\n (let ((new-point (aref points i)))\n (declare (complex new-point))\n (when (>= (abs (- new-point center)) (+ radius eps))\n (let ((new-center (calc-circumcenter q1 q2 new-point)))\n (setq center new-center\n radius (abs (- new-point new-center)))))))\n (values center radius)))\n\n(declaim (inline %shuffle!))\n(defun %shuffle! (vector &optional end)\n \"Destructively shuffles VECTOR by Fisher-Yates algorithm.\"\n (declare (vector vector))\n (loop for i from (- (or end (length vector)) 1) above 0\n for j = (random (+ i 1))\n do (rotatef (aref vector i) (aref vector j)))\n vector)\n\n(defun mini-disc-with-point (points end q eps)\n (declare (complex q)\n (double-float eps))\n (%shuffle! points end)\n (let* ((center (* 0.5d0 (+ (aref points 0) q)))\n (radius (abs (- q center))))\n (declare (complex center)\n (double-float radius))\n (loop for i from 1 below end\n for new-point of-type complex = (aref points i)\n when (>= (abs (- new-point center)) (+ radius eps))\n do (setf (values center radius)\n (mini-disc-with-2-points points i (aref points i) q eps)))\n (values center radius)))\n\n(defun calc-smallest-circle (points eps)\n (assert (>= (length points) 1))\n (when (= 1 (length points))\n (return-from calc-smallest-circle\n (values (aref points 0)\n (coerce 0 (type-of (realpart (aref points 0)))))))\n (let* ((points (copy-seq (%shuffle! points)))\n (copy (copy-seq points))\n (p0 (aref points 0))\n (p1 (aref points 1))\n (center (* 1/2 (+ p0 p1)))\n (radius (abs (- p0 center))))\n (loop for i from 2 below (length points)\n for new-point = (aref points i)\n when (>= (abs (- new-point center)) (+ radius eps))\n do (setf (values center radius)\n (mini-disc-with-point copy i new-point eps)))\n (values center radius)))\n\n(defun main ()\n (let* ((n (read))\n (points (make-array n :element-type '(complex double-float))))\n (declare (uint16 n))\n (dotimes (i n)\n (let ((x (float (read) 1d0))\n (y (float (read) 1d0)))\n (setf (aref points i) (complex x y))))\n (println (nth-value 1 (calc-smallest-circle points 1d-9)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n0 0\n1 0\n\"\n \"0.500000000000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n0 0\n0 1\n1 0\n\"\n \"0.707106781186497524\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n10 9\n5 9\n2 0\n0 0\n2 7\n3 3\n2 5\n10 0\n3 7\n1 9\n\"\n \"6.726812023536805158\n\")))\n", "language": "Lisp", "metadata": {"date": 1579339956, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02805.html", "problem_id": "p02805", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02805/input.txt", "sample_output_relpath": "derived/input_output/data/p02805/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02805/Lisp/s567565096.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s567565096", "user_id": "u352600849"}, "prompt_components": {"gold_output": "0.500000000000000000\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n\n;; http://www.ambrsoft.com/trigocalc/circle3d.htm\n;; FIXME: more sane handling of degeneracy\n(declaim (inline calc-circumcenter))\n(defun calc-circumcenter (p1 p2 p3)\n \"Returns the center of circumcirlce if it exists, otherwise returns NIL.\"\n (declare (complex p1 p2 p3))\n (let* ((x1 (realpart p1))\n (y1 (imagpart p1))\n (x2 (realpart p2))\n (y2 (imagpart p2))\n (x3 (realpart p3))\n (y3 (imagpart p3))\n (a (+ (* x1 (- y2 y3))\n (- (* y1 (- x2 x3)))\n (* x2 y3)\n (- (* x3 y2))))\n (b (+ (* (+ (* x1 x1) (* y1 y1)) (- y3 y2))\n (* (+ (* x2 x2) (* y2 y2)) (- y1 y3))\n (* (+ (* x3 x3) (* y3 y3)) (- y2 y1))))\n (c (+ (* (+ (* x1 x1) (* y1 y1)) (- x2 x3))\n (* (+ (* x2 x2) (* y2 y2)) (- x3 x1))\n (* (+ (* x3 x3) (* y3 y3)) (- x1 x2)))))\n (handler-bind ((error (lambda (c)\n (declare (ignore c))\n (return-from calc-circumcenter nil))))\n (complex (- (/ b (* 2 a)))\n (- (/ c (* 2 a)))))))\n\n(defun mini-disc-with-2-points (points end q1 q2 eps)\n \"Returns the smallest circle that contains points, q1 and q2 (contains q1 and\nq2 at the perimeter).\"\n (declare (complex q1 q2)\n (double-float eps)\n ((integer 0 #.most-positive-fixnum) end))\n (let* ((center (* 0.5d0 (+ q1 q2)))\n (radius (abs (- q1 center))))\n (declare (complex center)\n (double-float radius))\n (dotimes (i end)\n (let ((new-point (aref points i)))\n (declare (complex new-point))\n (when (>= (abs (- new-point center)) (+ radius eps))\n (let ((new-center (calc-circumcenter q1 q2 new-point)))\n (setq center new-center\n radius (abs (- new-point new-center)))))))\n (values center radius)))\n\n(declaim (inline %shuffle!))\n(defun %shuffle! (vector &optional end)\n \"Destructively shuffles VECTOR by Fisher-Yates algorithm.\"\n (declare (vector vector))\n (loop for i from (- (or end (length vector)) 1) above 0\n for j = (random (+ i 1))\n do (rotatef (aref vector i) (aref vector j)))\n vector)\n\n(defun mini-disc-with-point (points end q eps)\n (declare (complex q)\n (double-float eps))\n (%shuffle! points end)\n (let* ((center (* 0.5d0 (+ (aref points 0) q)))\n (radius (abs (- q center))))\n (declare (complex center)\n (double-float radius))\n (loop for i from 1 below end\n for new-point of-type complex = (aref points i)\n when (>= (abs (- new-point center)) (+ radius eps))\n do (setf (values center radius)\n (mini-disc-with-2-points points i (aref points i) q eps)))\n (values center radius)))\n\n(defun calc-smallest-circle (points eps)\n (assert (>= (length points) 1))\n (when (= 1 (length points))\n (return-from calc-smallest-circle\n (values (aref points 0)\n (coerce 0 (type-of (realpart (aref points 0)))))))\n (let* ((points (copy-seq (%shuffle! points)))\n (copy (copy-seq points))\n (p0 (aref points 0))\n (p1 (aref points 1))\n (center (* 1/2 (+ p0 p1)))\n (radius (abs (- p0 center))))\n (loop for i from 2 below (length points)\n for new-point = (aref points i)\n when (>= (abs (- new-point center)) (+ radius eps))\n do (setf (values center radius)\n (mini-disc-with-point copy i new-point eps)))\n (values center radius)))\n\n(defun main ()\n (let* ((n (read))\n (points (make-array n :element-type '(complex double-float))))\n (declare (uint16 n))\n (dotimes (i n)\n (let ((x (float (read) 1d0))\n (y (float (read) 1d0)))\n (setf (aref points i) (complex x y))))\n (println (nth-value 1 (calc-smallest-circle points 1d-9)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n0 0\n1 0\n\"\n \"0.500000000000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n0 0\n0 1\n1 0\n\"\n \"0.707106781186497524\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n10 9\n5 9\n2 0\n0 0\n2 7\n3 3\n2 5\n10 0\n3 7\n1 9\n\"\n \"6.726812023536805158\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven are N points (x_i, y_i) in a two-dimensional plane.\n\nFind the minimum radius of a circle such that all the points are inside or on it.\n\nConstraints\n\n2 \\leq N \\leq 50\n\n0 \\leq x_i \\leq 1000\n\n0 \\leq y_i \\leq 1000\n\nThe given N points are all different.\n\nThe values in input are all integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\n:\nx_N y_N\n\nOutput\n\nPrint the minimum radius of a circle such that all the N points are inside or on it.\n\nYour output will be considered correct if the absolute or relative error from our answer is at most 10^{-6}.\n\nSample Input 1\n\n2\n0 0\n1 0\n\nSample Output 1\n\n0.500000000000000000\n\nBoth points are contained in the circle centered at (0.5,0) with a radius of 0.5.\n\nSample Input 2\n\n3\n0 0\n0 1\n1 0\n\nSample Output 2\n\n0.707106781186497524\n\nSample Input 3\n\n10\n10 9\n5 9\n2 0\n0 0\n2 7\n3 3\n2 5\n10 0\n3 7\n1 9\n\nSample Output 3\n\n6.726812023536805158\n\nIf the absolute or relative error from our answer is at most 10^{-6}, the output will be considered correct.", "sample_input": "2\n0 0\n1 0\n"}, "reference_outputs": ["0.500000000000000000\n"], "source_document_id": "p02805", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are N points (x_i, y_i) in a two-dimensional plane.\n\nFind the minimum radius of a circle such that all the points are inside or on it.\n\nConstraints\n\n2 \\leq N \\leq 50\n\n0 \\leq x_i \\leq 1000\n\n0 \\leq y_i \\leq 1000\n\nThe given N points are all different.\n\nThe values in input are all integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\n:\nx_N y_N\n\nOutput\n\nPrint the minimum radius of a circle such that all the N points are inside or on it.\n\nYour output will be considered correct if the absolute or relative error from our answer is at most 10^{-6}.\n\nSample Input 1\n\n2\n0 0\n1 0\n\nSample Output 1\n\n0.500000000000000000\n\nBoth points are contained in the circle centered at (0.5,0) with a radius of 0.5.\n\nSample Input 2\n\n3\n0 0\n0 1\n1 0\n\nSample Output 2\n\n0.707106781186497524\n\nSample Input 3\n\n10\n10 9\n5 9\n2 0\n0 0\n2 7\n3 3\n2 5\n10 0\n3 7\n1 9\n\nSample Output 3\n\n6.726812023536805158\n\nIf the absolute or relative error from our answer is at most 10^{-6}, the output will be considered correct.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7901, "cpu_time_ms": 114, "memory_kb": 27112}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s563256657", "group_id": "codeNet:p02805", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n\n;; http://www.ambrsoft.com/trigocalc/circle3d.htm\n;; FIXME: more sane handling of degeneracy\n(declaim (inline calc-circumcenter))\n(defun calc-circumcenter (p1 p2 p3)\n \"Returns the center of circumcirlce if it exists, otherwise returns NIL.\"\n (declare (complex p1 p2 p3))\n (let* ((x1 (realpart p1))\n (y1 (imagpart p1))\n (x2 (realpart p2))\n (y2 (imagpart p2))\n (x3 (realpart p3))\n (y3 (imagpart p3))\n (a (+ (* x1 (- y2 y3))\n (- (* y1 (- x2 x3)))\n (* x2 y3)\n (- (* x3 y2))))\n (b (+ (* (+ (* x1 x1) (* y1 y1)) (- y3 y2))\n (* (+ (* x2 x2) (* y2 y2)) (- y1 y3))\n (* (+ (* x3 x3) (* y3 y3)) (- y2 y1))))\n (c (+ (* (+ (* x1 x1) (* y1 y1)) (- x2 x3))\n (* (+ (* x2 x2) (* y2 y2)) (- x3 x1))\n (* (+ (* x3 x3) (* y3 y3)) (- x1 x2)))))\n (handler-bind ((error (lambda (c)\n (declare (ignore c))\n (return-from calc-circumcenter nil))))\n (complex (- (/ b (* 2 a)))\n (- (/ c (* 2 a)))))))\n\n(defun mini-disc-with-2-points (points end q1 q2 eps)\n \"Returns the smallest circle that contains points, q1 and q2 (contains q1 and\nq2 at the perimeter).\"\n (declare (complex q1 q2)\n (double-float eps)\n ((integer 0 #.most-positive-fixnum) end))\n (let* ((center (* 1/2 (+ q1 q2)))\n (radius (abs (- q1 center))))\n (declare (complex center)\n (double-float radius))\n (dotimes (i end)\n (let ((new-point (aref points i)))\n (declare (complex new-point))\n (when (>= (abs (- new-point center)) (+ radius eps))\n (let ((new-center (calc-circumcenter q1 q2 new-point)))\n (setq center new-center\n radius (abs (- new-point new-center)))))))\n (values center radius)))\n\n(declaim (inline %shuffle!))\n(defun %shuffle! (vector &optional end)\n \"Destructively shuffles VECTOR by Fisher-Yates algorithm.\"\n (declare (vector vector))\n (loop for i from (- (or end (length vector)) 1) above 0\n for j = (random (+ i 1))\n do (rotatef (aref vector i) (aref vector j)))\n vector)\n\n(defun mini-disc-with-point (points end q eps)\n (declare (complex q)\n (double-float eps))\n (%shuffle! points end)\n (let* ((center (* 1/2 (+ (aref points 0) q)))\n (radius (abs (- q center))))\n (declare (complex center)\n (double-float radius))\n (loop for i from 1 below end\n for new-point of-type complex = (aref points i)\n when (>= (abs (- new-point center)) (+ radius eps))\n do (setf (values center radius)\n (mini-disc-with-2-points points i (aref points i) q eps)))\n (values center radius)))\n\n(defun calc-smallest-circle (points eps)\n (assert (>= (length points) 1))\n (when (= 1 (length points))\n (return-from calc-smallest-circle\n (values (aref points 0)\n (coerce 0 (type-of (realpart (aref points 0)))))))\n (let* ((points (copy-seq points))\n (copy (copy-seq points))\n (p0 (aref points 0))\n (p1 (aref points 1))\n (center (* 1/2 (+ p0 p1)))\n (radius (abs (- p0 center))))\n (%shuffle! points)\n (loop for i from 2 below (length points)\n for new-point = (aref points i)\n when (>= (abs (- new-point center)) (+ radius eps))\n do (setf (values center radius)\n (mini-disc-with-point copy i new-point eps)))\n (values center radius)))\n\n(defun main ()\n (let* ((n (read))\n (points (make-array n :element-type '(complex double-float))))\n (declare (uint16 n))\n (dotimes (i n)\n (let ((x (float (read) 1d0))\n (y (float (read) 1d0)))\n (setf (aref points i) (complex x y))))\n (println (nth-value 1 (calc-smallest-circle points 1d-9)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n0 0\n1 0\n\"\n \"0.500000000000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n0 0\n0 1\n1 0\n\"\n \"0.707106781186497524\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n10 9\n5 9\n2 0\n0 0\n2 7\n3 3\n2 5\n10 0\n3 7\n1 9\n\"\n \"6.726812023536805158\n\")))\n", "language": "Lisp", "metadata": {"date": 1579339530, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02805.html", "problem_id": "p02805", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02805/input.txt", "sample_output_relpath": "derived/input_output/data/p02805/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02805/Lisp/s563256657.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s563256657", "user_id": "u352600849"}, "prompt_components": {"gold_output": "0.500000000000000000\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n\n;; http://www.ambrsoft.com/trigocalc/circle3d.htm\n;; FIXME: more sane handling of degeneracy\n(declaim (inline calc-circumcenter))\n(defun calc-circumcenter (p1 p2 p3)\n \"Returns the center of circumcirlce if it exists, otherwise returns NIL.\"\n (declare (complex p1 p2 p3))\n (let* ((x1 (realpart p1))\n (y1 (imagpart p1))\n (x2 (realpart p2))\n (y2 (imagpart p2))\n (x3 (realpart p3))\n (y3 (imagpart p3))\n (a (+ (* x1 (- y2 y3))\n (- (* y1 (- x2 x3)))\n (* x2 y3)\n (- (* x3 y2))))\n (b (+ (* (+ (* x1 x1) (* y1 y1)) (- y3 y2))\n (* (+ (* x2 x2) (* y2 y2)) (- y1 y3))\n (* (+ (* x3 x3) (* y3 y3)) (- y2 y1))))\n (c (+ (* (+ (* x1 x1) (* y1 y1)) (- x2 x3))\n (* (+ (* x2 x2) (* y2 y2)) (- x3 x1))\n (* (+ (* x3 x3) (* y3 y3)) (- x1 x2)))))\n (handler-bind ((error (lambda (c)\n (declare (ignore c))\n (return-from calc-circumcenter nil))))\n (complex (- (/ b (* 2 a)))\n (- (/ c (* 2 a)))))))\n\n(defun mini-disc-with-2-points (points end q1 q2 eps)\n \"Returns the smallest circle that contains points, q1 and q2 (contains q1 and\nq2 at the perimeter).\"\n (declare (complex q1 q2)\n (double-float eps)\n ((integer 0 #.most-positive-fixnum) end))\n (let* ((center (* 1/2 (+ q1 q2)))\n (radius (abs (- q1 center))))\n (declare (complex center)\n (double-float radius))\n (dotimes (i end)\n (let ((new-point (aref points i)))\n (declare (complex new-point))\n (when (>= (abs (- new-point center)) (+ radius eps))\n (let ((new-center (calc-circumcenter q1 q2 new-point)))\n (setq center new-center\n radius (abs (- new-point new-center)))))))\n (values center radius)))\n\n(declaim (inline %shuffle!))\n(defun %shuffle! (vector &optional end)\n \"Destructively shuffles VECTOR by Fisher-Yates algorithm.\"\n (declare (vector vector))\n (loop for i from (- (or end (length vector)) 1) above 0\n for j = (random (+ i 1))\n do (rotatef (aref vector i) (aref vector j)))\n vector)\n\n(defun mini-disc-with-point (points end q eps)\n (declare (complex q)\n (double-float eps))\n (%shuffle! points end)\n (let* ((center (* 1/2 (+ (aref points 0) q)))\n (radius (abs (- q center))))\n (declare (complex center)\n (double-float radius))\n (loop for i from 1 below end\n for new-point of-type complex = (aref points i)\n when (>= (abs (- new-point center)) (+ radius eps))\n do (setf (values center radius)\n (mini-disc-with-2-points points i (aref points i) q eps)))\n (values center radius)))\n\n(defun calc-smallest-circle (points eps)\n (assert (>= (length points) 1))\n (when (= 1 (length points))\n (return-from calc-smallest-circle\n (values (aref points 0)\n (coerce 0 (type-of (realpart (aref points 0)))))))\n (let* ((points (copy-seq points))\n (copy (copy-seq points))\n (p0 (aref points 0))\n (p1 (aref points 1))\n (center (* 1/2 (+ p0 p1)))\n (radius (abs (- p0 center))))\n (%shuffle! points)\n (loop for i from 2 below (length points)\n for new-point = (aref points i)\n when (>= (abs (- new-point center)) (+ radius eps))\n do (setf (values center radius)\n (mini-disc-with-point copy i new-point eps)))\n (values center radius)))\n\n(defun main ()\n (let* ((n (read))\n (points (make-array n :element-type '(complex double-float))))\n (declare (uint16 n))\n (dotimes (i n)\n (let ((x (float (read) 1d0))\n (y (float (read) 1d0)))\n (setf (aref points i) (complex x y))))\n (println (nth-value 1 (calc-smallest-circle points 1d-9)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n0 0\n1 0\n\"\n \"0.500000000000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n0 0\n0 1\n1 0\n\"\n \"0.707106781186497524\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n10 9\n5 9\n2 0\n0 0\n2 7\n3 3\n2 5\n10 0\n3 7\n1 9\n\"\n \"6.726812023536805158\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven are N points (x_i, y_i) in a two-dimensional plane.\n\nFind the minimum radius of a circle such that all the points are inside or on it.\n\nConstraints\n\n2 \\leq N \\leq 50\n\n0 \\leq x_i \\leq 1000\n\n0 \\leq y_i \\leq 1000\n\nThe given N points are all different.\n\nThe values in input are all integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\n:\nx_N y_N\n\nOutput\n\nPrint the minimum radius of a circle such that all the N points are inside or on it.\n\nYour output will be considered correct if the absolute or relative error from our answer is at most 10^{-6}.\n\nSample Input 1\n\n2\n0 0\n1 0\n\nSample Output 1\n\n0.500000000000000000\n\nBoth points are contained in the circle centered at (0.5,0) with a radius of 0.5.\n\nSample Input 2\n\n3\n0 0\n0 1\n1 0\n\nSample Output 2\n\n0.707106781186497524\n\nSample Input 3\n\n10\n10 9\n5 9\n2 0\n0 0\n2 7\n3 3\n2 5\n10 0\n3 7\n1 9\n\nSample Output 3\n\n6.726812023536805158\n\nIf the absolute or relative error from our answer is at most 10^{-6}, the output will be considered correct.", "sample_input": "2\n0 0\n1 0\n"}, "reference_outputs": ["0.500000000000000000\n"], "source_document_id": "p02805", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are N points (x_i, y_i) in a two-dimensional plane.\n\nFind the minimum radius of a circle such that all the points are inside or on it.\n\nConstraints\n\n2 \\leq N \\leq 50\n\n0 \\leq x_i \\leq 1000\n\n0 \\leq y_i \\leq 1000\n\nThe given N points are all different.\n\nThe values in input are all integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\n:\nx_N y_N\n\nOutput\n\nPrint the minimum radius of a circle such that all the N points are inside or on it.\n\nYour output will be considered correct if the absolute or relative error from our answer is at most 10^{-6}.\n\nSample Input 1\n\n2\n0 0\n1 0\n\nSample Output 1\n\n0.500000000000000000\n\nBoth points are contained in the circle centered at (0.5,0) with a radius of 0.5.\n\nSample Input 2\n\n3\n0 0\n0 1\n1 0\n\nSample Output 2\n\n0.707106781186497524\n\nSample Input 3\n\n10\n10 9\n5 9\n2 0\n0 0\n2 7\n3 3\n2 5\n10 0\n3 7\n1 9\n\nSample Output 3\n\n6.726812023536805158\n\nIf the absolute or relative error from our answer is at most 10^{-6}, the output will be considered correct.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7908, "cpu_time_ms": 261, "memory_kb": 38496}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s959820867", "group_id": "codeNet:p02806", "input_text": "(defun solve (n playlist x)\n (declare (ignore n))\n (loop for ((title . s) . rest) on playlist\n if (string= title x)\n do (return\n (loop for (nil . time) in rest\n summing time))))\n\n#-swank\n(let* ((n (read))\n (playlist (loop repeat n\n for line = (read-line)\n for pos = (position #\\Space line)\n collect (cons (subseq line 0 pos)\n (parse-integer line :start (1+ pos)))))\n (x (read-line)))\n (format t \"~A~%\" (solve n playlist x)))\n", "language": "Lisp", "metadata": {"date": 1578791146, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02806.html", "problem_id": "p02806", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02806/input.txt", "sample_output_relpath": "derived/input_output/data/p02806/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02806/Lisp/s959820867.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s959820867", "user_id": "u202886318"}, "prompt_components": {"gold_output": "30\n", "input_to_evaluate": "(defun solve (n playlist x)\n (declare (ignore n))\n (loop for ((title . s) . rest) on playlist\n if (string= title x)\n do (return\n (loop for (nil . time) in rest\n summing time))))\n\n#-swank\n(let* ((n (read))\n (playlist (loop repeat n\n for line = (read-line)\n for pos = (position #\\Space line)\n collect (cons (subseq line 0 pos)\n (parse-integer line :start (1+ pos)))))\n (x (read-line)))\n (format t \"~A~%\" (solve n playlist x)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nNiwango created a playlist of N songs.\nThe title and the duration of the i-th song are s_i and t_i seconds, respectively.\nIt is guaranteed that s_1,\\ldots,s_N are all distinct.\n\nNiwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.)\nHowever, he fell asleep during his work, and he woke up after all the songs were played.\nAccording to his record, it turned out that he fell asleep at the very end of the song titled X.\n\nFind the duration of time when some song was played while Niwango was asleep.\n\nConstraints\n\n1 \\leq N \\leq 50\n\ns_i and X are strings of length between 1 and 100 (inclusive) consisting of lowercase English letters.\n\ns_1,\\ldots,s_N are distinct.\n\nThere exists an integer i such that s_i = X.\n\n1 \\leq t_i \\leq 1000\n\nt_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\ns_1 t_1\n\\vdots\ns_{N} t_N\nX\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3\ndwango 2\nsixth 5\nprelims 25\ndwango\n\nSample Output 1\n\n30\n\nWhile Niwango was asleep, two songs were played: sixth and prelims.\n\nThe answer is the total duration of these songs, 30.\n\nSample Input 2\n\n1\nabcde 1000\nabcde\n\nSample Output 2\n\n0\n\nNo songs were played while Niwango was asleep.\n\nIn such a case, the total duration of songs is 0.\n\nSample Input 3\n\n15\nypnxn 279\nkgjgwx 464\nqquhuwq 327\nrxing 549\npmuduhznoaqu 832\ndagktgdarveusju 595\nwunfagppcoi 200\ndhavrncwfw 720\njpcmigg 658\nwrczqxycivdqn 639\nmcmkkbnjfeod 992\nhtqvkgkbhtytsz 130\ntwflegsjz 467\ndswxxrxuzzfhkp 989\nszfwtzfpnscgue 958\npmuduhznoaqu\n\nSample Output 3\n\n6348", "sample_input": "3\ndwango 2\nsixth 5\nprelims 25\ndwango\n"}, "reference_outputs": ["30\n"], "source_document_id": "p02806", "source_text": "Score : 200 points\n\nProblem Statement\n\nNiwango created a playlist of N songs.\nThe title and the duration of the i-th song are s_i and t_i seconds, respectively.\nIt is guaranteed that s_1,\\ldots,s_N are all distinct.\n\nNiwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.)\nHowever, he fell asleep during his work, and he woke up after all the songs were played.\nAccording to his record, it turned out that he fell asleep at the very end of the song titled X.\n\nFind the duration of time when some song was played while Niwango was asleep.\n\nConstraints\n\n1 \\leq N \\leq 50\n\ns_i and X are strings of length between 1 and 100 (inclusive) consisting of lowercase English letters.\n\ns_1,\\ldots,s_N are distinct.\n\nThere exists an integer i such that s_i = X.\n\n1 \\leq t_i \\leq 1000\n\nt_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\ns_1 t_1\n\\vdots\ns_{N} t_N\nX\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3\ndwango 2\nsixth 5\nprelims 25\ndwango\n\nSample Output 1\n\n30\n\nWhile Niwango was asleep, two songs were played: sixth and prelims.\n\nThe answer is the total duration of these songs, 30.\n\nSample Input 2\n\n1\nabcde 1000\nabcde\n\nSample Output 2\n\n0\n\nNo songs were played while Niwango was asleep.\n\nIn such a case, the total duration of songs is 0.\n\nSample Input 3\n\n15\nypnxn 279\nkgjgwx 464\nqquhuwq 327\nrxing 549\npmuduhznoaqu 832\ndagktgdarveusju 595\nwunfagppcoi 200\ndhavrncwfw 720\njpcmigg 658\nwrczqxycivdqn 639\nmcmkkbnjfeod 992\nhtqvkgkbhtytsz 130\ntwflegsjz 467\ndswxxrxuzzfhkp 989\nszfwtzfpnscgue 958\npmuduhznoaqu\n\nSample Output 3\n\n6348", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 586, "cpu_time_ms": 157, "memory_kb": 16100}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s546346719", "group_id": "codeNet:p02807", "input_text": "(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defun fact (n)\n (if (= n 1)\n 1\n (* n (fact (1- n)))))\n\n(defparameter N (parse-integer (read-line)))\n(defparameter lst\n (mapcar #'parse-integer (split \" \" (read-line))))\n(defparameter const (+ 7 (expt 10 9)))\n(defparameter dists\n (loop for i from 0 below (1- N)\n collect (- (nth (1+ i) lst) (nth i lst))))\n(defparameter f (fact (1- N)))\n(defparameter coeff\n (loop for i from 1 below N\n collect (apply #'+\n (loop for j from 1 to i\n collect (/ 1 j)))))\n\n(format t \"~A\" (mod (* f (add-lst coeff dists)) const))\n", "language": "Lisp", "metadata": {"date": 1578805063, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02807.html", "problem_id": "p02807", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02807/input.txt", "sample_output_relpath": "derived/input_output/data/p02807/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02807/Lisp/s546346719.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s546346719", "user_id": "u425317134"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defun fact (n)\n (if (= n 1)\n 1\n (* n (fact (1- n)))))\n\n(defparameter N (parse-integer (read-line)))\n(defparameter lst\n (mapcar #'parse-integer (split \" \" (read-line))))\n(defparameter const (+ 7 (expt 10 9)))\n(defparameter dists\n (loop for i from 0 below (1- N)\n collect (- (nth (1+ i) lst) (nth i lst))))\n(defparameter f (fact (1- N)))\n(defparameter coeff\n (loop for i from 1 below N\n collect (apply #'+\n (loop for j from 1 to i\n collect (/ 1 j)))))\n\n(format t \"~A\" (mod (* f (add-lst coeff dists)) const))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere are N slimes standing on a number line.\nThe i-th slime from the left is at position x_i.\n\nIt is guaruanteed that 1 \\leq x_1 < x_2 < \\ldots < x_N \\leq 10^{9}.\n\nNiwango will perform N-1 operations. The i-th operation consists of the following procedures:\n\nChoose an integer k between 1 and N-i (inclusive) with equal probability.\n\nMove the k-th slime from the left, to the position of the neighboring slime to the right.\n\nFuse the two slimes at the same position into one slime.\n\nFind the total distance traveled by the slimes multiplied by (N-1)! (we can show that this value is an integer), modulo (10^{9}+7). If a slime is born by a fuse and that slime moves, we count it as just one slime.\n\nConstraints\n\n2 \\leq N \\leq 10^{5}\n\n1 \\leq x_1 < x_2 < \\ldots < x_N \\leq 10^{9}\n\nx_i is an integer.\n\nSubtasks\n\n400 points will be awarded for passing the test cases satisfying N \\leq 2000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 x_2 \\ldots x_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3\n1 2 3\n\nSample Output 1\n\n5\n\nWith probability \\frac{1}{2}, the leftmost slime is chosen in the first operation, in which case the total distance traveled is 2.\n\nWith probability \\frac{1}{2}, the middle slime is chosen in the first operation, in which case the total distance traveled is 3.\n\nThe answer is the expected total distance traveled, 2.5, multiplied by 2!, which is 5.\n\nSample Input 2\n\n12\n161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932\n\nSample Output 2\n\n750927044\n\nFind the expected value multiplied by (N-1)!, modulo (10^9+7).", "sample_input": "3\n1 2 3\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02807", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere are N slimes standing on a number line.\nThe i-th slime from the left is at position x_i.\n\nIt is guaruanteed that 1 \\leq x_1 < x_2 < \\ldots < x_N \\leq 10^{9}.\n\nNiwango will perform N-1 operations. The i-th operation consists of the following procedures:\n\nChoose an integer k between 1 and N-i (inclusive) with equal probability.\n\nMove the k-th slime from the left, to the position of the neighboring slime to the right.\n\nFuse the two slimes at the same position into one slime.\n\nFind the total distance traveled by the slimes multiplied by (N-1)! (we can show that this value is an integer), modulo (10^{9}+7). If a slime is born by a fuse and that slime moves, we count it as just one slime.\n\nConstraints\n\n2 \\leq N \\leq 10^{5}\n\n1 \\leq x_1 < x_2 < \\ldots < x_N \\leq 10^{9}\n\nx_i is an integer.\n\nSubtasks\n\n400 points will be awarded for passing the test cases satisfying N \\leq 2000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 x_2 \\ldots x_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3\n1 2 3\n\nSample Output 1\n\n5\n\nWith probability \\frac{1}{2}, the leftmost slime is chosen in the first operation, in which case the total distance traveled is 2.\n\nWith probability \\frac{1}{2}, the middle slime is chosen in the first operation, in which case the total distance traveled is 3.\n\nThe answer is the expected total distance traveled, 2.5, multiplied by 2!, which is 5.\n\nSample Input 2\n\n12\n161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932\n\nSample Output 2\n\n750927044\n\nFind the expected value multiplied by (N-1)!, modulo (10^9+7).", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 776, "cpu_time_ms": 2659, "memory_kb": 1009624}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s664812753", "group_id": "codeNet:p02811", "input_text": "(let ((n (read))\n (v (read)))\n (if (<= v (* n 500))\n (princ \"Yes\")\n (princ \"No\")))", "language": "Lisp", "metadata": {"date": 1585364899, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02811.html", "problem_id": "p02811", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02811/input.txt", "sample_output_relpath": "derived/input_output/data/p02811/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02811/Lisp/s664812753.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s664812753", "user_id": "u606976120"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((n (read))\n (v (read)))\n (if (<= v (* n 500))\n (princ \"Yes\")\n (princ \"No\")))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi has K 500-yen coins. (Yen is the currency of Japan.)\nIf these coins add up to X yen or more, print Yes; otherwise, print No.\n\nConstraints\n\n1 \\leq K \\leq 100\n\n1 \\leq X \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK X\n\nOutput\n\nIf the coins add up to X yen or more, print Yes; otherwise, print No.\n\nSample Input 1\n\n2 900\n\nSample Output 1\n\nYes\n\nTwo 500-yen coins add up to 1000 yen, which is not less than X = 900 yen.\n\nSample Input 2\n\n1 501\n\nSample Output 2\n\nNo\n\nOne 500-yen coin is worth 500 yen, which is less than X = 501 yen.\n\nSample Input 3\n\n4 2000\n\nSample Output 3\n\nYes\n\nFour 500-yen coins add up to 2000 yen, which is not less than X = 2000 yen.", "sample_input": "2 900\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02811", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi has K 500-yen coins. (Yen is the currency of Japan.)\nIf these coins add up to X yen or more, print Yes; otherwise, print No.\n\nConstraints\n\n1 \\leq K \\leq 100\n\n1 \\leq X \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK X\n\nOutput\n\nIf the coins add up to X yen or more, print Yes; otherwise, print No.\n\nSample Input 1\n\n2 900\n\nSample Output 1\n\nYes\n\nTwo 500-yen coins add up to 1000 yen, which is not less than X = 900 yen.\n\nSample Input 2\n\n1 501\n\nSample Output 2\n\nNo\n\nOne 500-yen coin is worth 500 yen, which is less than X = 501 yen.\n\nSample Input 3\n\n4 2000\n\nSample Output 3\n\nYes\n\nFour 500-yen coins add up to 2000 yen, which is not less than X = 2000 yen.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 98, "cpu_time_ms": 124, "memory_kb": 11496}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s872043400", "group_id": "codeNet:p02811", "input_text": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(defun f(k x)\n (<= x (* 500 k)))\n(let* ((line (mapcar #'parse-integer (splitat #\\space (read-line nil nil)))))\n (format t \"~A~%\" (if (f (car line) (cadr line)) \"Yes\" \"No\")))\n", "language": "Lisp", "metadata": {"date": 1578708243, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02811.html", "problem_id": "p02811", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02811/input.txt", "sample_output_relpath": "derived/input_output/data/p02811/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02811/Lisp/s872043400.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s872043400", "user_id": "u254205055"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(defun f(k x)\n (<= x (* 500 k)))\n(let* ((line (mapcar #'parse-integer (splitat #\\space (read-line nil nil)))))\n (format t \"~A~%\" (if (f (car line) (cadr line)) \"Yes\" \"No\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi has K 500-yen coins. (Yen is the currency of Japan.)\nIf these coins add up to X yen or more, print Yes; otherwise, print No.\n\nConstraints\n\n1 \\leq K \\leq 100\n\n1 \\leq X \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK X\n\nOutput\n\nIf the coins add up to X yen or more, print Yes; otherwise, print No.\n\nSample Input 1\n\n2 900\n\nSample Output 1\n\nYes\n\nTwo 500-yen coins add up to 1000 yen, which is not less than X = 900 yen.\n\nSample Input 2\n\n1 501\n\nSample Output 2\n\nNo\n\nOne 500-yen coin is worth 500 yen, which is less than X = 501 yen.\n\nSample Input 3\n\n4 2000\n\nSample Output 3\n\nYes\n\nFour 500-yen coins add up to 2000 yen, which is not less than X = 2000 yen.", "sample_input": "2 900\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02811", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi has K 500-yen coins. (Yen is the currency of Japan.)\nIf these coins add up to X yen or more, print Yes; otherwise, print No.\n\nConstraints\n\n1 \\leq K \\leq 100\n\n1 \\leq X \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK X\n\nOutput\n\nIf the coins add up to X yen or more, print Yes; otherwise, print No.\n\nSample Input 1\n\n2 900\n\nSample Output 1\n\nYes\n\nTwo 500-yen coins add up to 1000 yen, which is not less than X = 900 yen.\n\nSample Input 2\n\n1 501\n\nSample Output 2\n\nNo\n\nOne 500-yen coin is worth 500 yen, which is less than X = 501 yen.\n\nSample Input 3\n\n4 2000\n\nSample Output 3\n\nYes\n\nFour 500-yen coins add up to 2000 yen, which is not less than X = 2000 yen.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 424, "cpu_time_ms": 146, "memory_kb": 13800}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s623775398", "group_id": "codeNet:p02812", "input_text": "(let* ((m (read))\n (n (read-line)))\n (princ (loop :for k :from 0 :upto (- (length n) 3) :count (string= \"ABC\" (subseq n k (+ k 3))))))", "language": "Lisp", "metadata": {"date": 1578708735, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02812.html", "problem_id": "p02812", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02812/input.txt", "sample_output_relpath": "derived/input_output/data/p02812/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02812/Lisp/s623775398.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s623775398", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((m (read))\n (n (read-line)))\n (princ (loop :for k :from 0 :upto (- (length n) 3) :count (string= \"ABC\" (subseq n k (+ k 3))))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have a string S of length N consisting of uppercase English letters.\n\nHow many times does ABC occur in S as contiguous subsequences (see Sample Inputs and Outputs)?\n\nConstraints\n\n3 \\leq N \\leq 50\n\nS consists of uppercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint number of occurrences of ABC in S as contiguous subsequences.\n\nSample Input 1\n\n10\nZABCDBABCQ\n\nSample Output 1\n\n2\n\nTwo contiguous subsequences of S are equal to ABC: the 2-nd through 4-th characters, and the 7-th through 9-th characters.\n\nSample Input 2\n\n19\nTHREEONEFOURONEFIVE\n\nSample Output 2\n\n0\n\nNo contiguous subsequences of S are equal to ABC.\n\nSample Input 3\n\n33\nABCCABCBABCCABACBCBBABCBCBCBCABCB\n\nSample Output 3\n\n5", "sample_input": "10\nZABCDBABCQ\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02812", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have a string S of length N consisting of uppercase English letters.\n\nHow many times does ABC occur in S as contiguous subsequences (see Sample Inputs and Outputs)?\n\nConstraints\n\n3 \\leq N \\leq 50\n\nS consists of uppercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint number of occurrences of ABC in S as contiguous subsequences.\n\nSample Input 1\n\n10\nZABCDBABCQ\n\nSample Output 1\n\n2\n\nTwo contiguous subsequences of S are equal to ABC: the 2-nd through 4-th characters, and the 7-th through 9-th characters.\n\nSample Input 2\n\n19\nTHREEONEFOURONEFIVE\n\nSample Output 2\n\n0\n\nNo contiguous subsequences of S are equal to ABC.\n\nSample Input 3\n\n33\nABCCABCBABCCABACBCBBABCBCBCBCABCB\n\nSample Output 3\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 141, "cpu_time_ms": 188, "memory_kb": 11880}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s970152176", "group_id": "codeNet:p02813", "input_text": "(defun fact (n)\n (let ((fact 1))\n (loop :for i :from 2 :to n\n :do (setf fact (* i fact)))\n fact))\n\n(defun permutaions (n)\n (let ((table (make-hash-table :size (fact n) :test 'equalp))\n (order 0))\n (labels ((next (n use vec)\n (if (= (length vec) n)\n (setf (gethash (copy-seq vec) table) (incf order))\n (loop :for i :from 1 :to n\n :unless (aref use i)\n :do (progn\n (setf (aref use i) t)\n (vector-push i vec)\n (next n use vec)\n (vector-pop vec)\n (setf (aref use i) nil))))))\n (next n \n (make-array `(,(1+ n)) :initial-element nil)\n (make-array `(,n) :adjustable t :fill-pointer 0))\n table)))\n\n(let* ((n (read))\n (p (make-array `(,n)))\n (q (make-array `(,n)))\n (m (permutaions n)))\n (loop :for i :from 0 :to (1- n)\n :do (setf (aref p i) (read)))\n (loop :for i :from 0 :to (1- n)\n :do (setf (aref q i) (read)))\n (format t \"~A~%\" (abs (- (gethash p m) (gethash q m)))))\n", "language": "Lisp", "metadata": {"date": 1593721831, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02813.html", "problem_id": "p02813", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02813/input.txt", "sample_output_relpath": "derived/input_output/data/p02813/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02813/Lisp/s970152176.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s970152176", "user_id": "u608227593"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun fact (n)\n (let ((fact 1))\n (loop :for i :from 2 :to n\n :do (setf fact (* i fact)))\n fact))\n\n(defun permutaions (n)\n (let ((table (make-hash-table :size (fact n) :test 'equalp))\n (order 0))\n (labels ((next (n use vec)\n (if (= (length vec) n)\n (setf (gethash (copy-seq vec) table) (incf order))\n (loop :for i :from 1 :to n\n :unless (aref use i)\n :do (progn\n (setf (aref use i) t)\n (vector-push i vec)\n (next n use vec)\n (vector-pop vec)\n (setf (aref use i) nil))))))\n (next n \n (make-array `(,(1+ n)) :initial-element nil)\n (make-array `(,n) :adjustable t :fill-pointer 0))\n table)))\n\n(let* ((n (read))\n (p (make-array `(,n)))\n (q (make-array `(,n)))\n (m (permutaions n)))\n (loop :for i :from 0 :to (1- n)\n :do (setf (aref p i) (read)))\n (loop :for i :from 0 :to (1- n)\n :do (setf (aref q i) (read)))\n (format t \"~A~%\" (abs (- (gethash p m) (gethash q m)))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWe have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).\n\nThere are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.\n\nNotes\n\nFor two sequences X and Y, X is said to be lexicographically smaller than Y if and only if there exists an integer k such that X_i = Y_i~(1 \\leq i < k) and X_k < Y_k.\n\nConstraints\n\n2 \\leq N \\leq 8\n\nP and Q are permutations of size N.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 P_2 ... P_N\nQ_1 Q_2 ... Q_N\n\nOutput\n\nPrint |a - b|.\n\nSample Input 1\n\n3\n1 3 2\n3 1 2\n\nSample Output 1\n\n3\n\nThere are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3), (2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come 2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.\n\nSample Input 2\n\n8\n7 3 5 4 2 1 6 8\n3 8 2 5 4 6 7 1\n\nSample Output 2\n\n17517\n\nSample Input 3\n\n3\n1 2 3\n1 2 3\n\nSample Output 3\n\n0", "sample_input": "3\n1 3 2\n3 1 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02813", "source_text": "Score : 300 points\n\nProblem Statement\n\nWe have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).\n\nThere are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.\n\nNotes\n\nFor two sequences X and Y, X is said to be lexicographically smaller than Y if and only if there exists an integer k such that X_i = Y_i~(1 \\leq i < k) and X_k < Y_k.\n\nConstraints\n\n2 \\leq N \\leq 8\n\nP and Q are permutations of size N.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 P_2 ... P_N\nQ_1 Q_2 ... Q_N\n\nOutput\n\nPrint |a - b|.\n\nSample Input 1\n\n3\n1 3 2\n3 1 2\n\nSample Output 1\n\n3\n\nThere are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3), (2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come 2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.\n\nSample Input 2\n\n8\n7 3 5 4 2 1 6 8\n3 8 2 5 4 6 7 1\n\nSample Output 2\n\n17517\n\nSample Input 3\n\n3\n1 2 3\n1 2 3\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1206, "cpu_time_ms": 41, "memory_kb": 29248}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s404252174", "group_id": "codeNet:p02813", "input_text": "(let* ((n (read))\n (a (loop :repeat n :collect (read)))\n (b (loop :repeat n :collect (read)))\n (pm (reverse (mapcar #'reverse (permutation (loop :for k :from 1 :upto n :collect k))))))\n (princ (abs (- (position a pm :test #'equal) (position b pm :test #'equal)))))", "language": "Lisp", "metadata": {"date": 1591100380, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02813.html", "problem_id": "p02813", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02813/input.txt", "sample_output_relpath": "derived/input_output/data/p02813/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02813/Lisp/s404252174.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s404252174", "user_id": "u610490393"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let* ((n (read))\n (a (loop :repeat n :collect (read)))\n (b (loop :repeat n :collect (read)))\n (pm (reverse (mapcar #'reverse (permutation (loop :for k :from 1 :upto n :collect k))))))\n (princ (abs (- (position a pm :test #'equal) (position b pm :test #'equal)))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWe have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).\n\nThere are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.\n\nNotes\n\nFor two sequences X and Y, X is said to be lexicographically smaller than Y if and only if there exists an integer k such that X_i = Y_i~(1 \\leq i < k) and X_k < Y_k.\n\nConstraints\n\n2 \\leq N \\leq 8\n\nP and Q are permutations of size N.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 P_2 ... P_N\nQ_1 Q_2 ... Q_N\n\nOutput\n\nPrint |a - b|.\n\nSample Input 1\n\n3\n1 3 2\n3 1 2\n\nSample Output 1\n\n3\n\nThere are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3), (2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come 2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.\n\nSample Input 2\n\n8\n7 3 5 4 2 1 6 8\n3 8 2 5 4 6 7 1\n\nSample Output 2\n\n17517\n\nSample Input 3\n\n3\n1 2 3\n1 2 3\n\nSample Output 3\n\n0", "sample_input": "3\n1 3 2\n3 1 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02813", "source_text": "Score : 300 points\n\nProblem Statement\n\nWe have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).\n\nThere are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.\n\nNotes\n\nFor two sequences X and Y, X is said to be lexicographically smaller than Y if and only if there exists an integer k such that X_i = Y_i~(1 \\leq i < k) and X_k < Y_k.\n\nConstraints\n\n2 \\leq N \\leq 8\n\nP and Q are permutations of size N.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 P_2 ... P_N\nQ_1 Q_2 ... Q_N\n\nOutput\n\nPrint |a - b|.\n\nSample Input 1\n\n3\n1 3 2\n3 1 2\n\nSample Output 1\n\n3\n\nThere are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3), (2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come 2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.\n\nSample Input 2\n\n8\n7 3 5 4 2 1 6 8\n3 8 2 5 4 6 7 1\n\nSample Output 2\n\n17517\n\nSample Input 3\n\n3\n1 2 3\n1 2 3\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 283, "cpu_time_ms": 200, "memory_kb": 19424}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s242136316", "group_id": "codeNet:p02813", "input_text": "(defun split (input stack-string output-list)\n (let ((chara (car input)))\n (case chara\n ((nil) (append output-list (list stack-string)))\n (#\\space (split (cdr input)\n '()\n (append output-list (list stack-string))))\n (otherwise (split (cdr input)\n (concatenate 'string stack-string (list chara))\n output-list)))))\n\n(defun input-to-list (input)\n (mapcar #'parse-integer (split (concatenate 'list input)\n '()\n '())))\n\n(defun fact (n)\n (labels ((inner (mem n)\n (if (zerop n)\n mem\n (inner (* mem n) (1- n)))\n ))\n (inner 1 n)))\n\n(defun dec (lst n)\n (if lst \n (+ (* (fact (1- n)) (1- (car lst))) (dec (cdr lst) (1- n)))\n 0))\n\n(defvar n (parse-integer (read-line)))\n(defvar p (input-to-list (read-line)))\n(defvar q (input-to-list (read-line)))\n\n(princ (abs (- (dec p n) (dec q n))))", "language": "Lisp", "metadata": {"date": 1578713620, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02813.html", "problem_id": "p02813", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02813/input.txt", "sample_output_relpath": "derived/input_output/data/p02813/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02813/Lisp/s242136316.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s242136316", "user_id": "u250100102"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun split (input stack-string output-list)\n (let ((chara (car input)))\n (case chara\n ((nil) (append output-list (list stack-string)))\n (#\\space (split (cdr input)\n '()\n (append output-list (list stack-string))))\n (otherwise (split (cdr input)\n (concatenate 'string stack-string (list chara))\n output-list)))))\n\n(defun input-to-list (input)\n (mapcar #'parse-integer (split (concatenate 'list input)\n '()\n '())))\n\n(defun fact (n)\n (labels ((inner (mem n)\n (if (zerop n)\n mem\n (inner (* mem n) (1- n)))\n ))\n (inner 1 n)))\n\n(defun dec (lst n)\n (if lst \n (+ (* (fact (1- n)) (1- (car lst))) (dec (cdr lst) (1- n)))\n 0))\n\n(defvar n (parse-integer (read-line)))\n(defvar p (input-to-list (read-line)))\n(defvar q (input-to-list (read-line)))\n\n(princ (abs (- (dec p n) (dec q n))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWe have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).\n\nThere are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.\n\nNotes\n\nFor two sequences X and Y, X is said to be lexicographically smaller than Y if and only if there exists an integer k such that X_i = Y_i~(1 \\leq i < k) and X_k < Y_k.\n\nConstraints\n\n2 \\leq N \\leq 8\n\nP and Q are permutations of size N.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 P_2 ... P_N\nQ_1 Q_2 ... Q_N\n\nOutput\n\nPrint |a - b|.\n\nSample Input 1\n\n3\n1 3 2\n3 1 2\n\nSample Output 1\n\n3\n\nThere are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3), (2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come 2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.\n\nSample Input 2\n\n8\n7 3 5 4 2 1 6 8\n3 8 2 5 4 6 7 1\n\nSample Output 2\n\n17517\n\nSample Input 3\n\n3\n1 2 3\n1 2 3\n\nSample Output 3\n\n0", "sample_input": "3\n1 3 2\n3 1 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02813", "source_text": "Score : 300 points\n\nProblem Statement\n\nWe have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).\n\nThere are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.\n\nNotes\n\nFor two sequences X and Y, X is said to be lexicographically smaller than Y if and only if there exists an integer k such that X_i = Y_i~(1 \\leq i < k) and X_k < Y_k.\n\nConstraints\n\n2 \\leq N \\leq 8\n\nP and Q are permutations of size N.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 P_2 ... P_N\nQ_1 Q_2 ... Q_N\n\nOutput\n\nPrint |a - b|.\n\nSample Input 1\n\n3\n1 3 2\n3 1 2\n\nSample Output 1\n\n3\n\nThere are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3), (2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come 2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.\n\nSample Input 2\n\n8\n7 3 5 4 2 1 6 8\n3 8 2 5 4 6 7 1\n\nSample Output 2\n\n17517\n\nSample Input 3\n\n3\n1 2 3\n1 2 3\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1071, "cpu_time_ms": 132, "memory_kb": 12516}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s586950154", "group_id": "codeNet:p02813", "input_text": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(defun lessp(a b)\n (labels ((rec(a b)\n (if (null a)\n nil\n (if (< (car a) (car b))\n t\n (if (= (car a) (car b))\n (rec (cdr a) (cdr b))\n nil)))))\n (rec a b)))\n(defun flatten1(lst)\n (nreverse (reduce (lambda (acc a)\n\t\t\t\t\t (reduce (lambda (acc a)\n\t\t\t\t\t\t\t\t(cons a acc))\n\t\t\t\t\t\t\t a :initial-value acc))\n\t\t\t\t\tlst :initial-value nil)))\n(defun permutations(lst)\n (labels ((skip(i n lst acc)\n\t\t\t (cond ((null lst) acc)\n\t\t\t\t ((= i n) (skip (1+ i) n (cdr lst) acc))\n\t\t\t\t (t (skip (1+ i) n (cdr lst) (cons (car lst) acc)))))\n\t\t (rec (lst acc acc0)\n\t\t\t\t(if (null lst)\n\t\t\t\t (cons acc acc0)\n\t\t\t\t (flatten1 (mapcar (lambda(i) (rec (nreverse (skip 0 i lst nil)) (cons (nth i lst) acc) acc0)) (loop for i from 0 to (1- (length lst)) collect i)))\n\t\t\t\t ))\n\t\t\t\t)\n\t(rec lst nil nil)))\n(defun equallst(a b)\n (labels ((rec(a b)\n (if (null a)\n t\n (if (= (car a) (car b))\n (rec (cdr a) (cdr b))\n nil))))\n (rec a b)))\n(defun searcher (hystack needle)\n (labels ((rec(hystack i)\n (if (null hystack)\n -1\n (if (equallst (car hystack) needle)\n i\n (rec (cdr hystack) (1+ i))))))\n (rec hystack 0)))\n(defun f(n p q)\n (let* ((pq (sort (permutations (loop for i from 1 to n collect i)) #'lessp))\n (pn (searcher pq p))\n (qn (searcher pq q)))\n (abs (- pn qn))))\n\n(compile 'lessp)\n(compile 'equallst)\n(compile 'searcher)\n(compile 'f)\n(let* ((n (parse-integer (read-line nil nil)))\n (p (mapcar #'parse-integer (splitat #\\space (read-line nil nil))))\n (q (mapcar #'parse-integer (splitat #\\space (read-line nil nil)))))\n (format t \"~A~%\" (f n p q)))\n", "language": "Lisp", "metadata": {"date": 1578709740, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02813.html", "problem_id": "p02813", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02813/input.txt", "sample_output_relpath": "derived/input_output/data/p02813/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02813/Lisp/s586950154.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s586950154", "user_id": "u254205055"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(defun lessp(a b)\n (labels ((rec(a b)\n (if (null a)\n nil\n (if (< (car a) (car b))\n t\n (if (= (car a) (car b))\n (rec (cdr a) (cdr b))\n nil)))))\n (rec a b)))\n(defun flatten1(lst)\n (nreverse (reduce (lambda (acc a)\n\t\t\t\t\t (reduce (lambda (acc a)\n\t\t\t\t\t\t\t\t(cons a acc))\n\t\t\t\t\t\t\t a :initial-value acc))\n\t\t\t\t\tlst :initial-value nil)))\n(defun permutations(lst)\n (labels ((skip(i n lst acc)\n\t\t\t (cond ((null lst) acc)\n\t\t\t\t ((= i n) (skip (1+ i) n (cdr lst) acc))\n\t\t\t\t (t (skip (1+ i) n (cdr lst) (cons (car lst) acc)))))\n\t\t (rec (lst acc acc0)\n\t\t\t\t(if (null lst)\n\t\t\t\t (cons acc acc0)\n\t\t\t\t (flatten1 (mapcar (lambda(i) (rec (nreverse (skip 0 i lst nil)) (cons (nth i lst) acc) acc0)) (loop for i from 0 to (1- (length lst)) collect i)))\n\t\t\t\t ))\n\t\t\t\t)\n\t(rec lst nil nil)))\n(defun equallst(a b)\n (labels ((rec(a b)\n (if (null a)\n t\n (if (= (car a) (car b))\n (rec (cdr a) (cdr b))\n nil))))\n (rec a b)))\n(defun searcher (hystack needle)\n (labels ((rec(hystack i)\n (if (null hystack)\n -1\n (if (equallst (car hystack) needle)\n i\n (rec (cdr hystack) (1+ i))))))\n (rec hystack 0)))\n(defun f(n p q)\n (let* ((pq (sort (permutations (loop for i from 1 to n collect i)) #'lessp))\n (pn (searcher pq p))\n (qn (searcher pq q)))\n (abs (- pn qn))))\n\n(compile 'lessp)\n(compile 'equallst)\n(compile 'searcher)\n(compile 'f)\n(let* ((n (parse-integer (read-line nil nil)))\n (p (mapcar #'parse-integer (splitat #\\space (read-line nil nil))))\n (q (mapcar #'parse-integer (splitat #\\space (read-line nil nil)))))\n (format t \"~A~%\" (f n p q)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWe have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).\n\nThere are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.\n\nNotes\n\nFor two sequences X and Y, X is said to be lexicographically smaller than Y if and only if there exists an integer k such that X_i = Y_i~(1 \\leq i < k) and X_k < Y_k.\n\nConstraints\n\n2 \\leq N \\leq 8\n\nP and Q are permutations of size N.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 P_2 ... P_N\nQ_1 Q_2 ... Q_N\n\nOutput\n\nPrint |a - b|.\n\nSample Input 1\n\n3\n1 3 2\n3 1 2\n\nSample Output 1\n\n3\n\nThere are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3), (2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come 2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.\n\nSample Input 2\n\n8\n7 3 5 4 2 1 6 8\n3 8 2 5 4 6 7 1\n\nSample Output 2\n\n17517\n\nSample Input 3\n\n3\n1 2 3\n1 2 3\n\nSample Output 3\n\n0", "sample_input": "3\n1 3 2\n3 1 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02813", "source_text": "Score : 300 points\n\nProblem Statement\n\nWe have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).\n\nThere are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.\n\nNotes\n\nFor two sequences X and Y, X is said to be lexicographically smaller than Y if and only if there exists an integer k such that X_i = Y_i~(1 \\leq i < k) and X_k < Y_k.\n\nConstraints\n\n2 \\leq N \\leq 8\n\nP and Q are permutations of size N.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 P_2 ... P_N\nQ_1 Q_2 ... Q_N\n\nOutput\n\nPrint |a - b|.\n\nSample Input 1\n\n3\n1 3 2\n3 1 2\n\nSample Output 1\n\n3\n\nThere are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3), (2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come 2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.\n\nSample Input 2\n\n8\n7 3 5 4 2 1 6 8\n3 8 2 5 4 6 7 1\n\nSample Output 2\n\n17517\n\nSample Input 3\n\n3\n1 2 3\n1 2 3\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2063, "cpu_time_ms": 168, "memory_kb": 22884}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s069381650", "group_id": "codeNet:p02814", "input_text": ";; D - Semi Common Multiple\n\n(defun main ()\n (let* ((N (read))\n (M (read))\n (A (loop repeat N collect (read))))\n (princ (solve N M A))\n (fresh-line)))\n\n(defun solve (N M A)\n (let* ((H (mapcar #'(lambda (x) (floor x 2)) A)) ; a_i / 2\n (lcm (loop for x in H\n for l = x then (lcm l x) while (<= l M)\n finally (return l)))) ; Hの最小公倍数\n (if (and (<= lcm M)\n (every #'(lambda (x) (oddp (floor lcm x))) H)) ; 全要素の奇数倍\n (ash (1+ (floor M lcm)) -1) ; M以下のlcmの奇数倍の個数\n 0)))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1578789030, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02814.html", "problem_id": "p02814", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02814/input.txt", "sample_output_relpath": "derived/input_output/data/p02814/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02814/Lisp/s069381650.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s069381650", "user_id": "u227020436"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; D - Semi Common Multiple\n\n(defun main ()\n (let* ((N (read))\n (M (read))\n (A (loop repeat N collect (read))))\n (princ (solve N M A))\n (fresh-line)))\n\n(defun solve (N M A)\n (let* ((H (mapcar #'(lambda (x) (floor x 2)) A)) ; a_i / 2\n (lcm (loop for x in H\n for l = x then (lcm l x) while (<= l M)\n finally (return l)))) ; Hの最小公倍数\n (if (and (<= lcm M)\n (every #'(lambda (x) (oddp (floor lcm x))) H)) ; 全要素の奇数倍\n (ash (1+ (floor M lcm)) -1) ; M以下のlcmの奇数倍の個数\n 0)))\n\n(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nGiven are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.\n\nLet a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \\leq k \\leq N):\n\nThere exists a non-negative integer p such that X= a_k \\times (p+0.5).\n\nFind the number of semi-common multiples of A among the integers between 1 and M (inclusive).\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^9\n\n2 \\leq a_i \\leq 10^9\n\na_i is an even number.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 a_2 ... a_N\n\nOutput\n\nPrint the number of semi-common multiples of A among the integers between 1 and M (inclusive).\n\nSample Input 1\n\n2 50\n6 10\n\nSample Output 1\n\n2\n\n15 = 6 \\times 2.5\n\n15 = 10 \\times 1.5\n\n45 = 6 \\times 7.5\n\n45 = 10 \\times 4.5\n\nThus, 15 and 45 are semi-common multiples of A. There are no other semi-common multiples of A between 1 and 50, so the answer is 2.\n\nSample Input 2\n\n3 100\n14 22 40\n\nSample Output 2\n\n0\n\nThe answer can be 0.\n\nSample Input 3\n\n5 1000000000\n6 6 2 6 2\n\nSample Output 3\n\n166666667", "sample_input": "2 50\n6 10\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02814", "source_text": "Score : 400 points\n\nProblem Statement\n\nGiven are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.\n\nLet a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \\leq k \\leq N):\n\nThere exists a non-negative integer p such that X= a_k \\times (p+0.5).\n\nFind the number of semi-common multiples of A among the integers between 1 and M (inclusive).\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^9\n\n2 \\leq a_i \\leq 10^9\n\na_i is an even number.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 a_2 ... a_N\n\nOutput\n\nPrint the number of semi-common multiples of A among the integers between 1 and M (inclusive).\n\nSample Input 1\n\n2 50\n6 10\n\nSample Output 1\n\n2\n\n15 = 6 \\times 2.5\n\n15 = 10 \\times 1.5\n\n45 = 6 \\times 7.5\n\n45 = 10 \\times 4.5\n\nThus, 15 and 45 are semi-common multiples of A. There are no other semi-common multiples of A between 1 and 50, so the answer is 2.\n\nSample Input 2\n\n3 100\n14 22 40\n\nSample Output 2\n\n0\n\nThe answer can be 0.\n\nSample Input 3\n\n5 1000000000\n6 6 2 6 2\n\nSample Output 3\n\n166666667", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 614, "cpu_time_ms": 346, "memory_kb": 61924}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s273580284", "group_id": "codeNet:p02814", "input_text": "(defun solve (n m a)\n (let ((lcm (apply #'lcm\n (mapcar (lambda (x)\n (multiple-value-bind (quotient remainder)\n (truncate x 2)\n (if (zerop remainder)\n quotient\n (return-from solve 0))))\n a))))\n (ceiling (floor m lcm) 2)))\n\n#-swank\n(let* ((n (read))\n (m (read))\n (a (loop repeat n collect (read))))\n (format t \"~A~%\" (solve n m a)))\n", "language": "Lisp", "metadata": {"date": 1578729733, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02814.html", "problem_id": "p02814", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02814/input.txt", "sample_output_relpath": "derived/input_output/data/p02814/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02814/Lisp/s273580284.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s273580284", "user_id": "u202886318"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun solve (n m a)\n (let ((lcm (apply #'lcm\n (mapcar (lambda (x)\n (multiple-value-bind (quotient remainder)\n (truncate x 2)\n (if (zerop remainder)\n quotient\n (return-from solve 0))))\n a))))\n (ceiling (floor m lcm) 2)))\n\n#-swank\n(let* ((n (read))\n (m (read))\n (a (loop repeat n collect (read))))\n (format t \"~A~%\" (solve n m a)))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nGiven are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.\n\nLet a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \\leq k \\leq N):\n\nThere exists a non-negative integer p such that X= a_k \\times (p+0.5).\n\nFind the number of semi-common multiples of A among the integers between 1 and M (inclusive).\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^9\n\n2 \\leq a_i \\leq 10^9\n\na_i is an even number.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 a_2 ... a_N\n\nOutput\n\nPrint the number of semi-common multiples of A among the integers between 1 and M (inclusive).\n\nSample Input 1\n\n2 50\n6 10\n\nSample Output 1\n\n2\n\n15 = 6 \\times 2.5\n\n15 = 10 \\times 1.5\n\n45 = 6 \\times 7.5\n\n45 = 10 \\times 4.5\n\nThus, 15 and 45 are semi-common multiples of A. There are no other semi-common multiples of A between 1 and 50, so the answer is 2.\n\nSample Input 2\n\n3 100\n14 22 40\n\nSample Output 2\n\n0\n\nThe answer can be 0.\n\nSample Input 3\n\n5 1000000000\n6 6 2 6 2\n\nSample Output 3\n\n166666667", "sample_input": "2 50\n6 10\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02814", "source_text": "Score : 400 points\n\nProblem Statement\n\nGiven are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.\n\nLet a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \\leq k \\leq N):\n\nThere exists a non-negative integer p such that X= a_k \\times (p+0.5).\n\nFind the number of semi-common multiples of A among the integers between 1 and M (inclusive).\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^9\n\n2 \\leq a_i \\leq 10^9\n\na_i is an even number.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 a_2 ... a_N\n\nOutput\n\nPrint the number of semi-common multiples of A among the integers between 1 and M (inclusive).\n\nSample Input 1\n\n2 50\n6 10\n\nSample Output 1\n\n2\n\n15 = 6 \\times 2.5\n\n15 = 10 \\times 1.5\n\n45 = 6 \\times 7.5\n\n45 = 10 \\times 4.5\n\nThus, 15 and 45 are semi-common multiples of A. There are no other semi-common multiples of A between 1 and 50, so the answer is 2.\n\nSample Input 2\n\n3 100\n14 22 40\n\nSample Output 2\n\n0\n\nThe answer can be 0.\n\nSample Input 3\n\n5 1000000000\n6 6 2 6 2\n\nSample Output 3\n\n166666667", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 557, "cpu_time_ms": 330, "memory_kb": 59880}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s350332157", "group_id": "codeNet:p02814", "input_text": "(defun solve (n m a)\n (let ((lcm (apply #'lcm\n (mapcar (lambda (a) (/ a 2))\n a))))\n (ceiling (floor m lcm) 2)))\n\n#-swank\n(let* ((n (read))\n (m (read))\n (a (loop repeat n collect (read))))\n (format t \"~A~%\" (solve n m a)))\n", "language": "Lisp", "metadata": {"date": 1578711285, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02814.html", "problem_id": "p02814", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02814/input.txt", "sample_output_relpath": "derived/input_output/data/p02814/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02814/Lisp/s350332157.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s350332157", "user_id": "u202886318"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun solve (n m a)\n (let ((lcm (apply #'lcm\n (mapcar (lambda (a) (/ a 2))\n a))))\n (ceiling (floor m lcm) 2)))\n\n#-swank\n(let* ((n (read))\n (m (read))\n (a (loop repeat n collect (read))))\n (format t \"~A~%\" (solve n m a)))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nGiven are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.\n\nLet a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \\leq k \\leq N):\n\nThere exists a non-negative integer p such that X= a_k \\times (p+0.5).\n\nFind the number of semi-common multiples of A among the integers between 1 and M (inclusive).\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^9\n\n2 \\leq a_i \\leq 10^9\n\na_i is an even number.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 a_2 ... a_N\n\nOutput\n\nPrint the number of semi-common multiples of A among the integers between 1 and M (inclusive).\n\nSample Input 1\n\n2 50\n6 10\n\nSample Output 1\n\n2\n\n15 = 6 \\times 2.5\n\n15 = 10 \\times 1.5\n\n45 = 6 \\times 7.5\n\n45 = 10 \\times 4.5\n\nThus, 15 and 45 are semi-common multiples of A. There are no other semi-common multiples of A between 1 and 50, so the answer is 2.\n\nSample Input 2\n\n3 100\n14 22 40\n\nSample Output 2\n\n0\n\nThe answer can be 0.\n\nSample Input 3\n\n5 1000000000\n6 6 2 6 2\n\nSample Output 3\n\n166666667", "sample_input": "2 50\n6 10\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02814", "source_text": "Score : 400 points\n\nProblem Statement\n\nGiven are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.\n\nLet a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \\leq k \\leq N):\n\nThere exists a non-negative integer p such that X= a_k \\times (p+0.5).\n\nFind the number of semi-common multiples of A among the integers between 1 and M (inclusive).\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^9\n\n2 \\leq a_i \\leq 10^9\n\na_i is an even number.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 a_2 ... a_N\n\nOutput\n\nPrint the number of semi-common multiples of A among the integers between 1 and M (inclusive).\n\nSample Input 1\n\n2 50\n6 10\n\nSample Output 1\n\n2\n\n15 = 6 \\times 2.5\n\n15 = 10 \\times 1.5\n\n45 = 6 \\times 7.5\n\n45 = 10 \\times 4.5\n\nThus, 15 and 45 are semi-common multiples of A. There are no other semi-common multiples of A between 1 and 50, so the answer is 2.\n\nSample Input 2\n\n3 100\n14 22 40\n\nSample Output 2\n\n0\n\nThe answer can be 0.\n\nSample Input 3\n\n5 1000000000\n6 6 2 6 2\n\nSample Output 3\n\n166666667", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 285, "cpu_time_ms": 691, "memory_kb": 64744}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s812325219", "group_id": "codeNet:p02817", "input_text": "(map 'list #'(lambda (c) (unless (eq c #\\space) (princ c))) (read-line))", "language": "Lisp", "metadata": {"date": 1584572835, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02817.html", "problem_id": "p02817", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02817/input.txt", "sample_output_relpath": "derived/input_output/data/p02817/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02817/Lisp/s812325219.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s812325219", "user_id": "u334552723"}, "prompt_components": {"gold_output": "atcoder\n", "input_to_evaluate": "(map 'list #'(lambda (c) (unless (eq c #\\space) (princ c))) (read-line))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nGiven are two strings S and T consisting of lowercase English letters. Concatenate T and S in this order, without space in between, and print the resulting string.\n\nConstraints\n\nS and T are strings consisting of lowercase English letters.\n\nThe lengths of S and T are between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS T\n\nOutput\n\nPrint the resulting string.\n\nSample Input 1\n\noder atc\n\nSample Output 1\n\natcoder\n\nWhen S = oder and T = atc, concatenating T and S in this order results in atcoder.\n\nSample Input 2\n\nhumu humu\n\nSample Output 2\n\nhumuhumu", "sample_input": "oder atc\n"}, "reference_outputs": ["atcoder\n"], "source_document_id": "p02817", "source_text": "Score : 100 points\n\nProblem Statement\n\nGiven are two strings S and T consisting of lowercase English letters. Concatenate T and S in this order, without space in between, and print the resulting string.\n\nConstraints\n\nS and T are strings consisting of lowercase English letters.\n\nThe lengths of S and T are between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS T\n\nOutput\n\nPrint the resulting string.\n\nSample Input 1\n\noder atc\n\nSample Output 1\n\natcoder\n\nWhen S = oder and T = atc, concatenating T and S in this order results in atcoder.\n\nSample Input 2\n\nhumu humu\n\nSample Output 2\n\nhumuhumu", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 72, "cpu_time_ms": 9, "memory_kb": 3176}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s494592286", "group_id": "codeNet:p02819", "input_text": "(defun is-prime(x i)\n (if (= x 1)\n\tnil\n\t(if (= x 2)\n\t t\n\t (if (zerop (mod x i))\n\t\tnil\n\t\t(if (<= (* i i) x)\n\t\t (is-prime x (1+ i))\n\t\t t)))))\n\n(defun func(x)\n (if (is-prime x 2)\n\tx\n\t(func (1+ x))))\n\n(let ((x (read)))\n (princ (func x)))\n", "language": "Lisp", "metadata": {"date": 1577668276, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02819.html", "problem_id": "p02819", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02819/input.txt", "sample_output_relpath": "derived/input_output/data/p02819/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02819/Lisp/s494592286.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s494592286", "user_id": "u493610446"}, "prompt_components": {"gold_output": "23\n", "input_to_evaluate": "(defun is-prime(x i)\n (if (= x 1)\n\tnil\n\t(if (= x 2)\n\t t\n\t (if (zerop (mod x i))\n\t\tnil\n\t\t(if (<= (* i i) x)\n\t\t (is-prime x (1+ i))\n\t\t t)))))\n\n(defun func(x)\n (if (is-prime x 2)\n\tx\n\t(func (1+ x))))\n\n(let ((x (read)))\n (princ (func x)))\n", "problem_context": "Score: 300 points\n\nProblem Statement\n\nFind the minimum prime number greater than or equal to X.\n\nNotes\n\nA prime number is an integer greater than 1 that cannot be evenly divided by any positive integer except 1 and itself.\n\nFor example, 2, 3, and 5 are prime numbers, while 4 and 6 are not.\n\nConstraints\n\n2 \\le X \\le 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the minimum prime number greater than or equal to X.\n\nSample Input 1\n\n20\n\nSample Output 1\n\n23\n\nThe minimum prime number greater than or equal to 20 is 23.\n\nSample Input 2\n\n2\n\nSample Output 2\n\n2\n\nX itself can be a prime number.\n\nSample Input 3\n\n99992\n\nSample Output 3\n\n100003", "sample_input": "20\n"}, "reference_outputs": ["23\n"], "source_document_id": "p02819", "source_text": "Score: 300 points\n\nProblem Statement\n\nFind the minimum prime number greater than or equal to X.\n\nNotes\n\nA prime number is an integer greater than 1 that cannot be evenly divided by any positive integer except 1 and itself.\n\nFor example, 2, 3, and 5 are prime numbers, while 4 and 6 are not.\n\nConstraints\n\n2 \\le X \\le 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the minimum prime number greater than or equal to X.\n\nSample Input 1\n\n20\n\nSample Output 1\n\n23\n\nThe minimum prime number greater than or equal to 20 is 23.\n\nSample Input 2\n\n2\n\nSample Output 2\n\n2\n\nX itself can be a prime number.\n\nSample Input 3\n\n99992\n\nSample Output 3\n\n100003", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 241, "cpu_time_ms": 123, "memory_kb": 12896}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s143422381", "group_id": "codeNet:p02820", "input_text": "(let* ((n (read))\n (k (read))\n (r (read))\n (s (read))\n (p (read))\n (x (read-line))\n (y (make-array (list (1+ n)) :initial-element #\\x))\n (ans 0))\n (loop :for i :from 1 :to k\n :for h := (aref x (1- i))\n :do (cond ((char= h #\\r)\n (incf ans p)\n (setf (aref y i) #\\r))\n ((char= h #\\s)\n (incf ans r)\n (setf (aref y i) #\\s))\n ((char= h #\\p)\n (incf ans s)\n (setf (aref y i) #\\p))))\n (loop :for i :from (1+ k) :to n\n :for h := (aref x (1- i))\n :if (char/= (aref y (- i k)) h)\n :do (cond ((char= h #\\r)\n (incf ans p)\n (setf (aref y i) #\\r))\n ((char= h #\\s)\n (incf ans r)\n (setf (aref y i) #\\s))\n ((char= h #\\p)\n (incf ans s)\n (setf (aref y i) #\\p))))\n (format t \"~A~%\" ans))\n", "language": "Lisp", "metadata": {"date": 1594999896, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02820.html", "problem_id": "p02820", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02820/input.txt", "sample_output_relpath": "derived/input_output/data/p02820/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02820/Lisp/s143422381.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s143422381", "user_id": "u608227593"}, "prompt_components": {"gold_output": "27\n", "input_to_evaluate": "(let* ((n (read))\n (k (read))\n (r (read))\n (s (read))\n (p (read))\n (x (read-line))\n (y (make-array (list (1+ n)) :initial-element #\\x))\n (ans 0))\n (loop :for i :from 1 :to k\n :for h := (aref x (1- i))\n :do (cond ((char= h #\\r)\n (incf ans p)\n (setf (aref y i) #\\r))\n ((char= h #\\s)\n (incf ans r)\n (setf (aref y i) #\\s))\n ((char= h #\\p)\n (incf ans s)\n (setf (aref y i) #\\p))))\n (loop :for i :from (1+ k) :to n\n :for h := (aref x (1- i))\n :if (char/= (aref y (- i k)) h)\n :do (cond ((char= h #\\r)\n (incf ans p)\n (setf (aref y i) #\\r))\n ((char= h #\\s)\n (incf ans r)\n (setf (aref y i) #\\s))\n ((char= h #\\p)\n (incf ans s)\n (setf (aref y i) #\\p))))\n (format t \"~A~%\" ans))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nAt an arcade, Takahashi is playing a game called RPS Battle, which is played as follows:\n\nThe player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)\n\nEach time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):\n\nR points for winning with Rock;\n\nS points for winning with Scissors;\n\nP points for winning with Paper.\n\nHowever, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)\n\nBefore the start of the game, the machine decides the hand it will play in each round. With supernatural power, Takahashi managed to read all of those hands.\n\nThe information Takahashi obtained is given as a string T. If the i-th character of T (1 \\leq i \\leq N) is r, the machine will play Rock in the i-th round. Similarly, p and s stand for Paper and Scissors, respectively.\n\nWhat is the maximum total score earned in the game by adequately choosing the hand to play in each round?\n\nNotes\n\nIn this problem, Rock Paper Scissors can be thought of as a two-player game, in which each player simultaneously forms Rock, Paper, or Scissors with a hand.\n\nIf a player chooses Rock and the other chooses Scissors, the player choosing Rock wins;\n\nif a player chooses Scissors and the other chooses Paper, the player choosing Scissors wins;\n\nif a player chooses Paper and the other chooses Rock, the player choosing Paper wins;\n\nif both players play the same hand, it is a draw.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq K \\leq N-1\n\n1 \\leq R,S,P \\leq 10^4\n\nN,K,R,S, and P are all integers.\n\n|T| = N\n\nT consists of r, p, and s.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nR S P\nT\n\nOutput\n\nPrint the maximum total score earned in the game.\n\nSample Input 1\n\n5 2\n8 7 6\nrsrpr\n\nSample Output 1\n\n27\n\nThe machine will play {Rock, Scissors, Rock, Paper, Rock}.\n\nWe can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to earn 27 points.\nWe cannot earn more points, so the answer is 27.\n\nSample Input 2\n\n7 1\n100 10 1\nssssppr\n\nSample Output 2\n\n211\n\nSample Input 3\n\n30 5\n325 234 123\nrspsspspsrpspsppprpsprpssprpsr\n\nSample Output 3\n\n4996", "sample_input": "5 2\n8 7 6\nrsrpr\n"}, "reference_outputs": ["27\n"], "source_document_id": "p02820", "source_text": "Score : 400 points\n\nProblem Statement\n\nAt an arcade, Takahashi is playing a game called RPS Battle, which is played as follows:\n\nThe player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)\n\nEach time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):\n\nR points for winning with Rock;\n\nS points for winning with Scissors;\n\nP points for winning with Paper.\n\nHowever, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)\n\nBefore the start of the game, the machine decides the hand it will play in each round. With supernatural power, Takahashi managed to read all of those hands.\n\nThe information Takahashi obtained is given as a string T. If the i-th character of T (1 \\leq i \\leq N) is r, the machine will play Rock in the i-th round. Similarly, p and s stand for Paper and Scissors, respectively.\n\nWhat is the maximum total score earned in the game by adequately choosing the hand to play in each round?\n\nNotes\n\nIn this problem, Rock Paper Scissors can be thought of as a two-player game, in which each player simultaneously forms Rock, Paper, or Scissors with a hand.\n\nIf a player chooses Rock and the other chooses Scissors, the player choosing Rock wins;\n\nif a player chooses Scissors and the other chooses Paper, the player choosing Scissors wins;\n\nif a player chooses Paper and the other chooses Rock, the player choosing Paper wins;\n\nif both players play the same hand, it is a draw.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq K \\leq N-1\n\n1 \\leq R,S,P \\leq 10^4\n\nN,K,R,S, and P are all integers.\n\n|T| = N\n\nT consists of r, p, and s.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nR S P\nT\n\nOutput\n\nPrint the maximum total score earned in the game.\n\nSample Input 1\n\n5 2\n8 7 6\nrsrpr\n\nSample Output 1\n\n27\n\nThe machine will play {Rock, Scissors, Rock, Paper, Rock}.\n\nWe can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to earn 27 points.\nWe cannot earn more points, so the answer is 27.\n\nSample Input 2\n\n7 1\n100 10 1\nssssppr\n\nSample Output 2\n\n211\n\nSample Input 3\n\n30 5\n325 234 123\nrspsspspsrpspsppprpsprpssprpsr\n\nSample Output 3\n\n4996", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1030, "cpu_time_ms": 30, "memory_kb": 26656}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s953937047", "group_id": "codeNet:p02821", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of upper_bound of C++ or bisect_right of Python: Returns the smallest\nindex (or input) i that fulfills TARGET[i] > VALUE. In other words, this\nfunction returns the rightmost index at which VALUE can be inserted with keeping\nthe order. Therefore, TARGET must be monotonically non-decreasing with respect\nto ORDER.\n\nThis function returns END if VALUE >= TARGET[END-1]. Note that the range [START,\nEND) is half-open. END must be explicitly specified if TARGET is function. KEY\nis applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((body (accessor &optional declaration)\n `(progn\n (assert (<= start end))\n (if (= start end)\n end\n (labels\n ((%bisect-right (left ok)\n ;; TARGET[OK] > VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(list declaration)\n (let ((mid (ash (+ left ok) -1)))\n (if (= mid left)\n (if (funcall order value (funcall key (,accessor target left)))\n left\n ok)\n (if (funcall order value (funcall key (,accessor target mid)))\n (%bisect-right left mid)\n (%bisect-right mid ok))))))\n \n (%bisect-right start end))))))\n (etypecase target\n (vector\n (when (null end)\n (setf end (length target)))\n (body aref (declare ((integer 0 #.most-positive-fixnum) left ok))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (body funcall)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (m (read))\n (as (make-array n :element-type 'uint31)))\n (declare ((simple-array uint31 (*)) as))\n (dotimes (i n)\n (let ((a (read-fixnum)))\n (setf (aref as i) a)))\n (setq as (sort as #'>))\n (let ((cumuls (make-array (+ n 1) :element-type 'uint62)))\n (dotimes (i n)\n (setf (aref cumuls (+ i 1))\n (+ (aref as i) (aref cumuls i))))\n (labels ((%calc-sum (pivot threshold)\n (declare (uint62 pivot threshold))\n (let ((sup (bisect-right as\n (- threshold (aref as pivot))\n :order #'>)))\n (+ (the uint62 (* sup (aref as pivot)))\n (aref cumuls sup))))\n (calc-sum (threshold)\n (loop for i below n\n sum (%calc-sum i threshold) of-type uint62))\n (%calc-count (pivot threshold)\n (declare (uint62 pivot threshold))\n (let ((sup (bisect-right as\n (- threshold (aref as pivot))\n :order #'>)))\n sup))\n (calc-count (threshold)\n (loop for i below n\n sum (%calc-count i threshold) of-type uint62)))\n (sb-int:named-let bisect ((ok -1) (ng 10000000))\n (declare (int32 ng ok))\n (if (<= (- ng ok) 1)\n (let ((actual-count (calc-count ok))\n (sum (calc-sum ok)))\n (assert (>= actual-count m))\n (println\n (- sum (* (- actual-count m) ok))))\n (let ((mid (ash (+ ng ok) -1)))\n (if (>= (calc-count mid) m)\n (bisect mid ng)\n (bisect ok mid)))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 3\n10 14 19 34 33\n\"\n \"202\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9 14\n1 3 5 110 24 21 34 5 3\n\"\n \"1837\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9 73\n67597 52981 5828 66249 75177 64141 40773 79105 16076\n\"\n \"8128170\n\")))\n", "language": "Lisp", "metadata": {"date": 1577677364, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02821.html", "problem_id": "p02821", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02821/input.txt", "sample_output_relpath": "derived/input_output/data/p02821/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02821/Lisp/s953937047.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s953937047", "user_id": "u352600849"}, "prompt_components": {"gold_output": "202\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of upper_bound of C++ or bisect_right of Python: Returns the smallest\nindex (or input) i that fulfills TARGET[i] > VALUE. In other words, this\nfunction returns the rightmost index at which VALUE can be inserted with keeping\nthe order. Therefore, TARGET must be monotonically non-decreasing with respect\nto ORDER.\n\nThis function returns END if VALUE >= TARGET[END-1]. Note that the range [START,\nEND) is half-open. END must be explicitly specified if TARGET is function. KEY\nis applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((body (accessor &optional declaration)\n `(progn\n (assert (<= start end))\n (if (= start end)\n end\n (labels\n ((%bisect-right (left ok)\n ;; TARGET[OK] > VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(list declaration)\n (let ((mid (ash (+ left ok) -1)))\n (if (= mid left)\n (if (funcall order value (funcall key (,accessor target left)))\n left\n ok)\n (if (funcall order value (funcall key (,accessor target mid)))\n (%bisect-right left mid)\n (%bisect-right mid ok))))))\n \n (%bisect-right start end))))))\n (etypecase target\n (vector\n (when (null end)\n (setf end (length target)))\n (body aref (declare ((integer 0 #.most-positive-fixnum) left ok))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (body funcall)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (m (read))\n (as (make-array n :element-type 'uint31)))\n (declare ((simple-array uint31 (*)) as))\n (dotimes (i n)\n (let ((a (read-fixnum)))\n (setf (aref as i) a)))\n (setq as (sort as #'>))\n (let ((cumuls (make-array (+ n 1) :element-type 'uint62)))\n (dotimes (i n)\n (setf (aref cumuls (+ i 1))\n (+ (aref as i) (aref cumuls i))))\n (labels ((%calc-sum (pivot threshold)\n (declare (uint62 pivot threshold))\n (let ((sup (bisect-right as\n (- threshold (aref as pivot))\n :order #'>)))\n (+ (the uint62 (* sup (aref as pivot)))\n (aref cumuls sup))))\n (calc-sum (threshold)\n (loop for i below n\n sum (%calc-sum i threshold) of-type uint62))\n (%calc-count (pivot threshold)\n (declare (uint62 pivot threshold))\n (let ((sup (bisect-right as\n (- threshold (aref as pivot))\n :order #'>)))\n sup))\n (calc-count (threshold)\n (loop for i below n\n sum (%calc-count i threshold) of-type uint62)))\n (sb-int:named-let bisect ((ok -1) (ng 10000000))\n (declare (int32 ng ok))\n (if (<= (- ng ok) 1)\n (let ((actual-count (calc-count ok))\n (sum (calc-sum ok)))\n (assert (>= actual-count m))\n (println\n (- sum (* (- actual-count m) ok))))\n (let ((mid (ash (+ ng ok) -1)))\n (if (>= (calc-count mid) m)\n (bisect mid ng)\n (bisect ok mid)))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 3\n10 14 19 34 33\n\"\n \"202\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9 14\n1 3 5 110 24 21 34 5 3\n\"\n \"1837\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9 73\n67597 52981 5828 66249 75177 64141 40773 79105 16076\n\"\n \"8128170\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nTakahashi has come to a party as a special guest.\nThere are N ordinary guests at the party. The i-th ordinary guest has a power of A_i.\n\nTakahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0).\nA handshake will be performed as follows:\n\nTakahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same).\n\nThen, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y.\n\nHowever, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold:\n\nAssume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \\leq p < q \\leq M) such that (x_p,y_p)=(x_q,y_q).\n\nWhat is the maximum possible happiness after M handshakes?\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq N^2\n\n1 \\leq A_i \\leq 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible happiness after M handshakes.\n\nSample Input 1\n\n5 3\n10 14 19 34 33\n\nSample Output 1\n\n202\n\nLet us say that Takahashi performs the following handshakes:\n\nIn the first handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 4.\n\nIn the second handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 5.\n\nIn the third handshake, Takahashi shakes the left hand of Guest 5 and the right hand of Guest 4.\n\nThen, we will have the happiness of (34+34)+(34+33)+(33+34)=202.\n\nWe cannot achieve the happiness of 203 or greater, so the answer is 202.\n\nSample Input 2\n\n9 14\n1 3 5 110 24 21 34 5 3\n\nSample Output 2\n\n1837\n\nSample Input 3\n\n9 73\n67597 52981 5828 66249 75177 64141 40773 79105 16076\n\nSample Output 3\n\n8128170", "sample_input": "5 3\n10 14 19 34 33\n"}, "reference_outputs": ["202\n"], "source_document_id": "p02821", "source_text": "Score : 500 points\n\nProblem Statement\n\nTakahashi has come to a party as a special guest.\nThere are N ordinary guests at the party. The i-th ordinary guest has a power of A_i.\n\nTakahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0).\nA handshake will be performed as follows:\n\nTakahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same).\n\nThen, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y.\n\nHowever, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold:\n\nAssume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \\leq p < q \\leq M) such that (x_p,y_p)=(x_q,y_q).\n\nWhat is the maximum possible happiness after M handshakes?\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq N^2\n\n1 \\leq A_i \\leq 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible happiness after M handshakes.\n\nSample Input 1\n\n5 3\n10 14 19 34 33\n\nSample Output 1\n\n202\n\nLet us say that Takahashi performs the following handshakes:\n\nIn the first handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 4.\n\nIn the second handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 5.\n\nIn the third handshake, Takahashi shakes the left hand of Guest 5 and the right hand of Guest 4.\n\nThen, we will have the happiness of (34+34)+(34+33)+(33+34)=202.\n\nWe cannot achieve the happiness of 203 or greater, so the answer is 202.\n\nSample Input 2\n\n9 14\n1 3 5 110 24 21 34 5 3\n\nSample Output 2\n\n1837\n\nSample Input 3\n\n9 73\n67597 52981 5828 66249 75177 64141 40773 79105 16076\n\nSample Output 3\n\n8128170", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8992, "cpu_time_ms": 326, "memory_kb": 39652}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s736976460", "group_id": "codeNet:p02821", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ()))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 3\n10 14 19 34 33\n\"\n \"202\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9 14\n1 3 5 110 24 21 34 5 3\n\"\n \"1837\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9 73\n67597 52981 5828 66249 75177 64141 40773 79105 16076\n\"\n \"8128170\n\")))\n", "language": "Lisp", "metadata": {"date": 1577670412, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02821.html", "problem_id": "p02821", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02821/input.txt", "sample_output_relpath": "derived/input_output/data/p02821/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02821/Lisp/s736976460.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s736976460", "user_id": "u352600849"}, "prompt_components": {"gold_output": "202\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ()))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 3\n10 14 19 34 33\n\"\n \"202\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9 14\n1 3 5 110 24 21 34 5 3\n\"\n \"1837\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9 73\n67597 52981 5828 66249 75177 64141 40773 79105 16076\n\"\n \"8128170\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nTakahashi has come to a party as a special guest.\nThere are N ordinary guests at the party. The i-th ordinary guest has a power of A_i.\n\nTakahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0).\nA handshake will be performed as follows:\n\nTakahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same).\n\nThen, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y.\n\nHowever, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold:\n\nAssume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \\leq p < q \\leq M) such that (x_p,y_p)=(x_q,y_q).\n\nWhat is the maximum possible happiness after M handshakes?\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq N^2\n\n1 \\leq A_i \\leq 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible happiness after M handshakes.\n\nSample Input 1\n\n5 3\n10 14 19 34 33\n\nSample Output 1\n\n202\n\nLet us say that Takahashi performs the following handshakes:\n\nIn the first handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 4.\n\nIn the second handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 5.\n\nIn the third handshake, Takahashi shakes the left hand of Guest 5 and the right hand of Guest 4.\n\nThen, we will have the happiness of (34+34)+(34+33)+(33+34)=202.\n\nWe cannot achieve the happiness of 203 or greater, so the answer is 202.\n\nSample Input 2\n\n9 14\n1 3 5 110 24 21 34 5 3\n\nSample Output 2\n\n1837\n\nSample Input 3\n\n9 73\n67597 52981 5828 66249 75177 64141 40773 79105 16076\n\nSample Output 3\n\n8128170", "sample_input": "5 3\n10 14 19 34 33\n"}, "reference_outputs": ["202\n"], "source_document_id": "p02821", "source_text": "Score : 500 points\n\nProblem Statement\n\nTakahashi has come to a party as a special guest.\nThere are N ordinary guests at the party. The i-th ordinary guest has a power of A_i.\n\nTakahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0).\nA handshake will be performed as follows:\n\nTakahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same).\n\nThen, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y.\n\nHowever, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold:\n\nAssume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \\leq p < q \\leq M) such that (x_p,y_p)=(x_q,y_q).\n\nWhat is the maximum possible happiness after M handshakes?\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq N^2\n\n1 \\leq A_i \\leq 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible happiness after M handshakes.\n\nSample Input 1\n\n5 3\n10 14 19 34 33\n\nSample Output 1\n\n202\n\nLet us say that Takahashi performs the following handshakes:\n\nIn the first handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 4.\n\nIn the second handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 5.\n\nIn the third handshake, Takahashi shakes the left hand of Guest 5 and the right hand of Guest 4.\n\nThen, we will have the happiness of (34+34)+(34+33)+(33+34)=202.\n\nWe cannot achieve the happiness of 203 or greater, so the answer is 202.\n\nSample Input 2\n\n9 14\n1 3 5 110 24 21 34 5 3\n\nSample Output 2\n\n1837\n\nSample Input 3\n\n9 73\n67597 52981 5828 66249 75177 64141 40773 79105 16076\n\nSample Output 3\n\n8128170", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3851, "cpu_time_ms": 109, "memory_kb": 13796}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s165156104", "group_id": "codeNet:p02822", "input_text": ";; F - Surrounded Nodes\n\n(defparameter *modulus* (+ (expt 10 9) 7))\n\n(defun main ()\n (let* ((N (read)) ; 頂点数\n (tree (read-tree N)))\n (princ (solve N tree))\n (fresh-line)))\n\n; (a) 自分が白 かつ (b) 隣接する部分グラフの2つ以上に黒が含まれる\n; ならば, 自分はSに含まれる白頂点.\n; 塗り分け方すべて: 2^N\n; 自分が白: 2^(N - 1)\n; (b) == not ((b1) or (b2))\n; (b1) 隣接する部分グラフがすべて白: 1\n; (b2) 隣接する部分グラフのちょうど一つGに黒が含まれる: 2^size(G) - 1\n; 自分がSに含まれる白頂点である確率:\n; (2^(N - 1) - 1 - sum_G (2^size(G) - 1))/2^N\n; 全頂点の合計:\n; (N * 2^(N - 1) - N - (sum_G 2^size(G)) + 2 * (N - 1))/2^N\n\n(defun solve (N tree)\n (destructuring-bind\n ; 各頂点の親と各部分木の頂点数\n (parent subtree-size) (make-rooted-tree 0 tree)\n (let* ((subgraph-size ; 部分グラフの頂点数のリスト\n (loop for v below N append ; 各頂点\n (loop for next in (aref tree v) collect ; vの隣接頂点\n ; nextの向こう側の部分グラフの頂点数\n (if (eql next (aref parent v)) ; vの親?\n (- N (aref subtree-size v))\n (aref subtree-size next)))))\n (numerator (- (* N (1+ (ash 1 (1- N))))\n (reduce #'+\n (mapcar #'mod-expt-2\n (normalize-exponents subgraph-size)))\n 2)))\n ; (2^N) * z == numerator mod *modulus* であるz\n ; *modulus*が素数なので 2^(*modulus* - 1) == 1 mod *modulus*\n (mod (* (mod numerator *modulus*) (mod-expt-2 (- *modulus* 1 N)))\n *modulus*))))\n\n; 2, 2^100, 2^10000, 2^1000000 (mod *modulus*) のリスト\n(defparameter *expt-2*\n (loop for n = 1 then (* n 100) while (< n *modulus*)\n collect (mod (ash 1 n) *modulus*)))\n\n(defun mod-expt-2 (i)\n \"(mod (expt 2 i) *modulus*)を少し速く計算\"\n (mod (reduce #'*\n (loop for n = 1 then (* n 100)\n for x = i then (floor x 100) while (plusp x)\n for e in *expt-2*\n collect (expt e (mod x 100))))\n *modulus*))\n\n(defun normalize-exponents (lst)\n \"2の指数のリストを正規化\"\n (setf lst (sort lst #'<))\n (labels ((normalizer (head n lst result)\n (cond ((and lst (eql (car lst) head))\n (normalizer head (1+ n) (cdr lst) result))\n ((>= n 2)\n (normalizer (1+ head) (ash n -1) lst\n (if (oddp n) (cons head result) result)))\n (lst\n (normalizer (car lst) 1 (cdr lst) (cons head result)))\n (t (cons head result)))))\n (normalizer (car lst) 1 (cdr lst) ())))\n\n(defun make-rooted-tree (root tree)\n \"頂点rootを根としてtreeの各頂点の親を決める. 部分木の大きさも計算する.\"\n (let* ((N (array-dimension tree 0)) ; 頂点数\n (parent (make-array N :initial-element nil)) ; 親\n (subtree-size (make-array N :initial-element nil))) ; 部分木の頂点数\n (labels\n ((dfs (stack)\n (when stack\n (let ((v (pop stack)))\n (if (aref subtree-size v)\n ; 帰りがけ\n (loop for next in (aref tree v) ; vの隣接頂点\n unless (eql next (aref parent v)) ; 親以外\n do (incf (aref subtree-size v)\n (aref subtree-size next)))\n ; 行きがけ\n (loop\n initially (push v stack) ; 帰りがけ用に残す\n (setf (aref subtree-size v) 1)\n for next in (aref tree v) ; vの隣接頂点\n unless (eql next (aref parent v)) ; 親以外\n do (push next stack)\n (setf (aref parent next) v))))\n (dfs stack))))\n (dfs (list root))\n (list parent subtree-size))))\n\n(defun read-tree (N)\n \"N頂点の木をreadして作る. 頂点番号は0〜N-1\"\n (let ((tree (make-array N))) ; 隣接リスト\n (loop for i below N do (setf (aref tree i) nil))\n (loop repeat (1- N)\n do (let ((a (read-fixnum))\n (b (read-fixnum)))\n (push (1- b) (aref tree (1- a)))\n (push (1- a) (aref tree (1- b)))))\n tree))\n\n(defun read-fixnum (&optional (in *standard-input*))\n \"readより速い整数専用read. \n 参考: 競技プログラミングでCommon Lispを使っている人と\n これから使うかもしれない人のために, @sansaqua\n https://qiita.com/sansaqua/items/0b6417cb541047e29da4\"\n (loop with acc = 0\n with minus = nil\n with started = nil\n for byte = (read-byte in)\n if (<= 48 byte 57)\n do (setf acc (+ (* acc 10) (- byte 48)))\n (setf started t)\n else if started\n return (if minus (- acc) acc)\n else if (= byte 45)\n do (setf minus t)))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1577897526, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02822.html", "problem_id": "p02822", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02822/input.txt", "sample_output_relpath": "derived/input_output/data/p02822/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02822/Lisp/s165156104.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s165156104", "user_id": "u227020436"}, "prompt_components": {"gold_output": "125000001\n", "input_to_evaluate": ";; F - Surrounded Nodes\n\n(defparameter *modulus* (+ (expt 10 9) 7))\n\n(defun main ()\n (let* ((N (read)) ; 頂点数\n (tree (read-tree N)))\n (princ (solve N tree))\n (fresh-line)))\n\n; (a) 自分が白 かつ (b) 隣接する部分グラフの2つ以上に黒が含まれる\n; ならば, 自分はSに含まれる白頂点.\n; 塗り分け方すべて: 2^N\n; 自分が白: 2^(N - 1)\n; (b) == not ((b1) or (b2))\n; (b1) 隣接する部分グラフがすべて白: 1\n; (b2) 隣接する部分グラフのちょうど一つGに黒が含まれる: 2^size(G) - 1\n; 自分がSに含まれる白頂点である確率:\n; (2^(N - 1) - 1 - sum_G (2^size(G) - 1))/2^N\n; 全頂点の合計:\n; (N * 2^(N - 1) - N - (sum_G 2^size(G)) + 2 * (N - 1))/2^N\n\n(defun solve (N tree)\n (destructuring-bind\n ; 各頂点の親と各部分木の頂点数\n (parent subtree-size) (make-rooted-tree 0 tree)\n (let* ((subgraph-size ; 部分グラフの頂点数のリスト\n (loop for v below N append ; 各頂点\n (loop for next in (aref tree v) collect ; vの隣接頂点\n ; nextの向こう側の部分グラフの頂点数\n (if (eql next (aref parent v)) ; vの親?\n (- N (aref subtree-size v))\n (aref subtree-size next)))))\n (numerator (- (* N (1+ (ash 1 (1- N))))\n (reduce #'+\n (mapcar #'mod-expt-2\n (normalize-exponents subgraph-size)))\n 2)))\n ; (2^N) * z == numerator mod *modulus* であるz\n ; *modulus*が素数なので 2^(*modulus* - 1) == 1 mod *modulus*\n (mod (* (mod numerator *modulus*) (mod-expt-2 (- *modulus* 1 N)))\n *modulus*))))\n\n; 2, 2^100, 2^10000, 2^1000000 (mod *modulus*) のリスト\n(defparameter *expt-2*\n (loop for n = 1 then (* n 100) while (< n *modulus*)\n collect (mod (ash 1 n) *modulus*)))\n\n(defun mod-expt-2 (i)\n \"(mod (expt 2 i) *modulus*)を少し速く計算\"\n (mod (reduce #'*\n (loop for n = 1 then (* n 100)\n for x = i then (floor x 100) while (plusp x)\n for e in *expt-2*\n collect (expt e (mod x 100))))\n *modulus*))\n\n(defun normalize-exponents (lst)\n \"2の指数のリストを正規化\"\n (setf lst (sort lst #'<))\n (labels ((normalizer (head n lst result)\n (cond ((and lst (eql (car lst) head))\n (normalizer head (1+ n) (cdr lst) result))\n ((>= n 2)\n (normalizer (1+ head) (ash n -1) lst\n (if (oddp n) (cons head result) result)))\n (lst\n (normalizer (car lst) 1 (cdr lst) (cons head result)))\n (t (cons head result)))))\n (normalizer (car lst) 1 (cdr lst) ())))\n\n(defun make-rooted-tree (root tree)\n \"頂点rootを根としてtreeの各頂点の親を決める. 部分木の大きさも計算する.\"\n (let* ((N (array-dimension tree 0)) ; 頂点数\n (parent (make-array N :initial-element nil)) ; 親\n (subtree-size (make-array N :initial-element nil))) ; 部分木の頂点数\n (labels\n ((dfs (stack)\n (when stack\n (let ((v (pop stack)))\n (if (aref subtree-size v)\n ; 帰りがけ\n (loop for next in (aref tree v) ; vの隣接頂点\n unless (eql next (aref parent v)) ; 親以外\n do (incf (aref subtree-size v)\n (aref subtree-size next)))\n ; 行きがけ\n (loop\n initially (push v stack) ; 帰りがけ用に残す\n (setf (aref subtree-size v) 1)\n for next in (aref tree v) ; vの隣接頂点\n unless (eql next (aref parent v)) ; 親以外\n do (push next stack)\n (setf (aref parent next) v))))\n (dfs stack))))\n (dfs (list root))\n (list parent subtree-size))))\n\n(defun read-tree (N)\n \"N頂点の木をreadして作る. 頂点番号は0〜N-1\"\n (let ((tree (make-array N))) ; 隣接リスト\n (loop for i below N do (setf (aref tree i) nil))\n (loop repeat (1- N)\n do (let ((a (read-fixnum))\n (b (read-fixnum)))\n (push (1- b) (aref tree (1- a)))\n (push (1- a) (aref tree (1- b)))))\n tree))\n\n(defun read-fixnum (&optional (in *standard-input*))\n \"readより速い整数専用read. \n 参考: 競技プログラミングでCommon Lispを使っている人と\n これから使うかもしれない人のために, @sansaqua\n https://qiita.com/sansaqua/items/0b6417cb541047e29da4\"\n (loop with acc = 0\n with minus = nil\n with started = nil\n for byte = (read-byte in)\n if (<= 48 byte 57)\n do (setf acc (+ (* acc 10) (- byte 48)))\n (setf started t)\n else if started\n return (if minus (- acc) acc)\n else if (= byte 45)\n do (setf minus t)))\n\n(main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \\leq A_i,B_i \\leq N).\n\nNow, each vertex is painted black with probability 1/2 and white with probability 1/2, which is chosen independently from other vertices. Then, let S be the smallest subtree (connected subgraph) of T containing all the vertices painted black. (If no vertex is painted black, S is the empty graph.)\n\nLet the holeyness of S be the number of white vertices contained in S. Find the expected holeyness of S.\n\nSince the answer is a rational number, we ask you to print it \\bmod 10^9+7, as described in Notes.\n\nNotes\n\nWhen you print a rational number, first write it as a fraction \\frac{y}{x}, where x, y are integers, and x is not divisible by 10^9 + 7\n(under the constraints of the problem, such representation is always possible).\n\nThen, you need to print the only integer z between 0 and 10^9 + 6, inclusive, that satisfies xz \\equiv y \\pmod{10^9 + 7}.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i,B_i \\leq N\n\nThe given graph is a tree.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 B_1\n:\nA_{N-1} B_{N-1}\n\nOutput\n\nPrint the expected holeyness of S, \\bmod 10^9+7.\n\nSample Input 1\n\n3\n1 2\n2 3\n\nSample Output 1\n\n125000001\n\nIf the vertices 1, 2, 3 are painted black, white, black, respectively, the holeyness of S is 1.\n\nOtherwise, the holeyness is 0, so the expected holeyness is 1/8.\n\nSince 8 \\times 125000001 \\equiv 1 \\pmod{10^9+7}, we should print 125000001.\n\nSample Input 2\n\n4\n1 2\n2 3\n3 4\n\nSample Output 2\n\n375000003\n\nThe expected holeyness is 3/8.\n\nSince 8 \\times 375000003 \\equiv 3 \\pmod{10^9+7}, we should print 375000003.\n\nSample Input 3\n\n4\n1 2\n1 3\n1 4\n\nSample Output 3\n\n250000002\n\nThe expected holeyness is 1/4.\n\nSample Input 4\n\n7\n4 7\n3 1\n2 6\n5 2\n7 1\n2 7\n\nSample Output 4\n\n570312505", "sample_input": "3\n1 2\n2 3\n"}, "reference_outputs": ["125000001\n"], "source_document_id": "p02822", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \\leq A_i,B_i \\leq N).\n\nNow, each vertex is painted black with probability 1/2 and white with probability 1/2, which is chosen independently from other vertices. Then, let S be the smallest subtree (connected subgraph) of T containing all the vertices painted black. (If no vertex is painted black, S is the empty graph.)\n\nLet the holeyness of S be the number of white vertices contained in S. Find the expected holeyness of S.\n\nSince the answer is a rational number, we ask you to print it \\bmod 10^9+7, as described in Notes.\n\nNotes\n\nWhen you print a rational number, first write it as a fraction \\frac{y}{x}, where x, y are integers, and x is not divisible by 10^9 + 7\n(under the constraints of the problem, such representation is always possible).\n\nThen, you need to print the only integer z between 0 and 10^9 + 6, inclusive, that satisfies xz \\equiv y \\pmod{10^9 + 7}.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i,B_i \\leq N\n\nThe given graph is a tree.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 B_1\n:\nA_{N-1} B_{N-1}\n\nOutput\n\nPrint the expected holeyness of S, \\bmod 10^9+7.\n\nSample Input 1\n\n3\n1 2\n2 3\n\nSample Output 1\n\n125000001\n\nIf the vertices 1, 2, 3 are painted black, white, black, respectively, the holeyness of S is 1.\n\nOtherwise, the holeyness is 0, so the expected holeyness is 1/8.\n\nSince 8 \\times 125000001 \\equiv 1 \\pmod{10^9+7}, we should print 125000001.\n\nSample Input 2\n\n4\n1 2\n2 3\n3 4\n\nSample Output 2\n\n375000003\n\nThe expected holeyness is 3/8.\n\nSince 8 \\times 375000003 \\equiv 3 \\pmod{10^9+7}, we should print 375000003.\n\nSample Input 3\n\n4\n1 2\n1 3\n1 4\n\nSample Output 3\n\n250000002\n\nThe expected holeyness is 1/4.\n\nSample Input 4\n\n7\n4 7\n3 1\n2 6\n5 2\n7 1\n2 7\n\nSample Output 4\n\n570312505", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5060, "cpu_time_ms": 1213, "memory_kb": 88548}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s839233360", "group_id": "codeNet:p02822", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ()))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2\n2 3\n\"\n \"125000001\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 2\n2 3\n3 4\n\"\n \"375000003\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 2\n1 3\n1 4\n\"\n \"250000002\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\n4 7\n3 1\n2 6\n5 2\n7 1\n2 7\n\"\n \"570312505\n\")))\n", "language": "Lisp", "metadata": {"date": 1577677126, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02822.html", "problem_id": "p02822", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02822/input.txt", "sample_output_relpath": "derived/input_output/data/p02822/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02822/Lisp/s839233360.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s839233360", "user_id": "u352600849"}, "prompt_components": {"gold_output": "125000001\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ()))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2\n2 3\n\"\n \"125000001\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 2\n2 3\n3 4\n\"\n \"375000003\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 2\n1 3\n1 4\n\"\n \"250000002\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\n4 7\n3 1\n2 6\n5 2\n7 1\n2 7\n\"\n \"570312505\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \\leq A_i,B_i \\leq N).\n\nNow, each vertex is painted black with probability 1/2 and white with probability 1/2, which is chosen independently from other vertices. Then, let S be the smallest subtree (connected subgraph) of T containing all the vertices painted black. (If no vertex is painted black, S is the empty graph.)\n\nLet the holeyness of S be the number of white vertices contained in S. Find the expected holeyness of S.\n\nSince the answer is a rational number, we ask you to print it \\bmod 10^9+7, as described in Notes.\n\nNotes\n\nWhen you print a rational number, first write it as a fraction \\frac{y}{x}, where x, y are integers, and x is not divisible by 10^9 + 7\n(under the constraints of the problem, such representation is always possible).\n\nThen, you need to print the only integer z between 0 and 10^9 + 6, inclusive, that satisfies xz \\equiv y \\pmod{10^9 + 7}.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i,B_i \\leq N\n\nThe given graph is a tree.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 B_1\n:\nA_{N-1} B_{N-1}\n\nOutput\n\nPrint the expected holeyness of S, \\bmod 10^9+7.\n\nSample Input 1\n\n3\n1 2\n2 3\n\nSample Output 1\n\n125000001\n\nIf the vertices 1, 2, 3 are painted black, white, black, respectively, the holeyness of S is 1.\n\nOtherwise, the holeyness is 0, so the expected holeyness is 1/8.\n\nSince 8 \\times 125000001 \\equiv 1 \\pmod{10^9+7}, we should print 125000001.\n\nSample Input 2\n\n4\n1 2\n2 3\n3 4\n\nSample Output 2\n\n375000003\n\nThe expected holeyness is 3/8.\n\nSince 8 \\times 375000003 \\equiv 3 \\pmod{10^9+7}, we should print 375000003.\n\nSample Input 3\n\n4\n1 2\n1 3\n1 4\n\nSample Output 3\n\n250000002\n\nThe expected holeyness is 1/4.\n\nSample Input 4\n\n7\n4 7\n3 1\n2 6\n5 2\n7 1\n2 7\n\nSample Output 4\n\n570312505", "sample_input": "3\n1 2\n2 3\n"}, "reference_outputs": ["125000001\n"], "source_document_id": "p02822", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \\leq A_i,B_i \\leq N).\n\nNow, each vertex is painted black with probability 1/2 and white with probability 1/2, which is chosen independently from other vertices. Then, let S be the smallest subtree (connected subgraph) of T containing all the vertices painted black. (If no vertex is painted black, S is the empty graph.)\n\nLet the holeyness of S be the number of white vertices contained in S. Find the expected holeyness of S.\n\nSince the answer is a rational number, we ask you to print it \\bmod 10^9+7, as described in Notes.\n\nNotes\n\nWhen you print a rational number, first write it as a fraction \\frac{y}{x}, where x, y are integers, and x is not divisible by 10^9 + 7\n(under the constraints of the problem, such representation is always possible).\n\nThen, you need to print the only integer z between 0 and 10^9 + 6, inclusive, that satisfies xz \\equiv y \\pmod{10^9 + 7}.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i,B_i \\leq N\n\nThe given graph is a tree.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 B_1\n:\nA_{N-1} B_{N-1}\n\nOutput\n\nPrint the expected holeyness of S, \\bmod 10^9+7.\n\nSample Input 1\n\n3\n1 2\n2 3\n\nSample Output 1\n\n125000001\n\nIf the vertices 1, 2, 3 are painted black, white, black, respectively, the holeyness of S is 1.\n\nOtherwise, the holeyness is 0, so the expected holeyness is 1/8.\n\nSince 8 \\times 125000001 \\equiv 1 \\pmod{10^9+7}, we should print 125000001.\n\nSample Input 2\n\n4\n1 2\n2 3\n3 4\n\nSample Output 2\n\n375000003\n\nThe expected holeyness is 3/8.\n\nSince 8 \\times 375000003 \\equiv 3 \\pmod{10^9+7}, we should print 375000003.\n\nSample Input 3\n\n4\n1 2\n1 3\n1 4\n\nSample Output 3\n\n250000002\n\nThe expected holeyness is 1/4.\n\nSample Input 4\n\n7\n4 7\n3 1\n2 6\n5 2\n7 1\n2 7\n\nSample Output 4\n\n570312505", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3897, "cpu_time_ms": 105, "memory_kb": 13924}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s666428386", "group_id": "codeNet:p02823", "input_text": "(defun table-tennis-training ()\n (let ((n (read))\n (a (read))\n (b (read))\n (ans 0))\n (if (evenp (- b a))\n (setf ans (/ (- b a) 2))\n (if (< (- a 1) (- n b))\n (setf ans (- b 1))\n (setf ans (- n a))))\n ans))\n\n(format t \"~d~%\" (table-tennis-training))\n", "language": "Lisp", "metadata": {"date": 1584802128, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02823.html", "problem_id": "p02823", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02823/input.txt", "sample_output_relpath": "derived/input_output/data/p02823/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02823/Lisp/s666428386.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s666428386", "user_id": "u091381267"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun table-tennis-training ()\n (let ((n (read))\n (a (read))\n (b (read))\n (ans 0))\n (if (evenp (- b a))\n (setf ans (/ (- b a) 2))\n (if (< (- a 1) (- n b))\n (setf ans (- b 1))\n (setf ans (- n a))))\n ans))\n\n(format t \"~d~%\" (table-tennis-training))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\n2N players are running a competitive table tennis training on N tables numbered from 1 to N.\n\nThe training consists of rounds.\nIn each round, the players form N pairs, one pair per table.\nIn each pair, competitors play a match against each other.\nAs a result, one of them wins and the other one loses.\n\nThe winner of the match on table X plays on table X-1 in the next round,\nexcept for the winner of the match on table 1 who stays at table 1.\n\nSimilarly, the loser of the match on table X plays on table X+1 in the next round,\nexcept for the loser of the match on table N who stays at table N.\n\nTwo friends are playing their first round matches on distinct tables A and B.\nLet's assume that the friends are strong enough to win or lose any match at will.\nWhat is the smallest number of rounds after which the friends can get to play a match against each other?\n\nConstraints\n\n2 \\leq N \\leq 10^{18}\n\n1 \\leq A < B \\leq N\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint the smallest number of rounds after which the friends can get to play a match against each other.\n\nSample Input 1\n\n5 2 4\n\nSample Output 1\n\n1\n\nIf the first friend loses their match and the second friend wins their match, they will both move to table 3 and play each other in the next round.\n\nSample Input 2\n\n5 2 3\n\nSample Output 2\n\n2\n\nIf both friends win two matches in a row, they will both move to table 1.", "sample_input": "5 2 4\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02823", "source_text": "Score : 300 points\n\nProblem Statement\n\n2N players are running a competitive table tennis training on N tables numbered from 1 to N.\n\nThe training consists of rounds.\nIn each round, the players form N pairs, one pair per table.\nIn each pair, competitors play a match against each other.\nAs a result, one of them wins and the other one loses.\n\nThe winner of the match on table X plays on table X-1 in the next round,\nexcept for the winner of the match on table 1 who stays at table 1.\n\nSimilarly, the loser of the match on table X plays on table X+1 in the next round,\nexcept for the loser of the match on table N who stays at table N.\n\nTwo friends are playing their first round matches on distinct tables A and B.\nLet's assume that the friends are strong enough to win or lose any match at will.\nWhat is the smallest number of rounds after which the friends can get to play a match against each other?\n\nConstraints\n\n2 \\leq N \\leq 10^{18}\n\n1 \\leq A < B \\leq N\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint the smallest number of rounds after which the friends can get to play a match against each other.\n\nSample Input 1\n\n5 2 4\n\nSample Output 1\n\n1\n\nIf the first friend loses their match and the second friend wins their match, they will both move to table 3 and play each other in the next round.\n\nSample Input 2\n\n5 2 3\n\nSample Output 2\n\n2\n\nIf both friends win two matches in a row, they will both move to table 1.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 312, "cpu_time_ms": 20, "memory_kb": 3940}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s549446343", "group_id": "codeNet:p02823", "input_text": "(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defparameter lst (mapcar #'parse-integer (split \" \" (read-line))))\n(defparameter N (car lst))\n(defparameter A (cadr lst))\n(defparameter B (caddr lst))\n\n\n(if (oddp (- A B))\n (format t \"~A\" (min (1- (max A B)) (- N (min A B))))\n (format t \"~A\" (floor (abs (/ (- A B) 2)))))", "language": "Lisp", "metadata": {"date": 1577599678, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02823.html", "problem_id": "p02823", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02823/input.txt", "sample_output_relpath": "derived/input_output/data/p02823/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02823/Lisp/s549446343.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s549446343", "user_id": "u425317134"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defparameter lst (mapcar #'parse-integer (split \" \" (read-line))))\n(defparameter N (car lst))\n(defparameter A (cadr lst))\n(defparameter B (caddr lst))\n\n\n(if (oddp (- A B))\n (format t \"~A\" (min (1- (max A B)) (- N (min A B))))\n (format t \"~A\" (floor (abs (/ (- A B) 2)))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\n2N players are running a competitive table tennis training on N tables numbered from 1 to N.\n\nThe training consists of rounds.\nIn each round, the players form N pairs, one pair per table.\nIn each pair, competitors play a match against each other.\nAs a result, one of them wins and the other one loses.\n\nThe winner of the match on table X plays on table X-1 in the next round,\nexcept for the winner of the match on table 1 who stays at table 1.\n\nSimilarly, the loser of the match on table X plays on table X+1 in the next round,\nexcept for the loser of the match on table N who stays at table N.\n\nTwo friends are playing their first round matches on distinct tables A and B.\nLet's assume that the friends are strong enough to win or lose any match at will.\nWhat is the smallest number of rounds after which the friends can get to play a match against each other?\n\nConstraints\n\n2 \\leq N \\leq 10^{18}\n\n1 \\leq A < B \\leq N\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint the smallest number of rounds after which the friends can get to play a match against each other.\n\nSample Input 1\n\n5 2 4\n\nSample Output 1\n\n1\n\nIf the first friend loses their match and the second friend wins their match, they will both move to table 3 and play each other in the next round.\n\nSample Input 2\n\n5 2 3\n\nSample Output 2\n\n2\n\nIf both friends win two matches in a row, they will both move to table 1.", "sample_input": "5 2 4\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02823", "source_text": "Score : 300 points\n\nProblem Statement\n\n2N players are running a competitive table tennis training on N tables numbered from 1 to N.\n\nThe training consists of rounds.\nIn each round, the players form N pairs, one pair per table.\nIn each pair, competitors play a match against each other.\nAs a result, one of them wins and the other one loses.\n\nThe winner of the match on table X plays on table X-1 in the next round,\nexcept for the winner of the match on table 1 who stays at table 1.\n\nSimilarly, the loser of the match on table X plays on table X+1 in the next round,\nexcept for the loser of the match on table N who stays at table N.\n\nTwo friends are playing their first round matches on distinct tables A and B.\nLet's assume that the friends are strong enough to win or lose any match at will.\nWhat is the smallest number of rounds after which the friends can get to play a match against each other?\n\nConstraints\n\n2 \\leq N \\leq 10^{18}\n\n1 \\leq A < B \\leq N\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint the smallest number of rounds after which the friends can get to play a match against each other.\n\nSample Input 1\n\n5 2 4\n\nSample Output 1\n\n1\n\nIf the first friend loses their match and the second friend wins their match, they will both move to table 3 and play each other in the next round.\n\nSample Input 2\n\n5 2 3\n\nSample Output 2\n\n2\n\nIf both friends win two matches in a row, they will both move to table 1.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 468, "cpu_time_ms": 91, "memory_kb": 9696}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s405550205", "group_id": "codeNet:p02823", "input_text": "(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defparameter lst (mapcar #'parse-integer (split \" \" (read-line))))\n(defparameter N (car lst))\n(defparameter A (cadr lst))\n(defparameter B (caddr lst))\n\n\n(if (oddp (- A B))\n (format t \"~A\" (apply #'min (list (1- (apply #'max (list A B)))\n (- N (apply #'min (list A B))))))\n (format t \"~A\" (floot (abs (/ (- A B) 2)))))\n \n", "language": "Lisp", "metadata": {"date": 1577599203, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02823.html", "problem_id": "p02823", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02823/input.txt", "sample_output_relpath": "derived/input_output/data/p02823/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02823/Lisp/s405550205.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s405550205", "user_id": "u425317134"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defparameter lst (mapcar #'parse-integer (split \" \" (read-line))))\n(defparameter N (car lst))\n(defparameter A (cadr lst))\n(defparameter B (caddr lst))\n\n\n(if (oddp (- A B))\n (format t \"~A\" (apply #'min (list (1- (apply #'max (list A B)))\n (- N (apply #'min (list A B))))))\n (format t \"~A\" (floot (abs (/ (- A B) 2)))))\n \n", "problem_context": "Score : 300 points\n\nProblem Statement\n\n2N players are running a competitive table tennis training on N tables numbered from 1 to N.\n\nThe training consists of rounds.\nIn each round, the players form N pairs, one pair per table.\nIn each pair, competitors play a match against each other.\nAs a result, one of them wins and the other one loses.\n\nThe winner of the match on table X plays on table X-1 in the next round,\nexcept for the winner of the match on table 1 who stays at table 1.\n\nSimilarly, the loser of the match on table X plays on table X+1 in the next round,\nexcept for the loser of the match on table N who stays at table N.\n\nTwo friends are playing their first round matches on distinct tables A and B.\nLet's assume that the friends are strong enough to win or lose any match at will.\nWhat is the smallest number of rounds after which the friends can get to play a match against each other?\n\nConstraints\n\n2 \\leq N \\leq 10^{18}\n\n1 \\leq A < B \\leq N\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint the smallest number of rounds after which the friends can get to play a match against each other.\n\nSample Input 1\n\n5 2 4\n\nSample Output 1\n\n1\n\nIf the first friend loses their match and the second friend wins their match, they will both move to table 3 and play each other in the next round.\n\nSample Input 2\n\n5 2 3\n\nSample Output 2\n\n2\n\nIf both friends win two matches in a row, they will both move to table 1.", "sample_input": "5 2 4\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02823", "source_text": "Score : 300 points\n\nProblem Statement\n\n2N players are running a competitive table tennis training on N tables numbered from 1 to N.\n\nThe training consists of rounds.\nIn each round, the players form N pairs, one pair per table.\nIn each pair, competitors play a match against each other.\nAs a result, one of them wins and the other one loses.\n\nThe winner of the match on table X plays on table X-1 in the next round,\nexcept for the winner of the match on table 1 who stays at table 1.\n\nSimilarly, the loser of the match on table X plays on table X+1 in the next round,\nexcept for the loser of the match on table N who stays at table N.\n\nTwo friends are playing their first round matches on distinct tables A and B.\nLet's assume that the friends are strong enough to win or lose any match at will.\nWhat is the smallest number of rounds after which the friends can get to play a match against each other?\n\nConstraints\n\n2 \\leq N \\leq 10^{18}\n\n1 \\leq A < B \\leq N\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint the smallest number of rounds after which the friends can get to play a match against each other.\n\nSample Input 1\n\n5 2 4\n\nSample Output 1\n\n1\n\nIf the first friend loses their match and the second friend wins their match, they will both move to table 3 and play each other in the next round.\n\nSample Input 2\n\n5 2 3\n\nSample Output 2\n\n2\n\nIf both friends win two matches in a row, they will both move to table 1.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 579, "cpu_time_ms": 138, "memory_kb": 13284}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s103160558", "group_id": "codeNet:p02823", "input_text": "(defun solve (n a b)\n (let ((diff (abs (- a b))))\n (if (zerop (rem diff 2))\n (floor diff 2)\n (if (< a b)\n (min (- n a) (- b 1))\n (min (- n b) (- a 1))))))\n\n(let ((n (read))\n (a (read))\n (b (read)))\n (format t \"~A~%\" (solve n a b)))\n", "language": "Lisp", "metadata": {"date": 1577585952, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02823.html", "problem_id": "p02823", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02823/input.txt", "sample_output_relpath": "derived/input_output/data/p02823/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02823/Lisp/s103160558.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s103160558", "user_id": "u202886318"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun solve (n a b)\n (let ((diff (abs (- a b))))\n (if (zerop (rem diff 2))\n (floor diff 2)\n (if (< a b)\n (min (- n a) (- b 1))\n (min (- n b) (- a 1))))))\n\n(let ((n (read))\n (a (read))\n (b (read)))\n (format t \"~A~%\" (solve n a b)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\n2N players are running a competitive table tennis training on N tables numbered from 1 to N.\n\nThe training consists of rounds.\nIn each round, the players form N pairs, one pair per table.\nIn each pair, competitors play a match against each other.\nAs a result, one of them wins and the other one loses.\n\nThe winner of the match on table X plays on table X-1 in the next round,\nexcept for the winner of the match on table 1 who stays at table 1.\n\nSimilarly, the loser of the match on table X plays on table X+1 in the next round,\nexcept for the loser of the match on table N who stays at table N.\n\nTwo friends are playing their first round matches on distinct tables A and B.\nLet's assume that the friends are strong enough to win or lose any match at will.\nWhat is the smallest number of rounds after which the friends can get to play a match against each other?\n\nConstraints\n\n2 \\leq N \\leq 10^{18}\n\n1 \\leq A < B \\leq N\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint the smallest number of rounds after which the friends can get to play a match against each other.\n\nSample Input 1\n\n5 2 4\n\nSample Output 1\n\n1\n\nIf the first friend loses their match and the second friend wins their match, they will both move to table 3 and play each other in the next round.\n\nSample Input 2\n\n5 2 3\n\nSample Output 2\n\n2\n\nIf both friends win two matches in a row, they will both move to table 1.", "sample_input": "5 2 4\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02823", "source_text": "Score : 300 points\n\nProblem Statement\n\n2N players are running a competitive table tennis training on N tables numbered from 1 to N.\n\nThe training consists of rounds.\nIn each round, the players form N pairs, one pair per table.\nIn each pair, competitors play a match against each other.\nAs a result, one of them wins and the other one loses.\n\nThe winner of the match on table X plays on table X-1 in the next round,\nexcept for the winner of the match on table 1 who stays at table 1.\n\nSimilarly, the loser of the match on table X plays on table X+1 in the next round,\nexcept for the loser of the match on table N who stays at table N.\n\nTwo friends are playing their first round matches on distinct tables A and B.\nLet's assume that the friends are strong enough to win or lose any match at will.\nWhat is the smallest number of rounds after which the friends can get to play a match against each other?\n\nConstraints\n\n2 \\leq N \\leq 10^{18}\n\n1 \\leq A < B \\leq N\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint the smallest number of rounds after which the friends can get to play a match against each other.\n\nSample Input 1\n\n5 2 4\n\nSample Output 1\n\n1\n\nIf the first friend loses their match and the second friend wins their match, they will both move to table 3 and play each other in the next round.\n\nSample Input 2\n\n5 2 3\n\nSample Output 2\n\n2\n\nIf both friends win two matches in a row, they will both move to table 1.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 279, "cpu_time_ms": 135, "memory_kb": 15844}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s220421448", "group_id": "codeNet:p02829", "input_text": "(let ((ans (make-array '(4) :initial-element t)))\n (setf (aref ans (read)) nil)\n (setf (aref ans (read)) nil)\n (loop :for i :from 1 :to 3\n :if (aref ans i)\n :return (format t \"~A~%\" i)))\n", "language": "Lisp", "metadata": {"date": 1593746355, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02829.html", "problem_id": "p02829", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02829/input.txt", "sample_output_relpath": "derived/input_output/data/p02829/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02829/Lisp/s220421448.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s220421448", "user_id": "u608227593"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((ans (make-array '(4) :initial-element t)))\n (setf (aref ans (read)) nil)\n (setf (aref ans (read)) nil)\n (loop :for i :from 1 :to 3\n :if (aref ans i)\n :return (format t \"~A~%\" i)))\n", "problem_context": "Score: 100 points\n\nProblem Statement\n\nTakahashi is solving quizzes. He has easily solved all but the last one.\n\nThe last quiz has three choices: 1, 2, and 3.\n\nWith his supernatural power, Takahashi has found out that the choices A and B are both wrong.\n\nPrint the correct choice for this problem.\n\nConstraints\n\nEach of the numbers A and B is 1, 2, or 3.\n\nA and B are different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA\nB\n\nOutput\n\nPrint the correct choice.\n\nSample Input 1\n\n3\n1\n\nSample Output 1\n\n2\n\nWhen we know 3 and 1 are both wrong, the correct choice is 2.\n\nSample Input 2\n\n1\n2\n\nSample Output 2\n\n3", "sample_input": "3\n1\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02829", "source_text": "Score: 100 points\n\nProblem Statement\n\nTakahashi is solving quizzes. He has easily solved all but the last one.\n\nThe last quiz has three choices: 1, 2, and 3.\n\nWith his supernatural power, Takahashi has found out that the choices A and B are both wrong.\n\nPrint the correct choice for this problem.\n\nConstraints\n\nEach of the numbers A and B is 1, 2, or 3.\n\nA and B are different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA\nB\n\nOutput\n\nPrint the correct choice.\n\nSample Input 1\n\n3\n1\n\nSample Output 1\n\n2\n\nWhen we know 3 and 1 are both wrong, the correct choice is 2.\n\nSample Input 2\n\n1\n2\n\nSample Output 2\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 204, "cpu_time_ms": 15, "memory_kb": 24512}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s840964877", "group_id": "codeNet:p02829", "input_text": "(defun gen (str1 str2 &optional s)\n (cond ((equal str1 \"\") s)\n (t (gen (subseq str1 1) (subseq str2 1)\n (concatenate 'string s (subseq str1 0 1)(subseq str2 0 1)))))\n )\n\n\n(let* ((n (read))\n (s (read-line))\n (str1 (subseq s 0 n))\n (str2 (subseq s (+ n 1))))\n (format t \"~A~%\" (gen str1 str2)))", "language": "Lisp", "metadata": {"date": 1589123610, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02829.html", "problem_id": "p02829", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02829/input.txt", "sample_output_relpath": "derived/input_output/data/p02829/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02829/Lisp/s840964877.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s840964877", "user_id": "u425762225"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun gen (str1 str2 &optional s)\n (cond ((equal str1 \"\") s)\n (t (gen (subseq str1 1) (subseq str2 1)\n (concatenate 'string s (subseq str1 0 1)(subseq str2 0 1)))))\n )\n\n\n(let* ((n (read))\n (s (read-line))\n (str1 (subseq s 0 n))\n (str2 (subseq s (+ n 1))))\n (format t \"~A~%\" (gen str1 str2)))", "problem_context": "Score: 100 points\n\nProblem Statement\n\nTakahashi is solving quizzes. He has easily solved all but the last one.\n\nThe last quiz has three choices: 1, 2, and 3.\n\nWith his supernatural power, Takahashi has found out that the choices A and B are both wrong.\n\nPrint the correct choice for this problem.\n\nConstraints\n\nEach of the numbers A and B is 1, 2, or 3.\n\nA and B are different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA\nB\n\nOutput\n\nPrint the correct choice.\n\nSample Input 1\n\n3\n1\n\nSample Output 1\n\n2\n\nWhen we know 3 and 1 are both wrong, the correct choice is 2.\n\nSample Input 2\n\n1\n2\n\nSample Output 2\n\n3", "sample_input": "3\n1\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02829", "source_text": "Score: 100 points\n\nProblem Statement\n\nTakahashi is solving quizzes. He has easily solved all but the last one.\n\nThe last quiz has three choices: 1, 2, and 3.\n\nWith his supernatural power, Takahashi has found out that the choices A and B are both wrong.\n\nPrint the correct choice for this problem.\n\nConstraints\n\nEach of the numbers A and B is 1, 2, or 3.\n\nA and B are different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA\nB\n\nOutput\n\nPrint the correct choice.\n\nSample Input 1\n\n3\n1\n\nSample Output 1\n\n2\n\nWhen we know 3 and 1 are both wrong, the correct choice is 2.\n\nSample Input 2\n\n1\n2\n\nSample Output 2\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 326, "cpu_time_ms": 28, "memory_kb": 7396}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s106781943", "group_id": "codeNet:p02829", "input_text": "(defun solve (a b)\n (first\n (remove-if (lambda (x)\n (or (= x a)\n (= x b)))\n '(1 2 3))))\n\n#-swank\n(let ((a (read))\n (b (read)))\n (format t \"~A~%\" (solve a b)))\n", "language": "Lisp", "metadata": {"date": 1577066513, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02829.html", "problem_id": "p02829", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02829/input.txt", "sample_output_relpath": "derived/input_output/data/p02829/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02829/Lisp/s106781943.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s106781943", "user_id": "u202886318"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun solve (a b)\n (first\n (remove-if (lambda (x)\n (or (= x a)\n (= x b)))\n '(1 2 3))))\n\n#-swank\n(let ((a (read))\n (b (read)))\n (format t \"~A~%\" (solve a b)))\n", "problem_context": "Score: 100 points\n\nProblem Statement\n\nTakahashi is solving quizzes. He has easily solved all but the last one.\n\nThe last quiz has three choices: 1, 2, and 3.\n\nWith his supernatural power, Takahashi has found out that the choices A and B are both wrong.\n\nPrint the correct choice for this problem.\n\nConstraints\n\nEach of the numbers A and B is 1, 2, or 3.\n\nA and B are different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA\nB\n\nOutput\n\nPrint the correct choice.\n\nSample Input 1\n\n3\n1\n\nSample Output 1\n\n2\n\nWhen we know 3 and 1 are both wrong, the correct choice is 2.\n\nSample Input 2\n\n1\n2\n\nSample Output 2\n\n3", "sample_input": "3\n1\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02829", "source_text": "Score: 100 points\n\nProblem Statement\n\nTakahashi is solving quizzes. He has easily solved all but the last one.\n\nThe last quiz has three choices: 1, 2, and 3.\n\nWith his supernatural power, Takahashi has found out that the choices A and B are both wrong.\n\nPrint the correct choice for this problem.\n\nConstraints\n\nEach of the numbers A and B is 1, 2, or 3.\n\nA and B are different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA\nB\n\nOutput\n\nPrint the correct choice.\n\nSample Input 1\n\n3\n1\n\nSample Output 1\n\n2\n\nWhen we know 3 and 1 are both wrong, the correct choice is 2.\n\nSample Input 2\n\n1\n2\n\nSample Output 2\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 219, "cpu_time_ms": 123, "memory_kb": 10596}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s123278457", "group_id": "codeNet:p02830", "input_text": ";; B - Strings with the Same Length\n\n(defun main ()\n (let* ((N (read))\n (row (read-line))\n (SS (subseq row 0 N))\n (ST (subseq row (1+ N))))\n (princ (interleave SS ST))))\n\n(defun interleave (s1 s2)\n (apply #'concatenate 'string\n (mapcar #'(lambda (ls) (coerce ls 'string))\n (map 'list #'list s1 s2))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1577228987, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02830.html", "problem_id": "p02830", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02830/input.txt", "sample_output_relpath": "derived/input_output/data/p02830/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02830/Lisp/s123278457.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s123278457", "user_id": "u227020436"}, "prompt_components": {"gold_output": "icpc\n", "input_to_evaluate": ";; B - Strings with the Same Length\n\n(defun main ()\n (let* ((N (read))\n (row (read-line))\n (SS (subseq row 0 N))\n (ST (subseq row (1+ N))))\n (princ (interleave SS ST))))\n\n(defun interleave (s1 s2)\n (apply #'concatenate 'string\n (mapcar #'(lambda (ls) (coerce ls 'string))\n (map 'list #'list s1 s2))))\n\n(main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven are strings s and t of length N each, both consisting of lowercase English letters.\n\nLet us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n|S| = |T| = N\n\nS and T are strings consisting of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS T\n\nOutput\n\nPrint the string formed.\n\nSample Input 1\n\n2\nip cc\n\nSample Output 1\n\nicpc\n\nSample Input 2\n\n8\nhmhmnknk uuuuuuuu\n\nSample Output 2\n\nhumuhumunukunuku\n\nSample Input 3\n\n5\naaaaa aaaaa\n\nSample Output 3\n\naaaaaaaaaa", "sample_input": "2\nip cc\n"}, "reference_outputs": ["icpc\n"], "source_document_id": "p02830", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven are strings s and t of length N each, both consisting of lowercase English letters.\n\nLet us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n|S| = |T| = N\n\nS and T are strings consisting of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS T\n\nOutput\n\nPrint the string formed.\n\nSample Input 1\n\n2\nip cc\n\nSample Output 1\n\nicpc\n\nSample Input 2\n\n8\nhmhmnknk uuuuuuuu\n\nSample Output 2\n\nhumuhumunukunuku\n\nSample Input 3\n\n5\naaaaa aaaaa\n\nSample Output 3\n\naaaaaaaaaa", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 346, "cpu_time_ms": 162, "memory_kb": 16488}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s674930699", "group_id": "codeNet:p02830", "input_text": "(let* ((n (read))\n (str (read-line))\n (ans nil))\n (map nil (lambda (j k)\n (push j ans)\n (push k ans)) str (subseq str (+ 1 n)))\n (princ (concatenate 'string (reverse ans))))", "language": "Lisp", "metadata": {"date": 1577068629, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02830.html", "problem_id": "p02830", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02830/input.txt", "sample_output_relpath": "derived/input_output/data/p02830/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02830/Lisp/s674930699.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s674930699", "user_id": "u610490393"}, "prompt_components": {"gold_output": "icpc\n", "input_to_evaluate": "(let* ((n (read))\n (str (read-line))\n (ans nil))\n (map nil (lambda (j k)\n (push j ans)\n (push k ans)) str (subseq str (+ 1 n)))\n (princ (concatenate 'string (reverse ans))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven are strings s and t of length N each, both consisting of lowercase English letters.\n\nLet us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n|S| = |T| = N\n\nS and T are strings consisting of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS T\n\nOutput\n\nPrint the string formed.\n\nSample Input 1\n\n2\nip cc\n\nSample Output 1\n\nicpc\n\nSample Input 2\n\n8\nhmhmnknk uuuuuuuu\n\nSample Output 2\n\nhumuhumunukunuku\n\nSample Input 3\n\n5\naaaaa aaaaa\n\nSample Output 3\n\naaaaaaaaaa", "sample_input": "2\nip cc\n"}, "reference_outputs": ["icpc\n"], "source_document_id": "p02830", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven are strings s and t of length N each, both consisting of lowercase English letters.\n\nLet us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n|S| = |T| = N\n\nS and T are strings consisting of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS T\n\nOutput\n\nPrint the string formed.\n\nSample Input 1\n\n2\nip cc\n\nSample Output 1\n\nicpc\n\nSample Input 2\n\n8\nhmhmnknk uuuuuuuu\n\nSample Output 2\n\nhumuhumunukunuku\n\nSample Input 3\n\n5\naaaaa aaaaa\n\nSample Output 3\n\naaaaaaaaaa", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 211, "cpu_time_ms": 96, "memory_kb": 10468}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s486421706", "group_id": "codeNet:p02830", "input_text": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(defun f(str0 str1)\n (labels ((rec(i acc)\n (if (< i (length str0))\n (rec (1+ i) (cons (char str1 i) (cons (char str0 i) acc)))\n (nreverse acc))))\n (rec 0 nil)))\n(let* ((line0 (read-line nil nil))\n (line1 (read-line nil nil))\n (splited (splitat #\\space line1)))\n (format t \"~{~A~}~%\" (f (car splited) (cadr splited))))\n", "language": "Lisp", "metadata": {"date": 1577067460, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02830.html", "problem_id": "p02830", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02830/input.txt", "sample_output_relpath": "derived/input_output/data/p02830/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02830/Lisp/s486421706.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s486421706", "user_id": "u254205055"}, "prompt_components": {"gold_output": "icpc\n", "input_to_evaluate": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(defun f(str0 str1)\n (labels ((rec(i acc)\n (if (< i (length str0))\n (rec (1+ i) (cons (char str1 i) (cons (char str0 i) acc)))\n (nreverse acc))))\n (rec 0 nil)))\n(let* ((line0 (read-line nil nil))\n (line1 (read-line nil nil))\n (splited (splitat #\\space line1)))\n (format t \"~{~A~}~%\" (f (car splited) (cadr splited))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven are strings s and t of length N each, both consisting of lowercase English letters.\n\nLet us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n|S| = |T| = N\n\nS and T are strings consisting of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS T\n\nOutput\n\nPrint the string formed.\n\nSample Input 1\n\n2\nip cc\n\nSample Output 1\n\nicpc\n\nSample Input 2\n\n8\nhmhmnknk uuuuuuuu\n\nSample Output 2\n\nhumuhumunukunuku\n\nSample Input 3\n\n5\naaaaa aaaaa\n\nSample Output 3\n\naaaaaaaaaa", "sample_input": "2\nip cc\n"}, "reference_outputs": ["icpc\n"], "source_document_id": "p02830", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven are strings s and t of length N each, both consisting of lowercase English letters.\n\nLet us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n|S| = |T| = N\n\nS and T are strings consisting of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS T\n\nOutput\n\nPrint the string formed.\n\nSample Input 1\n\n2\nip cc\n\nSample Output 1\n\nicpc\n\nSample Input 2\n\n8\nhmhmnknk uuuuuuuu\n\nSample Output 2\n\nhumuhumunukunuku\n\nSample Input 3\n\n5\naaaaa aaaaa\n\nSample Output 3\n\naaaaaaaaaa", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 623, "cpu_time_ms": 167, "memory_kb": 13792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s309267442", "group_id": "codeNet:p02831", "input_text": "(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defparameter lst (mapcar #'parse-integer (split \" \" (read-line))))\n\n(format t \"~A\" (lcm (car lst) (cadr lst)))", "language": "Lisp", "metadata": {"date": 1577069824, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02831.html", "problem_id": "p02831", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02831/input.txt", "sample_output_relpath": "derived/input_output/data/p02831/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02831/Lisp/s309267442.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s309267442", "user_id": "u425317134"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defparameter lst (mapcar #'parse-integer (split \" \" (read-line))))\n\n(format t \"~A\" (lcm (car lst) (cadr lst)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi is organizing a party.\n\nAt the party, each guest will receive one or more snack pieces.\n\nTakahashi predicts that the number of guests at this party will be A or B.\n\nFind the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted.\n\nWe assume that a piece cannot be divided and distributed to multiple guests.\n\nConstraints\n\n1 \\leq A, B \\leq 10^5\n\nA \\neq B\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the minimum number of pieces that can be evenly distributed to the guests in both of the cases with A guests and B guests.\n\nSample Input 1\n\n2 3\n\nSample Output 1\n\n6\n\nWhen we have six snack pieces, each guest can take three pieces if we have two guests, and each guest can take two if we have three guests.\n\nSample Input 2\n\n123 456\n\nSample Output 2\n\n18696\n\nSample Input 3\n\n100000 99999\n\nSample Output 3\n\n9999900000", "sample_input": "2 3\n"}, "reference_outputs": ["6\n"], "source_document_id": "p02831", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi is organizing a party.\n\nAt the party, each guest will receive one or more snack pieces.\n\nTakahashi predicts that the number of guests at this party will be A or B.\n\nFind the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted.\n\nWe assume that a piece cannot be divided and distributed to multiple guests.\n\nConstraints\n\n1 \\leq A, B \\leq 10^5\n\nA \\neq B\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the minimum number of pieces that can be evenly distributed to the guests in both of the cases with A guests and B guests.\n\nSample Input 1\n\n2 3\n\nSample Output 1\n\n6\n\nWhen we have six snack pieces, each guest can take three pieces if we have two guests, and each guest can take two if we have three guests.\n\nSample Input 2\n\n123 456\n\nSample Output 2\n\n18696\n\nSample Input 3\n\n100000 99999\n\nSample Output 3\n\n9999900000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 301, "cpu_time_ms": 93, "memory_kb": 9832}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s952166048", "group_id": "codeNet:p02832", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(defun solve-2 (n i bricks start)\n (let ((next (position i bricks :start start :test #'=)))\n (if next\n (+ (- next start) (solve-2 n (1+ i) bricks (1+ next)))\n (- n start))))\n\n(defun solve (n bricks)\n (let ((res (solve-2 n 1 bricks 0)))\n (if (= n res)\n -1\n res)))\n\n#-swank\n(let* ((n (read))\n (bricks (make-array n :element-type 'integer)))\n (loop for i from 0 below n\n do (setf (aref bricks i) (read)))\n (format t \"~A~%\" (solve n bricks)))\n", "language": "Lisp", "metadata": {"date": 1577079736, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02832.html", "problem_id": "p02832", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02832/input.txt", "sample_output_relpath": "derived/input_output/data/p02832/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02832/Lisp/s952166048.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s952166048", "user_id": "u202886318"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(defun solve-2 (n i bricks start)\n (let ((next (position i bricks :start start :test #'=)))\n (if next\n (+ (- next start) (solve-2 n (1+ i) bricks (1+ next)))\n (- n start))))\n\n(defun solve (n bricks)\n (let ((res (solve-2 n 1 bricks 0)))\n (if (= n res)\n -1\n res)))\n\n#-swank\n(let* ((n (read))\n (bricks (make-array n :element-type 'integer)))\n (loop for i from 0 below n\n do (setf (aref bricks i) (read)))\n (format t \"~A~%\" (solve n bricks)))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have N bricks arranged in a row from left to right.\n\nThe i-th brick from the left (1 \\leq i \\leq N) has an integer a_i written on it.\n\nAmong them, you can break at most N-1 bricks of your choice.\n\nLet us say there are K bricks remaining. Snuke will be satisfied if, for each integer i (1 \\leq i \\leq K), the i-th of those brick from the left has the integer i written on it.\n\nFind the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 200000\n\n1 \\leq a_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable.\n\nSample Input 1\n\n3\n2 1 2\n\nSample Output 1\n\n1\n\nIf we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied.\n\nSample Input 2\n\n3\n2 2 2\n\nSample Output 2\n\n-1\n\nIn this case, there is no way to break some of the bricks to satisfy Snuke's desire.\n\nSample Input 3\n\n10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 3\n\n7\n\nSample Input 4\n\n1\n1\n\nSample Output 4\n\n0\n\nThere may be no need to break the bricks at all.", "sample_input": "3\n2 1 2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02832", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have N bricks arranged in a row from left to right.\n\nThe i-th brick from the left (1 \\leq i \\leq N) has an integer a_i written on it.\n\nAmong them, you can break at most N-1 bricks of your choice.\n\nLet us say there are K bricks remaining. Snuke will be satisfied if, for each integer i (1 \\leq i \\leq K), the i-th of those brick from the left has the integer i written on it.\n\nFind the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 200000\n\n1 \\leq a_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable.\n\nSample Input 1\n\n3\n2 1 2\n\nSample Output 1\n\n1\n\nIf we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied.\n\nSample Input 2\n\n3\n2 2 2\n\nSample Output 2\n\n-1\n\nIn this case, there is no way to break some of the bricks to satisfy Snuke's desire.\n\nSample Input 3\n\n10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 3\n\n7\n\nSample Input 4\n\n1\n1\n\nSample Output 4\n\n0\n\nThere may be no need to break the bricks at all.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 936, "cpu_time_ms": 418, "memory_kb": 76664}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s596330911", "group_id": "codeNet:p02832", "input_text": "(defun solve-2 (n i bricks start)\n (let ((next (position i bricks :start start :test #'=)))\n (if next\n (+ (- next start) (solve-2 n (1+ i) bricks (1+ next)))\n (- n start))))\n\n(defun solve (n bricks)\n (let ((res (solve-2 n 1 bricks 0)))\n (if (= n res)\n -1\n res)))\n\n#-swank\n(let* ((n (read))\n (bricks (make-array n :element-type 'integer)))\n (loop for i from 0 below n\n do (setf (aref bricks i) (read)))\n (format t \"~A~%\" (solve n bricks)))\n", "language": "Lisp", "metadata": {"date": 1577079145, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02832.html", "problem_id": "p02832", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02832/input.txt", "sample_output_relpath": "derived/input_output/data/p02832/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02832/Lisp/s596330911.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s596330911", "user_id": "u202886318"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun solve-2 (n i bricks start)\n (let ((next (position i bricks :start start :test #'=)))\n (if next\n (+ (- next start) (solve-2 n (1+ i) bricks (1+ next)))\n (- n start))))\n\n(defun solve (n bricks)\n (let ((res (solve-2 n 1 bricks 0)))\n (if (= n res)\n -1\n res)))\n\n#-swank\n(let* ((n (read))\n (bricks (make-array n :element-type 'integer)))\n (loop for i from 0 below n\n do (setf (aref bricks i) (read)))\n (format t \"~A~%\" (solve n bricks)))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have N bricks arranged in a row from left to right.\n\nThe i-th brick from the left (1 \\leq i \\leq N) has an integer a_i written on it.\n\nAmong them, you can break at most N-1 bricks of your choice.\n\nLet us say there are K bricks remaining. Snuke will be satisfied if, for each integer i (1 \\leq i \\leq K), the i-th of those brick from the left has the integer i written on it.\n\nFind the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 200000\n\n1 \\leq a_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable.\n\nSample Input 1\n\n3\n2 1 2\n\nSample Output 1\n\n1\n\nIf we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied.\n\nSample Input 2\n\n3\n2 2 2\n\nSample Output 2\n\n-1\n\nIn this case, there is no way to break some of the bricks to satisfy Snuke's desire.\n\nSample Input 3\n\n10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 3\n\n7\n\nSample Input 4\n\n1\n1\n\nSample Output 4\n\n0\n\nThere may be no need to break the bricks at all.", "sample_input": "3\n2 1 2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02832", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have N bricks arranged in a row from left to right.\n\nThe i-th brick from the left (1 \\leq i \\leq N) has an integer a_i written on it.\n\nAmong them, you can break at most N-1 bricks of your choice.\n\nLet us say there are K bricks remaining. Snuke will be satisfied if, for each integer i (1 \\leq i \\leq K), the i-th of those brick from the left has the integer i written on it.\n\nFind the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 200000\n\n1 \\leq a_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable.\n\nSample Input 1\n\n3\n2 1 2\n\nSample Output 1\n\n1\n\nIf we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied.\n\nSample Input 2\n\n3\n2 2 2\n\nSample Output 2\n\n-1\n\nIn this case, there is no way to break some of the bricks to satisfy Snuke's desire.\n\nSample Input 3\n\n10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 3\n\n7\n\nSample Input 4\n\n1\n1\n\nSample Output 4\n\n0\n\nThere may be no need to break the bricks at all.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 490, "cpu_time_ms": 2105, "memory_kb": 62976}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s627180502", "group_id": "codeNet:p02832", "input_text": "(defun func(n x)\n (if (> n 0)\n\t(if (eq (1+ x) (read))\n\t (func (1- n) (1+ x))\n\t (func (1- n) x))\n\tx))\n\n(let* ((n (read)) (s (func n 0)))\n (princ (if (eq s 0) -1 (- n s))))\n", "language": "Lisp", "metadata": {"date": 1577070848, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02832.html", "problem_id": "p02832", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02832/input.txt", "sample_output_relpath": "derived/input_output/data/p02832/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02832/Lisp/s627180502.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s627180502", "user_id": "u493610446"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun func(n x)\n (if (> n 0)\n\t(if (eq (1+ x) (read))\n\t (func (1- n) (1+ x))\n\t (func (1- n) x))\n\tx))\n\n(let* ((n (read)) (s (func n 0)))\n (princ (if (eq s 0) -1 (- n s))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have N bricks arranged in a row from left to right.\n\nThe i-th brick from the left (1 \\leq i \\leq N) has an integer a_i written on it.\n\nAmong them, you can break at most N-1 bricks of your choice.\n\nLet us say there are K bricks remaining. Snuke will be satisfied if, for each integer i (1 \\leq i \\leq K), the i-th of those brick from the left has the integer i written on it.\n\nFind the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 200000\n\n1 \\leq a_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable.\n\nSample Input 1\n\n3\n2 1 2\n\nSample Output 1\n\n1\n\nIf we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied.\n\nSample Input 2\n\n3\n2 2 2\n\nSample Output 2\n\n-1\n\nIn this case, there is no way to break some of the bricks to satisfy Snuke's desire.\n\nSample Input 3\n\n10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 3\n\n7\n\nSample Input 4\n\n1\n1\n\nSample Output 4\n\n0\n\nThere may be no need to break the bricks at all.", "sample_input": "3\n2 1 2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02832", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have N bricks arranged in a row from left to right.\n\nThe i-th brick from the left (1 \\leq i \\leq N) has an integer a_i written on it.\n\nAmong them, you can break at most N-1 bricks of your choice.\n\nLet us say there are K bricks remaining. Snuke will be satisfied if, for each integer i (1 \\leq i \\leq K), the i-th of those brick from the left has the integer i written on it.\n\nFind the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 200000\n\n1 \\leq a_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable.\n\nSample Input 1\n\n3\n2 1 2\n\nSample Output 1\n\n1\n\nIf we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied.\n\nSample Input 2\n\n3\n2 2 2\n\nSample Output 2\n\n-1\n\nIn this case, there is no way to break some of the bricks to satisfy Snuke's desire.\n\nSample Input 3\n\n10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 3\n\n7\n\nSample Input 4\n\n1\n1\n\nSample Output 4\n\n0\n\nThere may be no need to break the bricks at all.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 175, "cpu_time_ms": 405, "memory_kb": 57704}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s029726226", "group_id": "codeNet:p02832", "input_text": "(defun check-bits (n bits bricks)\n (loop with i = 0\n for j from 0\n for bitidx from (1- n) downto 0\n unless (logbitp bitidx bits)\n do (progn\n (incf i)\n (unless (= i (aref bricks j))\n (return nil)))\n finally (return t)))\n\n(defun solve (n bricks)\n (loop with ok = nil\n for bits from 0 below (1- (expt 2 n))\n if (check-bits n bits bricks)\n minimize (progn (setf ok t)\n (logcount bits)) into result\n finally\n (return (if ok result -1))))\n\n#-swank\n(let* ((n (read))\n (bricks (make-array n :element-type 'integer)))\n (loop for i from 0 below n\n do (setf (aref bricks i) (read)))\n (format t \"~A~%\" (solve n bricks)))\n", "language": "Lisp", "metadata": {"date": 1577070323, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02832.html", "problem_id": "p02832", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02832/input.txt", "sample_output_relpath": "derived/input_output/data/p02832/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02832/Lisp/s029726226.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s029726226", "user_id": "u202886318"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun check-bits (n bits bricks)\n (loop with i = 0\n for j from 0\n for bitidx from (1- n) downto 0\n unless (logbitp bitidx bits)\n do (progn\n (incf i)\n (unless (= i (aref bricks j))\n (return nil)))\n finally (return t)))\n\n(defun solve (n bricks)\n (loop with ok = nil\n for bits from 0 below (1- (expt 2 n))\n if (check-bits n bits bricks)\n minimize (progn (setf ok t)\n (logcount bits)) into result\n finally\n (return (if ok result -1))))\n\n#-swank\n(let* ((n (read))\n (bricks (make-array n :element-type 'integer)))\n (loop for i from 0 below n\n do (setf (aref bricks i) (read)))\n (format t \"~A~%\" (solve n bricks)))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have N bricks arranged in a row from left to right.\n\nThe i-th brick from the left (1 \\leq i \\leq N) has an integer a_i written on it.\n\nAmong them, you can break at most N-1 bricks of your choice.\n\nLet us say there are K bricks remaining. Snuke will be satisfied if, for each integer i (1 \\leq i \\leq K), the i-th of those brick from the left has the integer i written on it.\n\nFind the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 200000\n\n1 \\leq a_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable.\n\nSample Input 1\n\n3\n2 1 2\n\nSample Output 1\n\n1\n\nIf we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied.\n\nSample Input 2\n\n3\n2 2 2\n\nSample Output 2\n\n-1\n\nIn this case, there is no way to break some of the bricks to satisfy Snuke's desire.\n\nSample Input 3\n\n10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 3\n\n7\n\nSample Input 4\n\n1\n1\n\nSample Output 4\n\n0\n\nThere may be no need to break the bricks at all.", "sample_input": "3\n2 1 2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02832", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have N bricks arranged in a row from left to right.\n\nThe i-th brick from the left (1 \\leq i \\leq N) has an integer a_i written on it.\n\nAmong them, you can break at most N-1 bricks of your choice.\n\nLet us say there are K bricks remaining. Snuke will be satisfied if, for each integer i (1 \\leq i \\leq K), the i-th of those brick from the left has the integer i written on it.\n\nFind the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 200000\n\n1 \\leq a_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable.\n\nSample Input 1\n\n3\n2 1 2\n\nSample Output 1\n\n1\n\nIf we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied.\n\nSample Input 2\n\n3\n2 2 2\n\nSample Output 2\n\n-1\n\nIn this case, there is no way to break some of the bricks to satisfy Snuke's desire.\n\nSample Input 3\n\n10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 3\n\n7\n\nSample Input 4\n\n1\n1\n\nSample Output 4\n\n0\n\nThere may be no need to break the bricks at all.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 757, "cpu_time_ms": 2105, "memory_kb": 61736}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s573106870", "group_id": "codeNet:p02832", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint32))\n (len 0)\n (current-pos 0))\n (dotimes (i n)\n (setf (aref as i) (- (read-fixnum) 1)))\n (dotimes (i n)\n (let ((next-pos (position i as :start current-pos)))\n (unless next-pos\n (if (zerop i)\n (println -1)\n (println (- n i)))\n (return-from main))\n (setq current-pos next-pos)))\n (println 0)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n2 1 2\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n2 2 2\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n3 1 4 1 5 9 2 6 5 3\n\"\n \"7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n1\n\"\n \"0\n\")))\n", "language": "Lisp", "metadata": {"date": 1577067103, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02832.html", "problem_id": "p02832", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02832/input.txt", "sample_output_relpath": "derived/input_output/data/p02832/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02832/Lisp/s573106870.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s573106870", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint32))\n (len 0)\n (current-pos 0))\n (dotimes (i n)\n (setf (aref as i) (- (read-fixnum) 1)))\n (dotimes (i n)\n (let ((next-pos (position i as :start current-pos)))\n (unless next-pos\n (if (zerop i)\n (println -1)\n (println (- n i)))\n (return-from main))\n (setq current-pos next-pos)))\n (println 0)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n2 1 2\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n2 2 2\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n3 1 4 1 5 9 2 6 5 3\n\"\n \"7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n1\n\"\n \"0\n\")))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have N bricks arranged in a row from left to right.\n\nThe i-th brick from the left (1 \\leq i \\leq N) has an integer a_i written on it.\n\nAmong them, you can break at most N-1 bricks of your choice.\n\nLet us say there are K bricks remaining. Snuke will be satisfied if, for each integer i (1 \\leq i \\leq K), the i-th of those brick from the left has the integer i written on it.\n\nFind the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 200000\n\n1 \\leq a_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable.\n\nSample Input 1\n\n3\n2 1 2\n\nSample Output 1\n\n1\n\nIf we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied.\n\nSample Input 2\n\n3\n2 2 2\n\nSample Output 2\n\n-1\n\nIn this case, there is no way to break some of the bricks to satisfy Snuke's desire.\n\nSample Input 3\n\n10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 3\n\n7\n\nSample Input 4\n\n1\n1\n\nSample Output 4\n\n0\n\nThere may be no need to break the bricks at all.", "sample_input": "3\n2 1 2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02832", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have N bricks arranged in a row from left to right.\n\nThe i-th brick from the left (1 \\leq i \\leq N) has an integer a_i written on it.\n\nAmong them, you can break at most N-1 bricks of your choice.\n\nLet us say there are K bricks remaining. Snuke will be satisfied if, for each integer i (1 \\leq i \\leq K), the i-th of those brick from the left has the integer i written on it.\n\nFind the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 200000\n\n1 \\leq a_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable.\n\nSample Input 1\n\n3\n2 1 2\n\nSample Output 1\n\n1\n\nIf we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied.\n\nSample Input 2\n\n3\n2 2 2\n\nSample Output 2\n\n-1\n\nIn this case, there is no way to break some of the bricks to satisfy Snuke's desire.\n\nSample Input 3\n\n10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 3\n\n7\n\nSample Input 4\n\n1\n1\n\nSample Output 4\n\n0\n\nThere may be no need to break the bricks at all.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5388, "cpu_time_ms": 196, "memory_kb": 22496}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s287275460", "group_id": "codeNet:p02833", "input_text": "(defparameter m (read-line))\n(defparameter N (parse-integer m))\n\n(defun count-zero (n)\n (let* ((order (floor (log n 10)))\n (lst (loop for i from 0 to (+ 10 order)\n collect (floor (/ n (* 10 (expt 5 i)))))))\n (apply #'+ lst)))\n\n\n(defparameter answer\n (if (oddp N)\n 0\n (count-zero N)))\n\n(format t \"~A\" answer)", "language": "Lisp", "metadata": {"date": 1577079111, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02833.html", "problem_id": "p02833", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02833/input.txt", "sample_output_relpath": "derived/input_output/data/p02833/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02833/Lisp/s287275460.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s287275460", "user_id": "u425317134"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defparameter m (read-line))\n(defparameter N (parse-integer m))\n\n(defun count-zero (n)\n (let* ((order (floor (log n 10)))\n (lst (loop for i from 0 to (+ 10 order)\n collect (floor (/ n (* 10 (expt 5 i)))))))\n (apply #'+ lst)))\n\n\n(defparameter answer\n (if (oddp N)\n 0\n (count-zero N)))\n\n(format t \"~A\" answer)", "problem_context": "Score : 500 points\n\nProblem Statement\n\nFor an integer n not less than 0, let us define f(n) as follows:\n\nf(n) = 1 (if n < 2)\n\nf(n) = n f(n-2) (if n \\geq 2)\n\nGiven is an integer N. Find the number of trailing zeros in the decimal notation of f(N).\n\nConstraints\n\n0 \\leq N \\leq 10^{18}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the number of trailing zeros in the decimal notation of f(N).\n\nSample Input 1\n\n12\n\nSample Output 1\n\n1\n\nf(12) = 12 × 10 × 8 × 6 × 4 × 2 = 46080, which has one trailing zero.\n\nSample Input 2\n\n5\n\nSample Output 2\n\n0\n\nf(5) = 5 × 3 × 1 = 15, which has no trailing zeros.\n\nSample Input 3\n\n1000000000000000000\n\nSample Output 3\n\n124999999999999995", "sample_input": "12\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02833", "source_text": "Score : 500 points\n\nProblem Statement\n\nFor an integer n not less than 0, let us define f(n) as follows:\n\nf(n) = 1 (if n < 2)\n\nf(n) = n f(n-2) (if n \\geq 2)\n\nGiven is an integer N. Find the number of trailing zeros in the decimal notation of f(N).\n\nConstraints\n\n0 \\leq N \\leq 10^{18}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the number of trailing zeros in the decimal notation of f(N).\n\nSample Input 1\n\n12\n\nSample Output 1\n\n1\n\nf(12) = 12 × 10 × 8 × 6 × 4 × 2 = 46080, which has one trailing zero.\n\nSample Input 2\n\n5\n\nSample Output 2\n\n0\n\nf(5) = 5 × 3 × 1 = 15, which has no trailing zeros.\n\nSample Input 3\n\n1000000000000000000\n\nSample Output 3\n\n124999999999999995", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 353, "cpu_time_ms": 160, "memory_kb": 16992}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s140330522", "group_id": "codeNet:p02835", "input_text": "(let ((a (read-from-string (concatenate 'string \"(\" (read-line) \")\"))))\n (if (<= (reduce #'+ a) 21)\n (princ \"win\")\n (princ \"bust\")))", "language": "Lisp", "metadata": {"date": 1593203497, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02835.html", "problem_id": "p02835", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02835/input.txt", "sample_output_relpath": "derived/input_output/data/p02835/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02835/Lisp/s140330522.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s140330522", "user_id": "u425762225"}, "prompt_components": {"gold_output": "win\n", "input_to_evaluate": "(let ((a (read-from-string (concatenate 'string \"(\" (read-line) \")\"))))\n (if (<= (reduce #'+ a) 21)\n (princ \"win\")\n (princ \"bust\")))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nGiven are three integers A_1, A_2, and A_3.\n\nIf A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.\n\nConstraints\n\n1 \\leq A_i \\leq 13 \\ \\ (i=1,2,3)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA_1 A_2 A_3\n\nOutput\n\nIf A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.\n\nSample Input 1\n\n5 7 9\n\nSample Output 1\n\nwin\n\n5+7+9=21, so print win.\n\nSample Input 2\n\n13 7 2\n\nSample Output 2\n\nbust\n\n13+7+2=22, so print bust.", "sample_input": "5 7 9\n"}, "reference_outputs": ["win\n"], "source_document_id": "p02835", "source_text": "Score : 100 points\n\nProblem Statement\n\nGiven are three integers A_1, A_2, and A_3.\n\nIf A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.\n\nConstraints\n\n1 \\leq A_i \\leq 13 \\ \\ (i=1,2,3)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA_1 A_2 A_3\n\nOutput\n\nIf A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.\n\nSample Input 1\n\n5 7 9\n\nSample Output 1\n\nwin\n\n5+7+9=21, so print win.\n\nSample Input 2\n\n13 7 2\n\nSample Output 2\n\nbust\n\n13+7+2=22, so print bust.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 152, "cpu_time_ms": 18, "memory_kb": 24100}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s891208838", "group_id": "codeNet:p02835", "input_text": "(let*(\n (cards (list (read) (read) (read)))\n (sum (reduce (lambda (m x) (+ m x)) cards)))\n (princ cards)\n (princ sum)\n (if\n (< sum 22)\n (princ \"win\")\n (princ \"bust\")))", "language": "Lisp", "metadata": {"date": 1583694743, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02835.html", "problem_id": "p02835", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02835/input.txt", "sample_output_relpath": "derived/input_output/data/p02835/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02835/Lisp/s891208838.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s891208838", "user_id": "u606976120"}, "prompt_components": {"gold_output": "win\n", "input_to_evaluate": "(let*(\n (cards (list (read) (read) (read)))\n (sum (reduce (lambda (m x) (+ m x)) cards)))\n (princ cards)\n (princ sum)\n (if\n (< sum 22)\n (princ \"win\")\n (princ \"bust\")))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nGiven are three integers A_1, A_2, and A_3.\n\nIf A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.\n\nConstraints\n\n1 \\leq A_i \\leq 13 \\ \\ (i=1,2,3)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA_1 A_2 A_3\n\nOutput\n\nIf A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.\n\nSample Input 1\n\n5 7 9\n\nSample Output 1\n\nwin\n\n5+7+9=21, so print win.\n\nSample Input 2\n\n13 7 2\n\nSample Output 2\n\nbust\n\n13+7+2=22, so print bust.", "sample_input": "5 7 9\n"}, "reference_outputs": ["win\n"], "source_document_id": "p02835", "source_text": "Score : 100 points\n\nProblem Statement\n\nGiven are three integers A_1, A_2, and A_3.\n\nIf A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.\n\nConstraints\n\n1 \\leq A_i \\leq 13 \\ \\ (i=1,2,3)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA_1 A_2 A_3\n\nOutput\n\nIf A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.\n\nSample Input 1\n\n5 7 9\n\nSample Output 1\n\nwin\n\n5+7+9=21, so print win.\n\nSample Input 2\n\n13 7 2\n\nSample Output 2\n\nbust\n\n13+7+2=22, so print bust.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 185, "cpu_time_ms": 9, "memory_kb": 3304}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s830886607", "group_id": "codeNet:p02835", "input_text": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n\n\n(defun f(line)\n (let ((lst (mapcar #'parse-integer (splitat #\\space line))))\n (<= (reduce #'+ lst) 21)))\n(let ((line (read-line nil nil)))\n (format t \"~A~%\" (if (f line) \"win\" \"bust\")))\n", "language": "Lisp", "metadata": {"date": 1575856958, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02835.html", "problem_id": "p02835", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02835/input.txt", "sample_output_relpath": "derived/input_output/data/p02835/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02835/Lisp/s830886607.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s830886607", "user_id": "u254205055"}, "prompt_components": {"gold_output": "win\n", "input_to_evaluate": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n\n\n(defun f(line)\n (let ((lst (mapcar #'parse-integer (splitat #\\space line))))\n (<= (reduce #'+ lst) 21)))\n(let ((line (read-line nil nil)))\n (format t \"~A~%\" (if (f line) \"win\" \"bust\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nGiven are three integers A_1, A_2, and A_3.\n\nIf A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.\n\nConstraints\n\n1 \\leq A_i \\leq 13 \\ \\ (i=1,2,3)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA_1 A_2 A_3\n\nOutput\n\nIf A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.\n\nSample Input 1\n\n5 7 9\n\nSample Output 1\n\nwin\n\n5+7+9=21, so print win.\n\nSample Input 2\n\n13 7 2\n\nSample Output 2\n\nbust\n\n13+7+2=22, so print bust.", "sample_input": "5 7 9\n"}, "reference_outputs": ["win\n"], "source_document_id": "p02835", "source_text": "Score : 100 points\n\nProblem Statement\n\nGiven are three integers A_1, A_2, and A_3.\n\nIf A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.\n\nConstraints\n\n1 \\leq A_i \\leq 13 \\ \\ (i=1,2,3)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA_1 A_2 A_3\n\nOutput\n\nIf A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.\n\nSample Input 1\n\n5 7 9\n\nSample Output 1\n\nwin\n\n5+7+9=21, so print win.\n\nSample Input 2\n\n13 7 2\n\nSample Output 2\n\nbust\n\n13+7+2=22, so print bust.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 441, "cpu_time_ms": 370, "memory_kb": 12896}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s174648530", "group_id": "codeNet:p02836", "input_text": "(defun main ()\n (let* ((str (read-line))\n (buff)\n (n (length str)))\n (dotimes (i (/ n 2)) \n (setf buff (subseq str i (1+ i)))\n (if (/= buff (subseq str (- n 2 i) (- n 1 i)))\n (setf (subseq str (- n 2 i) (- n 1 i)) buff)))\n str)) \n\n(main) \n", "language": "Lisp", "metadata": {"date": 1582332543, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02836.html", "problem_id": "p02836", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02836/input.txt", "sample_output_relpath": "derived/input_output/data/p02836/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02836/Lisp/s174648530.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s174648530", "user_id": "u091381267"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun main ()\n (let* ((str (read-line))\n (buff)\n (n (length str)))\n (dotimes (i (/ n 2)) \n (setf buff (subseq str i (1+ i)))\n (if (/= buff (subseq str (- n 2 i) (- n 1 i)))\n (setf (subseq str (- n 2 i) (- n 1 i)) buff)))\n str)) \n\n(main) \n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice.\n\nGiven is a string S. Find the minimum number of hugs needed to make S palindromic.\n\nConstraints\n\nS is a string consisting of lowercase English letters.\n\nThe length of S is between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the minimum number of hugs needed to make S palindromic.\n\nSample Input 1\n\nredcoder\n\nSample Output 1\n\n1\n\nFor example, we can change the fourth character to o and get a palindrome redooder.\n\nSample Input 2\n\nvvvvvv\n\nSample Output 2\n\n0\n\nWe might need no hugs at all.\n\nSample Input 3\n\nabcdabc\n\nSample Output 3\n\n2", "sample_input": "redcoder\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02836", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice.\n\nGiven is a string S. Find the minimum number of hugs needed to make S palindromic.\n\nConstraints\n\nS is a string consisting of lowercase English letters.\n\nThe length of S is between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the minimum number of hugs needed to make S palindromic.\n\nSample Input 1\n\nredcoder\n\nSample Output 1\n\n1\n\nFor example, we can change the fourth character to o and get a palindrome redooder.\n\nSample Input 2\n\nvvvvvv\n\nSample Output 2\n\n0\n\nWe might need no hugs at all.\n\nSample Input 3\n\nabcdabc\n\nSample Output 3\n\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 279, "cpu_time_ms": 274, "memory_kb": 15584}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s925718557", "group_id": "codeNet:p02836", "input_text": "(defparameter data (read-line))\n\n(let ((count 0))\n (loop for i from 0 below (/ (length data) 2) do\n (if (not (eq (char data i)\n (char data (- (length data) i 1))))\n (incf count)))\n (format t \"~A\" count))", "language": "Lisp", "metadata": {"date": 1575857739, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02836.html", "problem_id": "p02836", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02836/input.txt", "sample_output_relpath": "derived/input_output/data/p02836/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02836/Lisp/s925718557.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s925718557", "user_id": "u425317134"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defparameter data (read-line))\n\n(let ((count 0))\n (loop for i from 0 below (/ (length data) 2) do\n (if (not (eq (char data i)\n (char data (- (length data) i 1))))\n (incf count)))\n (format t \"~A\" count))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice.\n\nGiven is a string S. Find the minimum number of hugs needed to make S palindromic.\n\nConstraints\n\nS is a string consisting of lowercase English letters.\n\nThe length of S is between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the minimum number of hugs needed to make S palindromic.\n\nSample Input 1\n\nredcoder\n\nSample Output 1\n\n1\n\nFor example, we can change the fourth character to o and get a palindrome redooder.\n\nSample Input 2\n\nvvvvvv\n\nSample Output 2\n\n0\n\nWe might need no hugs at all.\n\nSample Input 3\n\nabcdabc\n\nSample Output 3\n\n2", "sample_input": "redcoder\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02836", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice.\n\nGiven is a string S. Find the minimum number of hugs needed to make S palindromic.\n\nConstraints\n\nS is a string consisting of lowercase English letters.\n\nThe length of S is between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the minimum number of hugs needed to make S palindromic.\n\nSample Input 1\n\nredcoder\n\nSample Output 1\n\n1\n\nFor example, we can change the fourth character to o and get a palindrome redooder.\n\nSample Input 2\n\nvvvvvv\n\nSample Output 2\n\n0\n\nWe might need no hugs at all.\n\nSample Input 3\n\nabcdabc\n\nSample Output 3\n\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 258, "cpu_time_ms": 134, "memory_kb": 13156}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s022695275", "group_id": "codeNet:p02837", "input_text": "(defun make-init-array (i n)\n (let ((result (make-array n :initial-element -1)))\n (setf (aref result i) 1)\n result))\n\n(defun solve-1 (i n infos array)\n (if (= (aref array i) -1)\n (let ((array2 (copy-seq array)))\n (setf (aref array2 i) 1)\n (handler-case (progn (solve-1 i n infos array2)\n (setf array array2))\n (error () (setf (aref array i) 0))))\n (let ((honestp (= (aref array i) 1))\n (says (nth i infos)))\n (loop for (x . y) in says\n do (cond\n ((= (aref array (1- x)) -1)\n (setf (aref array (1- x))\n (if honestp\n y\n (if (= y 0) 1 0)))\n (solve-1 (1- x) n infos array))\n ((= (aref array (1- x)) (if honestp y (if (= y 0) 1 0))))\n (t\n (error \"Conflict\"))))))\n (let ((next (position-if (lambda (x) (= x -1)) array)))\n (if next\n (solve-1 next n infos array)\n array)))\n\n(defun solve (n infos)\n (loop for i from 0 below n\n for result = (handler-case (solve-1 i n infos (make-init-array i n))\n (error () nil))\n maximize (if result\n (count 1 result :test #'=)\n 0)))\n\n#-swank\n(let* ((n (read))\n (infos (loop repeat n\n collect (let ((m (read)))\n (loop repeat m\n collect (cons (read) (read)))))))\n (format t \"~S~%\" (solve n infos)))\n", "language": "Lisp", "metadata": {"date": 1577040883, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02837.html", "problem_id": "p02837", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02837/input.txt", "sample_output_relpath": "derived/input_output/data/p02837/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02837/Lisp/s022695275.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s022695275", "user_id": "u202886318"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun make-init-array (i n)\n (let ((result (make-array n :initial-element -1)))\n (setf (aref result i) 1)\n result))\n\n(defun solve-1 (i n infos array)\n (if (= (aref array i) -1)\n (let ((array2 (copy-seq array)))\n (setf (aref array2 i) 1)\n (handler-case (progn (solve-1 i n infos array2)\n (setf array array2))\n (error () (setf (aref array i) 0))))\n (let ((honestp (= (aref array i) 1))\n (says (nth i infos)))\n (loop for (x . y) in says\n do (cond\n ((= (aref array (1- x)) -1)\n (setf (aref array (1- x))\n (if honestp\n y\n (if (= y 0) 1 0)))\n (solve-1 (1- x) n infos array))\n ((= (aref array (1- x)) (if honestp y (if (= y 0) 1 0))))\n (t\n (error \"Conflict\"))))))\n (let ((next (position-if (lambda (x) (= x -1)) array)))\n (if next\n (solve-1 next n infos array)\n array)))\n\n(defun solve (n infos)\n (loop for i from 0 below n\n for result = (handler-case (solve-1 i n infos (make-init-array i n))\n (error () nil))\n maximize (if result\n (count 1 result :test #'=)\n 0)))\n\n#-swank\n(let* ((n (read))\n (infos (loop repeat n\n collect (let ((m (read)))\n (loop repeat m\n collect (cons (read) (read)))))))\n (format t \"~S~%\" (solve n infos)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N people numbered 1 to N. Each of them is either an honest person whose testimonies are always correct or an unkind person whose testimonies may be correct or not.\n\nPerson i gives A_i testimonies. The j-th testimony by Person i is represented by two integers x_{ij} and y_{ij}. If y_{ij} = 1, the testimony says Person x_{ij} is honest; if y_{ij} = 0, it says Person x_{ij} is unkind.\n\nHow many honest persons can be among those N people at most?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 15\n\n0 \\leq A_i \\leq N - 1\n\n1 \\leq x_{ij} \\leq N\n\nx_{ij} \\neq i\n\nx_{ij_1} \\neq x_{ij_2} (j_1 \\neq j_2)\n\ny_{ij} = 0, 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1\nx_{11} y_{11}\nx_{12} y_{12}\n:\nx_{1A_1} y_{1A_1}\nA_2\nx_{21} y_{21}\nx_{22} y_{22}\n:\nx_{2A_2} y_{2A_2}\n:\nA_N\nx_{N1} y_{N1}\nx_{N2} y_{N2}\n:\nx_{NA_N} y_{NA_N}\n\nOutput\n\nPrint the maximum possible number of honest persons among the N people.\n\nSample Input 1\n\n3\n1\n2 1\n1\n1 1\n1\n2 0\n\nSample Output 1\n\n2\n\nIf Person 1 and Person 2 are honest and Person 3 is unkind, we have two honest persons without inconsistencies, which is the maximum possible number of honest persons.\n\nSample Input 2\n\n3\n2\n2 1\n3 0\n2\n3 1\n1 0\n2\n1 1\n2 0\n\nSample Output 2\n\n0\n\nAssuming that one or more of them are honest immediately leads to a contradiction.\n\nSample Input 3\n\n2\n1\n2 0\n1\n1 0\n\nSample Output 3\n\n1", "sample_input": "3\n1\n2 1\n1\n1 1\n1\n2 0\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02837", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N people numbered 1 to N. Each of them is either an honest person whose testimonies are always correct or an unkind person whose testimonies may be correct or not.\n\nPerson i gives A_i testimonies. The j-th testimony by Person i is represented by two integers x_{ij} and y_{ij}. If y_{ij} = 1, the testimony says Person x_{ij} is honest; if y_{ij} = 0, it says Person x_{ij} is unkind.\n\nHow many honest persons can be among those N people at most?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 15\n\n0 \\leq A_i \\leq N - 1\n\n1 \\leq x_{ij} \\leq N\n\nx_{ij} \\neq i\n\nx_{ij_1} \\neq x_{ij_2} (j_1 \\neq j_2)\n\ny_{ij} = 0, 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1\nx_{11} y_{11}\nx_{12} y_{12}\n:\nx_{1A_1} y_{1A_1}\nA_2\nx_{21} y_{21}\nx_{22} y_{22}\n:\nx_{2A_2} y_{2A_2}\n:\nA_N\nx_{N1} y_{N1}\nx_{N2} y_{N2}\n:\nx_{NA_N} y_{NA_N}\n\nOutput\n\nPrint the maximum possible number of honest persons among the N people.\n\nSample Input 1\n\n3\n1\n2 1\n1\n1 1\n1\n2 0\n\nSample Output 1\n\n2\n\nIf Person 1 and Person 2 are honest and Person 3 is unkind, we have two honest persons without inconsistencies, which is the maximum possible number of honest persons.\n\nSample Input 2\n\n3\n2\n2 1\n3 0\n2\n3 1\n1 0\n2\n1 1\n2 0\n\nSample Output 2\n\n0\n\nAssuming that one or more of them are honest immediately leads to a contradiction.\n\nSample Input 3\n\n2\n1\n2 0\n1\n1 0\n\nSample Output 3\n\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1602, "cpu_time_ms": 160, "memory_kb": 43488}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s695760066", "group_id": "codeNet:p02838", "input_text": ";; D - Xor Sum 4\n\n(defparameter *modulus* (+ (expt 10 9) 7))\n(defparameter *max-bits* 60)\n\n(defun add-bits-to-vector (n vec)\n \"配列vecに整数nの2進各桁を加える\"\n (loop for m = n then (ash m -1) until (zerop m)\n for i from 0\n do (incf (aref vec i) (logand m 1))))\n\n(defun solve (N)\n (let ((vec (make-array *max-bits* :initial-element 0)))\n ; 各数を2進数に変換したときの各桁の1の個数を求める\n (loop repeat N do (add-bits-to-vector (read) vec))\n ; 各桁を集約\n (reduce #'(lambda (l h) (mod (+ l (ash h 1)) *modulus*))\n ; 2進各桁のXORの総和 (= 1の個数 * 0の個数)\n (map 'vector #'(lambda (m) (* m (- N m))) vec)\n :from-end t)))\n\n(defun main ()\n (print (solve (read)))\n (fresh-line))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1577118509, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02838.html", "problem_id": "p02838", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02838/input.txt", "sample_output_relpath": "derived/input_output/data/p02838/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02838/Lisp/s695760066.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s695760066", "user_id": "u227020436"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": ";; D - Xor Sum 4\n\n(defparameter *modulus* (+ (expt 10 9) 7))\n(defparameter *max-bits* 60)\n\n(defun add-bits-to-vector (n vec)\n \"配列vecに整数nの2進各桁を加える\"\n (loop for m = n then (ash m -1) until (zerop m)\n for i from 0\n do (incf (aref vec i) (logand m 1))))\n\n(defun solve (N)\n (let ((vec (make-array *max-bits* :initial-element 0)))\n ; 各数を2進数に変換したときの各桁の1の個数を求める\n (loop repeat N do (add-bits-to-vector (read) vec))\n ; 各桁を集約\n (reduce #'(lambda (l h) (mod (+ l (ash h 1)) *modulus*))\n ; 2進各桁のXORの総和 (= 1の個数 * 0の個数)\n (map 'vector #'(lambda (m) (* m (- N m))) vec)\n :from-end t)))\n\n(defun main ()\n (print (solve (read)))\n (fresh-line))\n\n(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have N integers. The i-th integer is A_i.\n\nFind \\sum_{i=1}^{N-1}\\sum_{j=i+1}^{N} (A_i \\mbox{ XOR } A_j), modulo (10^9+7).\n\nWhat is \\mbox{ XOR }?\n\nThe XOR of integers A and B, A \\mbox{ XOR } B, is defined as follows:\n\nWhen A \\mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \\geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.\n\nFor example, 3 \\mbox{ XOR } 5 = 6. (In base two: 011 \\mbox{ XOR } 101 = 110.)\n\nConstraints\n\n2 \\leq N \\leq 3 \\times 10^5\n\n0 \\leq A_i < 2^{60}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the value \\sum_{i=1}^{N-1}\\sum_{j=i+1}^{N} (A_i \\mbox{ XOR } A_j), modulo (10^9+7).\n\nSample Input 1\n\n3\n1 2 3\n\nSample Output 1\n\n6\n\nWe have (1\\mbox{ XOR } 2)+(1\\mbox{ XOR } 3)+(2\\mbox{ XOR } 3)=3+2+1=6.\n\nSample Input 2\n\n10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 2\n\n237\n\nSample Input 3\n\n10\n3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820\n\nSample Output 3\n\n103715602\n\nPrint the sum modulo (10^9+7).", "sample_input": "3\n1 2 3\n"}, "reference_outputs": ["6\n"], "source_document_id": "p02838", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have N integers. The i-th integer is A_i.\n\nFind \\sum_{i=1}^{N-1}\\sum_{j=i+1}^{N} (A_i \\mbox{ XOR } A_j), modulo (10^9+7).\n\nWhat is \\mbox{ XOR }?\n\nThe XOR of integers A and B, A \\mbox{ XOR } B, is defined as follows:\n\nWhen A \\mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \\geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.\n\nFor example, 3 \\mbox{ XOR } 5 = 6. (In base two: 011 \\mbox{ XOR } 101 = 110.)\n\nConstraints\n\n2 \\leq N \\leq 3 \\times 10^5\n\n0 \\leq A_i < 2^{60}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the value \\sum_{i=1}^{N-1}\\sum_{j=i+1}^{N} (A_i \\mbox{ XOR } A_j), modulo (10^9+7).\n\nSample Input 1\n\n3\n1 2 3\n\nSample Output 1\n\n6\n\nWe have (1\\mbox{ XOR } 2)+(1\\mbox{ XOR } 3)+(2\\mbox{ XOR } 3)=3+2+1=6.\n\nSample Input 2\n\n10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 2\n\n237\n\nSample Input 3\n\n10\n3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820\n\nSample Output 3\n\n103715602\n\nPrint the sum modulo (10^9+7).", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 784, "cpu_time_ms": 2105, "memory_kb": 68196}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s664520177", "group_id": "codeNet:p02838", "input_text": ";; D - Xor Sum 4\n\n(defparameter *modulus* (+ (expt 10 9) 7))\n(defparameter *max-bits* 60)\n\n(defun main ()\n (let* ((N (read))\n (A (loop repeat N collect (read))))\n (print (solve N A))\n (fresh-line)))\n\n(defun solve (N A)\n ; 各桁を集約\n (reduce #'(lambda (l h) (mod (+ l (ash h 1)) *modulus*))\n ; 2進各桁のXORの総和 (= 1の個数 * 0の個数)\n (map 'vector #'(lambda (m) (* m (- N m)))\n ; 各数を2進各桁のベクトルに変換し和 (2進各桁の1の個数) を求める\n (loop with vec = (to-bit-vector (car A))\n for elem in (cdr A)\n do (map-into vec #'+ vec (to-bit-vector elem))\n finally (return vec)))\n :from-end t))\n\n(defun to-bit-vector (n)\n \"整数nを2進各桁の配列 (最下位が前) に変換\"\n (loop with vec = (make-array *max-bits*)\n for i from 0 below *max-bits*\n for m = n then (ash m -1) do (setf (aref vec i) (mod m 2))\n finally (return vec)))\n\n(compile 'to-bit-vector)\n(compile 'solve)\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1577030482, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02838.html", "problem_id": "p02838", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02838/input.txt", "sample_output_relpath": "derived/input_output/data/p02838/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02838/Lisp/s664520177.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s664520177", "user_id": "u227020436"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": ";; D - Xor Sum 4\n\n(defparameter *modulus* (+ (expt 10 9) 7))\n(defparameter *max-bits* 60)\n\n(defun main ()\n (let* ((N (read))\n (A (loop repeat N collect (read))))\n (print (solve N A))\n (fresh-line)))\n\n(defun solve (N A)\n ; 各桁を集約\n (reduce #'(lambda (l h) (mod (+ l (ash h 1)) *modulus*))\n ; 2進各桁のXORの総和 (= 1の個数 * 0の個数)\n (map 'vector #'(lambda (m) (* m (- N m)))\n ; 各数を2進各桁のベクトルに変換し和 (2進各桁の1の個数) を求める\n (loop with vec = (to-bit-vector (car A))\n for elem in (cdr A)\n do (map-into vec #'+ vec (to-bit-vector elem))\n finally (return vec)))\n :from-end t))\n\n(defun to-bit-vector (n)\n \"整数nを2進各桁の配列 (最下位が前) に変換\"\n (loop with vec = (make-array *max-bits*)\n for i from 0 below *max-bits*\n for m = n then (ash m -1) do (setf (aref vec i) (mod m 2))\n finally (return vec)))\n\n(compile 'to-bit-vector)\n(compile 'solve)\n\n(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have N integers. The i-th integer is A_i.\n\nFind \\sum_{i=1}^{N-1}\\sum_{j=i+1}^{N} (A_i \\mbox{ XOR } A_j), modulo (10^9+7).\n\nWhat is \\mbox{ XOR }?\n\nThe XOR of integers A and B, A \\mbox{ XOR } B, is defined as follows:\n\nWhen A \\mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \\geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.\n\nFor example, 3 \\mbox{ XOR } 5 = 6. (In base two: 011 \\mbox{ XOR } 101 = 110.)\n\nConstraints\n\n2 \\leq N \\leq 3 \\times 10^5\n\n0 \\leq A_i < 2^{60}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the value \\sum_{i=1}^{N-1}\\sum_{j=i+1}^{N} (A_i \\mbox{ XOR } A_j), modulo (10^9+7).\n\nSample Input 1\n\n3\n1 2 3\n\nSample Output 1\n\n6\n\nWe have (1\\mbox{ XOR } 2)+(1\\mbox{ XOR } 3)+(2\\mbox{ XOR } 3)=3+2+1=6.\n\nSample Input 2\n\n10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 2\n\n237\n\nSample Input 3\n\n10\n3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820\n\nSample Output 3\n\n103715602\n\nPrint the sum modulo (10^9+7).", "sample_input": "3\n1 2 3\n"}, "reference_outputs": ["6\n"], "source_document_id": "p02838", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have N integers. The i-th integer is A_i.\n\nFind \\sum_{i=1}^{N-1}\\sum_{j=i+1}^{N} (A_i \\mbox{ XOR } A_j), modulo (10^9+7).\n\nWhat is \\mbox{ XOR }?\n\nThe XOR of integers A and B, A \\mbox{ XOR } B, is defined as follows:\n\nWhen A \\mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \\geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.\n\nFor example, 3 \\mbox{ XOR } 5 = 6. (In base two: 011 \\mbox{ XOR } 101 = 110.)\n\nConstraints\n\n2 \\leq N \\leq 3 \\times 10^5\n\n0 \\leq A_i < 2^{60}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the value \\sum_{i=1}^{N-1}\\sum_{j=i+1}^{N} (A_i \\mbox{ XOR } A_j), modulo (10^9+7).\n\nSample Input 1\n\n3\n1 2 3\n\nSample Output 1\n\n6\n\nWe have (1\\mbox{ XOR } 2)+(1\\mbox{ XOR } 3)+(2\\mbox{ XOR } 3)=3+2+1=6.\n\nSample Input 2\n\n10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 2\n\n237\n\nSample Input 3\n\n10\n3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820\n\nSample Output 3\n\n103715602\n\nPrint the sum modulo (10^9+7).", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1025, "cpu_time_ms": 2105, "memory_kb": 70500}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s727010433", "group_id": "codeNet:p02838", "input_text": "(let* ((n (read))\n (a (loop repeat n\n collect (read)))\n (count 0) b)\n (princ (mod\n (loop for c from 0 to 59\n with q\n do (setq q (mod (ash 1 c) 1000000007))\n do (setq count 0)\n do (loop for x in a\n if (eq (mod (ash x (- c)) 2) 1)\n do (setq count (1+ count))\n finally (setq b (* count (- n count) q)))\n sum (mod b 1000000007))\n 1000000007)))\n", "language": "Lisp", "metadata": {"date": 1575873068, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02838.html", "problem_id": "p02838", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02838/input.txt", "sample_output_relpath": "derived/input_output/data/p02838/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02838/Lisp/s727010433.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s727010433", "user_id": "u643747754"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(let* ((n (read))\n (a (loop repeat n\n collect (read)))\n (count 0) b)\n (princ (mod\n (loop for c from 0 to 59\n with q\n do (setq q (mod (ash 1 c) 1000000007))\n do (setq count 0)\n do (loop for x in a\n if (eq (mod (ash x (- c)) 2) 1)\n do (setq count (1+ count))\n finally (setq b (* count (- n count) q)))\n sum (mod b 1000000007))\n 1000000007)))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have N integers. The i-th integer is A_i.\n\nFind \\sum_{i=1}^{N-1}\\sum_{j=i+1}^{N} (A_i \\mbox{ XOR } A_j), modulo (10^9+7).\n\nWhat is \\mbox{ XOR }?\n\nThe XOR of integers A and B, A \\mbox{ XOR } B, is defined as follows:\n\nWhen A \\mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \\geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.\n\nFor example, 3 \\mbox{ XOR } 5 = 6. (In base two: 011 \\mbox{ XOR } 101 = 110.)\n\nConstraints\n\n2 \\leq N \\leq 3 \\times 10^5\n\n0 \\leq A_i < 2^{60}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the value \\sum_{i=1}^{N-1}\\sum_{j=i+1}^{N} (A_i \\mbox{ XOR } A_j), modulo (10^9+7).\n\nSample Input 1\n\n3\n1 2 3\n\nSample Output 1\n\n6\n\nWe have (1\\mbox{ XOR } 2)+(1\\mbox{ XOR } 3)+(2\\mbox{ XOR } 3)=3+2+1=6.\n\nSample Input 2\n\n10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 2\n\n237\n\nSample Input 3\n\n10\n3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820\n\nSample Output 3\n\n103715602\n\nPrint the sum modulo (10^9+7).", "sample_input": "3\n1 2 3\n"}, "reference_outputs": ["6\n"], "source_document_id": "p02838", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have N integers. The i-th integer is A_i.\n\nFind \\sum_{i=1}^{N-1}\\sum_{j=i+1}^{N} (A_i \\mbox{ XOR } A_j), modulo (10^9+7).\n\nWhat is \\mbox{ XOR }?\n\nThe XOR of integers A and B, A \\mbox{ XOR } B, is defined as follows:\n\nWhen A \\mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \\geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.\n\nFor example, 3 \\mbox{ XOR } 5 = 6. (In base two: 011 \\mbox{ XOR } 101 = 110.)\n\nConstraints\n\n2 \\leq N \\leq 3 \\times 10^5\n\n0 \\leq A_i < 2^{60}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the value \\sum_{i=1}^{N-1}\\sum_{j=i+1}^{N} (A_i \\mbox{ XOR } A_j), modulo (10^9+7).\n\nSample Input 1\n\n3\n1 2 3\n\nSample Output 1\n\n6\n\nWe have (1\\mbox{ XOR } 2)+(1\\mbox{ XOR } 3)+(2\\mbox{ XOR } 3)=3+2+1=6.\n\nSample Input 2\n\n10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 2\n\n237\n\nSample Input 3\n\n10\n3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820\n\nSample Output 3\n\n103715602\n\nPrint the sum modulo (10^9+7).", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 497, "cpu_time_ms": 2105, "memory_kb": 70112}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s236537053", "group_id": "codeNet:p02839", "input_text": ";; E - Balanced Path\n\n(defun main ()\n (let* ((H (read))\n (W (read))\n (A (loop repeat H collect (loop repeat W collect (read))))\n (B (loop repeat H collect (loop repeat W collect (read)))))\n (print (solve H W A B))\n (fresh-line)))\n\n(defmacro table-add (table i j elem)\n `(setf (aref ,table ,i ,j ,elem) 1))\n(defmacro table-contains (table i j elem)\n `(plusp (aref ,table ,i ,j ,elem)))\n\n(defun solve (H W A B)\n (let* ((maxdiff (* 80 (+ W H)))\n (D (make-array (list H W) :initial-contents\n (mapcar #'(lambda (a b) (mapcar #'- a b)) A B)))\n (table (make-array (list H W maxdiff) :element-type 'bit\n :initial-element 0)))\n\n ; table[0, 0]を初期化\n (table-add table 0 0 (abs (aref D 0 0)))\n\n ; table[i, j]を計算\n (loop for i below H do\n (loop for j below W\n for diff = (aref D i j) do\n (loop for prev below maxdiff\n when (or (and (plusp j) (table-contains table i (1- j) prev))\n (and (plusp i) (table-contains table (1- i) j prev)))\n do (table-add table i j (abs (+ prev diff)))\n (table-add table i j (abs (- prev diff))))))\n\n ; table[H-1, W-1]の最小値\n (loop for d from 0\n when (table-contains table (1- H) (1- W) d)\n return d)))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1577555441, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02839.html", "problem_id": "p02839", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02839/input.txt", "sample_output_relpath": "derived/input_output/data/p02839/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02839/Lisp/s236537053.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s236537053", "user_id": "u227020436"}, "prompt_components": {"gold_output": "0\n", "input_to_evaluate": ";; E - Balanced Path\n\n(defun main ()\n (let* ((H (read))\n (W (read))\n (A (loop repeat H collect (loop repeat W collect (read))))\n (B (loop repeat H collect (loop repeat W collect (read)))))\n (print (solve H W A B))\n (fresh-line)))\n\n(defmacro table-add (table i j elem)\n `(setf (aref ,table ,i ,j ,elem) 1))\n(defmacro table-contains (table i j elem)\n `(plusp (aref ,table ,i ,j ,elem)))\n\n(defun solve (H W A B)\n (let* ((maxdiff (* 80 (+ W H)))\n (D (make-array (list H W) :initial-contents\n (mapcar #'(lambda (a b) (mapcar #'- a b)) A B)))\n (table (make-array (list H W maxdiff) :element-type 'bit\n :initial-element 0)))\n\n ; table[0, 0]を初期化\n (table-add table 0 0 (abs (aref D 0 0)))\n\n ; table[i, j]を計算\n (loop for i below H do\n (loop for j below W\n for diff = (aref D i j) do\n (loop for prev below maxdiff\n when (or (and (plusp j) (table-contains table i (1- j) prev))\n (and (plusp i) (table-contains table (1- i) j prev)))\n do (table-add table i j (abs (+ prev diff)))\n (table-add table i j (abs (- prev diff))))))\n\n ; table[H-1, W-1]の最小値\n (loop for d from 0\n when (table-contains table (1- H) (1- W) d)\n return d)))\n\n(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nWe have a grid with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left.\n\nThe square (i, j) has two numbers A_{ij} and B_{ij} written on it.\n\nFirst, for each square, Takahashi paints one of the written numbers red and the other blue.\n\nThen, he travels from the square (1, 1) to the square (H, W). In one move, he can move from a square (i, j) to the square (i+1, j) or the square (i, j+1). He must not leave the grid.\n\nLet the unbalancedness be the absolute difference of the sum of red numbers and the sum of blue numbers written on the squares along Takahashi's path, including the squares (1, 1) and (H, W).\n\nTakahashi wants to make the unbalancedness as small as possible by appropriately painting the grid and traveling on it.\n\nFind the minimum unbalancedness possible.\n\nConstraints\n\n2 \\leq H \\leq 80\n\n2 \\leq W \\leq 80\n\n0 \\leq A_{ij} \\leq 80\n\n0 \\leq B_{ij} \\leq 80\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nA_{11} A_{12} \\ldots A_{1W}\n:\nA_{H1} A_{H2} \\ldots A_{HW}\nB_{11} B_{12} \\ldots B_{1W}\n:\nB_{H1} B_{H2} \\ldots B_{HW}\n\nOutput\n\nPrint the minimum unbalancedness possible.\n\nSample Input 1\n\n2 2\n1 2\n3 4\n3 4\n2 1\n\nSample Output 1\n\n0\n\nBy painting the grid and traveling on it as shown in the figure below, the sum of red numbers and the sum of blue numbers are 3+3+1=7 and 1+2+4=7, respectively, for the unbalancedness of 0.\n\nSample Input 2\n\n2 3\n1 10 80\n80 10 1\n1 2 3\n4 5 6\n\nSample Output 2\n\n2", "sample_input": "2 2\n1 2\n3 4\n3 4\n2 1\n"}, "reference_outputs": ["0\n"], "source_document_id": "p02839", "source_text": "Score : 500 points\n\nProblem Statement\n\nWe have a grid with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left.\n\nThe square (i, j) has two numbers A_{ij} and B_{ij} written on it.\n\nFirst, for each square, Takahashi paints one of the written numbers red and the other blue.\n\nThen, he travels from the square (1, 1) to the square (H, W). In one move, he can move from a square (i, j) to the square (i+1, j) or the square (i, j+1). He must not leave the grid.\n\nLet the unbalancedness be the absolute difference of the sum of red numbers and the sum of blue numbers written on the squares along Takahashi's path, including the squares (1, 1) and (H, W).\n\nTakahashi wants to make the unbalancedness as small as possible by appropriately painting the grid and traveling on it.\n\nFind the minimum unbalancedness possible.\n\nConstraints\n\n2 \\leq H \\leq 80\n\n2 \\leq W \\leq 80\n\n0 \\leq A_{ij} \\leq 80\n\n0 \\leq B_{ij} \\leq 80\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nA_{11} A_{12} \\ldots A_{1W}\n:\nA_{H1} A_{H2} \\ldots A_{HW}\nB_{11} B_{12} \\ldots B_{1W}\n:\nB_{H1} B_{H2} \\ldots B_{HW}\n\nOutput\n\nPrint the minimum unbalancedness possible.\n\nSample Input 1\n\n2 2\n1 2\n3 4\n3 4\n2 1\n\nSample Output 1\n\n0\n\nBy painting the grid and traveling on it as shown in the figure below, the sum of red numbers and the sum of blue numbers are 3+3+1=7 and 1+2+4=7, respectively, for the unbalancedness of 0.\n\nSample Input 2\n\n2 3\n1 10 80\n80 10 1\n1 2 3\n4 5 6\n\nSample Output 2\n\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1323, "cpu_time_ms": 1462, "memory_kb": 48488}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s331480244", "group_id": "codeNet:p02840", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (x (read))\n (d (read))\n (table (make-hash-table :test #'eq))\n (res 0))\n (declare (uint31 n)\n (int32 x d)\n (uint62 res))\n (when (zerop d)\n (if (zerop x)\n (println 0)\n (println (+ n 1)))\n (return-from main))\n (when (< d 0)\n (setq d (- d)\n x (- x)))\n (loop for p from 0 to n\n for rem = (mod (* p x) d)\n for init-idx of-type uint31 = (ash (* p (- p 1)) -1)\n for end-idx of-type uint31 = (+ 1\n (- (ash (* n (- n 1)) -1)\n (ash (* (- n p) (- n p 1)) -1)))\n do (dbg init-idx end-idx)\n (push (cons (+ (* p x) (* d init-idx)) 1)\n (gethash rem table))\n (push (cons (+ (* p x) (* d end-idx)) -1)\n (gethash rem table)))\n (labels ((recur (list prev depth)\n (declare (fixnum prev depth))\n (when list\n (destructuring-bind (pos . dir) (car list)\n (declare (fixnum pos dir))\n (if (= dir 1)\n (if (= depth 0)\n (recur (cdr list) pos 1)\n (recur (cdr list) prev (+ depth 1)))\n (if (= depth 1)\n (progn\n (incf res (- pos prev))\n (recur (cdr list) 0 0))\n (recur (cdr list) prev (- depth 1))))))))\n (loop for key being each hash-key of table\n do (setf (gethash key table)\n (sort (the list (gethash key table))\n (lambda (x y)\n (declare ((cons fixnum fixnum) x y))\n (or (< (car x) (car y))\n (and (= (car x) (car y))\n (< (cdr x) (cdr y))))))))\n (loop for nodes being each hash-value of table\n do (recur nodes 0 0))\n (println (/ res d))\n table)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 4 2\n\"\n \"8\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 3 -3\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"100 14 20\n\"\n \"49805\n\")))\n", "language": "Lisp", "metadata": {"date": 1575871964, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02840.html", "problem_id": "p02840", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02840/input.txt", "sample_output_relpath": "derived/input_output/data/p02840/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02840/Lisp/s331480244.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s331480244", "user_id": "u352600849"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (x (read))\n (d (read))\n (table (make-hash-table :test #'eq))\n (res 0))\n (declare (uint31 n)\n (int32 x d)\n (uint62 res))\n (when (zerop d)\n (if (zerop x)\n (println 0)\n (println (+ n 1)))\n (return-from main))\n (when (< d 0)\n (setq d (- d)\n x (- x)))\n (loop for p from 0 to n\n for rem = (mod (* p x) d)\n for init-idx of-type uint31 = (ash (* p (- p 1)) -1)\n for end-idx of-type uint31 = (+ 1\n (- (ash (* n (- n 1)) -1)\n (ash (* (- n p) (- n p 1)) -1)))\n do (dbg init-idx end-idx)\n (push (cons (+ (* p x) (* d init-idx)) 1)\n (gethash rem table))\n (push (cons (+ (* p x) (* d end-idx)) -1)\n (gethash rem table)))\n (labels ((recur (list prev depth)\n (declare (fixnum prev depth))\n (when list\n (destructuring-bind (pos . dir) (car list)\n (declare (fixnum pos dir))\n (if (= dir 1)\n (if (= depth 0)\n (recur (cdr list) pos 1)\n (recur (cdr list) prev (+ depth 1)))\n (if (= depth 1)\n (progn\n (incf res (- pos prev))\n (recur (cdr list) 0 0))\n (recur (cdr list) prev (- depth 1))))))))\n (loop for key being each hash-key of table\n do (setf (gethash key table)\n (sort (the list (gethash key table))\n (lambda (x y)\n (declare ((cons fixnum fixnum) x y))\n (or (< (car x) (car y))\n (and (= (car x) (car y))\n (< (cdr x) (cdr y))))))))\n (loop for nodes being each hash-value of table\n do (recur nodes 0 0))\n (println (/ res d))\n table)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 4 2\n\"\n \"8\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 3 -3\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"100 14 20\n\"\n \"49805\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nWe have an integer sequence A of length N, where A_1 = X, A_{i+1} = A_i + D (1 \\leq i < N ) holds.\n\nTakahashi will take some (possibly all or none) of the elements in this sequence, and Aoki will take all of the others.\n\nLet S and T be the sum of the numbers taken by Takahashi and Aoki, respectively. How many possible values of S - T are there?\n\nConstraints\n\n-10^8 \\leq X, D \\leq 10^8\n\n1 \\leq N \\leq 2 \\times 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X D\n\nOutput\n\nPrint the number of possible values of S - T.\n\nSample Input 1\n\n3 4 2\n\nSample Output 1\n\n8\n\nA is (4, 6, 8).\n\nThere are eight ways for (Takahashi, Aoki) to take the elements: ((), (4, 6, 8)), ((4), (6, 8)), ((6), (4, 8)), ((8), (4, 6))), ((4, 6), (8))), ((4, 8), (6))), ((6, 8), (4))), and ((4, 6, 8), ()).\n\nThe values of S - T in these ways are -18, -10, -6, -2, 2, 6, 10, and 18, respectively, so there are eight possible values of S - T.\n\nSample Input 2\n\n2 3 -3\n\nSample Output 2\n\n2\n\nA is (3, 0). There are two possible values of S - T: -3 and 3.\n\nSample Input 3\n\n100 14 20\n\nSample Output 3\n\n49805", "sample_input": "3 4 2\n"}, "reference_outputs": ["8\n"], "source_document_id": "p02840", "source_text": "Score : 600 points\n\nProblem Statement\n\nWe have an integer sequence A of length N, where A_1 = X, A_{i+1} = A_i + D (1 \\leq i < N ) holds.\n\nTakahashi will take some (possibly all or none) of the elements in this sequence, and Aoki will take all of the others.\n\nLet S and T be the sum of the numbers taken by Takahashi and Aoki, respectively. How many possible values of S - T are there?\n\nConstraints\n\n-10^8 \\leq X, D \\leq 10^8\n\n1 \\leq N \\leq 2 \\times 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X D\n\nOutput\n\nPrint the number of possible values of S - T.\n\nSample Input 1\n\n3 4 2\n\nSample Output 1\n\n8\n\nA is (4, 6, 8).\n\nThere are eight ways for (Takahashi, Aoki) to take the elements: ((), (4, 6, 8)), ((4), (6, 8)), ((6), (4, 8)), ((8), (4, 6))), ((4, 6), (8))), ((4, 8), (6))), ((6, 8), (4))), and ((4, 6, 8), ()).\n\nThe values of S - T in these ways are -18, -10, -6, -2, 2, 6, 10, and 18, respectively, so there are eight possible values of S - T.\n\nSample Input 2\n\n2 3 -3\n\nSample Output 2\n\n2\n\nA is (3, 0). There are two possible values of S - T: -3 and 3.\n\nSample Input 3\n\n100 14 20\n\nSample Output 3\n\n49805", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5758, "cpu_time_ms": 111, "memory_kb": 17504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s626110586", "group_id": "codeNet:p02842", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (lo (/ n 108/100))\n (hi (/ (+ n 1) 108/100))\n (res (ceiling lo)))\n (if (< res hi)\n (println res)\n (write-line \":(\"))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"432\n\"\n \"400\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1079\n\"\n \":(\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1001\n\"\n \"927\n\")))\n", "language": "Lisp", "metadata": {"date": 1575252300, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02842.html", "problem_id": "p02842", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02842/input.txt", "sample_output_relpath": "derived/input_output/data/p02842/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02842/Lisp/s626110586.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s626110586", "user_id": "u352600849"}, "prompt_components": {"gold_output": "400\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (lo (/ n 108/100))\n (hi (/ (+ n 1) 108/100))\n (res (ceiling lo)))\n (if (< res hi)\n (println res)\n (write-line \":(\"))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"432\n\"\n \"400\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1079\n\"\n \":(\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1001\n\"\n \"927\n\")))\n", "problem_context": "Score: 200 points\n\nProblem Statement\n\nTakahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it.\n\nThe consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \\times 1.08 yen (rounded down to the nearest integer).\n\nTakahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer.\n\nIf there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.\n\nConstraints\n\n1 \\leq N \\leq 50000\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf there are values that could be X, the price of the apple pie before tax, print any one of them.\n\nIf there are multiple such values, printing any one of them will be accepted.\n\nIf no value could be X, print :(.\n\nSample Input 1\n\n432\n\nSample Output 1\n\n400\n\nIf the apple pie is priced at 400 yen before tax, you have to pay 400 \\times 1.08 = 432 yen to buy one.\n\nOtherwise, the amount you have to pay will not be 432 yen.\n\nSample Input 2\n\n1079\n\nSample Output 2\n\n:(\n\nThere is no possible price before tax for which you have to pay 1079 yen with tax.\n\nSample Input 3\n\n1001\n\nSample Output 3\n\n927\n\nIf the apple pie is priced 927 yen before tax, by rounding down 927 \\times 1.08 = 1001.16, you have to pay 1001 yen.", "sample_input": "432\n"}, "reference_outputs": ["400\n"], "source_document_id": "p02842", "source_text": "Score: 200 points\n\nProblem Statement\n\nTakahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it.\n\nThe consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \\times 1.08 yen (rounded down to the nearest integer).\n\nTakahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer.\n\nIf there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.\n\nConstraints\n\n1 \\leq N \\leq 50000\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf there are values that could be X, the price of the apple pie before tax, print any one of them.\n\nIf there are multiple such values, printing any one of them will be accepted.\n\nIf no value could be X, print :(.\n\nSample Input 1\n\n432\n\nSample Output 1\n\n400\n\nIf the apple pie is priced at 400 yen before tax, you have to pay 400 \\times 1.08 = 432 yen to buy one.\n\nOtherwise, the amount you have to pay will not be 432 yen.\n\nSample Input 2\n\n1079\n\nSample Output 2\n\n:(\n\nThere is no possible price before tax for which you have to pay 1079 yen with tax.\n\nSample Input 3\n\n1001\n\nSample Output 3\n\n927\n\nIf the apple pie is priced 927 yen before tax, by rounding down 927 \\times 1.08 = 1001.16, you have to pay 1001 yen.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3801, "cpu_time_ms": 363, "memory_kb": 16352}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s762527288", "group_id": "codeNet:p02843", "input_text": "(setq n(read))\n(princ(if(<=(*(mod n 100)21)n)1 0))", "language": "Lisp", "metadata": {"date": 1575292818, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02843.html", "problem_id": "p02843", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02843/input.txt", "sample_output_relpath": "derived/input_output/data/p02843/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02843/Lisp/s762527288.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s762527288", "user_id": "u657913472"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(setq n(read))\n(princ(if(<=(*(mod n 100)21)n)1 0))", "problem_context": "Score: 300 points\n\nProblem Statement\n\nAtCoder Mart sells 1000000 of each of the six items below:\n\nRiceballs, priced at 100 yen (the currency of Japan) each\n\nSandwiches, priced at 101 yen each\n\nCookies, priced at 102 yen each\n\nCakes, priced at 103 yen each\n\nCandies, priced at 104 yen each\n\nComputers, priced at 105 yen each\n\nTakahashi wants to buy some of them that cost exactly X yen in total.\nDetermine whether this is possible.\n\n(Ignore consumption tax.)\n\nConstraints\n\n1 \\leq X \\leq 100000\n\nX is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nIf it is possible to buy some set of items that cost exactly X yen in total, print 1; otherwise, print 0.\n\nSample Input 1\n\n615\n\nSample Output 1\n\n1\n\nFor example, we can buy one of each kind of item, which will cost 100+101+102+103+104+105=615 yen in total.\n\nSample Input 2\n\n217\n\nSample Output 2\n\n0\n\nNo set of items costs 217 yen in total.", "sample_input": "615\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02843", "source_text": "Score: 300 points\n\nProblem Statement\n\nAtCoder Mart sells 1000000 of each of the six items below:\n\nRiceballs, priced at 100 yen (the currency of Japan) each\n\nSandwiches, priced at 101 yen each\n\nCookies, priced at 102 yen each\n\nCakes, priced at 103 yen each\n\nCandies, priced at 104 yen each\n\nComputers, priced at 105 yen each\n\nTakahashi wants to buy some of them that cost exactly X yen in total.\nDetermine whether this is possible.\n\n(Ignore consumption tax.)\n\nConstraints\n\n1 \\leq X \\leq 100000\n\nX is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nIf it is possible to buy some set of items that cost exactly X yen in total, print 1; otherwise, print 0.\n\nSample Input 1\n\n615\n\nSample Output 1\n\n1\n\nFor example, we can buy one of each kind of item, which will cost 100+101+102+103+104+105=615 yen in total.\n\nSample Input 2\n\n217\n\nSample Output 2\n\n0\n\nNo set of items costs 217 yen in total.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 50, "cpu_time_ms": 92, "memory_kb": 8544}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s087215111", "group_id": "codeNet:p02844", "input_text": " (let ((n (read))\n (s '())\n (a (make-array 3 :initial-element 0 :element-type 'fixnum))\n (ans 0))\n (setq s (loop for _ below n collect (read-char)))\n (loop for i below 1000 do\n (progn\n (setf (aref a 2) (floor (/ i 100)))\n (setf (aref a 1) (rem (floor (/ i 10)) 10))\n (setf (aref a 0) (rem i 10))\n (let ((f 0))\n (loop for j in s do\n (progn\n (if (string= j (princ-to-string (aref a f))) (incf f))\n (if (= f 3) (return))\n )\n )\n (if (= f 3) (incf ans))\n )\n )\n )\n \n (format t \"~D~%\" ans)\n )", "language": "Lisp", "metadata": {"date": 1594815555, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02844.html", "problem_id": "p02844", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02844/input.txt", "sample_output_relpath": "derived/input_output/data/p02844/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02844/Lisp/s087215111.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s087215111", "user_id": "u816441392"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": " (let ((n (read))\n (s '())\n (a (make-array 3 :initial-element 0 :element-type 'fixnum))\n (ans 0))\n (setq s (loop for _ below n collect (read-char)))\n (loop for i below 1000 do\n (progn\n (setf (aref a 2) (floor (/ i 100)))\n (setf (aref a 1) (rem (floor (/ i 10)) 10))\n (setf (aref a 0) (rem i 10))\n (let ((f 0))\n (loop for j in s do\n (progn\n (if (string= j (princ-to-string (aref a f))) (incf f))\n (if (= f 3) (return))\n )\n )\n (if (= f 3) (incf ans))\n )\n )\n )\n \n (format t \"~D~%\" ans)\n )", "problem_context": "Score: 400 points\n\nProblem Statement\n\nAtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code.\n\nThe company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code.\n\nHow many different PIN codes can he set this way?\n\nBoth the lucky number and the PIN code may begin with a 0.\n\nConstraints\n\n4 \\leq N \\leq 30000\n\nS is a string of length N consisting of digits.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the number of different PIN codes Takahashi can set.\n\nSample Input 1\n\n4\n0224\n\nSample Output 1\n\n3\n\nTakahashi has the following options:\n\nErase the first digit of S and set 224.\n\nErase the second digit of S and set 024.\n\nErase the third digit of S and set 024.\n\nErase the fourth digit of S and set 022.\n\nThus, he can set three different PIN codes: 022, 024, and 224.\n\nSample Input 2\n\n6\n123123\n\nSample Output 2\n\n17\n\nSample Input 3\n\n19\n3141592653589793238\n\nSample Output 3\n\n329", "sample_input": "4\n0224\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02844", "source_text": "Score: 400 points\n\nProblem Statement\n\nAtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code.\n\nThe company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code.\n\nHow many different PIN codes can he set this way?\n\nBoth the lucky number and the PIN code may begin with a 0.\n\nConstraints\n\n4 \\leq N \\leq 30000\n\nS is a string of length N consisting of digits.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the number of different PIN codes Takahashi can set.\n\nSample Input 1\n\n4\n0224\n\nSample Output 1\n\n3\n\nTakahashi has the following options:\n\nErase the first digit of S and set 224.\n\nErase the second digit of S and set 024.\n\nErase the third digit of S and set 024.\n\nErase the fourth digit of S and set 022.\n\nThus, he can set three different PIN codes: 022, 024, and 224.\n\nSample Input 2\n\n6\n123123\n\nSample Output 2\n\n17\n\nSample Input 3\n\n19\n3141592653589793238\n\nSample Output 3\n\n329", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 794, "cpu_time_ms": 2208, "memory_kb": 78344}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s457450379", "group_id": "codeNet:p02844", "input_text": "(let* ((n (read))\n (s (read-line))\n (a (make-array 3 :initial-element 0))\n (ans 0))\n (loop for i below 1000 do\n (progn\n (setf (aref a 2) (floor (/ i 100)))\n (setf (aref a 1) (rem (floor (/ i 10)) 10))\n (setf (aref a 0) (rem i 10))\n (let ((f 0))\n (loop for j to (- n 1) do\n (progn\n (if (string= (char s j) (princ-to-string (aref a f))) (incf f))\n (if (= f 3) (return))\n )\n )\n (if (= f 3) (incf ans))\n )\n )\n )\n\n (format t \"~D~%\" ans)\n)", "language": "Lisp", "metadata": {"date": 1594739011, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02844.html", "problem_id": "p02844", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02844/input.txt", "sample_output_relpath": "derived/input_output/data/p02844/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02844/Lisp/s457450379.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s457450379", "user_id": "u136500538"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let* ((n (read))\n (s (read-line))\n (a (make-array 3 :initial-element 0))\n (ans 0))\n (loop for i below 1000 do\n (progn\n (setf (aref a 2) (floor (/ i 100)))\n (setf (aref a 1) (rem (floor (/ i 10)) 10))\n (setf (aref a 0) (rem i 10))\n (let ((f 0))\n (loop for j to (- n 1) do\n (progn\n (if (string= (char s j) (princ-to-string (aref a f))) (incf f))\n (if (= f 3) (return))\n )\n )\n (if (= f 3) (incf ans))\n )\n )\n )\n\n (format t \"~D~%\" ans)\n)", "problem_context": "Score: 400 points\n\nProblem Statement\n\nAtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code.\n\nThe company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code.\n\nHow many different PIN codes can he set this way?\n\nBoth the lucky number and the PIN code may begin with a 0.\n\nConstraints\n\n4 \\leq N \\leq 30000\n\nS is a string of length N consisting of digits.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the number of different PIN codes Takahashi can set.\n\nSample Input 1\n\n4\n0224\n\nSample Output 1\n\n3\n\nTakahashi has the following options:\n\nErase the first digit of S and set 224.\n\nErase the second digit of S and set 024.\n\nErase the third digit of S and set 024.\n\nErase the fourth digit of S and set 022.\n\nThus, he can set three different PIN codes: 022, 024, and 224.\n\nSample Input 2\n\n6\n123123\n\nSample Output 2\n\n17\n\nSample Input 3\n\n19\n3141592653589793238\n\nSample Output 3\n\n329", "sample_input": "4\n0224\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02844", "source_text": "Score: 400 points\n\nProblem Statement\n\nAtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code.\n\nThe company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code.\n\nHow many different PIN codes can he set this way?\n\nBoth the lucky number and the PIN code may begin with a 0.\n\nConstraints\n\n4 \\leq N \\leq 30000\n\nS is a string of length N consisting of digits.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the number of different PIN codes Takahashi can set.\n\nSample Input 1\n\n4\n0224\n\nSample Output 1\n\n3\n\nTakahashi has the following options:\n\nErase the first digit of S and set 224.\n\nErase the second digit of S and set 024.\n\nErase the third digit of S and set 024.\n\nErase the fourth digit of S and set 022.\n\nThus, he can set three different PIN codes: 022, 024, and 224.\n\nSample Input 2\n\n6\n123123\n\nSample Output 2\n\n17\n\nSample Input 3\n\n19\n3141592653589793238\n\nSample Output 3\n\n329", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 645, "cpu_time_ms": 2208, "memory_kb": 77908}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s485706208", "group_id": "codeNet:p02848", "input_text": "(let ((n (read))\n (s (read-line)))\n (loop :for c :across s\n :do (format t \"~A\" (code-char (+ (mod (+ n (- (char-code c) 65)) 26) 65))))\n (format t \"~%\"))\n", "language": "Lisp", "metadata": {"date": 1593990018, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02848.html", "problem_id": "p02848", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02848/input.txt", "sample_output_relpath": "derived/input_output/data/p02848/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02848/Lisp/s485706208.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s485706208", "user_id": "u608227593"}, "prompt_components": {"gold_output": "CDEZAB\n", "input_to_evaluate": "(let ((n (read))\n (s (read-line)))\n (loop :for c :across s\n :do (format t \"~A\" (code-char (+ (mod (+ n (- (char-code c) 65)) 26) 65))))\n (format t \"~%\"))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have a string S consisting of uppercase English letters. Additionally, an integer N will be given.\n\nShift each character of S by N in alphabetical order (see below), and print the resulting string.\n\nWe assume that A follows Z. For example, shifting A by 2 results in C (A \\to B \\to C), and shifting Y by 3 results in B (Y \\to Z \\to A \\to B).\n\nConstraints\n\n0 \\leq N \\leq 26\n\n1 \\leq |S| \\leq 10^4\n\nS consists of uppercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the string resulting from shifting each character of S by N in alphabetical order.\n\nSample Input 1\n\n2\nABCXYZ\n\nSample Output 1\n\nCDEZAB\n\nNote that A follows Z.\n\nSample Input 2\n\n0\nABCXYZ\n\nSample Output 2\n\nABCXYZ\n\nSample Input 3\n\n13\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n\nSample Output 3\n\nNOPQRSTUVWXYZABCDEFGHIJKLM", "sample_input": "2\nABCXYZ\n"}, "reference_outputs": ["CDEZAB\n"], "source_document_id": "p02848", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have a string S consisting of uppercase English letters. Additionally, an integer N will be given.\n\nShift each character of S by N in alphabetical order (see below), and print the resulting string.\n\nWe assume that A follows Z. For example, shifting A by 2 results in C (A \\to B \\to C), and shifting Y by 3 results in B (Y \\to Z \\to A \\to B).\n\nConstraints\n\n0 \\leq N \\leq 26\n\n1 \\leq |S| \\leq 10^4\n\nS consists of uppercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the string resulting from shifting each character of S by N in alphabetical order.\n\nSample Input 1\n\n2\nABCXYZ\n\nSample Output 1\n\nCDEZAB\n\nNote that A follows Z.\n\nSample Input 2\n\n0\nABCXYZ\n\nSample Output 2\n\nABCXYZ\n\nSample Input 3\n\n13\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n\nSample Output 3\n\nNOPQRSTUVWXYZABCDEFGHIJKLM", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 168, "cpu_time_ms": 20, "memory_kb": 24664}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s394385616", "group_id": "codeNet:p02851", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'uint32))\n (cumuls (make-array (+ n 1) :element-type 'uint62 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (mod (- (read-fixnum) 1) k))\n (setf (aref cumuls (+ i 1))\n (mod (+ (aref cumuls i) (aref as i)) k)))\n (let ((table (make-hash-table :test #'eq))\n (res 0))\n (setf (gethash 0 table) 1)\n #>as\n #>cumuls\n (loop for i from 1 to n\n do (let ((sum (aref cumuls i)))\n (when (>= (- i k) 0)\n (decf (gethash (aref cumuls (- i k)) table)))\n (unless (gethash sum table)\n (setf (gethash sum table) 0))\n (incf res (gethash sum table))\n (incf (gethash sum table))))\n (println res))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 4\n1 4 2 3 5\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8 4\n4 2 4 2 4 2 4 2\n\"\n \"7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 7\n14 15 92 65 35 89 79 32 38 46\n\"\n \"8\n\")))\n", "language": "Lisp", "metadata": {"date": 1574652226, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02851.html", "problem_id": "p02851", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02851/input.txt", "sample_output_relpath": "derived/input_output/data/p02851/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02851/Lisp/s394385616.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s394385616", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'uint32))\n (cumuls (make-array (+ n 1) :element-type 'uint62 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (mod (- (read-fixnum) 1) k))\n (setf (aref cumuls (+ i 1))\n (mod (+ (aref cumuls i) (aref as i)) k)))\n (let ((table (make-hash-table :test #'eq))\n (res 0))\n (setf (gethash 0 table) 1)\n #>as\n #>cumuls\n (loop for i from 1 to n\n do (let ((sum (aref cumuls i)))\n (when (>= (- i k) 0)\n (decf (gethash (aref cumuls (- i k)) table)))\n (unless (gethash sum table)\n (setf (gethash sum table) 0))\n (incf res (gethash sum table))\n (incf (gethash sum table))))\n (println res))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 4\n1 4 2 3 5\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8 4\n4 2 4 2 4 2 4 2\n\"\n \"7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 7\n14 15 92 65 35 89 79 32 38 46\n\"\n \"8\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nGiven are a sequence of N positive integers A_1, A_2, \\ldots, A_N, and a positive integer K.\n\nFind the number of non-empty contiguous subsequences in A such that the remainder when dividing the sum of its elements by K is equal to the number of its elements. We consider two subsequences different if they are taken from different positions, even if they are equal sequences.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 2\\times 10^5\n\n1 \\leq K \\leq 10^9\n\n1 \\leq A_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 \\cdots A_N\n\nOutput\n\nPrint the number of subsequences that satisfy the condition.\n\nSample Input 1\n\n5 4\n1 4 2 3 5\n\nSample Output 1\n\n4\n\nFour sequences satisfy the condition: (1), (4,2), (1,4,2), and (5).\n\nSample Input 2\n\n8 4\n4 2 4 2 4 2 4 2\n\nSample Output 2\n\n7\n\n(4,2) is counted four times, and (2,4) is counted three times.\n\nSample Input 3\n\n10 7\n14 15 92 65 35 89 79 32 38 46\n\nSample Output 3\n\n8", "sample_input": "5 4\n1 4 2 3 5\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02851", "source_text": "Score : 500 points\n\nProblem Statement\n\nGiven are a sequence of N positive integers A_1, A_2, \\ldots, A_N, and a positive integer K.\n\nFind the number of non-empty contiguous subsequences in A such that the remainder when dividing the sum of its elements by K is equal to the number of its elements. We consider two subsequences different if they are taken from different positions, even if they are equal sequences.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 2\\times 10^5\n\n1 \\leq K \\leq 10^9\n\n1 \\leq A_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 \\cdots A_N\n\nOutput\n\nPrint the number of subsequences that satisfy the condition.\n\nSample Input 1\n\n5 4\n1 4 2 3 5\n\nSample Output 1\n\n4\n\nFour sequences satisfy the condition: (1), (4,2), (1,4,2), and (5).\n\nSample Input 2\n\n8 4\n4 2 4 2 4 2 4 2\n\nSample Output 2\n\n7\n\n(4,2) is counted four times, and (2,4) is counted three times.\n\nSample Input 3\n\n10 7\n14 15 92 65 35 89 79 32 38 46\n\nSample Output 3\n\n8", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6532, "cpu_time_ms": 303, "memory_kb": 37348}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s471229660", "group_id": "codeNet:p02854", "input_text": "(defun solve (n)\n (let ((a (make-array n))\n (l (make-array n))\n (r (make-array n)))\n (dotimes (i n)\n (setf (aref a i) (read)))\n (setf (aref l 0) (aref a 0))\n (setf (aref r (1- n)) (aref a (1- n)))\n (loop for i from 1 below n\n do (setf (aref l i) (+ (aref a i) (aref l (1- i)))))\n (loop for i from (- n 2) downto 0\n do (setf (aref r i) (+ (aref a i) (aref r (1+ i)))))\n (loop for i below (1- n) \n minimize (abs (- (aref l i) (aref r (1+ i)))))))\n\n(princ (solve (read)))", "language": "Lisp", "metadata": {"date": 1581660884, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02854.html", "problem_id": "p02854", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02854/input.txt", "sample_output_relpath": "derived/input_output/data/p02854/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02854/Lisp/s471229660.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s471229660", "user_id": "u672956630"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun solve (n)\n (let ((a (make-array n))\n (l (make-array n))\n (r (make-array n)))\n (dotimes (i n)\n (setf (aref a i) (read)))\n (setf (aref l 0) (aref a 0))\n (setf (aref r (1- n)) (aref a (1- n)))\n (loop for i from 1 below n\n do (setf (aref l i) (+ (aref a i) (aref l (1- i)))))\n (loop for i from (- n 2) downto 0\n do (setf (aref r i) (+ (aref a i) (aref r (1+ i)))))\n (loop for i below (1- n) \n minimize (abs (- (aref l i) (aref r (1+ i)))))))\n\n(princ (solve (read)))", "problem_context": "Score: 200 points\n\nProblem Statement\n\nTakahashi, who works at DISCO, is standing before an iron bar.\nThe bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.\n\nTakahashi wanted to choose a notch and cut the bar at that point into two parts with the same length.\nHowever, this may not be possible as is, so he will do the following operations some number of times before he does the cut:\n\nChoose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).\n\nChoose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.\n\nFind the minimum amount of money needed before cutting the bar into two parts with the same length.\n\nConstraints\n\n2 \\leq N \\leq 200000\n\n1 \\leq A_i \\leq 2020202020\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 A_3 ... A_N\n\nOutput\n\nPrint an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.\n\nSample Input 1\n\n3\n2 4 3\n\nSample Output 1\n\n3\n\nThe initial lengths of the sections are [2, 4, 3] (in millimeters). Takahashi can cut the bar equally after doing the following operations for 3 yen:\n\nShrink the second section from the left. The lengths of the sections are now [2, 3, 3].\n\nShrink the first section from the left. The lengths of the sections are now [1, 3, 3].\n\nShrink the second section from the left. The lengths of the sections are now [1, 2, 3], and we can cut the bar at the second notch from the left into two parts of length 3 each.\n\nSample Input 2\n\n12\n100 104 102 105 103 103 101 105 104 102 104 101\n\nSample Output 2\n\n0", "sample_input": "3\n2 4 3\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02854", "source_text": "Score: 200 points\n\nProblem Statement\n\nTakahashi, who works at DISCO, is standing before an iron bar.\nThe bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.\n\nTakahashi wanted to choose a notch and cut the bar at that point into two parts with the same length.\nHowever, this may not be possible as is, so he will do the following operations some number of times before he does the cut:\n\nChoose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).\n\nChoose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.\n\nFind the minimum amount of money needed before cutting the bar into two parts with the same length.\n\nConstraints\n\n2 \\leq N \\leq 200000\n\n1 \\leq A_i \\leq 2020202020\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 A_3 ... A_N\n\nOutput\n\nPrint an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.\n\nSample Input 1\n\n3\n2 4 3\n\nSample Output 1\n\n3\n\nThe initial lengths of the sections are [2, 4, 3] (in millimeters). Takahashi can cut the bar equally after doing the following operations for 3 yen:\n\nShrink the second section from the left. The lengths of the sections are now [2, 3, 3].\n\nShrink the first section from the left. The lengths of the sections are now [1, 3, 3].\n\nShrink the second section from the left. The lengths of the sections are now [1, 2, 3], and we can cut the bar at the second notch from the left into two parts of length 3 each.\n\nSample Input 2\n\n12\n100 104 102 105 103 103 101 105 104 102 104 101\n\nSample Output 2\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 533, "cpu_time_ms": 623, "memory_kb": 63944}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s220079576", "group_id": "codeNet:p02859", "input_text": "(format t \"~A~%\" (expt (read) 2))\n", "language": "Lisp", "metadata": {"date": 1593994097, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02859.html", "problem_id": "p02859", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02859/input.txt", "sample_output_relpath": "derived/input_output/data/p02859/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02859/Lisp/s220079576.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s220079576", "user_id": "u608227593"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(format t \"~A~%\" (expt (read) 2))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nGiven is an integer r.\n\nHow many times is the area of a circle of radius r larger than the area of a circle of radius 1?\n\nIt can be proved that the answer is always an integer under the constraints given.\n\nConstraints\n\n1 \\leq r \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr\n\nOutput\n\nPrint the area of a circle of radius r, divided by the area of a circle of radius 1, as an integer.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n4\n\nThe area of a circle of radius 2 is 4 times larger than the area of a circle of radius 1.\n\nNote that output must be an integer - for example, 4.0 will not be accepted.\n\nSample Input 2\n\n100\n\nSample Output 2\n\n10000", "sample_input": "2\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02859", "source_text": "Score : 100 points\n\nProblem Statement\n\nGiven is an integer r.\n\nHow many times is the area of a circle of radius r larger than the area of a circle of radius 1?\n\nIt can be proved that the answer is always an integer under the constraints given.\n\nConstraints\n\n1 \\leq r \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr\n\nOutput\n\nPrint the area of a circle of radius r, divided by the area of a circle of radius 1, as an integer.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n4\n\nThe area of a circle of radius 2 is 4 times larger than the area of a circle of radius 1.\n\nNote that output must be an integer - for example, 4.0 will not be accepted.\n\nSample Input 2\n\n100\n\nSample Output 2\n\n10000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 34, "cpu_time_ms": 21, "memory_kb": 23972}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s408390288", "group_id": "codeNet:p02859", "input_text": "(princ (expt (read) 2))", "language": "Lisp", "metadata": {"date": 1587351576, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02859.html", "problem_id": "p02859", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02859/input.txt", "sample_output_relpath": "derived/input_output/data/p02859/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02859/Lisp/s408390288.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s408390288", "user_id": "u334552723"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(princ (expt (read) 2))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nGiven is an integer r.\n\nHow many times is the area of a circle of radius r larger than the area of a circle of radius 1?\n\nIt can be proved that the answer is always an integer under the constraints given.\n\nConstraints\n\n1 \\leq r \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr\n\nOutput\n\nPrint the area of a circle of radius r, divided by the area of a circle of radius 1, as an integer.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n4\n\nThe area of a circle of radius 2 is 4 times larger than the area of a circle of radius 1.\n\nNote that output must be an integer - for example, 4.0 will not be accepted.\n\nSample Input 2\n\n100\n\nSample Output 2\n\n10000", "sample_input": "2\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02859", "source_text": "Score : 100 points\n\nProblem Statement\n\nGiven is an integer r.\n\nHow many times is the area of a circle of radius r larger than the area of a circle of radius 1?\n\nIt can be proved that the answer is always an integer under the constraints given.\n\nConstraints\n\n1 \\leq r \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr\n\nOutput\n\nPrint the area of a circle of radius r, divided by the area of a circle of radius 1, as an integer.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n4\n\nThe area of a circle of radius 2 is 4 times larger than the area of a circle of radius 1.\n\nNote that output must be an integer - for example, 4.0 will not be accepted.\n\nSample Input 2\n\n100\n\nSample Output 2\n\n10000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 23, "cpu_time_ms": 6, "memory_kb": 2792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s161173478", "group_id": "codeNet:p02859", "input_text": "(let\n ((r (read)))\n (princ (* r r)))", "language": "Lisp", "metadata": {"date": 1573956644, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02859.html", "problem_id": "p02859", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02859/input.txt", "sample_output_relpath": "derived/input_output/data/p02859/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02859/Lisp/s161173478.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s161173478", "user_id": "u046178504"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let\n ((r (read)))\n (princ (* r r)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nGiven is an integer r.\n\nHow many times is the area of a circle of radius r larger than the area of a circle of radius 1?\n\nIt can be proved that the answer is always an integer under the constraints given.\n\nConstraints\n\n1 \\leq r \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr\n\nOutput\n\nPrint the area of a circle of radius r, divided by the area of a circle of radius 1, as an integer.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n4\n\nThe area of a circle of radius 2 is 4 times larger than the area of a circle of radius 1.\n\nNote that output must be an integer - for example, 4.0 will not be accepted.\n\nSample Input 2\n\n100\n\nSample Output 2\n\n10000", "sample_input": "2\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02859", "source_text": "Score : 100 points\n\nProblem Statement\n\nGiven is an integer r.\n\nHow many times is the area of a circle of radius r larger than the area of a circle of radius 1?\n\nIt can be proved that the answer is always an integer under the constraints given.\n\nConstraints\n\n1 \\leq r \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr\n\nOutput\n\nPrint the area of a circle of radius r, divided by the area of a circle of radius 1, as an integer.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n4\n\nThe area of a circle of radius 2 is 4 times larger than the area of a circle of radius 1.\n\nNote that output must be an integer - for example, 4.0 will not be accepted.\n\nSample Input 2\n\n100\n\nSample Output 2\n\n10000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 40, "cpu_time_ms": 78, "memory_kb": 9316}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s992839351", "group_id": "codeNet:p02860", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (s (read-line)))\n (write-line\n (if (and (evenp n)\n (equal (subseq s 0 (floor n 2))\n (subseq s (floor n 2))))\n \"Yes\"\n \"No\"))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\nabcabc\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\nabcadc\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\nz\n\"\n \"No\n\")))\n", "language": "Lisp", "metadata": {"date": 1573956140, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02860.html", "problem_id": "p02860", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02860/input.txt", "sample_output_relpath": "derived/input_output/data/p02860/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02860/Lisp/s992839351.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s992839351", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (s (read-line)))\n (write-line\n (if (and (evenp n)\n (equal (subseq s 0 (floor n 2))\n (subseq s (floor n 2))))\n \"Yes\"\n \"No\"))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\nabcabc\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\nabcadc\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\nz\n\"\n \"No\n\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven are a positive integer N and a string S of length N consisting of lowercase English letters.\n\nDetermine whether the string is a concatenation of two copies of some string.\nThat is, determine whether there is a string T such that S = T + T.\n\nConstraints\n\n1 \\leq N \\leq 100\n\nS consists of lowercase English letters.\n\n|S| = N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nIf S is a concatenation of two copies of some string, print Yes; otherwise, print No.\n\nSample Input 1\n\n6\nabcabc\n\nSample Output 1\n\nYes\n\nLet T = abc, and S = T + T.\n\nSample Input 2\n\n6\nabcadc\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n1\nz\n\nSample Output 3\n\nNo", "sample_input": "6\nabcabc\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02860", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven are a positive integer N and a string S of length N consisting of lowercase English letters.\n\nDetermine whether the string is a concatenation of two copies of some string.\nThat is, determine whether there is a string T such that S = T + T.\n\nConstraints\n\n1 \\leq N \\leq 100\n\nS consists of lowercase English letters.\n\n|S| = N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nIf S is a concatenation of two copies of some string, print Yes; otherwise, print No.\n\nSample Input 1\n\n6\nabcabc\n\nSample Output 1\n\nYes\n\nLet T = abc, and S = T + T.\n\nSample Input 2\n\n6\nabcadc\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n1\nz\n\nSample Output 3\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3838, "cpu_time_ms": 187, "memory_kb": 19172}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s907402612", "group_id": "codeNet:p02864", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def orf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (hs (make-array n :element-type 'uint32))\n (dp (make-array '(301 301)\n :element-type 'uint62\n :initial-element #.(expt 10 14))))\n (declare (uint16 n k))\n (dotimes (i n)\n (setf (aref hs i) (read)))\n (setf (aref dp 0 0) 0)\n (loop\n for x from 1 to n\n do (loop\n for y from 1 to n\n do (setf (aref dp x y)\n (loop\n for i from 0 below x\n minimize (+ (aref dp i (- y 1))\n (max 0\n (- (aref hs (- x 1))\n (if (zerop i)\n 0\n (aref hs (- i 1))))))))))\n (println\n (loop for x to n\n minimize (loop for y from (- n k) to n\n minimize (aref dp x y))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 1\n2 3 4 1\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 2\n8 6 9 1 2 1\n\"\n \"7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 0\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000\n\"\n \"4999999996\n\")))\n", "language": "Lisp", "metadata": {"date": 1573974063, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02864.html", "problem_id": "p02864", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02864/input.txt", "sample_output_relpath": "derived/input_output/data/p02864/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02864/Lisp/s907402612.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s907402612", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def orf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (hs (make-array n :element-type 'uint32))\n (dp (make-array '(301 301)\n :element-type 'uint62\n :initial-element #.(expt 10 14))))\n (declare (uint16 n k))\n (dotimes (i n)\n (setf (aref hs i) (read)))\n (setf (aref dp 0 0) 0)\n (loop\n for x from 1 to n\n do (loop\n for y from 1 to n\n do (setf (aref dp x y)\n (loop\n for i from 0 below x\n minimize (+ (aref dp i (- y 1))\n (max 0\n (- (aref hs (- x 1))\n (if (zerop i)\n 0\n (aref hs (- i 1))))))))))\n (println\n (loop for x to n\n minimize (loop for y from (- n k) to n\n minimize (aref dp x y))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 1\n2 3 4 1\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 2\n8 6 9 1 2 1\n\"\n \"7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 0\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000\n\"\n \"4999999996\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nWe will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns.\n\nThe current plan is as follows: for the i-th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column.\n\nBefore starting to work, you can choose at most K columns (possibly zero) and change the values of H_i for these columns to any integers of your choice between 0 and 10^9 (inclusive).\n\nDifferent values can be chosen for different columns.\n\nThen, you will create the modified artwork by repeating the following operation:\n\nChoose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)\n\nFind the minimum number of times you need to perform this operation.\n\nConstraints\n\n1 \\leq N \\leq 300\n\n0 \\leq K \\leq N\n\n0 \\leq H_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nH_1 H_2 ... H_N\n\nOutput\n\nPrint the minimum number of operations required.\n\nSample Input 1\n\n4 1\n2 3 4 1\n\nSample Output 1\n\n3\n\nFor example, by changing the value of H_3 to 2, you can create the modified artwork by the following three operations:\n\nPaint black the 1-st through 4-th squares from the left in the 1-st row from the bottom.\n\nPaint black the 1-st through 3-rd squares from the left in the 2-nd row from the bottom.\n\nPaint black the 2-nd square from the left in the 3-rd row from the bottom.\n\nSample Input 2\n\n6 2\n8 6 9 1 2 1\n\nSample Output 2\n\n7\n\nSample Input 3\n\n10 0\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000\n\nSample Output 3\n\n4999999996", "sample_input": "4 1\n2 3 4 1\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02864", "source_text": "Score : 600 points\n\nProblem Statement\n\nWe will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns.\n\nThe current plan is as follows: for the i-th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column.\n\nBefore starting to work, you can choose at most K columns (possibly zero) and change the values of H_i for these columns to any integers of your choice between 0 and 10^9 (inclusive).\n\nDifferent values can be chosen for different columns.\n\nThen, you will create the modified artwork by repeating the following operation:\n\nChoose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)\n\nFind the minimum number of times you need to perform this operation.\n\nConstraints\n\n1 \\leq N \\leq 300\n\n0 \\leq K \\leq N\n\n0 \\leq H_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nH_1 H_2 ... H_N\n\nOutput\n\nPrint the minimum number of operations required.\n\nSample Input 1\n\n4 1\n2 3 4 1\n\nSample Output 1\n\n3\n\nFor example, by changing the value of H_3 to 2, you can create the modified artwork by the following three operations:\n\nPaint black the 1-st through 4-th squares from the left in the 1-st row from the bottom.\n\nPaint black the 1-st through 3-rd squares from the left in the 2-nd row from the bottom.\n\nPaint black the 2-nd square from the left in the 3-rd row from the bottom.\n\nSample Input 2\n\n6 2\n8 6 9 1 2 1\n\nSample Output 2\n\n7\n\nSample Input 3\n\n10 0\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000\n\nSample Output 3\n\n4999999996", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4917, "cpu_time_ms": 227, "memory_kb": 28644}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s508468108", "group_id": "codeNet:p02866", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline power-mod))\n(defun power-mod (base power modulus)\n \"BASE := integer\nPOWER, MODULUS := non-negative fixnum\"\n (declare ((integer 0 #.most-positive-fixnum) modulus power)\n (integer base))\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) x p)\n (values (integer 0 #.most-positive-fixnum)))\n (cond ((zerop p) 1)\n ((evenp p) (recur (mod (* x x) modulus) (ash p -1)))\n (t (mod (* x (recur x (- p 1))) modulus)))))\n (recur (mod base modulus) power)))\n\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(defun map-run-length (function seq &key (test #'eql))\n \"Applies FUNCTION to each equal successive element of SEQ. FUNCTION must take\ntwo arguments: the first one receives an element in SEQ and the second one\nreceives the number of the successive elements equal to the first.\n\nExample: (map-run-length (lambda (x c) (format t \\\"~D ~D~%\\\" x c)) #(1 1 1 2 2 1 3))\n1 3\n2 2\n1 1\n3 1\n\"\n (declare (sequence seq)\n (function test function))\n (etypecase seq\n (vector\n (unless (zerop (length seq))\n (let ((prev (aref seq 0))\n (start 0))\n (loop for pos from 1 below (length seq)\n unless (funcall test prev (aref seq pos))\n do (funcall function prev (- pos start))\n (setf prev (aref seq pos)\n start pos)\n finally (funcall function prev (- pos start))))))\n (list\n (when (cdr seq)\n (labels ((recur (lst prev count)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null lst)\n (funcall function prev count))\n ((funcall test prev (car lst))\n (recur (cdr lst) prev (+ 1 count)))\n (t (funcall function prev count)\n (recur (cdr lst) (car lst) 1)))))\n (recur (cdr seq) (car seq) 1))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 998244353)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n(defun main ()\n (let* ((n (read))\n (ds (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (setf (aref ds i) (read-fixnum)))\n (unless (and (zerop (aref ds 0)) (= 1 (count 0 ds)))\n (println 0)\n (return-from main))\n (setq ds (sort ds #'<))\n (let ((prev-dist -1)\n (prev-num 1)\n (res 1))\n (map-run-length\n (lambda (dist num)\n (unless (= dist (+ prev-dist 1))\n (println 0)\n (return-from main))\n (mulfmod res (power-mod prev-num num +mod+))\n (setq prev-dist dist\n prev-num num))\n ds)\n (println res))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n0 1 1 2\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 1 1 1\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\n0 3 2 1 2 2 1\n\"\n \"24\n\")))\n", "language": "Lisp", "metadata": {"date": 1573351756, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02866.html", "problem_id": "p02866", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02866/input.txt", "sample_output_relpath": "derived/input_output/data/p02866/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02866/Lisp/s508468108.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s508468108", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline power-mod))\n(defun power-mod (base power modulus)\n \"BASE := integer\nPOWER, MODULUS := non-negative fixnum\"\n (declare ((integer 0 #.most-positive-fixnum) modulus power)\n (integer base))\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) x p)\n (values (integer 0 #.most-positive-fixnum)))\n (cond ((zerop p) 1)\n ((evenp p) (recur (mod (* x x) modulus) (ash p -1)))\n (t (mod (* x (recur x (- p 1))) modulus)))))\n (recur (mod base modulus) power)))\n\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(defun map-run-length (function seq &key (test #'eql))\n \"Applies FUNCTION to each equal successive element of SEQ. FUNCTION must take\ntwo arguments: the first one receives an element in SEQ and the second one\nreceives the number of the successive elements equal to the first.\n\nExample: (map-run-length (lambda (x c) (format t \\\"~D ~D~%\\\" x c)) #(1 1 1 2 2 1 3))\n1 3\n2 2\n1 1\n3 1\n\"\n (declare (sequence seq)\n (function test function))\n (etypecase seq\n (vector\n (unless (zerop (length seq))\n (let ((prev (aref seq 0))\n (start 0))\n (loop for pos from 1 below (length seq)\n unless (funcall test prev (aref seq pos))\n do (funcall function prev (- pos start))\n (setf prev (aref seq pos)\n start pos)\n finally (funcall function prev (- pos start))))))\n (list\n (when (cdr seq)\n (labels ((recur (lst prev count)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null lst)\n (funcall function prev count))\n ((funcall test prev (car lst))\n (recur (cdr lst) prev (+ 1 count)))\n (t (funcall function prev count)\n (recur (cdr lst) (car lst) 1)))))\n (recur (cdr seq) (car seq) 1))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 998244353)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n(defun main ()\n (let* ((n (read))\n (ds (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (setf (aref ds i) (read-fixnum)))\n (unless (and (zerop (aref ds 0)) (= 1 (count 0 ds)))\n (println 0)\n (return-from main))\n (setq ds (sort ds #'<))\n (let ((prev-dist -1)\n (prev-num 1)\n (res 1))\n (map-run-length\n (lambda (dist num)\n (unless (= dist (+ prev-dist 1))\n (println 0)\n (return-from main))\n (mulfmod res (power-mod prev-num num +mod+))\n (setq prev-dist dist\n prev-num num))\n ds)\n (println res))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n0 1 1 2\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 1 1 1\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\n0 3 2 1 2 2 1\n\"\n \"24\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition:\n\nFor every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.\n\nNotes\n\nA tree of N vertices is a connected undirected graph with N vertices and N-1 edges, and the distance between two vertices are the number of edges in the shortest path between them.\n\nTwo trees are considered different if and only if there are two vertices x and y such that there is an edge between x and y in one of those trees and not in the other.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n0 \\leq D_i \\leq N-1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nD_1 D_2 ... D_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n4\n0 1 1 2\n\nSample Output 1\n\n2\n\nFor example, a tree with edges (1,2), (1,3), and (2,4) satisfies the condition.\n\nSample Input 2\n\n4\n1 1 1 1\n\nSample Output 2\n\n0\n\nSample Input 3\n\n7\n0 3 2 1 2 2 1\n\nSample Output 3\n\n24", "sample_input": "4\n0 1 1 2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02866", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition:\n\nFor every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.\n\nNotes\n\nA tree of N vertices is a connected undirected graph with N vertices and N-1 edges, and the distance between two vertices are the number of edges in the shortest path between them.\n\nTwo trees are considered different if and only if there are two vertices x and y such that there is an edge between x and y in one of those trees and not in the other.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n0 \\leq D_i \\leq N-1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nD_1 D_2 ... D_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n4\n0 1 1 2\n\nSample Output 1\n\n2\n\nFor example, a tree with edges (1,2), (1,3), and (2,4) satisfies the condition.\n\nSample Input 2\n\n4\n1 1 1 1\n\nSample Output 2\n\n0\n\nSample Input 3\n\n7\n0 3 2 1 2 2 1\n\nSample Output 3\n\n24", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8141, "cpu_time_ms": 237, "memory_kb": 24164}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s844243037", "group_id": "codeNet:p02867", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline decompose-to-cycles))\n(defun decompose-to-cycles (permutation)\n \"Returns the list of all the cyclic permutations in a given permutation of {0,\n1, ..., N-1}\"\n (declare (vector permutation))\n (let* ((n (length permutation))\n result\n (visited (make-array n :element-type 'bit :initial-element 0)))\n (dotimes (init n)\n (when (zerop (sbit visited init))\n (push (loop for x = init then (aref permutation x)\n until (= (sbit visited x) 1)\n collect x\n do (setf (sbit visited x) 1))\n result)))\n result))\n\n(declaim (inline make-reverse-inverse-table))\n(defun make-inverse-table (vector &key (test #'eql))\n \"Returns a hash-table that assigns each value of the (usually sorted) VECTOR\nof length n to the integers 0, ..., n-1.\"\n (let ((table (make-hash-table :test test :size (length vector))))\n (dotimes (i (length vector) table)\n (setf (gethash (aref vector i) table) i))))\n\n(declaim (inline make-monotone-inverse-table!))\n(defun make-monotone-inverse-table! (vector &key (test #'eql) (order #'<))\n \"Sorts VECTOR, deletes all adjacent duplicates, and returns a hash-table that\nassigns each value of the vector to the integers 0, 1, ...\"\n (declare (function test order)\n (vector vector)\n (inline sort))\n (setq vector (sort vector order))\n (let ((table (make-hash-table :test test :size (length vector)))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) index))\n (dotimes (pos (length vector))\n (when (or (zerop pos)\n (not (funcall test (aref vector pos) (aref vector (- pos 1)))))\n (setf (gethash (aref vector pos) table) index)\n (incf index)))\n (values table index)))\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(declaim (inline delete-adjacent-duplicates))\n(defun delete-adjacent-duplicates (seq &key (test #'eql))\n \"Destructively deletes adjacent duplicates of SEQ: e.g. #(1 1 1 2 2 1 3) ->\n#(1 2 1 3)\"\n (declare (sequence seq)\n (function test))\n (etypecase seq\n (vector\n (if (zerop (length seq))\n seq\n (let ((prev (aref seq 0))\n (end 1))\n (loop for pos from 1 below (length seq)\n unless (funcall test prev (aref seq pos))\n do (setf prev (aref seq pos)\n (aref seq end) (aref seq pos)\n end (+ 1 end)))\n ;; KLUDGE: Resorting to ADJUST-ARRAY is maybe substandard. \n (if (array-has-fill-pointer-p seq)\n (adjust-array seq end :fill-pointer end)\n (adjust-array seq end)))))\n (list\n (loop for rest on seq\n unless (and (cdr rest)\n (funcall test (first rest) (second rest)))\n collect (car rest)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n (bs (make-array n :element-type 'uint31))\n (pairs (make-array n :element-type '(cons uint32 uint32))))\n (dotimes (i n)\n (let ((a (read-fixnum)))\n (setf (aref as i) a)))\n (dotimes (i n)\n (let ((b (read-fixnum)))\n (setf (aref bs i) b)))\n (dotimes (i n)\n (setf (aref pairs i)\n (cons (aref as i) (aref bs i))))\n (setq pairs (sort pairs (lambda (x y) (< (the uint31 x) (the uint31 y))) :key #'cdr))\n (let ((new-as (make-array n :element-type 'uint31))\n (sorted-as (sort (copy-seq as) #'<))\n (sorted-bs (sort (copy-seq bs) #'<)))\n (declare ((simple-array uint31 (*)) sorted-as sorted-bs))\n (dotimes (i n)\n (setf (aref new-as i) (car (aref pairs i))))\n (when (loop for a across sorted-as\n for b across sorted-bs\n thereis (> a b))\n (write-line \"No\")\n (return-from main))\n (when (< (length (delete-adjacent-duplicates (copy-seq sorted-as)))\n n)\n (write-line \"Yes\")\n (return-from main))\n (let ((table (make-monotone-inverse-table! (copy-seq as)))\n (comped-as (make-array n :element-type 'uint31)))\n (dotimes (i n)\n (setf (aref comped-as i)\n (gethash (aref new-as i) table)))\n (when (< 1 (length (decompose-to-cycles comped-as)))\n (write-line \"Yes\")\n (return-from main)))\n (loop for i from 0 below (- n 1)\n when (<= (aref new-as (+ i 1))\n (aref sorted-bs i))\n do (write-line \"Yes\")\n (return-from main))\n (write-line \"No\"))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 3 2\n1 2 3\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2 3\n2 2 2\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n3 1 2 6 3 4\n2 2 8 3 4 3\n\"\n \"Yes\n\")))\n", "language": "Lisp", "metadata": {"date": 1573448428, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02867.html", "problem_id": "p02867", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02867/input.txt", "sample_output_relpath": "derived/input_output/data/p02867/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02867/Lisp/s844243037.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s844243037", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline decompose-to-cycles))\n(defun decompose-to-cycles (permutation)\n \"Returns the list of all the cyclic permutations in a given permutation of {0,\n1, ..., N-1}\"\n (declare (vector permutation))\n (let* ((n (length permutation))\n result\n (visited (make-array n :element-type 'bit :initial-element 0)))\n (dotimes (init n)\n (when (zerop (sbit visited init))\n (push (loop for x = init then (aref permutation x)\n until (= (sbit visited x) 1)\n collect x\n do (setf (sbit visited x) 1))\n result)))\n result))\n\n(declaim (inline make-reverse-inverse-table))\n(defun make-inverse-table (vector &key (test #'eql))\n \"Returns a hash-table that assigns each value of the (usually sorted) VECTOR\nof length n to the integers 0, ..., n-1.\"\n (let ((table (make-hash-table :test test :size (length vector))))\n (dotimes (i (length vector) table)\n (setf (gethash (aref vector i) table) i))))\n\n(declaim (inline make-monotone-inverse-table!))\n(defun make-monotone-inverse-table! (vector &key (test #'eql) (order #'<))\n \"Sorts VECTOR, deletes all adjacent duplicates, and returns a hash-table that\nassigns each value of the vector to the integers 0, 1, ...\"\n (declare (function test order)\n (vector vector)\n (inline sort))\n (setq vector (sort vector order))\n (let ((table (make-hash-table :test test :size (length vector)))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) index))\n (dotimes (pos (length vector))\n (when (or (zerop pos)\n (not (funcall test (aref vector pos) (aref vector (- pos 1)))))\n (setf (gethash (aref vector pos) table) index)\n (incf index)))\n (values table index)))\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(declaim (inline delete-adjacent-duplicates))\n(defun delete-adjacent-duplicates (seq &key (test #'eql))\n \"Destructively deletes adjacent duplicates of SEQ: e.g. #(1 1 1 2 2 1 3) ->\n#(1 2 1 3)\"\n (declare (sequence seq)\n (function test))\n (etypecase seq\n (vector\n (if (zerop (length seq))\n seq\n (let ((prev (aref seq 0))\n (end 1))\n (loop for pos from 1 below (length seq)\n unless (funcall test prev (aref seq pos))\n do (setf prev (aref seq pos)\n (aref seq end) (aref seq pos)\n end (+ 1 end)))\n ;; KLUDGE: Resorting to ADJUST-ARRAY is maybe substandard. \n (if (array-has-fill-pointer-p seq)\n (adjust-array seq end :fill-pointer end)\n (adjust-array seq end)))))\n (list\n (loop for rest on seq\n unless (and (cdr rest)\n (funcall test (first rest) (second rest)))\n collect (car rest)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n (bs (make-array n :element-type 'uint31))\n (pairs (make-array n :element-type '(cons uint32 uint32))))\n (dotimes (i n)\n (let ((a (read-fixnum)))\n (setf (aref as i) a)))\n (dotimes (i n)\n (let ((b (read-fixnum)))\n (setf (aref bs i) b)))\n (dotimes (i n)\n (setf (aref pairs i)\n (cons (aref as i) (aref bs i))))\n (setq pairs (sort pairs (lambda (x y) (< (the uint31 x) (the uint31 y))) :key #'cdr))\n (let ((new-as (make-array n :element-type 'uint31))\n (sorted-as (sort (copy-seq as) #'<))\n (sorted-bs (sort (copy-seq bs) #'<)))\n (declare ((simple-array uint31 (*)) sorted-as sorted-bs))\n (dotimes (i n)\n (setf (aref new-as i) (car (aref pairs i))))\n (when (loop for a across sorted-as\n for b across sorted-bs\n thereis (> a b))\n (write-line \"No\")\n (return-from main))\n (when (< (length (delete-adjacent-duplicates (copy-seq sorted-as)))\n n)\n (write-line \"Yes\")\n (return-from main))\n (let ((table (make-monotone-inverse-table! (copy-seq as)))\n (comped-as (make-array n :element-type 'uint31)))\n (dotimes (i n)\n (setf (aref comped-as i)\n (gethash (aref new-as i) table)))\n (when (< 1 (length (decompose-to-cycles comped-as)))\n (write-line \"Yes\")\n (return-from main)))\n (loop for i from 0 below (- n 1)\n when (<= (aref new-as (+ i 1))\n (aref sorted-bs i))\n do (write-line \"Yes\")\n (return-from main))\n (write-line \"No\"))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 3 2\n1 2 3\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2 3\n2 2 2\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n3 1 2 6 3 4\n2 2 8 3 4 3\n\"\n \"Yes\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven are two integer sequences of N elements each: A_1,...,A_N and B_1,...,B_N.\nDetermine if it is possible to do the following operation at most N-2 times (possibly zero) so that, for every integer i from 1 to N, A_i \\leq B_i holds:\n\nChoose two distinct integers x and y between 1 and N (inclusive), and swap the values of A_x and A_y.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq A_i,B_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\nB_1 B_2 ... B_N\n\nOutput\n\nIf the objective is achievable, print Yes; if it is not, print No.\n\nSample Input 1\n\n3\n1 3 2\n1 2 3\n\nSample Output 1\n\nYes\n\nWe should swap the values of A_2 and A_3.\n\nSample Input 2\n\n3\n1 2 3\n2 2 2\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n6\n3 1 2 6 3 4\n2 2 8 3 4 3\n\nSample Output 3\n\nYes", "sample_input": "3\n1 3 2\n1 2 3\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02867", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are two integer sequences of N elements each: A_1,...,A_N and B_1,...,B_N.\nDetermine if it is possible to do the following operation at most N-2 times (possibly zero) so that, for every integer i from 1 to N, A_i \\leq B_i holds:\n\nChoose two distinct integers x and y between 1 and N (inclusive), and swap the values of A_x and A_y.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq A_i,B_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\nB_1 B_2 ... B_N\n\nOutput\n\nIf the objective is achievable, print Yes; if it is not, print No.\n\nSample Input 1\n\n3\n1 3 2\n1 2 3\n\nSample Output 1\n\nYes\n\nWe should swap the values of A_2 and A_3.\n\nSample Input 2\n\n3\n1 2 3\n2 2 2\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n6\n3 1 2 6 3 4\n2 2 8 3 4 3\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9201, "cpu_time_ms": 757, "memory_kb": 78952}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s624884395", "group_id": "codeNet:p02867", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline decompose-to-cycles))\n(defun decompose-to-cycles (permutation)\n \"Returns the list of all the cyclic permutations in a given permutation of {0,\n1, ..., N-1}\"\n (declare (vector permutation))\n (let* ((n (length permutation))\n result\n (visited (make-array n :element-type 'bit :initial-element 0)))\n (dotimes (init n)\n (when (zerop (sbit visited init))\n (push (loop for x = init then (aref permutation x)\n until (= (sbit visited x) 1)\n collect x\n do (setf (sbit visited x) 1))\n result)))\n result))\n\n(declaim (inline make-reverse-inverse-table))\n(defun make-inverse-table (vector &key (test #'eql))\n \"Returns a hash-table that assigns each value of the (usually sorted) VECTOR\nof length n to the integers 0, ..., n-1.\"\n (let ((table (make-hash-table :test test :size (length vector))))\n (dotimes (i (length vector) table)\n (setf (gethash (aref vector i) table) i))))\n\n(declaim (inline make-monotone-inverse-table!))\n(defun make-monotone-inverse-table! (vector &key (test #'eql) (order #'<))\n \"Sorts VECTOR, deletes all adjacent duplicates, and returns a hash-table that\nassigns each value of the vector to the integers 0, 1, ...\"\n (declare (function test order)\n (vector vector)\n (inline sort))\n (setq vector (sort vector order))\n (let ((table (make-hash-table :test test :size (length vector)))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) index))\n (dotimes (pos (length vector))\n (when (or (zerop pos)\n (not (funcall test (aref vector pos) (aref vector (- pos 1)))))\n (setf (gethash (aref vector pos) table) index)\n (incf index)))\n (values table index)))\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;;;\n;;; Implicit treap\n;;; (treap with implicit key)\n;;;\n\n;; Note:\n;; - An empty treap is NIL.\n\n(declaim (inline op))\n(defun op (a b)\n \"Is a binary operator comprising a monoid.\"\n (declare (uint62 a b))\n (min a b))\n\n(defconstant +op-identity+ most-positive-fixnum\n \"identity element w.r.t. OP\")\n\n(defstruct (itreap (:constructor %make-itreap (value priority &key left right (count 1) (accumulator value)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (integer 0 #.most-positive-fixnum)) ; size of (sub)treap\n (left nil :type (or null itreap))\n (right nil :type (or null itreap)))\n\n(declaim (inline itreap-count))\n(defun itreap-count (itreap)\n \"Returns the number of the elements.\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-count itreap)\n 0))\n\n(declaim (inline itreap-accumulator))\n(defun itreap-accumulator (itreap)\n \"Returns the sum (w.r.t. OP) of the whole ITREAP:\nITREAP[0]+ITREAP[1]+...+ITREAP[SIZE-1].\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-accumulator itreap)\n +op-identity+))\n\n(declaim (inline update-count))\n(defun update-count (itreap)\n (declare (itreap itreap))\n (setf (%itreap-count itreap)\n (+ 1\n (itreap-count (%itreap-left itreap))\n (itreap-count (%itreap-right itreap)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (itreap)\n (declare (itreap itreap))\n (setf (%itreap-accumulator itreap)\n (if (%itreap-left itreap)\n (if (%itreap-right itreap)\n (let ((mid (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap))))\n (op mid (%itreap-accumulator (%itreap-right itreap))))\n (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap)))\n (if (%itreap-right itreap)\n (op (%itreap-value itreap)\n (%itreap-accumulator (%itreap-right itreap)))\n (%itreap-value itreap)))))\n\n(declaim (inline force-up))\n(defun force-up (itreap)\n \"Propagates up the information from children.\"\n (declare (itreap itreap))\n (update-count itreap)\n (update-accumulator itreap))\n\n(defun %heapify (top)\n \"Properly swaps the priorities of the node and its two children.\"\n (declare (optimize (speed 3) (safety 0)))\n (when top\n (let ((high-priority-node top))\n (when (and (%itreap-left top)\n (> (%itreap-priority (%itreap-left top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-left top)))\n (when (and (%itreap-right top)\n (> (%itreap-priority (%itreap-right top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-right top)))\n (unless (eql high-priority-node top)\n (rotatef (%itreap-priority high-priority-node)\n (%itreap-priority top))\n (%heapify high-priority-node)))))\n\n(declaim (inline make-itreap))\n(defun make-itreap (size &key initial-contents)\n \"Makes a treap of SIZE in O(SIZE) time. Its values are filled with the\nidentity element unless INITIAL-CONTENTS are supplied.\"\n (declare ((or null vector) initial-contents))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-itreap (if initial-contents\n (aref initial-contents mid)\n +op-identity+)\n (random most-positive-fixnum))))\n (setf (%itreap-left node) (build l mid))\n (setf (%itreap-right node) (build (+ mid 1) r))\n (%heapify node)\n (force-up node)\n node))))\n (build 0 size)))\n\n(defun itreap-split (itreap index)\n \"Destructively splits the ITREAP into two nodes [0, INDEX) and [INDEX, N),\nwhere N is the number of elements of the ITREAP.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) index))\n (unless (<= index (itreap-count itreap))\n (error 'invalid-itreap-index-error :index index :itreap itreap))\n (labels ((recur (itreap ikey)\n (unless itreap\n (return-from itreap-split (values nil nil)))\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= ikey left-count)\n (multiple-value-bind (left right)\n (itreap-split (%itreap-left itreap) ikey)\n (setf (%itreap-left itreap) right)\n (force-up itreap)\n (values left itreap))\n (multiple-value-bind (left right)\n (itreap-split (%itreap-right itreap) (- ikey left-count 1))\n (setf (%itreap-right itreap) left)\n (force-up itreap)\n (values itreap right))))))\n (recur itreap index)))\n\n(defun itreap-merge (left right)\n \"Destructively concatenates two ITREAPs.\"\n (declare #.OPT\n ((or null itreap) left right))\n (cond ((null left) (when right (force-up right)) right)\n ((null right) (when left (force-up left)) left)\n (t (if (> (%itreap-priority left) (%itreap-priority right))\n (progn\n (setf (%itreap-right left)\n (itreap-merge (%itreap-right left) right))\n (force-up left)\n left)\n (progn\n (setf (%itreap-left right)\n (itreap-merge left (%itreap-left right)))\n (force-up right)\n right)))))\n\n(declaim (inline itreap-map))\n(defun itreap-map (function itreap)\n \"Successively applies FUNCTION to ITREAP[0], ..., ITREAP[SIZE-1].\"\n (declare (function function))\n (labels ((recur (node)\n (when node\n (recur (%itreap-left node))\n (funcall function (%itreap-value node))\n (recur (%itreap-right node))\n (force-up node))))\n (recur itreap)))\n\n(defmethod print-object ((object itreap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (itreap-map (lambda (x)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write x :stream stream))\n object))))\n\n(declaim (inline itreap-ref))\n(defun itreap-ref (itreap index)\n \"Returns the element ITREAP[INDEX].\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index index))\n (labels ((%ref (itreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (prog1\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (cond ((< index left-count)\n (%ref (%itreap-left itreap) index))\n ((> index left-count)\n (%ref (%itreap-right itreap) (- index left-count 1)))\n (t (%itreap-value itreap))))\n (force-up itreap))))\n (%ref itreap index)))\n\n(declaim (inline (setf itreap-ref)))\n(defun (setf itreap-ref) (new-value itreap index)\n \"Sets ITREAP[INDEX] to the given value.\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index index))\n (labels ((%set (itreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (prog1\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (cond ((< index left-count)\n (%set (%itreap-left itreap) index))\n ((> index left-count)\n (%set (%itreap-right itreap) (- index left-count 1)))\n (t (setf (%itreap-value itreap) new-value))))\n (force-up itreap))))\n (%set itreap index)\n new-value))\n\n(declaim (inline itreap-query))\n(defun itreap-query (itreap l r)\n \"Queries the `sum' (w.r.t. OP) of the range ITREAP[L, R).\"\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless (<= l r (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index (cons l r)))\n (labels\n ((recur (itreap l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless itreap\n (return-from recur +op-identity+))\n (prog1\n (if (and (zerop l) (= r (%itreap-count itreap)))\n (itreap-accumulator itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= l left-count)\n (if (< left-count r)\n ;; LEFT-COUNT is in [L, R)\n (op (op (recur (%itreap-left itreap) l (min r left-count))\n (%itreap-value itreap))\n (recur (%itreap-right itreap) 0 (- r left-count 1)))\n ;; LEFT-COUNT is in [R, END)\n (recur (%itreap-left itreap) l (min r left-count)))\n ;; LEFT-COUNT is in [0, L)\n (recur (%itreap-right itreap) (- l left-count 1) (- r left-count 1)))))\n (force-up itreap))))\n (recur itreap l r)))\n\n;; FIXME: might be problematic when two priorities collide and START is not\n;; zero. (It will be negligible from the viewpoint of probability, however.)\n(declaim (inline itreap-range-bisect-left))\n(defun itreap-range-bisect-left (itreap value order &optional (start 0))\n \"Returns the smallest index that satisfies ITREAP[START]+ ITREAP[START+1] +\n... + ITREAP[index] >= VALUE (if ORDER is #'<).\n\nNote:\n- This function handles a **closed** interval.\n- This function returns the length of ITREAP instead if ITREAP[START]+\n... +ITREAP[length-1] < VALUE.\n- The prefix sums of ITREAP, (ITREAP[START], ITREAP[START]+ITREAP[START+1], ...)\n must be monotone w.r.t. ORDER.\n- ORDER must be a strict order\"\n (declare ((integer 0 #.most-positive-fixnum) start))\n (multiple-value-bind (itreap-prefix itreap)\n (if (zerop start)\n (values nil itreap)\n (itreap-split itreap start))\n (labels\n ((recur (itreap offset prev-sum)\n (declare ((integer 0 #.most-positive-fixnum) offset)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (unless itreap\n (return-from recur offset))\n (let ((sum prev-sum))\n (prog1\n (cond ((not (funcall order\n (setq sum (op sum (itreap-accumulator (%itreap-left itreap))))\n value))\n (recur (%itreap-left itreap) offset prev-sum))\n ((not (funcall order\n (setq sum (op sum (%itreap-value itreap)))\n value))\n (+ offset (itreap-count (%itreap-left itreap))))\n (t\n (recur (%itreap-right itreap)\n (+ offset (itreap-count (%itreap-left itreap)) 1)\n sum)))\n (force-up itreap)))))\n (prog1 (+ start (recur itreap 0 +op-identity+))\n (itreap-merge itreap-prefix itreap)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(declaim (inline delete-adjacent-duplicates))\n(defun delete-adjacent-duplicates (seq &key (test #'eql))\n \"Destructively deletes adjacent duplicates of SEQ: e.g. #(1 1 1 2 2 1 3) ->\n#(1 2 1 3)\"\n (declare (sequence seq)\n (function test))\n (etypecase seq\n (vector\n (if (zerop (length seq))\n seq\n (let ((prev (aref seq 0))\n (end 1))\n (loop for pos from 1 below (length seq)\n unless (funcall test prev (aref seq pos))\n do (setf prev (aref seq pos)\n (aref seq end) (aref seq pos)\n end (+ 1 end)))\n ;; KLUDGE: Resorting to ADJUST-ARRAY is maybe substandard. \n (if (array-has-fill-pointer-p seq)\n (adjust-array seq end :fill-pointer end)\n (adjust-array seq end)))))\n (list\n (loop for rest on seq\n unless (and (cdr rest)\n (funcall test (first rest) (second rest)))\n collect (car rest)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n (bs (make-array n :element-type 'uint31))\n (pairs (make-array n :element-type '(cons uint32 uint32))))\n (dotimes (i n)\n (let ((a (read-fixnum)))\n (setf (aref as i) a)))\n (dotimes (i n)\n (let ((b (read-fixnum)))\n (setf (aref bs i) b)))\n (dotimes (i n)\n (setf (aref pairs i)\n (cons (aref as i) (aref bs i))))\n (setq pairs (sort pairs (lambda (x y) (< (the uint31 x) (the uint31 y))) :key #'cdr))\n (let ((new-as (make-array n :element-type 'uint31))\n (sorted-as (sort (copy-seq as) #'<))\n (sorted-bs (sort (copy-seq bs) #'<)))\n (declare ((simple-array uint31 (*)) sorted-as sorted-bs))\n (dotimes (i n)\n (setf (aref new-as i) (car (aref pairs i))))\n (when (loop for a across sorted-as\n for b across sorted-bs\n thereis (> a b))\n (write-line \"No\")\n (return-from main))\n (when (< (length (delete-adjacent-duplicates (copy-seq sorted-as)))\n n)\n (write-line \"Yes\")\n (return-from main))\n (let ((dp (make-itreap n :initial-contents new-as))\n (pos 0))\n (dotimes (i (- n 2))\n (loop while (and (< pos n)\n (<= (itreap-ref dp pos) (aref sorted-bs pos)))\n do (incf pos))\n (when (= pos n)\n (return))\n (let* ((new-min (itreap-query dp pos n))\n (min-pos (itreap-range-bisect-left dp new-min #'> pos)))\n (rotatef (itreap-ref dp pos)\n (itreap-ref dp min-pos))))\n (when (loop for i below n\n always (<= (itreap-ref dp i) (aref sorted-bs i)))\n (write-line \"Yes\")\n (return-from main)))\n (let ((table (make-monotone-inverse-table! (copy-seq as)))\n (comped-as (make-array n :element-type 'uint31)))\n (dotimes (i n)\n (setf (aref comped-as i)\n (gethash (aref as i) table)))\n (if (= 1 (length (decompose-to-cycles comped-as)))\n (write-line \"No\")\n (write-line \"Yes\"))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 3 2\n1 2 3\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2 3\n2 2 2\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n3 1 2 6 3 4\n2 2 8 3 4 3\n\"\n \"Yes\n\")))\n", "language": "Lisp", "metadata": {"date": 1573368598, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02867.html", "problem_id": "p02867", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02867/input.txt", "sample_output_relpath": "derived/input_output/data/p02867/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02867/Lisp/s624884395.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s624884395", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline decompose-to-cycles))\n(defun decompose-to-cycles (permutation)\n \"Returns the list of all the cyclic permutations in a given permutation of {0,\n1, ..., N-1}\"\n (declare (vector permutation))\n (let* ((n (length permutation))\n result\n (visited (make-array n :element-type 'bit :initial-element 0)))\n (dotimes (init n)\n (when (zerop (sbit visited init))\n (push (loop for x = init then (aref permutation x)\n until (= (sbit visited x) 1)\n collect x\n do (setf (sbit visited x) 1))\n result)))\n result))\n\n(declaim (inline make-reverse-inverse-table))\n(defun make-inverse-table (vector &key (test #'eql))\n \"Returns a hash-table that assigns each value of the (usually sorted) VECTOR\nof length n to the integers 0, ..., n-1.\"\n (let ((table (make-hash-table :test test :size (length vector))))\n (dotimes (i (length vector) table)\n (setf (gethash (aref vector i) table) i))))\n\n(declaim (inline make-monotone-inverse-table!))\n(defun make-monotone-inverse-table! (vector &key (test #'eql) (order #'<))\n \"Sorts VECTOR, deletes all adjacent duplicates, and returns a hash-table that\nassigns each value of the vector to the integers 0, 1, ...\"\n (declare (function test order)\n (vector vector)\n (inline sort))\n (setq vector (sort vector order))\n (let ((table (make-hash-table :test test :size (length vector)))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) index))\n (dotimes (pos (length vector))\n (when (or (zerop pos)\n (not (funcall test (aref vector pos) (aref vector (- pos 1)))))\n (setf (gethash (aref vector pos) table) index)\n (incf index)))\n (values table index)))\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;;;\n;;; Implicit treap\n;;; (treap with implicit key)\n;;;\n\n;; Note:\n;; - An empty treap is NIL.\n\n(declaim (inline op))\n(defun op (a b)\n \"Is a binary operator comprising a monoid.\"\n (declare (uint62 a b))\n (min a b))\n\n(defconstant +op-identity+ most-positive-fixnum\n \"identity element w.r.t. OP\")\n\n(defstruct (itreap (:constructor %make-itreap (value priority &key left right (count 1) (accumulator value)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (integer 0 #.most-positive-fixnum)) ; size of (sub)treap\n (left nil :type (or null itreap))\n (right nil :type (or null itreap)))\n\n(declaim (inline itreap-count))\n(defun itreap-count (itreap)\n \"Returns the number of the elements.\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-count itreap)\n 0))\n\n(declaim (inline itreap-accumulator))\n(defun itreap-accumulator (itreap)\n \"Returns the sum (w.r.t. OP) of the whole ITREAP:\nITREAP[0]+ITREAP[1]+...+ITREAP[SIZE-1].\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-accumulator itreap)\n +op-identity+))\n\n(declaim (inline update-count))\n(defun update-count (itreap)\n (declare (itreap itreap))\n (setf (%itreap-count itreap)\n (+ 1\n (itreap-count (%itreap-left itreap))\n (itreap-count (%itreap-right itreap)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (itreap)\n (declare (itreap itreap))\n (setf (%itreap-accumulator itreap)\n (if (%itreap-left itreap)\n (if (%itreap-right itreap)\n (let ((mid (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap))))\n (op mid (%itreap-accumulator (%itreap-right itreap))))\n (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap)))\n (if (%itreap-right itreap)\n (op (%itreap-value itreap)\n (%itreap-accumulator (%itreap-right itreap)))\n (%itreap-value itreap)))))\n\n(declaim (inline force-up))\n(defun force-up (itreap)\n \"Propagates up the information from children.\"\n (declare (itreap itreap))\n (update-count itreap)\n (update-accumulator itreap))\n\n(defun %heapify (top)\n \"Properly swaps the priorities of the node and its two children.\"\n (declare (optimize (speed 3) (safety 0)))\n (when top\n (let ((high-priority-node top))\n (when (and (%itreap-left top)\n (> (%itreap-priority (%itreap-left top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-left top)))\n (when (and (%itreap-right top)\n (> (%itreap-priority (%itreap-right top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-right top)))\n (unless (eql high-priority-node top)\n (rotatef (%itreap-priority high-priority-node)\n (%itreap-priority top))\n (%heapify high-priority-node)))))\n\n(declaim (inline make-itreap))\n(defun make-itreap (size &key initial-contents)\n \"Makes a treap of SIZE in O(SIZE) time. Its values are filled with the\nidentity element unless INITIAL-CONTENTS are supplied.\"\n (declare ((or null vector) initial-contents))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-itreap (if initial-contents\n (aref initial-contents mid)\n +op-identity+)\n (random most-positive-fixnum))))\n (setf (%itreap-left node) (build l mid))\n (setf (%itreap-right node) (build (+ mid 1) r))\n (%heapify node)\n (force-up node)\n node))))\n (build 0 size)))\n\n(defun itreap-split (itreap index)\n \"Destructively splits the ITREAP into two nodes [0, INDEX) and [INDEX, N),\nwhere N is the number of elements of the ITREAP.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) index))\n (unless (<= index (itreap-count itreap))\n (error 'invalid-itreap-index-error :index index :itreap itreap))\n (labels ((recur (itreap ikey)\n (unless itreap\n (return-from itreap-split (values nil nil)))\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= ikey left-count)\n (multiple-value-bind (left right)\n (itreap-split (%itreap-left itreap) ikey)\n (setf (%itreap-left itreap) right)\n (force-up itreap)\n (values left itreap))\n (multiple-value-bind (left right)\n (itreap-split (%itreap-right itreap) (- ikey left-count 1))\n (setf (%itreap-right itreap) left)\n (force-up itreap)\n (values itreap right))))))\n (recur itreap index)))\n\n(defun itreap-merge (left right)\n \"Destructively concatenates two ITREAPs.\"\n (declare #.OPT\n ((or null itreap) left right))\n (cond ((null left) (when right (force-up right)) right)\n ((null right) (when left (force-up left)) left)\n (t (if (> (%itreap-priority left) (%itreap-priority right))\n (progn\n (setf (%itreap-right left)\n (itreap-merge (%itreap-right left) right))\n (force-up left)\n left)\n (progn\n (setf (%itreap-left right)\n (itreap-merge left (%itreap-left right)))\n (force-up right)\n right)))))\n\n(declaim (inline itreap-map))\n(defun itreap-map (function itreap)\n \"Successively applies FUNCTION to ITREAP[0], ..., ITREAP[SIZE-1].\"\n (declare (function function))\n (labels ((recur (node)\n (when node\n (recur (%itreap-left node))\n (funcall function (%itreap-value node))\n (recur (%itreap-right node))\n (force-up node))))\n (recur itreap)))\n\n(defmethod print-object ((object itreap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (itreap-map (lambda (x)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write x :stream stream))\n object))))\n\n(declaim (inline itreap-ref))\n(defun itreap-ref (itreap index)\n \"Returns the element ITREAP[INDEX].\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index index))\n (labels ((%ref (itreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (prog1\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (cond ((< index left-count)\n (%ref (%itreap-left itreap) index))\n ((> index left-count)\n (%ref (%itreap-right itreap) (- index left-count 1)))\n (t (%itreap-value itreap))))\n (force-up itreap))))\n (%ref itreap index)))\n\n(declaim (inline (setf itreap-ref)))\n(defun (setf itreap-ref) (new-value itreap index)\n \"Sets ITREAP[INDEX] to the given value.\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index index))\n (labels ((%set (itreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (prog1\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (cond ((< index left-count)\n (%set (%itreap-left itreap) index))\n ((> index left-count)\n (%set (%itreap-right itreap) (- index left-count 1)))\n (t (setf (%itreap-value itreap) new-value))))\n (force-up itreap))))\n (%set itreap index)\n new-value))\n\n(declaim (inline itreap-query))\n(defun itreap-query (itreap l r)\n \"Queries the `sum' (w.r.t. OP) of the range ITREAP[L, R).\"\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless (<= l r (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index (cons l r)))\n (labels\n ((recur (itreap l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless itreap\n (return-from recur +op-identity+))\n (prog1\n (if (and (zerop l) (= r (%itreap-count itreap)))\n (itreap-accumulator itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= l left-count)\n (if (< left-count r)\n ;; LEFT-COUNT is in [L, R)\n (op (op (recur (%itreap-left itreap) l (min r left-count))\n (%itreap-value itreap))\n (recur (%itreap-right itreap) 0 (- r left-count 1)))\n ;; LEFT-COUNT is in [R, END)\n (recur (%itreap-left itreap) l (min r left-count)))\n ;; LEFT-COUNT is in [0, L)\n (recur (%itreap-right itreap) (- l left-count 1) (- r left-count 1)))))\n (force-up itreap))))\n (recur itreap l r)))\n\n;; FIXME: might be problematic when two priorities collide and START is not\n;; zero. (It will be negligible from the viewpoint of probability, however.)\n(declaim (inline itreap-range-bisect-left))\n(defun itreap-range-bisect-left (itreap value order &optional (start 0))\n \"Returns the smallest index that satisfies ITREAP[START]+ ITREAP[START+1] +\n... + ITREAP[index] >= VALUE (if ORDER is #'<).\n\nNote:\n- This function handles a **closed** interval.\n- This function returns the length of ITREAP instead if ITREAP[START]+\n... +ITREAP[length-1] < VALUE.\n- The prefix sums of ITREAP, (ITREAP[START], ITREAP[START]+ITREAP[START+1], ...)\n must be monotone w.r.t. ORDER.\n- ORDER must be a strict order\"\n (declare ((integer 0 #.most-positive-fixnum) start))\n (multiple-value-bind (itreap-prefix itreap)\n (if (zerop start)\n (values nil itreap)\n (itreap-split itreap start))\n (labels\n ((recur (itreap offset prev-sum)\n (declare ((integer 0 #.most-positive-fixnum) offset)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (unless itreap\n (return-from recur offset))\n (let ((sum prev-sum))\n (prog1\n (cond ((not (funcall order\n (setq sum (op sum (itreap-accumulator (%itreap-left itreap))))\n value))\n (recur (%itreap-left itreap) offset prev-sum))\n ((not (funcall order\n (setq sum (op sum (%itreap-value itreap)))\n value))\n (+ offset (itreap-count (%itreap-left itreap))))\n (t\n (recur (%itreap-right itreap)\n (+ offset (itreap-count (%itreap-left itreap)) 1)\n sum)))\n (force-up itreap)))))\n (prog1 (+ start (recur itreap 0 +op-identity+))\n (itreap-merge itreap-prefix itreap)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(declaim (inline delete-adjacent-duplicates))\n(defun delete-adjacent-duplicates (seq &key (test #'eql))\n \"Destructively deletes adjacent duplicates of SEQ: e.g. #(1 1 1 2 2 1 3) ->\n#(1 2 1 3)\"\n (declare (sequence seq)\n (function test))\n (etypecase seq\n (vector\n (if (zerop (length seq))\n seq\n (let ((prev (aref seq 0))\n (end 1))\n (loop for pos from 1 below (length seq)\n unless (funcall test prev (aref seq pos))\n do (setf prev (aref seq pos)\n (aref seq end) (aref seq pos)\n end (+ 1 end)))\n ;; KLUDGE: Resorting to ADJUST-ARRAY is maybe substandard. \n (if (array-has-fill-pointer-p seq)\n (adjust-array seq end :fill-pointer end)\n (adjust-array seq end)))))\n (list\n (loop for rest on seq\n unless (and (cdr rest)\n (funcall test (first rest) (second rest)))\n collect (car rest)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n (bs (make-array n :element-type 'uint31))\n (pairs (make-array n :element-type '(cons uint32 uint32))))\n (dotimes (i n)\n (let ((a (read-fixnum)))\n (setf (aref as i) a)))\n (dotimes (i n)\n (let ((b (read-fixnum)))\n (setf (aref bs i) b)))\n (dotimes (i n)\n (setf (aref pairs i)\n (cons (aref as i) (aref bs i))))\n (setq pairs (sort pairs (lambda (x y) (< (the uint31 x) (the uint31 y))) :key #'cdr))\n (let ((new-as (make-array n :element-type 'uint31))\n (sorted-as (sort (copy-seq as) #'<))\n (sorted-bs (sort (copy-seq bs) #'<)))\n (declare ((simple-array uint31 (*)) sorted-as sorted-bs))\n (dotimes (i n)\n (setf (aref new-as i) (car (aref pairs i))))\n (when (loop for a across sorted-as\n for b across sorted-bs\n thereis (> a b))\n (write-line \"No\")\n (return-from main))\n (when (< (length (delete-adjacent-duplicates (copy-seq sorted-as)))\n n)\n (write-line \"Yes\")\n (return-from main))\n (let ((dp (make-itreap n :initial-contents new-as))\n (pos 0))\n (dotimes (i (- n 2))\n (loop while (and (< pos n)\n (<= (itreap-ref dp pos) (aref sorted-bs pos)))\n do (incf pos))\n (when (= pos n)\n (return))\n (let* ((new-min (itreap-query dp pos n))\n (min-pos (itreap-range-bisect-left dp new-min #'> pos)))\n (rotatef (itreap-ref dp pos)\n (itreap-ref dp min-pos))))\n (when (loop for i below n\n always (<= (itreap-ref dp i) (aref sorted-bs i)))\n (write-line \"Yes\")\n (return-from main)))\n (let ((table (make-monotone-inverse-table! (copy-seq as)))\n (comped-as (make-array n :element-type 'uint31)))\n (dotimes (i n)\n (setf (aref comped-as i)\n (gethash (aref as i) table)))\n (if (= 1 (length (decompose-to-cycles comped-as)))\n (write-line \"No\")\n (write-line \"Yes\"))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 3 2\n1 2 3\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2 3\n2 2 2\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n3 1 2 6 3 4\n2 2 8 3 4 3\n\"\n \"Yes\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven are two integer sequences of N elements each: A_1,...,A_N and B_1,...,B_N.\nDetermine if it is possible to do the following operation at most N-2 times (possibly zero) so that, for every integer i from 1 to N, A_i \\leq B_i holds:\n\nChoose two distinct integers x and y between 1 and N (inclusive), and swap the values of A_x and A_y.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq A_i,B_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\nB_1 B_2 ... B_N\n\nOutput\n\nIf the objective is achievable, print Yes; if it is not, print No.\n\nSample Input 1\n\n3\n1 3 2\n1 2 3\n\nSample Output 1\n\nYes\n\nWe should swap the values of A_2 and A_3.\n\nSample Input 2\n\n3\n1 2 3\n2 2 2\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n6\n3 1 2 6 3 4\n2 2 8 3 4 3\n\nSample Output 3\n\nYes", "sample_input": "3\n1 3 2\n1 2 3\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02867", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are two integer sequences of N elements each: A_1,...,A_N and B_1,...,B_N.\nDetermine if it is possible to do the following operation at most N-2 times (possibly zero) so that, for every integer i from 1 to N, A_i \\leq B_i holds:\n\nChoose two distinct integers x and y between 1 and N (inclusive), and swap the values of A_x and A_y.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq A_i,B_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\nB_1 B_2 ... B_N\n\nOutput\n\nIf the objective is achievable, print Yes; if it is not, print No.\n\nSample Input 1\n\n3\n1 3 2\n1 2 3\n\nSample Output 1\n\nYes\n\nWe should swap the values of A_2 and A_3.\n\nSample Input 2\n\n3\n1 2 3\n2 2 2\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n6\n3 1 2 6 3 4\n2 2 8 3 4 3\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 21482, "cpu_time_ms": 1207, "memory_kb": 72552}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s676502750", "group_id": "codeNet:p02867", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;;;\n;;; Implicit treap\n;;; (treap with implicit key)\n;;;\n\n;; Note:\n;; - An empty treap is NIL.\n\n(declaim (inline op))\n(defun op (a b)\n \"Is a binary operator comprising a monoid.\"\n (declare (uint62 a b))\n (min a b))\n\n(defconstant +op-identity+ most-positive-fixnum\n \"identity element w.r.t. OP\")\n\n(defstruct (itreap (:constructor %make-itreap (value priority &key left right (count 1) (accumulator value)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (integer 0 #.most-positive-fixnum)) ; size of (sub)treap\n (left nil :type (or null itreap))\n (right nil :type (or null itreap)))\n\n(declaim (inline itreap-count))\n(defun itreap-count (itreap)\n \"Returns the number of the elements.\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-count itreap)\n 0))\n\n(declaim (inline itreap-accumulator))\n(defun itreap-accumulator (itreap)\n \"Returns the sum (w.r.t. OP) of the whole ITREAP:\nITREAP[0]+ITREAP[1]+...+ITREAP[SIZE-1].\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-accumulator itreap)\n +op-identity+))\n\n(declaim (inline update-count))\n(defun update-count (itreap)\n (declare (itreap itreap))\n (setf (%itreap-count itreap)\n (+ 1\n (itreap-count (%itreap-left itreap))\n (itreap-count (%itreap-right itreap)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (itreap)\n (declare (itreap itreap))\n (setf (%itreap-accumulator itreap)\n (if (%itreap-left itreap)\n (if (%itreap-right itreap)\n (let ((mid (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap))))\n (op mid (%itreap-accumulator (%itreap-right itreap))))\n (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap)))\n (if (%itreap-right itreap)\n (op (%itreap-value itreap)\n (%itreap-accumulator (%itreap-right itreap)))\n (%itreap-value itreap)))))\n\n(declaim (inline force-up))\n(defun force-up (itreap)\n \"Propagates up the information from children.\"\n (declare (itreap itreap))\n (update-count itreap)\n (update-accumulator itreap))\n\n(defun %heapify (top)\n \"Properly swaps the priorities of the node and its two children.\"\n (declare (optimize (speed 3) (safety 0)))\n (when top\n (let ((high-priority-node top))\n (when (and (%itreap-left top)\n (> (%itreap-priority (%itreap-left top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-left top)))\n (when (and (%itreap-right top)\n (> (%itreap-priority (%itreap-right top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-right top)))\n (unless (eql high-priority-node top)\n (rotatef (%itreap-priority high-priority-node)\n (%itreap-priority top))\n (%heapify high-priority-node)))))\n\n(declaim (inline make-itreap))\n(defun make-itreap (size &key initial-contents)\n \"Makes a treap of SIZE in O(SIZE) time. Its values are filled with the\nidentity element unless INITIAL-CONTENTS are supplied.\"\n (declare ((or null vector) initial-contents))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-itreap (if initial-contents\n (aref initial-contents mid)\n +op-identity+)\n (random most-positive-fixnum))))\n (setf (%itreap-left node) (build l mid))\n (setf (%itreap-right node) (build (+ mid 1) r))\n (%heapify node)\n (force-up node)\n node))))\n (build 0 size)))\n\n(defun itreap-split (itreap index)\n \"Destructively splits the ITREAP into two nodes [0, INDEX) and [INDEX, N),\nwhere N is the number of elements of the ITREAP.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) index))\n (unless (<= index (itreap-count itreap))\n (error 'invalid-itreap-index-error :index index :itreap itreap))\n (labels ((recur (itreap ikey)\n (unless itreap\n (return-from itreap-split (values nil nil)))\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= ikey left-count)\n (multiple-value-bind (left right)\n (itreap-split (%itreap-left itreap) ikey)\n (setf (%itreap-left itreap) right)\n (force-up itreap)\n (values left itreap))\n (multiple-value-bind (left right)\n (itreap-split (%itreap-right itreap) (- ikey left-count 1))\n (setf (%itreap-right itreap) left)\n (force-up itreap)\n (values itreap right))))))\n (recur itreap index)))\n\n(defun itreap-merge (left right)\n \"Destructively concatenates two ITREAPs.\"\n (declare #.OPT\n ((or null itreap) left right))\n (cond ((null left) (when right (force-up right)) right)\n ((null right) (when left (force-up left)) left)\n (t (if (> (%itreap-priority left) (%itreap-priority right))\n (progn\n (setf (%itreap-right left)\n (itreap-merge (%itreap-right left) right))\n (force-up left)\n left)\n (progn\n (setf (%itreap-left right)\n (itreap-merge left (%itreap-left right)))\n (force-up right)\n right)))))\n\n(declaim (inline itreap-map))\n(defun itreap-map (function itreap)\n \"Successively applies FUNCTION to ITREAP[0], ..., ITREAP[SIZE-1].\"\n (declare (function function))\n (labels ((recur (node)\n (when node\n (recur (%itreap-left node))\n (funcall function (%itreap-value node))\n (recur (%itreap-right node))\n (force-up node))))\n (recur itreap)))\n\n(defmethod print-object ((object itreap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (itreap-map (lambda (x)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write x :stream stream))\n object))))\n\n(declaim (inline itreap-ref))\n(defun itreap-ref (itreap index)\n \"Returns the element ITREAP[INDEX].\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index index))\n (labels ((%ref (itreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (prog1\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (cond ((< index left-count)\n (%ref (%itreap-left itreap) index))\n ((> index left-count)\n (%ref (%itreap-right itreap) (- index left-count 1)))\n (t (%itreap-value itreap))))\n (force-up itreap))))\n (%ref itreap index)))\n\n(declaim (inline (setf itreap-ref)))\n(defun (setf itreap-ref) (new-value itreap index)\n \"Sets ITREAP[INDEX] to the given value.\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index index))\n (labels ((%set (itreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (prog1\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (cond ((< index left-count)\n (%set (%itreap-left itreap) index))\n ((> index left-count)\n (%set (%itreap-right itreap) (- index left-count 1)))\n (t (setf (%itreap-value itreap) new-value))))\n (force-up itreap))))\n (%set itreap index)\n new-value))\n\n(declaim (inline itreap-query))\n(defun itreap-query (itreap l r)\n \"Queries the `sum' (w.r.t. OP) of the range ITREAP[L, R).\"\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless (<= l r (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index (cons l r)))\n (labels\n ((recur (itreap l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless itreap\n (return-from recur +op-identity+))\n (prog1\n (if (and (zerop l) (= r (%itreap-count itreap)))\n (itreap-accumulator itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= l left-count)\n (if (< left-count r)\n ;; LEFT-COUNT is in [L, R)\n (op (op (recur (%itreap-left itreap) l (min r left-count))\n (%itreap-value itreap))\n (recur (%itreap-right itreap) 0 (- r left-count 1)))\n ;; LEFT-COUNT is in [R, END)\n (recur (%itreap-left itreap) l (min r left-count)))\n ;; LEFT-COUNT is in [0, L)\n (recur (%itreap-right itreap) (- l left-count 1) (- r left-count 1)))))\n (force-up itreap))))\n (recur itreap l r)))\n\n;; FIXME: might be problematic when two priorities collide and START is not\n;; zero. (It will be negligible from the viewpoint of probability, however.)\n(declaim (inline itreap-range-bisect-left))\n(defun itreap-range-bisect-left (itreap value order &optional (start 0))\n \"Returns the smallest index that satisfies ITREAP[START]+ ITREAP[START+1] +\n... + ITREAP[index] >= VALUE (if ORDER is #'<).\n\nNote:\n- This function handles a **closed** interval.\n- This function returns the length of ITREAP instead if ITREAP[START]+\n... +ITREAP[length-1] < VALUE.\n- The prefix sums of ITREAP, (ITREAP[START], ITREAP[START]+ITREAP[START+1], ...)\n must be monotone w.r.t. ORDER.\n- ORDER must be a strict order\"\n (declare ((integer 0 #.most-positive-fixnum) start))\n (multiple-value-bind (itreap-prefix itreap)\n (if (zerop start)\n (values nil itreap)\n (itreap-split itreap start))\n (labels\n ((recur (itreap offset prev-sum)\n (declare ((integer 0 #.most-positive-fixnum) offset)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (unless itreap\n (return-from recur offset))\n (let ((sum prev-sum))\n (prog1\n (cond ((not (funcall order\n (setq sum (op sum (itreap-accumulator (%itreap-left itreap))))\n value))\n (recur (%itreap-left itreap) offset prev-sum))\n ((not (funcall order\n (setq sum (op sum (%itreap-value itreap)))\n value))\n (+ offset (itreap-count (%itreap-left itreap))))\n (t\n (recur (%itreap-right itreap)\n (+ offset (itreap-count (%itreap-left itreap)) 1)\n sum)))\n (force-up itreap)))))\n (prog1 (+ start (recur itreap 0 +op-identity+))\n (itreap-merge itreap-prefix itreap)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(declaim (inline delete-adjacent-duplicates))\n(defun delete-adjacent-duplicates (seq &key (test #'eql))\n \"Destructively deletes adjacent duplicates of SEQ: e.g. #(1 1 1 2 2 1 3) ->\n#(1 2 1 3)\"\n (declare (sequence seq)\n (function test))\n (etypecase seq\n (vector\n (if (zerop (length seq))\n seq\n (let ((prev (aref seq 0))\n (end 1))\n (loop for pos from 1 below (length seq)\n unless (funcall test prev (aref seq pos))\n do (setf prev (aref seq pos)\n (aref seq end) (aref seq pos)\n end (+ 1 end)))\n ;; KLUDGE: Resorting to ADJUST-ARRAY is maybe substandard. \n (if (array-has-fill-pointer-p seq)\n (adjust-array seq end :fill-pointer end)\n (adjust-array seq end)))))\n (list\n (loop for rest on seq\n unless (and (cdr rest)\n (funcall test (first rest) (second rest)))\n collect (car rest)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n\n;; Note:\n;; - An empty treap is NIL.\n\n(declaim (inline mop))\n(defun mop (a b)\n \"Is a binary moperator comprising a monoid.\"\n (declare (uint62 a b))\n (max a b))\n\n(defconstant +mop-identity+ 0\n \"identity element w.r.t. MOP\")\n\n(defstruct (mitreap (:constructor %make-mitreap (value priority &key left right (count 1) (accumulator value)))\n (:copier nil)\n (:conc-name %mitreap-))\n (value +mop-identity+ :type fixnum)\n (accumulator +mop-identity+ :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (integer 0 #.most-positive-fixnum)) ; size of (sub)treap\n (left nil :type (or null mitreap))\n (right nil :type (or null mitreap)))\n\n(declaim (inline mitreap-count))\n(defun mitreap-count (mitreap)\n \"Returns the number of the elements.\"\n (declare ((or null mitreap) mitreap))\n (if mitreap\n (%mitreap-count mitreap)\n 0))\n\n(declaim (inline mitreap-accumulator))\n(defun mitreap-accumulator (mitreap)\n \"Returns the sum (w.r.t. MOP) of the whole MITREAP:\nMITREAP[0]+MITREAP[1]+...+MITREAP[SIZE-1].\"\n (declare ((or null mitreap) mitreap))\n (if mitreap\n (%mitreap-accumulator mitreap)\n +mop-identity+))\n\n(declaim (inline mupdate-count))\n(defun mupdate-count (mitreap)\n (declare (mitreap mitreap))\n (setf (%mitreap-count mitreap)\n (+ 1\n (mitreap-count (%mitreap-left mitreap))\n (mitreap-count (%mitreap-right mitreap)))))\n\n(declaim (inline mupdate-accumulator))\n(defun mupdate-accumulator (mitreap)\n (declare (mitreap mitreap))\n (setf (%mitreap-accumulator mitreap)\n (if (%mitreap-left mitreap)\n (if (%mitreap-right mitreap)\n (let ((mid (mop (%mitreap-accumulator (%mitreap-left mitreap))\n (%mitreap-value mitreap))))\n (mop mid (%mitreap-accumulator (%mitreap-right mitreap))))\n (mop (%mitreap-accumulator (%mitreap-left mitreap))\n (%mitreap-value mitreap)))\n (if (%mitreap-right mitreap)\n (mop (%mitreap-value mitreap)\n (%mitreap-accumulator (%mitreap-right mitreap)))\n (%mitreap-value mitreap)))))\n\n(declaim (inline mforce-up))\n(defun mforce-up (mitreap)\n \"Propagates up the information from children.\"\n (declare (mitreap mitreap))\n (mupdate-count mitreap)\n (mupdate-accumulator mitreap))\n\n(defun %mheapify (top)\n \"Properly swaps the priorities of the node and its two children.\"\n (declare (optimize (speed 3) (safety 0)))\n (when top\n (let ((high-priority-node top))\n (when (and (%mitreap-left top)\n (> (%mitreap-priority (%mitreap-left top))\n (%mitreap-priority high-priority-node)))\n (setq high-priority-node (%mitreap-left top)))\n (when (and (%mitreap-right top)\n (> (%mitreap-priority (%mitreap-right top))\n (%mitreap-priority high-priority-node)))\n (setq high-priority-node (%mitreap-right top)))\n (unless (eql high-priority-node top)\n (rotatef (%mitreap-priority high-priority-node)\n (%mitreap-priority top))\n (%mheapify high-priority-node)))))\n\n(declaim (inline make-mitreap))\n(defun make-mitreap (size &key initial-contents)\n \"Makes a treap of SIZE in O(SIZE) time. Its values are filled with the\nidentity element unless INITIAL-CONTENTS are supplied.\"\n (declare ((or null vector) initial-contents))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-mitreap (if initial-contents\n (aref initial-contents mid)\n +mop-identity+)\n (random most-positive-fixnum))))\n (setf (%mitreap-left node) (build l mid))\n (setf (%mitreap-right node) (build (+ mid 1) r))\n (%mheapify node)\n (mforce-up node)\n node))))\n (build 0 size)))\n\n(defun mitreap-split (mitreap index)\n \"Destructively splits the MITREAP into two nodes [0, INDEX) and [INDEX, N),\nwhere N is the number of elements of the MITREAP.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) index))\n (unless (<= index (mitreap-count mitreap))\n (error 'invalid-mitreap-index-error :index index :mitreap mitreap))\n (labels ((recur (mitreap ikey)\n (unless mitreap\n (return-from mitreap-split (values nil nil)))\n (let ((left-count (mitreap-count (%mitreap-left mitreap))))\n (if (<= ikey left-count)\n (multiple-value-bind (left right)\n (mitreap-split (%mitreap-left mitreap) ikey)\n (setf (%mitreap-left mitreap) right)\n (mforce-up mitreap)\n (values left mitreap))\n (multiple-value-bind (left right)\n (mitreap-split (%mitreap-right mitreap) (- ikey left-count 1))\n (setf (%mitreap-right mitreap) left)\n (mforce-up mitreap)\n (values mitreap right))))))\n (recur mitreap index)))\n\n(defun mitreap-merge (left right)\n \"Destructively concatenates two MITREAPs.\"\n (declare #.OPT\n ((or null mitreap) left right))\n (cond ((null left) (when right (mforce-up right)) right)\n ((null right) (when left (mforce-up left)) left)\n (t (if (> (%mitreap-priority left) (%mitreap-priority right))\n (progn\n (setf (%mitreap-right left)\n (mitreap-merge (%mitreap-right left) right))\n (mforce-up left)\n left)\n (progn\n (setf (%mitreap-left right)\n (mitreap-merge left (%mitreap-left right)))\n (mforce-up right)\n right)))))\n\n(declaim (inline mitreap-map))\n(defun mitreap-map (function mitreap)\n \"Successively applies FUNCTION to MITREAP[0], ..., MITREAP[SIZE-1].\"\n (declare (function function))\n (labels ((recur (node)\n (when node\n (recur (%mitreap-left node))\n (funcall function (%mitreap-value node))\n (recur (%mitreap-right node))\n (mforce-up node))))\n (recur mitreap)))\n\n(defmethod print-object ((object mitreap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (mitreap-map (lambda (x)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write x :stream stream))\n object))))\n\n(declaim (inline mitreap-ref))\n(defun mitreap-ref (mitreap index)\n \"Returns the element MITREAP[INDEX].\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (mitreap-count mitreap))\n (error 'invalid-mitreap-index-error :mitreap mitreap :index index))\n (labels ((%ref (mitreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (prog1\n (let ((left-count (mitreap-count (%mitreap-left mitreap))))\n (cond ((< index left-count)\n (%ref (%mitreap-left mitreap) index))\n ((> index left-count)\n (%ref (%mitreap-right mitreap) (- index left-count 1)))\n (t (%mitreap-value mitreap))))\n (mforce-up mitreap))))\n (%ref mitreap index)))\n\n(declaim (inline (setf mitreap-ref)))\n(defun (setf mitreap-ref) (new-value mitreap index)\n \"Sets MITREAP[INDEX] to the given value.\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (mitreap-count mitreap))\n (error 'invalid-mitreap-index-error :mitreap mitreap :index index))\n (labels ((%set (mitreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (prog1\n (let ((left-count (mitreap-count (%mitreap-left mitreap))))\n (cond ((< index left-count)\n (%set (%mitreap-left mitreap) index))\n ((> index left-count)\n (%set (%mitreap-right mitreap) (- index left-count 1)))\n (t (setf (%mitreap-value mitreap) new-value))))\n (mforce-up mitreap))))\n (%set mitreap index)\n new-value))\n\n(declaim (inline mitreap-query))\n(defun mitreap-query (mitreap l r)\n \"Queries the `sum' (w.r.t. MOP) of the range MITREAP[L, R).\"\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless (<= l r (mitreap-count mitreap))\n (error 'invalid-mitreap-index-error :mitreap mitreap :index (cons l r)))\n (labels\n ((recur (mitreap l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless mitreap\n (return-from recur +mop-identity+))\n (prog1\n (if (and (zerop l) (= r (%mitreap-count mitreap)))\n (mitreap-accumulator mitreap)\n (let ((left-count (mitreap-count (%mitreap-left mitreap))))\n (if (<= l left-count)\n (if (< left-count r)\n ;; LEFT-COUNT is in [L, R)\n (mop (mop (recur (%mitreap-left mitreap) l (min r left-count))\n (%mitreap-value mitreap))\n (recur (%mitreap-right mitreap) 0 (- r left-count 1)))\n ;; LEFT-COUNT is in [R, END)\n (recur (%mitreap-left mitreap) l (min r left-count)))\n ;; LEFT-COUNT is in [0, L)\n (recur (%mitreap-right mitreap) (- l left-count 1) (- r left-count 1)))))\n (mforce-up mitreap))))\n (recur mitreap l r)))\n\n;; FIXME: might be problematic when two priorities collide and START is not\n;; zero. (It will be negligible from the viewpoint of probability, however.)\n(declaim (inline mitreap-range-bisect-left))\n(defun mitreap-range-bisect-left (mitreap value order &optional (start 0))\n \"Returns the smallest index that satisfies MITREAP[START]+ MITREAP[START+1] +\n... + MITREAP[index] >= VALUE (if ORDER is #'<).\n\nNote:\n- This function handles a **closed** interval.\n- This function returns the length of MITREAP instead if MITREAP[START]+\n... +MITREAP[length-1] < VALUE.\n- The prefix sums of MITREAP, (MITREAP[START], MITREAP[START]+MITREAP[START+1], ...)\n must be monotone w.r.t. ORDER.\n- ORDER must be a strict order\"\n (declare ((integer 0 #.most-positive-fixnum) start))\n (multiple-value-bind (mitreap-prefix mitreap)\n (if (zerop start)\n (values nil mitreap)\n (mitreap-split mitreap start))\n (labels\n ((recur (mitreap offset prev-sum)\n (declare ((integer 0 #.most-positive-fixnum) offset)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (unless mitreap\n (return-from recur offset))\n (let ((sum prev-sum))\n (prog1\n (cond ((not (funcall order\n (setq sum (mop sum (mitreap-accumulator (%mitreap-left mitreap))))\n value))\n (recur (%mitreap-left mitreap) offset prev-sum))\n ((not (funcall order\n (setq sum (mop sum (%mitreap-value mitreap)))\n value))\n (+ offset (mitreap-count (%mitreap-left mitreap))))\n (t\n (recur (%mitreap-right mitreap)\n (+ offset (mitreap-count (%mitreap-left mitreap)) 1)\n sum)))\n (mforce-up mitreap)))))\n (prog1 (+ start (recur mitreap 0 +mop-identity+))\n (mitreap-merge mitreap-prefix mitreap)))))\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n (bs (make-array n :element-type 'uint31))\n (pairs (make-array n :element-type '(cons uint32 uint32))))\n (dotimes (i n)\n (let ((a (read-fixnum)))\n (setf (aref as i) a)))\n (dotimes (i n)\n (let ((b (read-fixnum)))\n (setf (aref bs i) b)))\n (dotimes (i n)\n (setf (aref pairs i)\n (cons (aref as i) (aref bs i))))\n (setq pairs (sort pairs (lambda (x y) (< (the uint31 x) (the uint31 y))) :key #'cdr))\n (let ((new-as (make-array n :element-type 'uint31))\n (sorted-as (sort (copy-seq as) #'<))\n (sorted-bs (sort (copy-seq bs) #'<)))\n (declare ((simple-array uint31 (*)) sorted-as sorted-bs))\n (dotimes (i n)\n (setf (aref new-as i) (car (aref pairs i))))\n (when (loop for a across sorted-as\n for b across sorted-bs\n thereis (> a b))\n (write-line \"No\")\n (return-from main))\n (when (< (length (delete-adjacent-duplicates (copy-seq sorted-as)))\n n)\n (write-line \"Yes\")\n (return-from main))\n (let ((dp (make-itreap n :initial-contents new-as))\n (pos 0))\n (dotimes (i (- n 2))\n (loop while (and (< pos n)\n (<= (itreap-ref dp pos) (aref sorted-bs pos)))\n do (incf pos))\n (when (= pos n)\n (return))\n (let* ((new-min (itreap-query dp pos n))\n (min-pos (itreap-range-bisect-left dp new-min #'> pos)))\n (declare (uint62 new-min min-pos))\n (unless (<= new-min (itreap-ref dp pos))\n (write-line \"No\")\n (return-from main))\n (rotatef (itreap-ref dp pos)\n (itreap-ref dp min-pos))))\n (when (loop for i below n\n always (<= (itreap-ref dp i) (aref sorted-bs i)))\n (write-line \"Yes\")\n (return-from main)))\n (let ((dp (make-mitreap n :initial-contents new-as))\n (pos (- n 1)))\n (dotimes (i (- n 2))\n (loop while (and (<= 0 pos)\n (<= (mitreap-ref dp pos) (aref sorted-bs pos)))\n do (decf pos))\n (when (< pos 0)\n (return))\n (let* ((new-max (mitreap-query dp 0 (+ pos 1)))\n (max-pos (mitreap-range-bisect-left dp new-max #'<)))\n (declare (uint62 new-max max-pos))\n (unless (<= new-max (mitreap-ref dp pos))\n (write-line \"No\")\n (return-from main))\n (rotatef (mitreap-ref dp pos)\n (mitreap-ref dp max-pos))))\n (when (loop for i below n\n always (<= (mitreap-ref dp i) (aref sorted-bs i)))\n (write-line \"Yes\")\n (return-from main)))\n (write-line \"No\"))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 3 2\n1 2 3\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2 3\n2 2 2\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n3 1 2 6 3 4\n2 2 8 3 4 3\n\"\n \"Yes\n\")))\n", "language": "Lisp", "metadata": {"date": 1573357366, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02867.html", "problem_id": "p02867", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02867/input.txt", "sample_output_relpath": "derived/input_output/data/p02867/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02867/Lisp/s676502750.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s676502750", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;;;\n;;; Implicit treap\n;;; (treap with implicit key)\n;;;\n\n;; Note:\n;; - An empty treap is NIL.\n\n(declaim (inline op))\n(defun op (a b)\n \"Is a binary operator comprising a monoid.\"\n (declare (uint62 a b))\n (min a b))\n\n(defconstant +op-identity+ most-positive-fixnum\n \"identity element w.r.t. OP\")\n\n(defstruct (itreap (:constructor %make-itreap (value priority &key left right (count 1) (accumulator value)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (integer 0 #.most-positive-fixnum)) ; size of (sub)treap\n (left nil :type (or null itreap))\n (right nil :type (or null itreap)))\n\n(declaim (inline itreap-count))\n(defun itreap-count (itreap)\n \"Returns the number of the elements.\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-count itreap)\n 0))\n\n(declaim (inline itreap-accumulator))\n(defun itreap-accumulator (itreap)\n \"Returns the sum (w.r.t. OP) of the whole ITREAP:\nITREAP[0]+ITREAP[1]+...+ITREAP[SIZE-1].\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-accumulator itreap)\n +op-identity+))\n\n(declaim (inline update-count))\n(defun update-count (itreap)\n (declare (itreap itreap))\n (setf (%itreap-count itreap)\n (+ 1\n (itreap-count (%itreap-left itreap))\n (itreap-count (%itreap-right itreap)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (itreap)\n (declare (itreap itreap))\n (setf (%itreap-accumulator itreap)\n (if (%itreap-left itreap)\n (if (%itreap-right itreap)\n (let ((mid (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap))))\n (op mid (%itreap-accumulator (%itreap-right itreap))))\n (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap)))\n (if (%itreap-right itreap)\n (op (%itreap-value itreap)\n (%itreap-accumulator (%itreap-right itreap)))\n (%itreap-value itreap)))))\n\n(declaim (inline force-up))\n(defun force-up (itreap)\n \"Propagates up the information from children.\"\n (declare (itreap itreap))\n (update-count itreap)\n (update-accumulator itreap))\n\n(defun %heapify (top)\n \"Properly swaps the priorities of the node and its two children.\"\n (declare (optimize (speed 3) (safety 0)))\n (when top\n (let ((high-priority-node top))\n (when (and (%itreap-left top)\n (> (%itreap-priority (%itreap-left top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-left top)))\n (when (and (%itreap-right top)\n (> (%itreap-priority (%itreap-right top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-right top)))\n (unless (eql high-priority-node top)\n (rotatef (%itreap-priority high-priority-node)\n (%itreap-priority top))\n (%heapify high-priority-node)))))\n\n(declaim (inline make-itreap))\n(defun make-itreap (size &key initial-contents)\n \"Makes a treap of SIZE in O(SIZE) time. Its values are filled with the\nidentity element unless INITIAL-CONTENTS are supplied.\"\n (declare ((or null vector) initial-contents))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-itreap (if initial-contents\n (aref initial-contents mid)\n +op-identity+)\n (random most-positive-fixnum))))\n (setf (%itreap-left node) (build l mid))\n (setf (%itreap-right node) (build (+ mid 1) r))\n (%heapify node)\n (force-up node)\n node))))\n (build 0 size)))\n\n(defun itreap-split (itreap index)\n \"Destructively splits the ITREAP into two nodes [0, INDEX) and [INDEX, N),\nwhere N is the number of elements of the ITREAP.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) index))\n (unless (<= index (itreap-count itreap))\n (error 'invalid-itreap-index-error :index index :itreap itreap))\n (labels ((recur (itreap ikey)\n (unless itreap\n (return-from itreap-split (values nil nil)))\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= ikey left-count)\n (multiple-value-bind (left right)\n (itreap-split (%itreap-left itreap) ikey)\n (setf (%itreap-left itreap) right)\n (force-up itreap)\n (values left itreap))\n (multiple-value-bind (left right)\n (itreap-split (%itreap-right itreap) (- ikey left-count 1))\n (setf (%itreap-right itreap) left)\n (force-up itreap)\n (values itreap right))))))\n (recur itreap index)))\n\n(defun itreap-merge (left right)\n \"Destructively concatenates two ITREAPs.\"\n (declare #.OPT\n ((or null itreap) left right))\n (cond ((null left) (when right (force-up right)) right)\n ((null right) (when left (force-up left)) left)\n (t (if (> (%itreap-priority left) (%itreap-priority right))\n (progn\n (setf (%itreap-right left)\n (itreap-merge (%itreap-right left) right))\n (force-up left)\n left)\n (progn\n (setf (%itreap-left right)\n (itreap-merge left (%itreap-left right)))\n (force-up right)\n right)))))\n\n(declaim (inline itreap-map))\n(defun itreap-map (function itreap)\n \"Successively applies FUNCTION to ITREAP[0], ..., ITREAP[SIZE-1].\"\n (declare (function function))\n (labels ((recur (node)\n (when node\n (recur (%itreap-left node))\n (funcall function (%itreap-value node))\n (recur (%itreap-right node))\n (force-up node))))\n (recur itreap)))\n\n(defmethod print-object ((object itreap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (itreap-map (lambda (x)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write x :stream stream))\n object))))\n\n(declaim (inline itreap-ref))\n(defun itreap-ref (itreap index)\n \"Returns the element ITREAP[INDEX].\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index index))\n (labels ((%ref (itreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (prog1\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (cond ((< index left-count)\n (%ref (%itreap-left itreap) index))\n ((> index left-count)\n (%ref (%itreap-right itreap) (- index left-count 1)))\n (t (%itreap-value itreap))))\n (force-up itreap))))\n (%ref itreap index)))\n\n(declaim (inline (setf itreap-ref)))\n(defun (setf itreap-ref) (new-value itreap index)\n \"Sets ITREAP[INDEX] to the given value.\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index index))\n (labels ((%set (itreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (prog1\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (cond ((< index left-count)\n (%set (%itreap-left itreap) index))\n ((> index left-count)\n (%set (%itreap-right itreap) (- index left-count 1)))\n (t (setf (%itreap-value itreap) new-value))))\n (force-up itreap))))\n (%set itreap index)\n new-value))\n\n(declaim (inline itreap-query))\n(defun itreap-query (itreap l r)\n \"Queries the `sum' (w.r.t. OP) of the range ITREAP[L, R).\"\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless (<= l r (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index (cons l r)))\n (labels\n ((recur (itreap l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless itreap\n (return-from recur +op-identity+))\n (prog1\n (if (and (zerop l) (= r (%itreap-count itreap)))\n (itreap-accumulator itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= l left-count)\n (if (< left-count r)\n ;; LEFT-COUNT is in [L, R)\n (op (op (recur (%itreap-left itreap) l (min r left-count))\n (%itreap-value itreap))\n (recur (%itreap-right itreap) 0 (- r left-count 1)))\n ;; LEFT-COUNT is in [R, END)\n (recur (%itreap-left itreap) l (min r left-count)))\n ;; LEFT-COUNT is in [0, L)\n (recur (%itreap-right itreap) (- l left-count 1) (- r left-count 1)))))\n (force-up itreap))))\n (recur itreap l r)))\n\n;; FIXME: might be problematic when two priorities collide and START is not\n;; zero. (It will be negligible from the viewpoint of probability, however.)\n(declaim (inline itreap-range-bisect-left))\n(defun itreap-range-bisect-left (itreap value order &optional (start 0))\n \"Returns the smallest index that satisfies ITREAP[START]+ ITREAP[START+1] +\n... + ITREAP[index] >= VALUE (if ORDER is #'<).\n\nNote:\n- This function handles a **closed** interval.\n- This function returns the length of ITREAP instead if ITREAP[START]+\n... +ITREAP[length-1] < VALUE.\n- The prefix sums of ITREAP, (ITREAP[START], ITREAP[START]+ITREAP[START+1], ...)\n must be monotone w.r.t. ORDER.\n- ORDER must be a strict order\"\n (declare ((integer 0 #.most-positive-fixnum) start))\n (multiple-value-bind (itreap-prefix itreap)\n (if (zerop start)\n (values nil itreap)\n (itreap-split itreap start))\n (labels\n ((recur (itreap offset prev-sum)\n (declare ((integer 0 #.most-positive-fixnum) offset)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (unless itreap\n (return-from recur offset))\n (let ((sum prev-sum))\n (prog1\n (cond ((not (funcall order\n (setq sum (op sum (itreap-accumulator (%itreap-left itreap))))\n value))\n (recur (%itreap-left itreap) offset prev-sum))\n ((not (funcall order\n (setq sum (op sum (%itreap-value itreap)))\n value))\n (+ offset (itreap-count (%itreap-left itreap))))\n (t\n (recur (%itreap-right itreap)\n (+ offset (itreap-count (%itreap-left itreap)) 1)\n sum)))\n (force-up itreap)))))\n (prog1 (+ start (recur itreap 0 +op-identity+))\n (itreap-merge itreap-prefix itreap)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(declaim (inline delete-adjacent-duplicates))\n(defun delete-adjacent-duplicates (seq &key (test #'eql))\n \"Destructively deletes adjacent duplicates of SEQ: e.g. #(1 1 1 2 2 1 3) ->\n#(1 2 1 3)\"\n (declare (sequence seq)\n (function test))\n (etypecase seq\n (vector\n (if (zerop (length seq))\n seq\n (let ((prev (aref seq 0))\n (end 1))\n (loop for pos from 1 below (length seq)\n unless (funcall test prev (aref seq pos))\n do (setf prev (aref seq pos)\n (aref seq end) (aref seq pos)\n end (+ 1 end)))\n ;; KLUDGE: Resorting to ADJUST-ARRAY is maybe substandard. \n (if (array-has-fill-pointer-p seq)\n (adjust-array seq end :fill-pointer end)\n (adjust-array seq end)))))\n (list\n (loop for rest on seq\n unless (and (cdr rest)\n (funcall test (first rest) (second rest)))\n collect (car rest)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n\n;; Note:\n;; - An empty treap is NIL.\n\n(declaim (inline mop))\n(defun mop (a b)\n \"Is a binary moperator comprising a monoid.\"\n (declare (uint62 a b))\n (max a b))\n\n(defconstant +mop-identity+ 0\n \"identity element w.r.t. MOP\")\n\n(defstruct (mitreap (:constructor %make-mitreap (value priority &key left right (count 1) (accumulator value)))\n (:copier nil)\n (:conc-name %mitreap-))\n (value +mop-identity+ :type fixnum)\n (accumulator +mop-identity+ :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (integer 0 #.most-positive-fixnum)) ; size of (sub)treap\n (left nil :type (or null mitreap))\n (right nil :type (or null mitreap)))\n\n(declaim (inline mitreap-count))\n(defun mitreap-count (mitreap)\n \"Returns the number of the elements.\"\n (declare ((or null mitreap) mitreap))\n (if mitreap\n (%mitreap-count mitreap)\n 0))\n\n(declaim (inline mitreap-accumulator))\n(defun mitreap-accumulator (mitreap)\n \"Returns the sum (w.r.t. MOP) of the whole MITREAP:\nMITREAP[0]+MITREAP[1]+...+MITREAP[SIZE-1].\"\n (declare ((or null mitreap) mitreap))\n (if mitreap\n (%mitreap-accumulator mitreap)\n +mop-identity+))\n\n(declaim (inline mupdate-count))\n(defun mupdate-count (mitreap)\n (declare (mitreap mitreap))\n (setf (%mitreap-count mitreap)\n (+ 1\n (mitreap-count (%mitreap-left mitreap))\n (mitreap-count (%mitreap-right mitreap)))))\n\n(declaim (inline mupdate-accumulator))\n(defun mupdate-accumulator (mitreap)\n (declare (mitreap mitreap))\n (setf (%mitreap-accumulator mitreap)\n (if (%mitreap-left mitreap)\n (if (%mitreap-right mitreap)\n (let ((mid (mop (%mitreap-accumulator (%mitreap-left mitreap))\n (%mitreap-value mitreap))))\n (mop mid (%mitreap-accumulator (%mitreap-right mitreap))))\n (mop (%mitreap-accumulator (%mitreap-left mitreap))\n (%mitreap-value mitreap)))\n (if (%mitreap-right mitreap)\n (mop (%mitreap-value mitreap)\n (%mitreap-accumulator (%mitreap-right mitreap)))\n (%mitreap-value mitreap)))))\n\n(declaim (inline mforce-up))\n(defun mforce-up (mitreap)\n \"Propagates up the information from children.\"\n (declare (mitreap mitreap))\n (mupdate-count mitreap)\n (mupdate-accumulator mitreap))\n\n(defun %mheapify (top)\n \"Properly swaps the priorities of the node and its two children.\"\n (declare (optimize (speed 3) (safety 0)))\n (when top\n (let ((high-priority-node top))\n (when (and (%mitreap-left top)\n (> (%mitreap-priority (%mitreap-left top))\n (%mitreap-priority high-priority-node)))\n (setq high-priority-node (%mitreap-left top)))\n (when (and (%mitreap-right top)\n (> (%mitreap-priority (%mitreap-right top))\n (%mitreap-priority high-priority-node)))\n (setq high-priority-node (%mitreap-right top)))\n (unless (eql high-priority-node top)\n (rotatef (%mitreap-priority high-priority-node)\n (%mitreap-priority top))\n (%mheapify high-priority-node)))))\n\n(declaim (inline make-mitreap))\n(defun make-mitreap (size &key initial-contents)\n \"Makes a treap of SIZE in O(SIZE) time. Its values are filled with the\nidentity element unless INITIAL-CONTENTS are supplied.\"\n (declare ((or null vector) initial-contents))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-mitreap (if initial-contents\n (aref initial-contents mid)\n +mop-identity+)\n (random most-positive-fixnum))))\n (setf (%mitreap-left node) (build l mid))\n (setf (%mitreap-right node) (build (+ mid 1) r))\n (%mheapify node)\n (mforce-up node)\n node))))\n (build 0 size)))\n\n(defun mitreap-split (mitreap index)\n \"Destructively splits the MITREAP into two nodes [0, INDEX) and [INDEX, N),\nwhere N is the number of elements of the MITREAP.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) index))\n (unless (<= index (mitreap-count mitreap))\n (error 'invalid-mitreap-index-error :index index :mitreap mitreap))\n (labels ((recur (mitreap ikey)\n (unless mitreap\n (return-from mitreap-split (values nil nil)))\n (let ((left-count (mitreap-count (%mitreap-left mitreap))))\n (if (<= ikey left-count)\n (multiple-value-bind (left right)\n (mitreap-split (%mitreap-left mitreap) ikey)\n (setf (%mitreap-left mitreap) right)\n (mforce-up mitreap)\n (values left mitreap))\n (multiple-value-bind (left right)\n (mitreap-split (%mitreap-right mitreap) (- ikey left-count 1))\n (setf (%mitreap-right mitreap) left)\n (mforce-up mitreap)\n (values mitreap right))))))\n (recur mitreap index)))\n\n(defun mitreap-merge (left right)\n \"Destructively concatenates two MITREAPs.\"\n (declare #.OPT\n ((or null mitreap) left right))\n (cond ((null left) (when right (mforce-up right)) right)\n ((null right) (when left (mforce-up left)) left)\n (t (if (> (%mitreap-priority left) (%mitreap-priority right))\n (progn\n (setf (%mitreap-right left)\n (mitreap-merge (%mitreap-right left) right))\n (mforce-up left)\n left)\n (progn\n (setf (%mitreap-left right)\n (mitreap-merge left (%mitreap-left right)))\n (mforce-up right)\n right)))))\n\n(declaim (inline mitreap-map))\n(defun mitreap-map (function mitreap)\n \"Successively applies FUNCTION to MITREAP[0], ..., MITREAP[SIZE-1].\"\n (declare (function function))\n (labels ((recur (node)\n (when node\n (recur (%mitreap-left node))\n (funcall function (%mitreap-value node))\n (recur (%mitreap-right node))\n (mforce-up node))))\n (recur mitreap)))\n\n(defmethod print-object ((object mitreap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (mitreap-map (lambda (x)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write x :stream stream))\n object))))\n\n(declaim (inline mitreap-ref))\n(defun mitreap-ref (mitreap index)\n \"Returns the element MITREAP[INDEX].\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (mitreap-count mitreap))\n (error 'invalid-mitreap-index-error :mitreap mitreap :index index))\n (labels ((%ref (mitreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (prog1\n (let ((left-count (mitreap-count (%mitreap-left mitreap))))\n (cond ((< index left-count)\n (%ref (%mitreap-left mitreap) index))\n ((> index left-count)\n (%ref (%mitreap-right mitreap) (- index left-count 1)))\n (t (%mitreap-value mitreap))))\n (mforce-up mitreap))))\n (%ref mitreap index)))\n\n(declaim (inline (setf mitreap-ref)))\n(defun (setf mitreap-ref) (new-value mitreap index)\n \"Sets MITREAP[INDEX] to the given value.\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (mitreap-count mitreap))\n (error 'invalid-mitreap-index-error :mitreap mitreap :index index))\n (labels ((%set (mitreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (prog1\n (let ((left-count (mitreap-count (%mitreap-left mitreap))))\n (cond ((< index left-count)\n (%set (%mitreap-left mitreap) index))\n ((> index left-count)\n (%set (%mitreap-right mitreap) (- index left-count 1)))\n (t (setf (%mitreap-value mitreap) new-value))))\n (mforce-up mitreap))))\n (%set mitreap index)\n new-value))\n\n(declaim (inline mitreap-query))\n(defun mitreap-query (mitreap l r)\n \"Queries the `sum' (w.r.t. MOP) of the range MITREAP[L, R).\"\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless (<= l r (mitreap-count mitreap))\n (error 'invalid-mitreap-index-error :mitreap mitreap :index (cons l r)))\n (labels\n ((recur (mitreap l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless mitreap\n (return-from recur +mop-identity+))\n (prog1\n (if (and (zerop l) (= r (%mitreap-count mitreap)))\n (mitreap-accumulator mitreap)\n (let ((left-count (mitreap-count (%mitreap-left mitreap))))\n (if (<= l left-count)\n (if (< left-count r)\n ;; LEFT-COUNT is in [L, R)\n (mop (mop (recur (%mitreap-left mitreap) l (min r left-count))\n (%mitreap-value mitreap))\n (recur (%mitreap-right mitreap) 0 (- r left-count 1)))\n ;; LEFT-COUNT is in [R, END)\n (recur (%mitreap-left mitreap) l (min r left-count)))\n ;; LEFT-COUNT is in [0, L)\n (recur (%mitreap-right mitreap) (- l left-count 1) (- r left-count 1)))))\n (mforce-up mitreap))))\n (recur mitreap l r)))\n\n;; FIXME: might be problematic when two priorities collide and START is not\n;; zero. (It will be negligible from the viewpoint of probability, however.)\n(declaim (inline mitreap-range-bisect-left))\n(defun mitreap-range-bisect-left (mitreap value order &optional (start 0))\n \"Returns the smallest index that satisfies MITREAP[START]+ MITREAP[START+1] +\n... + MITREAP[index] >= VALUE (if ORDER is #'<).\n\nNote:\n- This function handles a **closed** interval.\n- This function returns the length of MITREAP instead if MITREAP[START]+\n... +MITREAP[length-1] < VALUE.\n- The prefix sums of MITREAP, (MITREAP[START], MITREAP[START]+MITREAP[START+1], ...)\n must be monotone w.r.t. ORDER.\n- ORDER must be a strict order\"\n (declare ((integer 0 #.most-positive-fixnum) start))\n (multiple-value-bind (mitreap-prefix mitreap)\n (if (zerop start)\n (values nil mitreap)\n (mitreap-split mitreap start))\n (labels\n ((recur (mitreap offset prev-sum)\n (declare ((integer 0 #.most-positive-fixnum) offset)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (unless mitreap\n (return-from recur offset))\n (let ((sum prev-sum))\n (prog1\n (cond ((not (funcall order\n (setq sum (mop sum (mitreap-accumulator (%mitreap-left mitreap))))\n value))\n (recur (%mitreap-left mitreap) offset prev-sum))\n ((not (funcall order\n (setq sum (mop sum (%mitreap-value mitreap)))\n value))\n (+ offset (mitreap-count (%mitreap-left mitreap))))\n (t\n (recur (%mitreap-right mitreap)\n (+ offset (mitreap-count (%mitreap-left mitreap)) 1)\n sum)))\n (mforce-up mitreap)))))\n (prog1 (+ start (recur mitreap 0 +mop-identity+))\n (mitreap-merge mitreap-prefix mitreap)))))\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n (bs (make-array n :element-type 'uint31))\n (pairs (make-array n :element-type '(cons uint32 uint32))))\n (dotimes (i n)\n (let ((a (read-fixnum)))\n (setf (aref as i) a)))\n (dotimes (i n)\n (let ((b (read-fixnum)))\n (setf (aref bs i) b)))\n (dotimes (i n)\n (setf (aref pairs i)\n (cons (aref as i) (aref bs i))))\n (setq pairs (sort pairs (lambda (x y) (< (the uint31 x) (the uint31 y))) :key #'cdr))\n (let ((new-as (make-array n :element-type 'uint31))\n (sorted-as (sort (copy-seq as) #'<))\n (sorted-bs (sort (copy-seq bs) #'<)))\n (declare ((simple-array uint31 (*)) sorted-as sorted-bs))\n (dotimes (i n)\n (setf (aref new-as i) (car (aref pairs i))))\n (when (loop for a across sorted-as\n for b across sorted-bs\n thereis (> a b))\n (write-line \"No\")\n (return-from main))\n (when (< (length (delete-adjacent-duplicates (copy-seq sorted-as)))\n n)\n (write-line \"Yes\")\n (return-from main))\n (let ((dp (make-itreap n :initial-contents new-as))\n (pos 0))\n (dotimes (i (- n 2))\n (loop while (and (< pos n)\n (<= (itreap-ref dp pos) (aref sorted-bs pos)))\n do (incf pos))\n (when (= pos n)\n (return))\n (let* ((new-min (itreap-query dp pos n))\n (min-pos (itreap-range-bisect-left dp new-min #'> pos)))\n (declare (uint62 new-min min-pos))\n (unless (<= new-min (itreap-ref dp pos))\n (write-line \"No\")\n (return-from main))\n (rotatef (itreap-ref dp pos)\n (itreap-ref dp min-pos))))\n (when (loop for i below n\n always (<= (itreap-ref dp i) (aref sorted-bs i)))\n (write-line \"Yes\")\n (return-from main)))\n (let ((dp (make-mitreap n :initial-contents new-as))\n (pos (- n 1)))\n (dotimes (i (- n 2))\n (loop while (and (<= 0 pos)\n (<= (mitreap-ref dp pos) (aref sorted-bs pos)))\n do (decf pos))\n (when (< pos 0)\n (return))\n (let* ((new-max (mitreap-query dp 0 (+ pos 1)))\n (max-pos (mitreap-range-bisect-left dp new-max #'<)))\n (declare (uint62 new-max max-pos))\n (unless (<= new-max (mitreap-ref dp pos))\n (write-line \"No\")\n (return-from main))\n (rotatef (mitreap-ref dp pos)\n (mitreap-ref dp max-pos))))\n (when (loop for i below n\n always (<= (mitreap-ref dp i) (aref sorted-bs i)))\n (write-line \"Yes\")\n (return-from main)))\n (write-line \"No\"))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 3 2\n1 2 3\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2 3\n2 2 2\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n3 1 2 6 3 4\n2 2 8 3 4 3\n\"\n \"Yes\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven are two integer sequences of N elements each: A_1,...,A_N and B_1,...,B_N.\nDetermine if it is possible to do the following operation at most N-2 times (possibly zero) so that, for every integer i from 1 to N, A_i \\leq B_i holds:\n\nChoose two distinct integers x and y between 1 and N (inclusive), and swap the values of A_x and A_y.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq A_i,B_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\nB_1 B_2 ... B_N\n\nOutput\n\nIf the objective is achievable, print Yes; if it is not, print No.\n\nSample Input 1\n\n3\n1 3 2\n1 2 3\n\nSample Output 1\n\nYes\n\nWe should swap the values of A_2 and A_3.\n\nSample Input 2\n\n3\n1 2 3\n2 2 2\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n6\n3 1 2 6 3 4\n2 2 8 3 4 3\n\nSample Output 3\n\nYes", "sample_input": "3\n1 3 2\n1 2 3\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02867", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are two integer sequences of N elements each: A_1,...,A_N and B_1,...,B_N.\nDetermine if it is possible to do the following operation at most N-2 times (possibly zero) so that, for every integer i from 1 to N, A_i \\leq B_i holds:\n\nChoose two distinct integers x and y between 1 and N (inclusive), and swap the values of A_x and A_y.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq A_i,B_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\nB_1 B_2 ... B_N\n\nOutput\n\nIf the objective is achievable, print Yes; if it is not, print No.\n\nSample Input 1\n\n3\n1 3 2\n1 2 3\n\nSample Output 1\n\nYes\n\nWe should swap the values of A_2 and A_3.\n\nSample Input 2\n\n3\n1 2 3\n2 2 2\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n6\n3 1 2 6 3 4\n2 2 8 3 4 3\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 32449, "cpu_time_ms": 1806, "memory_kb": 104036}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s119992826", "group_id": "codeNet:p02868", "input_text": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Implicit treap\n;;; (treap with implicit key)\n;;;\n\n;; TODO: abstraction\n\n(defpackage :cp/implicit-treap\n (:use :cl)\n (:export #:itreap #:itreap-p #:itreap-count #:itreap-accumulator\n #:make-itreap #:invalid-itreap-index-error #:itreap-ref\n #:itreap-split #:itreap-merge #:itreap-insert #:itreap-delete\n #:itreap-push #:itreap-pop #:itreap-map #:do-itreap\n #:itreap-fold #:itreap-fold-bisect #:itreap-fold-bisect-from-end\n #:itreap-update #:itreap-reverse\n #:itreap-bisect-left #:itreap-bisect-right #:itreap-insort))\n(in-package :cp/implicit-treap)\n\n;; Note:\n;; - An empty treap is NIL.\n\n(declaim (inline op))\n(defun op (a b)\n \"Is a binary operator comprising a monoid.\"\n (min a b))\n\n(defconstant +op-identity+ most-positive-fixnum\n \"identity element w.r.t. OP\")\n\n(declaim (inline updater-op))\n(defun updater-op (lazy x)\n \"Is the operator to compute and update LAZY value. LAZY is the current LAZY\nvalue and X is an operand.\"\n (min lazy x))\n\n(defconstant +updater-identity+ most-positive-fixnum\n \"identity element w.r.t. UPDATER-OP\")\n\n(declaim (inline modifier-op))\n(defun modifier-op (acc lazy size)\n \"Is the operator to update ACCUMULATOR (and VALUE) based on LAZY value. ACC is\nthe current ACCUMULATOR value and LAZY is the LAZY value. SIZE is the length of\nthe target interval.\"\n (declare (ignorable size))\n (min acc lazy))\n\n(defstruct (itreap (:constructor %make-itreap (value priority &key left right (count 1) (accumulator value) (lazy +updater-identity+)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum)\n (lazy +updater-identity+ :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (mod #.most-positive-fixnum)) ; size of (sub)treap\n (left nil :type (or null itreap))\n (right nil :type (or null itreap)))\n\n(declaim (inline itreap-count))\n(defun itreap-count (itreap)\n \"Returns the number of the elements of ITREAP.\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-count itreap)\n 0))\n\n(declaim (inline itreap-accumulator))\n(defun itreap-accumulator (itreap)\n \"Returns the sum (w.r.t. OP) of the whole ITREAP:\nITREAP[0]+ITREAP[1]+...+ITREAP[SIZE-1].\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-accumulator itreap)\n +op-identity+))\n\n(declaim (inline update-count))\n(defun update-count (itreap)\n (declare (itreap itreap))\n (setf (%itreap-count itreap)\n (+ 1\n (itreap-count (%itreap-left itreap))\n (itreap-count (%itreap-right itreap)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (itreap)\n (declare (itreap itreap))\n (setf (%itreap-accumulator itreap)\n (if (%itreap-left itreap)\n (if (%itreap-right itreap)\n (let ((mid (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap))))\n (op mid (%itreap-accumulator (%itreap-right itreap))))\n (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap)))\n (if (%itreap-right itreap)\n (op (%itreap-value itreap)\n (%itreap-accumulator (%itreap-right itreap)))\n (%itreap-value itreap)))))\n\n(declaim (inline force-up))\n(defun force-up (itreap)\n \"Propagates up the information from children.\"\n (declare (itreap itreap))\n (update-count itreap)\n (update-accumulator itreap))\n\n(declaim (inline force-down))\n(defun force-down (itreap)\n \"Propagates down the information to children.\"\n (declare (itreap itreap))\n (unless (eql +updater-identity+ (%itreap-lazy itreap))\n (when (%itreap-left itreap)\n (setf (%itreap-lazy (%itreap-left itreap))\n (updater-op (%itreap-lazy (%itreap-left itreap))\n (%itreap-lazy itreap)))\n (setf (%itreap-accumulator (%itreap-left itreap))\n (modifier-op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-lazy itreap)\n (%itreap-count (%itreap-left itreap)))))\n (when (%itreap-right itreap)\n (setf (%itreap-lazy (%itreap-right itreap))\n (updater-op (%itreap-lazy (%itreap-right itreap))\n (%itreap-lazy itreap)))\n (setf (%itreap-accumulator (%itreap-right itreap))\n (modifier-op (%itreap-accumulator (%itreap-right itreap))\n (%itreap-lazy itreap)\n (%itreap-count (%itreap-right itreap)))))\n (setf (%itreap-value itreap)\n (modifier-op (%itreap-value itreap)\n (%itreap-lazy itreap)\n 1))\n (setf (%itreap-lazy itreap) +updater-identity+)))\n\n(defun %heapify (node)\n \"Makes it max-heap w.r.t. priorities by swapping the priorities of the whole\ntreap.\"\n (declare (optimize (speed 3) (safety 0)))\n (when node\n (let ((high-priority-node node))\n (when (and (%itreap-left node)\n (> (%itreap-priority (%itreap-left node))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-left node)))\n (when (and (%itreap-right node)\n (> (%itreap-priority (%itreap-right node))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-right node)))\n (unless (eql high-priority-node node)\n (rotatef (%itreap-priority high-priority-node)\n (%itreap-priority node))\n (%heapify high-priority-node)))))\n\n(declaim (inline make-itreap))\n(defun make-itreap (size &key initial-contents)\n \"Makes a treap of SIZE in O(SIZE) time. Its values are filled with the\nidentity element unless INITIAL-CONTENTS are supplied.\"\n (declare ((or null vector) initial-contents))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-itreap (if initial-contents\n (aref initial-contents mid)\n +op-identity+)\n (random most-positive-fixnum))))\n (setf (%itreap-left node) (build l mid))\n (setf (%itreap-right node) (build (+ mid 1) r))\n (%heapify node)\n (force-up node)\n node))))\n (build 0 size)))\n\n(define-condition invalid-itreap-index-error (type-error)\n ((itreap :initarg :itreap :reader invalid-itreap-index-error-itreap)\n (index :initarg :index :reader invalid-itreap-index-error-index))\n (:report\n (lambda (condition stream)\n (let ((index (invalid-itreap-index-error-index condition)))\n (if (consp index)\n (format stream \"Invalid range [~W, ~W) for itreap ~W.\"\n (car index)\n (cdr index)\n (invalid-itreap-index-error-itreap condition))\n (format stream \"Invalid index ~W for itreap ~W.\"\n index\n (invalid-itreap-index-error-itreap condition)))))))\n\n(defun itreap-split (itreap index)\n \"Destructively splits ITREAP at INDEX and returns two treaps (in ascending\norder).\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) index))\n (unless (<= index (itreap-count itreap))\n (error 'invalid-itreap-index-error :index index :itreap itreap))\n (labels ((recur (itreap ikey)\n (unless itreap\n (return-from itreap-split (values nil nil)))\n (force-down itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= ikey left-count)\n (multiple-value-bind (left right)\n (itreap-split (%itreap-left itreap) ikey)\n (setf (%itreap-left itreap) right)\n (force-up itreap)\n (values left itreap))\n (multiple-value-bind (left right)\n (itreap-split (%itreap-right itreap) (- ikey left-count 1))\n (setf (%itreap-right itreap) left)\n (force-up itreap)\n (values itreap right))))))\n (recur itreap index)))\n\n(defun itreap-merge (left right)\n \"Destructively concatenates two ITREAPs. Note that this `merge' is different\nfrom CL:MERGE and rather close to CL:CONCATENATE.\"\n (declare (optimize (speed 3))\n ((or null itreap) left right))\n (cond ((null left) (when right (force-down right) (force-up right)) right)\n ((null right) (when left (force-down left) (force-up left)) left)\n (t (force-down left)\n (force-down right)\n (if (> (%itreap-priority left) (%itreap-priority right))\n (progn\n (setf (%itreap-right left)\n (itreap-merge (%itreap-right left) right))\n (force-up left)\n left)\n (progn\n (setf (%itreap-left right)\n (itreap-merge left (%itreap-left right)))\n (force-up right)\n right)))))\n\n(defun itreap-insert (itreap index obj)\n \"Destructively inserts OBJ into ITREAP at INDEX and returns the resultant treap.\n\nYou cannot rely on the side effect. Use the returned value.\"\n (declare (optimize (speed 3))\n ((or null itreap) itreap)\n ((integer 0 #.most-positive-fixnum) index))\n (unless (<= index (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index index))\n (let ((node (%make-itreap obj (random most-positive-fixnum))))\n (labels ((recur (itreap ikey)\n (declare ((integer 0 #.most-positive-fixnum) ikey))\n (unless itreap (return-from recur node))\n (force-down itreap)\n (if (> (%itreap-priority node) (%itreap-priority itreap))\n (progn\n (setf (values (%itreap-left node) (%itreap-right node))\n (itreap-split itreap ikey))\n (force-up node)\n node)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= ikey left-count)\n (setf (%itreap-left itreap)\n (recur (%itreap-left itreap) ikey))\n (setf (%itreap-right itreap)\n (recur (%itreap-right itreap) (- ikey left-count 1))))\n (force-up itreap)\n itreap))))\n (recur itreap index))))\n\n(defun itreap-delete (itreap index)\n \"Destructively deletes the object at INDEX in ITREAP.\n\nYou cannot rely on the side effect. Use the returned value.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index index))\n (labels ((recur (itreap ikey)\n (declare ((integer 0 #.most-positive-fixnum) ikey))\n (force-down itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (cond ((< ikey left-count)\n (setf (%itreap-left itreap)\n (recur (%itreap-left itreap) ikey))\n (force-up itreap)\n itreap)\n ((> ikey left-count)\n (setf (%itreap-right itreap)\n (recur (%itreap-right itreap) (- ikey left-count 1)))\n (force-up itreap)\n itreap)\n (t\n (itreap-merge (%itreap-left itreap) (%itreap-right itreap)))))))\n (recur itreap index)))\n\n(defmacro itreap-push (obj itreap pos)\n \"Pushes OBJ to ITREAP at POS.\"\n `(setf ,itreap (itreap-insert ,itreap ,pos ,obj)))\n\n(defmacro itreap-pop (itreap pos)\n \"Returns the object at POS and deletes it.\"\n (let ((p (gensym)))\n `(let ((,p ,pos))\n (prog1 (itreap-ref ,itreap ,p)\n (setf ,itreap (itreap-delete ,itreap ,p))))))\n\n(declaim (inline itreap-map))\n(defun itreap-map (function itreap)\n \"Successively applies FUNCTION to ITREAP[0], ..., ITREAP[SIZE-1].\"\n (declare (function function))\n (labels ((recur (node)\n (when node\n (force-down node)\n (recur (%itreap-left node))\n (funcall function (%itreap-value node))\n (recur (%itreap-right node))\n (force-up node))))\n (recur itreap)))\n\n(defmethod print-object ((object itreap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (itreap-map (lambda (x)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write x :stream stream))\n object))))\n\n(defmacro do-itreap ((var itreap &optional result) &body body)\n \"Successively binds ITREAP[0], ..., ITREAP[SIZE-1] to VAR and executes BODY\neach time.\"\n `(block nil\n (itreap-map (lambda (,var) ,@body) ,itreap)\n ,result))\n\n(defun itreap (&rest args)\n ;; NOTE: This function takes O(nlog(n)) time. Use MAKE-ITREAP for efficiency.\n (labels ((recur (list position itreap)\n (declare ((integer 0 #.most-positive-fixnum) position))\n (if (null list)\n itreap\n (recur (cdr list)\n (1+ position)\n (itreap-insert itreap position (car list))))))\n (recur args 0 nil)))\n\n(declaim (inline itreap-ref))\n(defun itreap-ref (itreap index)\n \"Returns the element ITREAP[INDEX].\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index index))\n (labels ((%ref (itreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (force-down itreap)\n (prog1\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (cond ((< index left-count)\n (%ref (%itreap-left itreap) index))\n ((> index left-count)\n (%ref (%itreap-right itreap) (- index left-count 1)))\n (t (%itreap-value itreap))))\n (force-up itreap))))\n (%ref itreap index)))\n\n(declaim (inline (setf itreap-ref)))\n(defun (setf itreap-ref) (new-value itreap index)\n \"Sets ITREAP[INDEX] to the given value.\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index index))\n (labels ((%set (itreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (force-down itreap)\n (prog1\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (cond ((< index left-count)\n (%set (%itreap-left itreap) index))\n ((> index left-count)\n (%set (%itreap-right itreap) (- index left-count 1)))\n (t (setf (%itreap-value itreap) new-value))))\n (force-up itreap))))\n (%set itreap index)\n new-value))\n\n(declaim (inline itreap-fold))\n(defun itreap-fold (itreap l r)\n \"Returns the `sum' (w.r.t. OP) of the range ITREAP[L, R).\"\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless (<= l r (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index (cons l r)))\n (labels\n ((recur (itreap l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless itreap\n (return-from recur +op-identity+))\n (force-down itreap)\n (prog1\n (if (and (zerop l) (= r (%itreap-count itreap)))\n (itreap-accumulator itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= l left-count)\n (if (< left-count r)\n ;; LEFT-COUNT is in [L, R)\n (op (op (recur (%itreap-left itreap) l (min r left-count))\n (%itreap-value itreap))\n (recur (%itreap-right itreap) 0 (- r left-count 1)))\n ;; LEFT-COUNT is in [R, END)\n (recur (%itreap-left itreap) l (min r left-count)))\n ;; LEFT-COUNT is in [0, L)\n (recur (%itreap-right itreap) (- l left-count 1) (- r left-count 1)))))\n (force-up itreap))))\n (recur itreap l r)))\n\n;; FIXME: might be problematic when two priorities collide and START is not\n;; zero. (It will be negligible from the viewpoint of probability, however.)\n(declaim (inline itreap-fold-bisect))\n(defun itreap-fold-bisect (itreap test &optional (start 0))\n \"Returns the largest index that satisfies (FUNCALL TEST (OP ITREAP[START]\nITREAP[START+1] ... ITREAP[index-1])).\n\nNote:\n- (FUNCALL TEST +OP-IDENTITY+) must be true.\n- TEST must be monotone in the target range.\n\"\n (declare ((integer 0 #.most-positive-fixnum) start))\n (assert (funcall test +op-identity+))\n (multiple-value-bind (itreap-prefix itreap)\n (if (zerop start)\n (values nil itreap)\n (itreap-split itreap start))\n (labels\n ((recur (itreap offset prev-sum)\n (declare ((integer 0 #.most-positive-fixnum) offset)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (unless itreap\n (return-from recur offset))\n (force-down itreap)\n (let ((sum prev-sum))\n (prog1\n (cond ((not (funcall test (setq sum (op sum (itreap-accumulator (%itreap-left itreap))))))\n (recur (%itreap-left itreap) offset prev-sum))\n ((not (funcall test (setq sum (op sum (%itreap-value itreap)))))\n (+ offset (itreap-count (%itreap-left itreap))))\n (t\n (recur (%itreap-right itreap)\n (+ offset (itreap-count (%itreap-left itreap)) 1)\n sum)))\n (force-up itreap)))))\n (prog1 (+ start (recur itreap 0 +op-identity+))\n (itreap-merge itreap-prefix itreap)))))\n\n(declaim (inline itreap-fold-bisect-from-end))\n(defun itreap-fold-bisect-from-end (itreap test &optional end)\n \"Returns the smallest index that satisfies (FUNCALL TEST (OP ITREAP[index]\n ITREAP[index+1] ... ITREAP[END-1])).\n\nNote:\n- (FUNCALL TEST +OP-IDENTITY+) must be true.\n- TEST must be monotone in the target range.\n\"\n (declare ((or null (integer 0 #.most-positive-fixnum)) end))\n (assert (funcall test +op-identity+))\n (multiple-value-bind (itreap itreap-suffix)\n (if end\n (itreap-split itreap end)\n (values itreap nil))\n (labels\n ((recur (itreap offset prev-sum)\n (declare ((integer 0 #.most-positive-fixnum) offset)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (unless itreap\n (return-from recur offset))\n (force-down itreap)\n (let ((sum prev-sum))\n (prog1\n (cond ((not (funcall test (setq sum (op (itreap-accumulator (%itreap-right itreap)) sum))))\n (recur (%itreap-right itreap) offset prev-sum))\n ((not (funcall test (setq sum (op (%itreap-value itreap) sum))))\n (+ offset (itreap-count (%itreap-right itreap))))\n (t\n (recur (%itreap-left itreap)\n (+ offset (itreap-count (%itreap-right itreap)) 1)\n sum)))\n (force-up itreap)))))\n (prog1 (- (or end (itreap-count itreap))\n (recur itreap 0 +op-identity+))\n (itreap-merge itreap itreap-suffix)))))\n\n(declaim (inline itreap-update))\n(defun itreap-update (itreap operand l r)\n \"Updates ITRAP by ITREAP[i] := (OP ITREAP[i] OPERAND) for all i in [l, r)\"\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless (<= l r (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index (cons l r)))\n (labels\n ((recur (itreap l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (when itreap\n (if (and (zerop l) (= r (%itreap-count itreap)))\n (progn\n (setf (%itreap-lazy itreap)\n (updater-op (%itreap-lazy itreap) operand))\n (force-down itreap))\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (force-down itreap)\n (if (<= l left-count)\n (if (< left-count r)\n ;; LEFT-COUNT is in [L, R)\n (progn\n (recur (%itreap-left itreap) l (min r left-count))\n (setf (%itreap-value itreap)\n (modifier-op (%itreap-value itreap) operand 1))\n (recur (%itreap-right itreap) 0 (- r left-count 1)))\n ;; LEFT-COUNT is in [R, END)\n (recur (%itreap-left itreap) l (min r left-count)))\n ;; LEFT-COUNT is in [0, L)\n (recur (%itreap-right itreap) (- l left-count 1) (- r left-count 1)))))\n (force-up itreap))))\n (recur itreap l r)\n itreap))\n\n;;;\n;;; Below are utilities for treap whose values are sorted w.r.t. some order\n;;;\n\n(declaim (inline itreap-bisect-left)\n (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) itreap-bisect-left))\n(defun itreap-bisect-left (itreap value order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nITREAP[index] >= VALUE, where >= is the complement of ORDER. In other words,\nthis function returns a leftmost index at which value can be inserted with\nkeeping the order. Returns the size of ITREAP if ITREAP[length-1] <\nVALUE. The time complexity is O(log(n)).\"\n (labels ((recur (count itreap)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null itreap) nil)\n ((funcall order (%itreap-value itreap) value)\n (recur count (%itreap-right itreap)))\n (t\n (let ((left-count (- count (itreap-count (%itreap-right itreap)) 1)))\n (or (recur left-count (%itreap-left itreap))\n left-count))))))\n (or (recur (itreap-count itreap) itreap)\n (itreap-count itreap))))\n\n(declaim (inline itreap-bisect-right)\n (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) itreap-bisect-right))\n(defun itreap-bisect-right (itreap value order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nVALUE < ITREAP[index], where < is ORDER. In other words, this function\nreturns a rightmost index at which VALUE can be inserted with keeping the\norder. Returns the size of ITREAP if ITREAP[length-1] <= VALUE. The time\ncomplexity is O(log(n)).\"\n (labels ((recur (count itreap)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null itreap) nil)\n ((funcall order value (%itreap-value itreap))\n (let ((left-count (- count (itreap-count (%itreap-right itreap)) 1)))\n (or (recur left-count (%itreap-left itreap))\n left-count)))\n (t\n (recur count (%itreap-right itreap))))))\n (or (recur (itreap-count itreap) itreap)\n (itreap-count itreap))))\n\n(declaim (inline itreap-insort))\n(defun itreap-insort (itreap obj order)\n \"Does insertion to the sorted treap with keeping the order. You cannot rely on\nthe side effect. Use the returned value.\"\n (let ((pos (itreap-bisect-left itreap obj order)))\n (itreap-insert itreap pos obj)))\n\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/implicit-treap :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (events (make-array n :element-type 'list :initial-element nil))\n (itreap (make-itreap n)))\n (dotimes (i m)\n (let ((l (- (read-fixnum) 1))\n (r (read-fixnum))\n (c (read-fixnum)))\n (push (cons r c) (aref events l))))\n (setf (itreap-ref itreap 0) 0)\n (dotimes (l n)\n #>itreap\n (let ((dist (itreap-ref itreap l)))\n (unless (= dist most-positive-fixnum)\n (loop for (r . c) in (aref events l)\n do (dbg l r c) (itreap-update itreap (+ dist c) l r)))))\n (let ((res (itreap-ref itreap (- n 1))))\n (println (if (= res most-positive-fixnum)\n -1\n res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (5am:is\n (equal \"5\n\"\n (run \"4 3\n1 3 2\n2 4 3\n1 4 6\n\" nil)))\n (5am:is\n (equal \"-1\n\"\n (run \"4 2\n1 2 1\n3 4 2\n\" nil)))\n (5am:is\n (equal \"28\n\"\n (run \"10 7\n1 5 18\n3 4 8\n1 3 5\n4 7 10\n5 9 8\n6 10 5\n8 10 3\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1600770963, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02868.html", "problem_id": "p02868", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02868/input.txt", "sample_output_relpath": "derived/input_output/data/p02868/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02868/Lisp/s119992826.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s119992826", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Implicit treap\n;;; (treap with implicit key)\n;;;\n\n;; TODO: abstraction\n\n(defpackage :cp/implicit-treap\n (:use :cl)\n (:export #:itreap #:itreap-p #:itreap-count #:itreap-accumulator\n #:make-itreap #:invalid-itreap-index-error #:itreap-ref\n #:itreap-split #:itreap-merge #:itreap-insert #:itreap-delete\n #:itreap-push #:itreap-pop #:itreap-map #:do-itreap\n #:itreap-fold #:itreap-fold-bisect #:itreap-fold-bisect-from-end\n #:itreap-update #:itreap-reverse\n #:itreap-bisect-left #:itreap-bisect-right #:itreap-insort))\n(in-package :cp/implicit-treap)\n\n;; Note:\n;; - An empty treap is NIL.\n\n(declaim (inline op))\n(defun op (a b)\n \"Is a binary operator comprising a monoid.\"\n (min a b))\n\n(defconstant +op-identity+ most-positive-fixnum\n \"identity element w.r.t. OP\")\n\n(declaim (inline updater-op))\n(defun updater-op (lazy x)\n \"Is the operator to compute and update LAZY value. LAZY is the current LAZY\nvalue and X is an operand.\"\n (min lazy x))\n\n(defconstant +updater-identity+ most-positive-fixnum\n \"identity element w.r.t. UPDATER-OP\")\n\n(declaim (inline modifier-op))\n(defun modifier-op (acc lazy size)\n \"Is the operator to update ACCUMULATOR (and VALUE) based on LAZY value. ACC is\nthe current ACCUMULATOR value and LAZY is the LAZY value. SIZE is the length of\nthe target interval.\"\n (declare (ignorable size))\n (min acc lazy))\n\n(defstruct (itreap (:constructor %make-itreap (value priority &key left right (count 1) (accumulator value) (lazy +updater-identity+)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum)\n (lazy +updater-identity+ :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (mod #.most-positive-fixnum)) ; size of (sub)treap\n (left nil :type (or null itreap))\n (right nil :type (or null itreap)))\n\n(declaim (inline itreap-count))\n(defun itreap-count (itreap)\n \"Returns the number of the elements of ITREAP.\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-count itreap)\n 0))\n\n(declaim (inline itreap-accumulator))\n(defun itreap-accumulator (itreap)\n \"Returns the sum (w.r.t. OP) of the whole ITREAP:\nITREAP[0]+ITREAP[1]+...+ITREAP[SIZE-1].\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-accumulator itreap)\n +op-identity+))\n\n(declaim (inline update-count))\n(defun update-count (itreap)\n (declare (itreap itreap))\n (setf (%itreap-count itreap)\n (+ 1\n (itreap-count (%itreap-left itreap))\n (itreap-count (%itreap-right itreap)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (itreap)\n (declare (itreap itreap))\n (setf (%itreap-accumulator itreap)\n (if (%itreap-left itreap)\n (if (%itreap-right itreap)\n (let ((mid (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap))))\n (op mid (%itreap-accumulator (%itreap-right itreap))))\n (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap)))\n (if (%itreap-right itreap)\n (op (%itreap-value itreap)\n (%itreap-accumulator (%itreap-right itreap)))\n (%itreap-value itreap)))))\n\n(declaim (inline force-up))\n(defun force-up (itreap)\n \"Propagates up the information from children.\"\n (declare (itreap itreap))\n (update-count itreap)\n (update-accumulator itreap))\n\n(declaim (inline force-down))\n(defun force-down (itreap)\n \"Propagates down the information to children.\"\n (declare (itreap itreap))\n (unless (eql +updater-identity+ (%itreap-lazy itreap))\n (when (%itreap-left itreap)\n (setf (%itreap-lazy (%itreap-left itreap))\n (updater-op (%itreap-lazy (%itreap-left itreap))\n (%itreap-lazy itreap)))\n (setf (%itreap-accumulator (%itreap-left itreap))\n (modifier-op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-lazy itreap)\n (%itreap-count (%itreap-left itreap)))))\n (when (%itreap-right itreap)\n (setf (%itreap-lazy (%itreap-right itreap))\n (updater-op (%itreap-lazy (%itreap-right itreap))\n (%itreap-lazy itreap)))\n (setf (%itreap-accumulator (%itreap-right itreap))\n (modifier-op (%itreap-accumulator (%itreap-right itreap))\n (%itreap-lazy itreap)\n (%itreap-count (%itreap-right itreap)))))\n (setf (%itreap-value itreap)\n (modifier-op (%itreap-value itreap)\n (%itreap-lazy itreap)\n 1))\n (setf (%itreap-lazy itreap) +updater-identity+)))\n\n(defun %heapify (node)\n \"Makes it max-heap w.r.t. priorities by swapping the priorities of the whole\ntreap.\"\n (declare (optimize (speed 3) (safety 0)))\n (when node\n (let ((high-priority-node node))\n (when (and (%itreap-left node)\n (> (%itreap-priority (%itreap-left node))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-left node)))\n (when (and (%itreap-right node)\n (> (%itreap-priority (%itreap-right node))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-right node)))\n (unless (eql high-priority-node node)\n (rotatef (%itreap-priority high-priority-node)\n (%itreap-priority node))\n (%heapify high-priority-node)))))\n\n(declaim (inline make-itreap))\n(defun make-itreap (size &key initial-contents)\n \"Makes a treap of SIZE in O(SIZE) time. Its values are filled with the\nidentity element unless INITIAL-CONTENTS are supplied.\"\n (declare ((or null vector) initial-contents))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-itreap (if initial-contents\n (aref initial-contents mid)\n +op-identity+)\n (random most-positive-fixnum))))\n (setf (%itreap-left node) (build l mid))\n (setf (%itreap-right node) (build (+ mid 1) r))\n (%heapify node)\n (force-up node)\n node))))\n (build 0 size)))\n\n(define-condition invalid-itreap-index-error (type-error)\n ((itreap :initarg :itreap :reader invalid-itreap-index-error-itreap)\n (index :initarg :index :reader invalid-itreap-index-error-index))\n (:report\n (lambda (condition stream)\n (let ((index (invalid-itreap-index-error-index condition)))\n (if (consp index)\n (format stream \"Invalid range [~W, ~W) for itreap ~W.\"\n (car index)\n (cdr index)\n (invalid-itreap-index-error-itreap condition))\n (format stream \"Invalid index ~W for itreap ~W.\"\n index\n (invalid-itreap-index-error-itreap condition)))))))\n\n(defun itreap-split (itreap index)\n \"Destructively splits ITREAP at INDEX and returns two treaps (in ascending\norder).\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) index))\n (unless (<= index (itreap-count itreap))\n (error 'invalid-itreap-index-error :index index :itreap itreap))\n (labels ((recur (itreap ikey)\n (unless itreap\n (return-from itreap-split (values nil nil)))\n (force-down itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= ikey left-count)\n (multiple-value-bind (left right)\n (itreap-split (%itreap-left itreap) ikey)\n (setf (%itreap-left itreap) right)\n (force-up itreap)\n (values left itreap))\n (multiple-value-bind (left right)\n (itreap-split (%itreap-right itreap) (- ikey left-count 1))\n (setf (%itreap-right itreap) left)\n (force-up itreap)\n (values itreap right))))))\n (recur itreap index)))\n\n(defun itreap-merge (left right)\n \"Destructively concatenates two ITREAPs. Note that this `merge' is different\nfrom CL:MERGE and rather close to CL:CONCATENATE.\"\n (declare (optimize (speed 3))\n ((or null itreap) left right))\n (cond ((null left) (when right (force-down right) (force-up right)) right)\n ((null right) (when left (force-down left) (force-up left)) left)\n (t (force-down left)\n (force-down right)\n (if (> (%itreap-priority left) (%itreap-priority right))\n (progn\n (setf (%itreap-right left)\n (itreap-merge (%itreap-right left) right))\n (force-up left)\n left)\n (progn\n (setf (%itreap-left right)\n (itreap-merge left (%itreap-left right)))\n (force-up right)\n right)))))\n\n(defun itreap-insert (itreap index obj)\n \"Destructively inserts OBJ into ITREAP at INDEX and returns the resultant treap.\n\nYou cannot rely on the side effect. Use the returned value.\"\n (declare (optimize (speed 3))\n ((or null itreap) itreap)\n ((integer 0 #.most-positive-fixnum) index))\n (unless (<= index (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index index))\n (let ((node (%make-itreap obj (random most-positive-fixnum))))\n (labels ((recur (itreap ikey)\n (declare ((integer 0 #.most-positive-fixnum) ikey))\n (unless itreap (return-from recur node))\n (force-down itreap)\n (if (> (%itreap-priority node) (%itreap-priority itreap))\n (progn\n (setf (values (%itreap-left node) (%itreap-right node))\n (itreap-split itreap ikey))\n (force-up node)\n node)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= ikey left-count)\n (setf (%itreap-left itreap)\n (recur (%itreap-left itreap) ikey))\n (setf (%itreap-right itreap)\n (recur (%itreap-right itreap) (- ikey left-count 1))))\n (force-up itreap)\n itreap))))\n (recur itreap index))))\n\n(defun itreap-delete (itreap index)\n \"Destructively deletes the object at INDEX in ITREAP.\n\nYou cannot rely on the side effect. Use the returned value.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index index))\n (labels ((recur (itreap ikey)\n (declare ((integer 0 #.most-positive-fixnum) ikey))\n (force-down itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (cond ((< ikey left-count)\n (setf (%itreap-left itreap)\n (recur (%itreap-left itreap) ikey))\n (force-up itreap)\n itreap)\n ((> ikey left-count)\n (setf (%itreap-right itreap)\n (recur (%itreap-right itreap) (- ikey left-count 1)))\n (force-up itreap)\n itreap)\n (t\n (itreap-merge (%itreap-left itreap) (%itreap-right itreap)))))))\n (recur itreap index)))\n\n(defmacro itreap-push (obj itreap pos)\n \"Pushes OBJ to ITREAP at POS.\"\n `(setf ,itreap (itreap-insert ,itreap ,pos ,obj)))\n\n(defmacro itreap-pop (itreap pos)\n \"Returns the object at POS and deletes it.\"\n (let ((p (gensym)))\n `(let ((,p ,pos))\n (prog1 (itreap-ref ,itreap ,p)\n (setf ,itreap (itreap-delete ,itreap ,p))))))\n\n(declaim (inline itreap-map))\n(defun itreap-map (function itreap)\n \"Successively applies FUNCTION to ITREAP[0], ..., ITREAP[SIZE-1].\"\n (declare (function function))\n (labels ((recur (node)\n (when node\n (force-down node)\n (recur (%itreap-left node))\n (funcall function (%itreap-value node))\n (recur (%itreap-right node))\n (force-up node))))\n (recur itreap)))\n\n(defmethod print-object ((object itreap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (itreap-map (lambda (x)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write x :stream stream))\n object))))\n\n(defmacro do-itreap ((var itreap &optional result) &body body)\n \"Successively binds ITREAP[0], ..., ITREAP[SIZE-1] to VAR and executes BODY\neach time.\"\n `(block nil\n (itreap-map (lambda (,var) ,@body) ,itreap)\n ,result))\n\n(defun itreap (&rest args)\n ;; NOTE: This function takes O(nlog(n)) time. Use MAKE-ITREAP for efficiency.\n (labels ((recur (list position itreap)\n (declare ((integer 0 #.most-positive-fixnum) position))\n (if (null list)\n itreap\n (recur (cdr list)\n (1+ position)\n (itreap-insert itreap position (car list))))))\n (recur args 0 nil)))\n\n(declaim (inline itreap-ref))\n(defun itreap-ref (itreap index)\n \"Returns the element ITREAP[INDEX].\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index index))\n (labels ((%ref (itreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (force-down itreap)\n (prog1\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (cond ((< index left-count)\n (%ref (%itreap-left itreap) index))\n ((> index left-count)\n (%ref (%itreap-right itreap) (- index left-count 1)))\n (t (%itreap-value itreap))))\n (force-up itreap))))\n (%ref itreap index)))\n\n(declaim (inline (setf itreap-ref)))\n(defun (setf itreap-ref) (new-value itreap index)\n \"Sets ITREAP[INDEX] to the given value.\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index index))\n (labels ((%set (itreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (force-down itreap)\n (prog1\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (cond ((< index left-count)\n (%set (%itreap-left itreap) index))\n ((> index left-count)\n (%set (%itreap-right itreap) (- index left-count 1)))\n (t (setf (%itreap-value itreap) new-value))))\n (force-up itreap))))\n (%set itreap index)\n new-value))\n\n(declaim (inline itreap-fold))\n(defun itreap-fold (itreap l r)\n \"Returns the `sum' (w.r.t. OP) of the range ITREAP[L, R).\"\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless (<= l r (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index (cons l r)))\n (labels\n ((recur (itreap l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless itreap\n (return-from recur +op-identity+))\n (force-down itreap)\n (prog1\n (if (and (zerop l) (= r (%itreap-count itreap)))\n (itreap-accumulator itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= l left-count)\n (if (< left-count r)\n ;; LEFT-COUNT is in [L, R)\n (op (op (recur (%itreap-left itreap) l (min r left-count))\n (%itreap-value itreap))\n (recur (%itreap-right itreap) 0 (- r left-count 1)))\n ;; LEFT-COUNT is in [R, END)\n (recur (%itreap-left itreap) l (min r left-count)))\n ;; LEFT-COUNT is in [0, L)\n (recur (%itreap-right itreap) (- l left-count 1) (- r left-count 1)))))\n (force-up itreap))))\n (recur itreap l r)))\n\n;; FIXME: might be problematic when two priorities collide and START is not\n;; zero. (It will be negligible from the viewpoint of probability, however.)\n(declaim (inline itreap-fold-bisect))\n(defun itreap-fold-bisect (itreap test &optional (start 0))\n \"Returns the largest index that satisfies (FUNCALL TEST (OP ITREAP[START]\nITREAP[START+1] ... ITREAP[index-1])).\n\nNote:\n- (FUNCALL TEST +OP-IDENTITY+) must be true.\n- TEST must be monotone in the target range.\n\"\n (declare ((integer 0 #.most-positive-fixnum) start))\n (assert (funcall test +op-identity+))\n (multiple-value-bind (itreap-prefix itreap)\n (if (zerop start)\n (values nil itreap)\n (itreap-split itreap start))\n (labels\n ((recur (itreap offset prev-sum)\n (declare ((integer 0 #.most-positive-fixnum) offset)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (unless itreap\n (return-from recur offset))\n (force-down itreap)\n (let ((sum prev-sum))\n (prog1\n (cond ((not (funcall test (setq sum (op sum (itreap-accumulator (%itreap-left itreap))))))\n (recur (%itreap-left itreap) offset prev-sum))\n ((not (funcall test (setq sum (op sum (%itreap-value itreap)))))\n (+ offset (itreap-count (%itreap-left itreap))))\n (t\n (recur (%itreap-right itreap)\n (+ offset (itreap-count (%itreap-left itreap)) 1)\n sum)))\n (force-up itreap)))))\n (prog1 (+ start (recur itreap 0 +op-identity+))\n (itreap-merge itreap-prefix itreap)))))\n\n(declaim (inline itreap-fold-bisect-from-end))\n(defun itreap-fold-bisect-from-end (itreap test &optional end)\n \"Returns the smallest index that satisfies (FUNCALL TEST (OP ITREAP[index]\n ITREAP[index+1] ... ITREAP[END-1])).\n\nNote:\n- (FUNCALL TEST +OP-IDENTITY+) must be true.\n- TEST must be monotone in the target range.\n\"\n (declare ((or null (integer 0 #.most-positive-fixnum)) end))\n (assert (funcall test +op-identity+))\n (multiple-value-bind (itreap itreap-suffix)\n (if end\n (itreap-split itreap end)\n (values itreap nil))\n (labels\n ((recur (itreap offset prev-sum)\n (declare ((integer 0 #.most-positive-fixnum) offset)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (unless itreap\n (return-from recur offset))\n (force-down itreap)\n (let ((sum prev-sum))\n (prog1\n (cond ((not (funcall test (setq sum (op (itreap-accumulator (%itreap-right itreap)) sum))))\n (recur (%itreap-right itreap) offset prev-sum))\n ((not (funcall test (setq sum (op (%itreap-value itreap) sum))))\n (+ offset (itreap-count (%itreap-right itreap))))\n (t\n (recur (%itreap-left itreap)\n (+ offset (itreap-count (%itreap-right itreap)) 1)\n sum)))\n (force-up itreap)))))\n (prog1 (- (or end (itreap-count itreap))\n (recur itreap 0 +op-identity+))\n (itreap-merge itreap itreap-suffix)))))\n\n(declaim (inline itreap-update))\n(defun itreap-update (itreap operand l r)\n \"Updates ITRAP by ITREAP[i] := (OP ITREAP[i] OPERAND) for all i in [l, r)\"\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless (<= l r (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index (cons l r)))\n (labels\n ((recur (itreap l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (when itreap\n (if (and (zerop l) (= r (%itreap-count itreap)))\n (progn\n (setf (%itreap-lazy itreap)\n (updater-op (%itreap-lazy itreap) operand))\n (force-down itreap))\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (force-down itreap)\n (if (<= l left-count)\n (if (< left-count r)\n ;; LEFT-COUNT is in [L, R)\n (progn\n (recur (%itreap-left itreap) l (min r left-count))\n (setf (%itreap-value itreap)\n (modifier-op (%itreap-value itreap) operand 1))\n (recur (%itreap-right itreap) 0 (- r left-count 1)))\n ;; LEFT-COUNT is in [R, END)\n (recur (%itreap-left itreap) l (min r left-count)))\n ;; LEFT-COUNT is in [0, L)\n (recur (%itreap-right itreap) (- l left-count 1) (- r left-count 1)))))\n (force-up itreap))))\n (recur itreap l r)\n itreap))\n\n;;;\n;;; Below are utilities for treap whose values are sorted w.r.t. some order\n;;;\n\n(declaim (inline itreap-bisect-left)\n (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) itreap-bisect-left))\n(defun itreap-bisect-left (itreap value order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nITREAP[index] >= VALUE, where >= is the complement of ORDER. In other words,\nthis function returns a leftmost index at which value can be inserted with\nkeeping the order. Returns the size of ITREAP if ITREAP[length-1] <\nVALUE. The time complexity is O(log(n)).\"\n (labels ((recur (count itreap)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null itreap) nil)\n ((funcall order (%itreap-value itreap) value)\n (recur count (%itreap-right itreap)))\n (t\n (let ((left-count (- count (itreap-count (%itreap-right itreap)) 1)))\n (or (recur left-count (%itreap-left itreap))\n left-count))))))\n (or (recur (itreap-count itreap) itreap)\n (itreap-count itreap))))\n\n(declaim (inline itreap-bisect-right)\n (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) itreap-bisect-right))\n(defun itreap-bisect-right (itreap value order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nVALUE < ITREAP[index], where < is ORDER. In other words, this function\nreturns a rightmost index at which VALUE can be inserted with keeping the\norder. Returns the size of ITREAP if ITREAP[length-1] <= VALUE. The time\ncomplexity is O(log(n)).\"\n (labels ((recur (count itreap)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null itreap) nil)\n ((funcall order value (%itreap-value itreap))\n (let ((left-count (- count (itreap-count (%itreap-right itreap)) 1)))\n (or (recur left-count (%itreap-left itreap))\n left-count)))\n (t\n (recur count (%itreap-right itreap))))))\n (or (recur (itreap-count itreap) itreap)\n (itreap-count itreap))))\n\n(declaim (inline itreap-insort))\n(defun itreap-insort (itreap obj order)\n \"Does insertion to the sorted treap with keeping the order. You cannot rely on\nthe side effect. Use the returned value.\"\n (let ((pos (itreap-bisect-left itreap obj order)))\n (itreap-insert itreap pos obj)))\n\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/implicit-treap :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (events (make-array n :element-type 'list :initial-element nil))\n (itreap (make-itreap n)))\n (dotimes (i m)\n (let ((l (- (read-fixnum) 1))\n (r (read-fixnum))\n (c (read-fixnum)))\n (push (cons r c) (aref events l))))\n (setf (itreap-ref itreap 0) 0)\n (dotimes (l n)\n #>itreap\n (let ((dist (itreap-ref itreap l)))\n (unless (= dist most-positive-fixnum)\n (loop for (r . c) in (aref events l)\n do (dbg l r c) (itreap-update itreap (+ dist c) l r)))))\n (let ((res (itreap-ref itreap (- n 1))))\n (println (if (= res most-positive-fixnum)\n -1\n res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (5am:is\n (equal \"5\n\"\n (run \"4 3\n1 3 2\n2 4 3\n1 4 6\n\" nil)))\n (5am:is\n (equal \"-1\n\"\n (run \"4 2\n1 2 1\n3 4 2\n\" nil)))\n (5am:is\n (equal \"28\n\"\n (run \"10 7\n1 5 18\n3 4 8\n1 3 5\n4 7 10\n5 9 8\n6 10 5\n8 10 3\n\" nil))))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nWe have N points numbered 1 to N arranged in a line in this order.\n\nTakahashi decides to make an undirected graph, using these points as the vertices.\nIn the beginning, the graph has no edge. Takahashi will do M operations to add edges in this graph.\nThe i-th operation is as follows:\n\nThe operation uses integers L_i and R_i between 1 and N (inclusive), and a positive integer C_i. For every pair of integers (s, t) such that L_i \\leq s < t \\leq R_i, add an edge of length C_i between Vertex s and Vertex t.\n\nThe integers L_1, ..., L_M, R_1, ..., R_M, C_1, ..., C_M are all given as input.\n\nTakahashi wants to solve the shortest path problem in the final graph obtained. Find the length of the shortest path from Vertex 1 to Vertex N in the final graph.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq L_i < R_i \\leq N\n\n1 \\leq C_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nL_1 R_1 C_1\n:\nL_M R_M C_M\n\nOutput\n\nPrint the length of the shortest path from Vertex 1 to Vertex N in the final graph.\nIf there is no shortest path, print -1 instead.\n\nSample Input 1\n\n4 3\n1 3 2\n2 4 3\n1 4 6\n\nSample Output 1\n\n5\n\nWe have an edge of length 2 between Vertex 1 and Vertex 2, and an edge of length 3 between Vertex 2 and Vertex 4, so there is a path of length 5 between Vertex 1 and Vertex 4.\n\nSample Input 2\n\n4 2\n1 2 1\n3 4 2\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n10 7\n1 5 18\n3 4 8\n1 3 5\n4 7 10\n5 9 8\n6 10 5\n8 10 3\n\nSample Output 3\n\n28", "sample_input": "4 3\n1 3 2\n2 4 3\n1 4 6\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02868", "source_text": "Score : 600 points\n\nProblem Statement\n\nWe have N points numbered 1 to N arranged in a line in this order.\n\nTakahashi decides to make an undirected graph, using these points as the vertices.\nIn the beginning, the graph has no edge. Takahashi will do M operations to add edges in this graph.\nThe i-th operation is as follows:\n\nThe operation uses integers L_i and R_i between 1 and N (inclusive), and a positive integer C_i. For every pair of integers (s, t) such that L_i \\leq s < t \\leq R_i, add an edge of length C_i between Vertex s and Vertex t.\n\nThe integers L_1, ..., L_M, R_1, ..., R_M, C_1, ..., C_M are all given as input.\n\nTakahashi wants to solve the shortest path problem in the final graph obtained. Find the length of the shortest path from Vertex 1 to Vertex N in the final graph.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq L_i < R_i \\leq N\n\n1 \\leq C_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nL_1 R_1 C_1\n:\nL_M R_M C_M\n\nOutput\n\nPrint the length of the shortest path from Vertex 1 to Vertex N in the final graph.\nIf there is no shortest path, print -1 instead.\n\nSample Input 1\n\n4 3\n1 3 2\n2 4 3\n1 4 6\n\nSample Output 1\n\n5\n\nWe have an edge of length 2 between Vertex 1 and Vertex 2, and an edge of length 3 between Vertex 2 and Vertex 4, so there is a path of length 5 between Vertex 1 and Vertex 4.\n\nSample Input 2\n\n4 2\n1 2 1\n3 4 2\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n10 7\n1 5 18\n3 4 8\n1 3 5\n4 7 10\n5 9 8\n6 10 5\n8 10 3\n\nSample Output 3\n\n28", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 29958, "cpu_time_ms": 148, "memory_kb": 36260}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s302337045", "group_id": "codeNet:p02869", "input_text": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/treap\n (:use :cl)\n (:export #:treap #:treap-count #:treap-find #:treap-bisect-left #:treap-bisect-right-1\n #:treap-split #:treap-insert #:treap-push #:treap-pop #:treap-delete #:treap-merge\n #:treap-map #:invalid-treap-index-error #:treap-first #:treap-last))\n(in-package :cp/treap)\n\n;; Not included in test script. Better to use ref-able-treap instead.\n\n(defstruct (treap (:constructor %make-treap (key priority &optional left right))\n (:copier nil)\n (:predicate nil)\n (:conc-name %treap-))\n key\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (left nil :type (or null treap))\n (right nil :type (or null treap)))\n\n(declaim (inline treap-key))\n(defun treap-key (treap)\n (and treap (%treap-key treap)))\n\n(declaim (inline treap-find))\n(defun treap-find (key treap &key (order #'<))\n \"Searches the sub-treap of TREAP whose key satisfies (and (not (funcall order\nkey (%treap-key sub-treap))) (not (funcall order (%treap-key sub-treap) key))) and\nreturns KEY. Returns NIL if KEY is not contained.\"\n (declare (function order)\n ((or null treap) treap))\n (labels ((recur (treap)\n (cond ((null treap) nil)\n ((funcall order key (%treap-key treap))\n (recur (%treap-left treap)))\n ((funcall order (%treap-key treap) key)\n (recur (%treap-right treap)))\n (t key))))\n (recur treap)))\n\n(declaim (inline treap-split))\n(defun treap-split (key treap &key (order #'<))\n \"Destructively splits the TREAP with reference to KEY and returns two treaps,\nthe smaller sub-treap (< KEY) and the larger one (>= KEY).\"\n (declare (function order)\n ((or null treap) treap))\n (labels ((recur (treap)\n (cond ((null treap)\n (values nil nil))\n ((funcall order (%treap-key treap) key)\n (multiple-value-bind (left right)\n (recur (%treap-right treap))\n (setf (%treap-right treap) left)\n (values treap right)))\n (t\n (multiple-value-bind (left right)\n (recur (%treap-left treap))\n (setf (%treap-left treap) right)\n (values left treap))))))\n (recur treap)))\n\n(declaim (inline treap-insert))\n(defun treap-insert (key treap &key (order #'<))\n \"Destructively inserts KEY into TREAP and returns the resultant treap. You\ncannot rely on the side effect. Use the returned value.\n\nThe behavior is undefined when duplicate keys are inserted.\"\n (declare ((or null treap) treap)\n (function order))\n (labels ((recur (new-node treap)\n (declare (treap new-node))\n (cond ((null treap) new-node)\n ((> (%treap-priority new-node) (%treap-priority treap))\n (setf (values (%treap-left new-node) (%treap-right new-node))\n (treap-split (%treap-key new-node) treap :order order))\n new-node)\n (t\n (if (funcall order (%treap-key new-node) (%treap-key treap))\n (setf (%treap-left treap)\n (recur new-node (%treap-left treap)))\n (setf (%treap-right treap)\n (recur new-node (%treap-right treap))))\n treap))))\n (recur (%make-treap key (random most-positive-fixnum)) treap)))\n\n(defun treap-map (function treap)\n \"Successively applies FUNCTION to each key of TREAP in the given\norder. FUNCTION must take one argument.\"\n (declare (function function))\n (when treap\n (treap-map function (%treap-left treap))\n (funcall function (%treap-key treap))\n (treap-map function (%treap-right treap))))\n\n(defmethod print-object ((object treap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (treap-map (lambda (key)\n (if init\n (setf init nil)\n (write-char #\\ stream))\n (write key :stream stream))\n object))))\n\n(declaim (ftype (function * (values (or null treap) &optional)) treap-merge))\n(defun treap-merge (left right)\n \"Destructively concatenates two treaps. Assumes that all keys of LEFT are\nsmaller (or larger, depending on the order) than those of RIGHT.\"\n (declare (optimize (speed 3))\n ((or null treap) left right))\n (cond ((null left) right)\n ((null right) left)\n ((> (%treap-priority left) (%treap-priority right))\n (setf (%treap-right left)\n (treap-merge (%treap-right left) right))\n left)\n (t\n (setf (%treap-left right)\n (treap-merge left (%treap-left right)))\n right)))\n\n(declaim (inline treap-delete))\n(defun treap-delete (key treap &key (order #'<))\n \"Destructively deletes the KEY in TREAP and returns the resultant treap. You\ncannot rely on the side effect. Use the returned value.\"\n (declare ((or null treap) treap)\n (function order))\n (labels ((recur (treap)\n (cond ((null treap) nil)\n ((funcall order key (%treap-key treap))\n (setf (%treap-left treap) (recur (%treap-left treap)))\n treap)\n ((funcall order (%treap-key treap) key)\n (setf (%treap-right treap) (recur (%treap-right treap)))\n treap)\n (t\n (treap-merge (%treap-left treap) (%treap-right treap))))))\n (recur treap)))\n\n(defmacro treap-push (key treap order)\n \"Pushes KEY to TREAP.\"\n `(setf ,treap (treap-insert ,key ,treap :order ,order)))\n\n(defmacro treap-pop (key treap order)\n \"Deletes KEY from TREAP.\"\n `(setf ,treap (treap-delete ,key ,treap :order ,order)))\n\n(defun treap-first (treap)\n (declare (optimize (speed 3))\n (treap treap))\n (if (%treap-left treap)\n (treap-first (%treap-left treap))\n (%treap-key treap)))\n\n(defun treap-last (treap)\n (declare (optimize (speed 3))\n (treap treap))\n (if (%treap-right treap)\n (treap-last (%treap-right treap))\n (%treap-key treap)))\n\n(declaim (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) treap-count))\n(defun treap-count (treap)\n \"Counts the number of elements in TREAP in O(n) time.\"\n (declare (optimize (speed 3))\n ((or null treap) treap))\n (labels ((recur (treap)\n (declare (optimize (safety 0)))\n (if (null treap)\n 0\n (+ 1\n (treap-count (%treap-left treap))\n (treap-count (%treap-right treap))))))\n (recur treap)))\n\n(declaim (inline treap-bisect-left))\n(defun treap-bisect-left (treap key &key (order #'<))\n \"Returns the smallest key equal to or larger than KEY. Returns NIL if KEY is\nlarger than any keys in TREAP.\"\n (declare ((or null treap) treap)\n (function order))\n (labels ((recur (treap)\n (unless treap (return-from recur nil))\n (if (funcall order (%treap-key treap) key)\n (recur (%treap-right treap))\n (or (recur (%treap-left treap))\n treap))))\n (treap-key (recur treap))))\n\n(declaim (inline treap-bisect-right-1))\n(defun treap-bisect-right-1 (treap key &key (order #'<))\n \"Returns the largest key equal to or smaller than KEY. Returns NIL if KEY is\nsmaller than any keys in TREAP.\"\n (declare ((or null treap) treap)\n (function order))\n (labels ((recur (treap)\n (cond ((null treap) nil)\n ((funcall order key (%treap-key treap))\n (recur (%treap-left treap)))\n (t (or (recur (%treap-right treap))\n treap)))))\n (treap-key (recur treap))))\n\n;; (defun copy-treap (treap)\n;; \"For development. Recursively copies the whole TREAP.\"\n;; (declare ((or null treap) treap))\n;; (if (null treap)\n;; nil\n;; (%make-treap (%treap-key treap)\n;; (%treap-priority treap)\n;; (copy-treap (%treap-left treap))\n;; (copy-treap (%treap-right treap)))))\n\n;; Test\n;; (let ((treap1 (%make-treap 50 15))\n;; (treap2 (%make-treap 100 11)))\n;; (setf (%treap-left treap1) (%make-treap 30 5))\n;; (setf (%treap-left (%treap-left treap1)) (%make-treap 20 2))\n;; (setf (%treap-right (%treap-left treap1)) (%make-treap 40 4))\n;; (setf (%treap-right treap1) (%make-treap 70 10))\n;; (setf (%treap-right treap2) (%make-treap 200 3))\n;; (setf (%treap-left treap2) (%make-treap 99 5))\n;; ;; copy-treap\n;; (assert (equalp treap1 (copy-treap treap1)))\n;; (assert (not (eql treap1 (copy-treap treap1))))\n;; ;; split and merge\n;; (let ((treap (treap-merge (copy-treap treap1) (copy-treap treap2))))\n;; (multiple-value-bind (left right) (treap-split 80 (copy-treap treap))\n;; (assert (equalp treap (treap-merge left right)))))\n;; ;; find\n;; (assert (= 40 (treap-find 40 treap1)))\n;; (assert (null (treap-find 41 treap1)))\n;; ;; insert and delete\n;; (let ((inserted-treap1 (treap-insert 41 (copy-treap treap1))))\n;; (assert (= 41 (treap-find 41 inserted-treap1)))\n;; (let ((deleted-treap1 (treap-delete 41 inserted-treap1)))\n;; (assert (null (treap-find 41 deleted-treap1)))\n;; (assert (equalp treap1 deleted-treap1))\n;; (assert (equalp treap1 (treap-delete 41 deleted-treap1))))))\n\n;; (multiple-value-bind (left right) (treap-split 5 (treap-insert 0 (treap-insert 10 (treap-insert 5 nil))))\n;; (assert (= 0 (%treap-key left)))\n;; (assert (null (%treap-left left)))\n;; (assert (null (%treap-right left)))\n;; (assert (or (typep (%treap-left right) 'treap)\n;; (typep (%treap-right right) 'treap))))\n\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/treap :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n;; cには後半1/3をあてるべき\n(defun calc (x)\n (ash (* x (+ x 1)) -1))\n(defun main ()\n (let* ((n (read))\n (k (read))\n (ab-sum (- (calc (+ k (* 2 n) -1))\n (calc (+ k -1))))\n (c-sum (- (calc (+ k (* 3 n) -1))\n (calc (+ k (* 2 n) -1))))\n (out (make-string-output-stream :element-type 'base-char))\n res-ab)\n (dbg ab-sum c-sum)\n (labels ((no () (println -1) (return-from main)))\n (when (> ab-sum c-sum) (no))\n (if (oddp k)\n (let* ((cstart (+ k (* 2 n)))\n (astart k)\n (bstart (+ k n)))\n (loop for a from astart\n for b downfrom (- cstart 1) by 2\n do (dbg a b)\n while (and (< a bstart) (>= b bstart))\n do (push (cons a b) res-ab)\n finally (loop for a2 from a\n for b2 downfrom (- cstart 2) by 2\n while (and (< a2 bstart) (>= b2 bstart))\n do (push (cons a2 b2) res-ab)))\n (setq res-ab (sort res-ab #'< :key (lambda (cons) (+ (car cons) (cdr cons)))))\n (loop for (a . b) in res-ab\n for c from cstart\n unless (<= (+ a b) c)\n do (no)\n do (format out \"~D ~D ~D~%\" a b c)))\n (error \"Huh?\"))\n (write-string (get-output-stream-string out)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (5am:is\n (equal \"1 2 3\n\"\n (run \"1 1\n\" nil)))\n (5am:is\n (equal \"-1\n\"\n (run \"3 3\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1600774477, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02869.html", "problem_id": "p02869", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02869/input.txt", "sample_output_relpath": "derived/input_output/data/p02869/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02869/Lisp/s302337045.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s302337045", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1 2 3\n", "input_to_evaluate": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/treap\n (:use :cl)\n (:export #:treap #:treap-count #:treap-find #:treap-bisect-left #:treap-bisect-right-1\n #:treap-split #:treap-insert #:treap-push #:treap-pop #:treap-delete #:treap-merge\n #:treap-map #:invalid-treap-index-error #:treap-first #:treap-last))\n(in-package :cp/treap)\n\n;; Not included in test script. Better to use ref-able-treap instead.\n\n(defstruct (treap (:constructor %make-treap (key priority &optional left right))\n (:copier nil)\n (:predicate nil)\n (:conc-name %treap-))\n key\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (left nil :type (or null treap))\n (right nil :type (or null treap)))\n\n(declaim (inline treap-key))\n(defun treap-key (treap)\n (and treap (%treap-key treap)))\n\n(declaim (inline treap-find))\n(defun treap-find (key treap &key (order #'<))\n \"Searches the sub-treap of TREAP whose key satisfies (and (not (funcall order\nkey (%treap-key sub-treap))) (not (funcall order (%treap-key sub-treap) key))) and\nreturns KEY. Returns NIL if KEY is not contained.\"\n (declare (function order)\n ((or null treap) treap))\n (labels ((recur (treap)\n (cond ((null treap) nil)\n ((funcall order key (%treap-key treap))\n (recur (%treap-left treap)))\n ((funcall order (%treap-key treap) key)\n (recur (%treap-right treap)))\n (t key))))\n (recur treap)))\n\n(declaim (inline treap-split))\n(defun treap-split (key treap &key (order #'<))\n \"Destructively splits the TREAP with reference to KEY and returns two treaps,\nthe smaller sub-treap (< KEY) and the larger one (>= KEY).\"\n (declare (function order)\n ((or null treap) treap))\n (labels ((recur (treap)\n (cond ((null treap)\n (values nil nil))\n ((funcall order (%treap-key treap) key)\n (multiple-value-bind (left right)\n (recur (%treap-right treap))\n (setf (%treap-right treap) left)\n (values treap right)))\n (t\n (multiple-value-bind (left right)\n (recur (%treap-left treap))\n (setf (%treap-left treap) right)\n (values left treap))))))\n (recur treap)))\n\n(declaim (inline treap-insert))\n(defun treap-insert (key treap &key (order #'<))\n \"Destructively inserts KEY into TREAP and returns the resultant treap. You\ncannot rely on the side effect. Use the returned value.\n\nThe behavior is undefined when duplicate keys are inserted.\"\n (declare ((or null treap) treap)\n (function order))\n (labels ((recur (new-node treap)\n (declare (treap new-node))\n (cond ((null treap) new-node)\n ((> (%treap-priority new-node) (%treap-priority treap))\n (setf (values (%treap-left new-node) (%treap-right new-node))\n (treap-split (%treap-key new-node) treap :order order))\n new-node)\n (t\n (if (funcall order (%treap-key new-node) (%treap-key treap))\n (setf (%treap-left treap)\n (recur new-node (%treap-left treap)))\n (setf (%treap-right treap)\n (recur new-node (%treap-right treap))))\n treap))))\n (recur (%make-treap key (random most-positive-fixnum)) treap)))\n\n(defun treap-map (function treap)\n \"Successively applies FUNCTION to each key of TREAP in the given\norder. FUNCTION must take one argument.\"\n (declare (function function))\n (when treap\n (treap-map function (%treap-left treap))\n (funcall function (%treap-key treap))\n (treap-map function (%treap-right treap))))\n\n(defmethod print-object ((object treap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (treap-map (lambda (key)\n (if init\n (setf init nil)\n (write-char #\\ stream))\n (write key :stream stream))\n object))))\n\n(declaim (ftype (function * (values (or null treap) &optional)) treap-merge))\n(defun treap-merge (left right)\n \"Destructively concatenates two treaps. Assumes that all keys of LEFT are\nsmaller (or larger, depending on the order) than those of RIGHT.\"\n (declare (optimize (speed 3))\n ((or null treap) left right))\n (cond ((null left) right)\n ((null right) left)\n ((> (%treap-priority left) (%treap-priority right))\n (setf (%treap-right left)\n (treap-merge (%treap-right left) right))\n left)\n (t\n (setf (%treap-left right)\n (treap-merge left (%treap-left right)))\n right)))\n\n(declaim (inline treap-delete))\n(defun treap-delete (key treap &key (order #'<))\n \"Destructively deletes the KEY in TREAP and returns the resultant treap. You\ncannot rely on the side effect. Use the returned value.\"\n (declare ((or null treap) treap)\n (function order))\n (labels ((recur (treap)\n (cond ((null treap) nil)\n ((funcall order key (%treap-key treap))\n (setf (%treap-left treap) (recur (%treap-left treap)))\n treap)\n ((funcall order (%treap-key treap) key)\n (setf (%treap-right treap) (recur (%treap-right treap)))\n treap)\n (t\n (treap-merge (%treap-left treap) (%treap-right treap))))))\n (recur treap)))\n\n(defmacro treap-push (key treap order)\n \"Pushes KEY to TREAP.\"\n `(setf ,treap (treap-insert ,key ,treap :order ,order)))\n\n(defmacro treap-pop (key treap order)\n \"Deletes KEY from TREAP.\"\n `(setf ,treap (treap-delete ,key ,treap :order ,order)))\n\n(defun treap-first (treap)\n (declare (optimize (speed 3))\n (treap treap))\n (if (%treap-left treap)\n (treap-first (%treap-left treap))\n (%treap-key treap)))\n\n(defun treap-last (treap)\n (declare (optimize (speed 3))\n (treap treap))\n (if (%treap-right treap)\n (treap-last (%treap-right treap))\n (%treap-key treap)))\n\n(declaim (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) treap-count))\n(defun treap-count (treap)\n \"Counts the number of elements in TREAP in O(n) time.\"\n (declare (optimize (speed 3))\n ((or null treap) treap))\n (labels ((recur (treap)\n (declare (optimize (safety 0)))\n (if (null treap)\n 0\n (+ 1\n (treap-count (%treap-left treap))\n (treap-count (%treap-right treap))))))\n (recur treap)))\n\n(declaim (inline treap-bisect-left))\n(defun treap-bisect-left (treap key &key (order #'<))\n \"Returns the smallest key equal to or larger than KEY. Returns NIL if KEY is\nlarger than any keys in TREAP.\"\n (declare ((or null treap) treap)\n (function order))\n (labels ((recur (treap)\n (unless treap (return-from recur nil))\n (if (funcall order (%treap-key treap) key)\n (recur (%treap-right treap))\n (or (recur (%treap-left treap))\n treap))))\n (treap-key (recur treap))))\n\n(declaim (inline treap-bisect-right-1))\n(defun treap-bisect-right-1 (treap key &key (order #'<))\n \"Returns the largest key equal to or smaller than KEY. Returns NIL if KEY is\nsmaller than any keys in TREAP.\"\n (declare ((or null treap) treap)\n (function order))\n (labels ((recur (treap)\n (cond ((null treap) nil)\n ((funcall order key (%treap-key treap))\n (recur (%treap-left treap)))\n (t (or (recur (%treap-right treap))\n treap)))))\n (treap-key (recur treap))))\n\n;; (defun copy-treap (treap)\n;; \"For development. Recursively copies the whole TREAP.\"\n;; (declare ((or null treap) treap))\n;; (if (null treap)\n;; nil\n;; (%make-treap (%treap-key treap)\n;; (%treap-priority treap)\n;; (copy-treap (%treap-left treap))\n;; (copy-treap (%treap-right treap)))))\n\n;; Test\n;; (let ((treap1 (%make-treap 50 15))\n;; (treap2 (%make-treap 100 11)))\n;; (setf (%treap-left treap1) (%make-treap 30 5))\n;; (setf (%treap-left (%treap-left treap1)) (%make-treap 20 2))\n;; (setf (%treap-right (%treap-left treap1)) (%make-treap 40 4))\n;; (setf (%treap-right treap1) (%make-treap 70 10))\n;; (setf (%treap-right treap2) (%make-treap 200 3))\n;; (setf (%treap-left treap2) (%make-treap 99 5))\n;; ;; copy-treap\n;; (assert (equalp treap1 (copy-treap treap1)))\n;; (assert (not (eql treap1 (copy-treap treap1))))\n;; ;; split and merge\n;; (let ((treap (treap-merge (copy-treap treap1) (copy-treap treap2))))\n;; (multiple-value-bind (left right) (treap-split 80 (copy-treap treap))\n;; (assert (equalp treap (treap-merge left right)))))\n;; ;; find\n;; (assert (= 40 (treap-find 40 treap1)))\n;; (assert (null (treap-find 41 treap1)))\n;; ;; insert and delete\n;; (let ((inserted-treap1 (treap-insert 41 (copy-treap treap1))))\n;; (assert (= 41 (treap-find 41 inserted-treap1)))\n;; (let ((deleted-treap1 (treap-delete 41 inserted-treap1)))\n;; (assert (null (treap-find 41 deleted-treap1)))\n;; (assert (equalp treap1 deleted-treap1))\n;; (assert (equalp treap1 (treap-delete 41 deleted-treap1))))))\n\n;; (multiple-value-bind (left right) (treap-split 5 (treap-insert 0 (treap-insert 10 (treap-insert 5 nil))))\n;; (assert (= 0 (%treap-key left)))\n;; (assert (null (%treap-left left)))\n;; (assert (null (%treap-right left)))\n;; (assert (or (typep (%treap-left right) 'treap)\n;; (typep (%treap-right right) 'treap))))\n\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/treap :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n;; cには後半1/3をあてるべき\n(defun calc (x)\n (ash (* x (+ x 1)) -1))\n(defun main ()\n (let* ((n (read))\n (k (read))\n (ab-sum (- (calc (+ k (* 2 n) -1))\n (calc (+ k -1))))\n (c-sum (- (calc (+ k (* 3 n) -1))\n (calc (+ k (* 2 n) -1))))\n (out (make-string-output-stream :element-type 'base-char))\n res-ab)\n (dbg ab-sum c-sum)\n (labels ((no () (println -1) (return-from main)))\n (when (> ab-sum c-sum) (no))\n (if (oddp k)\n (let* ((cstart (+ k (* 2 n)))\n (astart k)\n (bstart (+ k n)))\n (loop for a from astart\n for b downfrom (- cstart 1) by 2\n do (dbg a b)\n while (and (< a bstart) (>= b bstart))\n do (push (cons a b) res-ab)\n finally (loop for a2 from a\n for b2 downfrom (- cstart 2) by 2\n while (and (< a2 bstart) (>= b2 bstart))\n do (push (cons a2 b2) res-ab)))\n (setq res-ab (sort res-ab #'< :key (lambda (cons) (+ (car cons) (cdr cons)))))\n (loop for (a . b) in res-ab\n for c from cstart\n unless (<= (+ a b) c)\n do (no)\n do (format out \"~D ~D ~D~%\" a b c)))\n (error \"Huh?\"))\n (write-string (get-output-stream-string out)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (5am:is\n (equal \"1 2 3\n\"\n (run \"1 1\n\" nil)))\n (5am:is\n (equal \"-1\n\"\n (run \"3 3\n\" nil))))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nGiven are positive integers N and K.\n\nDetermine if the 3N integers K, K+1, ..., K+3N-1 can be partitioned into N triples (a_1,b_1,c_1), ..., (a_N,b_N,c_N) so that the condition below is satisfied. Any of the integers K, K+1, ..., K+3N-1 must appear in exactly one of those triples.\n\nFor every integer i from 1 to N, a_i + b_i \\leq c_i holds.\n\nIf the answer is yes, construct one such partition.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq K \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nIf it is impossible to partition the integers satisfying the condition, print -1. If it is possible, print N triples in the following format:\n\na_1 b_1 c_1\n:\na_N b_N c_N\n\nSample Input 1\n\n1 1\n\nSample Output 1\n\n1 2 3\n\nSample Input 2\n\n3 3\n\nSample Output 2\n\n-1", "sample_input": "1 1\n"}, "reference_outputs": ["1 2 3\n"], "source_document_id": "p02869", "source_text": "Score : 700 points\n\nProblem Statement\n\nGiven are positive integers N and K.\n\nDetermine if the 3N integers K, K+1, ..., K+3N-1 can be partitioned into N triples (a_1,b_1,c_1), ..., (a_N,b_N,c_N) so that the condition below is satisfied. Any of the integers K, K+1, ..., K+3N-1 must appear in exactly one of those triples.\n\nFor every integer i from 1 to N, a_i + b_i \\leq c_i holds.\n\nIf the answer is yes, construct one such partition.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq K \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nIf it is impossible to partition the integers satisfying the condition, print -1. If it is possible, print N triples in the following format:\n\na_1 b_1 c_1\n:\na_N b_N c_N\n\nSample Input 1\n\n1 1\n\nSample Output 1\n\n1 2 3\n\nSample Input 2\n\n3 3\n\nSample Output 2\n\n-1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 14767, "cpu_time_ms": 97, "memory_kb": 33200}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s665923988", "group_id": "codeNet:p02873", "input_text": "(let* ((s (read-line))\n (x (make-array (list (length s)) :adjustable t :fill-pointer 0))\n (ans 0))\n (loop :with c := #\\=\n :with p := -1\n :for y :across s\n :if (char/= c y)\n :do (progn\n (vector-push-extend 0 x)\n (incf p)\n (setf c y))\n :do (if (char= y #\\<)\n (incf (aref x p))\n (decf (aref x p))))\n (loop :for v :across x\n :for w := (abs v)\n :for i :from 0\n :do (incf ans (/ (* w (- w 1)) 2))\n :if (> v 0)\n :do (incf ans (if (= (1+ i) (length x)) w (max w (abs (aref x (1+ i)))))))\n (when (< (aref x 0) 0)\n (incf ans (abs (aref x 0))))\n (format t \"~A~%\" ans))\n", "language": "Lisp", "metadata": {"date": 1595467626, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02873.html", "problem_id": "p02873", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02873/input.txt", "sample_output_relpath": "derived/input_output/data/p02873/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02873/Lisp/s665923988.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s665923988", "user_id": "u608227593"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let* ((s (read-line))\n (x (make-array (list (length s)) :adjustable t :fill-pointer 0))\n (ans 0))\n (loop :with c := #\\=\n :with p := -1\n :for y :across s\n :if (char/= c y)\n :do (progn\n (vector-push-extend 0 x)\n (incf p)\n (setf c y))\n :do (if (char= y #\\<)\n (incf (aref x p))\n (decf (aref x p))))\n (loop :for v :across x\n :for w := (abs v)\n :for i :from 0\n :do (incf ans (/ (* w (- w 1)) 2))\n :if (> v 0)\n :do (incf ans (if (= (1+ i) (length x)) w (max w (abs (aref x (1+ i)))))))\n (when (< (aref x 0) 0)\n (incf ans (abs (aref x 0))))\n (format t \"~A~%\" ans))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven is a string S of length N-1.\nEach character in S is < or >.\n\nA sequence of N non-negative integers, a_1,a_2,\\cdots,a_N, is said to be good when the following condition is satisfied for all i (1 \\leq i \\leq N-1):\n\nIf S_i= <: a_i: a_i>a_{i+1}\n\nFind the minimum possible sum of the elements of a good sequence of N non-negative integers.\n\nConstraints\n\n2 \\leq N \\leq 5 \\times 10^5\n\nS is a string of length N-1 consisting of < and >.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nFind the minimum possible sum of the elements of a good sequence of N non-negative integers.\n\nSample Input 1\n\n<>>\n\nSample Output 1\n\n3\n\na=(0,2,1,0) is a good sequence whose sum is 3.\nThere is no good sequence whose sum is less than 3.\n\nSample Input 2\n\n<>>><<><<<<<>>><\n\nSample Output 2\n\n28", "sample_input": "<>>\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02873", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven is a string S of length N-1.\nEach character in S is < or >.\n\nA sequence of N non-negative integers, a_1,a_2,\\cdots,a_N, is said to be good when the following condition is satisfied for all i (1 \\leq i \\leq N-1):\n\nIf S_i= <: a_i: a_i>a_{i+1}\n\nFind the minimum possible sum of the elements of a good sequence of N non-negative integers.\n\nConstraints\n\n2 \\leq N \\leq 5 \\times 10^5\n\nS is a string of length N-1 consisting of < and >.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nFind the minimum possible sum of the elements of a good sequence of N non-negative integers.\n\nSample Input 1\n\n<>>\n\nSample Output 1\n\n3\n\na=(0,2,1,0) is a good sequence whose sum is 3.\nThere is no good sequence whose sum is less than 3.\n\nSample Input 2\n\n<>>><<><<<<<>>><\n\nSample Output 2\n\n28", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 716, "cpu_time_ms": 62, "memory_kb": 31700}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s191726818", "group_id": "codeNet:p02873", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defun map-run-length (function seq &key (test #'eql))\n \"Applies FUNCTION to each equal successive element of SEQ. FUNCTION must take\ntwo arguments: the first one receives an element in SEQ and the second one\nreceives the number of the successive elements equal to the first.\n\nExample: (map-run-length (lambda (x c) (format t \\\"~D ~D~%\\\" x c)) #(1 1 1 2 2 1 3))\n1 3\n2 2\n1 1\n3 1\n\"\n (declare (sequence seq)\n (function test function))\n (etypecase seq\n (vector\n (unless (zerop (length seq))\n (let ((prev (aref seq 0))\n (start 0))\n (loop for pos from 1 below (length seq)\n unless (funcall test prev (aref seq pos))\n do (funcall function prev (- pos start))\n (setf prev (aref seq pos)\n start pos)\n finally (funcall function prev (- pos start))))))\n (list\n (when (cdr seq)\n (labels ((recur (lst prev count)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null lst)\n (funcall function prev count))\n ((funcall test prev (car lst))\n (recur (cdr lst) prev (+ 1 count)))\n (t (funcall function prev count)\n (recur (cdr lst) (car lst) 1)))))\n (recur (cdr seq) (car seq) 1))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((s (read-line))\n (n (length s))\n (dp (make-array (+ 1 n) :element-type 'uint32 :initial-element 0))\n (pos 0))\n (map-run-length\n (lambda (c num)\n (if (char= c #\\<)\n (loop for x from 0\n for i from pos to (+ pos num)\n do (setf (aref dp i) x))\n (loop for x from 0\n for i from (+ pos num) downto pos\n do (setf (aref dp i)\n (max x (aref dp i)))))\n (incf pos num))\n s)\n #>dp\n (println (reduce #'+ dp))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"<>>\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"<>>><<><<<<<>>><\n\"\n \"28\n\")))\n", "language": "Lisp", "metadata": {"date": 1572844240, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02873.html", "problem_id": "p02873", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02873/input.txt", "sample_output_relpath": "derived/input_output/data/p02873/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02873/Lisp/s191726818.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s191726818", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defun map-run-length (function seq &key (test #'eql))\n \"Applies FUNCTION to each equal successive element of SEQ. FUNCTION must take\ntwo arguments: the first one receives an element in SEQ and the second one\nreceives the number of the successive elements equal to the first.\n\nExample: (map-run-length (lambda (x c) (format t \\\"~D ~D~%\\\" x c)) #(1 1 1 2 2 1 3))\n1 3\n2 2\n1 1\n3 1\n\"\n (declare (sequence seq)\n (function test function))\n (etypecase seq\n (vector\n (unless (zerop (length seq))\n (let ((prev (aref seq 0))\n (start 0))\n (loop for pos from 1 below (length seq)\n unless (funcall test prev (aref seq pos))\n do (funcall function prev (- pos start))\n (setf prev (aref seq pos)\n start pos)\n finally (funcall function prev (- pos start))))))\n (list\n (when (cdr seq)\n (labels ((recur (lst prev count)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null lst)\n (funcall function prev count))\n ((funcall test prev (car lst))\n (recur (cdr lst) prev (+ 1 count)))\n (t (funcall function prev count)\n (recur (cdr lst) (car lst) 1)))))\n (recur (cdr seq) (car seq) 1))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((s (read-line))\n (n (length s))\n (dp (make-array (+ 1 n) :element-type 'uint32 :initial-element 0))\n (pos 0))\n (map-run-length\n (lambda (c num)\n (if (char= c #\\<)\n (loop for x from 0\n for i from pos to (+ pos num)\n do (setf (aref dp i) x))\n (loop for x from 0\n for i from (+ pos num) downto pos\n do (setf (aref dp i)\n (max x (aref dp i)))))\n (incf pos num))\n s)\n #>dp\n (println (reduce #'+ dp))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"<>>\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"<>>><<><<<<<>>><\n\"\n \"28\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven is a string S of length N-1.\nEach character in S is < or >.\n\nA sequence of N non-negative integers, a_1,a_2,\\cdots,a_N, is said to be good when the following condition is satisfied for all i (1 \\leq i \\leq N-1):\n\nIf S_i= <: a_i: a_i>a_{i+1}\n\nFind the minimum possible sum of the elements of a good sequence of N non-negative integers.\n\nConstraints\n\n2 \\leq N \\leq 5 \\times 10^5\n\nS is a string of length N-1 consisting of < and >.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nFind the minimum possible sum of the elements of a good sequence of N non-negative integers.\n\nSample Input 1\n\n<>>\n\nSample Output 1\n\n3\n\na=(0,2,1,0) is a good sequence whose sum is 3.\nThere is no good sequence whose sum is less than 3.\n\nSample Input 2\n\n<>>><<><<<<<>>><\n\nSample Output 2\n\n28", "sample_input": "<>>\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02873", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven is a string S of length N-1.\nEach character in S is < or >.\n\nA sequence of N non-negative integers, a_1,a_2,\\cdots,a_N, is said to be good when the following condition is satisfied for all i (1 \\leq i \\leq N-1):\n\nIf S_i= <: a_i: a_i>a_{i+1}\n\nFind the minimum possible sum of the elements of a good sequence of N non-negative integers.\n\nConstraints\n\n2 \\leq N \\leq 5 \\times 10^5\n\nS is a string of length N-1 consisting of < and >.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nFind the minimum possible sum of the elements of a good sequence of N non-negative integers.\n\nSample Input 1\n\n<>>\n\nSample Output 1\n\n3\n\na=(0,2,1,0) is a good sequence whose sum is 3.\nThere is no good sequence whose sum is less than 3.\n\nSample Input 2\n\n<>>><<><<<<<>>><\n\nSample Output 2\n\n28", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5416, "cpu_time_ms": 220, "memory_kb": 22500}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s964664877", "group_id": "codeNet:p02874", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defun delete-adjacent-duplicates (seq &key (test #'eql))\n \"Destructively deletes adjacent duplicates of SEQ: e.g. #(1 1 1 2 2 1 3) ->\n#(1 2 1 3)\"\n (declare #.OPT\n ((simple-array uint31 (*)) seq)\n (function test))\n (if (zerop (length seq))\n seq\n (let ((prev (aref seq 0))\n (end 1))\n (loop for pos from 1 below (length seq)\n unless (funcall test prev (aref seq pos))\n do (setf prev (aref seq pos)\n (aref seq end) (aref seq pos)\n end (+ 1 end)))\n ;; KLUDGE: Resorting to ADJUST-ARRAY is maybe substandard. \n (adjust-array seq end))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Treap with explicit key\n;;; Virtually it works like std::map, std::multiset, or java.util.TreeMap.\n;;;\n\n\n;; Tips to use this structure as a multiset: Just define OP as (defun op (x y)\n;; (+ x y)) and insert each element by (treap-ensure-key 1\n;; :if-exists #'1+) instead of TREAP-INSERT.\n\n(declaim (inline op))\n(defun op (x y)\n \"Is the operator comprising a monoid\"\n (declare (uint32 x y))\n (max x y))\n\n(defconstant +op-identity+ 0\n \"identity element w.r.t. OP\")\n\n(declaim (inline updater-op))\n(defun updater-op (a b)\n \"Is the operator to compute and update LAZY value.\"\n (declare (int32 a b))\n (+ a b))\n\n(defconstant +updater-identity+ 0\n \"identity element w.r.t. UPDATER-OP\")\n\n(declaim (inline modifier-op))\n(defun modifier-op (a b)\n \"Is the operator to update ACCUMULATOR based on LAZY value.\"\n (declare (int32 a b))\n (+ a b))\n\n;; Treap with explicit key\n(defstruct (treap (:constructor %make-treap (key value &key left right (accumulator value) lazy))\n (:copier nil)\n (:conc-name %treap-))\n (key 0 :type fixnum)\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum)\n (lazy +updater-identity+ :type fixnum)\n (left nil :type (or null treap))\n (right nil :type (or null treap)))\n\n(declaim (inline treap-accumulator))\n(defun treap-accumulator (treap)\n (declare ((or null treap) treap))\n (if (null treap)\n +op-identity+\n (%treap-accumulator treap)))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (treap)\n (declare (treap treap))\n (setf (%treap-accumulator treap)\n (if (%treap-left treap)\n (if (%treap-right treap)\n (let ((mid-res (op (%treap-accumulator (%treap-left treap))\n (%treap-value treap))))\n (declare (dynamic-extent mid-res))\n (op mid-res (%treap-accumulator (%treap-right treap))))\n (op (%treap-accumulator (%treap-left treap))\n (%treap-value treap)))\n (if (%treap-right treap)\n (op (%treap-value treap)\n (%treap-accumulator (%treap-right treap)))\n (%treap-value treap)))))\n\n(declaim (inline force-up))\n(defun force-up (treap)\n \"Propagates up the information from children.\"\n (declare (treap treap))\n (update-accumulator treap))\n\n(declaim (inline force-down))\n(defun force-down (treap)\n \"Propagates down the information to children.\"\n (declare (treap treap))\n (unless (eql +updater-identity+ (%treap-lazy treap))\n (when (%treap-left treap)\n (setf (%treap-lazy (%treap-left treap))\n (updater-op (%treap-lazy (%treap-left treap))\n (%treap-lazy treap)))\n (setf (%treap-accumulator (%treap-left treap))\n (modifier-op (%treap-accumulator (%treap-left treap))\n (%treap-lazy treap))))\n (when (%treap-right treap)\n (setf (%treap-lazy (%treap-right treap))\n (updater-op (%treap-lazy (%treap-right treap))\n (%treap-lazy treap)))\n (setf (%treap-accumulator (%treap-right treap))\n (modifier-op (%treap-accumulator (%treap-right treap))\n (%treap-lazy treap))))\n (setf (%treap-value treap)\n (modifier-op (%treap-value treap)\n (%treap-lazy treap)))\n (setf (%treap-lazy treap) +updater-identity+)))\n\n(defun treap-bisect-left (treap key)\n \"Returns the smallest key equal to or larger than KEY and the assigned\nvalue. Returns NIL if KEY is larger than any keys in TREAP.\"\n (declare #.OPT\n ((or null treap) treap))\n (labels ((recur (treap)\n (unless treap (return-from recur nil))\n (force-down treap)\n (if (< (%treap-key treap) key)\n (recur (%treap-right treap))\n (or (recur (%treap-left treap))\n treap))))\n (let ((result (recur treap)))\n (if result\n (values (%treap-key result) (%treap-value result))\n (values nil nil)))))\n\n(declaim (ftype (function * (values (or null treap) (or null treap) &optional)) treap-split))\n(defun treap-split (treap key)\n \"Destructively splits the TREAP with reference to KEY and returns two treaps,\nthe smaller sub-treap (< KEY) and the larger one (>= KEY).\"\n (declare #.OPT\n ((or null treap) treap)\n (uint32 key))\n (if (null treap)\n (values nil nil)\n (progn\n (force-down treap)\n (if (< (%treap-key treap) key)\n (multiple-value-bind (left right)\n (treap-split (%treap-right treap) key)\n (setf (%treap-right treap) left)\n (force-up treap)\n (values treap right))\n (multiple-value-bind (left right)\n (treap-split (%treap-left treap) key)\n (setf (%treap-left treap) right)\n (force-up treap)\n (values left treap))))))\n\n;; Reference: https://cp-algorithms.com/data_structures/treap.html\n;; TODO: take a sorted list as the argument\n(defun make-treap (sorted-vector)\n \"Makes a treap using each key of the given SORTED-VECTOR in O(n). Note that\nthis function doesn't check if the SORTED-VECTOR is actually sorted w.r.t. your\nintended order. The values are filled with the identity element.\"\n (declare #.OPT\n ((simple-array uint31 (*)) sorted-vector))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-treap (aref sorted-vector mid)\n +op-identity+)))\n (setf (%treap-left node) (build l mid))\n (setf (%treap-right node) (build (+ mid 1) r))\n node))))\n (build 0 (length sorted-vector))))\n\n(defconstant +pos-inf+ most-positive-fixnum)\n(defconstant +neg-inf+ most-negative-fixnum)\n\n(defun treap-query (treap &key left right)\n \"Queries the sum of the half-open interval specified by the keys: [LEFT,\nRIGHT). If LEFT [RIGHT] is not given, it is assumed to be -inf [+inf].\"\n (declare #.OPT)\n (setq left (or left +neg-inf+)\n right (or right +pos-inf+))\n (labels ((recur (treap l r)\n (declare (fixnum l r))\n (unless treap\n (return-from recur +op-identity+))\n (force-down treap)\n (prog1\n (if (and (= l +neg-inf+) (= r +pos-inf+))\n (%treap-accumulator treap)\n (let ((key (%treap-key treap)))\n (if (<= l key)\n (if (< key r)\n (funcall #'op\n (funcall #'op\n (recur (%treap-left treap) l +pos-inf+)\n (%treap-value treap))\n (recur (%treap-right treap) +neg-inf+ r))\n (recur (%treap-left treap) l r))\n (recur (%treap-right treap) l r))))\n (force-up treap))))\n (recur treap left right)))\n\n(defun treap-update (treap x left right)\n \"Updates TREAP[KEY] := (OP TREAP[KEY] X) for all KEY in [l, r)\"\n (declare #.OPT\n (fixnum left right))\n (assert (not (< right left)))\n (labels ((recur (treap l r)\n (declare (fixnum l r))\n (when treap\n (if (and (= l +neg-inf+) (= r +pos-inf+))\n (progn\n (setf (%treap-lazy treap)\n (updater-op (%treap-lazy treap) x))\n (force-down treap))\n (let ((key (%treap-key treap)))\n (force-down treap)\n (if (<= l key)\n (if (< key r)\n (progn\n (recur (%treap-left treap) l +pos-inf+)\n (setf (%treap-value treap)\n (modifier-op (%treap-value treap) x))\n (recur (%treap-right treap) +neg-inf+ r))\n (recur (%treap-left treap) l r))\n (recur (%treap-right treap) l r))))\n (force-up treap))))\n (recur treap left right)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun solve (n ls rs lrs seq)\n (declare #.OPT\n (uint31 n)\n ((simple-array uint31 (*)) ls rs seq)\n ((simple-array (cons uint31 uint31) (*)) lrs))\n (let ((inf (reduce #'max seq))\n (treap1 (make-treap seq))\n (treap2 (make-treap seq))\n (res 0))\n (dotimes (i n)\n (let ((l (aref ls i))\n (r (aref rs i)))\n (dbg l r)\n (treap-update treap2 1 l r)))\n (dotimes (i n)\n (let* ((lr (aref lrs i))\n (required1 i)\n (required2 (- n i))\n (l (car lr))\n (r (cdr lr))\n (max1 (treap-query treap1))\n (max2 (treap-query treap2)))\n (when (and (= required1 max1) (= required2 max2))\n (let* ((max1l (sb-int:named-let bisect ((ng 0) (ok inf))\n (declare (uint32 ng ok))\n (if (<= (- ok ng) 1)\n (- ok 1)\n (let ((mid (ash (+ ng ok) -1)))\n (if (= (treap-query treap1 :right mid) max1)\n (bisect ng mid)\n (bisect mid ok))))))\n (max1r (sb-int:named-let bisect ((ng max1l) (ok inf))\n (declare (uint32 ng ok))\n (if (<= (- ok ng) 1)\n (treap-bisect-left treap1 ok)\n (let ((mid (ash (+ ng ok) -1)))\n (if (< (treap-query treap1 :left mid) max1)\n (bisect ng mid)\n (bisect mid ok))))))\n (max2l (sb-int:named-let bisect ((ng 0) (ok inf))\n (declare (uint32 ng ok))\n (if (<= (- ok ng) 1)\n (- ok 1)\n (let ((mid (ash (+ ng ok) -1)))\n (if (= (treap-query treap2 :right mid) max2)\n (bisect ng mid)\n (bisect mid ok))))))\n (max2r (sb-int:named-let bisect ((ng max2l) (ok inf))\n (declare (uint32 ng ok))\n (if (<= (- ok ng) 1)\n (treap-bisect-left treap2 ok)\n (let ((mid (ash (+ ng ok) -1)))\n (if (< (treap-query treap2 :left mid) max2)\n (bisect ng mid)\n (bisect mid ok))))))\n (new-score (+ (- max1r max1l) (- max2r max2l))))\n (unless (zerop i)\n (setq res (max res new-score)))))\n (treap-update treap1 1 l r)\n (treap-update treap2 -1 l r)))\n res))\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (ls (make-array n :element-type 'uint31))\n (rs (make-array n :element-type 'uint31))\n (lrs (make-array n :element-type '(cons uint31 uint31)))\n (seq (make-array (+ n n) :element-type 'uint31)))\n (dotimes (i n)\n (let ((l (- (read-fixnum) 1))\n (r (read-fixnum)))\n (setf (aref ls i) l\n (aref rs i) r\n (aref lrs i) (cons l r)\n (aref seq i) l\n (aref seq (+ i n)) r)))\n (setq seq (sort seq #'<)\n lrs (sort lrs (lambda (x y) (< (the uint32 x) (the uint32 y))) :key #'cdr))\n (setq seq (delete-adjacent-duplicates seq))\n (let ((cand (solve n ls rs lrs seq)))\n (let ((idx 0)\n (l 0)\n (r 1000000000))\n (dotimes (i n)\n (when (>= (- (aref rs i) (aref ls i))\n (- (aref rs idx) (aref ls idx)))\n (setq idx i)))\n (dotimes (i n)\n (unless (= idx i)\n (setq l (max l (aref ls i))\n r (min r (aref rs i)))))\n (let ((cand2 (+ (- (aref rs idx) (aref ls idx))\n (max 0 (- r l)))))\n (println (max cand cand2)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n4 7\n1 4\n5 8\n2 5\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 20\n2 19\n3 18\n4 17\n\"\n \"34\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n457835016 996058008\n456475528 529149798\n455108441 512701454\n455817105 523506955\n457368248 814532746\n455073228 459494089\n456651538 774276744\n457667152 974637457\n457293701 800549465\n456580262 636471526\n\"\n \"540049931\n\")))\n", "language": "Lisp", "metadata": {"date": 1572854406, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02874.html", "problem_id": "p02874", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02874/input.txt", "sample_output_relpath": "derived/input_output/data/p02874/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02874/Lisp/s964664877.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s964664877", "user_id": "u352600849"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defun delete-adjacent-duplicates (seq &key (test #'eql))\n \"Destructively deletes adjacent duplicates of SEQ: e.g. #(1 1 1 2 2 1 3) ->\n#(1 2 1 3)\"\n (declare #.OPT\n ((simple-array uint31 (*)) seq)\n (function test))\n (if (zerop (length seq))\n seq\n (let ((prev (aref seq 0))\n (end 1))\n (loop for pos from 1 below (length seq)\n unless (funcall test prev (aref seq pos))\n do (setf prev (aref seq pos)\n (aref seq end) (aref seq pos)\n end (+ 1 end)))\n ;; KLUDGE: Resorting to ADJUST-ARRAY is maybe substandard. \n (adjust-array seq end))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Treap with explicit key\n;;; Virtually it works like std::map, std::multiset, or java.util.TreeMap.\n;;;\n\n\n;; Tips to use this structure as a multiset: Just define OP as (defun op (x y)\n;; (+ x y)) and insert each element by (treap-ensure-key 1\n;; :if-exists #'1+) instead of TREAP-INSERT.\n\n(declaim (inline op))\n(defun op (x y)\n \"Is the operator comprising a monoid\"\n (declare (uint32 x y))\n (max x y))\n\n(defconstant +op-identity+ 0\n \"identity element w.r.t. OP\")\n\n(declaim (inline updater-op))\n(defun updater-op (a b)\n \"Is the operator to compute and update LAZY value.\"\n (declare (int32 a b))\n (+ a b))\n\n(defconstant +updater-identity+ 0\n \"identity element w.r.t. UPDATER-OP\")\n\n(declaim (inline modifier-op))\n(defun modifier-op (a b)\n \"Is the operator to update ACCUMULATOR based on LAZY value.\"\n (declare (int32 a b))\n (+ a b))\n\n;; Treap with explicit key\n(defstruct (treap (:constructor %make-treap (key value &key left right (accumulator value) lazy))\n (:copier nil)\n (:conc-name %treap-))\n (key 0 :type fixnum)\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum)\n (lazy +updater-identity+ :type fixnum)\n (left nil :type (or null treap))\n (right nil :type (or null treap)))\n\n(declaim (inline treap-accumulator))\n(defun treap-accumulator (treap)\n (declare ((or null treap) treap))\n (if (null treap)\n +op-identity+\n (%treap-accumulator treap)))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (treap)\n (declare (treap treap))\n (setf (%treap-accumulator treap)\n (if (%treap-left treap)\n (if (%treap-right treap)\n (let ((mid-res (op (%treap-accumulator (%treap-left treap))\n (%treap-value treap))))\n (declare (dynamic-extent mid-res))\n (op mid-res (%treap-accumulator (%treap-right treap))))\n (op (%treap-accumulator (%treap-left treap))\n (%treap-value treap)))\n (if (%treap-right treap)\n (op (%treap-value treap)\n (%treap-accumulator (%treap-right treap)))\n (%treap-value treap)))))\n\n(declaim (inline force-up))\n(defun force-up (treap)\n \"Propagates up the information from children.\"\n (declare (treap treap))\n (update-accumulator treap))\n\n(declaim (inline force-down))\n(defun force-down (treap)\n \"Propagates down the information to children.\"\n (declare (treap treap))\n (unless (eql +updater-identity+ (%treap-lazy treap))\n (when (%treap-left treap)\n (setf (%treap-lazy (%treap-left treap))\n (updater-op (%treap-lazy (%treap-left treap))\n (%treap-lazy treap)))\n (setf (%treap-accumulator (%treap-left treap))\n (modifier-op (%treap-accumulator (%treap-left treap))\n (%treap-lazy treap))))\n (when (%treap-right treap)\n (setf (%treap-lazy (%treap-right treap))\n (updater-op (%treap-lazy (%treap-right treap))\n (%treap-lazy treap)))\n (setf (%treap-accumulator (%treap-right treap))\n (modifier-op (%treap-accumulator (%treap-right treap))\n (%treap-lazy treap))))\n (setf (%treap-value treap)\n (modifier-op (%treap-value treap)\n (%treap-lazy treap)))\n (setf (%treap-lazy treap) +updater-identity+)))\n\n(defun treap-bisect-left (treap key)\n \"Returns the smallest key equal to or larger than KEY and the assigned\nvalue. Returns NIL if KEY is larger than any keys in TREAP.\"\n (declare #.OPT\n ((or null treap) treap))\n (labels ((recur (treap)\n (unless treap (return-from recur nil))\n (force-down treap)\n (if (< (%treap-key treap) key)\n (recur (%treap-right treap))\n (or (recur (%treap-left treap))\n treap))))\n (let ((result (recur treap)))\n (if result\n (values (%treap-key result) (%treap-value result))\n (values nil nil)))))\n\n(declaim (ftype (function * (values (or null treap) (or null treap) &optional)) treap-split))\n(defun treap-split (treap key)\n \"Destructively splits the TREAP with reference to KEY and returns two treaps,\nthe smaller sub-treap (< KEY) and the larger one (>= KEY).\"\n (declare #.OPT\n ((or null treap) treap)\n (uint32 key))\n (if (null treap)\n (values nil nil)\n (progn\n (force-down treap)\n (if (< (%treap-key treap) key)\n (multiple-value-bind (left right)\n (treap-split (%treap-right treap) key)\n (setf (%treap-right treap) left)\n (force-up treap)\n (values treap right))\n (multiple-value-bind (left right)\n (treap-split (%treap-left treap) key)\n (setf (%treap-left treap) right)\n (force-up treap)\n (values left treap))))))\n\n;; Reference: https://cp-algorithms.com/data_structures/treap.html\n;; TODO: take a sorted list as the argument\n(defun make-treap (sorted-vector)\n \"Makes a treap using each key of the given SORTED-VECTOR in O(n). Note that\nthis function doesn't check if the SORTED-VECTOR is actually sorted w.r.t. your\nintended order. The values are filled with the identity element.\"\n (declare #.OPT\n ((simple-array uint31 (*)) sorted-vector))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-treap (aref sorted-vector mid)\n +op-identity+)))\n (setf (%treap-left node) (build l mid))\n (setf (%treap-right node) (build (+ mid 1) r))\n node))))\n (build 0 (length sorted-vector))))\n\n(defconstant +pos-inf+ most-positive-fixnum)\n(defconstant +neg-inf+ most-negative-fixnum)\n\n(defun treap-query (treap &key left right)\n \"Queries the sum of the half-open interval specified by the keys: [LEFT,\nRIGHT). If LEFT [RIGHT] is not given, it is assumed to be -inf [+inf].\"\n (declare #.OPT)\n (setq left (or left +neg-inf+)\n right (or right +pos-inf+))\n (labels ((recur (treap l r)\n (declare (fixnum l r))\n (unless treap\n (return-from recur +op-identity+))\n (force-down treap)\n (prog1\n (if (and (= l +neg-inf+) (= r +pos-inf+))\n (%treap-accumulator treap)\n (let ((key (%treap-key treap)))\n (if (<= l key)\n (if (< key r)\n (funcall #'op\n (funcall #'op\n (recur (%treap-left treap) l +pos-inf+)\n (%treap-value treap))\n (recur (%treap-right treap) +neg-inf+ r))\n (recur (%treap-left treap) l r))\n (recur (%treap-right treap) l r))))\n (force-up treap))))\n (recur treap left right)))\n\n(defun treap-update (treap x left right)\n \"Updates TREAP[KEY] := (OP TREAP[KEY] X) for all KEY in [l, r)\"\n (declare #.OPT\n (fixnum left right))\n (assert (not (< right left)))\n (labels ((recur (treap l r)\n (declare (fixnum l r))\n (when treap\n (if (and (= l +neg-inf+) (= r +pos-inf+))\n (progn\n (setf (%treap-lazy treap)\n (updater-op (%treap-lazy treap) x))\n (force-down treap))\n (let ((key (%treap-key treap)))\n (force-down treap)\n (if (<= l key)\n (if (< key r)\n (progn\n (recur (%treap-left treap) l +pos-inf+)\n (setf (%treap-value treap)\n (modifier-op (%treap-value treap) x))\n (recur (%treap-right treap) +neg-inf+ r))\n (recur (%treap-left treap) l r))\n (recur (%treap-right treap) l r))))\n (force-up treap))))\n (recur treap left right)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun solve (n ls rs lrs seq)\n (declare #.OPT\n (uint31 n)\n ((simple-array uint31 (*)) ls rs seq)\n ((simple-array (cons uint31 uint31) (*)) lrs))\n (let ((inf (reduce #'max seq))\n (treap1 (make-treap seq))\n (treap2 (make-treap seq))\n (res 0))\n (dotimes (i n)\n (let ((l (aref ls i))\n (r (aref rs i)))\n (dbg l r)\n (treap-update treap2 1 l r)))\n (dotimes (i n)\n (let* ((lr (aref lrs i))\n (required1 i)\n (required2 (- n i))\n (l (car lr))\n (r (cdr lr))\n (max1 (treap-query treap1))\n (max2 (treap-query treap2)))\n (when (and (= required1 max1) (= required2 max2))\n (let* ((max1l (sb-int:named-let bisect ((ng 0) (ok inf))\n (declare (uint32 ng ok))\n (if (<= (- ok ng) 1)\n (- ok 1)\n (let ((mid (ash (+ ng ok) -1)))\n (if (= (treap-query treap1 :right mid) max1)\n (bisect ng mid)\n (bisect mid ok))))))\n (max1r (sb-int:named-let bisect ((ng max1l) (ok inf))\n (declare (uint32 ng ok))\n (if (<= (- ok ng) 1)\n (treap-bisect-left treap1 ok)\n (let ((mid (ash (+ ng ok) -1)))\n (if (< (treap-query treap1 :left mid) max1)\n (bisect ng mid)\n (bisect mid ok))))))\n (max2l (sb-int:named-let bisect ((ng 0) (ok inf))\n (declare (uint32 ng ok))\n (if (<= (- ok ng) 1)\n (- ok 1)\n (let ((mid (ash (+ ng ok) -1)))\n (if (= (treap-query treap2 :right mid) max2)\n (bisect ng mid)\n (bisect mid ok))))))\n (max2r (sb-int:named-let bisect ((ng max2l) (ok inf))\n (declare (uint32 ng ok))\n (if (<= (- ok ng) 1)\n (treap-bisect-left treap2 ok)\n (let ((mid (ash (+ ng ok) -1)))\n (if (< (treap-query treap2 :left mid) max2)\n (bisect ng mid)\n (bisect mid ok))))))\n (new-score (+ (- max1r max1l) (- max2r max2l))))\n (unless (zerop i)\n (setq res (max res new-score)))))\n (treap-update treap1 1 l r)\n (treap-update treap2 -1 l r)))\n res))\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (ls (make-array n :element-type 'uint31))\n (rs (make-array n :element-type 'uint31))\n (lrs (make-array n :element-type '(cons uint31 uint31)))\n (seq (make-array (+ n n) :element-type 'uint31)))\n (dotimes (i n)\n (let ((l (- (read-fixnum) 1))\n (r (read-fixnum)))\n (setf (aref ls i) l\n (aref rs i) r\n (aref lrs i) (cons l r)\n (aref seq i) l\n (aref seq (+ i n)) r)))\n (setq seq (sort seq #'<)\n lrs (sort lrs (lambda (x y) (< (the uint32 x) (the uint32 y))) :key #'cdr))\n (setq seq (delete-adjacent-duplicates seq))\n (let ((cand (solve n ls rs lrs seq)))\n (let ((idx 0)\n (l 0)\n (r 1000000000))\n (dotimes (i n)\n (when (>= (- (aref rs i) (aref ls i))\n (- (aref rs idx) (aref ls idx)))\n (setq idx i)))\n (dotimes (i n)\n (unless (= idx i)\n (setq l (max l (aref ls i))\n r (min r (aref rs i)))))\n (let ((cand2 (+ (- (aref rs idx) (aref ls idx))\n (max 0 (- r l)))))\n (println (max cand cand2)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n4 7\n1 4\n5 8\n2 5\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 20\n2 19\n3 18\n4 17\n\"\n \"34\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n457835016 996058008\n456475528 529149798\n455108441 512701454\n455817105 523506955\n457368248 814532746\n455073228 459494089\n456651538 774276744\n457667152 974637457\n457293701 800549465\n456580262 636471526\n\"\n \"540049931\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\n10^9 contestants, numbered 1 to 10^9, will compete in a competition.\nThere will be two contests in this competition.\n\nThe organizer prepared N problems, numbered 1 to N, to use in these contests.\nWhen Problem i is presented in a contest, it will be solved by all contestants from Contestant L_i to Contestant R_i (inclusive), and will not be solved by any other contestants.\n\nThe organizer will use these N problems in the two contests.\nEach problem must be used in exactly one of the contests, and each contest must have at least one problem.\n\nThe joyfulness of each contest is the number of contestants who will solve all the problems in the contest.\nFind the maximum possible total joyfulness of the two contests.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq L_i \\leq R_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nL_1 R_1\nL_2 R_2\n\\vdots\nL_N R_N\n\nOutput\n\nPrint the maximum possible total joyfulness of the two contests.\n\nSample Input 1\n\n4\n4 7\n1 4\n5 8\n2 5\n\nSample Output 1\n\n6\n\nThe optimal choice is:\n\nUse Problem 1 and 3 in the first contest. Contestant 5, 6, and 7 will solve both of them, so the joyfulness of this contest is 3.\n\nUse Problem 2 and 4 in the second contest. Contestant 2, 3, and 4 will solve both of them, so the joyfulness of this contest is 3.\n\nThe total joyfulness of these two contests is 6. We cannot make the total joyfulness greater than 6.\n\nSample Input 2\n\n4\n1 20\n2 19\n3 18\n4 17\n\nSample Output 2\n\n34\n\nSample Input 3\n\n10\n457835016 996058008\n456475528 529149798\n455108441 512701454\n455817105 523506955\n457368248 814532746\n455073228 459494089\n456651538 774276744\n457667152 974637457\n457293701 800549465\n456580262 636471526\n\nSample Output 3\n\n540049931", "sample_input": "4\n4 7\n1 4\n5 8\n2 5\n"}, "reference_outputs": ["6\n"], "source_document_id": "p02874", "source_text": "Score : 600 points\n\nProblem Statement\n\n10^9 contestants, numbered 1 to 10^9, will compete in a competition.\nThere will be two contests in this competition.\n\nThe organizer prepared N problems, numbered 1 to N, to use in these contests.\nWhen Problem i is presented in a contest, it will be solved by all contestants from Contestant L_i to Contestant R_i (inclusive), and will not be solved by any other contestants.\n\nThe organizer will use these N problems in the two contests.\nEach problem must be used in exactly one of the contests, and each contest must have at least one problem.\n\nThe joyfulness of each contest is the number of contestants who will solve all the problems in the contest.\nFind the maximum possible total joyfulness of the two contests.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq L_i \\leq R_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nL_1 R_1\nL_2 R_2\n\\vdots\nL_N R_N\n\nOutput\n\nPrint the maximum possible total joyfulness of the two contests.\n\nSample Input 1\n\n4\n4 7\n1 4\n5 8\n2 5\n\nSample Output 1\n\n6\n\nThe optimal choice is:\n\nUse Problem 1 and 3 in the first contest. Contestant 5, 6, and 7 will solve both of them, so the joyfulness of this contest is 3.\n\nUse Problem 2 and 4 in the second contest. Contestant 2, 3, and 4 will solve both of them, so the joyfulness of this contest is 3.\n\nThe total joyfulness of these two contests is 6. We cannot make the total joyfulness greater than 6.\n\nSample Input 2\n\n4\n1 20\n2 19\n3 18\n4 17\n\nSample Output 2\n\n34\n\nSample Input 3\n\n10\n457835016 996058008\n456475528 529149798\n455108441 512701454\n455817105 523506955\n457368248 814532746\n455073228 459494089\n456651538 774276744\n457667152 974637457\n457293701 800549465\n456580262 636471526\n\nSample Output 3\n\n540049931", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 18064, "cpu_time_ms": 2105, "memory_kb": 70504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s882663261", "group_id": "codeNet:p02880", "input_text": "(defun b-81 ()\n (let* ((n (read))\n (x (do ((i 9 (1- i)))\n ((= 0 (mod n i)) (floor n i)))))\n (if (< x 10)\n (format t \"Yes\")\n (format t \"No\"))))\n\n(b-81)\n", "language": "Lisp", "metadata": {"date": 1572227437, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02880.html", "problem_id": "p02880", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02880/input.txt", "sample_output_relpath": "derived/input_output/data/p02880/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02880/Lisp/s882663261.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s882663261", "user_id": "u845695466"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun b-81 ()\n (let* ((n (read))\n (x (do ((i 9 (1- i)))\n ((= 0 (mod n i)) (floor n i)))))\n (if (< x 10)\n (format t \"Yes\")\n (format t \"No\"))))\n\n(b-81)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nHaving learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together.\n\nGiven an integer N, determine whether N can be represented as the product of two integers between 1 and 9. If it can, print Yes; if it cannot, print No.\n\nConstraints\n\n1 \\leq N \\leq 100\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf N can be represented as the product of two integers between 1 and 9 (inclusive), print Yes; if it cannot, print No.\n\nSample Input 1\n\n10\n\nSample Output 1\n\nYes\n\n10 can be represented as, for example, 2 \\times 5.\n\nSample Input 2\n\n50\n\nSample Output 2\n\nNo\n\n50 cannot be represented as the product of two integers between 1 and 9.\n\nSample Input 3\n\n81\n\nSample Output 3\n\nYes", "sample_input": "10\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02880", "source_text": "Score : 200 points\n\nProblem Statement\n\nHaving learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together.\n\nGiven an integer N, determine whether N can be represented as the product of two integers between 1 and 9. If it can, print Yes; if it cannot, print No.\n\nConstraints\n\n1 \\leq N \\leq 100\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf N can be represented as the product of two integers between 1 and 9 (inclusive), print Yes; if it cannot, print No.\n\nSample Input 1\n\n10\n\nSample Output 1\n\nYes\n\n10 can be represented as, for example, 2 \\times 5.\n\nSample Input 2\n\n50\n\nSample Output 2\n\nNo\n\n50 cannot be represented as the product of two integers between 1 and 9.\n\nSample Input 3\n\n81\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 184, "cpu_time_ms": 362, "memory_kb": 13412}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s865722008", "group_id": "codeNet:p02880", "input_text": "(defun f(n)\n (labels ((rec (m i)\n (if (> i 9)\n nil\n (if (zerop (mod m i))\n (let ((a (/ m i)))\n (if (and (< a 10)\n (> a 0))\n t\n (rec m (1+ i))))\n (rec m (1+ i))))))\n (rec n 1)))\n(let* ((line (read-line nil nil)))\n (format t \"~A\" (if (f (parse-integer line)) \"Yes\" \"No\")))\n", "language": "Lisp", "metadata": {"date": 1572225521, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02880.html", "problem_id": "p02880", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02880/input.txt", "sample_output_relpath": "derived/input_output/data/p02880/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02880/Lisp/s865722008.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s865722008", "user_id": "u254205055"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun f(n)\n (labels ((rec (m i)\n (if (> i 9)\n nil\n (if (zerop (mod m i))\n (let ((a (/ m i)))\n (if (and (< a 10)\n (> a 0))\n t\n (rec m (1+ i))))\n (rec m (1+ i))))))\n (rec n 1)))\n(let* ((line (read-line nil nil)))\n (format t \"~A\" (if (f (parse-integer line)) \"Yes\" \"No\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nHaving learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together.\n\nGiven an integer N, determine whether N can be represented as the product of two integers between 1 and 9. If it can, print Yes; if it cannot, print No.\n\nConstraints\n\n1 \\leq N \\leq 100\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf N can be represented as the product of two integers between 1 and 9 (inclusive), print Yes; if it cannot, print No.\n\nSample Input 1\n\n10\n\nSample Output 1\n\nYes\n\n10 can be represented as, for example, 2 \\times 5.\n\nSample Input 2\n\n50\n\nSample Output 2\n\nNo\n\n50 cannot be represented as the product of two integers between 1 and 9.\n\nSample Input 3\n\n81\n\nSample Output 3\n\nYes", "sample_input": "10\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02880", "source_text": "Score : 200 points\n\nProblem Statement\n\nHaving learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together.\n\nGiven an integer N, determine whether N can be represented as the product of two integers between 1 and 9. If it can, print Yes; if it cannot, print No.\n\nConstraints\n\n1 \\leq N \\leq 100\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf N can be represented as the product of two integers between 1 and 9 (inclusive), print Yes; if it cannot, print No.\n\nSample Input 1\n\n10\n\nSample Output 1\n\nYes\n\n10 can be represented as, for example, 2 \\times 5.\n\nSample Input 2\n\n50\n\nSample Output 2\n\nNo\n\n50 cannot be represented as the product of two integers between 1 and 9.\n\nSample Input 3\n\n81\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 460, "cpu_time_ms": 367, "memory_kb": 13544}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s058042410", "group_id": "codeNet:p02884", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n;; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Memoization macro\n;;;\n\n;;\n;; Basic usage:\n;;\n;; (with-cache (:hash-table :test #'equal :key #'cons)\n;; (defun add (a b)\n;; (+ a b)))\n;; This function caches the returned values for already passed combinations of\n;; arguments. In this case ADD stores the key (CONS A B) and the return value to\n;; a hash-table when evaluating (ADD A B) for the first time. ADD returns the\n;; stored value when it is called with the same arguments (w.r.t. EQUAL) again.\n;;\n;; The storage for the cache is hash-table or array. Let's see an example for\n;; array:\n;; (with-cache (:array (10 20 30) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c) ... ))\n;; This form stores the value of FOO in the array created by (make-array (list\n;; 10 20 30) :initial-element -1 :element-type 'fixnum). Note that\n;; INITIAL-ELEMENT must always be given here as it is used as the flag for `not\n;; yet stored'. (Therefore INITIAL-ELEMENT should be a value FOO never takes.)\n;;\n;; If you want to ignore some arguments, you can put `*' in dimensions:\n;; (with-cache (:array (10 10 * 10) :initial-element -1)\n;; (defun foo (a b c d) ...)) ; then C is ignored when querying or storing cache\n;;\n;; Available definition forms in WITH-CACHE are DEFUN, LABELS, FLET, and\n;; SB-INT:NAMED-LET.\n;;\n;; You can trace the memoized function by :TRACE option:\n;; (with-cache (:array (10 10) :initial-element -1 :trace t)\n;; (defun foo (x y) ...))\n;; Then FOO is traced as with CL:TRACE.\n;;\n\n;; TODO & NOTE: Currently a memoized function is not enclosed with a block of\n;; the function name.\n\n;; FIXME: *RECURSION-DEPTH* should be included within the macro.\n(declaim (type (integer 0 #.most-positive-fixnum) *recursion-depth*))\n(defparameter *recursion-depth* 0)\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun %enclose-with-trace (fname args form)\n (let ((value (gensym)))\n `(progn\n (format t \"~&~A~A: (~A ~{~A~^ ~}) =>\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args))\n (let ((,value (let ((*recursion-depth* (1+ *recursion-depth*)))\n ,form)))\n (format t \"~&~A~A: (~A ~{~A~^ ~}) => ~A\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args)\n ,value)\n ,value))))\n\n (defun %extract-declarations (body)\n (remove-if-not (lambda (form) (and (consp form) (eql 'declare (car form))))\n body))\n\n (defun %parse-cache-form (cache-specifier)\n (let ((cache-type (car cache-specifier))\n (cache-attribs (cdr cache-specifier)))\n (assert (member cache-type '(:hash-table :array)))\n (let* ((dims-with-* (when (eql cache-type :array) (first cache-attribs)))\n (dims (remove '* dims-with-*))\n (rank (length dims))\n (rest-attribs (ecase cache-type\n (:hash-table cache-attribs)\n (:array (cdr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (trace-p (prog1 (getf rest-attribs :trace) (remf rest-attribs :trace)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array (list ,@dims) ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym \"CACHE\"))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels\n ((make-cache-querier (cache-type name args)\n (let ((res (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dims-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value))))))))\n (if trace-p\n (%enclose-with-trace name args res)\n res)))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name)))))\n (values cache cache-form cache-type name-alias\n #'make-reset-name\n #'make-reset-form\n #'make-cache-querier)))))))\n\n(defmacro with-cache ((cache-type &rest cache-attribs) def-form)\n \"CACHE-TYPE := :HASH-TABLE | :ARRAY.\nDEF-FORM := definition form with DEFUN, LABELS, FLET, or SB-INT:NAMED-LET.\"\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form\n make-cache-querier)\n (%parse-cache-form (cons cache-type cache-attribs))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (defun ,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (defun ,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form)\n ((,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args)))\n ,@(cdr definitions))\n (declare (ignorable #',(funcall make-reset-name name)))\n ,@labels-body)))))\n ((nlet #+sbcl sb-int:named-let)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form) ,name ,bindings\n ,@(%extract-declarations body)\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))))))\n\n(defmacro with-caches (cache-specs def-form)\n \"DEF-FORM := definition form by LABELS or FLET.\n\n (with-caches (cache-spec1 cache-spec2)\n (labels ((f (x) ...) (g (y) ...))))\nis equivalent to the line up of\n (with-cache cache-spec1 (labels ((f (x) ...))))\nand\n (with-cache cache-spec2 (labels ((g (y) ...))))\n\nThis macro will be useful to do mutual recursion between memoized local\nfunctions.\"\n (assert (member (car def-form) '(labels flet)))\n (let (cache-symbol-list cache-form-list cache-type-list name-alias-list make-reset-name-list make-reset-form-list make-cache-querier-list)\n (dolist (cache-spec (reverse cache-specs))\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form make-cache-querier)\n (%parse-cache-form cache-spec)\n (push cache-symbol cache-symbol-list)\n (push cache-form cache-form-list)\n (push cache-type cache-type-list)\n (push name-alias name-alias-list)\n (push make-reset-name make-reset-name-list)\n (push make-reset-form make-reset-form-list)\n (push make-cache-querier make-cache-querier-list)))\n (labels ((def-name (def) (first def))\n (def-args (def) (second def))\n (def-body (def) (cddr def)))\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n `(let ,(loop for cache-symbol in cache-symbol-list\n for cache-form in cache-form-list\n collect `(,cache-symbol ,cache-form))\n (,(car def-form)\n (,@(loop for def in definitions\n for cache-type in cache-type-list\n for make-reset-name in make-reset-name-list\n for make-reset-form in make-reset-form-list\n collect `(,(funcall make-reset-name (def-name def)) ()\n ,(funcall make-reset-form cache-type)))\n ,@(loop for def in definitions\n for cache-type in cache-type-list\n for name-alias in name-alias-list\n for make-cache-querier in make-cache-querier-list\n collect `(,(def-name def) ,(def-args def)\n ,@(%extract-declarations (def-body def))\n (labels ((,name-alias ,(def-args def) ,@(def-body def)))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type (def-name def) (def-args def))))))\n (declare (ignorable ,@(loop for def in definitions\n for make-reset-name in make-reset-name-list\n collect `#',(funcall make-reset-name\n (def-name def)))))\n ,@labels-body))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n;; Reference: http://drken1215.hatenablog.com/entry/2019/03/20/202800\n(defun echelon! (matrix &optional extended)\n \"Returns the row echelon form of MATRIX by gaussian elimination and returns\nthe rank as the second value.\n\nThis function destructively modifies MATRIX.\"\n (labels ((%zerop (x)\n (< (abs x) 1d-9)))\n (destructuring-bind (m n) (array-dimensions matrix)\n (declare ((integer 0 #.most-positive-fixnum) m n))\n (let ((rank 0))\n (dotimes (target-col (if extended (- n 1) n))\n (let ((pivot-row (do ((i rank (+ 1 i)))\n ((= i m) -1)\n (unless (%zerop (aref matrix i target-col))\n (return i)))))\n (when (>= pivot-row 0)\n ;; swap rows\n (loop for j from target-col below n\n do (rotatef (aref matrix rank j) (aref matrix pivot-row j)))\n (let ((inv (/ (aref matrix rank target-col))))\n (dotimes (j n)\n (setf (aref matrix rank j)\n (* inv (aref matrix rank j))))\n (dotimes (i m)\n (unless (or (= i rank) (%zerop (aref matrix i target-col)))\n (let ((factor (aref matrix i target-col)))\n (loop for j from target-col below n\n do (setf (aref matrix i j)\n (- (aref matrix i j)\n (* (aref matrix rank j) factor))))))))\n (incf rank))))\n (values matrix rank)))))\n\n(defun solve-linear-system (matrix vector)\n \"Solves Ax ≡ b and returns a root vector if it exists. Otherwise it returns\nNIL. In addition, this function returns the rank of A as the second value.\"\n (destructuring-bind (m n) (array-dimensions matrix)\n (declare ((integer 0 #.most-positive-fixnum) m n))\n (assert (= n (length vector)))\n (let ((extended (make-array (list m (+ n 1)) :element-type (array-element-type matrix))))\n (labels ((%zerop (x)\n (< (abs x) 1d-9)))\n (dotimes (i m)\n (dotimes (j n) (setf (aref extended i j) (aref matrix i j)))\n (setf (aref extended i n) (aref vector i)))\n (let ((rank (nth-value 1 (echelon! extended t))))\n (if (loop for i from rank below m\n always (%zerop (aref extended i n)))\n (let ((result (make-array m\n :element-type (array-element-type matrix)\n :initial-element 0)))\n (dotimes (i rank)\n (setf (aref result i) (aref extended i n)))\n (values result rank))\n (values nil rank)))))))\n\n;; (defun main ()\n;; (let* ((n (read))\n;; (m (read))\n;; (graph (make-array n :element-type 'list :initial-element nil))\n;; (revgraph (make-array n :element-type 'list :initial-element nil))\n;; (out-degrees (make-array n :element-type 'uint31))\n;; (in-degrees (make-array n :element-type 'uint31))\n;; (mat (make-array (list n n) :element-type 'double-float :initial-element 0d0)))\n;; (dotimes (i m)\n;; (let ((src (- (read-fixnum) 1))\n;; (dest (- (read-fixnum) 1)))\n;; (push dest (aref graph src))\n;; (push src (aref revgraph dest))\n;; (incf (aref out-degrees src))\n;; (incf (aref in-degrees dest))))\n;; (dotimes (w n)\n;; (let ((adj-list (aref revgraph w)))\n;; (dolist (v adj-list)\n;; (setf (aref mat w v)\n;; (/ (float (aref out-degrees v) 1d0))))))\n;; #>mat\n;; (dotimes (i n)\n;; (dotimes (j n)\n;; (if (= i j)\n;; (setf (aref mat i j) (- 1d0 (aref mat i j)))\n;; (setf (aref mat i j) (- (aref mat i j))))))\n;; mat))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (revgraph (make-array n :element-type 'list :initial-element nil))\n (out-degrees (make-array n :element-type 'uint31))\n (in-degrees (make-array n :element-type 'uint31))\n (ss (make-array m :element-type 'uint31))\n (ts (make-array m :element-type 'uint31)))\n (dotimes (i m)\n (let ((src (- (read-fixnum) 1))\n (dest (- (read-fixnum) 1)))\n (push dest (aref graph src))\n (push src (aref revgraph dest))\n (incf (aref out-degrees src))\n (incf (aref in-degrees dest))\n (setf (aref ss i) src)\n (setf (aref ts i) dest)))\n #>out-degrees\n (with-cache (:array (601 (+ m 1)) :element-type 'double-float :initial-element most-negative-double-float)\n (labels ((calc (v seg-id)\n (if (zerop v)\n 0d0\n (let ((exists nil)\n (value 0d0)\n (src (if (= seg-id m) -1 (aref ss seg-id)))\n (dest (if (= seg-id m) -1 (aref ts seg-id))))\n (dolist (prev (aref revgraph v))\n (unless (and (= prev src) (= dest v))\n (let ((delta (calc prev seg-id)))\n (unless (= delta most-positive-double-float)\n (setq exists t)\n (incf value (/ delta (aref out-degrees prev)))))))\n (if exists\n (+ value 1d0)\n most-positive-double-float)))))\n (let ((res (calc (- n 1) m)))\n (loop for seg-id from 0 below m\n do (let ((src (aref ss seg-id))\n (dest (aref ts seg-id)))\n (decf (aref out-degrees src))\n #>out-degrees\n (let ((value #>(calc (- n 1) seg-id)))\n (unless (= most-positive-double-float value)\n (setq res (min res value))))\n (incf (aref out-degrees src))))\n (println res))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 6\n1 4\n2 3\n1 3\n1 2\n3 4\n2 4\n\"\n \"1.5000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 2\n1 2\n2 3\n\"\n \"2.0000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 33\n3 7\n5 10\n8 9\n1 10\n4 6\n2 5\n1 7\n6 10\n1 4\n1 3\n8 10\n1 5\n2 6\n6 9\n5 6\n5 8\n3 6\n4 8\n2 7\n2 9\n6 7\n1 2\n5 9\n6 8\n9 10\n3 9\n7 8\n4 5\n2 10\n5 7\n3 5\n4 7\n4 9\n\"\n \"3.0133333333\n\")))\n", "language": "Lisp", "metadata": {"date": 1572230300, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02884.html", "problem_id": "p02884", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02884/input.txt", "sample_output_relpath": "derived/input_output/data/p02884/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02884/Lisp/s058042410.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s058042410", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1.5000000000\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n;; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Memoization macro\n;;;\n\n;;\n;; Basic usage:\n;;\n;; (with-cache (:hash-table :test #'equal :key #'cons)\n;; (defun add (a b)\n;; (+ a b)))\n;; This function caches the returned values for already passed combinations of\n;; arguments. In this case ADD stores the key (CONS A B) and the return value to\n;; a hash-table when evaluating (ADD A B) for the first time. ADD returns the\n;; stored value when it is called with the same arguments (w.r.t. EQUAL) again.\n;;\n;; The storage for the cache is hash-table or array. Let's see an example for\n;; array:\n;; (with-cache (:array (10 20 30) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c) ... ))\n;; This form stores the value of FOO in the array created by (make-array (list\n;; 10 20 30) :initial-element -1 :element-type 'fixnum). Note that\n;; INITIAL-ELEMENT must always be given here as it is used as the flag for `not\n;; yet stored'. (Therefore INITIAL-ELEMENT should be a value FOO never takes.)\n;;\n;; If you want to ignore some arguments, you can put `*' in dimensions:\n;; (with-cache (:array (10 10 * 10) :initial-element -1)\n;; (defun foo (a b c d) ...)) ; then C is ignored when querying or storing cache\n;;\n;; Available definition forms in WITH-CACHE are DEFUN, LABELS, FLET, and\n;; SB-INT:NAMED-LET.\n;;\n;; You can trace the memoized function by :TRACE option:\n;; (with-cache (:array (10 10) :initial-element -1 :trace t)\n;; (defun foo (x y) ...))\n;; Then FOO is traced as with CL:TRACE.\n;;\n\n;; TODO & NOTE: Currently a memoized function is not enclosed with a block of\n;; the function name.\n\n;; FIXME: *RECURSION-DEPTH* should be included within the macro.\n(declaim (type (integer 0 #.most-positive-fixnum) *recursion-depth*))\n(defparameter *recursion-depth* 0)\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun %enclose-with-trace (fname args form)\n (let ((value (gensym)))\n `(progn\n (format t \"~&~A~A: (~A ~{~A~^ ~}) =>\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args))\n (let ((,value (let ((*recursion-depth* (1+ *recursion-depth*)))\n ,form)))\n (format t \"~&~A~A: (~A ~{~A~^ ~}) => ~A\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args)\n ,value)\n ,value))))\n\n (defun %extract-declarations (body)\n (remove-if-not (lambda (form) (and (consp form) (eql 'declare (car form))))\n body))\n\n (defun %parse-cache-form (cache-specifier)\n (let ((cache-type (car cache-specifier))\n (cache-attribs (cdr cache-specifier)))\n (assert (member cache-type '(:hash-table :array)))\n (let* ((dims-with-* (when (eql cache-type :array) (first cache-attribs)))\n (dims (remove '* dims-with-*))\n (rank (length dims))\n (rest-attribs (ecase cache-type\n (:hash-table cache-attribs)\n (:array (cdr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (trace-p (prog1 (getf rest-attribs :trace) (remf rest-attribs :trace)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array (list ,@dims) ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym \"CACHE\"))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels\n ((make-cache-querier (cache-type name args)\n (let ((res (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dims-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value))))))))\n (if trace-p\n (%enclose-with-trace name args res)\n res)))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name)))))\n (values cache cache-form cache-type name-alias\n #'make-reset-name\n #'make-reset-form\n #'make-cache-querier)))))))\n\n(defmacro with-cache ((cache-type &rest cache-attribs) def-form)\n \"CACHE-TYPE := :HASH-TABLE | :ARRAY.\nDEF-FORM := definition form with DEFUN, LABELS, FLET, or SB-INT:NAMED-LET.\"\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form\n make-cache-querier)\n (%parse-cache-form (cons cache-type cache-attribs))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (defun ,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (defun ,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form)\n ((,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args)))\n ,@(cdr definitions))\n (declare (ignorable #',(funcall make-reset-name name)))\n ,@labels-body)))))\n ((nlet #+sbcl sb-int:named-let)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form) ,name ,bindings\n ,@(%extract-declarations body)\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))))))\n\n(defmacro with-caches (cache-specs def-form)\n \"DEF-FORM := definition form by LABELS or FLET.\n\n (with-caches (cache-spec1 cache-spec2)\n (labels ((f (x) ...) (g (y) ...))))\nis equivalent to the line up of\n (with-cache cache-spec1 (labels ((f (x) ...))))\nand\n (with-cache cache-spec2 (labels ((g (y) ...))))\n\nThis macro will be useful to do mutual recursion between memoized local\nfunctions.\"\n (assert (member (car def-form) '(labels flet)))\n (let (cache-symbol-list cache-form-list cache-type-list name-alias-list make-reset-name-list make-reset-form-list make-cache-querier-list)\n (dolist (cache-spec (reverse cache-specs))\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form make-cache-querier)\n (%parse-cache-form cache-spec)\n (push cache-symbol cache-symbol-list)\n (push cache-form cache-form-list)\n (push cache-type cache-type-list)\n (push name-alias name-alias-list)\n (push make-reset-name make-reset-name-list)\n (push make-reset-form make-reset-form-list)\n (push make-cache-querier make-cache-querier-list)))\n (labels ((def-name (def) (first def))\n (def-args (def) (second def))\n (def-body (def) (cddr def)))\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n `(let ,(loop for cache-symbol in cache-symbol-list\n for cache-form in cache-form-list\n collect `(,cache-symbol ,cache-form))\n (,(car def-form)\n (,@(loop for def in definitions\n for cache-type in cache-type-list\n for make-reset-name in make-reset-name-list\n for make-reset-form in make-reset-form-list\n collect `(,(funcall make-reset-name (def-name def)) ()\n ,(funcall make-reset-form cache-type)))\n ,@(loop for def in definitions\n for cache-type in cache-type-list\n for name-alias in name-alias-list\n for make-cache-querier in make-cache-querier-list\n collect `(,(def-name def) ,(def-args def)\n ,@(%extract-declarations (def-body def))\n (labels ((,name-alias ,(def-args def) ,@(def-body def)))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type (def-name def) (def-args def))))))\n (declare (ignorable ,@(loop for def in definitions\n for make-reset-name in make-reset-name-list\n collect `#',(funcall make-reset-name\n (def-name def)))))\n ,@labels-body))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n;; Reference: http://drken1215.hatenablog.com/entry/2019/03/20/202800\n(defun echelon! (matrix &optional extended)\n \"Returns the row echelon form of MATRIX by gaussian elimination and returns\nthe rank as the second value.\n\nThis function destructively modifies MATRIX.\"\n (labels ((%zerop (x)\n (< (abs x) 1d-9)))\n (destructuring-bind (m n) (array-dimensions matrix)\n (declare ((integer 0 #.most-positive-fixnum) m n))\n (let ((rank 0))\n (dotimes (target-col (if extended (- n 1) n))\n (let ((pivot-row (do ((i rank (+ 1 i)))\n ((= i m) -1)\n (unless (%zerop (aref matrix i target-col))\n (return i)))))\n (when (>= pivot-row 0)\n ;; swap rows\n (loop for j from target-col below n\n do (rotatef (aref matrix rank j) (aref matrix pivot-row j)))\n (let ((inv (/ (aref matrix rank target-col))))\n (dotimes (j n)\n (setf (aref matrix rank j)\n (* inv (aref matrix rank j))))\n (dotimes (i m)\n (unless (or (= i rank) (%zerop (aref matrix i target-col)))\n (let ((factor (aref matrix i target-col)))\n (loop for j from target-col below n\n do (setf (aref matrix i j)\n (- (aref matrix i j)\n (* (aref matrix rank j) factor))))))))\n (incf rank))))\n (values matrix rank)))))\n\n(defun solve-linear-system (matrix vector)\n \"Solves Ax ≡ b and returns a root vector if it exists. Otherwise it returns\nNIL. In addition, this function returns the rank of A as the second value.\"\n (destructuring-bind (m n) (array-dimensions matrix)\n (declare ((integer 0 #.most-positive-fixnum) m n))\n (assert (= n (length vector)))\n (let ((extended (make-array (list m (+ n 1)) :element-type (array-element-type matrix))))\n (labels ((%zerop (x)\n (< (abs x) 1d-9)))\n (dotimes (i m)\n (dotimes (j n) (setf (aref extended i j) (aref matrix i j)))\n (setf (aref extended i n) (aref vector i)))\n (let ((rank (nth-value 1 (echelon! extended t))))\n (if (loop for i from rank below m\n always (%zerop (aref extended i n)))\n (let ((result (make-array m\n :element-type (array-element-type matrix)\n :initial-element 0)))\n (dotimes (i rank)\n (setf (aref result i) (aref extended i n)))\n (values result rank))\n (values nil rank)))))))\n\n;; (defun main ()\n;; (let* ((n (read))\n;; (m (read))\n;; (graph (make-array n :element-type 'list :initial-element nil))\n;; (revgraph (make-array n :element-type 'list :initial-element nil))\n;; (out-degrees (make-array n :element-type 'uint31))\n;; (in-degrees (make-array n :element-type 'uint31))\n;; (mat (make-array (list n n) :element-type 'double-float :initial-element 0d0)))\n;; (dotimes (i m)\n;; (let ((src (- (read-fixnum) 1))\n;; (dest (- (read-fixnum) 1)))\n;; (push dest (aref graph src))\n;; (push src (aref revgraph dest))\n;; (incf (aref out-degrees src))\n;; (incf (aref in-degrees dest))))\n;; (dotimes (w n)\n;; (let ((adj-list (aref revgraph w)))\n;; (dolist (v adj-list)\n;; (setf (aref mat w v)\n;; (/ (float (aref out-degrees v) 1d0))))))\n;; #>mat\n;; (dotimes (i n)\n;; (dotimes (j n)\n;; (if (= i j)\n;; (setf (aref mat i j) (- 1d0 (aref mat i j)))\n;; (setf (aref mat i j) (- (aref mat i j))))))\n;; mat))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (revgraph (make-array n :element-type 'list :initial-element nil))\n (out-degrees (make-array n :element-type 'uint31))\n (in-degrees (make-array n :element-type 'uint31))\n (ss (make-array m :element-type 'uint31))\n (ts (make-array m :element-type 'uint31)))\n (dotimes (i m)\n (let ((src (- (read-fixnum) 1))\n (dest (- (read-fixnum) 1)))\n (push dest (aref graph src))\n (push src (aref revgraph dest))\n (incf (aref out-degrees src))\n (incf (aref in-degrees dest))\n (setf (aref ss i) src)\n (setf (aref ts i) dest)))\n #>out-degrees\n (with-cache (:array (601 (+ m 1)) :element-type 'double-float :initial-element most-negative-double-float)\n (labels ((calc (v seg-id)\n (if (zerop v)\n 0d0\n (let ((exists nil)\n (value 0d0)\n (src (if (= seg-id m) -1 (aref ss seg-id)))\n (dest (if (= seg-id m) -1 (aref ts seg-id))))\n (dolist (prev (aref revgraph v))\n (unless (and (= prev src) (= dest v))\n (let ((delta (calc prev seg-id)))\n (unless (= delta most-positive-double-float)\n (setq exists t)\n (incf value (/ delta (aref out-degrees prev)))))))\n (if exists\n (+ value 1d0)\n most-positive-double-float)))))\n (let ((res (calc (- n 1) m)))\n (loop for seg-id from 0 below m\n do (let ((src (aref ss seg-id))\n (dest (aref ts seg-id)))\n (decf (aref out-degrees src))\n #>out-degrees\n (let ((value #>(calc (- n 1) seg-id)))\n (unless (= most-positive-double-float value)\n (setq res (min res value))))\n (incf (aref out-degrees src))))\n (println res))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 6\n1 4\n2 3\n1 3\n1 2\n3 4\n2 4\n\"\n \"1.5000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 2\n1 2\n2 3\n\"\n \"2.0000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 33\n3 7\n5 10\n8 9\n1 10\n4 6\n2 5\n1 7\n6 10\n1 4\n1 3\n8 10\n1 5\n2 6\n6 9\n5 6\n5 8\n3 6\n4 8\n2 7\n2 9\n6 7\n1 2\n5 9\n6 8\n9 10\n3 9\n7 8\n4 5\n2 10\n5 7\n3 5\n4 7\n4 9\n\"\n \"3.0133333333\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere is a cave consisting of N rooms and M one-directional passages. The rooms are numbered 1 through N.\n\nTakahashi is now in Room 1, and Room N has the exit. The i-th passage connects Room s_i and Room t_i (s_i < t_i) and can only be traversed in the direction from Room s_i to Room t_i. It is known that, for each room except Room N, there is at least one passage going from that room.\n\nTakahashi will escape from the cave. Each time he reaches a room (assume that he has reached Room 1 at the beginning), he will choose a passage uniformly at random from the ones going from that room and take that passage.\n\nAoki, a friend of Takahashi's, can block one of the passages (or do nothing) before Takahashi leaves Room 1. However, it is not allowed to block a passage so that Takahashi is potentially unable to reach Room N.\n\nLet E be the expected number of passages Takahashi takes before he reaches Room N. Find the value of E when Aoki makes a choice that minimizes E.\n\nConstraints\n\n2 \\leq N \\leq 600\n\nN-1 \\leq M \\leq \\frac{N(N-1)}{2}\n\ns_i < t_i\n\nIf i != j, (s_i, t_i) \\neq (s_j, t_j). (Added 21:23 JST)\n\nFor every v = 1, 2, ..., N-1, there exists i such that v = s_i.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\ns_1 t_1\n:\ns_M t_M\n\nOutput\n\nPrint the value of E when Aoki makes a choice that minimizes E.\nYour output will be judged as correct when the absolute or relative error from the judge's output is at most 10^{-6}.\n\nSample Input 1\n\n4 6\n1 4\n2 3\n1 3\n1 2\n3 4\n2 4\n\nSample Output 1\n\n1.5000000000\n\nIf Aoki blocks the passage from Room 1 to Room 2, Takahashi will go along the path 1 → 3 → 4 with probability \\frac{1}{2} and 1 → 4 with probability \\frac{1}{2}. E = 1.5 here, and this is the minimum possible value of E.\n\nSample Input 2\n\n3 2\n1 2\n2 3\n\nSample Output 2\n\n2.0000000000\n\nBlocking any one passage makes Takahashi unable to reach Room N, so Aoki cannot block a passage.\n\nSample Input 3\n\n10 33\n3 7\n5 10\n8 9\n1 10\n4 6\n2 5\n1 7\n6 10\n1 4\n1 3\n8 10\n1 5\n2 6\n6 9\n5 6\n5 8\n3 6\n4 8\n2 7\n2 9\n6 7\n1 2\n5 9\n6 8\n9 10\n3 9\n7 8\n4 5\n2 10\n5 7\n3 5\n4 7\n4 9\n\nSample Output 3\n\n3.0133333333", "sample_input": "4 6\n1 4\n2 3\n1 3\n1 2\n3 4\n2 4\n"}, "reference_outputs": ["1.5000000000\n"], "source_document_id": "p02884", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere is a cave consisting of N rooms and M one-directional passages. The rooms are numbered 1 through N.\n\nTakahashi is now in Room 1, and Room N has the exit. The i-th passage connects Room s_i and Room t_i (s_i < t_i) and can only be traversed in the direction from Room s_i to Room t_i. It is known that, for each room except Room N, there is at least one passage going from that room.\n\nTakahashi will escape from the cave. Each time he reaches a room (assume that he has reached Room 1 at the beginning), he will choose a passage uniformly at random from the ones going from that room and take that passage.\n\nAoki, a friend of Takahashi's, can block one of the passages (or do nothing) before Takahashi leaves Room 1. However, it is not allowed to block a passage so that Takahashi is potentially unable to reach Room N.\n\nLet E be the expected number of passages Takahashi takes before he reaches Room N. Find the value of E when Aoki makes a choice that minimizes E.\n\nConstraints\n\n2 \\leq N \\leq 600\n\nN-1 \\leq M \\leq \\frac{N(N-1)}{2}\n\ns_i < t_i\n\nIf i != j, (s_i, t_i) \\neq (s_j, t_j). (Added 21:23 JST)\n\nFor every v = 1, 2, ..., N-1, there exists i such that v = s_i.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\ns_1 t_1\n:\ns_M t_M\n\nOutput\n\nPrint the value of E when Aoki makes a choice that minimizes E.\nYour output will be judged as correct when the absolute or relative error from the judge's output is at most 10^{-6}.\n\nSample Input 1\n\n4 6\n1 4\n2 3\n1 3\n1 2\n3 4\n2 4\n\nSample Output 1\n\n1.5000000000\n\nIf Aoki blocks the passage from Room 1 to Room 2, Takahashi will go along the path 1 → 3 → 4 with probability \\frac{1}{2} and 1 → 4 with probability \\frac{1}{2}. E = 1.5 here, and this is the minimum possible value of E.\n\nSample Input 2\n\n3 2\n1 2\n2 3\n\nSample Output 2\n\n2.0000000000\n\nBlocking any one passage makes Takahashi unable to reach Room N, so Aoki cannot block a passage.\n\nSample Input 3\n\n10 33\n3 7\n5 10\n8 9\n1 10\n4 6\n2 5\n1 7\n6 10\n1 4\n1 3\n8 10\n1 5\n2 6\n6 9\n5 6\n5 8\n3 6\n4 8\n2 7\n2 9\n6 7\n1 2\n5 9\n6 8\n9 10\n3 9\n7 8\n4 5\n2 10\n5 7\n3 5\n4 7\n4 9\n\nSample Output 3\n\n3.0133333333", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 23264, "cpu_time_ms": 2116, "memory_kb": 921080}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s413412475", "group_id": "codeNet:p02885", "input_text": "(let ((a (read))\n (b (read))\n (ans 0))\n\n (if (> a (* b 2))\n (setq ans (- a b b))\n )\n (princ ans)\n)", "language": "Lisp", "metadata": {"date": 1593978653, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02885.html", "problem_id": "p02885", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02885/input.txt", "sample_output_relpath": "derived/input_output/data/p02885/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02885/Lisp/s413412475.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s413412475", "user_id": "u136500538"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (ans 0))\n\n (if (> a (* b 2))\n (setq ans (- a b b))\n )\n (princ ans)\n)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThe window of Takahashi's room has a width of A. There are two curtains hung over the window, each of which has a horizontal length of B. (Vertically, the curtains are long enough to cover the whole window.)\n\nWe will close the window so as to minimize the total horizontal length of the uncovered part of the window.\nFind the total horizontal length of the uncovered parts of the window then.\n\nConstraints\n\n1 \\leq A \\leq 100\n\n1 \\leq B \\leq 100\n\nA and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the total horizontal length of the uncovered parts of the window.\n\nSample Input 1\n\n12 4\n\nSample Output 1\n\n4\n\nWe have a window with a horizontal length of 12, and two curtains, each of length 4, that cover both ends of the window, for example. The uncovered part has a horizontal length of 4.\n\nSample Input 2\n\n20 15\n\nSample Output 2\n\n0\n\nIf the window is completely covered, print 0.\n\nSample Input 3\n\n20 30\n\nSample Output 3\n\n0\n\nEach curtain may be longer than the window.", "sample_input": "12 4\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02885", "source_text": "Score : 100 points\n\nProblem Statement\n\nThe window of Takahashi's room has a width of A. There are two curtains hung over the window, each of which has a horizontal length of B. (Vertically, the curtains are long enough to cover the whole window.)\n\nWe will close the window so as to minimize the total horizontal length of the uncovered part of the window.\nFind the total horizontal length of the uncovered parts of the window then.\n\nConstraints\n\n1 \\leq A \\leq 100\n\n1 \\leq B \\leq 100\n\nA and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the total horizontal length of the uncovered parts of the window.\n\nSample Input 1\n\n12 4\n\nSample Output 1\n\n4\n\nWe have a window with a horizontal length of 12, and two curtains, each of length 4, that cover both ends of the window, for example. The uncovered part has a horizontal length of 4.\n\nSample Input 2\n\n20 15\n\nSample Output 2\n\n0\n\nIf the window is completely covered, print 0.\n\nSample Input 3\n\n20 30\n\nSample Output 3\n\n0\n\nEach curtain may be longer than the window.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 120, "cpu_time_ms": 20, "memory_kb": 24364}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s934289917", "group_id": "codeNet:p02885", "input_text": "(defun curtain (a b)\n (if(< (- a (* 2 b)) 0) 0 (- a (* 2 b)))\n )\n(prin1 (curtain (read) (read)))\n\n", "language": "Lisp", "metadata": {"date": 1571951206, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02885.html", "problem_id": "p02885", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02885/input.txt", "sample_output_relpath": "derived/input_output/data/p02885/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02885/Lisp/s934289917.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s934289917", "user_id": "u423656246"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun curtain (a b)\n (if(< (- a (* 2 b)) 0) 0 (- a (* 2 b)))\n )\n(prin1 (curtain (read) (read)))\n\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThe window of Takahashi's room has a width of A. There are two curtains hung over the window, each of which has a horizontal length of B. (Vertically, the curtains are long enough to cover the whole window.)\n\nWe will close the window so as to minimize the total horizontal length of the uncovered part of the window.\nFind the total horizontal length of the uncovered parts of the window then.\n\nConstraints\n\n1 \\leq A \\leq 100\n\n1 \\leq B \\leq 100\n\nA and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the total horizontal length of the uncovered parts of the window.\n\nSample Input 1\n\n12 4\n\nSample Output 1\n\n4\n\nWe have a window with a horizontal length of 12, and two curtains, each of length 4, that cover both ends of the window, for example. The uncovered part has a horizontal length of 4.\n\nSample Input 2\n\n20 15\n\nSample Output 2\n\n0\n\nIf the window is completely covered, print 0.\n\nSample Input 3\n\n20 30\n\nSample Output 3\n\n0\n\nEach curtain may be longer than the window.", "sample_input": "12 4\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02885", "source_text": "Score : 100 points\n\nProblem Statement\n\nThe window of Takahashi's room has a width of A. There are two curtains hung over the window, each of which has a horizontal length of B. (Vertically, the curtains are long enough to cover the whole window.)\n\nWe will close the window so as to minimize the total horizontal length of the uncovered part of the window.\nFind the total horizontal length of the uncovered parts of the window then.\n\nConstraints\n\n1 \\leq A \\leq 100\n\n1 \\leq B \\leq 100\n\nA and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the total horizontal length of the uncovered parts of the window.\n\nSample Input 1\n\n12 4\n\nSample Output 1\n\n4\n\nWe have a window with a horizontal length of 12, and two curtains, each of length 4, that cover both ends of the window, for example. The uncovered part has a horizontal length of 4.\n\nSample Input 2\n\n20 15\n\nSample Output 2\n\n0\n\nIf the window is completely covered, print 0.\n\nSample Input 3\n\n20 30\n\nSample Output 3\n\n0\n\nEach curtain may be longer than the window.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 111, "cpu_time_ms": 145, "memory_kb": 11236}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s485254908", "group_id": "codeNet:p02885", "input_text": "(setq a (read) b (read))\n(format t \"~A~%\" (max 0 (- a (* b 2))))", "language": "Lisp", "metadata": {"date": 1571540569, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02885.html", "problem_id": "p02885", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02885/input.txt", "sample_output_relpath": "derived/input_output/data/p02885/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02885/Lisp/s485254908.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s485254908", "user_id": "u223904637"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(setq a (read) b (read))\n(format t \"~A~%\" (max 0 (- a (* b 2))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThe window of Takahashi's room has a width of A. There are two curtains hung over the window, each of which has a horizontal length of B. (Vertically, the curtains are long enough to cover the whole window.)\n\nWe will close the window so as to minimize the total horizontal length of the uncovered part of the window.\nFind the total horizontal length of the uncovered parts of the window then.\n\nConstraints\n\n1 \\leq A \\leq 100\n\n1 \\leq B \\leq 100\n\nA and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the total horizontal length of the uncovered parts of the window.\n\nSample Input 1\n\n12 4\n\nSample Output 1\n\n4\n\nWe have a window with a horizontal length of 12, and two curtains, each of length 4, that cover both ends of the window, for example. The uncovered part has a horizontal length of 4.\n\nSample Input 2\n\n20 15\n\nSample Output 2\n\n0\n\nIf the window is completely covered, print 0.\n\nSample Input 3\n\n20 30\n\nSample Output 3\n\n0\n\nEach curtain may be longer than the window.", "sample_input": "12 4\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02885", "source_text": "Score : 100 points\n\nProblem Statement\n\nThe window of Takahashi's room has a width of A. There are two curtains hung over the window, each of which has a horizontal length of B. (Vertically, the curtains are long enough to cover the whole window.)\n\nWe will close the window so as to minimize the total horizontal length of the uncovered part of the window.\nFind the total horizontal length of the uncovered parts of the window then.\n\nConstraints\n\n1 \\leq A \\leq 100\n\n1 \\leq B \\leq 100\n\nA and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the total horizontal length of the uncovered parts of the window.\n\nSample Input 1\n\n12 4\n\nSample Output 1\n\n4\n\nWe have a window with a horizontal length of 12, and two curtains, each of length 4, that cover both ends of the window, for example. The uncovered part has a horizontal length of 4.\n\nSample Input 2\n\n20 15\n\nSample Output 2\n\n0\n\nIf the window is completely covered, print 0.\n\nSample Input 3\n\n20 30\n\nSample Output 3\n\n0\n\nEach curtain may be longer than the window.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 64, "cpu_time_ms": 72, "memory_kb": 8548}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s046204225", "group_id": "codeNet:p02885", "input_text": "(let ((a (read))\n (b (read)))\n (format t \"~A~%\" (max 0 (- a (* 2 b)))))", "language": "Lisp", "metadata": {"date": 1571534370, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02885.html", "problem_id": "p02885", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02885/input.txt", "sample_output_relpath": "derived/input_output/data/p02885/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02885/Lisp/s046204225.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s046204225", "user_id": "u608227593"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let ((a (read))\n (b (read)))\n (format t \"~A~%\" (max 0 (- a (* 2 b)))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThe window of Takahashi's room has a width of A. There are two curtains hung over the window, each of which has a horizontal length of B. (Vertically, the curtains are long enough to cover the whole window.)\n\nWe will close the window so as to minimize the total horizontal length of the uncovered part of the window.\nFind the total horizontal length of the uncovered parts of the window then.\n\nConstraints\n\n1 \\leq A \\leq 100\n\n1 \\leq B \\leq 100\n\nA and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the total horizontal length of the uncovered parts of the window.\n\nSample Input 1\n\n12 4\n\nSample Output 1\n\n4\n\nWe have a window with a horizontal length of 12, and two curtains, each of length 4, that cover both ends of the window, for example. The uncovered part has a horizontal length of 4.\n\nSample Input 2\n\n20 15\n\nSample Output 2\n\n0\n\nIf the window is completely covered, print 0.\n\nSample Input 3\n\n20 30\n\nSample Output 3\n\n0\n\nEach curtain may be longer than the window.", "sample_input": "12 4\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02885", "source_text": "Score : 100 points\n\nProblem Statement\n\nThe window of Takahashi's room has a width of A. There are two curtains hung over the window, each of which has a horizontal length of B. (Vertically, the curtains are long enough to cover the whole window.)\n\nWe will close the window so as to minimize the total horizontal length of the uncovered part of the window.\nFind the total horizontal length of the uncovered parts of the window then.\n\nConstraints\n\n1 \\leq A \\leq 100\n\n1 \\leq B \\leq 100\n\nA and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the total horizontal length of the uncovered parts of the window.\n\nSample Input 1\n\n12 4\n\nSample Output 1\n\n4\n\nWe have a window with a horizontal length of 12, and two curtains, each of length 4, that cover both ends of the window, for example. The uncovered part has a horizontal length of 4.\n\nSample Input 2\n\n20 15\n\nSample Output 2\n\n0\n\nIf the window is completely covered, print 0.\n\nSample Input 3\n\n20 30\n\nSample Output 3\n\n0\n\nEach curtain may be longer than the window.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 77, "cpu_time_ms": 194, "memory_kb": 12904}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s397120090", "group_id": "codeNet:p02888", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; 1-dimensional binary indexed tree on arbitrary commutative monoid\n;;;\n\n(defmacro define-bitree (name &key (operator '#'+) (identity 0) sum-type (order '#'<))\n \"OPERATOR := binary operator (comprising a commutative monoid)\nIDENTITY := object (identity element of the monoid)\nORDER := nil | strict comparison operator on the monoid\nSUM-TYPE := nil | type specifier\n\nDefines no structure; BIT is just a vector. This macro defines the three\nfunction: -UPDATE!, point-update function, -SUM, query function for\nprefix sum, and COERCE-TO-!, constructor. If ORDER is specified, this\nmacro in addition defines -BISECT-LEFT and -BISECT-RIGHT, the\nbisection functions for prefix sums. (Note that these functions work only when\nthe sequence of prefix sums (VECTOR[0], VECTOR[0]+VECTOR[1], ...) is monotone.)\n\nSUM-TYPE is used only for the type declaration: each sum\nVECTOR[i]+VECTOR[i+1]...+VECTOR[i+k] is declared to be this type. (The\nelement-type of vector itself doesn't need to be SUM-TYPE.)\"\n (let* ((name (string name))\n (fname-update (intern (format nil \"~A-UPDATE!\" name)))\n (fname-sum (intern (format nil \"~A-SUM\" name)))\n (fname-coerce (intern (format nil \"COERCE-TO-~A!\" name)))\n (fname-bisect-left (intern (format nil \"~A-BISECT-LEFT\" name)))\n (fname-bisect-right (intern (format nil \"~A-BISECT-RIGHT\" name))))\n `(progn\n (declaim (inline ,fname-update))\n (defun ,fname-update (bitree index delta)\n \"Destructively increments the vector: vector[INDEX] = vector[INDEX] +\nDELTA\"\n (let ((len (length bitree)))\n (do ((i index (logior i (+ i 1))))\n ((>= i len) bitree)\n (declare ((integer 0 #.most-positive-fixnum) i))\n (setf (aref bitree i)\n (funcall ,operator (aref bitree i) delta)))))\n\n (declaim (inline ,fname-sum))\n (defun ,fname-sum (bitree end)\n \"Returns the sum of the prefix: vector[0] + ... + vector[END-1].\"\n (declare ((integer 0 #.most-positive-fixnum) end))\n (let ((res ,identity))\n ,@(when sum-type `((declare (type ,sum-type res))))\n (do ((i (- end 1) (- (logand i (+ i 1)) 1)))\n ((< i 0) res)\n (declare ((integer -1 #.most-positive-fixnum) i))\n (setf res (funcall ,operator res (aref bitree i))))))\n\n (declaim (inline ,fname-coerce))\n (defun ,fname-coerce (vector)\n \"Destructively constructs BIT from VECTOR. (You will not need to call\nthis constructor if what you need is a `zero-filled' BIT because a vector filled\nwith the identity elements is a valid BIT as it is.)\"\n (loop with len = (length vector)\n for i below len\n for dest-i = (logior i (+ i 1))\n when (< dest-i len)\n do (setf (aref vector dest-i)\n (funcall ,operator (aref vector dest-i) (aref vector i)))\n finally (return vector)))\n\n ,@(when order\n `((declaim (inline ,fname-bisect-left))\n (defun ,fname-bisect-left (bitree value)\n \"Returns the smallest index that satisfies VECTOR[0]+ ... +\nVECTOR[index] >= VALUE. Returns the length of VECTOR if VECTOR[0]+\n... +VECTOR[length-1] < VALUE.\"\n (declare (vector bitree))\n (if (not (funcall ,order ,identity value))\n 0\n (let ((len (length bitree))\n (index+1 0)\n (cumul ,identity))\n (declare ((integer 0 #.most-positive-fixnum) index+1)\n ,@(when sum-type\n `((type ,sum-type cumul))))\n (do ((delta (ash 1 (- (integer-length len) 1))\n (ash delta -1)))\n ((zerop delta) index+1)\n (declare ((integer 0 #.most-positive-fixnum) delta))\n (let ((next-index (+ index+1 delta -1)))\n (when (< next-index len)\n (let ((next-cumul (funcall ,operator cumul (aref bitree next-index))))\n ,@(when sum-type\n `((declare (type ,sum-type next-cumul))))\n (when (funcall ,order next-cumul value)\n (setf cumul next-cumul)\n (incf index+1 delta)))))))))\n (declaim (inline ,fname-bisect-right))\n (defun ,fname-bisect-right (bitree value)\n \"Returns the smallest index that satisfies VECTOR[0]+ ... +\nVECTOR[index] > VALUE. Returns the length of VECTOR if VECTOR[0]+\n... +VECTOR[length-1] <= VALUE.\"\n (declare (vector bitree))\n (if (funcall ,order value ,identity)\n 0\n (let ((len (length bitree))\n (index+1 0)\n (cumul ,identity))\n (declare ((integer 0 #.most-positive-fixnum) index+1)\n ,@(when sum-type\n `((type ,sum-type cumul))))\n (do ((delta (ash 1 (- (integer-length len) 1))\n (ash delta -1)))\n ((zerop delta) index+1)\n (declare ((integer 0 #.most-positive-fixnum) delta))\n (let ((next-index (+ index+1 delta -1)))\n (when (< next-index len)\n (let ((next-cumul (funcall ,operator cumul (aref bitree next-index))))\n ,@(when sum-type\n `((declare (type ,sum-type next-cumul))))\n (unless (funcall ,order value next-cumul)\n (setf cumul next-cumul)\n (incf index+1 delta))))))))))))))\n\n(define-bitree bitree\n :operator #'+\n :identity 0\n :sum-type fixnum\n :order #'<)\n\n;; Example: compute the number of inversions in a sequence\n;; (declaim (inline make-inverse-lookup-table))\n;; (defun make-inverse-lookup-table (vector &key (test #'eql))\n;; \"Assigns each value of the (usually sorted) VECTOR of length n to the integers\n;; 0, ..., n-1.\"\n;; (let ((table (make-hash-table :test test :size (length vector))))\n;; (dotimes (i (length vector) table)\n;; (setf (gethash (aref vector i) table) i))))\n\n;; (defun calc-inversion-number (vector &key (order #'<))\n;; (declare (vector vector))\n;; (let* ((len (length vector))\n;; (inv-lookup-table (make-inverse-lookup-table (sort (copy-seq vector) order)))\n;; (bitree (make-array len :element-type '(integer 0 #.most-positive-fixnum)))\n;; (inversion-number 0))\n;; (declare (integer inversion-number))\n;; (loop for j below len\n;; for element = (aref vector j)\n;; for compressed = (gethash element inv-lookup-table)\n;; for delta of-type integer = (- j (bitree-sum bitree (1+ compressed)))\n;; do (incf inversion-number delta)\n;; (bitree-update! bitree compressed 1))\n;; inversion-number))\n\n;; (progn\n;; (assert (= 3 (calc-inversion-number #(2 4 1 3 5))))\n;; (assert (zerop (calc-inversion-number #(0))))\n;; (assert (zerop (calc-inversion-number #())))\n;; (assert (zerop (calc-inversion-number #(1 2))))\n;; (assert (= 1 (calc-inversion-number #(2 1)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (ls (make-array n :element-type 'uint32))\n (cumuls (make-array 2001 :element-type 'uint32))\n (res 0))\n (dotimes (i n)\n (let ((l (read-fixnum)))\n (setf (aref ls i) l)\n (bitree-update! cumuls l 1)))\n (dotimes (i n)\n (let ((a (aref ls i)))\n (loop for j from (+ i 1) below n\n for b = (aref ls j)\n for a+b = (+ a b)\n for a-b+1 = (min a+b (+ 1 (max 0 (abs (- b a)))))\n do (bitree-update! cumuls a -1)\n (bitree-update! cumuls b -1)\n (let ((value (- (bitree-sum cumuls a+b)\n (bitree-sum cumuls a-b+1))))\n (incf res value)\n (bitree-update! cumuls a 1)\n (bitree-update! cumuls b 1)\n (dbg a b value a+b a-b+1)\n (incf res value)))))\n (assert (zerop (mod res 6)))\n (println (floor res 6c))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n3 4 2 1\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 1000 1\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\n218 786 704 233 645 728 389\n\"\n \"23\n\")))\n", "language": "Lisp", "metadata": {"date": 1571534386, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02888.html", "problem_id": "p02888", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02888/input.txt", "sample_output_relpath": "derived/input_output/data/p02888/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02888/Lisp/s397120090.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s397120090", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; 1-dimensional binary indexed tree on arbitrary commutative monoid\n;;;\n\n(defmacro define-bitree (name &key (operator '#'+) (identity 0) sum-type (order '#'<))\n \"OPERATOR := binary operator (comprising a commutative monoid)\nIDENTITY := object (identity element of the monoid)\nORDER := nil | strict comparison operator on the monoid\nSUM-TYPE := nil | type specifier\n\nDefines no structure; BIT is just a vector. This macro defines the three\nfunction: -UPDATE!, point-update function, -SUM, query function for\nprefix sum, and COERCE-TO-!, constructor. If ORDER is specified, this\nmacro in addition defines -BISECT-LEFT and -BISECT-RIGHT, the\nbisection functions for prefix sums. (Note that these functions work only when\nthe sequence of prefix sums (VECTOR[0], VECTOR[0]+VECTOR[1], ...) is monotone.)\n\nSUM-TYPE is used only for the type declaration: each sum\nVECTOR[i]+VECTOR[i+1]...+VECTOR[i+k] is declared to be this type. (The\nelement-type of vector itself doesn't need to be SUM-TYPE.)\"\n (let* ((name (string name))\n (fname-update (intern (format nil \"~A-UPDATE!\" name)))\n (fname-sum (intern (format nil \"~A-SUM\" name)))\n (fname-coerce (intern (format nil \"COERCE-TO-~A!\" name)))\n (fname-bisect-left (intern (format nil \"~A-BISECT-LEFT\" name)))\n (fname-bisect-right (intern (format nil \"~A-BISECT-RIGHT\" name))))\n `(progn\n (declaim (inline ,fname-update))\n (defun ,fname-update (bitree index delta)\n \"Destructively increments the vector: vector[INDEX] = vector[INDEX] +\nDELTA\"\n (let ((len (length bitree)))\n (do ((i index (logior i (+ i 1))))\n ((>= i len) bitree)\n (declare ((integer 0 #.most-positive-fixnum) i))\n (setf (aref bitree i)\n (funcall ,operator (aref bitree i) delta)))))\n\n (declaim (inline ,fname-sum))\n (defun ,fname-sum (bitree end)\n \"Returns the sum of the prefix: vector[0] + ... + vector[END-1].\"\n (declare ((integer 0 #.most-positive-fixnum) end))\n (let ((res ,identity))\n ,@(when sum-type `((declare (type ,sum-type res))))\n (do ((i (- end 1) (- (logand i (+ i 1)) 1)))\n ((< i 0) res)\n (declare ((integer -1 #.most-positive-fixnum) i))\n (setf res (funcall ,operator res (aref bitree i))))))\n\n (declaim (inline ,fname-coerce))\n (defun ,fname-coerce (vector)\n \"Destructively constructs BIT from VECTOR. (You will not need to call\nthis constructor if what you need is a `zero-filled' BIT because a vector filled\nwith the identity elements is a valid BIT as it is.)\"\n (loop with len = (length vector)\n for i below len\n for dest-i = (logior i (+ i 1))\n when (< dest-i len)\n do (setf (aref vector dest-i)\n (funcall ,operator (aref vector dest-i) (aref vector i)))\n finally (return vector)))\n\n ,@(when order\n `((declaim (inline ,fname-bisect-left))\n (defun ,fname-bisect-left (bitree value)\n \"Returns the smallest index that satisfies VECTOR[0]+ ... +\nVECTOR[index] >= VALUE. Returns the length of VECTOR if VECTOR[0]+\n... +VECTOR[length-1] < VALUE.\"\n (declare (vector bitree))\n (if (not (funcall ,order ,identity value))\n 0\n (let ((len (length bitree))\n (index+1 0)\n (cumul ,identity))\n (declare ((integer 0 #.most-positive-fixnum) index+1)\n ,@(when sum-type\n `((type ,sum-type cumul))))\n (do ((delta (ash 1 (- (integer-length len) 1))\n (ash delta -1)))\n ((zerop delta) index+1)\n (declare ((integer 0 #.most-positive-fixnum) delta))\n (let ((next-index (+ index+1 delta -1)))\n (when (< next-index len)\n (let ((next-cumul (funcall ,operator cumul (aref bitree next-index))))\n ,@(when sum-type\n `((declare (type ,sum-type next-cumul))))\n (when (funcall ,order next-cumul value)\n (setf cumul next-cumul)\n (incf index+1 delta)))))))))\n (declaim (inline ,fname-bisect-right))\n (defun ,fname-bisect-right (bitree value)\n \"Returns the smallest index that satisfies VECTOR[0]+ ... +\nVECTOR[index] > VALUE. Returns the length of VECTOR if VECTOR[0]+\n... +VECTOR[length-1] <= VALUE.\"\n (declare (vector bitree))\n (if (funcall ,order value ,identity)\n 0\n (let ((len (length bitree))\n (index+1 0)\n (cumul ,identity))\n (declare ((integer 0 #.most-positive-fixnum) index+1)\n ,@(when sum-type\n `((type ,sum-type cumul))))\n (do ((delta (ash 1 (- (integer-length len) 1))\n (ash delta -1)))\n ((zerop delta) index+1)\n (declare ((integer 0 #.most-positive-fixnum) delta))\n (let ((next-index (+ index+1 delta -1)))\n (when (< next-index len)\n (let ((next-cumul (funcall ,operator cumul (aref bitree next-index))))\n ,@(when sum-type\n `((declare (type ,sum-type next-cumul))))\n (unless (funcall ,order value next-cumul)\n (setf cumul next-cumul)\n (incf index+1 delta))))))))))))))\n\n(define-bitree bitree\n :operator #'+\n :identity 0\n :sum-type fixnum\n :order #'<)\n\n;; Example: compute the number of inversions in a sequence\n;; (declaim (inline make-inverse-lookup-table))\n;; (defun make-inverse-lookup-table (vector &key (test #'eql))\n;; \"Assigns each value of the (usually sorted) VECTOR of length n to the integers\n;; 0, ..., n-1.\"\n;; (let ((table (make-hash-table :test test :size (length vector))))\n;; (dotimes (i (length vector) table)\n;; (setf (gethash (aref vector i) table) i))))\n\n;; (defun calc-inversion-number (vector &key (order #'<))\n;; (declare (vector vector))\n;; (let* ((len (length vector))\n;; (inv-lookup-table (make-inverse-lookup-table (sort (copy-seq vector) order)))\n;; (bitree (make-array len :element-type '(integer 0 #.most-positive-fixnum)))\n;; (inversion-number 0))\n;; (declare (integer inversion-number))\n;; (loop for j below len\n;; for element = (aref vector j)\n;; for compressed = (gethash element inv-lookup-table)\n;; for delta of-type integer = (- j (bitree-sum bitree (1+ compressed)))\n;; do (incf inversion-number delta)\n;; (bitree-update! bitree compressed 1))\n;; inversion-number))\n\n;; (progn\n;; (assert (= 3 (calc-inversion-number #(2 4 1 3 5))))\n;; (assert (zerop (calc-inversion-number #(0))))\n;; (assert (zerop (calc-inversion-number #())))\n;; (assert (zerop (calc-inversion-number #(1 2))))\n;; (assert (= 1 (calc-inversion-number #(2 1)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (ls (make-array n :element-type 'uint32))\n (cumuls (make-array 2001 :element-type 'uint32))\n (res 0))\n (dotimes (i n)\n (let ((l (read-fixnum)))\n (setf (aref ls i) l)\n (bitree-update! cumuls l 1)))\n (dotimes (i n)\n (let ((a (aref ls i)))\n (loop for j from (+ i 1) below n\n for b = (aref ls j)\n for a+b = (+ a b)\n for a-b+1 = (min a+b (+ 1 (max 0 (abs (- b a)))))\n do (bitree-update! cumuls a -1)\n (bitree-update! cumuls b -1)\n (let ((value (- (bitree-sum cumuls a+b)\n (bitree-sum cumuls a-b+1))))\n (incf res value)\n (bitree-update! cumuls a 1)\n (bitree-update! cumuls b 1)\n (dbg a b value a+b a-b+1)\n (incf res value)))))\n (assert (zerop (mod res 6)))\n (println (floor res 6c))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n3 4 2 1\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 1000 1\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\n218 786 704 233 645 728 389\n\"\n \"23\n\")))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nTakahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.\n\nHe is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:\n\na < b + c\n\nb < c + a\n\nc < a + b\n\nHow many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq N \\leq 2 \\times 10^3\n\n1 \\leq L_i \\leq 10^3\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nL_1 L_2 ... L_N\n\nConstraints\n\nPrint the number of different triangles that can be formed.\n\nSample Input 1\n\n4\n3 4 2 1\n\nSample Output 1\n\n1\n\nOnly one triangle can be formed: the triangle formed by the first, second, and third sticks.\n\nSample Input 2\n\n3\n1 1000 1\n\nSample Output 2\n\n0\n\nNo triangles can be formed.\n\nSample Input 3\n\n7\n218 786 704 233 645 728 389\n\nSample Output 3\n\n23", "sample_input": "4\n3 4 2 1\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02888", "source_text": "Score : 400 points\n\nProblem Statement\n\nTakahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.\n\nHe is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:\n\na < b + c\n\nb < c + a\n\nc < a + b\n\nHow many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq N \\leq 2 \\times 10^3\n\n1 \\leq L_i \\leq 10^3\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nL_1 L_2 ... L_N\n\nConstraints\n\nPrint the number of different triangles that can be formed.\n\nSample Input 1\n\n4\n3 4 2 1\n\nSample Output 1\n\n1\n\nOnly one triangle can be formed: the triangle formed by the first, second, and third sticks.\n\nSample Input 2\n\n3\n1 1000 1\n\nSample Output 2\n\n0\n\nNo triangles can be formed.\n\nSample Input 3\n\n7\n218 786 704 233 645 728 389\n\nSample Output 3\n\n23", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 13126, "cpu_time_ms": 551, "memory_kb": 38120}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s985377468", "group_id": "codeNet:p02890", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; Should we do this with UNWIND-PROTECT?\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline binsort!))\n(defun binsort! (vector range-max)\n (declare ((mod #.array-total-size-limit) range-max))\n (let ((counts (make-array (1+ range-max) :element-type 'uint31 :initial-element 0)))\n (declare (dynamic-extent counts))\n (sb-int:dovector (e vector)\n (incf (aref counts e)))\n (let ((pos 0))\n (declare ((integer 0 #.most-positive-fixnum) pos))\n (loop for x to range-max\n do (loop repeat (aref counts x)\n do (setf (aref vector pos) x)\n (incf pos))))\n vector))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (cs (make-array n :element-type 'uint31))\n (cumuls (make-array (+ n 1) :element-type 'uint31))\n (fs (make-array (+ n 1) :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n))\n (dotimes (i n)\n (let ((a (read-fixnum)))\n (incf (aref cs (- a 1)))))\n (binsort! cs n)\n (dotimes (i n)\n (setf (aref cumuls (+ i 1))\n (+ (aref cumuls i) (aref cs i))))\n (let ((pos (- n 1)))\n (declare (int32 pos))\n (loop for x from n downto 1\n do (loop (when (= -1 pos)\n (return))\n (when (< (aref cs pos) x)\n (return))\n (decf pos))\n (setf (aref fs x)\n (+ (floor (aref cumuls (+ pos 1)) x)\n (- n (+ pos 1))))))\n (let ((pos n))\n (with-buffered-stdout\n (loop for k from 1 to n\n do (loop (when (zerop pos)\n (return))\n (when (>= (aref fs pos) k)\n (return))\n (decf pos))\n (println pos))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1571614220, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02890.html", "problem_id": "p02890", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02890/input.txt", "sample_output_relpath": "derived/input_output/data/p02890/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02890/Lisp/s985377468.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s985377468", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n1\n0\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; Should we do this with UNWIND-PROTECT?\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline binsort!))\n(defun binsort! (vector range-max)\n (declare ((mod #.array-total-size-limit) range-max))\n (let ((counts (make-array (1+ range-max) :element-type 'uint31 :initial-element 0)))\n (declare (dynamic-extent counts))\n (sb-int:dovector (e vector)\n (incf (aref counts e)))\n (let ((pos 0))\n (declare ((integer 0 #.most-positive-fixnum) pos))\n (loop for x to range-max\n do (loop repeat (aref counts x)\n do (setf (aref vector pos) x)\n (incf pos))))\n vector))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (cs (make-array n :element-type 'uint31))\n (cumuls (make-array (+ n 1) :element-type 'uint31))\n (fs (make-array (+ n 1) :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n))\n (dotimes (i n)\n (let ((a (read-fixnum)))\n (incf (aref cs (- a 1)))))\n (binsort! cs n)\n (dotimes (i n)\n (setf (aref cumuls (+ i 1))\n (+ (aref cumuls i) (aref cs i))))\n (let ((pos (- n 1)))\n (declare (int32 pos))\n (loop for x from n downto 1\n do (loop (when (= -1 pos)\n (return))\n (when (< (aref cs pos) x)\n (return))\n (decf pos))\n (setf (aref fs x)\n (+ (floor (aref cumuls (+ pos 1)) x)\n (- n (+ pos 1))))))\n (let ((pos n))\n (with-buffered-stdout\n (loop for k from 1 to n\n do (loop (when (zerop pos)\n (return))\n (when (>= (aref fs pos) k)\n (return))\n (decf pos))\n (println pos))))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nTakahashi has N cards. The i-th of these cards has an integer A_i written on it.\n\nTakahashi will choose an integer K, and then repeat the following operation some number of times:\n\nChoose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)\n\nFor each K = 1,2, \\ldots, N, find the maximum number of times Takahashi can do the operation.\n\nConstraints\n\n1 \\le N \\le 3 \\times 10^5\n\n1 \\le A_i \\le N\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 \\ldots A_N\n\nOutput\n\nPrint N integers.\nThe t-th (1 \\le t \\le N) of them should be the answer for the case K=t.\n\nSample Input 1\n\n3\n2 1 2\n\nSample Output 1\n\n3\n1\n0\n\nFor K = 1, we can do the operation as follows:\n\nChoose the first card to eat.\n\nChoose the second card to eat.\n\nChoose the third card to eat.\n\nFor K = 2, we can do the operation as follows:\n\nChoose the first and second cards to eat.\n\nFor K = 3, we cannot do the operation at all. Note that we cannot choose the first and third cards at the same time.\n\nSample Input 2\n\n5\n1 2 3 4 5\n\nSample Output 2\n\n5\n2\n1\n1\n1\n\nSample Input 3\n\n4\n1 3 3 3\n\nSample Output 3\n\n4\n1\n0\n0", "sample_input": "3\n2 1 2\n"}, "reference_outputs": ["3\n1\n0\n"], "source_document_id": "p02890", "source_text": "Score : 600 points\n\nProblem Statement\n\nTakahashi has N cards. The i-th of these cards has an integer A_i written on it.\n\nTakahashi will choose an integer K, and then repeat the following operation some number of times:\n\nChoose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)\n\nFor each K = 1,2, \\ldots, N, find the maximum number of times Takahashi can do the operation.\n\nConstraints\n\n1 \\le N \\le 3 \\times 10^5\n\n1 \\le A_i \\le N\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 \\ldots A_N\n\nOutput\n\nPrint N integers.\nThe t-th (1 \\le t \\le N) of them should be the answer for the case K=t.\n\nSample Input 1\n\n3\n2 1 2\n\nSample Output 1\n\n3\n1\n0\n\nFor K = 1, we can do the operation as follows:\n\nChoose the first card to eat.\n\nChoose the second card to eat.\n\nChoose the third card to eat.\n\nFor K = 2, we can do the operation as follows:\n\nChoose the first and second cards to eat.\n\nFor K = 3, we cannot do the operation at all. Note that we cannot choose the first and third cards at the same time.\n\nSample Input 2\n\n5\n1 2 3 4 5\n\nSample Output 2\n\n5\n2\n1\n1\n1\n\nSample Input 3\n\n4\n1 3 3 3\n\nSample Output 3\n\n4\n1\n0\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4671, "cpu_time_ms": 205, "memory_kb": 25960}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s892845314", "group_id": "codeNet:p02890", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; Should we do this with UNWIND-PROTECT?\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (cs (make-array n :element-type 'uint31))\n (cumuls (make-array (+ n 1) :element-type 'uint31))\n (fs (make-array (+ n 1) :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n))\n (dotimes (i n)\n (let ((a (read-fixnum)))\n (incf (aref cs (- a 1)))))\n (setf cs (sort cs #'<))\n (dotimes (i n)\n (setf (aref cumuls (+ i 1))\n (+ (aref cumuls i) (aref cs i))))\n (let ((pos (- n 1)))\n (declare (int32 pos))\n (loop for x from n downto 1\n do (loop (when (= -1 pos)\n (return))\n (when (< (aref cs pos) x)\n (return))\n (decf pos))\n (let ((value (+ (* x (- n (+ pos 1)))\n (aref cumuls (+ pos 1)))))\n (setf (aref fs x)\n (floor value x)))))\n (let ((pos n))\n (with-buffered-stdout\n (loop for k from 1 to n\n do (loop (when (zerop pos)\n (return))\n (when (>= (aref fs pos) k)\n (return))\n (decf pos))\n (println pos))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n2 1 2\n\"\n \"3\n1\n0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n1 2 3 4 5\n\"\n \"5\n2\n1\n1\n1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 3 3 3\n\"\n \"4\n1\n0\n0\n\")))\n", "language": "Lisp", "metadata": {"date": 1571606473, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02890.html", "problem_id": "p02890", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02890/input.txt", "sample_output_relpath": "derived/input_output/data/p02890/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02890/Lisp/s892845314.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s892845314", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n1\n0\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; Should we do this with UNWIND-PROTECT?\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (cs (make-array n :element-type 'uint31))\n (cumuls (make-array (+ n 1) :element-type 'uint31))\n (fs (make-array (+ n 1) :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n))\n (dotimes (i n)\n (let ((a (read-fixnum)))\n (incf (aref cs (- a 1)))))\n (setf cs (sort cs #'<))\n (dotimes (i n)\n (setf (aref cumuls (+ i 1))\n (+ (aref cumuls i) (aref cs i))))\n (let ((pos (- n 1)))\n (declare (int32 pos))\n (loop for x from n downto 1\n do (loop (when (= -1 pos)\n (return))\n (when (< (aref cs pos) x)\n (return))\n (decf pos))\n (let ((value (+ (* x (- n (+ pos 1)))\n (aref cumuls (+ pos 1)))))\n (setf (aref fs x)\n (floor value x)))))\n (let ((pos n))\n (with-buffered-stdout\n (loop for k from 1 to n\n do (loop (when (zerop pos)\n (return))\n (when (>= (aref fs pos) k)\n (return))\n (decf pos))\n (println pos))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n2 1 2\n\"\n \"3\n1\n0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n1 2 3 4 5\n\"\n \"5\n2\n1\n1\n1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 3 3 3\n\"\n \"4\n1\n0\n0\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nTakahashi has N cards. The i-th of these cards has an integer A_i written on it.\n\nTakahashi will choose an integer K, and then repeat the following operation some number of times:\n\nChoose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)\n\nFor each K = 1,2, \\ldots, N, find the maximum number of times Takahashi can do the operation.\n\nConstraints\n\n1 \\le N \\le 3 \\times 10^5\n\n1 \\le A_i \\le N\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 \\ldots A_N\n\nOutput\n\nPrint N integers.\nThe t-th (1 \\le t \\le N) of them should be the answer for the case K=t.\n\nSample Input 1\n\n3\n2 1 2\n\nSample Output 1\n\n3\n1\n0\n\nFor K = 1, we can do the operation as follows:\n\nChoose the first card to eat.\n\nChoose the second card to eat.\n\nChoose the third card to eat.\n\nFor K = 2, we can do the operation as follows:\n\nChoose the first and second cards to eat.\n\nFor K = 3, we cannot do the operation at all. Note that we cannot choose the first and third cards at the same time.\n\nSample Input 2\n\n5\n1 2 3 4 5\n\nSample Output 2\n\n5\n2\n1\n1\n1\n\nSample Input 3\n\n4\n1 3 3 3\n\nSample Output 3\n\n4\n1\n0\n0", "sample_input": "3\n2 1 2\n"}, "reference_outputs": ["3\n1\n0\n"], "source_document_id": "p02890", "source_text": "Score : 600 points\n\nProblem Statement\n\nTakahashi has N cards. The i-th of these cards has an integer A_i written on it.\n\nTakahashi will choose an integer K, and then repeat the following operation some number of times:\n\nChoose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)\n\nFor each K = 1,2, \\ldots, N, find the maximum number of times Takahashi can do the operation.\n\nConstraints\n\n1 \\le N \\le 3 \\times 10^5\n\n1 \\le A_i \\le N\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 \\ldots A_N\n\nOutput\n\nPrint N integers.\nThe t-th (1 \\le t \\le N) of them should be the answer for the case K=t.\n\nSample Input 1\n\n3\n2 1 2\n\nSample Output 1\n\n3\n1\n0\n\nFor K = 1, we can do the operation as follows:\n\nChoose the first card to eat.\n\nChoose the second card to eat.\n\nChoose the third card to eat.\n\nFor K = 2, we can do the operation as follows:\n\nChoose the first and second cards to eat.\n\nFor K = 3, we cannot do the operation at all. Note that we cannot choose the first and third cards at the same time.\n\nSample Input 2\n\n5\n1 2 3 4 5\n\nSample Output 2\n\n5\n2\n1\n1\n1\n\nSample Input 3\n\n4\n1 3 3 3\n\nSample Output 3\n\n4\n1\n0\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6405, "cpu_time_ms": 264, "memory_kb": 33124}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s247285578", "group_id": "codeNet:p02897", "input_text": "(defun f(n)\n (if (oddp n)\n (/ (length (loop for i from 1 to n when (oddp i) collect i)) n)\n 0.5))\n(let ((line (read-line nil nil)))\n (format t \"~F\" (f (parse-integer line))))\n", "language": "Lisp", "metadata": {"date": 1569719208, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02897.html", "problem_id": "p02897", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02897/input.txt", "sample_output_relpath": "derived/input_output/data/p02897/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02897/Lisp/s247285578.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s247285578", "user_id": "u254205055"}, "prompt_components": {"gold_output": "0.5000000000\n", "input_to_evaluate": "(defun f(n)\n (if (oddp n)\n (/ (length (loop for i from 1 to n when (oddp i) collect i)) n)\n 0.5))\n(let ((line (read-line nil nil)))\n (format t \"~F\" (f (parse-integer line))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nGiven is an integer N.\n\nTakahashi chooses an integer a from the positive integers not greater than N with equal probability.\n\nFind the probability that a is odd.\n\nConstraints\n\n1 \\leq N \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the probability that a is odd.\nYour output will be considered correct when its absolute or relative error from the judge's output is at most 10^{-6}.\n\nSample Input 1\n\n4\n\nSample Output 1\n\n0.5000000000\n\nThere are four positive integers not greater than 4: 1, 2, 3, and 4. Among them, we have two odd numbers: 1 and 3. Thus, the answer is \\frac{2}{4} = 0.5.\n\nSample Input 2\n\n5\n\nSample Output 2\n\n0.6000000000\n\nSample Input 3\n\n1\n\nSample Output 3\n\n1.0000000000", "sample_input": "4\n"}, "reference_outputs": ["0.5000000000\n"], "source_document_id": "p02897", "source_text": "Score : 100 points\n\nProblem Statement\n\nGiven is an integer N.\n\nTakahashi chooses an integer a from the positive integers not greater than N with equal probability.\n\nFind the probability that a is odd.\n\nConstraints\n\n1 \\leq N \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the probability that a is odd.\nYour output will be considered correct when its absolute or relative error from the judge's output is at most 10^{-6}.\n\nSample Input 1\n\n4\n\nSample Output 1\n\n0.5000000000\n\nThere are four positive integers not greater than 4: 1, 2, 3, and 4. Among them, we have two odd numbers: 1 and 3. Thus, the answer is \\frac{2}{4} = 0.5.\n\nSample Input 2\n\n5\n\nSample Output 2\n\n0.6000000000\n\nSample Input 3\n\n1\n\nSample Output 3\n\n1.0000000000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 183, "cpu_time_ms": 116, "memory_kb": 13540}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s574004571", "group_id": "codeNet:p02898", "input_text": "(defun takai ()\n (let ((n (read))\n (k (read))\n (cnt 0))\n (dotimes (i n)\n (if (<= k (read)) (incf cnt)))\n (format t \"~a\" cnt)))\n\n(takai)", "language": "Lisp", "metadata": {"date": 1569720609, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02898.html", "problem_id": "p02898", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02898/input.txt", "sample_output_relpath": "derived/input_output/data/p02898/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02898/Lisp/s574004571.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s574004571", "user_id": "u845695466"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun takai ()\n (let ((n (read))\n (k (read))\n (cnt 0))\n (dotimes (i n)\n (if (<= k (read)) (incf cnt)))\n (format t \"~a\" cnt)))\n\n(takai)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nN friends of Takahashi has come to a theme park.\n\nTo ride the most popular roller coaster in the park, you must be at least K centimeters tall.\n\nThe i-th friend is h_i centimeters tall.\n\nHow many of the Takahashi's friends can ride the roller coaster?\n\nConstraints\n\n1 \\le N \\le 10^5\n\n1 \\le K \\le 500\n\n1 \\le h_i \\le 500\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nh_1 h_2 \\ldots h_N\n\nOutput\n\nPrint the number of people among the Takahashi's friends who can ride the roller coaster.\n\nSample Input 1\n\n4 150\n150 140 100 200\n\nSample Output 1\n\n2\n\nTwo of them can ride the roller coaster: the first and fourth friends.\n\nSample Input 2\n\n1 500\n499\n\nSample Output 2\n\n0\n\nSample Input 3\n\n5 1\n100 200 300 400 500\n\nSample Output 3\n\n5", "sample_input": "4 150\n150 140 100 200\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02898", "source_text": "Score : 200 points\n\nProblem Statement\n\nN friends of Takahashi has come to a theme park.\n\nTo ride the most popular roller coaster in the park, you must be at least K centimeters tall.\n\nThe i-th friend is h_i centimeters tall.\n\nHow many of the Takahashi's friends can ride the roller coaster?\n\nConstraints\n\n1 \\le N \\le 10^5\n\n1 \\le K \\le 500\n\n1 \\le h_i \\le 500\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nh_1 h_2 \\ldots h_N\n\nOutput\n\nPrint the number of people among the Takahashi's friends who can ride the roller coaster.\n\nSample Input 1\n\n4 150\n150 140 100 200\n\nSample Output 1\n\n2\n\nTwo of them can ride the roller coaster: the first and fourth friends.\n\nSample Input 2\n\n1 500\n499\n\nSample Output 2\n\n0\n\nSample Input 3\n\n5 1\n100 200 300 400 500\n\nSample Output 3\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 161, "cpu_time_ms": 156, "memory_kb": 57704}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s079126660", "group_id": "codeNet:p02899", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; Should we do this with UNWIND-PROTECT?\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare (inline sort)\n #.OPT)\n (let* ((n (read))\n (data (make-array n :element-type '(cons uint32 uint32)))\n (init t))\n (loop for i below n\n for a = (read-fixnum)\n do (setf (aref data i) (cons a (+ i 1))))\n (setf data (sort data (lambda (x y) (< (the uint32 x) (the uint32 y))) :key #'car))\n (with-buffered-stdout\n (loop for (a . idx) across data\n do (if init\n (setq init nil)\n (write-char #\\ ))\n (princ idx))\n (terpri))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1569725035, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02899.html", "problem_id": "p02899", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02899/input.txt", "sample_output_relpath": "derived/input_output/data/p02899/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02899/Lisp/s079126660.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s079126660", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3 1 2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; Should we do this with UNWIND-PROTECT?\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare (inline sort)\n #.OPT)\n (let* ((n (read))\n (data (make-array n :element-type '(cons uint32 uint32)))\n (init t))\n (loop for i below n\n for a = (read-fixnum)\n do (setf (aref data i) (cons a (+ i 1))))\n (setf data (sort data (lambda (x y) (< (the uint32 x) (the uint32 y))) :key #'car))\n (with-buffered-stdout\n (loop for (a . idx) across data\n do (if init\n (setq init nil)\n (write-char #\\ ))\n (princ idx))\n (terpri))))\n\n#-swank (main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi is a teacher responsible for a class of N students.\n\nThe students are given distinct student numbers from 1 to N.\n\nToday, all the students entered the classroom at different times.\n\nAccording to Takahashi's record, there were A_i students in the classroom when student number i entered the classroom (including student number i).\n\nFrom these records, reconstruct the order in which the students entered the classroom.\n\nConstraints\n\n1 \\le N \\le 10^5\n\n1 \\le A_i \\le N\n\nA_i \\neq A_j (i \\neq j)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 \\ldots A_N\n\nOutput\n\nPrint the student numbers of the students in the order the students entered the classroom.\n\nSample Input 1\n\n3\n2 3 1\n\nSample Output 1\n\n3 1 2\n\nFirst, student number 3 entered the classroom.\n\nThen, student number 1 entered the classroom.\n\nFinally, student number 2 entered the classroom.\n\nSample Input 2\n\n5\n1 2 3 4 5\n\nSample Output 2\n\n1 2 3 4 5\n\nSample Input 3\n\n8\n8 2 7 3 4 5 6 1\n\nSample Output 3\n\n8 2 4 5 6 7 3 1", "sample_input": "3\n2 3 1\n"}, "reference_outputs": ["3 1 2\n"], "source_document_id": "p02899", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi is a teacher responsible for a class of N students.\n\nThe students are given distinct student numbers from 1 to N.\n\nToday, all the students entered the classroom at different times.\n\nAccording to Takahashi's record, there were A_i students in the classroom when student number i entered the classroom (including student number i).\n\nFrom these records, reconstruct the order in which the students entered the classroom.\n\nConstraints\n\n1 \\le N \\le 10^5\n\n1 \\le A_i \\le N\n\nA_i \\neq A_j (i \\neq j)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 \\ldots A_N\n\nOutput\n\nPrint the student numbers of the students in the order the students entered the classroom.\n\nSample Input 1\n\n3\n2 3 1\n\nSample Output 1\n\n3 1 2\n\nFirst, student number 3 entered the classroom.\n\nThen, student number 1 entered the classroom.\n\nFinally, student number 2 entered the classroom.\n\nSample Input 2\n\n5\n1 2 3 4 5\n\nSample Output 2\n\n1 2 3 4 5\n\nSample Input 3\n\n8\n8 2 7 3 4 5 6 1\n\nSample Output 3\n\n8 2 4 5 6 7 3 1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3490, "cpu_time_ms": 235, "memory_kb": 28644}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s527504929", "group_id": "codeNet:p02901", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline zeta-subtransform!))\n(defun zeta-subtransform! (vector &optional (plus #'+))\n (declare (vector vector))\n (let* ((n (length vector))\n ;; cardinality of the underlying set\n (card (- (integer-length n) 1)))\n (assert (= 1 (logcount n)))\n (dotimes (i card)\n (let ((mask (ash 1 i)))\n (dotimes (j n)\n (unless (zerop (logand j mask))\n (setf (aref vector j)\n (funcall plus\n (aref vector j)\n (aref vector (logxor j mask))))))))\n vector))\n\n(declaim (inline zeta-supertransform!))\n(defun zeta-supertransform! (vector &optional (plus #'+))\n (declare (vector vector))\n (let* ((n (length vector))\n (card (- (integer-length n) 1)))\n (assert (= 1 (logcount n)))\n (dotimes (i card)\n (let ((mask (ash 1 i)))\n (dotimes (j n)\n (when (zerop (logand j mask))\n (setf (aref vector j)\n (funcall plus\n (aref vector j)\n (aref vector (logior j mask))))))))\n vector))\n\n(declaim (inline moebius-subtransform!))\n(defun moebius-subtransform! (vector &optional (minus #'-))\n (declare (vector vector))\n (let* ((n (length vector))\n (card (- (integer-length n) 1)))\n (assert (= 1 (logcount n)))\n (dotimes (i card)\n (let ((mask (ash 1 i)))\n (dotimes (j n)\n (unless (zerop (logand j mask))\n (setf (aref vector j)\n (funcall minus\n (aref vector j)\n (aref vector (logxor j mask))))))))\n vector))\n\n(declaim (inline moebius-supertransform!))\n(defun moebius-supertransform! (vector &optional (minus #'+))\n (declare (vector vector))\n (let* ((n (length vector))\n (card (- (integer-length n) 1)))\n (assert (= 1 (logcount n)))\n (dotimes (i card)\n (let ((mask (ash 1 i)))\n (dotimes (j n)\n (when (zerop (logand j mask))\n (setf (aref vector j)\n (funcall minus\n (aref vector j)\n (aref vector (logior j mask))))))))\n vector))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-modify-macro minf (new-value) min)\n(defconstant +inf+ #xffffffff)\n\n(defun main ()\n ;; (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (costs (make-array (expt 2 n) :element-type 'uint32 :initial-element +inf+))\n (dp (make-array (expt 2 n) :element-type 'uint32 :initial-element +inf+)))\n (declare ((integer 1 12) n)\n (uint32 m))\n (dotimes (i m)\n (let ((a (read-fixnum))\n (b (read-fixnum))\n (bits 0))\n (declare (uint32 bits))\n (dotimes (j b)\n (let ((c (- (read-fixnum) 1)))\n (declare ((mod 12) c))\n (setf (ldb (byte 1 c) bits) 1)))\n (setf (aref costs bits) a)))\n (setf (aref costs 0) 0)\n (zeta-supertransform! costs #'min)\n #>costs\n (dotimes (bits (expt 2 n))\n (let ((res (aref costs bits)))\n (declare (uint32 res))\n (do ((subset bits (logand (- subset 1) bits)))\n ((zerop subset))\n (let ((dif (logxor bits subset)))\n (minf res (+ (aref dp subset) (aref costs dif)))))\n (setf (aref dp bits) res)))\n (let ((res (aref dp (- (expt 2 n) 1))))\n (println\n (if (= res +inf+)\n -1\n res)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1569745183, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02901.html", "problem_id": "p02901", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02901/input.txt", "sample_output_relpath": "derived/input_output/data/p02901/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02901/Lisp/s527504929.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s527504929", "user_id": "u352600849"}, "prompt_components": {"gold_output": "25\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline zeta-subtransform!))\n(defun zeta-subtransform! (vector &optional (plus #'+))\n (declare (vector vector))\n (let* ((n (length vector))\n ;; cardinality of the underlying set\n (card (- (integer-length n) 1)))\n (assert (= 1 (logcount n)))\n (dotimes (i card)\n (let ((mask (ash 1 i)))\n (dotimes (j n)\n (unless (zerop (logand j mask))\n (setf (aref vector j)\n (funcall plus\n (aref vector j)\n (aref vector (logxor j mask))))))))\n vector))\n\n(declaim (inline zeta-supertransform!))\n(defun zeta-supertransform! (vector &optional (plus #'+))\n (declare (vector vector))\n (let* ((n (length vector))\n (card (- (integer-length n) 1)))\n (assert (= 1 (logcount n)))\n (dotimes (i card)\n (let ((mask (ash 1 i)))\n (dotimes (j n)\n (when (zerop (logand j mask))\n (setf (aref vector j)\n (funcall plus\n (aref vector j)\n (aref vector (logior j mask))))))))\n vector))\n\n(declaim (inline moebius-subtransform!))\n(defun moebius-subtransform! (vector &optional (minus #'-))\n (declare (vector vector))\n (let* ((n (length vector))\n (card (- (integer-length n) 1)))\n (assert (= 1 (logcount n)))\n (dotimes (i card)\n (let ((mask (ash 1 i)))\n (dotimes (j n)\n (unless (zerop (logand j mask))\n (setf (aref vector j)\n (funcall minus\n (aref vector j)\n (aref vector (logxor j mask))))))))\n vector))\n\n(declaim (inline moebius-supertransform!))\n(defun moebius-supertransform! (vector &optional (minus #'+))\n (declare (vector vector))\n (let* ((n (length vector))\n (card (- (integer-length n) 1)))\n (assert (= 1 (logcount n)))\n (dotimes (i card)\n (let ((mask (ash 1 i)))\n (dotimes (j n)\n (when (zerop (logand j mask))\n (setf (aref vector j)\n (funcall minus\n (aref vector j)\n (aref vector (logior j mask))))))))\n vector))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-modify-macro minf (new-value) min)\n(defconstant +inf+ #xffffffff)\n\n(defun main ()\n ;; (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (costs (make-array (expt 2 n) :element-type 'uint32 :initial-element +inf+))\n (dp (make-array (expt 2 n) :element-type 'uint32 :initial-element +inf+)))\n (declare ((integer 1 12) n)\n (uint32 m))\n (dotimes (i m)\n (let ((a (read-fixnum))\n (b (read-fixnum))\n (bits 0))\n (declare (uint32 bits))\n (dotimes (j b)\n (let ((c (- (read-fixnum) 1)))\n (declare ((mod 12) c))\n (setf (ldb (byte 1 c) bits) 1)))\n (setf (aref costs bits) a)))\n (setf (aref costs 0) 0)\n (zeta-supertransform! costs #'min)\n #>costs\n (dotimes (bits (expt 2 n))\n (let ((res (aref costs bits)))\n (declare (uint32 res))\n (do ((subset bits (logand (- subset 1) bits)))\n ((zerop subset))\n (let ((dif (logxor bits subset)))\n (minf res (+ (aref dp subset) (aref costs dif)))))\n (setf (aref dp bits) res)))\n (let ((res (aref dp (- (expt 2 n) 1))))\n (println\n (if (= res +inf+)\n -1\n res)))))\n\n#-swank (main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nWe have N locked treasure boxes, numbered 1 to N.\n\nA shop sells M keys. The i-th key is sold for a_i yen (the currency of Japan), and it can unlock b_i of the boxes: Box c_{i1}, c_{i2}, ..., c_{i{b_i}}. Each key purchased can be used any number of times.\n\nFind the minimum cost required to unlock all the treasure boxes. If it is impossible to unlock all of them, print -1.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 12\n\n1 \\leq M \\leq 10^3\n\n1 \\leq a_i \\leq 10^5\n\n1 \\leq b_i \\leq N\n\n1 \\leq c_{i1} < c_{i2} < ... < c_{i{b_i}} \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\nc_{11} c_{12} ... c_{1{b_1}}\n:\na_M b_M\nc_{M1} c_{M2} ... c_{M{b_M}}\n\nOutput\n\nPrint the minimum cost required to unlock all the treasure boxes.\nIf it is impossible to unlock all of them, print -1.\n\nSample Input 1\n\n2 3\n10 1\n1\n15 1\n2\n30 2\n1 2\n\nSample Output 1\n\n25\n\nWe can unlock all the boxes by purchasing the first and second keys, at the cost of 25 yen, which is the minimum cost required.\n\nSample Input 2\n\n12 1\n100000 1\n2\n\nSample Output 2\n\n-1\n\nWe cannot unlock all the boxes.\n\nSample Input 3\n\n4 6\n67786 3\n1 3 4\n3497 1\n2\n44908 3\n2 3 4\n2156 3\n2 3 4\n26230 1\n2\n86918 1\n3\n\nSample Output 3\n\n69942", "sample_input": "2 3\n10 1\n1\n15 1\n2\n30 2\n1 2\n"}, "reference_outputs": ["25\n"], "source_document_id": "p02901", "source_text": "Score : 500 points\n\nProblem Statement\n\nWe have N locked treasure boxes, numbered 1 to N.\n\nA shop sells M keys. The i-th key is sold for a_i yen (the currency of Japan), and it can unlock b_i of the boxes: Box c_{i1}, c_{i2}, ..., c_{i{b_i}}. Each key purchased can be used any number of times.\n\nFind the minimum cost required to unlock all the treasure boxes. If it is impossible to unlock all of them, print -1.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 12\n\n1 \\leq M \\leq 10^3\n\n1 \\leq a_i \\leq 10^5\n\n1 \\leq b_i \\leq N\n\n1 \\leq c_{i1} < c_{i2} < ... < c_{i{b_i}} \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\nc_{11} c_{12} ... c_{1{b_1}}\n:\na_M b_M\nc_{M1} c_{M2} ... c_{M{b_M}}\n\nOutput\n\nPrint the minimum cost required to unlock all the treasure boxes.\nIf it is impossible to unlock all of them, print -1.\n\nSample Input 1\n\n2 3\n10 1\n1\n15 1\n2\n30 2\n1 2\n\nSample Output 1\n\n25\n\nWe can unlock all the boxes by purchasing the first and second keys, at the cost of 25 yen, which is the minimum cost required.\n\nSample Input 2\n\n12 1\n100000 1\n2\n\nSample Output 2\n\n-1\n\nWe cannot unlock all the boxes.\n\nSample Input 3\n\n4 6\n67786 3\n1 3 4\n3497 1\n2\n44908 3\n2 3 4\n2156 3\n2 3 4\n26230 1\n2\n86918 1\n3\n\nSample Output 3\n\n69942", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5851, "cpu_time_ms": 239, "memory_kb": 31204}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s021653604", "group_id": "codeNet:p02902", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Binary heap\n;;;\n\n(define-condition heap-empty-error (simple-error)\n ((heap :initarg :heap :reader heap-empty-error-heap))\n (:report\n (lambda (condition stream)\n (format stream \"Attempted to pop empty heap ~W\" (heap-empty-error-heap condition)))))\n\n(define-condition heap-full-error (simple-error)\n ((heap :initarg :heap :reader heap-full-error-heap)\n (item :initarg :item :reader heap-full-error-item))\n (:report\n (lambda (condition stream)\n (format stream \"Attempted to push item ~W to full heap ~W\"\n (heap-full-error-item condition)\n (heap-full-error-heap condition)))))\n\n(defmacro define-binary-heap (name &key (order '#'>) (element-type 'fixnum))\n \"Defines the binary heap specialized for the given order and the element\ntype. This macro defines a structure of the name NAME and relevant functions:\nMAKE-, -PUSH, -POP, -REINITIALIZE, -EMPTY-P,\n-COUNT, and -PEEK.\"\n (check-type name symbol)\n (let* ((string-name (string name))\n (fname-push (intern (format nil \"~A-PUSH\" string-name)))\n (fname-pop (intern (format nil \"~A-POP\" string-name)))\n (fname-reinitialize (intern (format nil \"~A-REINITIALIZE\" string-name)))\n (fname-empty-p (intern (format nil \"~A-EMPTY-P\" string-name)))\n (fname-count (intern (format nil \"~A-COUNT\" string-name)))\n (fname-peek (intern (format nil \"~A-PEEK\" string-name)))\n (fname-make (intern (format nil \"MAKE-~A\" string-name)))\n (acc-position (intern (format nil \"~A-POSITION\" string-name)))\n (acc-data (intern (format nil \"~A-DATA\" string-name))))\n `(progn\n (defstruct (,name\n (:constructor ,fname-make\n (size\n &aux (data ,(if (eql element-type '*)\n `(make-array (1+ size))\n `(make-array (1+ size) :element-type ',element-type))))))\n (data #() :type (simple-array ,element-type (*)) :read-only t)\n (position 1 :type (integer 1 #.most-positive-fixnum)))\n\n (declaim #+sbcl (sb-ext:maybe-inline ,fname-push))\n (defun ,fname-push (obj heap)\n \"Adds OBJ to the end of HEAP.\"\n (declare (optimize (speed 3))\n (type ,name heap))\n (symbol-macrolet ((position (,acc-position heap)))\n (let ((data (,acc-data heap)))\n (declare ((simple-array ,element-type (*)) data))\n (labels ((update (pos)\n (declare (optimize (speed 3) (safety 0)))\n (unless (= pos 1)\n (let ((parent-pos (ash pos -1)))\n (when (funcall ,order (aref data pos) (aref data parent-pos))\n (rotatef (aref data pos) (aref data parent-pos))\n (update parent-pos))))))\n (unless (< position (length data))\n (error 'heap-full-error :heap heap :item obj))\n (setf (aref data position) obj)\n (update position)\n (incf position)\n heap))))\n\n (declaim #+sbcl (sb-ext:maybe-inline ,fname-pop))\n (defun ,fname-pop (heap)\n \"Removes and returns the element at the top of HEAP.\"\n (declare (optimize (speed 3))\n (type ,name heap))\n (symbol-macrolet ((position (,acc-position heap)))\n (let ((data (,acc-data heap)))\n (declare ((simple-array ,element-type (*)) data))\n (labels ((update (pos)\n (declare (optimize (speed 3) (safety 0))\n ((integer 1 #.most-positive-fixnum) pos))\n (let* ((child-pos1 (+ pos pos))\n (child-pos2 (1+ child-pos1)))\n (when (<= child-pos1 position)\n (if (<= child-pos2 position)\n (if (funcall ,order (aref data child-pos1) (aref data child-pos2))\n (unless (funcall ,order (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))\n (update child-pos1))\n (unless (funcall ,order (aref data pos) (aref data child-pos2))\n (rotatef (aref data pos) (aref data child-pos2))\n (update child-pos2)))\n (unless (funcall ,order (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))))))))\n (when (= position 1)\n (error 'heap-empty-error :heap heap))\n (prog1 (aref data 1)\n (decf position)\n (setf (aref data 1) (aref data position))\n (update 1))))))\n\n (declaim (inline ,fname-reinitialize))\n (defun ,fname-reinitialize (heap)\n \"Makes HEAP empty.\"\n (setf (,acc-position heap) 1)\n heap)\n\n (declaim (inline ,fname-empty-p))\n (defun ,fname-empty-p (heap)\n \"Returns true iff HEAP is empty.\"\n (= 1 (,acc-position heap)))\n\n (declaim (inline ,fname-count))\n (defun ,fname-count (heap)\n \"Returns the current number of the elements in HEAP.\"\n (- (,acc-position heap) 1))\n\n (declaim (inline ,fname-peek))\n (defun ,fname-peek (heap)\n \"Returns the topmost element of HEAP.\"\n (if (= 1 (,acc-position heap))\n (error 'heap-empty-error :heap heap)\n (aref (,acc-data heap) 1))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #xffffffff)\n;; dist . v\n(define-binary-heap heap\n :order (lambda (x y)\n (< (the uint32 (car x)) (the uint32 (car y))))\n :element-type (cons uint32 uint32))\n\n(defun min-cycle-cost (src dest n graph que)\n (declare #.OPT\n ((simple-array list (*)) graph)\n (uint32 n src dest))\n (heap-reinitialize que)\n (let ((dists (make-array (* 2 n) :element-type 'uint32 :initial-element +inf+)))\n (heap-push (cons 0 src) que)\n (loop until (heap-empty-p que)\n for (dist . current) of-type (uint32 . uint32) = (heap-pop que)\n when (< dist (aref dists current))\n do (setf (aref dists current) dist)\n (dolist (neighbor (aref graph current))\n (declare (uint32 neighbor))\n (let ((cost (if (= neighbor (+ current n)) 0 1)))\n (when (< (+ dist cost) (aref dists neighbor))\n (heap-push (cons (+ dist cost) neighbor) que)))))\n (values (aref dists dest) dists)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n ;; in : out\n (graph (make-array (* 2 n) :element-type 'list :initial-element nil))\n (que (make-heap (+ m n n)))\n (min-len +inf+)\n (min-src 0)\n min-dists)\n (declare (uint32 n m min-len min-src))\n (dotimes (i n)\n (push (+ i n) (aref graph i)))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (declare (uint32 a b))\n (push b (aref graph (+ a n)))))\n (dotimes (i n)\n (let ((src (+ i n))\n (dest i))\n (multiple-value-bind (len dists) (min-cycle-cost src dest n graph que)\n (declare (uint32 len))\n (when (< len min-len)\n (setq min-len len\n min-src src\n min-dists dists)))))\n (if (= min-len +inf+)\n (println -1)\n (let* ((marked (make-array (* 2 n) :element-type 'bit :initial-element 0))\n (min-dest (- min-src n))\n (path\n (block dfs\n (sb-int:named-let recur ((v min-src) (path (list min-src)))\n (when (= v min-dest)\n (return-from dfs (nreverse path)))\n (setf (aref marked v) 1)\n (dolist (neighbor (aref graph v))\n (when (and (zerop (aref marked neighbor))\n (= (aref min-dists neighbor)\n (+ (aref min-dists v)\n (if (= neighbor (+ v n)) 0 1))))\n (recur neighbor (cons neighbor path))))))))\n (declare ((simple-array uint32 (*)) min-dists))\n (println min-len)\n (dolist (v path)\n (declare (uint32 v))\n (when (< v n)\n (println (+ 1 v))))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1569724369, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02902.html", "problem_id": "p02902", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02902/input.txt", "sample_output_relpath": "derived/input_output/data/p02902/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02902/Lisp/s021653604.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s021653604", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n1\n2\n4\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Binary heap\n;;;\n\n(define-condition heap-empty-error (simple-error)\n ((heap :initarg :heap :reader heap-empty-error-heap))\n (:report\n (lambda (condition stream)\n (format stream \"Attempted to pop empty heap ~W\" (heap-empty-error-heap condition)))))\n\n(define-condition heap-full-error (simple-error)\n ((heap :initarg :heap :reader heap-full-error-heap)\n (item :initarg :item :reader heap-full-error-item))\n (:report\n (lambda (condition stream)\n (format stream \"Attempted to push item ~W to full heap ~W\"\n (heap-full-error-item condition)\n (heap-full-error-heap condition)))))\n\n(defmacro define-binary-heap (name &key (order '#'>) (element-type 'fixnum))\n \"Defines the binary heap specialized for the given order and the element\ntype. This macro defines a structure of the name NAME and relevant functions:\nMAKE-, -PUSH, -POP, -REINITIALIZE, -EMPTY-P,\n-COUNT, and -PEEK.\"\n (check-type name symbol)\n (let* ((string-name (string name))\n (fname-push (intern (format nil \"~A-PUSH\" string-name)))\n (fname-pop (intern (format nil \"~A-POP\" string-name)))\n (fname-reinitialize (intern (format nil \"~A-REINITIALIZE\" string-name)))\n (fname-empty-p (intern (format nil \"~A-EMPTY-P\" string-name)))\n (fname-count (intern (format nil \"~A-COUNT\" string-name)))\n (fname-peek (intern (format nil \"~A-PEEK\" string-name)))\n (fname-make (intern (format nil \"MAKE-~A\" string-name)))\n (acc-position (intern (format nil \"~A-POSITION\" string-name)))\n (acc-data (intern (format nil \"~A-DATA\" string-name))))\n `(progn\n (defstruct (,name\n (:constructor ,fname-make\n (size\n &aux (data ,(if (eql element-type '*)\n `(make-array (1+ size))\n `(make-array (1+ size) :element-type ',element-type))))))\n (data #() :type (simple-array ,element-type (*)) :read-only t)\n (position 1 :type (integer 1 #.most-positive-fixnum)))\n\n (declaim #+sbcl (sb-ext:maybe-inline ,fname-push))\n (defun ,fname-push (obj heap)\n \"Adds OBJ to the end of HEAP.\"\n (declare (optimize (speed 3))\n (type ,name heap))\n (symbol-macrolet ((position (,acc-position heap)))\n (let ((data (,acc-data heap)))\n (declare ((simple-array ,element-type (*)) data))\n (labels ((update (pos)\n (declare (optimize (speed 3) (safety 0)))\n (unless (= pos 1)\n (let ((parent-pos (ash pos -1)))\n (when (funcall ,order (aref data pos) (aref data parent-pos))\n (rotatef (aref data pos) (aref data parent-pos))\n (update parent-pos))))))\n (unless (< position (length data))\n (error 'heap-full-error :heap heap :item obj))\n (setf (aref data position) obj)\n (update position)\n (incf position)\n heap))))\n\n (declaim #+sbcl (sb-ext:maybe-inline ,fname-pop))\n (defun ,fname-pop (heap)\n \"Removes and returns the element at the top of HEAP.\"\n (declare (optimize (speed 3))\n (type ,name heap))\n (symbol-macrolet ((position (,acc-position heap)))\n (let ((data (,acc-data heap)))\n (declare ((simple-array ,element-type (*)) data))\n (labels ((update (pos)\n (declare (optimize (speed 3) (safety 0))\n ((integer 1 #.most-positive-fixnum) pos))\n (let* ((child-pos1 (+ pos pos))\n (child-pos2 (1+ child-pos1)))\n (when (<= child-pos1 position)\n (if (<= child-pos2 position)\n (if (funcall ,order (aref data child-pos1) (aref data child-pos2))\n (unless (funcall ,order (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))\n (update child-pos1))\n (unless (funcall ,order (aref data pos) (aref data child-pos2))\n (rotatef (aref data pos) (aref data child-pos2))\n (update child-pos2)))\n (unless (funcall ,order (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))))))))\n (when (= position 1)\n (error 'heap-empty-error :heap heap))\n (prog1 (aref data 1)\n (decf position)\n (setf (aref data 1) (aref data position))\n (update 1))))))\n\n (declaim (inline ,fname-reinitialize))\n (defun ,fname-reinitialize (heap)\n \"Makes HEAP empty.\"\n (setf (,acc-position heap) 1)\n heap)\n\n (declaim (inline ,fname-empty-p))\n (defun ,fname-empty-p (heap)\n \"Returns true iff HEAP is empty.\"\n (= 1 (,acc-position heap)))\n\n (declaim (inline ,fname-count))\n (defun ,fname-count (heap)\n \"Returns the current number of the elements in HEAP.\"\n (- (,acc-position heap) 1))\n\n (declaim (inline ,fname-peek))\n (defun ,fname-peek (heap)\n \"Returns the topmost element of HEAP.\"\n (if (= 1 (,acc-position heap))\n (error 'heap-empty-error :heap heap)\n (aref (,acc-data heap) 1))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #xffffffff)\n;; dist . v\n(define-binary-heap heap\n :order (lambda (x y)\n (< (the uint32 (car x)) (the uint32 (car y))))\n :element-type (cons uint32 uint32))\n\n(defun min-cycle-cost (src dest n graph que)\n (declare #.OPT\n ((simple-array list (*)) graph)\n (uint32 n src dest))\n (heap-reinitialize que)\n (let ((dists (make-array (* 2 n) :element-type 'uint32 :initial-element +inf+)))\n (heap-push (cons 0 src) que)\n (loop until (heap-empty-p que)\n for (dist . current) of-type (uint32 . uint32) = (heap-pop que)\n when (< dist (aref dists current))\n do (setf (aref dists current) dist)\n (dolist (neighbor (aref graph current))\n (declare (uint32 neighbor))\n (let ((cost (if (= neighbor (+ current n)) 0 1)))\n (when (< (+ dist cost) (aref dists neighbor))\n (heap-push (cons (+ dist cost) neighbor) que)))))\n (values (aref dists dest) dists)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n ;; in : out\n (graph (make-array (* 2 n) :element-type 'list :initial-element nil))\n (que (make-heap (+ m n n)))\n (min-len +inf+)\n (min-src 0)\n min-dists)\n (declare (uint32 n m min-len min-src))\n (dotimes (i n)\n (push (+ i n) (aref graph i)))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (declare (uint32 a b))\n (push b (aref graph (+ a n)))))\n (dotimes (i n)\n (let ((src (+ i n))\n (dest i))\n (multiple-value-bind (len dists) (min-cycle-cost src dest n graph que)\n (declare (uint32 len))\n (when (< len min-len)\n (setq min-len len\n min-src src\n min-dists dists)))))\n (if (= min-len +inf+)\n (println -1)\n (let* ((marked (make-array (* 2 n) :element-type 'bit :initial-element 0))\n (min-dest (- min-src n))\n (path\n (block dfs\n (sb-int:named-let recur ((v min-src) (path (list min-src)))\n (when (= v min-dest)\n (return-from dfs (nreverse path)))\n (setf (aref marked v) 1)\n (dolist (neighbor (aref graph v))\n (when (and (zerop (aref marked neighbor))\n (= (aref min-dists neighbor)\n (+ (aref min-dists v)\n (if (= neighbor (+ v n)) 0 1))))\n (recur neighbor (cons neighbor path))))))))\n (declare ((simple-array uint32 (*)) min-dists))\n (println min-len)\n (dolist (v path)\n (declare (uint32 v))\n (when (< v n)\n (println (+ 1 v))))))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven is a directed graph G with N vertices and M edges.\n\nThe vertices are numbered 1 to N, and the i-th edge is directed from Vertex A_i to Vertex B_i.\n\nIt is guaranteed that the graph contains no self-loops or multiple edges.\n\nDetermine whether there exists an induced subgraph (see Notes) of G such that the in-degree and out-degree of every vertex are both 1. If the answer is yes, show one such subgraph.\n\nHere the null graph is not considered as a subgraph.\n\nNotes\n\nFor a directed graph G = (V, E), we call a directed graph G' = (V', E') satisfying the following conditions an induced subgraph of G:\n\nV' is a (non-empty) subset of V.\n\nE' is the set of all the edges in E that have both endpoints in V'.\n\nConstraints\n\n1 \\leq N \\leq 1000\n\n0 \\leq M \\leq 2000\n\n1 \\leq A_i,B_i \\leq N\n\nA_i \\neq B_i\n\nAll pairs (A_i, B_i) are distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\nA_2 B_2\n:\nA_M B_M\n\nOutput\n\nIf there is no induced subgraph of G that satisfies the condition, print -1.\nOtherwise, print an induced subgraph of G that satisfies the condition, in the following format:\n\nK\nv_1\nv_2\n:\nv_K\n\nThis represents the induced subgraph of G with K vertices whose vertex set is \\{v_1, v_2, \\ldots, v_K\\}. (The order of v_1, v_2, \\ldots, v_K does not matter.)\nIf there are multiple subgraphs of G that satisfy the condition, printing any of them is accepted.\n\nSample Input 1\n\n4 5\n1 2\n2 3\n2 4\n4 1\n4 3\n\nSample Output 1\n\n3\n1\n2\n4\n\nThe induced subgraph of G whose vertex set is \\{1, 2, 4\\} has the edge set \\{(1, 2), (2, 4), (4, 1)\\}. The in-degree and out-degree of every vertex in this graph are both 1.\n\nSample Input 2\n\n4 5\n1 2\n2 3\n2 4\n1 4\n4 3\n\nSample Output 2\n\n-1\n\nThere is no induced subgraph of G that satisfies the condition.\n\nSample Input 3\n\n6 9\n1 2\n2 3\n3 4\n4 5\n5 6\n5 1\n5 2\n6 1\n6 2\n\nSample Output 3\n\n4\n2\n3\n4\n5", "sample_input": "4 5\n1 2\n2 3\n2 4\n4 1\n4 3\n"}, "reference_outputs": ["3\n1\n2\n4\n"], "source_document_id": "p02902", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven is a directed graph G with N vertices and M edges.\n\nThe vertices are numbered 1 to N, and the i-th edge is directed from Vertex A_i to Vertex B_i.\n\nIt is guaranteed that the graph contains no self-loops or multiple edges.\n\nDetermine whether there exists an induced subgraph (see Notes) of G such that the in-degree and out-degree of every vertex are both 1. If the answer is yes, show one such subgraph.\n\nHere the null graph is not considered as a subgraph.\n\nNotes\n\nFor a directed graph G = (V, E), we call a directed graph G' = (V', E') satisfying the following conditions an induced subgraph of G:\n\nV' is a (non-empty) subset of V.\n\nE' is the set of all the edges in E that have both endpoints in V'.\n\nConstraints\n\n1 \\leq N \\leq 1000\n\n0 \\leq M \\leq 2000\n\n1 \\leq A_i,B_i \\leq N\n\nA_i \\neq B_i\n\nAll pairs (A_i, B_i) are distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\nA_2 B_2\n:\nA_M B_M\n\nOutput\n\nIf there is no induced subgraph of G that satisfies the condition, print -1.\nOtherwise, print an induced subgraph of G that satisfies the condition, in the following format:\n\nK\nv_1\nv_2\n:\nv_K\n\nThis represents the induced subgraph of G with K vertices whose vertex set is \\{v_1, v_2, \\ldots, v_K\\}. (The order of v_1, v_2, \\ldots, v_K does not matter.)\nIf there are multiple subgraphs of G that satisfy the condition, printing any of them is accepted.\n\nSample Input 1\n\n4 5\n1 2\n2 3\n2 4\n4 1\n4 3\n\nSample Output 1\n\n3\n1\n2\n4\n\nThe induced subgraph of G whose vertex set is \\{1, 2, 4\\} has the edge set \\{(1, 2), (2, 4), (4, 1)\\}. The in-degree and out-degree of every vertex in this graph are both 1.\n\nSample Input 2\n\n4 5\n1 2\n2 3\n2 4\n1 4\n4 3\n\nSample Output 2\n\n-1\n\nThere is no induced subgraph of G that satisfies the condition.\n\nSample Input 3\n\n6 9\n1 2\n2 3\n3 4\n4 5\n5 6\n5 1\n5 2\n6 1\n6 2\n\nSample Output 3\n\n4\n2\n3\n4\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11102, "cpu_time_ms": 341, "memory_kb": 60264}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s550936678", "group_id": "codeNet:p02902", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Binary heap\n;;;\n\n(define-condition heap-empty-error (simple-error)\n ((heap :initarg :heap :reader heap-empty-error-heap))\n (:report\n (lambda (condition stream)\n (format stream \"Attempted to pop empty heap ~W\" (heap-empty-error-heap condition)))))\n\n(define-condition heap-full-error (simple-error)\n ((heap :initarg :heap :reader heap-full-error-heap)\n (item :initarg :item :reader heap-full-error-item))\n (:report\n (lambda (condition stream)\n (format stream \"Attempted to push item ~W to full heap ~W\"\n (heap-full-error-item condition)\n (heap-full-error-heap condition)))))\n\n(defmacro define-binary-heap (name &key (order '#'>) (element-type 'fixnum))\n \"Defines the binary heap specialized for the given order and the element\ntype. This macro defines a structure of the name NAME and relevant functions:\nMAKE-, -PUSH, -POP, -REINITIALIZE, -EMPTY-P,\n-COUNT, and -PEEK.\"\n (check-type name symbol)\n (let* ((string-name (string name))\n (fname-push (intern (format nil \"~A-PUSH\" string-name)))\n (fname-pop (intern (format nil \"~A-POP\" string-name)))\n (fname-reinitialize (intern (format nil \"~A-REINITIALIZE\" string-name)))\n (fname-empty-p (intern (format nil \"~A-EMPTY-P\" string-name)))\n (fname-count (intern (format nil \"~A-COUNT\" string-name)))\n (fname-peek (intern (format nil \"~A-PEEK\" string-name)))\n (fname-make (intern (format nil \"MAKE-~A\" string-name)))\n (acc-position (intern (format nil \"~A-POSITION\" string-name)))\n (acc-data (intern (format nil \"~A-DATA\" string-name))))\n `(progn\n (defstruct (,name\n (:constructor ,fname-make\n (size\n &aux (data ,(if (eql element-type '*)\n `(make-array (1+ size))\n `(make-array (1+ size) :element-type ',element-type))))))\n (data #() :type (simple-array ,element-type (*)) :read-only t)\n (position 1 :type (integer 1 #.most-positive-fixnum)))\n\n (declaim #+sbcl (sb-ext:maybe-inline ,fname-push))\n (defun ,fname-push (obj heap)\n \"Adds OBJ to the end of HEAP.\"\n (declare (optimize (speed 3))\n (type ,name heap))\n (symbol-macrolet ((position (,acc-position heap)))\n (let ((data (,acc-data heap)))\n (declare ((simple-array ,element-type (*)) data))\n (labels ((update (pos)\n (declare (optimize (speed 3) (safety 0)))\n (unless (= pos 1)\n (let ((parent-pos (ash pos -1)))\n (when (funcall ,order (aref data pos) (aref data parent-pos))\n (rotatef (aref data pos) (aref data parent-pos))\n (update parent-pos))))))\n (unless (< position (length data))\n (error 'heap-full-error :heap heap :item obj))\n (setf (aref data position) obj)\n (update position)\n (incf position)\n heap))))\n\n (declaim #+sbcl (sb-ext:maybe-inline ,fname-pop))\n (defun ,fname-pop (heap)\n \"Removes and returns the element at the top of HEAP.\"\n (declare (optimize (speed 3))\n (type ,name heap))\n (symbol-macrolet ((position (,acc-position heap)))\n (let ((data (,acc-data heap)))\n (declare ((simple-array ,element-type (*)) data))\n (labels ((update (pos)\n (declare (optimize (speed 3) (safety 0))\n ((integer 1 #.most-positive-fixnum) pos))\n (let* ((child-pos1 (+ pos pos))\n (child-pos2 (1+ child-pos1)))\n (when (<= child-pos1 position)\n (if (<= child-pos2 position)\n (if (funcall ,order (aref data child-pos1) (aref data child-pos2))\n (unless (funcall ,order (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))\n (update child-pos1))\n (unless (funcall ,order (aref data pos) (aref data child-pos2))\n (rotatef (aref data pos) (aref data child-pos2))\n (update child-pos2)))\n (unless (funcall ,order (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))))))))\n (when (= position 1)\n (error 'heap-empty-error :heap heap))\n (prog1 (aref data 1)\n (decf position)\n (setf (aref data 1) (aref data position))\n (update 1))))))\n\n (declaim (inline ,fname-reinitialize))\n (defun ,fname-reinitialize (heap)\n \"Makes HEAP empty.\"\n (setf (,acc-position heap) 1)\n heap)\n\n (declaim (inline ,fname-empty-p))\n (defun ,fname-empty-p (heap)\n \"Returns true iff HEAP is empty.\"\n (= 1 (,acc-position heap)))\n\n (declaim (inline ,fname-count))\n (defun ,fname-count (heap)\n \"Returns the current number of the elements in HEAP.\"\n (- (,acc-position heap) 1))\n\n (declaim (inline ,fname-peek))\n (defun ,fname-peek (heap)\n \"Returns the topmost element of HEAP.\"\n (if (= 1 (,acc-position heap))\n (error 'heap-empty-error :heap heap)\n (aref (,acc-data heap) 1))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #xffffffff)\n;; dist . v\n(define-binary-heap heap\n :order (lambda (x y)\n (< (the uint32 (car x)) (the uint32 (car y))))\n :element-type list)\n\n(defun min-cycle-cost (src dest n graph que)\n (declare ((simple-array list (*)) graph)\n (uint32 n src dest))\n (heap-reinitialize que)\n (let ((dists (make-array (* 2 n) :element-type 'uint32 :initial-element +inf+)))\n (heap-push (cons 0 src) que)\n (loop until (heap-empty-p que)\n for (dist . current) = (heap-pop que)\n when (< dist (aref dists current))\n do (setf (aref dists current) dist)\n (dolist (neighbor (aref graph current))\n (let ((cost (if (= neighbor (+ current n)) 0 1)))\n (when (< (+ dist cost) (aref dists neighbor))\n (heap-push (cons (+ dist cost) neighbor) que)))))\n (values (aref dists dest) dists)))\n\n(defun min-cycle (src n graph que)\n (declare ((simple-array list (*)) graph)\n (uint32 n src))\n (heap-reinitialize que)\n (let ((dists (make-array (* 2 n) :element-type 'uint32 :initial-element +inf+))\n (paths (make-array (* 2 n) :element-type 'list :initial-element nil)))\n (heap-push (list 0 src (list src)) que)\n (loop until (heap-empty-p que)\n for (dist current path) = (heap-pop que)\n when (< dist (aref dists current))\n do (setf (aref dists current) dist\n (aref paths current) path)\n (dolist (neighbor (aref graph current))\n (let ((cost (if (= neighbor (+ current n)) 0 1)))\n (when (< (+ dist cost) (aref dists neighbor))\n (heap-push (list (+ dist cost) neighbor (cons neighbor path)) que)))))\n paths))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n ;; in : out\n (graph (make-array (* 2 n) :element-type 'list :initial-element nil))\n (revgraph (make-array (* 2 n) :element-type 'list :initial-element nil))\n (que (make-heap (+ m n n)))\n (min-value +inf+)\n (min-src 0)\n min-dists)\n (declare (uint32 n m min-value min-src))\n (dotimes (i n)\n (push (+ i n) (aref graph i))\n (push i (aref revgraph (+ i n))))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (declare (uint32 a b))\n (push b (aref graph (+ a n)))\n (push (+ a n) (aref revgraph b))))\n (dotimes (i n)\n (let ((src (+ i n))\n (dest i))\n (multiple-value-bind (res dists) (min-cycle-cost src dest n graph que)\n (when (< res min-value)\n (setf min-value res\n min-src src\n min-dists dists)))))\n (if (= min-value +inf+)\n (println -1)\n (let* ((paths (min-cycle min-src n graph que))\n (min-dest (- min-src n))\n (path (reverse (aref paths min-dest))))\n (println min-value)\n (dolist (v path)\n (when (< v n)\n (println (+ 1 v))))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1569723401, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02902.html", "problem_id": "p02902", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02902/input.txt", "sample_output_relpath": "derived/input_output/data/p02902/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02902/Lisp/s550936678.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s550936678", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n1\n2\n4\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Binary heap\n;;;\n\n(define-condition heap-empty-error (simple-error)\n ((heap :initarg :heap :reader heap-empty-error-heap))\n (:report\n (lambda (condition stream)\n (format stream \"Attempted to pop empty heap ~W\" (heap-empty-error-heap condition)))))\n\n(define-condition heap-full-error (simple-error)\n ((heap :initarg :heap :reader heap-full-error-heap)\n (item :initarg :item :reader heap-full-error-item))\n (:report\n (lambda (condition stream)\n (format stream \"Attempted to push item ~W to full heap ~W\"\n (heap-full-error-item condition)\n (heap-full-error-heap condition)))))\n\n(defmacro define-binary-heap (name &key (order '#'>) (element-type 'fixnum))\n \"Defines the binary heap specialized for the given order and the element\ntype. This macro defines a structure of the name NAME and relevant functions:\nMAKE-, -PUSH, -POP, -REINITIALIZE, -EMPTY-P,\n-COUNT, and -PEEK.\"\n (check-type name symbol)\n (let* ((string-name (string name))\n (fname-push (intern (format nil \"~A-PUSH\" string-name)))\n (fname-pop (intern (format nil \"~A-POP\" string-name)))\n (fname-reinitialize (intern (format nil \"~A-REINITIALIZE\" string-name)))\n (fname-empty-p (intern (format nil \"~A-EMPTY-P\" string-name)))\n (fname-count (intern (format nil \"~A-COUNT\" string-name)))\n (fname-peek (intern (format nil \"~A-PEEK\" string-name)))\n (fname-make (intern (format nil \"MAKE-~A\" string-name)))\n (acc-position (intern (format nil \"~A-POSITION\" string-name)))\n (acc-data (intern (format nil \"~A-DATA\" string-name))))\n `(progn\n (defstruct (,name\n (:constructor ,fname-make\n (size\n &aux (data ,(if (eql element-type '*)\n `(make-array (1+ size))\n `(make-array (1+ size) :element-type ',element-type))))))\n (data #() :type (simple-array ,element-type (*)) :read-only t)\n (position 1 :type (integer 1 #.most-positive-fixnum)))\n\n (declaim #+sbcl (sb-ext:maybe-inline ,fname-push))\n (defun ,fname-push (obj heap)\n \"Adds OBJ to the end of HEAP.\"\n (declare (optimize (speed 3))\n (type ,name heap))\n (symbol-macrolet ((position (,acc-position heap)))\n (let ((data (,acc-data heap)))\n (declare ((simple-array ,element-type (*)) data))\n (labels ((update (pos)\n (declare (optimize (speed 3) (safety 0)))\n (unless (= pos 1)\n (let ((parent-pos (ash pos -1)))\n (when (funcall ,order (aref data pos) (aref data parent-pos))\n (rotatef (aref data pos) (aref data parent-pos))\n (update parent-pos))))))\n (unless (< position (length data))\n (error 'heap-full-error :heap heap :item obj))\n (setf (aref data position) obj)\n (update position)\n (incf position)\n heap))))\n\n (declaim #+sbcl (sb-ext:maybe-inline ,fname-pop))\n (defun ,fname-pop (heap)\n \"Removes and returns the element at the top of HEAP.\"\n (declare (optimize (speed 3))\n (type ,name heap))\n (symbol-macrolet ((position (,acc-position heap)))\n (let ((data (,acc-data heap)))\n (declare ((simple-array ,element-type (*)) data))\n (labels ((update (pos)\n (declare (optimize (speed 3) (safety 0))\n ((integer 1 #.most-positive-fixnum) pos))\n (let* ((child-pos1 (+ pos pos))\n (child-pos2 (1+ child-pos1)))\n (when (<= child-pos1 position)\n (if (<= child-pos2 position)\n (if (funcall ,order (aref data child-pos1) (aref data child-pos2))\n (unless (funcall ,order (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))\n (update child-pos1))\n (unless (funcall ,order (aref data pos) (aref data child-pos2))\n (rotatef (aref data pos) (aref data child-pos2))\n (update child-pos2)))\n (unless (funcall ,order (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))))))))\n (when (= position 1)\n (error 'heap-empty-error :heap heap))\n (prog1 (aref data 1)\n (decf position)\n (setf (aref data 1) (aref data position))\n (update 1))))))\n\n (declaim (inline ,fname-reinitialize))\n (defun ,fname-reinitialize (heap)\n \"Makes HEAP empty.\"\n (setf (,acc-position heap) 1)\n heap)\n\n (declaim (inline ,fname-empty-p))\n (defun ,fname-empty-p (heap)\n \"Returns true iff HEAP is empty.\"\n (= 1 (,acc-position heap)))\n\n (declaim (inline ,fname-count))\n (defun ,fname-count (heap)\n \"Returns the current number of the elements in HEAP.\"\n (- (,acc-position heap) 1))\n\n (declaim (inline ,fname-peek))\n (defun ,fname-peek (heap)\n \"Returns the topmost element of HEAP.\"\n (if (= 1 (,acc-position heap))\n (error 'heap-empty-error :heap heap)\n (aref (,acc-data heap) 1))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #xffffffff)\n;; dist . v\n(define-binary-heap heap\n :order (lambda (x y)\n (< (the uint32 (car x)) (the uint32 (car y))))\n :element-type list)\n\n(defun min-cycle-cost (src dest n graph que)\n (declare ((simple-array list (*)) graph)\n (uint32 n src dest))\n (heap-reinitialize que)\n (let ((dists (make-array (* 2 n) :element-type 'uint32 :initial-element +inf+)))\n (heap-push (cons 0 src) que)\n (loop until (heap-empty-p que)\n for (dist . current) = (heap-pop que)\n when (< dist (aref dists current))\n do (setf (aref dists current) dist)\n (dolist (neighbor (aref graph current))\n (let ((cost (if (= neighbor (+ current n)) 0 1)))\n (when (< (+ dist cost) (aref dists neighbor))\n (heap-push (cons (+ dist cost) neighbor) que)))))\n (values (aref dists dest) dists)))\n\n(defun min-cycle (src n graph que)\n (declare ((simple-array list (*)) graph)\n (uint32 n src))\n (heap-reinitialize que)\n (let ((dists (make-array (* 2 n) :element-type 'uint32 :initial-element +inf+))\n (paths (make-array (* 2 n) :element-type 'list :initial-element nil)))\n (heap-push (list 0 src (list src)) que)\n (loop until (heap-empty-p que)\n for (dist current path) = (heap-pop que)\n when (< dist (aref dists current))\n do (setf (aref dists current) dist\n (aref paths current) path)\n (dolist (neighbor (aref graph current))\n (let ((cost (if (= neighbor (+ current n)) 0 1)))\n (when (< (+ dist cost) (aref dists neighbor))\n (heap-push (list (+ dist cost) neighbor (cons neighbor path)) que)))))\n paths))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n ;; in : out\n (graph (make-array (* 2 n) :element-type 'list :initial-element nil))\n (revgraph (make-array (* 2 n) :element-type 'list :initial-element nil))\n (que (make-heap (+ m n n)))\n (min-value +inf+)\n (min-src 0)\n min-dists)\n (declare (uint32 n m min-value min-src))\n (dotimes (i n)\n (push (+ i n) (aref graph i))\n (push i (aref revgraph (+ i n))))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (declare (uint32 a b))\n (push b (aref graph (+ a n)))\n (push (+ a n) (aref revgraph b))))\n (dotimes (i n)\n (let ((src (+ i n))\n (dest i))\n (multiple-value-bind (res dists) (min-cycle-cost src dest n graph que)\n (when (< res min-value)\n (setf min-value res\n min-src src\n min-dists dists)))))\n (if (= min-value +inf+)\n (println -1)\n (let* ((paths (min-cycle min-src n graph que))\n (min-dest (- min-src n))\n (path (reverse (aref paths min-dest))))\n (println min-value)\n (dolist (v path)\n (when (< v n)\n (println (+ 1 v))))))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven is a directed graph G with N vertices and M edges.\n\nThe vertices are numbered 1 to N, and the i-th edge is directed from Vertex A_i to Vertex B_i.\n\nIt is guaranteed that the graph contains no self-loops or multiple edges.\n\nDetermine whether there exists an induced subgraph (see Notes) of G such that the in-degree and out-degree of every vertex are both 1. If the answer is yes, show one such subgraph.\n\nHere the null graph is not considered as a subgraph.\n\nNotes\n\nFor a directed graph G = (V, E), we call a directed graph G' = (V', E') satisfying the following conditions an induced subgraph of G:\n\nV' is a (non-empty) subset of V.\n\nE' is the set of all the edges in E that have both endpoints in V'.\n\nConstraints\n\n1 \\leq N \\leq 1000\n\n0 \\leq M \\leq 2000\n\n1 \\leq A_i,B_i \\leq N\n\nA_i \\neq B_i\n\nAll pairs (A_i, B_i) are distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\nA_2 B_2\n:\nA_M B_M\n\nOutput\n\nIf there is no induced subgraph of G that satisfies the condition, print -1.\nOtherwise, print an induced subgraph of G that satisfies the condition, in the following format:\n\nK\nv_1\nv_2\n:\nv_K\n\nThis represents the induced subgraph of G with K vertices whose vertex set is \\{v_1, v_2, \\ldots, v_K\\}. (The order of v_1, v_2, \\ldots, v_K does not matter.)\nIf there are multiple subgraphs of G that satisfy the condition, printing any of them is accepted.\n\nSample Input 1\n\n4 5\n1 2\n2 3\n2 4\n4 1\n4 3\n\nSample Output 1\n\n3\n1\n2\n4\n\nThe induced subgraph of G whose vertex set is \\{1, 2, 4\\} has the edge set \\{(1, 2), (2, 4), (4, 1)\\}. The in-degree and out-degree of every vertex in this graph are both 1.\n\nSample Input 2\n\n4 5\n1 2\n2 3\n2 4\n1 4\n4 3\n\nSample Output 2\n\n-1\n\nThere is no induced subgraph of G that satisfies the condition.\n\nSample Input 3\n\n6 9\n1 2\n2 3\n3 4\n4 5\n5 6\n5 1\n5 2\n6 1\n6 2\n\nSample Output 3\n\n4\n2\n3\n4\n5", "sample_input": "4 5\n1 2\n2 3\n2 4\n4 1\n4 3\n"}, "reference_outputs": ["3\n1\n2\n4\n"], "source_document_id": "p02902", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven is a directed graph G with N vertices and M edges.\n\nThe vertices are numbered 1 to N, and the i-th edge is directed from Vertex A_i to Vertex B_i.\n\nIt is guaranteed that the graph contains no self-loops or multiple edges.\n\nDetermine whether there exists an induced subgraph (see Notes) of G such that the in-degree and out-degree of every vertex are both 1. If the answer is yes, show one such subgraph.\n\nHere the null graph is not considered as a subgraph.\n\nNotes\n\nFor a directed graph G = (V, E), we call a directed graph G' = (V', E') satisfying the following conditions an induced subgraph of G:\n\nV' is a (non-empty) subset of V.\n\nE' is the set of all the edges in E that have both endpoints in V'.\n\nConstraints\n\n1 \\leq N \\leq 1000\n\n0 \\leq M \\leq 2000\n\n1 \\leq A_i,B_i \\leq N\n\nA_i \\neq B_i\n\nAll pairs (A_i, B_i) are distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\nA_2 B_2\n:\nA_M B_M\n\nOutput\n\nIf there is no induced subgraph of G that satisfies the condition, print -1.\nOtherwise, print an induced subgraph of G that satisfies the condition, in the following format:\n\nK\nv_1\nv_2\n:\nv_K\n\nThis represents the induced subgraph of G with K vertices whose vertex set is \\{v_1, v_2, \\ldots, v_K\\}. (The order of v_1, v_2, \\ldots, v_K does not matter.)\nIf there are multiple subgraphs of G that satisfy the condition, printing any of them is accepted.\n\nSample Input 1\n\n4 5\n1 2\n2 3\n2 4\n4 1\n4 3\n\nSample Output 1\n\n3\n1\n2\n4\n\nThe induced subgraph of G whose vertex set is \\{1, 2, 4\\} has the edge set \\{(1, 2), (2, 4), (4, 1)\\}. The in-degree and out-degree of every vertex in this graph are both 1.\n\nSample Input 2\n\n4 5\n1 2\n2 3\n2 4\n1 4\n4 3\n\nSample Output 2\n\n-1\n\nThere is no induced subgraph of G that satisfies the condition.\n\nSample Input 3\n\n6 9\n1 2\n2 3\n3 4\n4 5\n5 6\n5 1\n5 2\n6 1\n6 2\n\nSample Output 3\n\n4\n2\n3\n4\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11243, "cpu_time_ms": 297, "memory_kb": 62308}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s883923962", "group_id": "codeNet:p02905", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n(defconstant +mod+ 998244353)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\n\n;; TODO: non-global handling\n\n(defconstant +binom-size+ 1100000)\n(defconstant +binom-mod+ +mod+)\n\n(declaim ((simple-array (unsigned-byte 32) (*)) *inv*))\n(defparameter *inv* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of inverses of non-negative integers\")\n\n(defun initialize-binom ()\n (declare (optimize (speed 3) (safety 0)))\n (setf (aref *inv* 1) 1)\n (loop for i from 2 below +binom-size+\n do (setf (aref *inv* i) (- +binom-mod+\n (mod (* (aref *inv* (rem +binom-mod+ i))\n (floor +binom-mod+ i))\n +binom-mod+)))))\n\n(initialize-binom)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (defun mod- (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod- (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (- ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(declaim (inline divisor-transform!))\n(defun divisor-transform! (vector &optional (plus #'+))\n \"Sets each VECTOR[i] to the sum of VECTOR[d] for all the divisors d of i.\"\n (declare (vector vector))\n (let ((n (length vector)))\n (loop for i from (- (ceiling n 2) 1) downto 1\n do (loop for j from (+ i i) below n by i\n do (setf (aref vector j)\n (funcall plus (aref vector j) (aref vector i)))))\n vector))\n\n(declaim (inline inverse-divisor-transform!))\n(defun inverse-divisor-transform! (vector &optional (minus #'-))\n \"Does the inverse transform of DIVISOR-TRANSFORM!.\"\n (declare (vector vector))\n (let ((n (length vector)))\n (loop for i from 1 below (ceiling n 2)\n do (loop for j from (+ i i) below n by i\n do (setf (aref vector j)\n (funcall minus (aref vector j) (aref vector i)))))\n vector))\n\n(declaim (inline multiple-transform!))\n(defun multiple-transform! (vector &optional (plus #'+))\n \"Sets each VECTOR[i] to the sum of VECTOR[m] for all the multiples m of i. (To\nbe precise, all the multiples smaller than the length of VECTOR.)\"\n (declare (vector vector))\n (let ((n (length vector)))\n (loop for i from 1 below (ceiling n 2)\n do (loop for j from (+ i i) below n by i\n do (setf (aref vector i)\n (funcall plus (aref vector i) (aref vector j)))))\n vector))\n\n(declaim (inline inverse-multiple-transform!))\n(defun inverse-multiple-transform! (vector &optional (minus #'-))\n \"Does the inverse transform of MULTIPLE-TRANSFORM!.\"\n (declare (vector vector))\n (let ((n (length vector)))\n (loop for i from (- (ceiling n 2) 1) downto 1\n do (loop for j from (+ i i) below n by i\n do (setf (aref vector i)\n (funcall minus (aref vector i) (aref vector j)))))\n vector))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n (dp (make-array 1000001 :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n))\n (dotimes (i n)\n (let ((a (read-fixnum)))\n (incfmod (aref dp a) a)\n (setf (aref as i) a)))\n (multiple-transform! dp #'mod+)\n (dotimes (i (length dp))\n (setf (aref dp i) (mod* (aref dp i) (aref dp i))))\n (inverse-multiple-transform! dp\n (lambda (x y)\n (let ((res (+ x (- +mod+ y))))\n (if (>= res +mod+)\n (- res +mod+)\n res))))\n (loop for a across as\n do (decfmod (aref dp a) (* a a)))\n (loop for i from 1 below (length dp)\n do (setf (aref dp i)\n (mod* (aref dp i) (aref *inv* i))))\n (println (mod* (mod (reduce #'+ dp) +mod+)\n (aref *inv* 2)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1569149192, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02905.html", "problem_id": "p02905", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02905/input.txt", "sample_output_relpath": "derived/input_output/data/p02905/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02905/Lisp/s883923962.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s883923962", "user_id": "u352600849"}, "prompt_components": {"gold_output": "22\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n(defconstant +mod+ 998244353)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\n\n;; TODO: non-global handling\n\n(defconstant +binom-size+ 1100000)\n(defconstant +binom-mod+ +mod+)\n\n(declaim ((simple-array (unsigned-byte 32) (*)) *inv*))\n(defparameter *inv* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of inverses of non-negative integers\")\n\n(defun initialize-binom ()\n (declare (optimize (speed 3) (safety 0)))\n (setf (aref *inv* 1) 1)\n (loop for i from 2 below +binom-size+\n do (setf (aref *inv* i) (- +binom-mod+\n (mod (* (aref *inv* (rem +binom-mod+ i))\n (floor +binom-mod+ i))\n +binom-mod+)))))\n\n(initialize-binom)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (defun mod- (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod- (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (- ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(declaim (inline divisor-transform!))\n(defun divisor-transform! (vector &optional (plus #'+))\n \"Sets each VECTOR[i] to the sum of VECTOR[d] for all the divisors d of i.\"\n (declare (vector vector))\n (let ((n (length vector)))\n (loop for i from (- (ceiling n 2) 1) downto 1\n do (loop for j from (+ i i) below n by i\n do (setf (aref vector j)\n (funcall plus (aref vector j) (aref vector i)))))\n vector))\n\n(declaim (inline inverse-divisor-transform!))\n(defun inverse-divisor-transform! (vector &optional (minus #'-))\n \"Does the inverse transform of DIVISOR-TRANSFORM!.\"\n (declare (vector vector))\n (let ((n (length vector)))\n (loop for i from 1 below (ceiling n 2)\n do (loop for j from (+ i i) below n by i\n do (setf (aref vector j)\n (funcall minus (aref vector j) (aref vector i)))))\n vector))\n\n(declaim (inline multiple-transform!))\n(defun multiple-transform! (vector &optional (plus #'+))\n \"Sets each VECTOR[i] to the sum of VECTOR[m] for all the multiples m of i. (To\nbe precise, all the multiples smaller than the length of VECTOR.)\"\n (declare (vector vector))\n (let ((n (length vector)))\n (loop for i from 1 below (ceiling n 2)\n do (loop for j from (+ i i) below n by i\n do (setf (aref vector i)\n (funcall plus (aref vector i) (aref vector j)))))\n vector))\n\n(declaim (inline inverse-multiple-transform!))\n(defun inverse-multiple-transform! (vector &optional (minus #'-))\n \"Does the inverse transform of MULTIPLE-TRANSFORM!.\"\n (declare (vector vector))\n (let ((n (length vector)))\n (loop for i from (- (ceiling n 2) 1) downto 1\n do (loop for j from (+ i i) below n by i\n do (setf (aref vector i)\n (funcall minus (aref vector i) (aref vector j)))))\n vector))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n (dp (make-array 1000001 :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n))\n (dotimes (i n)\n (let ((a (read-fixnum)))\n (incfmod (aref dp a) a)\n (setf (aref as i) a)))\n (multiple-transform! dp #'mod+)\n (dotimes (i (length dp))\n (setf (aref dp i) (mod* (aref dp i) (aref dp i))))\n (inverse-multiple-transform! dp\n (lambda (x y)\n (let ((res (+ x (- +mod+ y))))\n (if (>= res +mod+)\n (- res +mod+)\n res))))\n (loop for a across as\n do (decfmod (aref dp a) (* a a)))\n (loop for i from 1 below (length dp)\n do (setf (aref dp i)\n (mod* (aref dp i) (aref *inv* i))))\n (println (mod* (mod (reduce #'+ dp) +mod+)\n (aref *inv* 2)))))\n\n#-swank (main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nWe have an integer sequence of length N: A_0,A_1,\\cdots,A_{N-1}.\n\nFind the following sum (\\mathrm{lcm}(a, b) denotes the least common multiple of a and b):\n\n\\sum_{i=0}^{N-2} \\sum_{j=i+1}^{N-1} \\mathrm{lcm}(A_i,A_j)\n\nSince the answer may be enormous, compute it modulo 998244353.\n\nConstraints\n\n1 \\leq N \\leq 200000\n\n1 \\leq A_i \\leq 1000000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_0\\ A_1\\ \\cdots\\ A_{N-1}\n\nOutput\n\nPrint the sum modulo 998244353.\n\nSample Input 1\n\n3\n2 4 6\n\nSample Output 1\n\n22\n\n\\mathrm{lcm}(2,4)+\\mathrm{lcm}(2,6)+\\mathrm{lcm}(4,6)=4+6+12=22.\n\nSample Input 2\n\n8\n1 2 3 4 6 8 12 12\n\nSample Output 2\n\n313\n\nSample Input 3\n\n10\n356822 296174 484500 710640 518322 888250 259161 609120 592348 713644\n\nSample Output 3\n\n353891724", "sample_input": "3\n2 4 6\n"}, "reference_outputs": ["22\n"], "source_document_id": "p02905", "source_text": "Score : 700 points\n\nProblem Statement\n\nWe have an integer sequence of length N: A_0,A_1,\\cdots,A_{N-1}.\n\nFind the following sum (\\mathrm{lcm}(a, b) denotes the least common multiple of a and b):\n\n\\sum_{i=0}^{N-2} \\sum_{j=i+1}^{N-1} \\mathrm{lcm}(A_i,A_j)\n\nSince the answer may be enormous, compute it modulo 998244353.\n\nConstraints\n\n1 \\leq N \\leq 200000\n\n1 \\leq A_i \\leq 1000000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_0\\ A_1\\ \\cdots\\ A_{N-1}\n\nOutput\n\nPrint the sum modulo 998244353.\n\nSample Input 1\n\n3\n2 4 6\n\nSample Output 1\n\n22\n\n\\mathrm{lcm}(2,4)+\\mathrm{lcm}(2,6)+\\mathrm{lcm}(4,6)=4+6+12=22.\n\nSample Input 2\n\n8\n1 2 3 4 6 8 12 12\n\nSample Output 2\n\n313\n\nSample Input 3\n\n10\n356822 296174 484500 710640 518322 888250 259161 609120 592348 713644\n\nSample Output 3\n\n353891724", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7327, "cpu_time_ms": 486, "memory_kb": 35424}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s165940275", "group_id": "codeNet:p02906", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Disjoint set by Union-Find algorithm\n;;;\n\n(defstruct (disjoint-set\n (:constructor make-disjoint-set\n (size &aux (data (make-array size :element-type 'fixnum :initial-element -1))))\n (:conc-name ds-))\n (data nil :type (simple-array fixnum (*))))\n\n(declaim (ftype (function * (values (mod #.array-total-size-limit) &optional)) ds-root))\n(defun ds-root (disjoint-set x)\n \"Returns the root of X.\"\n (declare (optimize (speed 3))\n ((mod #.array-total-size-limit) x))\n (let ((data (ds-data disjoint-set)))\n (if (< (aref data x) 0)\n x\n (setf (aref data x)\n (ds-root disjoint-set (aref data x))))))\n\n(declaim (inline ds-unite!))\n(defun ds-unite! (disjoint-set x1 x2)\n \"Destructively unites X1 and X2 and returns true iff X1 and X2 become\nconnected for the first time.\"\n (let ((root1 (ds-root disjoint-set x1))\n (root2 (ds-root disjoint-set x2)))\n (unless (= root1 root2)\n (let ((data (ds-data disjoint-set)))\n ;; ensure the size of root1 >= the size of root2\n (when (> (aref data root1) (aref data root2))\n (rotatef root1 root2))\n (incf (aref data root1) (aref data root2))\n (setf (aref data root2) root1)))))\n\n(declaim (inline ds-connected-p))\n(defun ds-connected-p (disjoint-set x1 x2)\n \"Returns true iff X1 and X2 have the same root.\"\n (= (ds-root disjoint-set x1) (ds-root disjoint-set x2)))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (q (read))\n (as (make-array q :element-type 'uint31))\n (bs (make-array q :element-type 'uint31))\n (cs (make-array q :element-type 'uint31))\n (dset (make-disjoint-set n))\n (table (make-hash-table :test #'eq :size n)))\n (declare (uint31 n q)\n (uint62 m))\n (dotimes (i q)\n (let ((a (read-fixnum))\n (b (read-fixnum))\n (c (read-fixnum)))\n (setf (aref as i) a\n (aref bs i) b\n (aref cs i) c)\n (when (zerop c)\n (ds-unite! dset a b))))\n (dotimes (i n)\n (setf (gethash (ds-root dset i) table) t))\n (let ((k (hash-table-count table)))\n (declare (uint31 k))\n (write-line\n (cond ((= m (- n 1))\n (if (zerop (count 1 cs))\n \"Yes\"\n \"No\"))\n ((loop for i below q\n for a = (aref as i)\n for b = (aref bs i)\n for c = (aref cs i)\n thereis (and (= c 1)\n (ds-connected-p dset a b)))\n \"No\")\n ((<= m (+ n (floor (* k (- k 3)) 2)))\n \"Yes\")\n (t \"No\"))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1569631766, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02906.html", "problem_id": "p02906", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02906/input.txt", "sample_output_relpath": "derived/input_output/data/p02906/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02906/Lisp/s165940275.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s165940275", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Disjoint set by Union-Find algorithm\n;;;\n\n(defstruct (disjoint-set\n (:constructor make-disjoint-set\n (size &aux (data (make-array size :element-type 'fixnum :initial-element -1))))\n (:conc-name ds-))\n (data nil :type (simple-array fixnum (*))))\n\n(declaim (ftype (function * (values (mod #.array-total-size-limit) &optional)) ds-root))\n(defun ds-root (disjoint-set x)\n \"Returns the root of X.\"\n (declare (optimize (speed 3))\n ((mod #.array-total-size-limit) x))\n (let ((data (ds-data disjoint-set)))\n (if (< (aref data x) 0)\n x\n (setf (aref data x)\n (ds-root disjoint-set (aref data x))))))\n\n(declaim (inline ds-unite!))\n(defun ds-unite! (disjoint-set x1 x2)\n \"Destructively unites X1 and X2 and returns true iff X1 and X2 become\nconnected for the first time.\"\n (let ((root1 (ds-root disjoint-set x1))\n (root2 (ds-root disjoint-set x2)))\n (unless (= root1 root2)\n (let ((data (ds-data disjoint-set)))\n ;; ensure the size of root1 >= the size of root2\n (when (> (aref data root1) (aref data root2))\n (rotatef root1 root2))\n (incf (aref data root1) (aref data root2))\n (setf (aref data root2) root1)))))\n\n(declaim (inline ds-connected-p))\n(defun ds-connected-p (disjoint-set x1 x2)\n \"Returns true iff X1 and X2 have the same root.\"\n (= (ds-root disjoint-set x1) (ds-root disjoint-set x2)))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (q (read))\n (as (make-array q :element-type 'uint31))\n (bs (make-array q :element-type 'uint31))\n (cs (make-array q :element-type 'uint31))\n (dset (make-disjoint-set n))\n (table (make-hash-table :test #'eq :size n)))\n (declare (uint31 n q)\n (uint62 m))\n (dotimes (i q)\n (let ((a (read-fixnum))\n (b (read-fixnum))\n (c (read-fixnum)))\n (setf (aref as i) a\n (aref bs i) b\n (aref cs i) c)\n (when (zerop c)\n (ds-unite! dset a b))))\n (dotimes (i n)\n (setf (gethash (ds-root dset i) table) t))\n (let ((k (hash-table-count table)))\n (declare (uint31 k))\n (write-line\n (cond ((= m (- n 1))\n (if (zerop (count 1 cs))\n \"Yes\"\n \"No\"))\n ((loop for i below q\n for a = (aref as i)\n for b = (aref bs i)\n for c = (aref cs i)\n thereis (and (= c 1)\n (ds-connected-p dset a b)))\n \"No\")\n ((<= m (+ n (floor (* k (- k 3)) 2)))\n \"Yes\")\n (t \"No\"))))))\n\n#-swank (main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nSnuke's mother gave Snuke an undirected graph consisting of N vertices numbered 0 to N-1 and M edges.\nThis graph was connected and contained no parallel edges or self-loops.\n\nOne day, Snuke broke this graph.\nFortunately, he remembered Q clues about the graph.\nThe i-th clue (0 \\leq i \\leq Q-1) is represented as integers A_i,B_i,C_i and means the following:\n\nIf C_i=0: there was exactly one simple path (a path that never visits the same vertex twice) from Vertex A_i to B_i.\n\nIf C_i=1: there were two or more simple paths from Vertex A_i to B_i.\n\nSnuke is not sure if his memory is correct, and worried whether there is a graph that matches these Q clues.\nDetermine if there exists a graph that matches Snuke's memory.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\nN-1 \\leq M \\leq N \\times (N-1)/2\n\n1 \\leq Q \\leq 10^5\n\n0 \\leq A_i,B_i \\leq N-1\n\nA_i \\neq B_i\n\n0 \\leq C_i \\leq 1\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M Q\nA_0 B_0 C_0\nA_1 B_1 C_1\n\\vdots\nA_{Q-1} B_{Q-1} C_{Q-1}\n\nOutput\n\nIf there exists a graph that matches Snuke's memory, print Yes; otherwise, print No.\n\nSample Input 1\n\n5 5 3\n0 1 0\n1 2 1\n2 3 0\n\nSample Output 1\n\nYes\n\nFor example, consider a graph with edges (0,1),(1,2),(1,4),(2,3),(2,4). This graph matches the clues.\n\nSample Input 2\n\n4 4 3\n0 1 0\n1 2 1\n2 3 0\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n10 9 9\n7 6 0\n4 5 1\n9 7 0\n2 9 0\n2 3 0\n4 1 0\n8 0 0\n9 1 0\n3 0 0\n\nSample Output 3\n\nNo", "sample_input": "5 5 3\n0 1 0\n1 2 1\n2 3 0\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02906", "source_text": "Score : 700 points\n\nProblem Statement\n\nSnuke's mother gave Snuke an undirected graph consisting of N vertices numbered 0 to N-1 and M edges.\nThis graph was connected and contained no parallel edges or self-loops.\n\nOne day, Snuke broke this graph.\nFortunately, he remembered Q clues about the graph.\nThe i-th clue (0 \\leq i \\leq Q-1) is represented as integers A_i,B_i,C_i and means the following:\n\nIf C_i=0: there was exactly one simple path (a path that never visits the same vertex twice) from Vertex A_i to B_i.\n\nIf C_i=1: there were two or more simple paths from Vertex A_i to B_i.\n\nSnuke is not sure if his memory is correct, and worried whether there is a graph that matches these Q clues.\nDetermine if there exists a graph that matches Snuke's memory.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\nN-1 \\leq M \\leq N \\times (N-1)/2\n\n1 \\leq Q \\leq 10^5\n\n0 \\leq A_i,B_i \\leq N-1\n\nA_i \\neq B_i\n\n0 \\leq C_i \\leq 1\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M Q\nA_0 B_0 C_0\nA_1 B_1 C_1\n\\vdots\nA_{Q-1} B_{Q-1} C_{Q-1}\n\nOutput\n\nIf there exists a graph that matches Snuke's memory, print Yes; otherwise, print No.\n\nSample Input 1\n\n5 5 3\n0 1 0\n1 2 1\n2 3 0\n\nSample Output 1\n\nYes\n\nFor example, consider a graph with edges (0,1),(1,2),(1,4),(2,3),(2,4). This graph matches the clues.\n\nSample Input 2\n\n4 4 3\n0 1 0\n1 2 1\n2 3 0\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n10 9 9\n7 6 0\n4 5 1\n9 7 0\n2 9 0\n2 3 0\n4 1 0\n8 0 0\n9 1 0\n3 0 0\n\nSample Output 3\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5142, "cpu_time_ms": 124, "memory_kb": 23144}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s204498018", "group_id": "codeNet:p02906", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Disjoint set by Union-Find algorithm\n;;;\n\n(defstruct (disjoint-set\n (:constructor make-disjoint-set\n (size &aux (data (make-array size :element-type 'fixnum :initial-element -1))))\n (:conc-name ds-))\n (data nil :type (simple-array fixnum (*))))\n\n(declaim (ftype (function * (values (mod #.array-total-size-limit) &optional)) ds-root))\n(defun ds-root (disjoint-set x)\n \"Returns the root of X.\"\n (declare (optimize (speed 3))\n ((mod #.array-total-size-limit) x))\n (let ((data (ds-data disjoint-set)))\n (if (< (aref data x) 0)\n x\n (setf (aref data x)\n (ds-root disjoint-set (aref data x))))))\n\n(declaim (inline ds-unite!))\n(defun ds-unite! (disjoint-set x1 x2)\n \"Destructively unites X1 and X2 and returns true iff X1 and X2 become\nconnected for the first time.\"\n (let ((root1 (ds-root disjoint-set x1))\n (root2 (ds-root disjoint-set x2)))\n (unless (= root1 root2)\n (let ((data (ds-data disjoint-set)))\n ;; ensure the size of root1 >= the size of root2\n (when (> (aref data root1) (aref data root2))\n (rotatef root1 root2))\n (incf (aref data root1) (aref data root2))\n (setf (aref data root2) root1)))))\n\n(declaim (inline ds-connected-p))\n(defun ds-connected-p (disjoint-set x1 x2)\n \"Returns true iff X1 and X2 have the same root.\"\n (= (ds-root disjoint-set x1) (ds-root disjoint-set x2)))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (q (read))\n (as (make-array q :element-type 'uint31))\n (bs (make-array q :element-type 'uint31))\n (cs (make-array q :element-type 'uint31))\n (dset (make-disjoint-set n))\n (table (make-hash-table :test #'eq :size n)))\n (declare (uint31 n q)\n (uint62 m))\n (dotimes (i q)\n (let ((a (read-fixnum))\n (b (read-fixnum))\n (c (read-fixnum)))\n (setf (aref as i) a\n (aref bs i) b\n (aref cs i) c)\n (when (zerop c)\n (ds-unite! dset b c))))\n (dotimes (i n)\n (setf (gethash (ds-root dset i) table) t))\n (let ((k (hash-table-count table)))\n (declare (uint31 k))\n (write-line\n (cond ((= m (- n 1))\n (if (zerop (count 1 cs))\n \"Yes\"\n \"No\"))\n ((loop for i below q\n for a = (aref as i)\n for b = (aref bs i)\n for c = (aref cs i)\n thereis (and (= c 1)\n (ds-connected-p dset a b)))\n \"No\")\n (;; N-k+k <= M <= N-k + 1/2k(k-1)\n (<= m (+ n (floor (* k (- k 3)) 2)))\n \"Yes\")\n (t (error \"Huh?\");; \"No\"\n ))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1569631073, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02906.html", "problem_id": "p02906", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02906/input.txt", "sample_output_relpath": "derived/input_output/data/p02906/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02906/Lisp/s204498018.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s204498018", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Disjoint set by Union-Find algorithm\n;;;\n\n(defstruct (disjoint-set\n (:constructor make-disjoint-set\n (size &aux (data (make-array size :element-type 'fixnum :initial-element -1))))\n (:conc-name ds-))\n (data nil :type (simple-array fixnum (*))))\n\n(declaim (ftype (function * (values (mod #.array-total-size-limit) &optional)) ds-root))\n(defun ds-root (disjoint-set x)\n \"Returns the root of X.\"\n (declare (optimize (speed 3))\n ((mod #.array-total-size-limit) x))\n (let ((data (ds-data disjoint-set)))\n (if (< (aref data x) 0)\n x\n (setf (aref data x)\n (ds-root disjoint-set (aref data x))))))\n\n(declaim (inline ds-unite!))\n(defun ds-unite! (disjoint-set x1 x2)\n \"Destructively unites X1 and X2 and returns true iff X1 and X2 become\nconnected for the first time.\"\n (let ((root1 (ds-root disjoint-set x1))\n (root2 (ds-root disjoint-set x2)))\n (unless (= root1 root2)\n (let ((data (ds-data disjoint-set)))\n ;; ensure the size of root1 >= the size of root2\n (when (> (aref data root1) (aref data root2))\n (rotatef root1 root2))\n (incf (aref data root1) (aref data root2))\n (setf (aref data root2) root1)))))\n\n(declaim (inline ds-connected-p))\n(defun ds-connected-p (disjoint-set x1 x2)\n \"Returns true iff X1 and X2 have the same root.\"\n (= (ds-root disjoint-set x1) (ds-root disjoint-set x2)))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (q (read))\n (as (make-array q :element-type 'uint31))\n (bs (make-array q :element-type 'uint31))\n (cs (make-array q :element-type 'uint31))\n (dset (make-disjoint-set n))\n (table (make-hash-table :test #'eq :size n)))\n (declare (uint31 n q)\n (uint62 m))\n (dotimes (i q)\n (let ((a (read-fixnum))\n (b (read-fixnum))\n (c (read-fixnum)))\n (setf (aref as i) a\n (aref bs i) b\n (aref cs i) c)\n (when (zerop c)\n (ds-unite! dset b c))))\n (dotimes (i n)\n (setf (gethash (ds-root dset i) table) t))\n (let ((k (hash-table-count table)))\n (declare (uint31 k))\n (write-line\n (cond ((= m (- n 1))\n (if (zerop (count 1 cs))\n \"Yes\"\n \"No\"))\n ((loop for i below q\n for a = (aref as i)\n for b = (aref bs i)\n for c = (aref cs i)\n thereis (and (= c 1)\n (ds-connected-p dset a b)))\n \"No\")\n (;; N-k+k <= M <= N-k + 1/2k(k-1)\n (<= m (+ n (floor (* k (- k 3)) 2)))\n \"Yes\")\n (t (error \"Huh?\");; \"No\"\n ))))))\n\n#-swank (main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nSnuke's mother gave Snuke an undirected graph consisting of N vertices numbered 0 to N-1 and M edges.\nThis graph was connected and contained no parallel edges or self-loops.\n\nOne day, Snuke broke this graph.\nFortunately, he remembered Q clues about the graph.\nThe i-th clue (0 \\leq i \\leq Q-1) is represented as integers A_i,B_i,C_i and means the following:\n\nIf C_i=0: there was exactly one simple path (a path that never visits the same vertex twice) from Vertex A_i to B_i.\n\nIf C_i=1: there were two or more simple paths from Vertex A_i to B_i.\n\nSnuke is not sure if his memory is correct, and worried whether there is a graph that matches these Q clues.\nDetermine if there exists a graph that matches Snuke's memory.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\nN-1 \\leq M \\leq N \\times (N-1)/2\n\n1 \\leq Q \\leq 10^5\n\n0 \\leq A_i,B_i \\leq N-1\n\nA_i \\neq B_i\n\n0 \\leq C_i \\leq 1\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M Q\nA_0 B_0 C_0\nA_1 B_1 C_1\n\\vdots\nA_{Q-1} B_{Q-1} C_{Q-1}\n\nOutput\n\nIf there exists a graph that matches Snuke's memory, print Yes; otherwise, print No.\n\nSample Input 1\n\n5 5 3\n0 1 0\n1 2 1\n2 3 0\n\nSample Output 1\n\nYes\n\nFor example, consider a graph with edges (0,1),(1,2),(1,4),(2,3),(2,4). This graph matches the clues.\n\nSample Input 2\n\n4 4 3\n0 1 0\n1 2 1\n2 3 0\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n10 9 9\n7 6 0\n4 5 1\n9 7 0\n2 9 0\n2 3 0\n4 1 0\n8 0 0\n9 1 0\n3 0 0\n\nSample Output 3\n\nNo", "sample_input": "5 5 3\n0 1 0\n1 2 1\n2 3 0\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02906", "source_text": "Score : 700 points\n\nProblem Statement\n\nSnuke's mother gave Snuke an undirected graph consisting of N vertices numbered 0 to N-1 and M edges.\nThis graph was connected and contained no parallel edges or self-loops.\n\nOne day, Snuke broke this graph.\nFortunately, he remembered Q clues about the graph.\nThe i-th clue (0 \\leq i \\leq Q-1) is represented as integers A_i,B_i,C_i and means the following:\n\nIf C_i=0: there was exactly one simple path (a path that never visits the same vertex twice) from Vertex A_i to B_i.\n\nIf C_i=1: there were two or more simple paths from Vertex A_i to B_i.\n\nSnuke is not sure if his memory is correct, and worried whether there is a graph that matches these Q clues.\nDetermine if there exists a graph that matches Snuke's memory.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\nN-1 \\leq M \\leq N \\times (N-1)/2\n\n1 \\leq Q \\leq 10^5\n\n0 \\leq A_i,B_i \\leq N-1\n\nA_i \\neq B_i\n\n0 \\leq C_i \\leq 1\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M Q\nA_0 B_0 C_0\nA_1 B_1 C_1\n\\vdots\nA_{Q-1} B_{Q-1} C_{Q-1}\n\nOutput\n\nIf there exists a graph that matches Snuke's memory, print Yes; otherwise, print No.\n\nSample Input 1\n\n5 5 3\n0 1 0\n1 2 1\n2 3 0\n\nSample Output 1\n\nYes\n\nFor example, consider a graph with edges (0,1),(1,2),(1,4),(2,3),(2,4). This graph matches the clues.\n\nSample Input 2\n\n4 4 3\n0 1 0\n1 2 1\n2 3 0\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n10 9 9\n7 6 0\n4 5 1\n9 7 0\n2 9 0\n2 3 0\n4 1 0\n8 0 0\n9 1 0\n3 0 0\n\nSample Output 3\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5223, "cpu_time_ms": 300, "memory_kb": 30176}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s683752422", "group_id": "codeNet:p02906", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Disjoint set by Union-Find algorithm\n;;;\n\n(defstruct (disjoint-set\n (:constructor make-disjoint-set\n (size &aux (data (make-array size :element-type 'fixnum :initial-element -1))))\n (:conc-name ds-))\n (data nil :type (simple-array fixnum (*))))\n\n(declaim (ftype (function * (values (mod #.array-total-size-limit) &optional)) ds-root))\n(defun ds-root (disjoint-set x)\n \"Returns the root of X.\"\n (declare (optimize (speed 3))\n ((mod #.array-total-size-limit) x))\n (let ((data (ds-data disjoint-set)))\n (if (< (aref data x) 0)\n x\n (setf (aref data x)\n (ds-root disjoint-set (aref data x))))))\n\n(declaim (inline ds-unite!))\n(defun ds-unite! (disjoint-set x1 x2)\n \"Destructively unites X1 and X2 and returns true iff X1 and X2 become\nconnected for the first time.\"\n (let ((root1 (ds-root disjoint-set x1))\n (root2 (ds-root disjoint-set x2)))\n (unless (= root1 root2)\n (let ((data (ds-data disjoint-set)))\n ;; ensure the size of root1 >= the size of root2\n (when (> (aref data root1) (aref data root2))\n (rotatef root1 root2))\n (incf (aref data root1) (aref data root2))\n (setf (aref data root2) root1)))))\n\n(declaim (inline ds-connected-p))\n(defun ds-connected-p (disjoint-set x1 x2)\n \"Returns true iff X1 and X2 have the same root.\"\n (= (ds-root disjoint-set x1) (ds-root disjoint-set x2)))\n\n(declaim (inline ds-size))\n(defun ds-size (disjoint-set x)\n \"Returns the size of the connected component to which X belongs.\"\n (- (aref (ds-data disjoint-set)\n (ds-root disjoint-set x))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (q (read))\n (as (make-array q :element-type 'uint31))\n (bs (make-array q :element-type 'uint31))\n (cs (make-array q :element-type 'uint31))\n (dset (make-disjoint-set n))\n (table (make-hash-table :test #'eq :size n)))\n (declare (uint31 n q)\n (uint62 m))\n (dotimes (i q)\n (let ((a (read-fixnum))\n (b (read-fixnum))\n (c (read-fixnum)))\n (setf (aref as i) a\n (aref bs i) b\n (aref cs i) c)\n (when (zerop c)\n (ds-unite! dset b c))))\n (dotimes (i n)\n (setf (gethash (ds-root dset i) table) t))\n (let ((k (hash-table-count table)))\n (declare (uint31 k))\n (write-line\n (cond ((= m (- n 1))\n (if (zerop (count 1 cs))\n \"Yes\"\n \"No\"))\n ((loop for i below q\n for a = (aref as i)\n for b = (aref bs i)\n for c = (aref cs i)\n thereis (and (= c 1)\n (ds-connected-p dset a b)))\n \"No\")\n (;; N-k+k <= M <= N-k + 1/2k(k-1)\n (<= m (+ n (floor (* k (- k 3)) 2)))\n \"Yes\")\n (t \"No\"))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1569630999, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02906.html", "problem_id": "p02906", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02906/input.txt", "sample_output_relpath": "derived/input_output/data/p02906/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02906/Lisp/s683752422.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s683752422", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Disjoint set by Union-Find algorithm\n;;;\n\n(defstruct (disjoint-set\n (:constructor make-disjoint-set\n (size &aux (data (make-array size :element-type 'fixnum :initial-element -1))))\n (:conc-name ds-))\n (data nil :type (simple-array fixnum (*))))\n\n(declaim (ftype (function * (values (mod #.array-total-size-limit) &optional)) ds-root))\n(defun ds-root (disjoint-set x)\n \"Returns the root of X.\"\n (declare (optimize (speed 3))\n ((mod #.array-total-size-limit) x))\n (let ((data (ds-data disjoint-set)))\n (if (< (aref data x) 0)\n x\n (setf (aref data x)\n (ds-root disjoint-set (aref data x))))))\n\n(declaim (inline ds-unite!))\n(defun ds-unite! (disjoint-set x1 x2)\n \"Destructively unites X1 and X2 and returns true iff X1 and X2 become\nconnected for the first time.\"\n (let ((root1 (ds-root disjoint-set x1))\n (root2 (ds-root disjoint-set x2)))\n (unless (= root1 root2)\n (let ((data (ds-data disjoint-set)))\n ;; ensure the size of root1 >= the size of root2\n (when (> (aref data root1) (aref data root2))\n (rotatef root1 root2))\n (incf (aref data root1) (aref data root2))\n (setf (aref data root2) root1)))))\n\n(declaim (inline ds-connected-p))\n(defun ds-connected-p (disjoint-set x1 x2)\n \"Returns true iff X1 and X2 have the same root.\"\n (= (ds-root disjoint-set x1) (ds-root disjoint-set x2)))\n\n(declaim (inline ds-size))\n(defun ds-size (disjoint-set x)\n \"Returns the size of the connected component to which X belongs.\"\n (- (aref (ds-data disjoint-set)\n (ds-root disjoint-set x))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (q (read))\n (as (make-array q :element-type 'uint31))\n (bs (make-array q :element-type 'uint31))\n (cs (make-array q :element-type 'uint31))\n (dset (make-disjoint-set n))\n (table (make-hash-table :test #'eq :size n)))\n (declare (uint31 n q)\n (uint62 m))\n (dotimes (i q)\n (let ((a (read-fixnum))\n (b (read-fixnum))\n (c (read-fixnum)))\n (setf (aref as i) a\n (aref bs i) b\n (aref cs i) c)\n (when (zerop c)\n (ds-unite! dset b c))))\n (dotimes (i n)\n (setf (gethash (ds-root dset i) table) t))\n (let ((k (hash-table-count table)))\n (declare (uint31 k))\n (write-line\n (cond ((= m (- n 1))\n (if (zerop (count 1 cs))\n \"Yes\"\n \"No\"))\n ((loop for i below q\n for a = (aref as i)\n for b = (aref bs i)\n for c = (aref cs i)\n thereis (and (= c 1)\n (ds-connected-p dset a b)))\n \"No\")\n (;; N-k+k <= M <= N-k + 1/2k(k-1)\n (<= m (+ n (floor (* k (- k 3)) 2)))\n \"Yes\")\n (t \"No\"))))))\n\n#-swank (main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nSnuke's mother gave Snuke an undirected graph consisting of N vertices numbered 0 to N-1 and M edges.\nThis graph was connected and contained no parallel edges or self-loops.\n\nOne day, Snuke broke this graph.\nFortunately, he remembered Q clues about the graph.\nThe i-th clue (0 \\leq i \\leq Q-1) is represented as integers A_i,B_i,C_i and means the following:\n\nIf C_i=0: there was exactly one simple path (a path that never visits the same vertex twice) from Vertex A_i to B_i.\n\nIf C_i=1: there were two or more simple paths from Vertex A_i to B_i.\n\nSnuke is not sure if his memory is correct, and worried whether there is a graph that matches these Q clues.\nDetermine if there exists a graph that matches Snuke's memory.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\nN-1 \\leq M \\leq N \\times (N-1)/2\n\n1 \\leq Q \\leq 10^5\n\n0 \\leq A_i,B_i \\leq N-1\n\nA_i \\neq B_i\n\n0 \\leq C_i \\leq 1\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M Q\nA_0 B_0 C_0\nA_1 B_1 C_1\n\\vdots\nA_{Q-1} B_{Q-1} C_{Q-1}\n\nOutput\n\nIf there exists a graph that matches Snuke's memory, print Yes; otherwise, print No.\n\nSample Input 1\n\n5 5 3\n0 1 0\n1 2 1\n2 3 0\n\nSample Output 1\n\nYes\n\nFor example, consider a graph with edges (0,1),(1,2),(1,4),(2,3),(2,4). This graph matches the clues.\n\nSample Input 2\n\n4 4 3\n0 1 0\n1 2 1\n2 3 0\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n10 9 9\n7 6 0\n4 5 1\n9 7 0\n2 9 0\n2 3 0\n4 1 0\n8 0 0\n9 1 0\n3 0 0\n\nSample Output 3\n\nNo", "sample_input": "5 5 3\n0 1 0\n1 2 1\n2 3 0\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02906", "source_text": "Score : 700 points\n\nProblem Statement\n\nSnuke's mother gave Snuke an undirected graph consisting of N vertices numbered 0 to N-1 and M edges.\nThis graph was connected and contained no parallel edges or self-loops.\n\nOne day, Snuke broke this graph.\nFortunately, he remembered Q clues about the graph.\nThe i-th clue (0 \\leq i \\leq Q-1) is represented as integers A_i,B_i,C_i and means the following:\n\nIf C_i=0: there was exactly one simple path (a path that never visits the same vertex twice) from Vertex A_i to B_i.\n\nIf C_i=1: there were two or more simple paths from Vertex A_i to B_i.\n\nSnuke is not sure if his memory is correct, and worried whether there is a graph that matches these Q clues.\nDetermine if there exists a graph that matches Snuke's memory.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\nN-1 \\leq M \\leq N \\times (N-1)/2\n\n1 \\leq Q \\leq 10^5\n\n0 \\leq A_i,B_i \\leq N-1\n\nA_i \\neq B_i\n\n0 \\leq C_i \\leq 1\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M Q\nA_0 B_0 C_0\nA_1 B_1 C_1\n\\vdots\nA_{Q-1} B_{Q-1} C_{Q-1}\n\nOutput\n\nIf there exists a graph that matches Snuke's memory, print Yes; otherwise, print No.\n\nSample Input 1\n\n5 5 3\n0 1 0\n1 2 1\n2 3 0\n\nSample Output 1\n\nYes\n\nFor example, consider a graph with edges (0,1),(1,2),(1,4),(2,3),(2,4). This graph matches the clues.\n\nSample Input 2\n\n4 4 3\n0 1 0\n1 2 1\n2 3 0\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n10 9 9\n7 6 0\n4 5 1\n9 7 0\n2 9 0\n2 3 0\n4 1 0\n8 0 0\n9 1 0\n3 0 0\n\nSample Output 3\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5390, "cpu_time_ms": 306, "memory_kb": 30180}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s810063069", "group_id": "codeNet:p02906", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Disjoint set by Union-Find algorithm\n;;;\n\n(defstruct (disjoint-set\n (:constructor make-disjoint-set\n (size &aux (data (make-array size :element-type 'fixnum :initial-element -1))))\n (:conc-name ds-))\n (data nil :type (simple-array fixnum (*))))\n\n(declaim (ftype (function * (values (mod #.array-total-size-limit) &optional)) ds-root))\n(defun ds-root (x disjoint-set)\n \"Returns the root of X.\"\n (declare (optimize (speed 3))\n ((mod #.array-total-size-limit) x))\n (let ((data (ds-data disjoint-set)))\n (if (< (aref data x) 0)\n x\n (setf (aref data x)\n (ds-root (aref data x) disjoint-set)))))\n\n(declaim (inline ds-unite!))\n(defun ds-unite! (x1 x2 disjoint-set)\n \"Destructively unites X1 and X2 and returns true iff X1 and X2 become\nconnected for the first time.\"\n (let ((root1 (ds-root x1 disjoint-set))\n (root2 (ds-root x2 disjoint-set)))\n (unless (= root1 root2)\n (let ((data (ds-data disjoint-set)))\n ;; ensure the size of root1 >= the size of root2\n (when (> (aref data root1) (aref data root2))\n (rotatef root1 root2))\n (incf (aref data root1) (aref data root2))\n (setf (aref data root2) root1)))))\n\n(declaim (inline ds-connected-p))\n(defun ds-connected-p (x1 x2 disjoint-set)\n \"Returns true iff X1 and X2 have the same root.\"\n (= (ds-root x1 disjoint-set) (ds-root x2 disjoint-set)))\n\n(declaim (inline ds-size))\n(defun ds-size (x disjoint-set)\n \"Returns the size of the connected component to which X belongs.\"\n (- (aref (ds-data disjoint-set)\n (ds-root x disjoint-set))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline =>))\n(defun => (x y)\n (or (not x) y))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (q (read))\n (as (make-array q :element-type 'uint32))\n (bs (make-array q :element-type 'uint32))\n (cs (make-array q :element-type 'uint32))\n (dset (make-disjoint-set n))\n (table (make-hash-table :test #'eq :size n)))\n (declare (uint31 n m q))\n (dotimes (i q)\n (let ((a (read-fixnum ))\n (b (read-fixnum))\n (c (read-fixnum)))\n (setf (aref as i) a\n (aref bs i) b\n (aref cs i) c)\n (when (zerop c)\n (ds-unite! b c dset))))\n (dotimes (i n)\n (setf (gethash (ds-root i dset) table) t))\n (let ((k (hash-table-count table)))\n (declare (uint31 k))\n (write-line\n (cond ((= m (- n 1))\n (if (zerop (count 1 cs))\n \"Yes\"\n \"No\"))\n ((loop for i below q\n for a = (aref as i)\n for b = (aref bs i)\n for c = (aref cs i)\n thereis (and (= c 1)\n (ds-connected-p a b dset)))\n \"No\")\n (;; N-k+k <= M <= N-k + 1/2k(k-1)\n (<= m (+ n (floor (* k (- k 3)) 2)))\n \"Yes\")\n (t \"No\"))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1569630727, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02906.html", "problem_id": "p02906", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02906/input.txt", "sample_output_relpath": "derived/input_output/data/p02906/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02906/Lisp/s810063069.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s810063069", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Disjoint set by Union-Find algorithm\n;;;\n\n(defstruct (disjoint-set\n (:constructor make-disjoint-set\n (size &aux (data (make-array size :element-type 'fixnum :initial-element -1))))\n (:conc-name ds-))\n (data nil :type (simple-array fixnum (*))))\n\n(declaim (ftype (function * (values (mod #.array-total-size-limit) &optional)) ds-root))\n(defun ds-root (x disjoint-set)\n \"Returns the root of X.\"\n (declare (optimize (speed 3))\n ((mod #.array-total-size-limit) x))\n (let ((data (ds-data disjoint-set)))\n (if (< (aref data x) 0)\n x\n (setf (aref data x)\n (ds-root (aref data x) disjoint-set)))))\n\n(declaim (inline ds-unite!))\n(defun ds-unite! (x1 x2 disjoint-set)\n \"Destructively unites X1 and X2 and returns true iff X1 and X2 become\nconnected for the first time.\"\n (let ((root1 (ds-root x1 disjoint-set))\n (root2 (ds-root x2 disjoint-set)))\n (unless (= root1 root2)\n (let ((data (ds-data disjoint-set)))\n ;; ensure the size of root1 >= the size of root2\n (when (> (aref data root1) (aref data root2))\n (rotatef root1 root2))\n (incf (aref data root1) (aref data root2))\n (setf (aref data root2) root1)))))\n\n(declaim (inline ds-connected-p))\n(defun ds-connected-p (x1 x2 disjoint-set)\n \"Returns true iff X1 and X2 have the same root.\"\n (= (ds-root x1 disjoint-set) (ds-root x2 disjoint-set)))\n\n(declaim (inline ds-size))\n(defun ds-size (x disjoint-set)\n \"Returns the size of the connected component to which X belongs.\"\n (- (aref (ds-data disjoint-set)\n (ds-root x disjoint-set))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline =>))\n(defun => (x y)\n (or (not x) y))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (q (read))\n (as (make-array q :element-type 'uint32))\n (bs (make-array q :element-type 'uint32))\n (cs (make-array q :element-type 'uint32))\n (dset (make-disjoint-set n))\n (table (make-hash-table :test #'eq :size n)))\n (declare (uint31 n m q))\n (dotimes (i q)\n (let ((a (read-fixnum ))\n (b (read-fixnum))\n (c (read-fixnum)))\n (setf (aref as i) a\n (aref bs i) b\n (aref cs i) c)\n (when (zerop c)\n (ds-unite! b c dset))))\n (dotimes (i n)\n (setf (gethash (ds-root i dset) table) t))\n (let ((k (hash-table-count table)))\n (declare (uint31 k))\n (write-line\n (cond ((= m (- n 1))\n (if (zerop (count 1 cs))\n \"Yes\"\n \"No\"))\n ((loop for i below q\n for a = (aref as i)\n for b = (aref bs i)\n for c = (aref cs i)\n thereis (and (= c 1)\n (ds-connected-p a b dset)))\n \"No\")\n (;; N-k+k <= M <= N-k + 1/2k(k-1)\n (<= m (+ n (floor (* k (- k 3)) 2)))\n \"Yes\")\n (t \"No\"))))))\n\n#-swank (main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nSnuke's mother gave Snuke an undirected graph consisting of N vertices numbered 0 to N-1 and M edges.\nThis graph was connected and contained no parallel edges or self-loops.\n\nOne day, Snuke broke this graph.\nFortunately, he remembered Q clues about the graph.\nThe i-th clue (0 \\leq i \\leq Q-1) is represented as integers A_i,B_i,C_i and means the following:\n\nIf C_i=0: there was exactly one simple path (a path that never visits the same vertex twice) from Vertex A_i to B_i.\n\nIf C_i=1: there were two or more simple paths from Vertex A_i to B_i.\n\nSnuke is not sure if his memory is correct, and worried whether there is a graph that matches these Q clues.\nDetermine if there exists a graph that matches Snuke's memory.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\nN-1 \\leq M \\leq N \\times (N-1)/2\n\n1 \\leq Q \\leq 10^5\n\n0 \\leq A_i,B_i \\leq N-1\n\nA_i \\neq B_i\n\n0 \\leq C_i \\leq 1\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M Q\nA_0 B_0 C_0\nA_1 B_1 C_1\n\\vdots\nA_{Q-1} B_{Q-1} C_{Q-1}\n\nOutput\n\nIf there exists a graph that matches Snuke's memory, print Yes; otherwise, print No.\n\nSample Input 1\n\n5 5 3\n0 1 0\n1 2 1\n2 3 0\n\nSample Output 1\n\nYes\n\nFor example, consider a graph with edges (0,1),(1,2),(1,4),(2,3),(2,4). This graph matches the clues.\n\nSample Input 2\n\n4 4 3\n0 1 0\n1 2 1\n2 3 0\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n10 9 9\n7 6 0\n4 5 1\n9 7 0\n2 9 0\n2 3 0\n4 1 0\n8 0 0\n9 1 0\n3 0 0\n\nSample Output 3\n\nNo", "sample_input": "5 5 3\n0 1 0\n1 2 1\n2 3 0\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02906", "source_text": "Score : 700 points\n\nProblem Statement\n\nSnuke's mother gave Snuke an undirected graph consisting of N vertices numbered 0 to N-1 and M edges.\nThis graph was connected and contained no parallel edges or self-loops.\n\nOne day, Snuke broke this graph.\nFortunately, he remembered Q clues about the graph.\nThe i-th clue (0 \\leq i \\leq Q-1) is represented as integers A_i,B_i,C_i and means the following:\n\nIf C_i=0: there was exactly one simple path (a path that never visits the same vertex twice) from Vertex A_i to B_i.\n\nIf C_i=1: there were two or more simple paths from Vertex A_i to B_i.\n\nSnuke is not sure if his memory is correct, and worried whether there is a graph that matches these Q clues.\nDetermine if there exists a graph that matches Snuke's memory.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\nN-1 \\leq M \\leq N \\times (N-1)/2\n\n1 \\leq Q \\leq 10^5\n\n0 \\leq A_i,B_i \\leq N-1\n\nA_i \\neq B_i\n\n0 \\leq C_i \\leq 1\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M Q\nA_0 B_0 C_0\nA_1 B_1 C_1\n\\vdots\nA_{Q-1} B_{Q-1} C_{Q-1}\n\nOutput\n\nIf there exists a graph that matches Snuke's memory, print Yes; otherwise, print No.\n\nSample Input 1\n\n5 5 3\n0 1 0\n1 2 1\n2 3 0\n\nSample Output 1\n\nYes\n\nFor example, consider a graph with edges (0,1),(1,2),(1,4),(2,3),(2,4). This graph matches the clues.\n\nSample Input 2\n\n4 4 3\n0 1 0\n1 2 1\n2 3 0\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n10 9 9\n7 6 0\n4 5 1\n9 7 0\n2 9 0\n2 3 0\n4 1 0\n8 0 0\n9 1 0\n3 0 0\n\nSample Output 3\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5426, "cpu_time_ms": 279, "memory_kb": 30048}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s309086053", "group_id": "codeNet:p02909", "input_text": "(defun ans (w)\n (cond\n ((equal w \"Sunny\") \"Cloudy\")\n ((equal w \"Cloudy\") \"Rainy\")\n (t \"Sunny\")))\n\n(format t \"~a~%\" (ans (read-line)))", "language": "Lisp", "metadata": {"date": 1569012361, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02909.html", "problem_id": "p02909", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02909/input.txt", "sample_output_relpath": "derived/input_output/data/p02909/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02909/Lisp/s309086053.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s309086053", "user_id": "u358554431"}, "prompt_components": {"gold_output": "Cloudy\n", "input_to_evaluate": "(defun ans (w)\n (cond\n ((equal w \"Sunny\") \"Cloudy\")\n ((equal w \"Cloudy\") \"Rainy\")\n (t \"Sunny\")))\n\n(format t \"~a~%\" (ans (read-line)))", "problem_context": "Score: 100 points\n\nProblem Statement\n\nThe weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ...\n\nGiven is a string S representing the weather in the town today. Predict the weather tomorrow.\n\nConstraints\n\nS is Sunny, Cloudy, or Rainy.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint a string representing the expected weather tomorrow, in the same format in which input is given.\n\nSample Input 1\n\nSunny\n\nSample Output 1\n\nCloudy\n\nIn Takahashi's town, a sunny day is followed by a cloudy day.\n\nSample Input 2\n\nRainy\n\nSample Output 2\n\nSunny", "sample_input": "Sunny\n"}, "reference_outputs": ["Cloudy\n"], "source_document_id": "p02909", "source_text": "Score: 100 points\n\nProblem Statement\n\nThe weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ...\n\nGiven is a string S representing the weather in the town today. Predict the weather tomorrow.\n\nConstraints\n\nS is Sunny, Cloudy, or Rainy.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint a string representing the expected weather tomorrow, in the same format in which input is given.\n\nSample Input 1\n\nSunny\n\nSample Output 1\n\nCloudy\n\nIn Takahashi's town, a sunny day is followed by a cloudy day.\n\nSample Input 2\n\nRainy\n\nSample Output 2\n\nSunny", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 143, "cpu_time_ms": 8, "memory_kb": 3176}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s881910972", "group_id": "codeNet:p02909", "input_text": "(defun f(s)\n (if (string= s \"Sunny\")\n \"Cloudy\"\n (if (string= s \"Cloudy\")\n \"Rainy\"\n \"Sunny\")))\n(let ((line (read-line nil nil)))\n (format t \"~A\" (f line)))\n", "language": "Lisp", "metadata": {"date": 1568595919, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02909.html", "problem_id": "p02909", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02909/input.txt", "sample_output_relpath": "derived/input_output/data/p02909/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02909/Lisp/s881910972.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s881910972", "user_id": "u254205055"}, "prompt_components": {"gold_output": "Cloudy\n", "input_to_evaluate": "(defun f(s)\n (if (string= s \"Sunny\")\n \"Cloudy\"\n (if (string= s \"Cloudy\")\n \"Rainy\"\n \"Sunny\")))\n(let ((line (read-line nil nil)))\n (format t \"~A\" (f line)))\n", "problem_context": "Score: 100 points\n\nProblem Statement\n\nThe weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ...\n\nGiven is a string S representing the weather in the town today. Predict the weather tomorrow.\n\nConstraints\n\nS is Sunny, Cloudy, or Rainy.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint a string representing the expected weather tomorrow, in the same format in which input is given.\n\nSample Input 1\n\nSunny\n\nSample Output 1\n\nCloudy\n\nIn Takahashi's town, a sunny day is followed by a cloudy day.\n\nSample Input 2\n\nRainy\n\nSample Output 2\n\nSunny", "sample_input": "Sunny\n"}, "reference_outputs": ["Cloudy\n"], "source_document_id": "p02909", "source_text": "Score: 100 points\n\nProblem Statement\n\nThe weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ...\n\nGiven is a string S representing the weather in the town today. Predict the weather tomorrow.\n\nConstraints\n\nS is Sunny, Cloudy, or Rainy.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint a string representing the expected weather tomorrow, in the same format in which input is given.\n\nSample Input 1\n\nSunny\n\nSample Output 1\n\nCloudy\n\nIn Takahashi's town, a sunny day is followed by a cloudy day.\n\nSample Input 2\n\nRainy\n\nSample Output 2\n\nSunny", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 173, "cpu_time_ms": 124, "memory_kb": 10464}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s886833437", "group_id": "codeNet:p02911", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; Should we do this with UNWIND-PROTECT?\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (with-buffered-stdout\n (let* ((n (read))\n (k (read))\n (q (read))\n (dp (make-array n :element-type 'fixnum :initial-element (- k q))))\n (declare (uint62 n k q))\n (dotimes (i q)\n (let ((a (- (read-fixnum) 1)))\n (incf (aref dp a))))\n (dotimes (i n)\n (write-line\n (if (> (aref dp i) 0)\n \"Yes\"\n \"No\"))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1568602656, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02911.html", "problem_id": "p02911", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02911/input.txt", "sample_output_relpath": "derived/input_output/data/p02911/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02911/Lisp/s886833437.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s886833437", "user_id": "u352600849"}, "prompt_components": {"gold_output": "No\nNo\nYes\nNo\nNo\nNo\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; Should we do this with UNWIND-PROTECT?\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (with-buffered-stdout\n (let* ((n (read))\n (k (read))\n (q (read))\n (dp (make-array n :element-type 'fixnum :initial-element (- k q))))\n (declare (uint62 n k q))\n (dotimes (i q)\n (let ((a (- (read-fixnum) 1)))\n (incf (aref dp a))))\n (dotimes (i n)\n (write-line\n (if (> (aref dp i) 0)\n \"Yes\"\n \"No\"))))))\n\n#-swank (main)\n", "problem_context": "Score: 300 points\n\nProblem Statement\n\nTakahashi has decided to hold fastest-finger-fast quiz games. Kizahashi, who is in charge of making the scoreboard, is struggling to write the program that manages the players' scores in a game, which proceeds as follows.\n\nA game is played by N players, numbered 1 to N. At the beginning of a game, each player has K points.\n\nWhen a player correctly answers a question, each of the other N-1 players receives minus one (-1) point. There is no other factor that affects the players' scores.\n\nAt the end of a game, the players with 0 points or lower are eliminated, and the remaining players survive.\n\nIn the last game, the players gave a total of Q correct answers, the i-th of which was given by Player A_i.\nFor Kizahashi, write a program that determines whether each of the N players survived this game.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10^5\n\n1 \\leq K \\leq 10^9\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq A_i \\leq N\\ (1 \\leq i \\leq Q)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K Q\nA_1\nA_2\n.\n.\n.\nA_Q\n\nOutput\n\nPrint N lines. The i-th line should contain Yes if Player i survived the game, and No otherwise.\n\nSample Input 1\n\n6 3 4\n3\n1\n3\n2\n\nSample Output 1\n\nNo\nNo\nYes\nNo\nNo\nNo\n\nIn the beginning, the players' scores are (3, 3, 3, 3, 3, 3).\n\nPlayer 3 correctly answers a question. The players' scores are now (2, 2, 3, 2, 2, 2).\n\nPlayer 1 correctly answers a question. The players' scores are now (2, 1, 2, 1, 1, 1).\n\nPlayer 3 correctly answers a question. The players' scores are now (1, 0, 2, 0, 0, 0).\n\nPlayer 2 correctly answers a question. The players' scores are now (0, 0, 1, -1, -1, -1).\n\nPlayers 1, 2, 4, 5 and 6, who have 0 points or lower, are eliminated, and Player 3 survives this game.\n\nSample Input 2\n\n6 5 4\n3\n1\n3\n2\n\nSample Output 2\n\nYes\nYes\nYes\nYes\nYes\nYes\n\nSample Input 3\n\n10 13 15\n3\n1\n4\n1\n5\n9\n2\n6\n5\n3\n5\n8\n9\n7\n9\n\nSample Output 3\n\nNo\nNo\nNo\nNo\nYes\nNo\nNo\nNo\nYes\nNo", "sample_input": "6 3 4\n3\n1\n3\n2\n"}, "reference_outputs": ["No\nNo\nYes\nNo\nNo\nNo\n"], "source_document_id": "p02911", "source_text": "Score: 300 points\n\nProblem Statement\n\nTakahashi has decided to hold fastest-finger-fast quiz games. Kizahashi, who is in charge of making the scoreboard, is struggling to write the program that manages the players' scores in a game, which proceeds as follows.\n\nA game is played by N players, numbered 1 to N. At the beginning of a game, each player has K points.\n\nWhen a player correctly answers a question, each of the other N-1 players receives minus one (-1) point. There is no other factor that affects the players' scores.\n\nAt the end of a game, the players with 0 points or lower are eliminated, and the remaining players survive.\n\nIn the last game, the players gave a total of Q correct answers, the i-th of which was given by Player A_i.\nFor Kizahashi, write a program that determines whether each of the N players survived this game.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10^5\n\n1 \\leq K \\leq 10^9\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq A_i \\leq N\\ (1 \\leq i \\leq Q)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K Q\nA_1\nA_2\n.\n.\n.\nA_Q\n\nOutput\n\nPrint N lines. The i-th line should contain Yes if Player i survived the game, and No otherwise.\n\nSample Input 1\n\n6 3 4\n3\n1\n3\n2\n\nSample Output 1\n\nNo\nNo\nYes\nNo\nNo\nNo\n\nIn the beginning, the players' scores are (3, 3, 3, 3, 3, 3).\n\nPlayer 3 correctly answers a question. The players' scores are now (2, 2, 3, 2, 2, 2).\n\nPlayer 1 correctly answers a question. The players' scores are now (2, 1, 2, 1, 1, 1).\n\nPlayer 3 correctly answers a question. The players' scores are now (1, 0, 2, 0, 0, 0).\n\nPlayer 2 correctly answers a question. The players' scores are now (0, 0, 1, -1, -1, -1).\n\nPlayers 1, 2, 4, 5 and 6, who have 0 points or lower, are eliminated, and Player 3 survives this game.\n\nSample Input 2\n\n6 5 4\n3\n1\n3\n2\n\nSample Output 2\n\nYes\nYes\nYes\nYes\nYes\nYes\n\nSample Input 3\n\n10 13 15\n3\n1\n4\n1\n5\n9\n2\n6\n5\n3\n5\n8\n9\n7\n9\n\nSample Output 3\n\nNo\nNo\nNo\nNo\nYes\nNo\nNo\nNo\nYes\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3363, "cpu_time_ms": 214, "memory_kb": 22244}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s636634137", "group_id": "codeNet:p02911", "input_text": "(defun all-ok (n)\n (loop for i from 1 to n\n do (format t \"Yes~%\")))\n\n(let ((n (read))\n (k (read))\n (q (read))\n (b 0)\n p)\n (setf b (- k q))\n (if (> b 0)\n (all-ok n)\n (progn \n (setf p (make-array n))\n (loop for i from 1 to q\n do (let ((a (read)))\n (incf (aref p (1- a)))))\n (loop for o across p\n do (if (> (+ b o) 0)\n (format t \"Yes~%\")\n (format t \"No~%\"))))))", "language": "Lisp", "metadata": {"date": 1568597461, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02911.html", "problem_id": "p02911", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02911/input.txt", "sample_output_relpath": "derived/input_output/data/p02911/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02911/Lisp/s636634137.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s636634137", "user_id": "u608227593"}, "prompt_components": {"gold_output": "No\nNo\nYes\nNo\nNo\nNo\n", "input_to_evaluate": "(defun all-ok (n)\n (loop for i from 1 to n\n do (format t \"Yes~%\")))\n\n(let ((n (read))\n (k (read))\n (q (read))\n (b 0)\n p)\n (setf b (- k q))\n (if (> b 0)\n (all-ok n)\n (progn \n (setf p (make-array n))\n (loop for i from 1 to q\n do (let ((a (read)))\n (incf (aref p (1- a)))))\n (loop for o across p\n do (if (> (+ b o) 0)\n (format t \"Yes~%\")\n (format t \"No~%\"))))))", "problem_context": "Score: 300 points\n\nProblem Statement\n\nTakahashi has decided to hold fastest-finger-fast quiz games. Kizahashi, who is in charge of making the scoreboard, is struggling to write the program that manages the players' scores in a game, which proceeds as follows.\n\nA game is played by N players, numbered 1 to N. At the beginning of a game, each player has K points.\n\nWhen a player correctly answers a question, each of the other N-1 players receives minus one (-1) point. There is no other factor that affects the players' scores.\n\nAt the end of a game, the players with 0 points or lower are eliminated, and the remaining players survive.\n\nIn the last game, the players gave a total of Q correct answers, the i-th of which was given by Player A_i.\nFor Kizahashi, write a program that determines whether each of the N players survived this game.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10^5\n\n1 \\leq K \\leq 10^9\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq A_i \\leq N\\ (1 \\leq i \\leq Q)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K Q\nA_1\nA_2\n.\n.\n.\nA_Q\n\nOutput\n\nPrint N lines. The i-th line should contain Yes if Player i survived the game, and No otherwise.\n\nSample Input 1\n\n6 3 4\n3\n1\n3\n2\n\nSample Output 1\n\nNo\nNo\nYes\nNo\nNo\nNo\n\nIn the beginning, the players' scores are (3, 3, 3, 3, 3, 3).\n\nPlayer 3 correctly answers a question. The players' scores are now (2, 2, 3, 2, 2, 2).\n\nPlayer 1 correctly answers a question. The players' scores are now (2, 1, 2, 1, 1, 1).\n\nPlayer 3 correctly answers a question. The players' scores are now (1, 0, 2, 0, 0, 0).\n\nPlayer 2 correctly answers a question. The players' scores are now (0, 0, 1, -1, -1, -1).\n\nPlayers 1, 2, 4, 5 and 6, who have 0 points or lower, are eliminated, and Player 3 survives this game.\n\nSample Input 2\n\n6 5 4\n3\n1\n3\n2\n\nSample Output 2\n\nYes\nYes\nYes\nYes\nYes\nYes\n\nSample Input 3\n\n10 13 15\n3\n1\n4\n1\n5\n9\n2\n6\n5\n3\n5\n8\n9\n7\n9\n\nSample Output 3\n\nNo\nNo\nNo\nNo\nYes\nNo\nNo\nNo\nYes\nNo", "sample_input": "6 3 4\n3\n1\n3\n2\n"}, "reference_outputs": ["No\nNo\nYes\nNo\nNo\nNo\n"], "source_document_id": "p02911", "source_text": "Score: 300 points\n\nProblem Statement\n\nTakahashi has decided to hold fastest-finger-fast quiz games. Kizahashi, who is in charge of making the scoreboard, is struggling to write the program that manages the players' scores in a game, which proceeds as follows.\n\nA game is played by N players, numbered 1 to N. At the beginning of a game, each player has K points.\n\nWhen a player correctly answers a question, each of the other N-1 players receives minus one (-1) point. There is no other factor that affects the players' scores.\n\nAt the end of a game, the players with 0 points or lower are eliminated, and the remaining players survive.\n\nIn the last game, the players gave a total of Q correct answers, the i-th of which was given by Player A_i.\nFor Kizahashi, write a program that determines whether each of the N players survived this game.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10^5\n\n1 \\leq K \\leq 10^9\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq A_i \\leq N\\ (1 \\leq i \\leq Q)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K Q\nA_1\nA_2\n.\n.\n.\nA_Q\n\nOutput\n\nPrint N lines. The i-th line should contain Yes if Player i survived the game, and No otherwise.\n\nSample Input 1\n\n6 3 4\n3\n1\n3\n2\n\nSample Output 1\n\nNo\nNo\nYes\nNo\nNo\nNo\n\nIn the beginning, the players' scores are (3, 3, 3, 3, 3, 3).\n\nPlayer 3 correctly answers a question. The players' scores are now (2, 2, 3, 2, 2, 2).\n\nPlayer 1 correctly answers a question. The players' scores are now (2, 1, 2, 1, 1, 1).\n\nPlayer 3 correctly answers a question. The players' scores are now (1, 0, 2, 0, 0, 0).\n\nPlayer 2 correctly answers a question. The players' scores are now (0, 0, 1, -1, -1, -1).\n\nPlayers 1, 2, 4, 5 and 6, who have 0 points or lower, are eliminated, and Player 3 survives this game.\n\nSample Input 2\n\n6 5 4\n3\n1\n3\n2\n\nSample Output 2\n\nYes\nYes\nYes\nYes\nYes\nYes\n\nSample Input 3\n\n10 13 15\n3\n1\n4\n1\n5\n9\n2\n6\n5\n3\n5\n8\n9\n7\n9\n\nSample Output 3\n\nNo\nNo\nNo\nNo\nYes\nNo\nNo\nNo\nYes\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 503, "cpu_time_ms": 394, "memory_kb": 58088}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s693886828", "group_id": "codeNet:p02914", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;;;\n;;; Bit-reversal operation\n;;; Reference: https://stackoverflow.com/questions/746171/efficient-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c\n;;;\n\n(declaim ((simple-array (unsigned-byte 16) (65536)) *bit-reverse-table*))\n(defparameter *bit-reverse-table*\n (make-array 65536 :element-type '(unsigned-byte 16)))\n\n(defun initialize-bit-reverse-table ()\n (declare #.OPT)\n (let ((table *bit-reverse-table*))\n (dotimes (idx (length *bit-reverse-table*))\n (let ((x idx))\n (setq x (logior (ash (logand x #xaaaa) -1)\n (ash (logand x #x5555) 1)))\n (setq x (logior (ash (logand x #xcccc) -2)\n (ash (logand x #x3333) 2)))\n (setq x (logior (ash (logand x #xf0f0) -4)\n (ash (logand x #x0f0f) 4)))\n (setq x (logior (ash x -8) (ldb (byte 16 0) (ash x 8))))\n (setf (aref table idx) x)))))\n\n(initialize-bit-reverse-table)\n\n(declaim (inline logreverse))\n(defun logreverse (x size)\n \"Returns the bit-reversal in the range [0, SIZE) of X.\"\n (declare ((unsigned-byte 64) x)\n ((integer 0 64) size))\n (let ((table *bit-reverse-table*))\n (ash (logior\n (ash (aref table (logand x #xffff)) 48)\n (ash (aref table (logand (ash x -16) #xffff)) 32)\n (ash (aref table (logand (ash x -32) #xffff)) 16)\n (aref table (logand (ash x -48) #xffff)))\n (- size 64))))\n\n;;;\n;;; Fast operations on GF(2)\n;;;\n\n(defun f2-echelon! (matrix)\n (declare #.OPT\n ((simple-array uint62 (100000)) matrix))\n (let* ((rank 0))\n (declare ((integer 0 #.most-positive-fixnum) rank))\n (dotimes (target-col 64)\n (let* ((pivot-row (do ((i rank (+ 1 i)))\n ((= i 100000) -1)\n (when (logbitp target-col (aref matrix i))\n (return i)))))\n (when (>= pivot-row 0)\n ;; swap rows\n (rotatef (aref matrix rank) (aref matrix pivot-row))\n ;; eliminate the column\n (dotimes (i 100000)\n (when (and (/= i rank) (logbitp target-col (aref matrix i)))\n (setf (aref matrix i)\n (logxor (aref matrix i)\n (aref matrix rank)))))\n (incf rank))))\n (values matrix rank)))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint62))\n (mat (sb-int:make-static-vector 100000 :element-type 'uint62)))\n (declare (uint32 n)\n ((simple-array uint62 (*)) mat))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (let* ((total-xor (reduce #'logxor as)))\n (declare (uint62 total-xor))\n (dotimes (i n)\n (setf (aref mat i)\n (logreverse (logandc2 (aref as i) total-xor) 62)))\n (f2-echelon! mat)\n (let ((rxor 0))\n (declare (uint62 rxor))\n (dotimes (i n)\n (setf rxor (logxor rxor (logreverse (aref mat i) 62))))\n (println (+ (logior rxor total-xor) rxor))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1568962728, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02914.html", "problem_id": "p02914", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02914/input.txt", "sample_output_relpath": "derived/input_output/data/p02914/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02914/Lisp/s693886828.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s693886828", "user_id": "u352600849"}, "prompt_components": {"gold_output": "12\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;;;\n;;; Bit-reversal operation\n;;; Reference: https://stackoverflow.com/questions/746171/efficient-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c\n;;;\n\n(declaim ((simple-array (unsigned-byte 16) (65536)) *bit-reverse-table*))\n(defparameter *bit-reverse-table*\n (make-array 65536 :element-type '(unsigned-byte 16)))\n\n(defun initialize-bit-reverse-table ()\n (declare #.OPT)\n (let ((table *bit-reverse-table*))\n (dotimes (idx (length *bit-reverse-table*))\n (let ((x idx))\n (setq x (logior (ash (logand x #xaaaa) -1)\n (ash (logand x #x5555) 1)))\n (setq x (logior (ash (logand x #xcccc) -2)\n (ash (logand x #x3333) 2)))\n (setq x (logior (ash (logand x #xf0f0) -4)\n (ash (logand x #x0f0f) 4)))\n (setq x (logior (ash x -8) (ldb (byte 16 0) (ash x 8))))\n (setf (aref table idx) x)))))\n\n(initialize-bit-reverse-table)\n\n(declaim (inline logreverse))\n(defun logreverse (x size)\n \"Returns the bit-reversal in the range [0, SIZE) of X.\"\n (declare ((unsigned-byte 64) x)\n ((integer 0 64) size))\n (let ((table *bit-reverse-table*))\n (ash (logior\n (ash (aref table (logand x #xffff)) 48)\n (ash (aref table (logand (ash x -16) #xffff)) 32)\n (ash (aref table (logand (ash x -32) #xffff)) 16)\n (aref table (logand (ash x -48) #xffff)))\n (- size 64))))\n\n;;;\n;;; Fast operations on GF(2)\n;;;\n\n(defun f2-echelon! (matrix)\n (declare #.OPT\n ((simple-array uint62 (100000)) matrix))\n (let* ((rank 0))\n (declare ((integer 0 #.most-positive-fixnum) rank))\n (dotimes (target-col 64)\n (let* ((pivot-row (do ((i rank (+ 1 i)))\n ((= i 100000) -1)\n (when (logbitp target-col (aref matrix i))\n (return i)))))\n (when (>= pivot-row 0)\n ;; swap rows\n (rotatef (aref matrix rank) (aref matrix pivot-row))\n ;; eliminate the column\n (dotimes (i 100000)\n (when (and (/= i rank) (logbitp target-col (aref matrix i)))\n (setf (aref matrix i)\n (logxor (aref matrix i)\n (aref matrix rank)))))\n (incf rank))))\n (values matrix rank)))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint62))\n (mat (sb-int:make-static-vector 100000 :element-type 'uint62)))\n (declare (uint32 n)\n ((simple-array uint62 (*)) mat))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (let* ((total-xor (reduce #'logxor as)))\n (declare (uint62 total-xor))\n (dotimes (i n)\n (setf (aref mat i)\n (logreverse (logandc2 (aref as i) total-xor) 62)))\n (f2-echelon! mat)\n (let ((rxor 0))\n (declare (uint62 rxor))\n (dotimes (i n)\n (setf rxor (logxor rxor (logreverse (aref mat i) 62))))\n (println (+ (logior rxor total-xor) rxor))))))\n\n#-swank (main)\n", "problem_context": "Score: 600 points\n\nProblem Statement\n\nWe have N non-negative integers: A_1, A_2, ..., A_N.\n\nConsider painting at least one and at most N-1 integers among them in red, and painting the rest in blue.\n\nLet the beauty of the painting be the \\mbox{XOR} of the integers painted in red, plus the \\mbox{XOR} of the integers painted in blue.\n\nFind the maximum possible beauty of the painting.\n\nWhat is \\mbox{XOR}?\n\nThe bitwise \\mbox{XOR} x_1 \\oplus x_2 \\oplus \\ldots \\oplus x_n of n non-negative integers x_1, x_2, \\ldots, x_n is defined as follows:\n\nWhen x_1 \\oplus x_2 \\oplus \\ldots \\oplus x_n is written in base two, the digit in the 2^k's place (k \\geq 0) is 1 if the number of integers among x_1, x_2, \\ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.\n\nFor example, 3 \\oplus 5 = 6.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10^5\n\n0 \\leq A_i < 2^{60}\\ (1 \\leq i \\leq N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible beauty of the painting.\n\nSample Input 1\n\n3\n3 6 5\n\nSample Output 1\n\n12\n\nIf we paint 3, 6, 5 in blue, red, blue, respectively, the beauty will be (6) + (3 \\oplus 5) = 12.\n\nThere is no way to paint the integers resulting in greater beauty than 12, so the answer is 12.\n\nSample Input 2\n\n4\n23 36 66 65\n\nSample Output 2\n\n188\n\nSample Input 3\n\n20\n1008288677408720767 539403903321871999 1044301017184589821 215886900497862655 504277496111605629 972104334925272829 792625803473366909 972333547668684797 467386965442856573 755861732751878143 1151846447448561405 467257771752201853 683930041385277311 432010719984459389 319104378117934975 611451291444233983 647509226592964607 251832107792119421 827811265410084479 864032478037725181\n\nSample Output 3\n\n2012721721873704572\n\nA_i and the answer may not fit into a 32-bit integer type.", "sample_input": "3\n3 6 5\n"}, "reference_outputs": ["12\n"], "source_document_id": "p02914", "source_text": "Score: 600 points\n\nProblem Statement\n\nWe have N non-negative integers: A_1, A_2, ..., A_N.\n\nConsider painting at least one and at most N-1 integers among them in red, and painting the rest in blue.\n\nLet the beauty of the painting be the \\mbox{XOR} of the integers painted in red, plus the \\mbox{XOR} of the integers painted in blue.\n\nFind the maximum possible beauty of the painting.\n\nWhat is \\mbox{XOR}?\n\nThe bitwise \\mbox{XOR} x_1 \\oplus x_2 \\oplus \\ldots \\oplus x_n of n non-negative integers x_1, x_2, \\ldots, x_n is defined as follows:\n\nWhen x_1 \\oplus x_2 \\oplus \\ldots \\oplus x_n is written in base two, the digit in the 2^k's place (k \\geq 0) is 1 if the number of integers among x_1, x_2, \\ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.\n\nFor example, 3 \\oplus 5 = 6.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10^5\n\n0 \\leq A_i < 2^{60}\\ (1 \\leq i \\leq N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible beauty of the painting.\n\nSample Input 1\n\n3\n3 6 5\n\nSample Output 1\n\n12\n\nIf we paint 3, 6, 5 in blue, red, blue, respectively, the beauty will be (6) + (3 \\oplus 5) = 12.\n\nThere is no way to paint the integers resulting in greater beauty than 12, so the answer is 12.\n\nSample Input 2\n\n4\n23 36 66 65\n\nSample Output 2\n\n188\n\nSample Input 3\n\n20\n1008288677408720767 539403903321871999 1044301017184589821 215886900497862655 504277496111605629 972104334925272829 792625803473366909 972333547668684797 467386965442856573 755861732751878143 1151846447448561405 467257771752201853 683930041385277311 432010719984459389 319104378117934975 611451291444233983 647509226592964607 251832107792119421 827811265410084479 864032478037725181\n\nSample Output 3\n\n2012721721873704572\n\nA_i and the answer may not fit into a 32-bit integer type.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5479, "cpu_time_ms": 138, "memory_kb": 15592}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s803588108", "group_id": "codeNet:p02914", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; 1-dimensional binary indexed tree on arbitrary commutative monoid\n;;;\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +time-limit+ 1.8f0)\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (as (make-array n :element-type 'uint62)))\n (declare (uint32 n))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (setf as (sort as #'>))\n (let ((rxor 0)\n (totalxor (reduce #'logxor as))\n (max-temp (float (the uint62 (sb-int:power-of-two-ceiling (reduce #'max as))) 1f0)))\n (declare (uint62 rxor totalxor)\n (single-float max-temp))\n (dotimes (i n)\n (when (evenp i)\n (setq rxor (logxor rxor (aref as i)))))\n (let ((res (+ rxor (logxor totalxor rxor))))\n (declare (uint62 res))\n (sb-int:with-progressive-timeout (get-remaining-time :seconds +time-limit+)\n (dotimes (_ most-positive-fixnum)\n (let ((remaining-time (get-remaining-time)))\n (when (eq 0 (get-remaining-time))\n (println res)\n (return-from main))\n (let* ((ratio (* (the single-float remaining-time) #.(/ +time-limit+)))\n (temp (+ 1f0 (* max-temp ratio))))\n (declare (single-float temp))\n (dotimes (_ 5000)\n (let* ((idx (random n))\n (old-val (+ rxor (logxor totalxor rxor)))\n (new-rxor (logxor rxor (aref as idx)))\n (new-val (+ new-rxor (logxor totalxor new-rxor)))\n (prob (exp (/ (- new-val old-val) temp))))\n (declare (uint62 old-val new-val)\n (single-float prob))\n (when (< (random 1f0) prob)\n (setq res (max res new-val)\n rxor new-rxor))))))))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1568613244, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02914.html", "problem_id": "p02914", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02914/input.txt", "sample_output_relpath": "derived/input_output/data/p02914/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02914/Lisp/s803588108.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s803588108", "user_id": "u352600849"}, "prompt_components": {"gold_output": "12\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; 1-dimensional binary indexed tree on arbitrary commutative monoid\n;;;\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +time-limit+ 1.8f0)\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (as (make-array n :element-type 'uint62)))\n (declare (uint32 n))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (setf as (sort as #'>))\n (let ((rxor 0)\n (totalxor (reduce #'logxor as))\n (max-temp (float (the uint62 (sb-int:power-of-two-ceiling (reduce #'max as))) 1f0)))\n (declare (uint62 rxor totalxor)\n (single-float max-temp))\n (dotimes (i n)\n (when (evenp i)\n (setq rxor (logxor rxor (aref as i)))))\n (let ((res (+ rxor (logxor totalxor rxor))))\n (declare (uint62 res))\n (sb-int:with-progressive-timeout (get-remaining-time :seconds +time-limit+)\n (dotimes (_ most-positive-fixnum)\n (let ((remaining-time (get-remaining-time)))\n (when (eq 0 (get-remaining-time))\n (println res)\n (return-from main))\n (let* ((ratio (* (the single-float remaining-time) #.(/ +time-limit+)))\n (temp (+ 1f0 (* max-temp ratio))))\n (declare (single-float temp))\n (dotimes (_ 5000)\n (let* ((idx (random n))\n (old-val (+ rxor (logxor totalxor rxor)))\n (new-rxor (logxor rxor (aref as idx)))\n (new-val (+ new-rxor (logxor totalxor new-rxor)))\n (prob (exp (/ (- new-val old-val) temp))))\n (declare (uint62 old-val new-val)\n (single-float prob))\n (when (< (random 1f0) prob)\n (setq res (max res new-val)\n rxor new-rxor))))))))))))\n\n#-swank (main)\n", "problem_context": "Score: 600 points\n\nProblem Statement\n\nWe have N non-negative integers: A_1, A_2, ..., A_N.\n\nConsider painting at least one and at most N-1 integers among them in red, and painting the rest in blue.\n\nLet the beauty of the painting be the \\mbox{XOR} of the integers painted in red, plus the \\mbox{XOR} of the integers painted in blue.\n\nFind the maximum possible beauty of the painting.\n\nWhat is \\mbox{XOR}?\n\nThe bitwise \\mbox{XOR} x_1 \\oplus x_2 \\oplus \\ldots \\oplus x_n of n non-negative integers x_1, x_2, \\ldots, x_n is defined as follows:\n\nWhen x_1 \\oplus x_2 \\oplus \\ldots \\oplus x_n is written in base two, the digit in the 2^k's place (k \\geq 0) is 1 if the number of integers among x_1, x_2, \\ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.\n\nFor example, 3 \\oplus 5 = 6.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10^5\n\n0 \\leq A_i < 2^{60}\\ (1 \\leq i \\leq N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible beauty of the painting.\n\nSample Input 1\n\n3\n3 6 5\n\nSample Output 1\n\n12\n\nIf we paint 3, 6, 5 in blue, red, blue, respectively, the beauty will be (6) + (3 \\oplus 5) = 12.\n\nThere is no way to paint the integers resulting in greater beauty than 12, so the answer is 12.\n\nSample Input 2\n\n4\n23 36 66 65\n\nSample Output 2\n\n188\n\nSample Input 3\n\n20\n1008288677408720767 539403903321871999 1044301017184589821 215886900497862655 504277496111605629 972104334925272829 792625803473366909 972333547668684797 467386965442856573 755861732751878143 1151846447448561405 467257771752201853 683930041385277311 432010719984459389 319104378117934975 611451291444233983 647509226592964607 251832107792119421 827811265410084479 864032478037725181\n\nSample Output 3\n\n2012721721873704572\n\nA_i and the answer may not fit into a 32-bit integer type.", "sample_input": "3\n3 6 5\n"}, "reference_outputs": ["12\n"], "source_document_id": "p02914", "source_text": "Score: 600 points\n\nProblem Statement\n\nWe have N non-negative integers: A_1, A_2, ..., A_N.\n\nConsider painting at least one and at most N-1 integers among them in red, and painting the rest in blue.\n\nLet the beauty of the painting be the \\mbox{XOR} of the integers painted in red, plus the \\mbox{XOR} of the integers painted in blue.\n\nFind the maximum possible beauty of the painting.\n\nWhat is \\mbox{XOR}?\n\nThe bitwise \\mbox{XOR} x_1 \\oplus x_2 \\oplus \\ldots \\oplus x_n of n non-negative integers x_1, x_2, \\ldots, x_n is defined as follows:\n\nWhen x_1 \\oplus x_2 \\oplus \\ldots \\oplus x_n is written in base two, the digit in the 2^k's place (k \\geq 0) is 1 if the number of integers among x_1, x_2, \\ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.\n\nFor example, 3 \\oplus 5 = 6.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10^5\n\n0 \\leq A_i < 2^{60}\\ (1 \\leq i \\leq N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible beauty of the painting.\n\nSample Input 1\n\n3\n3 6 5\n\nSample Output 1\n\n12\n\nIf we paint 3, 6, 5 in blue, red, blue, respectively, the beauty will be (6) + (3 \\oplus 5) = 12.\n\nThere is no way to paint the integers resulting in greater beauty than 12, so the answer is 12.\n\nSample Input 2\n\n4\n23 36 66 65\n\nSample Output 2\n\n188\n\nSample Input 3\n\n20\n1008288677408720767 539403903321871999 1044301017184589821 215886900497862655 504277496111605629 972104334925272829 792625803473366909 972333547668684797 467386965442856573 755861732751878143 1151846447448561405 467257771752201853 683930041385277311 432010719984459389 319104378117934975 611451291444233983 647509226592964607 251832107792119421 827811265410084479 864032478037725181\n\nSample Output 3\n\n2012721721873704572\n\nA_i and the answer may not fit into a 32-bit integer type.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4317, "cpu_time_ms": 1963, "memory_kb": 21352}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s678050780", "group_id": "codeNet:p02914", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; 1-dimensional binary indexed tree on arbitrary commutative monoid\n;;;\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(PROGN\n (DEFUN BITREE-UPDATE! (BITREE INDEX DELTA)\n \"Destructively increments the vector: vector[INDEX] = vector[INDEX] +\nDELTA\"\n (declare #.OPT\n ((simple-array uint32 (*)) bitree)\n (int32 delta))\n (LET ((LEN (LENGTH BITREE)))\n (DO ((I INDEX (LOGIOR I (+ I 1))))\n ((>= I LEN) BITREE)\n (DECLARE ((INTEGER 0 4611686018427387903) I))\n (SETF (AREF BITREE I) (FUNCALL #'+ (AREF BITREE I) DELTA)))))\n (DEFUN BITREE-BISECT-LEFT (BITREE VALUE)\n \"Returns the smallest index that satisfies VECTOR[0]+ ... +\nVECTOR[index] >= VALUE. Returns the length of VECTOR if VECTOR[0]+\n... +VECTOR[length-1] < VALUE.\"\n (DECLARE #.OPT\n ((simple-array uint32 (*)) BITREE)\n (uint32 value))\n (IF (NOT (FUNCALL #'< 0 VALUE))\n 0\n (LET ((LEN (LENGTH BITREE)) (INDEX+1 0) (CUMUL 0))\n (DECLARE ((INTEGER 0 4611686018427387903) INDEX+1)\n (TYPE UINT32 CUMUL))\n (DO ((DELTA (ASH 1 (- (INTEGER-LENGTH LEN) 1)) (ASH DELTA -1)))\n ((ZEROP DELTA) INDEX+1)\n (DECLARE ((INTEGER 0 4611686018427387903) DELTA))\n (LET ((NEXT-INDEX (+ INDEX+1 DELTA -1)))\n (WHEN (< NEXT-INDEX LEN)\n (LET ((NEXT-CUMUL (FUNCALL #'+ CUMUL (AREF BITREE NEXT-INDEX))))\n (DECLARE (TYPE UINT32 NEXT-CUMUL))\n (WHEN (FUNCALL #'< NEXT-CUMUL VALUE)\n (SETF CUMUL NEXT-CUMUL)\n (INCF INDEX+1 DELTA))))))))))\n\n(defconstant +time-limit+ 1.8d0)\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint62)))\n (declare (uint32 n))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (let ((rxor (aref as 0))\n (bxor (aref as 1))\n (rcount 1)\n (bcount 1)\n (rdp (make-array 100000 :element-type 'uint32))\n (bdp (make-array 100000 :element-type 'uint32))\n (res 0)\n (max-temp (float (the uint62 (sb-int:power-of-two-ceiling (reduce #'max as))) 1d0)))\n (declare (uint62 rxor bxor res)\n (uint32 rcount bcount)\n (double-float max-temp))\n (bitree-update! rdp 0 1)\n (bitree-update! bdp 1 1)\n (loop for i from 2 below n\n do (if (>= (logxor rxor (aref as i))\n (logxor bxor (aref as i)))\n (progn\n (bitree-update! rdp i 1)\n (incf rcount)\n (setq rxor (logxor rxor (aref as i))))\n (progn\n (bitree-update! bdp i 1)\n (incf bcount)\n (setq bxor (logxor bxor (aref as i))))))\n (sb-int:with-progressive-timeout (get-remaining-time :seconds +time-limit+)\n (dotimes (_ most-positive-fixnum)\n (let ((remaining-time (get-remaining-time)))\n (when (eq 0 (get-remaining-time))\n (println res)\n (return-from main))\n (let* ((ratio (* (the single-float remaining-time) #.(/ +time-limit+)))\n (temp (+ 1d0 (* max-temp ratio))))\n (dotimes (_ 5000)\n (let ((r (random 3)))\n (cond ((= 0 r)\n (let* ((rpos (+ 1 (random rcount)))\n (bpos (+ 1 (random bcount)))\n (ridx (bitree-bisect-left rdp rpos))\n (bidx (bitree-bisect-left bdp bpos))\n (rval (aref as ridx))\n (bval (aref as bidx))\n (old-val (+ rxor bxor))\n (new-rxor (logxor rxor rval bval))\n (new-bxor (logxor bxor rval bval))\n (new-val (+ new-rxor new-bxor))\n (prob (exp (/ (- new-val old-val) temp))))\n (when (< (random 1d0) prob)\n (setq res (max res new-val))\n (setq rxor new-rxor\n bxor new-bxor)\n (bitree-update! rdp ridx -1)\n (bitree-update! bdp bidx -1)\n (bitree-update! rdp bidx 1)\n (bitree-update! bdp ridx 1))))\n ((= 1 r)\n (when (> rcount 1)\n (let* ((rpos (+ 1 (random rcount)))\n (ridx (bitree-bisect-left rdp rpos))\n (rval (aref as ridx))\n (old-val (+ rxor bxor))\n (new-rxor (logxor rxor rval))\n (new-bxor (logxor bxor rval))\n (new-val (+ new-rxor new-bxor))\n (prob (exp (/ (- new-val old-val) temp))))\n (declare (uint32 ridx))\n (when (< (random 1d0) prob)\n (setq res (max res new-val))\n (decf rcount)\n (incf bcount)\n (setq rxor new-rxor\n bxor new-bxor)\n (bitree-update! rdp ridx -1)\n (bitree-update! bdp ridx 1)))))\n (t\n (when (> bcount 1)\n (let* ((bpos (+ 1 (random bcount)))\n (bidx (bitree-bisect-left bdp bpos))\n (bval (aref as bidx))\n (old-val (+ rxor bxor))\n (new-rxor (logxor rxor bval))\n (new-bxor (logxor bxor bval))\n (new-val (+ new-rxor new-bxor))\n (prob (exp (/ (- new-val old-val) temp))))\n (declare (uint32 bidx))\n (when (< (random 1d0) prob)\n (setq res (max res new-val))\n (decf bcount)\n (incf rcount)\n (setq rxor new-rxor\n bxor new-bxor)\n (bitree-update! bdp bidx -1)\n (bitree-update! rdp bidx 1)))))))))))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1568611057, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02914.html", "problem_id": "p02914", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02914/input.txt", "sample_output_relpath": "derived/input_output/data/p02914/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02914/Lisp/s678050780.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s678050780", "user_id": "u352600849"}, "prompt_components": {"gold_output": "12\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; 1-dimensional binary indexed tree on arbitrary commutative monoid\n;;;\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(PROGN\n (DEFUN BITREE-UPDATE! (BITREE INDEX DELTA)\n \"Destructively increments the vector: vector[INDEX] = vector[INDEX] +\nDELTA\"\n (declare #.OPT\n ((simple-array uint32 (*)) bitree)\n (int32 delta))\n (LET ((LEN (LENGTH BITREE)))\n (DO ((I INDEX (LOGIOR I (+ I 1))))\n ((>= I LEN) BITREE)\n (DECLARE ((INTEGER 0 4611686018427387903) I))\n (SETF (AREF BITREE I) (FUNCALL #'+ (AREF BITREE I) DELTA)))))\n (DEFUN BITREE-BISECT-LEFT (BITREE VALUE)\n \"Returns the smallest index that satisfies VECTOR[0]+ ... +\nVECTOR[index] >= VALUE. Returns the length of VECTOR if VECTOR[0]+\n... +VECTOR[length-1] < VALUE.\"\n (DECLARE #.OPT\n ((simple-array uint32 (*)) BITREE)\n (uint32 value))\n (IF (NOT (FUNCALL #'< 0 VALUE))\n 0\n (LET ((LEN (LENGTH BITREE)) (INDEX+1 0) (CUMUL 0))\n (DECLARE ((INTEGER 0 4611686018427387903) INDEX+1)\n (TYPE UINT32 CUMUL))\n (DO ((DELTA (ASH 1 (- (INTEGER-LENGTH LEN) 1)) (ASH DELTA -1)))\n ((ZEROP DELTA) INDEX+1)\n (DECLARE ((INTEGER 0 4611686018427387903) DELTA))\n (LET ((NEXT-INDEX (+ INDEX+1 DELTA -1)))\n (WHEN (< NEXT-INDEX LEN)\n (LET ((NEXT-CUMUL (FUNCALL #'+ CUMUL (AREF BITREE NEXT-INDEX))))\n (DECLARE (TYPE UINT32 NEXT-CUMUL))\n (WHEN (FUNCALL #'< NEXT-CUMUL VALUE)\n (SETF CUMUL NEXT-CUMUL)\n (INCF INDEX+1 DELTA))))))))))\n\n(defconstant +time-limit+ 1.8d0)\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint62)))\n (declare (uint32 n))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (let ((rxor (aref as 0))\n (bxor (aref as 1))\n (rcount 1)\n (bcount 1)\n (rdp (make-array 100000 :element-type 'uint32))\n (bdp (make-array 100000 :element-type 'uint32))\n (res 0)\n (max-temp (float (the uint62 (sb-int:power-of-two-ceiling (reduce #'max as))) 1d0)))\n (declare (uint62 rxor bxor res)\n (uint32 rcount bcount)\n (double-float max-temp))\n (bitree-update! rdp 0 1)\n (bitree-update! bdp 1 1)\n (loop for i from 2 below n\n do (if (>= (logxor rxor (aref as i))\n (logxor bxor (aref as i)))\n (progn\n (bitree-update! rdp i 1)\n (incf rcount)\n (setq rxor (logxor rxor (aref as i))))\n (progn\n (bitree-update! bdp i 1)\n (incf bcount)\n (setq bxor (logxor bxor (aref as i))))))\n (sb-int:with-progressive-timeout (get-remaining-time :seconds +time-limit+)\n (dotimes (_ most-positive-fixnum)\n (let ((remaining-time (get-remaining-time)))\n (when (eq 0 (get-remaining-time))\n (println res)\n (return-from main))\n (let* ((ratio (* (the single-float remaining-time) #.(/ +time-limit+)))\n (temp (+ 1d0 (* max-temp ratio))))\n (dotimes (_ 5000)\n (let ((r (random 3)))\n (cond ((= 0 r)\n (let* ((rpos (+ 1 (random rcount)))\n (bpos (+ 1 (random bcount)))\n (ridx (bitree-bisect-left rdp rpos))\n (bidx (bitree-bisect-left bdp bpos))\n (rval (aref as ridx))\n (bval (aref as bidx))\n (old-val (+ rxor bxor))\n (new-rxor (logxor rxor rval bval))\n (new-bxor (logxor bxor rval bval))\n (new-val (+ new-rxor new-bxor))\n (prob (exp (/ (- new-val old-val) temp))))\n (when (< (random 1d0) prob)\n (setq res (max res new-val))\n (setq rxor new-rxor\n bxor new-bxor)\n (bitree-update! rdp ridx -1)\n (bitree-update! bdp bidx -1)\n (bitree-update! rdp bidx 1)\n (bitree-update! bdp ridx 1))))\n ((= 1 r)\n (when (> rcount 1)\n (let* ((rpos (+ 1 (random rcount)))\n (ridx (bitree-bisect-left rdp rpos))\n (rval (aref as ridx))\n (old-val (+ rxor bxor))\n (new-rxor (logxor rxor rval))\n (new-bxor (logxor bxor rval))\n (new-val (+ new-rxor new-bxor))\n (prob (exp (/ (- new-val old-val) temp))))\n (declare (uint32 ridx))\n (when (< (random 1d0) prob)\n (setq res (max res new-val))\n (decf rcount)\n (incf bcount)\n (setq rxor new-rxor\n bxor new-bxor)\n (bitree-update! rdp ridx -1)\n (bitree-update! bdp ridx 1)))))\n (t\n (when (> bcount 1)\n (let* ((bpos (+ 1 (random bcount)))\n (bidx (bitree-bisect-left bdp bpos))\n (bval (aref as bidx))\n (old-val (+ rxor bxor))\n (new-rxor (logxor rxor bval))\n (new-bxor (logxor bxor bval))\n (new-val (+ new-rxor new-bxor))\n (prob (exp (/ (- new-val old-val) temp))))\n (declare (uint32 bidx))\n (when (< (random 1d0) prob)\n (setq res (max res new-val))\n (decf bcount)\n (incf rcount)\n (setq rxor new-rxor\n bxor new-bxor)\n (bitree-update! bdp bidx -1)\n (bitree-update! rdp bidx 1)))))))))))))))\n\n#-swank (main)\n", "problem_context": "Score: 600 points\n\nProblem Statement\n\nWe have N non-negative integers: A_1, A_2, ..., A_N.\n\nConsider painting at least one and at most N-1 integers among them in red, and painting the rest in blue.\n\nLet the beauty of the painting be the \\mbox{XOR} of the integers painted in red, plus the \\mbox{XOR} of the integers painted in blue.\n\nFind the maximum possible beauty of the painting.\n\nWhat is \\mbox{XOR}?\n\nThe bitwise \\mbox{XOR} x_1 \\oplus x_2 \\oplus \\ldots \\oplus x_n of n non-negative integers x_1, x_2, \\ldots, x_n is defined as follows:\n\nWhen x_1 \\oplus x_2 \\oplus \\ldots \\oplus x_n is written in base two, the digit in the 2^k's place (k \\geq 0) is 1 if the number of integers among x_1, x_2, \\ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.\n\nFor example, 3 \\oplus 5 = 6.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10^5\n\n0 \\leq A_i < 2^{60}\\ (1 \\leq i \\leq N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible beauty of the painting.\n\nSample Input 1\n\n3\n3 6 5\n\nSample Output 1\n\n12\n\nIf we paint 3, 6, 5 in blue, red, blue, respectively, the beauty will be (6) + (3 \\oplus 5) = 12.\n\nThere is no way to paint the integers resulting in greater beauty than 12, so the answer is 12.\n\nSample Input 2\n\n4\n23 36 66 65\n\nSample Output 2\n\n188\n\nSample Input 3\n\n20\n1008288677408720767 539403903321871999 1044301017184589821 215886900497862655 504277496111605629 972104334925272829 792625803473366909 972333547668684797 467386965442856573 755861732751878143 1151846447448561405 467257771752201853 683930041385277311 432010719984459389 319104378117934975 611451291444233983 647509226592964607 251832107792119421 827811265410084479 864032478037725181\n\nSample Output 3\n\n2012721721873704572\n\nA_i and the answer may not fit into a 32-bit integer type.", "sample_input": "3\n3 6 5\n"}, "reference_outputs": ["12\n"], "source_document_id": "p02914", "source_text": "Score: 600 points\n\nProblem Statement\n\nWe have N non-negative integers: A_1, A_2, ..., A_N.\n\nConsider painting at least one and at most N-1 integers among them in red, and painting the rest in blue.\n\nLet the beauty of the painting be the \\mbox{XOR} of the integers painted in red, plus the \\mbox{XOR} of the integers painted in blue.\n\nFind the maximum possible beauty of the painting.\n\nWhat is \\mbox{XOR}?\n\nThe bitwise \\mbox{XOR} x_1 \\oplus x_2 \\oplus \\ldots \\oplus x_n of n non-negative integers x_1, x_2, \\ldots, x_n is defined as follows:\n\nWhen x_1 \\oplus x_2 \\oplus \\ldots \\oplus x_n is written in base two, the digit in the 2^k's place (k \\geq 0) is 1 if the number of integers among x_1, x_2, \\ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.\n\nFor example, 3 \\oplus 5 = 6.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10^5\n\n0 \\leq A_i < 2^{60}\\ (1 \\leq i \\leq N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible beauty of the painting.\n\nSample Input 1\n\n3\n3 6 5\n\nSample Output 1\n\n12\n\nIf we paint 3, 6, 5 in blue, red, blue, respectively, the beauty will be (6) + (3 \\oplus 5) = 12.\n\nThere is no way to paint the integers resulting in greater beauty than 12, so the answer is 12.\n\nSample Input 2\n\n4\n23 36 66 65\n\nSample Output 2\n\n188\n\nSample Input 3\n\n20\n1008288677408720767 539403903321871999 1044301017184589821 215886900497862655 504277496111605629 972104334925272829 792625803473366909 972333547668684797 467386965442856573 755861732751878143 1151846447448561405 467257771752201853 683930041385277311 432010719984459389 319104378117934975 611451291444233983 647509226592964607 251832107792119421 827811265410084479 864032478037725181\n\nSample Output 3\n\n2012721721873704572\n\nA_i and the answer may not fit into a 32-bit integer type.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9057, "cpu_time_ms": 1944, "memory_kb": 21092}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s363268093", "group_id": "codeNet:p02915", "input_text": "(format t \"~A~%\" (expt (read) 3))", "language": "Lisp", "metadata": {"date": 1567958430, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02915.html", "problem_id": "p02915", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02915/input.txt", "sample_output_relpath": "derived/input_output/data/p02915/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02915/Lisp/s363268093.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s363268093", "user_id": "u606976120"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(format t \"~A~%\" (expt (read) 3))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi is going to set a 3-character password.\n\nHow many possible passwords are there if each of its characters must be a digit between 1 and N (inclusive)?\n\nConstraints\n\n1 \\leq N \\leq 9\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the number of possible passwords.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n8\n\nThere are eight possible passwords: 111, 112, 121, 122, 211, 212, 221, and 222.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n1\n\nThere is only one possible password if you can only use one kind of character.", "sample_input": "2\n"}, "reference_outputs": ["8\n"], "source_document_id": "p02915", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi is going to set a 3-character password.\n\nHow many possible passwords are there if each of its characters must be a digit between 1 and N (inclusive)?\n\nConstraints\n\n1 \\leq N \\leq 9\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the number of possible passwords.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n8\n\nThere are eight possible passwords: 111, 112, 121, 122, 211, 212, 221, and 222.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n1\n\nThere is only one possible password if you can only use one kind of character.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 33, "cpu_time_ms": 20, "memory_kb": 3812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s505707366", "group_id": "codeNet:p02915", "input_text": "(defun main ()\n (let ((n (read)))\n (format t \"~A~%\" (expt n 3))))\n\n(main)", "language": "Lisp", "metadata": {"date": 1567904690, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02915.html", "problem_id": "p02915", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02915/input.txt", "sample_output_relpath": "derived/input_output/data/p02915/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02915/Lisp/s505707366.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s505707366", "user_id": "u924821799"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(defun main ()\n (let ((n (read)))\n (format t \"~A~%\" (expt n 3))))\n\n(main)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi is going to set a 3-character password.\n\nHow many possible passwords are there if each of its characters must be a digit between 1 and N (inclusive)?\n\nConstraints\n\n1 \\leq N \\leq 9\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the number of possible passwords.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n8\n\nThere are eight possible passwords: 111, 112, 121, 122, 211, 212, 221, and 222.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n1\n\nThere is only one possible password if you can only use one kind of character.", "sample_input": "2\n"}, "reference_outputs": ["8\n"], "source_document_id": "p02915", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi is going to set a 3-character password.\n\nHow many possible passwords are there if each of its characters must be a digit between 1 and N (inclusive)?\n\nConstraints\n\n1 \\leq N \\leq 9\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the number of possible passwords.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n8\n\nThere are eight possible passwords: 111, 112, 121, 122, 211, 212, 221, and 222.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n1\n\nThere is only one possible password if you can only use one kind of character.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 77, "cpu_time_ms": 123, "memory_kb": 10212}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s877087821", "group_id": "codeNet:p02917", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (bs (make-array (- n 1) :element-type 'uint32)))\n (dotimes (i (- n 1))\n (setf (aref bs i) (read)))\n (let ((as (make-array n :element-type 'uint32)))\n (setf (aref as 0) (aref bs 0))\n (setf (aref as (- n 1)) (aref bs (- n 2)))\n (loop for i from 1 below (- n 1)\n do (setf (aref as i)\n (min (aref bs (- i 1)) (aref bs i))))\n (println (reduce #'+ as)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n2 5\n\"\n \"9\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n3\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n0 153 10 10 23\n\"\n \"53\n\")))\n", "language": "Lisp", "metadata": {"date": 1567905052, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02917.html", "problem_id": "p02917", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02917/input.txt", "sample_output_relpath": "derived/input_output/data/p02917/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02917/Lisp/s877087821.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s877087821", "user_id": "u352600849"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (bs (make-array (- n 1) :element-type 'uint32)))\n (dotimes (i (- n 1))\n (setf (aref bs i) (read)))\n (let ((as (make-array n :element-type 'uint32)))\n (setf (aref as 0) (aref bs 0))\n (setf (aref as (- n 1)) (aref bs (- n 2)))\n (loop for i from 1 below (- n 1)\n do (setf (aref as i)\n (min (aref bs (- i 1)) (aref bs i))))\n (println (reduce #'+ as)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n2 5\n\"\n \"9\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n3\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n0 153 10 10 23\n\"\n \"53\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere is an integer sequence A of length N whose values are unknown.\n\nGiven is an integer sequence B of length N-1 which is known to satisfy the following:\n\nB_i \\geq \\max(A_i, A_{i+1})\n\nFind the maximum possible sum of the elements of A.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 100\n\n0 \\leq B_i \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nB_1 B_2 ... B_{N-1}\n\nOutput\n\nPrint the maximum possible sum of the elements of A.\n\nSample Input 1\n\n3\n2 5\n\nSample Output 1\n\n9\n\nA can be, for example, ( 2 , 1 , 5 ), ( -1 , -2 , -3 ), or ( 2 , 2 , 5 ). Among those candidates, A = ( 2 , 2 , 5 ) has the maximum possible sum.\n\nSample Input 2\n\n2\n3\n\nSample Output 2\n\n6\n\nSample Input 3\n\n6\n0 153 10 10 23\n\nSample Output 3\n\n53", "sample_input": "3\n2 5\n"}, "reference_outputs": ["9\n"], "source_document_id": "p02917", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere is an integer sequence A of length N whose values are unknown.\n\nGiven is an integer sequence B of length N-1 which is known to satisfy the following:\n\nB_i \\geq \\max(A_i, A_{i+1})\n\nFind the maximum possible sum of the elements of A.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 100\n\n0 \\leq B_i \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nB_1 B_2 ... B_{N-1}\n\nOutput\n\nPrint the maximum possible sum of the elements of A.\n\nSample Input 1\n\n3\n2 5\n\nSample Output 1\n\n9\n\nA can be, for example, ( 2 , 1 , 5 ), ( -1 , -2 , -3 ), or ( 2 , 2 , 5 ). Among those candidates, A = ( 2 , 2 , 5 ) has the maximum possible sum.\n\nSample Input 2\n\n2\n3\n\nSample Output 2\n\n6\n\nSample Input 3\n\n6\n0 153 10 10 23\n\nSample Output 3\n\n53", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3978, "cpu_time_ms": 181, "memory_kb": 19936}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s137592404", "group_id": "codeNet:p02918", "input_text": "(defun count-happy-people (s)\n (labels ((inner (s &optional (cnt 0))\n (cond\n ((null (cdr s)) cnt)\n ((char-equal\n (first s)\n (second s))\n (inner (rest s) (1+ cnt)))\n (t\n (inner (rest s) cnt)))))\n (inner s)))\n\n(defun solve (n k s)\n (let ((start (count-happy-people s)))\n (min (+ start (* k 2))\n (1- n))))\n\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (s (concatenate 'list (read-line))))\n (format t \"~a~%\" (solve n k s))))\n\n(main)", "language": "Lisp", "metadata": {"date": 1598718334, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02918.html", "problem_id": "p02918", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02918/input.txt", "sample_output_relpath": "derived/input_output/data/p02918/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02918/Lisp/s137592404.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s137592404", "user_id": "u425762225"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun count-happy-people (s)\n (labels ((inner (s &optional (cnt 0))\n (cond\n ((null (cdr s)) cnt)\n ((char-equal\n (first s)\n (second s))\n (inner (rest s) (1+ cnt)))\n (t\n (inner (rest s) cnt)))))\n (inner s)))\n\n(defun solve (n k s)\n (let ((start (count-happy-people s)))\n (min (+ start (* k 2))\n (1- n))))\n\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (s (concatenate 'list (read-line))))\n (format t \"~a~%\" (solve n k s))))\n\n(main)", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are N people standing in a queue from west to east.\n\nGiven is a string S of length N representing the directions of the people.\nThe i-th person from the west is facing west if the i-th character of S is L, and east if that character of S is R.\n\nA person is happy if the person in front of him/her is facing the same direction.\nIf no person is standing in front of a person, however, he/she is not happy.\n\nYou can perform the following operation any number of times between 0 and K (inclusive):\n\nOperation: Choose integers l and r such that 1 \\leq l \\leq r \\leq N, and rotate by 180 degrees the part of the queue: the l-th, (l+1)-th, ..., r-th persons. That is, for each i = 0, 1, ..., r-l, the (l + i)-th person from the west will stand the (r - i)-th from the west after the operation, facing east if he/she is facing west now, and vice versa.\n\nWhat is the maximum possible number of happy people you can have?\n\nConstraints\n\nN is an integer satisfying 1 \\leq N \\leq 10^5.\n\nK is an integer satisfying 1 \\leq K \\leq 10^5.\n\n|S| = N\n\nEach character of S is L or R.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nS\n\nOutput\n\nPrint the maximum possible number of happy people after at most K operations.\n\nSample Input 1\n\n6 1\nLRLRRL\n\nSample Output 1\n\n3\n\nIf we choose (l, r) = (2, 5), we have LLLRLL, where the 2-nd, 3-rd, and 6-th persons from the west are happy.\n\nSample Input 2\n\n13 3\nLRRLRLRRLRLLR\n\nSample Output 2\n\n9\n\nSample Input 3\n\n10 1\nLLLLLRRRRR\n\nSample Output 3\n\n9\n\nSample Input 4\n\n9 2\nRRRLRLRLL\n\nSample Output 4\n\n7", "sample_input": "6 1\nLRLRRL\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02918", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are N people standing in a queue from west to east.\n\nGiven is a string S of length N representing the directions of the people.\nThe i-th person from the west is facing west if the i-th character of S is L, and east if that character of S is R.\n\nA person is happy if the person in front of him/her is facing the same direction.\nIf no person is standing in front of a person, however, he/she is not happy.\n\nYou can perform the following operation any number of times between 0 and K (inclusive):\n\nOperation: Choose integers l and r such that 1 \\leq l \\leq r \\leq N, and rotate by 180 degrees the part of the queue: the l-th, (l+1)-th, ..., r-th persons. That is, for each i = 0, 1, ..., r-l, the (l + i)-th person from the west will stand the (r - i)-th from the west after the operation, facing east if he/she is facing west now, and vice versa.\n\nWhat is the maximum possible number of happy people you can have?\n\nConstraints\n\nN is an integer satisfying 1 \\leq N \\leq 10^5.\n\nK is an integer satisfying 1 \\leq K \\leq 10^5.\n\n|S| = N\n\nEach character of S is L or R.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nS\n\nOutput\n\nPrint the maximum possible number of happy people after at most K operations.\n\nSample Input 1\n\n6 1\nLRLRRL\n\nSample Output 1\n\n3\n\nIf we choose (l, r) = (2, 5), we have LLLRLL, where the 2-nd, 3-rd, and 6-th persons from the west are happy.\n\nSample Input 2\n\n13 3\nLRRLRLRRLRLLR\n\nSample Output 2\n\n9\n\nSample Input 3\n\n10 1\nLLLLLRRRRR\n\nSample Output 3\n\n9\n\nSample Input 4\n\n9 2\nRRRLRLRLL\n\nSample Output 4\n\n7", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 583, "cpu_time_ms": 28, "memory_kb": 27232}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s223508542", "group_id": "codeNet:p02919", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;;;\n;;; Implicit treap\n;;; (treap with implicit key)\n;;;\n\n(defconstant +op-identity+ 0\n \"identity element w.r.t. OP\")\n\n(defstruct (itreap (:constructor %make-itreap (value &key left right (count 1) (accumulator value)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum)\n (count 1 :type (integer 0 #.most-positive-fixnum)) ; size of (sub)treap\n (left nil :type (or null itreap))\n (right nil :type (or null itreap)))\n\n(declaim (inline itreap-count))\n(defun itreap-count (itreap)\n \"Returns the length of ITREAP.\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-count itreap)\n 0))\n\n(declaim (inline itreap-accumulator))\n(defun itreap-accumulator (itreap)\n \"Returns the sum (w.r.t. OP) of the whole ITREAP:\nITREAP[0]+ITREAP[1]+...+ITREAP[SIZE-1].\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-accumulator itreap)\n +op-identity+))\n\n(declaim (inline update-count))\n(defun update-count (itreap)\n (declare (itreap itreap))\n (setf (%itreap-count itreap)\n (+ 1\n (itreap-count (%itreap-left itreap))\n (itreap-count (%itreap-right itreap)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (itreap)\n (declare (itreap itreap))\n (setf (%itreap-accumulator itreap)\n (if (%itreap-left itreap)\n (if (%itreap-right itreap)\n (max (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap)\n (%itreap-accumulator (%itreap-right itreap)))\n (max (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap)))\n (if (%itreap-right itreap)\n (max (%itreap-value itreap)\n (%itreap-accumulator (%itreap-right itreap)))\n (%itreap-value itreap)))))\n\n(declaim (inline force-up))\n(defun force-up (itreap)\n \"Propagates up the information from children.\"\n (declare (itreap itreap))\n (update-count itreap)\n (update-accumulator itreap))\n\n(defun make-itreap (vector)\n (declare #.OPT ((simple-array uint31 (*)) vector))\n (let ((size (length vector)))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-itreap (aref vector mid))))\n (setf (%itreap-left node) (build l mid))\n (setf (%itreap-right node) (build (+ mid 1) r))\n (force-up node)\n node))))\n (build 0 size))))\n\n(declaim (inline itreap-query))\n(defun itreap-query (itreap l r)\n \"Queries the `sum' (w.r.t. OP) of the interval [L, R).\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) l r))\n (labels\n ((recur (itreap l r)\n (declare ((integer 0 #.most-positive-fixnum) l r)\n (values fixnum))\n (unless itreap\n (return-from recur +op-identity+))\n (if (and (zerop l) (= r (%itreap-count itreap)))\n (%itreap-accumulator itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= l left-count)\n (if (< left-count r)\n ;; LEFT-COUNT is in [L, R)\n (max (recur (%itreap-left itreap) l (min r left-count))\n (%itreap-value itreap)\n (recur (%itreap-right itreap) 0 (- r left-count 1)))\n ;; LEFT-COUNT is in [R, END)\n (recur (%itreap-left itreap) l (min r left-count)))\n ;; LEFT-COUNT is in [0, L)\n (recur (%itreap-right itreap) (- l left-count 1) (- r left-count 1)))))))\n (recur itreap l r)))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (ps (make-array 100000 :element-type 'uint31)))\n (declare (uint31 n))\n (dotimes (i n)\n (setf (aref ps i) (read-fixnum)))\n (let ((itreap (make-itreap ps)))\n (let ((res 0))\n (declare ((integer 0 #.most-positive-fixnum) res))\n (dotimes (i n)\n (let* ((p (aref ps i))\n (l (sb-int:named-let bisect ((ok -1) (ng i))\n (declare (int32 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap mid i)))\n (declare (fixnum val))\n (if (> val p)\n (bisect mid ng)\n (bisect ok mid))))))\n (r+1 (sb-int:named-let bisect ((ng i) (ok (+ n 1)))\n (declare (int32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap i mid)))\n (declare (fixnum val))\n (if (> val p)\n (bisect ng mid)\n (bisect mid ok))))))\n (r (- r+1 1)))\n (declare (uint31 p))\n (when (>= l 0)\n (let* ((ll (sb-int:named-let bisect ((ok -1) (ng l))\n (declare (int32 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap mid l)))\n (declare (fixnum val))\n (if (> val p)\n (bisect mid ng)\n (bisect ok mid)))))))\n (incf res (* (- r i) (- l ll) p))))\n (when (< r n)\n (let* ((rr+1 (sb-int:named-let bisect ((ng (+ r 1)) (ok (+ n 1)))\n (declare (int32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap r+1 mid)))\n (declare (fixnum val))\n (if (> val p)\n (bisect ng mid)\n (bisect mid ok))))))\n (rr (- rr+1 1)))\n (incf res (* (- i l) (- rr r) p))))))\n (println res)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1567960528, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02919.html", "problem_id": "p02919", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02919/input.txt", "sample_output_relpath": "derived/input_output/data/p02919/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02919/Lisp/s223508542.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s223508542", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;;;\n;;; Implicit treap\n;;; (treap with implicit key)\n;;;\n\n(defconstant +op-identity+ 0\n \"identity element w.r.t. OP\")\n\n(defstruct (itreap (:constructor %make-itreap (value &key left right (count 1) (accumulator value)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum)\n (count 1 :type (integer 0 #.most-positive-fixnum)) ; size of (sub)treap\n (left nil :type (or null itreap))\n (right nil :type (or null itreap)))\n\n(declaim (inline itreap-count))\n(defun itreap-count (itreap)\n \"Returns the length of ITREAP.\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-count itreap)\n 0))\n\n(declaim (inline itreap-accumulator))\n(defun itreap-accumulator (itreap)\n \"Returns the sum (w.r.t. OP) of the whole ITREAP:\nITREAP[0]+ITREAP[1]+...+ITREAP[SIZE-1].\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-accumulator itreap)\n +op-identity+))\n\n(declaim (inline update-count))\n(defun update-count (itreap)\n (declare (itreap itreap))\n (setf (%itreap-count itreap)\n (+ 1\n (itreap-count (%itreap-left itreap))\n (itreap-count (%itreap-right itreap)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (itreap)\n (declare (itreap itreap))\n (setf (%itreap-accumulator itreap)\n (if (%itreap-left itreap)\n (if (%itreap-right itreap)\n (max (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap)\n (%itreap-accumulator (%itreap-right itreap)))\n (max (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap)))\n (if (%itreap-right itreap)\n (max (%itreap-value itreap)\n (%itreap-accumulator (%itreap-right itreap)))\n (%itreap-value itreap)))))\n\n(declaim (inline force-up))\n(defun force-up (itreap)\n \"Propagates up the information from children.\"\n (declare (itreap itreap))\n (update-count itreap)\n (update-accumulator itreap))\n\n(defun make-itreap (vector)\n (declare #.OPT ((simple-array uint31 (*)) vector))\n (let ((size (length vector)))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-itreap (aref vector mid))))\n (setf (%itreap-left node) (build l mid))\n (setf (%itreap-right node) (build (+ mid 1) r))\n (force-up node)\n node))))\n (build 0 size))))\n\n(declaim (inline itreap-query))\n(defun itreap-query (itreap l r)\n \"Queries the `sum' (w.r.t. OP) of the interval [L, R).\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) l r))\n (labels\n ((recur (itreap l r)\n (declare ((integer 0 #.most-positive-fixnum) l r)\n (values fixnum))\n (unless itreap\n (return-from recur +op-identity+))\n (if (and (zerop l) (= r (%itreap-count itreap)))\n (%itreap-accumulator itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= l left-count)\n (if (< left-count r)\n ;; LEFT-COUNT is in [L, R)\n (max (recur (%itreap-left itreap) l (min r left-count))\n (%itreap-value itreap)\n (recur (%itreap-right itreap) 0 (- r left-count 1)))\n ;; LEFT-COUNT is in [R, END)\n (recur (%itreap-left itreap) l (min r left-count)))\n ;; LEFT-COUNT is in [0, L)\n (recur (%itreap-right itreap) (- l left-count 1) (- r left-count 1)))))))\n (recur itreap l r)))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (ps (make-array 100000 :element-type 'uint31)))\n (declare (uint31 n))\n (dotimes (i n)\n (setf (aref ps i) (read-fixnum)))\n (let ((itreap (make-itreap ps)))\n (let ((res 0))\n (declare ((integer 0 #.most-positive-fixnum) res))\n (dotimes (i n)\n (let* ((p (aref ps i))\n (l (sb-int:named-let bisect ((ok -1) (ng i))\n (declare (int32 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap mid i)))\n (declare (fixnum val))\n (if (> val p)\n (bisect mid ng)\n (bisect ok mid))))))\n (r+1 (sb-int:named-let bisect ((ng i) (ok (+ n 1)))\n (declare (int32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap i mid)))\n (declare (fixnum val))\n (if (> val p)\n (bisect ng mid)\n (bisect mid ok))))))\n (r (- r+1 1)))\n (declare (uint31 p))\n (when (>= l 0)\n (let* ((ll (sb-int:named-let bisect ((ok -1) (ng l))\n (declare (int32 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap mid l)))\n (declare (fixnum val))\n (if (> val p)\n (bisect mid ng)\n (bisect ok mid)))))))\n (incf res (* (- r i) (- l ll) p))))\n (when (< r n)\n (let* ((rr+1 (sb-int:named-let bisect ((ng (+ r 1)) (ok (+ n 1)))\n (declare (int32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap r+1 mid)))\n (declare (fixnum val))\n (if (> val p)\n (bisect ng mid)\n (bisect mid ok))))))\n (rr (- rr+1 1)))\n (incf res (* (- i l) (- rr r) p))))))\n (println res)))))\n\n#-swank (main)\n", "problem_context": "Score: 500 points\n\nProblem Statement\n\nGiven is a permutation P of \\{1, 2, \\ldots, N\\}.\n\nFor a pair (L, R) (1 \\le L \\lt R \\le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \\ldots, P_R.\n\nFind \\displaystyle \\sum_{L=1}^{N-1} \\sum_{R=L+1}^{N} X_{L,R}.\n\nConstraints\n\n2 \\le N \\le 10^5\n\n1 \\le P_i \\le N\n\nP_i \\neq P_j (i \\neq j)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 P_2 \\ldots P_N\n\nOutput\n\nPrint \\displaystyle \\sum_{L=1}^{N-1} \\sum_{R=L+1}^{N} X_{L,R}.\n\nSample Input 1\n\n3\n2 3 1\n\nSample Output 1\n\n5\n\nX_{1, 2} = 2, X_{1, 3} = 2, and X_{2, 3} = 1, so the sum is 2 + 2 + 1 = 5.\n\nSample Input 2\n\n5\n1 2 3 4 5\n\nSample Output 2\n\n30\n\nSample Input 3\n\n8\n8 2 7 3 4 5 6 1\n\nSample Output 3\n\n136", "sample_input": "3\n2 3 1\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02919", "source_text": "Score: 500 points\n\nProblem Statement\n\nGiven is a permutation P of \\{1, 2, \\ldots, N\\}.\n\nFor a pair (L, R) (1 \\le L \\lt R \\le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \\ldots, P_R.\n\nFind \\displaystyle \\sum_{L=1}^{N-1} \\sum_{R=L+1}^{N} X_{L,R}.\n\nConstraints\n\n2 \\le N \\le 10^5\n\n1 \\le P_i \\le N\n\nP_i \\neq P_j (i \\neq j)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 P_2 \\ldots P_N\n\nOutput\n\nPrint \\displaystyle \\sum_{L=1}^{N-1} \\sum_{R=L+1}^{N} X_{L,R}.\n\nSample Input 1\n\n3\n2 3 1\n\nSample Output 1\n\n5\n\nX_{1, 2} = 2, X_{1, 3} = 2, and X_{2, 3} = 1, so the sum is 2 + 2 + 1 = 5.\n\nSample Input 2\n\n5\n1 2 3 4 5\n\nSample Output 2\n\n30\n\nSample Input 3\n\n8\n8 2 7 3 4 5 6 1\n\nSample Output 3\n\n136", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9157, "cpu_time_ms": 1286, "memory_kb": 30944}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s734350229", "group_id": "codeNet:p02919", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Implicit treap\n;;; (treap with implicit key)\n;;;\n\n;; Note:\n;; - You cannot rely on the side effect when you call any destructive operations\n;; on a treap. Always use the returned value.\n;; - An empty treap is NIL.\n\n(declaim (inline op))\n(defun op (a b)\n \"Is a binary operator comprising a monoid.\"\n (declare (fixnum a b))\n (max a b))\n\n(defconstant +op-identity+ 0\n \"identity element w.r.t. OP\")\n\n(defstruct (itreap (:constructor %make-itreap (value priority &key left right (count 1) (accumulator value)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (integer 0 #.most-positive-fixnum)) ; size of (sub)treap\n (left nil :type (or null itreap))\n (right nil :type (or null itreap)))\n\n(declaim (inline itreap-count))\n(defun itreap-count (itreap)\n \"Returns the length of ITREAP.\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-count itreap)\n 0))\n\n(declaim (inline itreap-accumulator))\n(defun itreap-accumulator (itreap)\n \"Returns the sum (w.r.t. OP) of the whole ITREAP:\nITREAP[0]+ITREAP[1]+...+ITREAP[SIZE-1].\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-accumulator itreap)\n +op-identity+))\n\n(declaim (inline update-count))\n(defun update-count (itreap)\n (declare (itreap itreap))\n (setf (%itreap-count itreap)\n (+ 1\n (itreap-count (%itreap-left itreap))\n (itreap-count (%itreap-right itreap)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (itreap)\n (declare (itreap itreap))\n (setf (%itreap-accumulator itreap)\n (if (%itreap-left itreap)\n (if (%itreap-right itreap)\n (let ((mid (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap))))\n (op mid (%itreap-accumulator (%itreap-right itreap))))\n (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap)))\n (if (%itreap-right itreap)\n (op (%itreap-value itreap)\n (%itreap-accumulator (%itreap-right itreap)))\n (%itreap-value itreap)))))\n\n(declaim (inline force-up))\n(defun force-up (itreap)\n \"Propagates up the information from children.\"\n (declare (itreap itreap))\n (update-count itreap)\n (update-accumulator itreap))\n\n(declaim (inline itreap-map))\n(defun itreap-map (function itreap)\n \"Successively applies FUNCTION to ITREAP[0], ..., ITREAP[SIZE-1].\"\n (declare (function function))\n (labels ((recur (node)\n (when node\n (recur (%itreap-left node))\n (funcall function (%itreap-value node))\n (recur (%itreap-right node))\n (force-up node))))\n (recur itreap)))\n\n(defmethod print-object ((object itreap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (itreap-map (lambda (x)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write x :stream stream))\n object))))\n\n(defun %heapify (top)\n \"Properly swaps the priorities of the node and its two children.\"\n (declare (optimize (speed 3) (safety 0)))\n (when top\n (let ((high-priority-node top))\n (when (and (%itreap-left top)\n (> (%itreap-priority (%itreap-left top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-left top)))\n (when (and (%itreap-right top)\n (> (%itreap-priority (%itreap-right top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-right top)))\n (unless (eql high-priority-node top)\n (rotatef (%itreap-priority high-priority-node)\n (%itreap-priority top))\n (%heapify high-priority-node)))))\n\n(declaim (inline make-itreap))\n(defun make-itreap (size &key initial-contents)\n \"Makes a treap of SIZE in O(SIZE) time. Its values are filled with the\nidentity element unless INITIAL-CONTENTS are supplied.\"\n (declare ((or null vector) initial-contents))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-itreap (if initial-contents\n (aref initial-contents mid)\n +op-identity+)\n (random most-positive-fixnum))))\n (setf (%itreap-left node) (build l mid))\n (setf (%itreap-right node) (build (+ mid 1) r))\n (%heapify node)\n (force-up node)\n node))))\n (build 0 size)))\n\n(defun itreap-query (itreap l r)\n \"Queries the `sum' (w.r.t. OP) of the interval [L, R).\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) l r))\n (labels\n ((recur (itreap l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless itreap\n (return-from recur +op-identity+))\n (if (and (zerop l) (= r (%itreap-count itreap)))\n (%itreap-accumulator itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= l left-count)\n (if (< left-count r)\n ;; LEFT-COUNT is in [L, R)\n (op (op (recur (%itreap-left itreap) l (min r left-count))\n (%itreap-value itreap))\n (recur (%itreap-right itreap) 0 (- r left-count 1)))\n ;; LEFT-COUNT is in [R, END)\n (recur (%itreap-left itreap) l (min r left-count)))\n ;; LEFT-COUNT is in [0, L)\n (recur (%itreap-right itreap) (- l left-count 1) (- r left-count 1)))))))\n (recur itreap l r)))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (ps (make-array 100000 :element-type 'uint31)))\n (declare (uint31 n))\n (dotimes (i n)\n (setf (aref ps i) (read-fixnum)))\n (let ((itreap (make-itreap 100000 :initial-contents ps)))\n (let ((res 0))\n (declare ((integer 0 #.most-positive-fixnum) res))\n (dotimes (i n)\n (let* ((l (sb-int:named-let bisect ((ok -1) (ng i))\n (declare (int32 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap mid i)))\n (declare (fixnum val))\n (if (> val (aref ps i))\n (bisect mid ng)\n (bisect ok mid))))))\n (r+1 (sb-int:named-let bisect ((ng i) (ok (+ n 1)))\n (declare (int32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap i mid)))\n (declare (fixnum val))\n (if (> val (aref ps i))\n (bisect ng mid)\n (bisect mid ok))))))\n (r (- r+1 1)))\n (when (>= l 0)\n (let* ((ll (sb-int:named-let bisect ((ok -1) (ng l))\n (declare (int32 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap mid l)))\n (declare (fixnum val))\n (if (> val (aref ps i))\n (bisect mid ng)\n (bisect ok mid)))))))\n (incf res (* (- r i) (- l ll) (aref ps i)))))\n (when (< r n)\n (let* ((rr+1 (sb-int:named-let bisect ((ng (+ r 1)) (ok (+ n 1)))\n (declare (int32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap r+1 mid)))\n (declare (fixnum val))\n (if (> val (aref ps i))\n (bisect ng mid)\n (bisect mid ok))))))\n (rr (- rr+1 1)))\n (incf res (* (- i l) (- rr r) (aref ps i)))))))\n (println res)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1567959634, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02919.html", "problem_id": "p02919", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02919/input.txt", "sample_output_relpath": "derived/input_output/data/p02919/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02919/Lisp/s734350229.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s734350229", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Implicit treap\n;;; (treap with implicit key)\n;;;\n\n;; Note:\n;; - You cannot rely on the side effect when you call any destructive operations\n;; on a treap. Always use the returned value.\n;; - An empty treap is NIL.\n\n(declaim (inline op))\n(defun op (a b)\n \"Is a binary operator comprising a monoid.\"\n (declare (fixnum a b))\n (max a b))\n\n(defconstant +op-identity+ 0\n \"identity element w.r.t. OP\")\n\n(defstruct (itreap (:constructor %make-itreap (value priority &key left right (count 1) (accumulator value)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (integer 0 #.most-positive-fixnum)) ; size of (sub)treap\n (left nil :type (or null itreap))\n (right nil :type (or null itreap)))\n\n(declaim (inline itreap-count))\n(defun itreap-count (itreap)\n \"Returns the length of ITREAP.\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-count itreap)\n 0))\n\n(declaim (inline itreap-accumulator))\n(defun itreap-accumulator (itreap)\n \"Returns the sum (w.r.t. OP) of the whole ITREAP:\nITREAP[0]+ITREAP[1]+...+ITREAP[SIZE-1].\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-accumulator itreap)\n +op-identity+))\n\n(declaim (inline update-count))\n(defun update-count (itreap)\n (declare (itreap itreap))\n (setf (%itreap-count itreap)\n (+ 1\n (itreap-count (%itreap-left itreap))\n (itreap-count (%itreap-right itreap)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (itreap)\n (declare (itreap itreap))\n (setf (%itreap-accumulator itreap)\n (if (%itreap-left itreap)\n (if (%itreap-right itreap)\n (let ((mid (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap))))\n (op mid (%itreap-accumulator (%itreap-right itreap))))\n (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap)))\n (if (%itreap-right itreap)\n (op (%itreap-value itreap)\n (%itreap-accumulator (%itreap-right itreap)))\n (%itreap-value itreap)))))\n\n(declaim (inline force-up))\n(defun force-up (itreap)\n \"Propagates up the information from children.\"\n (declare (itreap itreap))\n (update-count itreap)\n (update-accumulator itreap))\n\n(declaim (inline itreap-map))\n(defun itreap-map (function itreap)\n \"Successively applies FUNCTION to ITREAP[0], ..., ITREAP[SIZE-1].\"\n (declare (function function))\n (labels ((recur (node)\n (when node\n (recur (%itreap-left node))\n (funcall function (%itreap-value node))\n (recur (%itreap-right node))\n (force-up node))))\n (recur itreap)))\n\n(defmethod print-object ((object itreap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (itreap-map (lambda (x)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write x :stream stream))\n object))))\n\n(defun %heapify (top)\n \"Properly swaps the priorities of the node and its two children.\"\n (declare (optimize (speed 3) (safety 0)))\n (when top\n (let ((high-priority-node top))\n (when (and (%itreap-left top)\n (> (%itreap-priority (%itreap-left top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-left top)))\n (when (and (%itreap-right top)\n (> (%itreap-priority (%itreap-right top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-right top)))\n (unless (eql high-priority-node top)\n (rotatef (%itreap-priority high-priority-node)\n (%itreap-priority top))\n (%heapify high-priority-node)))))\n\n(declaim (inline make-itreap))\n(defun make-itreap (size &key initial-contents)\n \"Makes a treap of SIZE in O(SIZE) time. Its values are filled with the\nidentity element unless INITIAL-CONTENTS are supplied.\"\n (declare ((or null vector) initial-contents))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-itreap (if initial-contents\n (aref initial-contents mid)\n +op-identity+)\n (random most-positive-fixnum))))\n (setf (%itreap-left node) (build l mid))\n (setf (%itreap-right node) (build (+ mid 1) r))\n (%heapify node)\n (force-up node)\n node))))\n (build 0 size)))\n\n(defun itreap-query (itreap l r)\n \"Queries the `sum' (w.r.t. OP) of the interval [L, R).\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) l r))\n (labels\n ((recur (itreap l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless itreap\n (return-from recur +op-identity+))\n (if (and (zerop l) (= r (%itreap-count itreap)))\n (%itreap-accumulator itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= l left-count)\n (if (< left-count r)\n ;; LEFT-COUNT is in [L, R)\n (op (op (recur (%itreap-left itreap) l (min r left-count))\n (%itreap-value itreap))\n (recur (%itreap-right itreap) 0 (- r left-count 1)))\n ;; LEFT-COUNT is in [R, END)\n (recur (%itreap-left itreap) l (min r left-count)))\n ;; LEFT-COUNT is in [0, L)\n (recur (%itreap-right itreap) (- l left-count 1) (- r left-count 1)))))))\n (recur itreap l r)))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (ps (make-array 100000 :element-type 'uint31)))\n (declare (uint31 n))\n (dotimes (i n)\n (setf (aref ps i) (read-fixnum)))\n (let ((itreap (make-itreap 100000 :initial-contents ps)))\n (let ((res 0))\n (declare ((integer 0 #.most-positive-fixnum) res))\n (dotimes (i n)\n (let* ((l (sb-int:named-let bisect ((ok -1) (ng i))\n (declare (int32 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap mid i)))\n (declare (fixnum val))\n (if (> val (aref ps i))\n (bisect mid ng)\n (bisect ok mid))))))\n (r+1 (sb-int:named-let bisect ((ng i) (ok (+ n 1)))\n (declare (int32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap i mid)))\n (declare (fixnum val))\n (if (> val (aref ps i))\n (bisect ng mid)\n (bisect mid ok))))))\n (r (- r+1 1)))\n (when (>= l 0)\n (let* ((ll (sb-int:named-let bisect ((ok -1) (ng l))\n (declare (int32 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap mid l)))\n (declare (fixnum val))\n (if (> val (aref ps i))\n (bisect mid ng)\n (bisect ok mid)))))))\n (incf res (* (- r i) (- l ll) (aref ps i)))))\n (when (< r n)\n (let* ((rr+1 (sb-int:named-let bisect ((ng (+ r 1)) (ok (+ n 1)))\n (declare (int32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap r+1 mid)))\n (declare (fixnum val))\n (if (> val (aref ps i))\n (bisect ng mid)\n (bisect mid ok))))))\n (rr (- rr+1 1)))\n (incf res (* (- i l) (- rr r) (aref ps i)))))))\n (println res)))))\n\n#-swank (main)\n", "problem_context": "Score: 500 points\n\nProblem Statement\n\nGiven is a permutation P of \\{1, 2, \\ldots, N\\}.\n\nFor a pair (L, R) (1 \\le L \\lt R \\le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \\ldots, P_R.\n\nFind \\displaystyle \\sum_{L=1}^{N-1} \\sum_{R=L+1}^{N} X_{L,R}.\n\nConstraints\n\n2 \\le N \\le 10^5\n\n1 \\le P_i \\le N\n\nP_i \\neq P_j (i \\neq j)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 P_2 \\ldots P_N\n\nOutput\n\nPrint \\displaystyle \\sum_{L=1}^{N-1} \\sum_{R=L+1}^{N} X_{L,R}.\n\nSample Input 1\n\n3\n2 3 1\n\nSample Output 1\n\n5\n\nX_{1, 2} = 2, X_{1, 3} = 2, and X_{2, 3} = 1, so the sum is 2 + 2 + 1 = 5.\n\nSample Input 2\n\n5\n1 2 3 4 5\n\nSample Output 2\n\n30\n\nSample Input 3\n\n8\n8 2 7 3 4 5 6 1\n\nSample Output 3\n\n136", "sample_input": "3\n2 3 1\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02919", "source_text": "Score: 500 points\n\nProblem Statement\n\nGiven is a permutation P of \\{1, 2, \\ldots, N\\}.\n\nFor a pair (L, R) (1 \\le L \\lt R \\le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \\ldots, P_R.\n\nFind \\displaystyle \\sum_{L=1}^{N-1} \\sum_{R=L+1}^{N} X_{L,R}.\n\nConstraints\n\n2 \\le N \\le 10^5\n\n1 \\le P_i \\le N\n\nP_i \\neq P_j (i \\neq j)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 P_2 \\ldots P_N\n\nOutput\n\nPrint \\displaystyle \\sum_{L=1}^{N-1} \\sum_{R=L+1}^{N} X_{L,R}.\n\nSample Input 1\n\n3\n2 3 1\n\nSample Output 1\n\n5\n\nX_{1, 2} = 2, X_{1, 3} = 2, and X_{2, 3} = 1, so the sum is 2 + 2 + 1 = 5.\n\nSample Input 2\n\n5\n1 2 3 4 5\n\nSample Output 2\n\n30\n\nSample Input 3\n\n8\n8 2 7 3 4 5 6 1\n\nSample Output 3\n\n136", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11402, "cpu_time_ms": 1381, "memory_kb": 46568}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s078320767", "group_id": "codeNet:p02919", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;;;\n;;; Disjoint sparse table on arbitrary semigroup\n;;;\n\n;;; Reference:\n;;; https://discuss.codechef.com/questions/117696/tutorial-disjoint-sparse-table\n;;; http://noshi91.hatenablog.com/entry/2018/05/08/183946 (Japanese)\n;;; http://drken1215.hatenablog.com/entry/2018/09/08/162600 (Japanese)\n\n;; NOTE: This constructor is slow on SBCL version earlier than 1.5.6 as the type\n;; propagation of MAKE-ARRAY doesn't work. The following files are required to\n;; enable the optimization.\n;; version < 1.5.0: array-element-type.lisp, make-array-header.lisp\n;; version < 1.5.6: make-array-header.lisp\n(declaim (inline make-disjoint-sparse-table))\n(defun make-disjoint-sparse-table (vector binop)\n \"BINOP := binary operator (comprising a semigroup)\"\n (let* ((n (length vector))\n (height (integer-length (- n 1)))\n (table (make-array (list height n) :element-type 'uint32)))\n (dotimes (j n)\n (setf (aref table 0 j) (aref vector j)))\n (do ((i 1 (+ i 1)))\n ((>= i height))\n (let* ((width/2 (ash 1 i))\n (width (* width/2 2)))\n (do ((j 0 (+ j width)))\n ((>= j n))\n (let ((mid (min (+ j width/2) n)))\n ;; fill the first half\n (setf (aref table i (- mid 1))\n (aref vector (- mid 1)))\n (do ((k (- mid 2) (- k 1)))\n ((< k j))\n (setf (aref table i k)\n (funcall binop (aref vector k) (aref table i (+ k 1)))))\n (when (>= mid n)\n (return))\n ;; fill the second half\n (setf (aref table i mid)\n (aref vector mid))\n (let ((end (min n (+ mid width/2))))\n (do ((k (+ mid 1) (+ k 1)))\n ((>= k end))\n (setf (aref table i k)\n (funcall binop (aref table i (- k 1)) (aref vector k)))))))))\n table))\n\n(declaim (inline dst-query))\n(defun dst-query (table binop left right)\n \"Queries the interval [LEFT, RIGHT).\"\n (declare ((integer 0 #.most-positive-fixnum) left right)\n ((simple-array * (* *)) table))\n (when (= left right)\n (return-from dst-query 0))\n (setq right (- right 1)) ;; change to closed interval\n (if (= left right)\n (aref table 0 left)\n (let ((h (- (integer-length (logxor left right)) 1)))\n (funcall binop\n (aref table h left)\n (aref table h right)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (ps (make-array 100000 :element-type 'uint32)))\n (declare (uint31 n))\n (dotimes (i n)\n (setf (aref ps i) (read-fixnum)))\n (let ((dtable (make-disjoint-sparse-table ps #'max)))\n (let ((res 0))\n (declare (fixnum res))\n (dotimes (i n)\n (let ((p (aref ps i)))\n (declare (uint31 p))\n (let* ((l (sb-int:named-let bisect ((ok -1) (ng i))\n (declare (int32 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (dst-query dtable #'max mid i)))\n (declare (uint32 val))\n (if (> val p)\n (bisect mid ng)\n (bisect ok mid))))))\n (r+1 (sb-int:named-let bisect ((ng i) (ok (+ n 1)))\n (declare (int32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (dst-query dtable #'max i mid)))\n (declare (uint32 val))\n (if (> val p)\n (bisect ng mid)\n (bisect mid ok))))))\n (r (- r+1 1)))\n (when (>= l 0)\n (let* ((ll (sb-int:named-let bisect ((ok -1) (ng l))\n (declare (int32 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (dst-query dtable #'max mid l)))\n (declare (uint32 val))\n (if (> val p)\n (bisect mid ng)\n (bisect ok mid)))))))\n (incf res (* (- r i)\n (- l ll)\n p))))\n (when (< r n)\n (let* ((rr+1 (sb-int:named-let bisect ((ng (+ r 1)) (ok (+ n 1)))\n (declare (int32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (dst-query dtable #'max r+1 mid)))\n (declare (uint32 val))\n (if (> val p)\n (bisect ng mid)\n (bisect mid ok))))))\n (rr (- rr+1 1)))\n (incf res (* (- i l)\n (- rr r)\n p)))))))\n (println res)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1567894535, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02919.html", "problem_id": "p02919", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02919/input.txt", "sample_output_relpath": "derived/input_output/data/p02919/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02919/Lisp/s078320767.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s078320767", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;;;\n;;; Disjoint sparse table on arbitrary semigroup\n;;;\n\n;;; Reference:\n;;; https://discuss.codechef.com/questions/117696/tutorial-disjoint-sparse-table\n;;; http://noshi91.hatenablog.com/entry/2018/05/08/183946 (Japanese)\n;;; http://drken1215.hatenablog.com/entry/2018/09/08/162600 (Japanese)\n\n;; NOTE: This constructor is slow on SBCL version earlier than 1.5.6 as the type\n;; propagation of MAKE-ARRAY doesn't work. The following files are required to\n;; enable the optimization.\n;; version < 1.5.0: array-element-type.lisp, make-array-header.lisp\n;; version < 1.5.6: make-array-header.lisp\n(declaim (inline make-disjoint-sparse-table))\n(defun make-disjoint-sparse-table (vector binop)\n \"BINOP := binary operator (comprising a semigroup)\"\n (let* ((n (length vector))\n (height (integer-length (- n 1)))\n (table (make-array (list height n) :element-type 'uint32)))\n (dotimes (j n)\n (setf (aref table 0 j) (aref vector j)))\n (do ((i 1 (+ i 1)))\n ((>= i height))\n (let* ((width/2 (ash 1 i))\n (width (* width/2 2)))\n (do ((j 0 (+ j width)))\n ((>= j n))\n (let ((mid (min (+ j width/2) n)))\n ;; fill the first half\n (setf (aref table i (- mid 1))\n (aref vector (- mid 1)))\n (do ((k (- mid 2) (- k 1)))\n ((< k j))\n (setf (aref table i k)\n (funcall binop (aref vector k) (aref table i (+ k 1)))))\n (when (>= mid n)\n (return))\n ;; fill the second half\n (setf (aref table i mid)\n (aref vector mid))\n (let ((end (min n (+ mid width/2))))\n (do ((k (+ mid 1) (+ k 1)))\n ((>= k end))\n (setf (aref table i k)\n (funcall binop (aref table i (- k 1)) (aref vector k)))))))))\n table))\n\n(declaim (inline dst-query))\n(defun dst-query (table binop left right)\n \"Queries the interval [LEFT, RIGHT).\"\n (declare ((integer 0 #.most-positive-fixnum) left right)\n ((simple-array * (* *)) table))\n (when (= left right)\n (return-from dst-query 0))\n (setq right (- right 1)) ;; change to closed interval\n (if (= left right)\n (aref table 0 left)\n (let ((h (- (integer-length (logxor left right)) 1)))\n (funcall binop\n (aref table h left)\n (aref table h right)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (ps (make-array 100000 :element-type 'uint32)))\n (declare (uint31 n))\n (dotimes (i n)\n (setf (aref ps i) (read-fixnum)))\n (let ((dtable (make-disjoint-sparse-table ps #'max)))\n (let ((res 0))\n (declare (fixnum res))\n (dotimes (i n)\n (let ((p (aref ps i)))\n (declare (uint31 p))\n (let* ((l (sb-int:named-let bisect ((ok -1) (ng i))\n (declare (int32 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (dst-query dtable #'max mid i)))\n (declare (uint32 val))\n (if (> val p)\n (bisect mid ng)\n (bisect ok mid))))))\n (r+1 (sb-int:named-let bisect ((ng i) (ok (+ n 1)))\n (declare (int32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (dst-query dtable #'max i mid)))\n (declare (uint32 val))\n (if (> val p)\n (bisect ng mid)\n (bisect mid ok))))))\n (r (- r+1 1)))\n (when (>= l 0)\n (let* ((ll (sb-int:named-let bisect ((ok -1) (ng l))\n (declare (int32 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (dst-query dtable #'max mid l)))\n (declare (uint32 val))\n (if (> val p)\n (bisect mid ng)\n (bisect ok mid)))))))\n (incf res (* (- r i)\n (- l ll)\n p))))\n (when (< r n)\n (let* ((rr+1 (sb-int:named-let bisect ((ng (+ r 1)) (ok (+ n 1)))\n (declare (int32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (dst-query dtable #'max r+1 mid)))\n (declare (uint32 val))\n (if (> val p)\n (bisect ng mid)\n (bisect mid ok))))))\n (rr (- rr+1 1)))\n (incf res (* (- i l)\n (- rr r)\n p)))))))\n (println res)))))\n\n#-swank (main)\n", "problem_context": "Score: 500 points\n\nProblem Statement\n\nGiven is a permutation P of \\{1, 2, \\ldots, N\\}.\n\nFor a pair (L, R) (1 \\le L \\lt R \\le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \\ldots, P_R.\n\nFind \\displaystyle \\sum_{L=1}^{N-1} \\sum_{R=L+1}^{N} X_{L,R}.\n\nConstraints\n\n2 \\le N \\le 10^5\n\n1 \\le P_i \\le N\n\nP_i \\neq P_j (i \\neq j)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 P_2 \\ldots P_N\n\nOutput\n\nPrint \\displaystyle \\sum_{L=1}^{N-1} \\sum_{R=L+1}^{N} X_{L,R}.\n\nSample Input 1\n\n3\n2 3 1\n\nSample Output 1\n\n5\n\nX_{1, 2} = 2, X_{1, 3} = 2, and X_{2, 3} = 1, so the sum is 2 + 2 + 1 = 5.\n\nSample Input 2\n\n5\n1 2 3 4 5\n\nSample Output 2\n\n30\n\nSample Input 3\n\n8\n8 2 7 3 4 5 6 1\n\nSample Output 3\n\n136", "sample_input": "3\n2 3 1\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02919", "source_text": "Score: 500 points\n\nProblem Statement\n\nGiven is a permutation P of \\{1, 2, \\ldots, N\\}.\n\nFor a pair (L, R) (1 \\le L \\lt R \\le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \\ldots, P_R.\n\nFind \\displaystyle \\sum_{L=1}^{N-1} \\sum_{R=L+1}^{N} X_{L,R}.\n\nConstraints\n\n2 \\le N \\le 10^5\n\n1 \\le P_i \\le N\n\nP_i \\neq P_j (i \\neq j)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 P_2 \\ldots P_N\n\nOutput\n\nPrint \\displaystyle \\sum_{L=1}^{N-1} \\sum_{R=L+1}^{N} X_{L,R}.\n\nSample Input 1\n\n3\n2 3 1\n\nSample Output 1\n\n5\n\nX_{1, 2} = 2, X_{1, 3} = 2, and X_{2, 3} = 1, so the sum is 2 + 2 + 1 = 5.\n\nSample Input 2\n\n5\n1 2 3 4 5\n\nSample Output 2\n\n30\n\nSample Input 3\n\n8\n8 2 7 3 4 5 6 1\n\nSample Output 3\n\n136", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7917, "cpu_time_ms": 277, "memory_kb": 42596}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s399964439", "group_id": "codeNet:p02919", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Implicit treap\n;;; (treap with implicit key)\n;;;\n\n;; Note:\n;; - You cannot rely on the side effect when you call any destructive operations\n;; on a treap. Always use the returned value.\n;; - An empty treap is NIL.\n\n(declaim (inline op))\n(defun op (a b)\n \"Is a binary operator comprising a monoid.\"\n (declare (fixnum a b))\n (max a b))\n\n(defconstant +op-identity+ 0\n \"identity element w.r.t. OP\")\n\n(defstruct (itreap (:constructor %make-itreap (value priority &key left right (count 1) (accumulator value)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (integer 0 #.most-positive-fixnum)) ; size of (sub)treap\n (left nil :type (or null itreap))\n (right nil :type (or null itreap)))\n\n(declaim (inline itreap-count))\n(defun itreap-count (itreap)\n \"Returns the length of ITREAP.\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-count itreap)\n 0))\n\n(declaim (inline itreap-accumulator))\n(defun itreap-accumulator (itreap)\n \"Returns the sum (w.r.t. OP) of the whole ITREAP:\nITREAP[0]+ITREAP[1]+...+ITREAP[SIZE-1].\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-accumulator itreap)\n +op-identity+))\n\n(declaim (inline update-count))\n(defun update-count (itreap)\n (declare (itreap itreap))\n (setf (%itreap-count itreap)\n (+ 1\n (itreap-count (%itreap-left itreap))\n (itreap-count (%itreap-right itreap)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (itreap)\n (declare (itreap itreap))\n (setf (%itreap-accumulator itreap)\n (if (%itreap-left itreap)\n (if (%itreap-right itreap)\n (let ((mid (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap))))\n (declare (dynamic-extent mid))\n (op mid (%itreap-accumulator (%itreap-right itreap))))\n (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap)))\n (if (%itreap-right itreap)\n (op (%itreap-value itreap)\n (%itreap-accumulator (%itreap-right itreap)))\n (%itreap-value itreap)))))\n\n(declaim (inline force-up))\n(defun force-up (itreap)\n \"Propagates up the information from children.\"\n (declare (itreap itreap))\n (update-count itreap)\n (update-accumulator itreap))\n\n(declaim (inline force-down))\n(defun force-down (itreap)\n \"Propagates down the information to children.\"\n (declare (ignorable itreap)))\n\n(defun itreap-split (itreap index)\n \"Destructively splits the ITREAP into two nodes [0, INDEX) and [INDEX, N),\nwhere N is the number of elements of the ITREAP.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) index))\n (unless (<= index (itreap-count itreap))\n (error 'invalid-itreap-index-error :index index :itreap itreap))\n (labels ((recur (itreap ikey)\n (unless itreap\n (return-from itreap-split (values nil nil)))\n (force-down itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= ikey left-count)\n (multiple-value-bind (left right)\n (itreap-split (%itreap-left itreap) ikey)\n (setf (%itreap-left itreap) right)\n (force-up itreap)\n (values left itreap))\n (multiple-value-bind (left right)\n (itreap-split (%itreap-right itreap) (- ikey left-count 1))\n (setf (%itreap-right itreap) left)\n (force-up itreap)\n (values itreap right))))))\n (recur itreap index)))\n\n(defun itreap-merge (left right)\n \"Destructively concatenates two ITREAPs.\"\n (declare (optimize (speed 3))\n ((or null itreap) left right))\n (cond ((null left) (when right (force-down right) (force-up right)) right)\n ((null right) (when left (force-down left) (force-up left)) left)\n (t (force-down left)\n (force-down right)\n (if (> (%itreap-priority left) (%itreap-priority right))\n (progn\n (setf (%itreap-right left)\n (itreap-merge (%itreap-right left) right))\n (force-up left)\n left)\n (progn\n (setf (%itreap-left right)\n (itreap-merge left (%itreap-left right)))\n (force-up right)\n right)))))\n\n(define-condition invalid-itreap-index-error (type-error)\n ((itreap :initarg :itreap :reader invalid-itreap-index-error-itreap)\n (index :initarg :index :reader invalid-itreap-index-error-index))\n (:report\n (lambda (condition stream)\n (let ((index (invalid-itreap-index-error-index condition)))\n (if (consp index)\n (format stream \"Invalid range [~W, ~W) for itreap ~W.\"\n (car index)\n (cdr index)\n (invalid-itreap-index-error-itreap condition))\n (format stream \"Invalid index ~W for itreap ~W.\"\n index\n (invalid-itreap-index-error-itreap condition)))))))\n\n(declaim (inline itreap-map))\n(defun itreap-map (function itreap)\n \"Successively applies FUNCTION to ITREAP[0], ..., ITREAP[SIZE-1].\"\n (declare (function function))\n (labels ((recur (node)\n (when node\n (force-down node)\n (recur (%itreap-left node))\n (funcall function (%itreap-value node))\n (recur (%itreap-right node))\n (force-up node))))\n (recur itreap)))\n\n(defmethod print-object ((object itreap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (itreap-map (lambda (x)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write x :stream stream))\n object))))\n\n(defun %heapify (top)\n \"Properly swaps the priorities of the node and its two children.\"\n (declare (optimize (speed 3) (safety 0)))\n (when top\n (let ((high-priority-node top))\n (when (and (%itreap-left top)\n (> (%itreap-priority (%itreap-left top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-left top)))\n (when (and (%itreap-right top)\n (> (%itreap-priority (%itreap-right top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-right top)))\n (unless (eql high-priority-node top)\n (rotatef (%itreap-priority high-priority-node)\n (%itreap-priority top))\n (%heapify high-priority-node)))))\n\n(declaim (inline make-itreap))\n(defun make-itreap (size &key initial-contents)\n \"Makes a treap of SIZE in O(SIZE) time. Its values are filled with the\nidentity element unless INITIAL-CONTENTS are supplied.\"\n (declare ((or null vector) initial-contents))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-itreap (if initial-contents\n (aref initial-contents mid)\n +op-identity+)\n (random most-positive-fixnum))))\n (setf (%itreap-left node) (build l mid))\n (setf (%itreap-right node) (build (+ mid 1) r))\n (%heapify node)\n (force-up node)\n node))))\n (build 0 size)))\n\n(defun itreap-query (itreap l r)\n \"Queries the `sum' (w.r.t. OP) of the interval [L, R).\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) l r))\n (unless (<= l r (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index (cons l r)))\n (labels\n ((recur (itreap l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless itreap\n (return-from recur +op-identity+))\n (force-down itreap)\n (prog1\n (if (and (zerop l) (= r (%itreap-count itreap)))\n (itreap-accumulator itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= l left-count)\n (if (< left-count r)\n ;; LEFT-COUNT is in [L, R)\n (op (op (recur (%itreap-left itreap) l (min r left-count))\n (%itreap-value itreap))\n (recur (%itreap-right itreap) 0 (- r left-count 1)))\n ;; LEFT-COUNT is in [R, END)\n (recur (%itreap-left itreap) l (min r left-count)))\n ;; LEFT-COUNT is in [0, L)\n (recur (%itreap-right itreap) (- l left-count 1) (- r left-count 1)))))\n (force-up itreap))))\n (recur itreap l r)))\n\n;; merge/split version of itreap-query (a bit slower but simpler)\n;; FIXME: might be problematic when two priorities collide.\n;; (declaim (inline itreap-query))\n;; (defun itreap-query (itreap l r)\n;; \"Queries the `sum' (w.r.t. OP) of the interval [L, R).\"\n;; (declare ((integer 0 #.most-positive-fixnum) l r))\n;; (unless (<= l r (itreap-count itreap))\n;; (error 'invalid-itreap-index-error :itreap itreap :index (cons l r)))\n;; (if (= l r)\n;; +op-identity+\n;; (multiple-value-bind (itreap-0-l itreap-l-n)\n;; (itreap-split itreap l)\n;; (multiple-value-bind (itreap-l-r itreap-r-n)\n;; (itreap-split itreap-l-n (- r l))\n;; (prog1 (%itreap-accumulator itreap-l-r)\n;; (itreap-merge itreap-0-l (itreap-merge itreap-l-r itreap-r-n)))))))\n\n;; merge/split version of itreap-update (a bit slower but simpler)\n;; (declaim (inline itreap-update))\n;; (defun itreap-update (itreap operand l r)\n;; \"Updates ITREAP[i] := (OP ITREAP[i] OPERAND) for all i in [l, r)\"\n;; (declare ((integer 0 #.most-positive-fixnum) l r))\n;; (unless (<= l r (itreap-count itreap))\n;; (error 'invalid-itreap-index-error :itreap itreap :index (cons l r)))\n;; (multiple-value-bind (itreap-0-l itreap-l-n)\n;; (itreap-split itreap l)\n;; (multiple-value-bind (itreap-l-r itreap-r-n)\n;; (itreap-split itreap-l-n (- r l))\n;; (when itreap-l-r\n;; (setf (%itreap-lazy itreap-l-r)\n;; (updater-op (%itreap-lazy itreap-l-r) operand)))\n;; (itreap-merge itreap-0-l (itreap-merge itreap-l-r itreap-r-n)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (ps (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (setf (aref ps i) (read-fixnum)))\n (let ((itreap (make-itreap n :initial-contents ps))\n (ls (make-array n :element-type 'int32 :initial-element 0))\n (rs (make-array n :element-type 'int32 :initial-element 0)))\n (dotimes (i n)\n (let ((p (aref ps i)))\n (sb-int:named-let bisect ((ok -1) (ng i))\n (if (<= (- ng ok) 1)\n (setf (aref ls i) ok)\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap mid i)))\n (if (> val (aref ps i))\n (bisect mid ng)\n (bisect ok mid)))))\n (sb-int:named-let bisect ((ng i) (ok (+ n 1)))\n (if (<= (- ok ng) 1)\n (setf (aref rs i) (- ok 1))\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap i mid)))\n (if (> val (aref ps i))\n (bisect ng mid)\n (bisect mid ok)))))))\n (let ((res 0))\n (dotimes (i n)\n (let* ((l (sb-int:named-let bisect ((ok -1) (ng i))\n (declare (int32 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap mid i)))\n (if (> val (aref ps i))\n (bisect mid ng)\n (bisect ok mid))))))\n (r+1 (sb-int:named-let bisect ((ng i) (ok (+ n 1)))\n (declare (int32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap i mid)))\n (if (> val (aref ps i))\n (bisect ng mid)\n (bisect mid ok))))))\n (r (- r+1 1)))\n (when (>= l 0)\n (let* ((ll (sb-int:named-let bisect ((ok -1) (ng l))\n (declare (int32 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap mid l)))\n (if (> val (aref ps i))\n (bisect mid ng)\n (bisect ok mid)))))))\n (dbg 'l i ll l r)\n (incf res (* (- r i)\n (- l ll)\n (aref ps i)))))\n (when (< r n)\n (let* ((rr+1 (sb-int:named-let bisect ((ng (+ r 1)) (ok (+ n 1)))\n (declare (int32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap r+1 mid)))\n (if (> val (aref ps i))\n (bisect ng mid)\n (bisect mid ok))))))\n (rr (- rr+1 1)))\n (dbg 'r i l r rr)\n (incf res (* (- i l)\n (- rr r)\n (aref ps i)))))))\n (println res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n2 3 1\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n1 2 3 4 5\n\"\n \"30\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n8 2 7 3 4 5 6 1\n\"\n \"136\n\")))\n", "language": "Lisp", "metadata": {"date": 1567887396, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02919.html", "problem_id": "p02919", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02919/input.txt", "sample_output_relpath": "derived/input_output/data/p02919/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02919/Lisp/s399964439.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s399964439", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Implicit treap\n;;; (treap with implicit key)\n;;;\n\n;; Note:\n;; - You cannot rely on the side effect when you call any destructive operations\n;; on a treap. Always use the returned value.\n;; - An empty treap is NIL.\n\n(declaim (inline op))\n(defun op (a b)\n \"Is a binary operator comprising a monoid.\"\n (declare (fixnum a b))\n (max a b))\n\n(defconstant +op-identity+ 0\n \"identity element w.r.t. OP\")\n\n(defstruct (itreap (:constructor %make-itreap (value priority &key left right (count 1) (accumulator value)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (integer 0 #.most-positive-fixnum)) ; size of (sub)treap\n (left nil :type (or null itreap))\n (right nil :type (or null itreap)))\n\n(declaim (inline itreap-count))\n(defun itreap-count (itreap)\n \"Returns the length of ITREAP.\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-count itreap)\n 0))\n\n(declaim (inline itreap-accumulator))\n(defun itreap-accumulator (itreap)\n \"Returns the sum (w.r.t. OP) of the whole ITREAP:\nITREAP[0]+ITREAP[1]+...+ITREAP[SIZE-1].\"\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-accumulator itreap)\n +op-identity+))\n\n(declaim (inline update-count))\n(defun update-count (itreap)\n (declare (itreap itreap))\n (setf (%itreap-count itreap)\n (+ 1\n (itreap-count (%itreap-left itreap))\n (itreap-count (%itreap-right itreap)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (itreap)\n (declare (itreap itreap))\n (setf (%itreap-accumulator itreap)\n (if (%itreap-left itreap)\n (if (%itreap-right itreap)\n (let ((mid (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap))))\n (declare (dynamic-extent mid))\n (op mid (%itreap-accumulator (%itreap-right itreap))))\n (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap)))\n (if (%itreap-right itreap)\n (op (%itreap-value itreap)\n (%itreap-accumulator (%itreap-right itreap)))\n (%itreap-value itreap)))))\n\n(declaim (inline force-up))\n(defun force-up (itreap)\n \"Propagates up the information from children.\"\n (declare (itreap itreap))\n (update-count itreap)\n (update-accumulator itreap))\n\n(declaim (inline force-down))\n(defun force-down (itreap)\n \"Propagates down the information to children.\"\n (declare (ignorable itreap)))\n\n(defun itreap-split (itreap index)\n \"Destructively splits the ITREAP into two nodes [0, INDEX) and [INDEX, N),\nwhere N is the number of elements of the ITREAP.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) index))\n (unless (<= index (itreap-count itreap))\n (error 'invalid-itreap-index-error :index index :itreap itreap))\n (labels ((recur (itreap ikey)\n (unless itreap\n (return-from itreap-split (values nil nil)))\n (force-down itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= ikey left-count)\n (multiple-value-bind (left right)\n (itreap-split (%itreap-left itreap) ikey)\n (setf (%itreap-left itreap) right)\n (force-up itreap)\n (values left itreap))\n (multiple-value-bind (left right)\n (itreap-split (%itreap-right itreap) (- ikey left-count 1))\n (setf (%itreap-right itreap) left)\n (force-up itreap)\n (values itreap right))))))\n (recur itreap index)))\n\n(defun itreap-merge (left right)\n \"Destructively concatenates two ITREAPs.\"\n (declare (optimize (speed 3))\n ((or null itreap) left right))\n (cond ((null left) (when right (force-down right) (force-up right)) right)\n ((null right) (when left (force-down left) (force-up left)) left)\n (t (force-down left)\n (force-down right)\n (if (> (%itreap-priority left) (%itreap-priority right))\n (progn\n (setf (%itreap-right left)\n (itreap-merge (%itreap-right left) right))\n (force-up left)\n left)\n (progn\n (setf (%itreap-left right)\n (itreap-merge left (%itreap-left right)))\n (force-up right)\n right)))))\n\n(define-condition invalid-itreap-index-error (type-error)\n ((itreap :initarg :itreap :reader invalid-itreap-index-error-itreap)\n (index :initarg :index :reader invalid-itreap-index-error-index))\n (:report\n (lambda (condition stream)\n (let ((index (invalid-itreap-index-error-index condition)))\n (if (consp index)\n (format stream \"Invalid range [~W, ~W) for itreap ~W.\"\n (car index)\n (cdr index)\n (invalid-itreap-index-error-itreap condition))\n (format stream \"Invalid index ~W for itreap ~W.\"\n index\n (invalid-itreap-index-error-itreap condition)))))))\n\n(declaim (inline itreap-map))\n(defun itreap-map (function itreap)\n \"Successively applies FUNCTION to ITREAP[0], ..., ITREAP[SIZE-1].\"\n (declare (function function))\n (labels ((recur (node)\n (when node\n (force-down node)\n (recur (%itreap-left node))\n (funcall function (%itreap-value node))\n (recur (%itreap-right node))\n (force-up node))))\n (recur itreap)))\n\n(defmethod print-object ((object itreap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (itreap-map (lambda (x)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write x :stream stream))\n object))))\n\n(defun %heapify (top)\n \"Properly swaps the priorities of the node and its two children.\"\n (declare (optimize (speed 3) (safety 0)))\n (when top\n (let ((high-priority-node top))\n (when (and (%itreap-left top)\n (> (%itreap-priority (%itreap-left top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-left top)))\n (when (and (%itreap-right top)\n (> (%itreap-priority (%itreap-right top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-right top)))\n (unless (eql high-priority-node top)\n (rotatef (%itreap-priority high-priority-node)\n (%itreap-priority top))\n (%heapify high-priority-node)))))\n\n(declaim (inline make-itreap))\n(defun make-itreap (size &key initial-contents)\n \"Makes a treap of SIZE in O(SIZE) time. Its values are filled with the\nidentity element unless INITIAL-CONTENTS are supplied.\"\n (declare ((or null vector) initial-contents))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-itreap (if initial-contents\n (aref initial-contents mid)\n +op-identity+)\n (random most-positive-fixnum))))\n (setf (%itreap-left node) (build l mid))\n (setf (%itreap-right node) (build (+ mid 1) r))\n (%heapify node)\n (force-up node)\n node))))\n (build 0 size)))\n\n(defun itreap-query (itreap l r)\n \"Queries the `sum' (w.r.t. OP) of the interval [L, R).\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) l r))\n (unless (<= l r (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index (cons l r)))\n (labels\n ((recur (itreap l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless itreap\n (return-from recur +op-identity+))\n (force-down itreap)\n (prog1\n (if (and (zerop l) (= r (%itreap-count itreap)))\n (itreap-accumulator itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= l left-count)\n (if (< left-count r)\n ;; LEFT-COUNT is in [L, R)\n (op (op (recur (%itreap-left itreap) l (min r left-count))\n (%itreap-value itreap))\n (recur (%itreap-right itreap) 0 (- r left-count 1)))\n ;; LEFT-COUNT is in [R, END)\n (recur (%itreap-left itreap) l (min r left-count)))\n ;; LEFT-COUNT is in [0, L)\n (recur (%itreap-right itreap) (- l left-count 1) (- r left-count 1)))))\n (force-up itreap))))\n (recur itreap l r)))\n\n;; merge/split version of itreap-query (a bit slower but simpler)\n;; FIXME: might be problematic when two priorities collide.\n;; (declaim (inline itreap-query))\n;; (defun itreap-query (itreap l r)\n;; \"Queries the `sum' (w.r.t. OP) of the interval [L, R).\"\n;; (declare ((integer 0 #.most-positive-fixnum) l r))\n;; (unless (<= l r (itreap-count itreap))\n;; (error 'invalid-itreap-index-error :itreap itreap :index (cons l r)))\n;; (if (= l r)\n;; +op-identity+\n;; (multiple-value-bind (itreap-0-l itreap-l-n)\n;; (itreap-split itreap l)\n;; (multiple-value-bind (itreap-l-r itreap-r-n)\n;; (itreap-split itreap-l-n (- r l))\n;; (prog1 (%itreap-accumulator itreap-l-r)\n;; (itreap-merge itreap-0-l (itreap-merge itreap-l-r itreap-r-n)))))))\n\n;; merge/split version of itreap-update (a bit slower but simpler)\n;; (declaim (inline itreap-update))\n;; (defun itreap-update (itreap operand l r)\n;; \"Updates ITREAP[i] := (OP ITREAP[i] OPERAND) for all i in [l, r)\"\n;; (declare ((integer 0 #.most-positive-fixnum) l r))\n;; (unless (<= l r (itreap-count itreap))\n;; (error 'invalid-itreap-index-error :itreap itreap :index (cons l r)))\n;; (multiple-value-bind (itreap-0-l itreap-l-n)\n;; (itreap-split itreap l)\n;; (multiple-value-bind (itreap-l-r itreap-r-n)\n;; (itreap-split itreap-l-n (- r l))\n;; (when itreap-l-r\n;; (setf (%itreap-lazy itreap-l-r)\n;; (updater-op (%itreap-lazy itreap-l-r) operand)))\n;; (itreap-merge itreap-0-l (itreap-merge itreap-l-r itreap-r-n)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (ps (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (setf (aref ps i) (read-fixnum)))\n (let ((itreap (make-itreap n :initial-contents ps))\n (ls (make-array n :element-type 'int32 :initial-element 0))\n (rs (make-array n :element-type 'int32 :initial-element 0)))\n (dotimes (i n)\n (let ((p (aref ps i)))\n (sb-int:named-let bisect ((ok -1) (ng i))\n (if (<= (- ng ok) 1)\n (setf (aref ls i) ok)\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap mid i)))\n (if (> val (aref ps i))\n (bisect mid ng)\n (bisect ok mid)))))\n (sb-int:named-let bisect ((ng i) (ok (+ n 1)))\n (if (<= (- ok ng) 1)\n (setf (aref rs i) (- ok 1))\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap i mid)))\n (if (> val (aref ps i))\n (bisect ng mid)\n (bisect mid ok)))))))\n (let ((res 0))\n (dotimes (i n)\n (let* ((l (sb-int:named-let bisect ((ok -1) (ng i))\n (declare (int32 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap mid i)))\n (if (> val (aref ps i))\n (bisect mid ng)\n (bisect ok mid))))))\n (r+1 (sb-int:named-let bisect ((ng i) (ok (+ n 1)))\n (declare (int32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap i mid)))\n (if (> val (aref ps i))\n (bisect ng mid)\n (bisect mid ok))))))\n (r (- r+1 1)))\n (when (>= l 0)\n (let* ((ll (sb-int:named-let bisect ((ok -1) (ng l))\n (declare (int32 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap mid l)))\n (if (> val (aref ps i))\n (bisect mid ng)\n (bisect ok mid)))))))\n (dbg 'l i ll l r)\n (incf res (* (- r i)\n (- l ll)\n (aref ps i)))))\n (when (< r n)\n (let* ((rr+1 (sb-int:named-let bisect ((ng (+ r 1)) (ok (+ n 1)))\n (declare (int32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (val (itreap-query itreap r+1 mid)))\n (if (> val (aref ps i))\n (bisect ng mid)\n (bisect mid ok))))))\n (rr (- rr+1 1)))\n (dbg 'r i l r rr)\n (incf res (* (- i l)\n (- rr r)\n (aref ps i)))))))\n (println res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n2 3 1\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n1 2 3 4 5\n\"\n \"30\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n8 2 7 3 4 5 6 1\n\"\n \"136\n\")))\n", "problem_context": "Score: 500 points\n\nProblem Statement\n\nGiven is a permutation P of \\{1, 2, \\ldots, N\\}.\n\nFor a pair (L, R) (1 \\le L \\lt R \\le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \\ldots, P_R.\n\nFind \\displaystyle \\sum_{L=1}^{N-1} \\sum_{R=L+1}^{N} X_{L,R}.\n\nConstraints\n\n2 \\le N \\le 10^5\n\n1 \\le P_i \\le N\n\nP_i \\neq P_j (i \\neq j)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 P_2 \\ldots P_N\n\nOutput\n\nPrint \\displaystyle \\sum_{L=1}^{N-1} \\sum_{R=L+1}^{N} X_{L,R}.\n\nSample Input 1\n\n3\n2 3 1\n\nSample Output 1\n\n5\n\nX_{1, 2} = 2, X_{1, 3} = 2, and X_{2, 3} = 1, so the sum is 2 + 2 + 1 = 5.\n\nSample Input 2\n\n5\n1 2 3 4 5\n\nSample Output 2\n\n30\n\nSample Input 3\n\n8\n8 2 7 3 4 5 6 1\n\nSample Output 3\n\n136", "sample_input": "3\n2 3 1\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02919", "source_text": "Score: 500 points\n\nProblem Statement\n\nGiven is a permutation P of \\{1, 2, \\ldots, N\\}.\n\nFor a pair (L, R) (1 \\le L \\lt R \\le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \\ldots, P_R.\n\nFind \\displaystyle \\sum_{L=1}^{N-1} \\sum_{R=L+1}^{N} X_{L,R}.\n\nConstraints\n\n2 \\le N \\le 10^5\n\n1 \\le P_i \\le N\n\nP_i \\neq P_j (i \\neq j)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1 P_2 \\ldots P_N\n\nOutput\n\nPrint \\displaystyle \\sum_{L=1}^{N-1} \\sum_{R=L+1}^{N} X_{L,R}.\n\nSample Input 1\n\n3\n2 3 1\n\nSample Output 1\n\n5\n\nX_{1, 2} = 2, X_{1, 3} = 2, and X_{2, 3} = 1, so the sum is 2 + 2 + 1 = 5.\n\nSample Input 2\n\n5\n1 2 3 4 5\n\nSample Output 2\n\n30\n\nSample Input 3\n\n8\n8 2 7 3 4 5 6 1\n\nSample Output 3\n\n136", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 19079, "cpu_time_ms": 2105, "memory_kb": 59748}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s479599245", "group_id": "codeNet:p02921", "input_text": "(defun ans (s u)\n (setq s (concatenate 'list s))\n (setq u (concatenate 'list u))\n (count t (mapcar #'equal s u)))\n\n(format t \"~a~%\" (ans (read-line) (read-line)))", "language": "Lisp", "metadata": {"date": 1568989178, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02921.html", "problem_id": "p02921", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02921/input.txt", "sample_output_relpath": "derived/input_output/data/p02921/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02921/Lisp/s479599245.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s479599245", "user_id": "u358554431"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun ans (s u)\n (setq s (concatenate 'list s))\n (setq u (concatenate 'list u))\n (count t (mapcar #'equal s u)))\n\n(format t \"~a~%\" (ans (read-line) (read-line)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou will be given a string S of length 3 representing the weather forecast for three days in the past.\n\nThe i-th character (1 \\leq i \\leq 3) of S represents the forecast for the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.\n\nYou will also be given a string T of length 3 representing the actual weather on those three days.\n\nThe i-th character (1 \\leq i \\leq 3) of S represents the actual weather on the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.\n\nPrint the number of days for which the forecast was correct.\n\nConstraints\n\nS and T are strings of length 3 each.\n\nS and T consist of S, C, and R.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nPrint the number of days for which the forecast was correct.\n\nSample Input 1\n\nCSS\nCSR\n\nSample Output 1\n\n2\n\nFor the first day, it was forecast to be cloudy, and it was indeed cloudy.\n\nFor the second day, it was forecast to be sunny, and it was indeed sunny.\n\nFor the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\nSample Input 2\n\nSSR\nSSR\n\nSample Output 2\n\n3\n\nSample Input 3\n\nRRR\nSSS\n\nSample Output 3\n\n0", "sample_input": "CSS\nCSR\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02921", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou will be given a string S of length 3 representing the weather forecast for three days in the past.\n\nThe i-th character (1 \\leq i \\leq 3) of S represents the forecast for the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.\n\nYou will also be given a string T of length 3 representing the actual weather on those three days.\n\nThe i-th character (1 \\leq i \\leq 3) of S represents the actual weather on the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.\n\nPrint the number of days for which the forecast was correct.\n\nConstraints\n\nS and T are strings of length 3 each.\n\nS and T consist of S, C, and R.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nPrint the number of days for which the forecast was correct.\n\nSample Input 1\n\nCSS\nCSR\n\nSample Output 1\n\n2\n\nFor the first day, it was forecast to be cloudy, and it was indeed cloudy.\n\nFor the second day, it was forecast to be sunny, and it was indeed sunny.\n\nFor the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\nSample Input 2\n\nSSR\nSSR\n\nSample Output 2\n\n3\n\nSample Input 3\n\nRRR\nSSS\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 165, "cpu_time_ms": 21, "memory_kb": 4064}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s634085279", "group_id": "codeNet:p02921", "input_text": "(print (count t (mapcar #'char-equal\n (coerce (read-line) 'list)\n (coerce (read-line) 'list))))", "language": "Lisp", "metadata": {"date": 1567478665, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02921.html", "problem_id": "p02921", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02921/input.txt", "sample_output_relpath": "derived/input_output/data/p02921/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02921/Lisp/s634085279.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s634085279", "user_id": "u529272520"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(print (count t (mapcar #'char-equal\n (coerce (read-line) 'list)\n (coerce (read-line) 'list))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou will be given a string S of length 3 representing the weather forecast for three days in the past.\n\nThe i-th character (1 \\leq i \\leq 3) of S represents the forecast for the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.\n\nYou will also be given a string T of length 3 representing the actual weather on those three days.\n\nThe i-th character (1 \\leq i \\leq 3) of S represents the actual weather on the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.\n\nPrint the number of days for which the forecast was correct.\n\nConstraints\n\nS and T are strings of length 3 each.\n\nS and T consist of S, C, and R.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nPrint the number of days for which the forecast was correct.\n\nSample Input 1\n\nCSS\nCSR\n\nSample Output 1\n\n2\n\nFor the first day, it was forecast to be cloudy, and it was indeed cloudy.\n\nFor the second day, it was forecast to be sunny, and it was indeed sunny.\n\nFor the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\nSample Input 2\n\nSSR\nSSR\n\nSample Output 2\n\n3\n\nSample Input 3\n\nRRR\nSSS\n\nSample Output 3\n\n0", "sample_input": "CSS\nCSR\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02921", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou will be given a string S of length 3 representing the weather forecast for three days in the past.\n\nThe i-th character (1 \\leq i \\leq 3) of S represents the forecast for the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.\n\nYou will also be given a string T of length 3 representing the actual weather on those three days.\n\nThe i-th character (1 \\leq i \\leq 3) of S represents the actual weather on the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.\n\nPrint the number of days for which the forecast was correct.\n\nConstraints\n\nS and T are strings of length 3 each.\n\nS and T consist of S, C, and R.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nPrint the number of days for which the forecast was correct.\n\nSample Input 1\n\nCSS\nCSR\n\nSample Output 1\n\n2\n\nFor the first day, it was forecast to be cloudy, and it was indeed cloudy.\n\nFor the second day, it was forecast to be sunny, and it was indeed sunny.\n\nFor the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\nSample Input 2\n\nSSR\nSSR\n\nSample Output 2\n\n3\n\nSample Input 3\n\nRRR\nSSS\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 145, "cpu_time_ms": 29, "memory_kb": 3936}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s424891411", "group_id": "codeNet:p02921", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((s1 (read-line))\n (s2 (read-line)))\n (println\n (loop for c1 across s1\n for c2 across s2\n count (char= c1 c2)))))\n\n#-swank (main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"CSS\nCSR\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"SSR\nSSR\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"RRR\nSSS\n\"\n \"0\n\")))\n", "language": "Lisp", "metadata": {"date": 1567364556, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02921.html", "problem_id": "p02921", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02921/input.txt", "sample_output_relpath": "derived/input_output/data/p02921/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02921/Lisp/s424891411.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s424891411", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((s1 (read-line))\n (s2 (read-line)))\n (println\n (loop for c1 across s1\n for c2 across s2\n count (char= c1 c2)))))\n\n#-swank (main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"CSS\nCSR\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"SSR\nSSR\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"RRR\nSSS\n\"\n \"0\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou will be given a string S of length 3 representing the weather forecast for three days in the past.\n\nThe i-th character (1 \\leq i \\leq 3) of S represents the forecast for the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.\n\nYou will also be given a string T of length 3 representing the actual weather on those three days.\n\nThe i-th character (1 \\leq i \\leq 3) of S represents the actual weather on the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.\n\nPrint the number of days for which the forecast was correct.\n\nConstraints\n\nS and T are strings of length 3 each.\n\nS and T consist of S, C, and R.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nPrint the number of days for which the forecast was correct.\n\nSample Input 1\n\nCSS\nCSR\n\nSample Output 1\n\n2\n\nFor the first day, it was forecast to be cloudy, and it was indeed cloudy.\n\nFor the second day, it was forecast to be sunny, and it was indeed sunny.\n\nFor the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\nSample Input 2\n\nSSR\nSSR\n\nSample Output 2\n\n3\n\nSample Input 3\n\nRRR\nSSS\n\nSample Output 3\n\n0", "sample_input": "CSS\nCSR\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02921", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou will be given a string S of length 3 representing the weather forecast for three days in the past.\n\nThe i-th character (1 \\leq i \\leq 3) of S represents the forecast for the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.\n\nYou will also be given a string T of length 3 representing the actual weather on those three days.\n\nThe i-th character (1 \\leq i \\leq 3) of S represents the actual weather on the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.\n\nPrint the number of days for which the forecast was correct.\n\nConstraints\n\nS and T are strings of length 3 each.\n\nS and T consist of S, C, and R.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nPrint the number of days for which the forecast was correct.\n\nSample Input 1\n\nCSS\nCSR\n\nSample Output 1\n\n2\n\nFor the first day, it was forecast to be cloudy, and it was indeed cloudy.\n\nFor the second day, it was forecast to be sunny, and it was indeed sunny.\n\nFor the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\nSample Input 2\n\nSSR\nSSR\n\nSample Output 2\n\n3\n\nSample Input 3\n\nRRR\nSSS\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3676, "cpu_time_ms": 147, "memory_kb": 16100}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s028203611", "group_id": "codeNet:p02922", "input_text": "(let ((a (read))\n (b (read))\n (kazu 1)\n (ans 0))\n (loop for i below b while (< kazu b) do\n (progn\n (decf kazu)\n (incf kazu a)\n (incf ans)\n ) \n )\n (format t \"~D~%\" ans)\n)\n", "language": "Lisp", "metadata": {"date": 1599158191, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02922.html", "problem_id": "p02922", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02922/input.txt", "sample_output_relpath": "derived/input_output/data/p02922/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02922/Lisp/s028203611.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s028203611", "user_id": "u136500538"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (kazu 1)\n (ans 0))\n (loop for i below b while (< kazu b) do\n (progn\n (decf kazu)\n (incf kazu a)\n (incf ans)\n ) \n )\n (format t \"~D~%\" ans)\n)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi's house has only one socket.\n\nTakahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.\n\nOne power strip with A sockets can extend one empty socket into A empty sockets.\n\nFind the minimum number of power strips required.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq A \\leq 20\n\n1 \\leq B \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the minimum number of power strips required.\n\nSample Input 1\n\n4 10\n\nSample Output 1\n\n3\n\n3 power strips, each with 4 sockets, extend the socket into 10 empty sockets.\n\nSample Input 2\n\n8 9\n\nSample Output 2\n\n2\n\n2 power strips, each with 8 sockets, extend the socket into 15 empty sockets.\n\nSample Input 3\n\n8 8\n\nSample Output 3\n\n1", "sample_input": "4 10\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02922", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi's house has only one socket.\n\nTakahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.\n\nOne power strip with A sockets can extend one empty socket into A empty sockets.\n\nFind the minimum number of power strips required.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq A \\leq 20\n\n1 \\leq B \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the minimum number of power strips required.\n\nSample Input 1\n\n4 10\n\nSample Output 1\n\n3\n\n3 power strips, each with 4 sockets, extend the socket into 10 empty sockets.\n\nSample Input 2\n\n8 9\n\nSample Output 2\n\n2\n\n2 power strips, each with 8 sockets, extend the socket into 15 empty sockets.\n\nSample Input 3\n\n8 8\n\nSample Output 3\n\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 238, "cpu_time_ms": 20, "memory_kb": 24352}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s106741380", "group_id": "codeNet:p02922", "input_text": "(let ((a (read))\n (b (read)))\n (if (<= b a)\n (princ 1)\n (princ (1+ (ceiling (- b a) (1- a))))))\n", "language": "Lisp", "metadata": {"date": 1567370200, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02922.html", "problem_id": "p02922", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02922/input.txt", "sample_output_relpath": "derived/input_output/data/p02922/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02922/Lisp/s106741380.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s106741380", "user_id": "u994767958"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((a (read))\n (b (read)))\n (if (<= b a)\n (princ 1)\n (princ (1+ (ceiling (- b a) (1- a))))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi's house has only one socket.\n\nTakahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.\n\nOne power strip with A sockets can extend one empty socket into A empty sockets.\n\nFind the minimum number of power strips required.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq A \\leq 20\n\n1 \\leq B \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the minimum number of power strips required.\n\nSample Input 1\n\n4 10\n\nSample Output 1\n\n3\n\n3 power strips, each with 4 sockets, extend the socket into 10 empty sockets.\n\nSample Input 2\n\n8 9\n\nSample Output 2\n\n2\n\n2 power strips, each with 8 sockets, extend the socket into 15 empty sockets.\n\nSample Input 3\n\n8 8\n\nSample Output 3\n\n1", "sample_input": "4 10\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02922", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi's house has only one socket.\n\nTakahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.\n\nOne power strip with A sockets can extend one empty socket into A empty sockets.\n\nFind the minimum number of power strips required.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq A \\leq 20\n\n1 \\leq B \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the minimum number of power strips required.\n\nSample Input 1\n\n4 10\n\nSample Output 1\n\n3\n\n3 power strips, each with 4 sockets, extend the socket into 10 empty sockets.\n\nSample Input 2\n\n8 9\n\nSample Output 2\n\n2\n\n2 power strips, each with 8 sockets, extend the socket into 15 empty sockets.\n\nSample Input 3\n\n8 8\n\nSample Output 3\n\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 112, "cpu_time_ms": 114, "memory_kb": 12132}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s722269002", "group_id": "codeNet:p02922", "input_text": "(let ((a (read))\n (b (read)))\n (defun calc (i)\n (let ((n (+ 1 (* (1- a) i))))\n (if (>= n b)\n i\n (calc (1+ i)))))\n (format t \"~A~%\" (calc 0)))", "language": "Lisp", "metadata": {"date": 1567365681, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02922.html", "problem_id": "p02922", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02922/input.txt", "sample_output_relpath": "derived/input_output/data/p02922/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02922/Lisp/s722269002.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s722269002", "user_id": "u608227593"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((a (read))\n (b (read)))\n (defun calc (i)\n (let ((n (+ 1 (* (1- a) i))))\n (if (>= n b)\n i\n (calc (1+ i)))))\n (format t \"~A~%\" (calc 0)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi's house has only one socket.\n\nTakahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.\n\nOne power strip with A sockets can extend one empty socket into A empty sockets.\n\nFind the minimum number of power strips required.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq A \\leq 20\n\n1 \\leq B \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the minimum number of power strips required.\n\nSample Input 1\n\n4 10\n\nSample Output 1\n\n3\n\n3 power strips, each with 4 sockets, extend the socket into 10 empty sockets.\n\nSample Input 2\n\n8 9\n\nSample Output 2\n\n2\n\n2 power strips, each with 8 sockets, extend the socket into 15 empty sockets.\n\nSample Input 3\n\n8 8\n\nSample Output 3\n\n1", "sample_input": "4 10\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02922", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi's house has only one socket.\n\nTakahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.\n\nOne power strip with A sockets can extend one empty socket into A empty sockets.\n\nFind the minimum number of power strips required.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq A \\leq 20\n\n1 \\leq B \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the minimum number of power strips required.\n\nSample Input 1\n\n4 10\n\nSample Output 1\n\n3\n\n3 power strips, each with 4 sockets, extend the socket into 10 empty sockets.\n\nSample Input 2\n\n8 9\n\nSample Output 2\n\n2\n\n2 power strips, each with 8 sockets, extend the socket into 15 empty sockets.\n\nSample Input 3\n\n8 8\n\nSample Output 3\n\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 174, "cpu_time_ms": 203, "memory_kb": 13156}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s307796686", "group_id": "codeNet:p02923", "input_text": "(defun counter (l left-path right-path &optional (count 0))\n (let ((left (nth left-path l))\n (right (nth right-path l)))\n (if (or (null left) (null right))\n count\n (if (>= left right)\n (counter l (1+ left-path) (1+ right-path) (1+ count))\n count))))\n\n(defun main ()\n (let* ((N (read))\n (H-list (loop for i from 1 to N\n collect (read)))\n (result 0)\n (left-path 0)\n (right-path 0))\n (dotimes (x N)\n (let ((tmp (counter H-list x (1+ x))))\n (when (> tmp result)\n (setq result tmp))))))\n\n\n(main)\n\n", "language": "Lisp", "metadata": {"date": 1567672967, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02923.html", "problem_id": "p02923", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02923/input.txt", "sample_output_relpath": "derived/input_output/data/p02923/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02923/Lisp/s307796686.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s307796686", "user_id": "u631655863"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun counter (l left-path right-path &optional (count 0))\n (let ((left (nth left-path l))\n (right (nth right-path l)))\n (if (or (null left) (null right))\n count\n (if (>= left right)\n (counter l (1+ left-path) (1+ right-path) (1+ count))\n count))))\n\n(defun main ()\n (let* ((N (read))\n (H-list (loop for i from 1 to N\n collect (read)))\n (result 0)\n (left-path 0)\n (right-path 0))\n (dotimes (x N)\n (let ((tmp (counter H-list x (1+ x))))\n (when (> tmp result)\n (setq result tmp))))))\n\n\n(main)\n\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N squares arranged in a row from left to right.\n\nThe height of the i-th square from the left is H_i.\n\nYou will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square.\n\nFind the maximum number of times you can move.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq H_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nH_1 H_2 ... H_N\n\nOutput\n\nPrint the maximum number of times you can move.\n\nSample Input 1\n\n5\n10 4 8 7 3\n\nSample Output 1\n\n2\n\nBy landing on the third square from the left, you can move to the right twice.\n\nSample Input 2\n\n7\n4 4 5 6 6 5 5\n\nSample Output 2\n\n3\n\nBy landing on the fourth square from the left, you can move to the right three times.\n\nSample Input 3\n\n4\n1 2 3 4\n\nSample Output 3\n\n0", "sample_input": "5\n10 4 8 7 3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02923", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N squares arranged in a row from left to right.\n\nThe height of the i-th square from the left is H_i.\n\nYou will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square.\n\nFind the maximum number of times you can move.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq H_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nH_1 H_2 ... H_N\n\nOutput\n\nPrint the maximum number of times you can move.\n\nSample Input 1\n\n5\n10 4 8 7 3\n\nSample Output 1\n\n2\n\nBy landing on the third square from the left, you can move to the right twice.\n\nSample Input 2\n\n7\n4 4 5 6 6 5 5\n\nSample Output 2\n\n3\n\nBy landing on the fourth square from the left, you can move to the right three times.\n\nSample Input 3\n\n4\n1 2 3 4\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 618, "cpu_time_ms": 2104, "memory_kb": 59748}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s064468795", "group_id": "codeNet:p02923", "input_text": "(loop with list = (loop repeat (read) collect (read))\n with max = 0\n for glmax = 0 then (max glmax max)\n for prev = (first list) then el \n for el in (rest list)\n do (print glmax)\n if (>= prev el) do (incf max)\n else do (setf max 0)\n finally (print glmax))", "language": "Lisp", "metadata": {"date": 1567565336, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02923.html", "problem_id": "p02923", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02923/input.txt", "sample_output_relpath": "derived/input_output/data/p02923/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02923/Lisp/s064468795.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s064468795", "user_id": "u529272520"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(loop with list = (loop repeat (read) collect (read))\n with max = 0\n for glmax = 0 then (max glmax max)\n for prev = (first list) then el \n for el in (rest list)\n do (print glmax)\n if (>= prev el) do (incf max)\n else do (setf max 0)\n finally (print glmax))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N squares arranged in a row from left to right.\n\nThe height of the i-th square from the left is H_i.\n\nYou will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square.\n\nFind the maximum number of times you can move.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq H_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nH_1 H_2 ... H_N\n\nOutput\n\nPrint the maximum number of times you can move.\n\nSample Input 1\n\n5\n10 4 8 7 3\n\nSample Output 1\n\n2\n\nBy landing on the third square from the left, you can move to the right twice.\n\nSample Input 2\n\n7\n4 4 5 6 6 5 5\n\nSample Output 2\n\n3\n\nBy landing on the fourth square from the left, you can move to the right three times.\n\nSample Input 3\n\n4\n1 2 3 4\n\nSample Output 3\n\n0", "sample_input": "5\n10 4 8 7 3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02923", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N squares arranged in a row from left to right.\n\nThe height of the i-th square from the left is H_i.\n\nYou will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square.\n\nFind the maximum number of times you can move.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq H_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nH_1 H_2 ... H_N\n\nOutput\n\nPrint the maximum number of times you can move.\n\nSample Input 1\n\n5\n10 4 8 7 3\n\nSample Output 1\n\n2\n\nBy landing on the third square from the left, you can move to the right twice.\n\nSample Input 2\n\n7\n4 4 5 6 6 5 5\n\nSample Output 2\n\n3\n\nBy landing on the fourth square from the left, you can move to the right three times.\n\nSample Input 3\n\n4\n1 2 3 4\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 381, "cpu_time_ms": 560, "memory_kb": 60516}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s359369160", "group_id": "codeNet:p02923", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (hs (make-array n :element-type 'uint32))\n (res 0)\n (base 0))\n (dotimes (i n) (setf (aref hs i) (read-fixnum)))\n (dotimes (i (- n 1))\n (unless (>= (aref hs i) (aref hs (+ i 1)))\n (setq res (max res #>(- i base)))\n (setq base (+ i 1))))\n (setq res (max res (- n base 1)))\n (println res)))\n\n#-swank (main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n10 4 8 7 3\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\n4 4 5 6 6 5 5\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 2 3 4\n\"\n \"0\n\")))\n", "language": "Lisp", "metadata": {"date": 1567365046, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02923.html", "problem_id": "p02923", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02923/input.txt", "sample_output_relpath": "derived/input_output/data/p02923/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02923/Lisp/s359369160.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s359369160", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (hs (make-array n :element-type 'uint32))\n (res 0)\n (base 0))\n (dotimes (i n) (setf (aref hs i) (read-fixnum)))\n (dotimes (i (- n 1))\n (unless (>= (aref hs i) (aref hs (+ i 1)))\n (setq res (max res #>(- i base)))\n (setq base (+ i 1))))\n (setq res (max res (- n base 1)))\n (println res)))\n\n#-swank (main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n10 4 8 7 3\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\n4 4 5 6 6 5 5\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 2 3 4\n\"\n \"0\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N squares arranged in a row from left to right.\n\nThe height of the i-th square from the left is H_i.\n\nYou will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square.\n\nFind the maximum number of times you can move.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq H_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nH_1 H_2 ... H_N\n\nOutput\n\nPrint the maximum number of times you can move.\n\nSample Input 1\n\n5\n10 4 8 7 3\n\nSample Output 1\n\n2\n\nBy landing on the third square from the left, you can move to the right twice.\n\nSample Input 2\n\n7\n4 4 5 6 6 5 5\n\nSample Output 2\n\n3\n\nBy landing on the fourth square from the left, you can move to the right three times.\n\nSample Input 3\n\n4\n1 2 3 4\n\nSample Output 3\n\n0", "sample_input": "5\n10 4 8 7 3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02923", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N squares arranged in a row from left to right.\n\nThe height of the i-th square from the left is H_i.\n\nYou will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square.\n\nFind the maximum number of times you can move.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq H_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nH_1 H_2 ... H_N\n\nOutput\n\nPrint the maximum number of times you can move.\n\nSample Input 1\n\n5\n10 4 8 7 3\n\nSample Output 1\n\n2\n\nBy landing on the third square from the left, you can move to the right twice.\n\nSample Input 2\n\n7\n4 4 5 6 6 5 5\n\nSample Output 2\n\n3\n\nBy landing on the fourth square from the left, you can move to the right three times.\n\nSample Input 3\n\n4\n1 2 3 4\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5002, "cpu_time_ms": 200, "memory_kb": 22376}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s877516224", "group_id": "codeNet:p02924", "input_text": "(let ((n (read)))\n (princ (floor (* n (- n 1)) 2)))", "language": "Lisp", "metadata": {"date": 1590341956, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02924.html", "problem_id": "p02924", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02924/input.txt", "sample_output_relpath": "derived/input_output/data/p02924/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02924/Lisp/s877516224.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s877516224", "user_id": "u425762225"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let ((n (read)))\n (princ (floor (* n (- n 1)) 2)))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nFor an integer N, we will choose a permutation \\{P_1, P_2, ..., P_N\\} of \\{1, 2, ..., N\\}.\n\nThen, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i.\n\nFind the maximum possible value of M_1 + M_2 + \\cdots + M_N.\n\nConstraints\n\nN is an integer satisfying 1 \\leq N \\leq 10^9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the maximum possible value of M_1 + M_2 + \\cdots + M_N.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n1\n\nWhen the permutation \\{P_1, P_2\\} = \\{2, 1\\} is chosen, M_1 + M_2 = 1 + 0 = 1.\n\nSample Input 2\n\n13\n\nSample Output 2\n\n78\n\nSample Input 3\n\n1\n\nSample Output 3\n\n0", "sample_input": "2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02924", "source_text": "Score : 400 points\n\nProblem Statement\n\nFor an integer N, we will choose a permutation \\{P_1, P_2, ..., P_N\\} of \\{1, 2, ..., N\\}.\n\nThen, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i.\n\nFind the maximum possible value of M_1 + M_2 + \\cdots + M_N.\n\nConstraints\n\nN is an integer satisfying 1 \\leq N \\leq 10^9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the maximum possible value of M_1 + M_2 + \\cdots + M_N.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n1\n\nWhen the permutation \\{P_1, P_2\\} = \\{2, 1\\} is chosen, M_1 + M_2 = 1 + 0 = 1.\n\nSample Input 2\n\n13\n\nSample Output 2\n\n78\n\nSample Input 3\n\n1\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 55, "cpu_time_ms": 23, "memory_kb": 4324}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s218959668", "group_id": "codeNet:p02924", "input_text": "(let* ((n (read))\n (lst (loop :for k :from 1 :upto n :collect k)))\n (defun rotate ()\n (setf lst (cons (car (last lst)) (subseq lst 0 (1- n)))))\n (rotate)\n (princ (reduce #'+ (mapcar #'mod lst (loop :for k :from 1 :upto n :collect k)))))", "language": "Lisp", "metadata": {"date": 1567366940, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02924.html", "problem_id": "p02924", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02924/input.txt", "sample_output_relpath": "derived/input_output/data/p02924/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02924/Lisp/s218959668.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s218959668", "user_id": "u610490393"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let* ((n (read))\n (lst (loop :for k :from 1 :upto n :collect k)))\n (defun rotate ()\n (setf lst (cons (car (last lst)) (subseq lst 0 (1- n)))))\n (rotate)\n (princ (reduce #'+ (mapcar #'mod lst (loop :for k :from 1 :upto n :collect k)))))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nFor an integer N, we will choose a permutation \\{P_1, P_2, ..., P_N\\} of \\{1, 2, ..., N\\}.\n\nThen, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i.\n\nFind the maximum possible value of M_1 + M_2 + \\cdots + M_N.\n\nConstraints\n\nN is an integer satisfying 1 \\leq N \\leq 10^9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the maximum possible value of M_1 + M_2 + \\cdots + M_N.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n1\n\nWhen the permutation \\{P_1, P_2\\} = \\{2, 1\\} is chosen, M_1 + M_2 = 1 + 0 = 1.\n\nSample Input 2\n\n13\n\nSample Output 2\n\n78\n\nSample Input 3\n\n1\n\nSample Output 3\n\n0", "sample_input": "2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02924", "source_text": "Score : 400 points\n\nProblem Statement\n\nFor an integer N, we will choose a permutation \\{P_1, P_2, ..., P_N\\} of \\{1, 2, ..., N\\}.\n\nThen, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i.\n\nFind the maximum possible value of M_1 + M_2 + \\cdots + M_N.\n\nConstraints\n\nN is an integer satisfying 1 \\leq N \\leq 10^9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the maximum possible value of M_1 + M_2 + \\cdots + M_N.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n1\n\nWhen the permutation \\{P_1, P_2\\} = \\{2, 1\\} is chosen, M_1 + M_2 = 1 + 0 = 1.\n\nSample Input 2\n\n13\n\nSample Output 2\n\n78\n\nSample Input 3\n\n1\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 248, "cpu_time_ms": 2108, "memory_kb": 946952}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s544444737", "group_id": "codeNet:p02924", "input_text": "(let ((n (read)))\n (princ (floor (* (1- n) n) 2)))", "language": "Lisp", "metadata": {"date": 1567365369, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02924.html", "problem_id": "p02924", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02924/input.txt", "sample_output_relpath": "derived/input_output/data/p02924/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02924/Lisp/s544444737.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s544444737", "user_id": "u994767958"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let ((n (read)))\n (princ (floor (* (1- n) n) 2)))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nFor an integer N, we will choose a permutation \\{P_1, P_2, ..., P_N\\} of \\{1, 2, ..., N\\}.\n\nThen, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i.\n\nFind the maximum possible value of M_1 + M_2 + \\cdots + M_N.\n\nConstraints\n\nN is an integer satisfying 1 \\leq N \\leq 10^9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the maximum possible value of M_1 + M_2 + \\cdots + M_N.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n1\n\nWhen the permutation \\{P_1, P_2\\} = \\{2, 1\\} is chosen, M_1 + M_2 = 1 + 0 = 1.\n\nSample Input 2\n\n13\n\nSample Output 2\n\n78\n\nSample Input 3\n\n1\n\nSample Output 3\n\n0", "sample_input": "2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02924", "source_text": "Score : 400 points\n\nProblem Statement\n\nFor an integer N, we will choose a permutation \\{P_1, P_2, ..., P_N\\} of \\{1, 2, ..., N\\}.\n\nThen, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i.\n\nFind the maximum possible value of M_1 + M_2 + \\cdots + M_N.\n\nConstraints\n\nN is an integer satisfying 1 \\leq N \\leq 10^9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the maximum possible value of M_1 + M_2 + \\cdots + M_N.\n\nSample Input 1\n\n2\n\nSample Output 1\n\n1\n\nWhen the permutation \\{P_1, P_2\\} = \\{2, 1\\} is chosen, M_1 + M_2 = 1 + 0 = 1.\n\nSample Input 2\n\n13\n\nSample Output 2\n\n78\n\nSample Input 3\n\n1\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 54, "cpu_time_ms": 146, "memory_kb": 12260}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s062834529", "group_id": "codeNet:p02925", "input_text": "(defun check (a n)\n (let (acc)\n (loop for i from 1 to n\n do (let ((e (car (nth (1- i) a))))\n (if (and e (= (car (nth (1- e) a)) i))\n (push i acc))))\n acc))\n\n(defun pick (a n &optional (c 0))\n (if (= (count nil a) n)\n c\n (let ((rl (check a n)))\n (if (null rl)\n -1\n (progn \n (loop for i from 1 to n\n do (if (member i rl)\n (setf (nth (1- i) a) (cdr (nth (1- i) a)))))\n (pick a\n n \n (1+ c)))))))\n \n(defun main ()\n (let ((n (read))\n (a))\n (setf a\n (loop for i from 1 to n\n collect (loop for j from 2 to n\n collect (read))))\n (format t \"~A~%\" (pick a n))))\n(main)\n\n", "language": "Lisp", "metadata": {"date": 1567375300, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02925.html", "problem_id": "p02925", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02925/input.txt", "sample_output_relpath": "derived/input_output/data/p02925/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02925/Lisp/s062834529.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s062834529", "user_id": "u608227593"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun check (a n)\n (let (acc)\n (loop for i from 1 to n\n do (let ((e (car (nth (1- i) a))))\n (if (and e (= (car (nth (1- e) a)) i))\n (push i acc))))\n acc))\n\n(defun pick (a n &optional (c 0))\n (if (= (count nil a) n)\n c\n (let ((rl (check a n)))\n (if (null rl)\n -1\n (progn \n (loop for i from 1 to n\n do (if (member i rl)\n (setf (nth (1- i) a) (cdr (nth (1- i) a)))))\n (pick a\n n \n (1+ c)))))))\n \n(defun main ()\n (let ((n (read))\n (a))\n (setf a\n (loop for i from 1 to n\n collect (loop for j from 2 to n\n collect (read))))\n (format t \"~A~%\" (pick a n))))\n(main)\n\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nN players will participate in a tennis tournament. We will call them Player 1, Player 2, \\ldots, Player N.\n\nThe tournament is round-robin format, and there will be N(N-1)/2 matches in total.\nIs it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.\n\nEach player plays at most one matches in a day.\n\nEach player i (1 \\leq i \\leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \\ldots, A_{i, N-1} in this order.\n\nConstraints\n\n3 \\leq N \\leq 1000\n\n1 \\leq A_{i, j} \\leq N\n\nA_{i, j} \\neq i\n\nA_{i, 1}, A_{i, 2}, \\ldots, A_{i, N-1} are all different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_{1, 1} A_{1, 2} \\ldots A_{1, N-1}\nA_{2, 1} A_{2, 2} \\ldots A_{2, N-1}\n:\nA_{N, 1} A_{N, 2} \\ldots A_{N, N-1}\n\nOutput\n\nIf it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print -1.\n\nSample Input 1\n\n3\n2 3\n1 3\n1 2\n\nSample Output 1\n\n3\n\nAll the conditions can be satisfied if the matches are scheduled for three days as follows:\n\nDay 1: Player 1 vs Player 2\n\nDay 2: Player 1 vs Player 3\n\nDay 3: Player 2 vs Player 3\n\nThis is the minimum number of days required.\n\nSample Input 2\n\n4\n2 3 4\n1 3 4\n4 1 2\n3 1 2\n\nSample Output 2\n\n4\n\nAll the conditions can be satisfied if the matches are scheduled for four days as follows:\n\nDay 1: Player 1 vs Player 2, Player 3 vs Player 4\n\nDay 2: Player 1 vs Player 3\n\nDay 3: Player 1 vs Player 4, Player 2 vs Player 3\n\nDay 4: Player 2 vs Player 4\n\nThis is the minimum number of days required.\n\nSample Input 3\n\n3\n2 3\n3 1\n1 2\n\nSample Output 3\n\n-1\n\nAny scheduling of the matches violates some condition.", "sample_input": "3\n2 3\n1 3\n1 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02925", "source_text": "Score : 500 points\n\nProblem Statement\n\nN players will participate in a tennis tournament. We will call them Player 1, Player 2, \\ldots, Player N.\n\nThe tournament is round-robin format, and there will be N(N-1)/2 matches in total.\nIs it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.\n\nEach player plays at most one matches in a day.\n\nEach player i (1 \\leq i \\leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \\ldots, A_{i, N-1} in this order.\n\nConstraints\n\n3 \\leq N \\leq 1000\n\n1 \\leq A_{i, j} \\leq N\n\nA_{i, j} \\neq i\n\nA_{i, 1}, A_{i, 2}, \\ldots, A_{i, N-1} are all different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_{1, 1} A_{1, 2} \\ldots A_{1, N-1}\nA_{2, 1} A_{2, 2} \\ldots A_{2, N-1}\n:\nA_{N, 1} A_{N, 2} \\ldots A_{N, N-1}\n\nOutput\n\nIf it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print -1.\n\nSample Input 1\n\n3\n2 3\n1 3\n1 2\n\nSample Output 1\n\n3\n\nAll the conditions can be satisfied if the matches are scheduled for three days as follows:\n\nDay 1: Player 1 vs Player 2\n\nDay 2: Player 1 vs Player 3\n\nDay 3: Player 2 vs Player 3\n\nThis is the minimum number of days required.\n\nSample Input 2\n\n4\n2 3 4\n1 3 4\n4 1 2\n3 1 2\n\nSample Output 2\n\n4\n\nAll the conditions can be satisfied if the matches are scheduled for four days as follows:\n\nDay 1: Player 1 vs Player 2, Player 3 vs Player 4\n\nDay 2: Player 1 vs Player 3\n\nDay 3: Player 1 vs Player 4, Player 2 vs Player 3\n\nDay 4: Player 2 vs Player 4\n\nThis is the minimum number of days required.\n\nSample Input 3\n\n3\n2 3\n3 1\n1 2\n\nSample Output 3\n\n-1\n\nAny scheduling of the matches violates some condition.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 824, "cpu_time_ms": 2105, "memory_kb": 74120}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s055904385", "group_id": "codeNet:p02925", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"256MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n;; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Topological sort\n;;;\n\n(define-condition cycle-detected-error (simple-error)\n ((graph :initarg :graph :reader cycle-detected-error-graph)\n (vertex :initarg :vertex :reader cycle-detected-error-vertex))\n (:report\n (lambda (condition stream)\n (format stream \"Detected a cycle containing ~A in ~A.\"\n (cycle-detected-error-vertex condition)\n (cycle-detected-error-graph condition)))))\n\n(declaim (ftype (function * (values (simple-array (integer 0 #.most-positive-fixnum) (*)) &optional))\n topological-sort))\n(defun topological-sort (graph)\n \"Returns a topologically sorted array of all the vertex in GRAPH. This\nfunction signals CYCLE-DETECTED-ERROR when it detects a cycle.\n\nGRAPH := vector of adjacency lists.\"\n (declare #.OPT\n ((simple-array list (*)) graph))\n (let* ((n (length graph))\n (tmp-marked (make-array n :element-type 'bit :initial-element 0))\n (marked (make-array n :element-type 'bit :initial-element 0))\n (result (make-array n :element-type '(integer 0 #.most-positive-fixnum)))\n (index (- n 1)))\n (declare (fixnum index))\n (labels ((visit (v)\n (when (= 0 (aref marked v))\n (when (= 1 (aref tmp-marked v))\n (error 'cycle-detected-error :graph graph :vertex v))\n (setf (aref tmp-marked v) 1)\n (dolist (next (aref graph v))\n (visit next))\n (setf (aref marked v) 1)\n (setf (aref result index) v)\n (decf index))))\n (dotimes (v n result)\n (when (= 0 (aref marked v))\n (visit v))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline encode))\n(defun encode (x y)\n (when (> x y)\n (rotatef x y))\n (dpb y (byte 10 10) x))\n\n(defconstant +max+ (ash 1 20))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array (list n (- n 1)) :element-type 'uint32))\n (graph (make-array +max+ :element-type 'list :initial-element nil)))\n (declare (uint16 n))\n (dotimes (i n)\n (dotimes (j (- n 1))\n (let ((a (- (read-fixnum) 1)))\n (setf (aref as i j) a))))\n (dotimes (i n)\n (dotimes (j (- n 2))\n (let* ((op1 (aref as i j))\n (op2 (aref as i (+ j 1)))\n (v1 (encode i op1))\n (v2 (encode i op2)))\n (push v2 (aref graph v1)))))\n (handler-bind ((cycle-detected-error\n (lambda (c) (println -1) (return-from main))))\n (let ((seq (topological-sort graph))\n (dp (make-array +max+ :element-type 'uint32 :initial-element 1)))\n (dotimes (i +max+)\n (let ((v (aref seq i)))\n (dolist (neighbor (aref graph v))\n (setf (aref dp neighbor)\n (max (aref dp neighbor)\n (+ 1 (aref dp v)))))))\n (println (reduce #'max dp))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1567371128, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02925.html", "problem_id": "p02925", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02925/input.txt", "sample_output_relpath": "derived/input_output/data/p02925/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02925/Lisp/s055904385.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s055904385", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"256MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n;; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Topological sort\n;;;\n\n(define-condition cycle-detected-error (simple-error)\n ((graph :initarg :graph :reader cycle-detected-error-graph)\n (vertex :initarg :vertex :reader cycle-detected-error-vertex))\n (:report\n (lambda (condition stream)\n (format stream \"Detected a cycle containing ~A in ~A.\"\n (cycle-detected-error-vertex condition)\n (cycle-detected-error-graph condition)))))\n\n(declaim (ftype (function * (values (simple-array (integer 0 #.most-positive-fixnum) (*)) &optional))\n topological-sort))\n(defun topological-sort (graph)\n \"Returns a topologically sorted array of all the vertex in GRAPH. This\nfunction signals CYCLE-DETECTED-ERROR when it detects a cycle.\n\nGRAPH := vector of adjacency lists.\"\n (declare #.OPT\n ((simple-array list (*)) graph))\n (let* ((n (length graph))\n (tmp-marked (make-array n :element-type 'bit :initial-element 0))\n (marked (make-array n :element-type 'bit :initial-element 0))\n (result (make-array n :element-type '(integer 0 #.most-positive-fixnum)))\n (index (- n 1)))\n (declare (fixnum index))\n (labels ((visit (v)\n (when (= 0 (aref marked v))\n (when (= 1 (aref tmp-marked v))\n (error 'cycle-detected-error :graph graph :vertex v))\n (setf (aref tmp-marked v) 1)\n (dolist (next (aref graph v))\n (visit next))\n (setf (aref marked v) 1)\n (setf (aref result index) v)\n (decf index))))\n (dotimes (v n result)\n (when (= 0 (aref marked v))\n (visit v))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline encode))\n(defun encode (x y)\n (when (> x y)\n (rotatef x y))\n (dpb y (byte 10 10) x))\n\n(defconstant +max+ (ash 1 20))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array (list n (- n 1)) :element-type 'uint32))\n (graph (make-array +max+ :element-type 'list :initial-element nil)))\n (declare (uint16 n))\n (dotimes (i n)\n (dotimes (j (- n 1))\n (let ((a (- (read-fixnum) 1)))\n (setf (aref as i j) a))))\n (dotimes (i n)\n (dotimes (j (- n 2))\n (let* ((op1 (aref as i j))\n (op2 (aref as i (+ j 1)))\n (v1 (encode i op1))\n (v2 (encode i op2)))\n (push v2 (aref graph v1)))))\n (handler-bind ((cycle-detected-error\n (lambda (c) (println -1) (return-from main))))\n (let ((seq (topological-sort graph))\n (dp (make-array +max+ :element-type 'uint32 :initial-element 1)))\n (dotimes (i +max+)\n (let ((v (aref seq i)))\n (dolist (neighbor (aref graph v))\n (setf (aref dp neighbor)\n (max (aref dp neighbor)\n (+ 1 (aref dp v)))))))\n (println (reduce #'max dp))))))\n\n#-swank (main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nN players will participate in a tennis tournament. We will call them Player 1, Player 2, \\ldots, Player N.\n\nThe tournament is round-robin format, and there will be N(N-1)/2 matches in total.\nIs it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.\n\nEach player plays at most one matches in a day.\n\nEach player i (1 \\leq i \\leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \\ldots, A_{i, N-1} in this order.\n\nConstraints\n\n3 \\leq N \\leq 1000\n\n1 \\leq A_{i, j} \\leq N\n\nA_{i, j} \\neq i\n\nA_{i, 1}, A_{i, 2}, \\ldots, A_{i, N-1} are all different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_{1, 1} A_{1, 2} \\ldots A_{1, N-1}\nA_{2, 1} A_{2, 2} \\ldots A_{2, N-1}\n:\nA_{N, 1} A_{N, 2} \\ldots A_{N, N-1}\n\nOutput\n\nIf it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print -1.\n\nSample Input 1\n\n3\n2 3\n1 3\n1 2\n\nSample Output 1\n\n3\n\nAll the conditions can be satisfied if the matches are scheduled for three days as follows:\n\nDay 1: Player 1 vs Player 2\n\nDay 2: Player 1 vs Player 3\n\nDay 3: Player 2 vs Player 3\n\nThis is the minimum number of days required.\n\nSample Input 2\n\n4\n2 3 4\n1 3 4\n4 1 2\n3 1 2\n\nSample Output 2\n\n4\n\nAll the conditions can be satisfied if the matches are scheduled for four days as follows:\n\nDay 1: Player 1 vs Player 2, Player 3 vs Player 4\n\nDay 2: Player 1 vs Player 3\n\nDay 3: Player 1 vs Player 4, Player 2 vs Player 3\n\nDay 4: Player 2 vs Player 4\n\nThis is the minimum number of days required.\n\nSample Input 3\n\n3\n2 3\n3 1\n1 2\n\nSample Output 3\n\n-1\n\nAny scheduling of the matches violates some condition.", "sample_input": "3\n2 3\n1 3\n1 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02925", "source_text": "Score : 500 points\n\nProblem Statement\n\nN players will participate in a tennis tournament. We will call them Player 1, Player 2, \\ldots, Player N.\n\nThe tournament is round-robin format, and there will be N(N-1)/2 matches in total.\nIs it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.\n\nEach player plays at most one matches in a day.\n\nEach player i (1 \\leq i \\leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \\ldots, A_{i, N-1} in this order.\n\nConstraints\n\n3 \\leq N \\leq 1000\n\n1 \\leq A_{i, j} \\leq N\n\nA_{i, j} \\neq i\n\nA_{i, 1}, A_{i, 2}, \\ldots, A_{i, N-1} are all different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_{1, 1} A_{1, 2} \\ldots A_{1, N-1}\nA_{2, 1} A_{2, 2} \\ldots A_{2, N-1}\n:\nA_{N, 1} A_{N, 2} \\ldots A_{N, N-1}\n\nOutput\n\nIf it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print -1.\n\nSample Input 1\n\n3\n2 3\n1 3\n1 2\n\nSample Output 1\n\n3\n\nAll the conditions can be satisfied if the matches are scheduled for three days as follows:\n\nDay 1: Player 1 vs Player 2\n\nDay 2: Player 1 vs Player 3\n\nDay 3: Player 2 vs Player 3\n\nThis is the minimum number of days required.\n\nSample Input 2\n\n4\n2 3 4\n1 3 4\n4 1 2\n3 1 2\n\nSample Output 2\n\n4\n\nAll the conditions can be satisfied if the matches are scheduled for four days as follows:\n\nDay 1: Player 1 vs Player 2, Player 3 vs Player 4\n\nDay 2: Player 1 vs Player 3\n\nDay 3: Player 1 vs Player 4, Player 2 vs Player 3\n\nDay 4: Player 2 vs Player 4\n\nThis is the minimum number of days required.\n\nSample Input 3\n\n3\n2 3\n3 1\n1 2\n\nSample Output 3\n\n-1\n\nAny scheduling of the matches violates some condition.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5796, "cpu_time_ms": 360, "memory_kb": 60728}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s717226056", "group_id": "codeNet:p02925", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"256MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n;; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Topological sort\n;;;(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n\n(define-condition cycle-detected-error (simple-error)\n ((graph :initarg :graph :reader cycle-detected-error-graph)\n (vertex :initarg :vertex :reader cycle-detected-error-vertex))\n (:report\n (lambda (condition stream)\n (format stream \"Detected a cycle containing ~A in ~A.\"\n (cycle-detected-error-vertex condition)\n (cycle-detected-error-graph condition)))))\n\n(defun topological-sort (graph)\n \"Returns a topologically sorted array of all the vertex in GRAPH. This\nfunction signals CYCLE-DETECTED-ERROR when it detects a cycle.\n\nGRAPH := vector of adjacency lists.\"\n (declare ((array list (*)) graph))\n (let* ((n (length graph))\n (tmp-marked (make-array n :element-type 'bit :initial-element 0))\n (marked (make-array n :element-type 'bit :initial-element 0))\n (result (make-array n :element-type '(integer 0 #.most-positive-fixnum)))\n (index (- n 1)))\n (declare (fixnum index))\n (labels ((visit (v)\n (when (= 0 (aref marked v))\n (when (= 1 (aref tmp-marked v))\n (error 'cycle-detected-error :graph graph :vertex v))\n (setf (aref tmp-marked v) 1)\n (dolist (next (aref graph v))\n (visit next))\n (setf (aref marked v) 1)\n (setf (aref result index) v)\n (decf index))))\n (dotimes (v n result)\n (when (= 0 (aref marked v))\n (visit v))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline encode))\n(defun encode (x y)\n (when (> x y)\n (rotatef x y))\n (dpb y (byte 10 10) x))\n\n(defconstant +max+ (ash 1 20))\n\n(defun main ()\n (let* ((n (read))\n (as (make-array (list n (- n 1)) :element-type 'uint32))\n (graph (make-array +max+ :element-type 'list :initial-element nil)))\n (dotimes (i n)\n (dotimes (j (- n 1))\n (let ((a (- (read-fixnum) 1)))\n (setf (aref as i j) a))))\n ;; #>as\n (dotimes (i n)\n (dotimes (j (- n 2))\n (let* ((op1 (aref as i j))\n (op2 (aref as i (+ j 1)))\n (v1 (encode i op1))\n (v2 (encode i op2)))\n (push v2 (aref graph v1)))))\n ;; #>(subseq graph 0 1000)\n (handler-bind ((cycle-detected-error (lambda (c) (println -1) (return-from main))))\n (let ((seq (topological-sort graph))\n (dp (make-array +max+ :element-type 'uint32 :initial-element 1)))\n ;; #>seq\n (dotimes (i +max+)\n (let ((v (aref seq i)))\n (dolist (neighbor (aref graph v))\n (setf (aref dp neighbor)\n (max (aref dp neighbor)\n (+ 1 (aref dp v)))))))\n (println (reduce #'max dp))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1567366894, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02925.html", "problem_id": "p02925", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02925/input.txt", "sample_output_relpath": "derived/input_output/data/p02925/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02925/Lisp/s717226056.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s717226056", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"256MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n;; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Topological sort\n;;;(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n\n(define-condition cycle-detected-error (simple-error)\n ((graph :initarg :graph :reader cycle-detected-error-graph)\n (vertex :initarg :vertex :reader cycle-detected-error-vertex))\n (:report\n (lambda (condition stream)\n (format stream \"Detected a cycle containing ~A in ~A.\"\n (cycle-detected-error-vertex condition)\n (cycle-detected-error-graph condition)))))\n\n(defun topological-sort (graph)\n \"Returns a topologically sorted array of all the vertex in GRAPH. This\nfunction signals CYCLE-DETECTED-ERROR when it detects a cycle.\n\nGRAPH := vector of adjacency lists.\"\n (declare ((array list (*)) graph))\n (let* ((n (length graph))\n (tmp-marked (make-array n :element-type 'bit :initial-element 0))\n (marked (make-array n :element-type 'bit :initial-element 0))\n (result (make-array n :element-type '(integer 0 #.most-positive-fixnum)))\n (index (- n 1)))\n (declare (fixnum index))\n (labels ((visit (v)\n (when (= 0 (aref marked v))\n (when (= 1 (aref tmp-marked v))\n (error 'cycle-detected-error :graph graph :vertex v))\n (setf (aref tmp-marked v) 1)\n (dolist (next (aref graph v))\n (visit next))\n (setf (aref marked v) 1)\n (setf (aref result index) v)\n (decf index))))\n (dotimes (v n result)\n (when (= 0 (aref marked v))\n (visit v))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline encode))\n(defun encode (x y)\n (when (> x y)\n (rotatef x y))\n (dpb y (byte 10 10) x))\n\n(defconstant +max+ (ash 1 20))\n\n(defun main ()\n (let* ((n (read))\n (as (make-array (list n (- n 1)) :element-type 'uint32))\n (graph (make-array +max+ :element-type 'list :initial-element nil)))\n (dotimes (i n)\n (dotimes (j (- n 1))\n (let ((a (- (read-fixnum) 1)))\n (setf (aref as i j) a))))\n ;; #>as\n (dotimes (i n)\n (dotimes (j (- n 2))\n (let* ((op1 (aref as i j))\n (op2 (aref as i (+ j 1)))\n (v1 (encode i op1))\n (v2 (encode i op2)))\n (push v2 (aref graph v1)))))\n ;; #>(subseq graph 0 1000)\n (handler-bind ((cycle-detected-error (lambda (c) (println -1) (return-from main))))\n (let ((seq (topological-sort graph))\n (dp (make-array +max+ :element-type 'uint32 :initial-element 1)))\n ;; #>seq\n (dotimes (i +max+)\n (let ((v (aref seq i)))\n (dolist (neighbor (aref graph v))\n (setf (aref dp neighbor)\n (max (aref dp neighbor)\n (+ 1 (aref dp v)))))))\n (println (reduce #'max dp))))))\n\n#-swank (main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nN players will participate in a tennis tournament. We will call them Player 1, Player 2, \\ldots, Player N.\n\nThe tournament is round-robin format, and there will be N(N-1)/2 matches in total.\nIs it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.\n\nEach player plays at most one matches in a day.\n\nEach player i (1 \\leq i \\leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \\ldots, A_{i, N-1} in this order.\n\nConstraints\n\n3 \\leq N \\leq 1000\n\n1 \\leq A_{i, j} \\leq N\n\nA_{i, j} \\neq i\n\nA_{i, 1}, A_{i, 2}, \\ldots, A_{i, N-1} are all different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_{1, 1} A_{1, 2} \\ldots A_{1, N-1}\nA_{2, 1} A_{2, 2} \\ldots A_{2, N-1}\n:\nA_{N, 1} A_{N, 2} \\ldots A_{N, N-1}\n\nOutput\n\nIf it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print -1.\n\nSample Input 1\n\n3\n2 3\n1 3\n1 2\n\nSample Output 1\n\n3\n\nAll the conditions can be satisfied if the matches are scheduled for three days as follows:\n\nDay 1: Player 1 vs Player 2\n\nDay 2: Player 1 vs Player 3\n\nDay 3: Player 2 vs Player 3\n\nThis is the minimum number of days required.\n\nSample Input 2\n\n4\n2 3 4\n1 3 4\n4 1 2\n3 1 2\n\nSample Output 2\n\n4\n\nAll the conditions can be satisfied if the matches are scheduled for four days as follows:\n\nDay 1: Player 1 vs Player 2, Player 3 vs Player 4\n\nDay 2: Player 1 vs Player 3\n\nDay 3: Player 1 vs Player 4, Player 2 vs Player 3\n\nDay 4: Player 2 vs Player 4\n\nThis is the minimum number of days required.\n\nSample Input 3\n\n3\n2 3\n3 1\n1 2\n\nSample Output 3\n\n-1\n\nAny scheduling of the matches violates some condition.", "sample_input": "3\n2 3\n1 3\n1 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02925", "source_text": "Score : 500 points\n\nProblem Statement\n\nN players will participate in a tennis tournament. We will call them Player 1, Player 2, \\ldots, Player N.\n\nThe tournament is round-robin format, and there will be N(N-1)/2 matches in total.\nIs it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.\n\nEach player plays at most one matches in a day.\n\nEach player i (1 \\leq i \\leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \\ldots, A_{i, N-1} in this order.\n\nConstraints\n\n3 \\leq N \\leq 1000\n\n1 \\leq A_{i, j} \\leq N\n\nA_{i, j} \\neq i\n\nA_{i, 1}, A_{i, 2}, \\ldots, A_{i, N-1} are all different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_{1, 1} A_{1, 2} \\ldots A_{1, N-1}\nA_{2, 1} A_{2, 2} \\ldots A_{2, N-1}\n:\nA_{N, 1} A_{N, 2} \\ldots A_{N, N-1}\n\nOutput\n\nIf it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print -1.\n\nSample Input 1\n\n3\n2 3\n1 3\n1 2\n\nSample Output 1\n\n3\n\nAll the conditions can be satisfied if the matches are scheduled for three days as follows:\n\nDay 1: Player 1 vs Player 2\n\nDay 2: Player 1 vs Player 3\n\nDay 3: Player 2 vs Player 3\n\nThis is the minimum number of days required.\n\nSample Input 2\n\n4\n2 3 4\n1 3 4\n4 1 2\n3 1 2\n\nSample Output 2\n\n4\n\nAll the conditions can be satisfied if the matches are scheduled for four days as follows:\n\nDay 1: Player 1 vs Player 2, Player 3 vs Player 4\n\nDay 2: Player 1 vs Player 3\n\nDay 3: Player 1 vs Player 4, Player 2 vs Player 3\n\nDay 4: Player 2 vs Player 4\n\nThis is the minimum number of days required.\n\nSample Input 3\n\n3\n2 3\n3 1\n1 2\n\nSample Output 3\n\n-1\n\nAny scheduling of the matches violates some condition.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5630, "cpu_time_ms": 326, "memory_kb": 62776}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s271805654", "group_id": "codeNet:p02926", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; ARRAY-ELEMENT-TYPE is not constant-folded on SBCL version earlier than\n;;; 1.5.0. See\n;;; https://github.com/sbcl/sbcl/commit/9f0d12e7ab961828931d01c0b2a76a5885ad35d2\n;;;\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:deftransform array-element-type ((array))\n (let ((type (sb-c::lvar-type array)))\n (flet ((element-type (type)\n (and (sb-c::array-type-p type)\n (sb-int:neq (sb-kernel::array-type-specialized-element-type type) sb-kernel:*wild-type*)\n (sb-kernel:type-specifier (sb-kernel::array-type-specialized-element-type type)))))\n (cond ((let ((type (element-type type)))\n (and type\n `',type)))\n ((sb-kernel:union-type-p type)\n (let (result)\n (loop for type in (sb-kernel:union-type-types type)\n for et = (element-type type)\n unless (and et\n (if result\n (equal result et)\n (setf result et)))\n do (sb-c::give-up-ir1-transform))\n `',result))\n ((sb-kernel:intersection-type-p type)\n (loop for type in (sb-kernel:intersection-type-types type)\n for et = (element-type type)\n when et\n return `',et\n finally (sb-c::give-up-ir1-transform)))\n (t\n (sb-c::give-up-ir1-transform)))))))\n\n;;;\n;;; 2D convex hull of points (Monotone Chain Algorithm)\n;;; Complexity: O(nlog(n))\n;;;\n\n(declaim (inline make-convex-hull!))\n(defun make-convex-hull! (points &optional (eps 0))\n \"Returns the vector of the vertices comprising the convex hull, which are\nsorted in the anticlockwise direction around the perimeter. This function sorts\nPOINTS as a side effect.\n\nIf EPS is non-negative, three vertices in a straight line are excluded (when the\ncalculation error is within EPS, of course); they are allowed if EPS is\nnegative.\n\nPOINTS := vector of complex number\"\n (declare (inline sort)\n (vector points))\n ;; FIXME: The returned vector may contain duplicate vertices in a degenerative\n ;; case: E.g. (make-convex-hull! #(#c(1 2) #c(1 2) #c(1 2) #c(1 2)) ) |->\n ;; #(#C(1 2) #C(1 2))\n (macrolet ((outer (p1 p2) ; outer product\n `(let ((c1 ,p1)\n (c2 ,p2))\n (- (* (realpart c1) (imagpart c2))\n (* (imagpart c1) (realpart c2))))))\n (when (<= (length points) 1)\n (return-from make-convex-hull! (copy-seq points)))\n (let* ((n (length points))\n (end 0)\n (res (make-array (* n 2) :element-type (array-element-type points)))\n (points (sort points (lambda (p1 p2)\n (if (= (realpart p1) (realpart p2))\n (< (imagpart p1) (imagpart p2))\n (< (realpart p1) (realpart p2)))))))\n (declare (fixnum end))\n (do ((i 0 (+ i 1)))\n ((= i n))\n (loop (if (and (> end 1)\n (<= (outer (- (aref res (- end 1)) (aref res (- end 2)))\n (- (aref points i) (aref res (- end 1))))\n eps))\n (decf end)\n (return)))\n (setf (aref res end) (aref points i))\n (incf end))\n (let ((tmp-end end))\n (do ((i (- n 2) (- i 1)))\n ((< i 0))\n (loop (if (and (> end tmp-end)\n (<= (outer (- (aref res (- end 1)) (aref res (- end 2)))\n (- (aref points i) (aref res (- end 1))))\n eps))\n (decf end)\n (return)))\n (setf (aref res end) (aref points i))\n (incf end)))\n (adjust-array res (- end 1)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +eps+ 1d-9)\n\n(defun main ()\n (let* ((n (read))\n (vecs (make-array n :element-type '(complex double-float)))\n (points (make-array 1 :element-type '(complex double-float)\n :initial-element #c(0d0 0d0))))\n (dotimes (i n)\n (let ((x (float (read) 1d0))\n (y (float (read) 1d0)))\n (setf (aref vecs i) (complex x y))))\n (sb-int:dovector (v vecs)\n (let* ((len (length points))\n (translation (adjust-array points (* 2 len))))\n (declare (uint32 len)\n ((simple-array (complex double-float) (*)) translation))\n (dotimes (i len)\n (setf (aref translation (+ i len))\n (+ (aref translation i) v)))\n (setq points (make-convex-hull! translation +eps+))))\n (println (reduce #'max points :key #'abs))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1567515675, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02926.html", "problem_id": "p02926", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02926/input.txt", "sample_output_relpath": "derived/input_output/data/p02926/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02926/Lisp/s271805654.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s271805654", "user_id": "u352600849"}, "prompt_components": {"gold_output": "10.000000000000000000000000000000000000000000000000\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; ARRAY-ELEMENT-TYPE is not constant-folded on SBCL version earlier than\n;;; 1.5.0. See\n;;; https://github.com/sbcl/sbcl/commit/9f0d12e7ab961828931d01c0b2a76a5885ad35d2\n;;;\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:deftransform array-element-type ((array))\n (let ((type (sb-c::lvar-type array)))\n (flet ((element-type (type)\n (and (sb-c::array-type-p type)\n (sb-int:neq (sb-kernel::array-type-specialized-element-type type) sb-kernel:*wild-type*)\n (sb-kernel:type-specifier (sb-kernel::array-type-specialized-element-type type)))))\n (cond ((let ((type (element-type type)))\n (and type\n `',type)))\n ((sb-kernel:union-type-p type)\n (let (result)\n (loop for type in (sb-kernel:union-type-types type)\n for et = (element-type type)\n unless (and et\n (if result\n (equal result et)\n (setf result et)))\n do (sb-c::give-up-ir1-transform))\n `',result))\n ((sb-kernel:intersection-type-p type)\n (loop for type in (sb-kernel:intersection-type-types type)\n for et = (element-type type)\n when et\n return `',et\n finally (sb-c::give-up-ir1-transform)))\n (t\n (sb-c::give-up-ir1-transform)))))))\n\n;;;\n;;; 2D convex hull of points (Monotone Chain Algorithm)\n;;; Complexity: O(nlog(n))\n;;;\n\n(declaim (inline make-convex-hull!))\n(defun make-convex-hull! (points &optional (eps 0))\n \"Returns the vector of the vertices comprising the convex hull, which are\nsorted in the anticlockwise direction around the perimeter. This function sorts\nPOINTS as a side effect.\n\nIf EPS is non-negative, three vertices in a straight line are excluded (when the\ncalculation error is within EPS, of course); they are allowed if EPS is\nnegative.\n\nPOINTS := vector of complex number\"\n (declare (inline sort)\n (vector points))\n ;; FIXME: The returned vector may contain duplicate vertices in a degenerative\n ;; case: E.g. (make-convex-hull! #(#c(1 2) #c(1 2) #c(1 2) #c(1 2)) ) |->\n ;; #(#C(1 2) #C(1 2))\n (macrolet ((outer (p1 p2) ; outer product\n `(let ((c1 ,p1)\n (c2 ,p2))\n (- (* (realpart c1) (imagpart c2))\n (* (imagpart c1) (realpart c2))))))\n (when (<= (length points) 1)\n (return-from make-convex-hull! (copy-seq points)))\n (let* ((n (length points))\n (end 0)\n (res (make-array (* n 2) :element-type (array-element-type points)))\n (points (sort points (lambda (p1 p2)\n (if (= (realpart p1) (realpart p2))\n (< (imagpart p1) (imagpart p2))\n (< (realpart p1) (realpart p2)))))))\n (declare (fixnum end))\n (do ((i 0 (+ i 1)))\n ((= i n))\n (loop (if (and (> end 1)\n (<= (outer (- (aref res (- end 1)) (aref res (- end 2)))\n (- (aref points i) (aref res (- end 1))))\n eps))\n (decf end)\n (return)))\n (setf (aref res end) (aref points i))\n (incf end))\n (let ((tmp-end end))\n (do ((i (- n 2) (- i 1)))\n ((< i 0))\n (loop (if (and (> end tmp-end)\n (<= (outer (- (aref res (- end 1)) (aref res (- end 2)))\n (- (aref points i) (aref res (- end 1))))\n eps))\n (decf end)\n (return)))\n (setf (aref res end) (aref points i))\n (incf end)))\n (adjust-array res (- end 1)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +eps+ 1d-9)\n\n(defun main ()\n (let* ((n (read))\n (vecs (make-array n :element-type '(complex double-float)))\n (points (make-array 1 :element-type '(complex double-float)\n :initial-element #c(0d0 0d0))))\n (dotimes (i n)\n (let ((x (float (read) 1d0))\n (y (float (read) 1d0)))\n (setf (aref vecs i) (complex x y))))\n (sb-int:dovector (v vecs)\n (let* ((len (length points))\n (translation (adjust-array points (* 2 len))))\n (declare (uint32 len)\n ((simple-array (complex double-float) (*)) translation))\n (dotimes (i len)\n (setf (aref translation (+ i len))\n (+ (aref translation i) v)))\n (setq points (make-convex-hull! translation +eps+))))\n (println (reduce #'max points :key #'abs))))\n\n#-swank (main)\n", "problem_context": "Score: 600 points\n\nProblem Statement\n\nE869120 is initially standing at the origin (0, 0) in a two-dimensional plane.\n\nHe has N engines, which can be used as follows:\n\nWhen E869120 uses the i-th engine, his X- and Y-coordinate change by x_i and y_i, respectively. In other words, if E869120 uses the i-th engine from coordinates (X, Y), he will move to the coordinates (X + x_i, Y + y_i).\n\nE869120 can use these engines in any order, but each engine can be used at most once. He may also choose not to use some of the engines.\n\nHe wants to go as far as possible from the origin.\nLet (X, Y) be his final coordinates. Find the maximum possible value of \\sqrt{X^2 + Y^2}, the distance from the origin.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n-1 \\ 000 \\ 000 \\leq x_i \\leq 1 \\ 000 \\ 000\n\n-1 \\ 000 \\ 000 \\leq y_i \\leq 1 \\ 000 \\ 000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\nx_2 y_2\n: :\nx_N y_N\n\nOutput\n\nPrint the maximum possible final distance from the origin, as a real value.\nYour output is considered correct when the relative or absolute error from the true answer is at most 10^{-10}.\n\nSample Input 1\n\n3\n0 10\n5 -5\n-5 -5\n\nSample Output 1\n\n10.000000000000000000000000000000000000000000000000\n\nThe final distance from the origin can be 10 if we use the engines in one of the following three ways:\n\nUse Engine 1 to move to (0, 10).\n\nUse Engine 2 to move to (5, -5), and then use Engine 3 to move to (0, -10).\n\nUse Engine 3 to move to (-5, -5), and then use Engine 2 to move to (0, -10).\n\nThe distance cannot be greater than 10, so the maximum possible distance is 10.\n\nSample Input 2\n\n5\n1 1\n1 0\n0 1\n-1 0\n0 -1\n\nSample Output 2\n\n2.828427124746190097603377448419396157139343750753\n\nThe maximum possible final distance is 2 \\sqrt{2} = 2.82842....\nOne of the ways to achieve it is:\n\nUse Engine 1 to move to (1, 1), and then use Engine 2 to move to (2, 1), and finally use Engine 3 to move to (2, 2).\n\nSample Input 3\n\n5\n1 1\n2 2\n3 3\n4 4\n5 5\n\nSample Output 3\n\n21.213203435596425732025330863145471178545078130654\n\nIf we use all the engines in the order 1 \\rightarrow 2 \\rightarrow 3 \\rightarrow 4 \\rightarrow 5, we will end up at (15, 15), with the distance 15 \\sqrt{2} = 21.2132... from the origin.\n\nSample Input 4\n\n3\n0 0\n0 1\n1 0\n\nSample Output 4\n\n1.414213562373095048801688724209698078569671875376\n\nThere can be useless engines with (x_i, y_i) = (0, 0).\n\nSample Input 5\n\n1\n90447 91000\n\nSample Output 5\n\n128303.000000000000000000000000000000000000000000000000\n\nNote that there can be only one engine.\n\nSample Input 6\n\n2\n96000 -72000\n-72000 54000\n\nSample Output 6\n\n120000.000000000000000000000000000000000000000000000000\n\nThere can be only two engines, too.\n\nSample Input 7\n\n10\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\n15 16\n17 18\n19 20\n\nSample Output 7\n\n148.660687473185055226120082139313966514489855137208", "sample_input": "3\n0 10\n5 -5\n-5 -5\n"}, "reference_outputs": ["10.000000000000000000000000000000000000000000000000\n"], "source_document_id": "p02926", "source_text": "Score: 600 points\n\nProblem Statement\n\nE869120 is initially standing at the origin (0, 0) in a two-dimensional plane.\n\nHe has N engines, which can be used as follows:\n\nWhen E869120 uses the i-th engine, his X- and Y-coordinate change by x_i and y_i, respectively. In other words, if E869120 uses the i-th engine from coordinates (X, Y), he will move to the coordinates (X + x_i, Y + y_i).\n\nE869120 can use these engines in any order, but each engine can be used at most once. He may also choose not to use some of the engines.\n\nHe wants to go as far as possible from the origin.\nLet (X, Y) be his final coordinates. Find the maximum possible value of \\sqrt{X^2 + Y^2}, the distance from the origin.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n-1 \\ 000 \\ 000 \\leq x_i \\leq 1 \\ 000 \\ 000\n\n-1 \\ 000 \\ 000 \\leq y_i \\leq 1 \\ 000 \\ 000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\nx_2 y_2\n: :\nx_N y_N\n\nOutput\n\nPrint the maximum possible final distance from the origin, as a real value.\nYour output is considered correct when the relative or absolute error from the true answer is at most 10^{-10}.\n\nSample Input 1\n\n3\n0 10\n5 -5\n-5 -5\n\nSample Output 1\n\n10.000000000000000000000000000000000000000000000000\n\nThe final distance from the origin can be 10 if we use the engines in one of the following three ways:\n\nUse Engine 1 to move to (0, 10).\n\nUse Engine 2 to move to (5, -5), and then use Engine 3 to move to (0, -10).\n\nUse Engine 3 to move to (-5, -5), and then use Engine 2 to move to (0, -10).\n\nThe distance cannot be greater than 10, so the maximum possible distance is 10.\n\nSample Input 2\n\n5\n1 1\n1 0\n0 1\n-1 0\n0 -1\n\nSample Output 2\n\n2.828427124746190097603377448419396157139343750753\n\nThe maximum possible final distance is 2 \\sqrt{2} = 2.82842....\nOne of the ways to achieve it is:\n\nUse Engine 1 to move to (1, 1), and then use Engine 2 to move to (2, 1), and finally use Engine 3 to move to (2, 2).\n\nSample Input 3\n\n5\n1 1\n2 2\n3 3\n4 4\n5 5\n\nSample Output 3\n\n21.213203435596425732025330863145471178545078130654\n\nIf we use all the engines in the order 1 \\rightarrow 2 \\rightarrow 3 \\rightarrow 4 \\rightarrow 5, we will end up at (15, 15), with the distance 15 \\sqrt{2} = 21.2132... from the origin.\n\nSample Input 4\n\n3\n0 0\n0 1\n1 0\n\nSample Output 4\n\n1.414213562373095048801688724209698078569671875376\n\nThere can be useless engines with (x_i, y_i) = (0, 0).\n\nSample Input 5\n\n1\n90447 91000\n\nSample Output 5\n\n128303.000000000000000000000000000000000000000000000000\n\nNote that there can be only one engine.\n\nSample Input 6\n\n2\n96000 -72000\n-72000 54000\n\nSample Output 6\n\n120000.000000000000000000000000000000000000000000000000\n\nThere can be only two engines, too.\n\nSample Input 7\n\n10\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\n15 16\n17 18\n19 20\n\nSample Output 7\n\n148.660687473185055226120082139313966514489855137208", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6180, "cpu_time_ms": 270, "memory_kb": 47076}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s463706171", "group_id": "codeNet:p02926", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +eps+ 1d-9)\n\n(declaim (inline hypot))\n(defun hypot (x y)\n (sqrt (+ (* x x) (* y y))))\n\n(defun scan-anticlockwise (n xs ys)\n (declare ((simple-array double-float (*)) xs ys)\n (uint32 n))\n (let ((phases (make-array (* 2 n) :element-type 'double-float))\n (ords (make-array (* 2 n) :element-type 'uint32)))\n (dotimes (i (* 2 n))\n (setf (aref ords i) i))\n (dotimes (i n)\n (setf (aref phases i) (atan (aref ys i) (aref xs i))\n (aref phases (+ i n)) (+ (* 2 pi) (aref phases i))))\n (setf ords (sort ords (lambda (i j)\n (< (aref phases i) (aref phases j)))))\n (let ((res 0d0))\n (declare (double-float res))\n (labels ((calc-max! (phase-width)\n (dotimes (i n)\n (let* ((base-vec (aref ords i))\n (base-phase (aref phases base-vec))\n (xsum 0d0)\n (ysum 0d0))\n (declare (double-float xsum ysum))\n (loop for j from i below (+ i n)\n for new-vec = (aref ords j)\n for new-phase = (aref phases new-vec)\n while (<= (- new-phase base-phase) phase-width)\n do (incf xsum (aref xs new-vec))\n (incf ysum (aref ys new-vec)))\n (setq res (max res\n (hypot xsum ysum)\n ;; exclude the base vector\n (hypot (- xsum (aref xs base-vec))\n (- ysum (aref ys base-vec)))))))))\n (calc-max! (+ pi +eps+))\n res))))\n\n(defun main ()\n (let* ((n (read))\n (xs (make-array (* 2 n) :element-type 'double-float))\n (ys (make-array (* 2 n) :element-type 'double-float)))\n (dotimes (i n)\n (let* ((x (float (read) 1d0))\n (y (float (read) 1d0)))\n (setf (aref xs i) x\n (aref xs (+ i n)) x\n (aref ys i) y\n (aref ys (+ i n)) y)))\n (let ((res 0))\n (setq res (max res (scan-anticlockwise n xs ys)))\n ;; reflect all the points to scan them clockwise\n (dotimes (i (* 2 n)) (setf (aref xs i) (- (aref xs i))))\n ;; (setq res (max res (scan-anticlockwise n xs ys)))\n (println res))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1567424989, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02926.html", "problem_id": "p02926", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02926/input.txt", "sample_output_relpath": "derived/input_output/data/p02926/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02926/Lisp/s463706171.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s463706171", "user_id": "u352600849"}, "prompt_components": {"gold_output": "10.000000000000000000000000000000000000000000000000\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +eps+ 1d-9)\n\n(declaim (inline hypot))\n(defun hypot (x y)\n (sqrt (+ (* x x) (* y y))))\n\n(defun scan-anticlockwise (n xs ys)\n (declare ((simple-array double-float (*)) xs ys)\n (uint32 n))\n (let ((phases (make-array (* 2 n) :element-type 'double-float))\n (ords (make-array (* 2 n) :element-type 'uint32)))\n (dotimes (i (* 2 n))\n (setf (aref ords i) i))\n (dotimes (i n)\n (setf (aref phases i) (atan (aref ys i) (aref xs i))\n (aref phases (+ i n)) (+ (* 2 pi) (aref phases i))))\n (setf ords (sort ords (lambda (i j)\n (< (aref phases i) (aref phases j)))))\n (let ((res 0d0))\n (declare (double-float res))\n (labels ((calc-max! (phase-width)\n (dotimes (i n)\n (let* ((base-vec (aref ords i))\n (base-phase (aref phases base-vec))\n (xsum 0d0)\n (ysum 0d0))\n (declare (double-float xsum ysum))\n (loop for j from i below (+ i n)\n for new-vec = (aref ords j)\n for new-phase = (aref phases new-vec)\n while (<= (- new-phase base-phase) phase-width)\n do (incf xsum (aref xs new-vec))\n (incf ysum (aref ys new-vec)))\n (setq res (max res\n (hypot xsum ysum)\n ;; exclude the base vector\n (hypot (- xsum (aref xs base-vec))\n (- ysum (aref ys base-vec)))))))))\n (calc-max! (+ pi +eps+))\n res))))\n\n(defun main ()\n (let* ((n (read))\n (xs (make-array (* 2 n) :element-type 'double-float))\n (ys (make-array (* 2 n) :element-type 'double-float)))\n (dotimes (i n)\n (let* ((x (float (read) 1d0))\n (y (float (read) 1d0)))\n (setf (aref xs i) x\n (aref xs (+ i n)) x\n (aref ys i) y\n (aref ys (+ i n)) y)))\n (let ((res 0))\n (setq res (max res (scan-anticlockwise n xs ys)))\n ;; reflect all the points to scan them clockwise\n (dotimes (i (* 2 n)) (setf (aref xs i) (- (aref xs i))))\n ;; (setq res (max res (scan-anticlockwise n xs ys)))\n (println res))))\n\n#-swank (main)\n", "problem_context": "Score: 600 points\n\nProblem Statement\n\nE869120 is initially standing at the origin (0, 0) in a two-dimensional plane.\n\nHe has N engines, which can be used as follows:\n\nWhen E869120 uses the i-th engine, his X- and Y-coordinate change by x_i and y_i, respectively. In other words, if E869120 uses the i-th engine from coordinates (X, Y), he will move to the coordinates (X + x_i, Y + y_i).\n\nE869120 can use these engines in any order, but each engine can be used at most once. He may also choose not to use some of the engines.\n\nHe wants to go as far as possible from the origin.\nLet (X, Y) be his final coordinates. Find the maximum possible value of \\sqrt{X^2 + Y^2}, the distance from the origin.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n-1 \\ 000 \\ 000 \\leq x_i \\leq 1 \\ 000 \\ 000\n\n-1 \\ 000 \\ 000 \\leq y_i \\leq 1 \\ 000 \\ 000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\nx_2 y_2\n: :\nx_N y_N\n\nOutput\n\nPrint the maximum possible final distance from the origin, as a real value.\nYour output is considered correct when the relative or absolute error from the true answer is at most 10^{-10}.\n\nSample Input 1\n\n3\n0 10\n5 -5\n-5 -5\n\nSample Output 1\n\n10.000000000000000000000000000000000000000000000000\n\nThe final distance from the origin can be 10 if we use the engines in one of the following three ways:\n\nUse Engine 1 to move to (0, 10).\n\nUse Engine 2 to move to (5, -5), and then use Engine 3 to move to (0, -10).\n\nUse Engine 3 to move to (-5, -5), and then use Engine 2 to move to (0, -10).\n\nThe distance cannot be greater than 10, so the maximum possible distance is 10.\n\nSample Input 2\n\n5\n1 1\n1 0\n0 1\n-1 0\n0 -1\n\nSample Output 2\n\n2.828427124746190097603377448419396157139343750753\n\nThe maximum possible final distance is 2 \\sqrt{2} = 2.82842....\nOne of the ways to achieve it is:\n\nUse Engine 1 to move to (1, 1), and then use Engine 2 to move to (2, 1), and finally use Engine 3 to move to (2, 2).\n\nSample Input 3\n\n5\n1 1\n2 2\n3 3\n4 4\n5 5\n\nSample Output 3\n\n21.213203435596425732025330863145471178545078130654\n\nIf we use all the engines in the order 1 \\rightarrow 2 \\rightarrow 3 \\rightarrow 4 \\rightarrow 5, we will end up at (15, 15), with the distance 15 \\sqrt{2} = 21.2132... from the origin.\n\nSample Input 4\n\n3\n0 0\n0 1\n1 0\n\nSample Output 4\n\n1.414213562373095048801688724209698078569671875376\n\nThere can be useless engines with (x_i, y_i) = (0, 0).\n\nSample Input 5\n\n1\n90447 91000\n\nSample Output 5\n\n128303.000000000000000000000000000000000000000000000000\n\nNote that there can be only one engine.\n\nSample Input 6\n\n2\n96000 -72000\n-72000 54000\n\nSample Output 6\n\n120000.000000000000000000000000000000000000000000000000\n\nThere can be only two engines, too.\n\nSample Input 7\n\n10\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\n15 16\n17 18\n19 20\n\nSample Output 7\n\n148.660687473185055226120082139313966514489855137208", "sample_input": "3\n0 10\n5 -5\n-5 -5\n"}, "reference_outputs": ["10.000000000000000000000000000000000000000000000000\n"], "source_document_id": "p02926", "source_text": "Score: 600 points\n\nProblem Statement\n\nE869120 is initially standing at the origin (0, 0) in a two-dimensional plane.\n\nHe has N engines, which can be used as follows:\n\nWhen E869120 uses the i-th engine, his X- and Y-coordinate change by x_i and y_i, respectively. In other words, if E869120 uses the i-th engine from coordinates (X, Y), he will move to the coordinates (X + x_i, Y + y_i).\n\nE869120 can use these engines in any order, but each engine can be used at most once. He may also choose not to use some of the engines.\n\nHe wants to go as far as possible from the origin.\nLet (X, Y) be his final coordinates. Find the maximum possible value of \\sqrt{X^2 + Y^2}, the distance from the origin.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n-1 \\ 000 \\ 000 \\leq x_i \\leq 1 \\ 000 \\ 000\n\n-1 \\ 000 \\ 000 \\leq y_i \\leq 1 \\ 000 \\ 000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\nx_2 y_2\n: :\nx_N y_N\n\nOutput\n\nPrint the maximum possible final distance from the origin, as a real value.\nYour output is considered correct when the relative or absolute error from the true answer is at most 10^{-10}.\n\nSample Input 1\n\n3\n0 10\n5 -5\n-5 -5\n\nSample Output 1\n\n10.000000000000000000000000000000000000000000000000\n\nThe final distance from the origin can be 10 if we use the engines in one of the following three ways:\n\nUse Engine 1 to move to (0, 10).\n\nUse Engine 2 to move to (5, -5), and then use Engine 3 to move to (0, -10).\n\nUse Engine 3 to move to (-5, -5), and then use Engine 2 to move to (0, -10).\n\nThe distance cannot be greater than 10, so the maximum possible distance is 10.\n\nSample Input 2\n\n5\n1 1\n1 0\n0 1\n-1 0\n0 -1\n\nSample Output 2\n\n2.828427124746190097603377448419396157139343750753\n\nThe maximum possible final distance is 2 \\sqrt{2} = 2.82842....\nOne of the ways to achieve it is:\n\nUse Engine 1 to move to (1, 1), and then use Engine 2 to move to (2, 1), and finally use Engine 3 to move to (2, 2).\n\nSample Input 3\n\n5\n1 1\n2 2\n3 3\n4 4\n5 5\n\nSample Output 3\n\n21.213203435596425732025330863145471178545078130654\n\nIf we use all the engines in the order 1 \\rightarrow 2 \\rightarrow 3 \\rightarrow 4 \\rightarrow 5, we will end up at (15, 15), with the distance 15 \\sqrt{2} = 21.2132... from the origin.\n\nSample Input 4\n\n3\n0 0\n0 1\n1 0\n\nSample Output 4\n\n1.414213562373095048801688724209698078569671875376\n\nThere can be useless engines with (x_i, y_i) = (0, 0).\n\nSample Input 5\n\n1\n90447 91000\n\nSample Output 5\n\n128303.000000000000000000000000000000000000000000000000\n\nNote that there can be only one engine.\n\nSample Input 6\n\n2\n96000 -72000\n-72000 54000\n\nSample Output 6\n\n120000.000000000000000000000000000000000000000000000000\n\nThere can be only two engines, too.\n\nSample Input 7\n\n10\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\n15 16\n17 18\n19 20\n\nSample Output 7\n\n148.660687473185055226120082139313966514489855137208", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3736, "cpu_time_ms": 272, "memory_kb": 27104}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s023112164", "group_id": "codeNet:p02934", "input_text": "(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(setq *n* (read))\n(setq *ai* (mapcar #'parse-integer (split \" \" (read-line))))\n\n(defun my-denominator (n l)\n (if (equal (car l) nil)\n 0\n (+ (/ n (car l)) (my-denominator n (cdr l)))\n ))\n\n(defun my-numerator (l)\n (apply #'* l))\n\n;(print (my-numerator *ai*))\n;(print (my-denominator (my-numerator *ai*) *ai*))\n(print (float (/ (my-numerator *ai*) (my-denominator (my-numerator *ai*) *ai*))))\n", "language": "Lisp", "metadata": {"date": 1569544900, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02934.html", "problem_id": "p02934", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02934/input.txt", "sample_output_relpath": "derived/input_output/data/p02934/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02934/Lisp/s023112164.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s023112164", "user_id": "u358554431"}, "prompt_components": {"gold_output": "7.5\n", "input_to_evaluate": "(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(setq *n* (read))\n(setq *ai* (mapcar #'parse-integer (split \" \" (read-line))))\n\n(defun my-denominator (n l)\n (if (equal (car l) nil)\n 0\n (+ (/ n (car l)) (my-denominator n (cdr l)))\n ))\n\n(defun my-numerator (l)\n (apply #'* l))\n\n;(print (my-numerator *ai*))\n;(print (my-denominator (my-numerator *ai*) *ai*))\n(print (float (/ (my-numerator *ai*) (my-denominator (my-numerator *ai*) *ai*))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven is a sequence of N integers A_1, \\ldots, A_N.\n\nFind the (multiplicative) inverse of the sum of the inverses of these numbers, \\frac{1}{\\frac{1}{A_1} + \\ldots + \\frac{1}{A_N}}.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq A_i \\leq 1000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 \\ldots A_N\n\nOutput\n\nPrint a decimal number (or an integer) representing the value of \\frac{1}{\\frac{1}{A_1} + \\ldots + \\frac{1}{A_N}}.\n\nYour output will be judged correct when its absolute or relative error from the judge's output is at most 10^{-5}.\n\nSample Input 1\n\n2\n10 30\n\nSample Output 1\n\n7.5\n\n\\frac{1}{\\frac{1}{10} + \\frac{1}{30}} = \\frac{1}{\\frac{4}{30}} = \\frac{30}{4} = 7.5.\n\nPrinting 7.50001, 7.49999, and so on will also be accepted.\n\nSample Input 2\n\n3\n200 200 200\n\nSample Output 2\n\n66.66666666666667\n\n\\frac{1}{\\frac{1}{200} + \\frac{1}{200} + \\frac{1}{200}} = \\frac{1}{\\frac{3}{200}} = \\frac{200}{3} = 66.6666....\n\nPrinting 6.66666e+1 and so on will also be accepted.\n\nSample Input 3\n\n1\n1000\n\nSample Output 3\n\n1000\n\n\\frac{1}{\\frac{1}{1000}} = 1000.\n\nPrinting +1000.0 and so on will also be accepted.", "sample_input": "2\n10 30\n"}, "reference_outputs": ["7.5\n"], "source_document_id": "p02934", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven is a sequence of N integers A_1, \\ldots, A_N.\n\nFind the (multiplicative) inverse of the sum of the inverses of these numbers, \\frac{1}{\\frac{1}{A_1} + \\ldots + \\frac{1}{A_N}}.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq A_i \\leq 1000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 \\ldots A_N\n\nOutput\n\nPrint a decimal number (or an integer) representing the value of \\frac{1}{\\frac{1}{A_1} + \\ldots + \\frac{1}{A_N}}.\n\nYour output will be judged correct when its absolute or relative error from the judge's output is at most 10^{-5}.\n\nSample Input 1\n\n2\n10 30\n\nSample Output 1\n\n7.5\n\n\\frac{1}{\\frac{1}{10} + \\frac{1}{30}} = \\frac{1}{\\frac{4}{30}} = \\frac{30}{4} = 7.5.\n\nPrinting 7.50001, 7.49999, and so on will also be accepted.\n\nSample Input 2\n\n3\n200 200 200\n\nSample Output 2\n\n66.66666666666667\n\n\\frac{1}{\\frac{1}{200} + \\frac{1}{200} + \\frac{1}{200}} = \\frac{1}{\\frac{3}{200}} = \\frac{200}{3} = 66.6666....\n\nPrinting 6.66666e+1 and so on will also be accepted.\n\nSample Input 3\n\n1\n1000\n\nSample Output 3\n\n1000\n\n\\frac{1}{\\frac{1}{1000}} = 1000.\n\nPrinting +1000.0 and so on will also be accepted.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 591, "cpu_time_ms": 15, "memory_kb": 4328}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s803933386", "group_id": "codeNet:p02937", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((s (read-line))\n (target (read-line))\n (slen (length s))\n (table (make-array (list 26 slen) :element-type 'int32 :initial-element -1)))\n (declare (simple-string s target))\n (dotimes (i slen)\n (let ((c (- (char-code (aref s i)) 97)))\n (loop for j from i downto 0\n while (= (aref table c j) -1)\n do (setf (aref table c j) i))))\n (dbg table)\n (let ((spos 0)\n (count 1))\n (dotimes (i (length target))\n (let* ((c (- (char-code (aref target i)) 97))\n (next-pos (aref table c spos)))\n (dbg c next-pos)\n (when (= -1 next-pos)\n (setq next-pos (aref table c 0))\n (incf count)\n (when (= -1 next-pos)\n (println -1)\n (return-from main)))\n (setq spos (+ 1 next-pos))\n (when (= spos slen)\n (setq spos 0)\n (incf count))))\n (let ((res (+ spos (* slen (- count 1)))))\n (println res)))))\n\n#-swank (main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &key (target #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes TARGET, and returns true if the\nstring output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall target)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input;\nstring: run #'MAIN using the string as input;\nsymbol: alias of FIVEAM:RUN!;\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"contest\nson\n\"\n \"10\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"contest\nprogramming\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"contest\nsentence\n\"\n \"33\n\")))\n", "language": "Lisp", "metadata": {"date": 1566178793, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02937.html", "problem_id": "p02937", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02937/input.txt", "sample_output_relpath": "derived/input_output/data/p02937/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02937/Lisp/s803933386.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s803933386", "user_id": "u352600849"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((s (read-line))\n (target (read-line))\n (slen (length s))\n (table (make-array (list 26 slen) :element-type 'int32 :initial-element -1)))\n (declare (simple-string s target))\n (dotimes (i slen)\n (let ((c (- (char-code (aref s i)) 97)))\n (loop for j from i downto 0\n while (= (aref table c j) -1)\n do (setf (aref table c j) i))))\n (dbg table)\n (let ((spos 0)\n (count 1))\n (dotimes (i (length target))\n (let* ((c (- (char-code (aref target i)) 97))\n (next-pos (aref table c spos)))\n (dbg c next-pos)\n (when (= -1 next-pos)\n (setq next-pos (aref table c 0))\n (incf count)\n (when (= -1 next-pos)\n (println -1)\n (return-from main)))\n (setq spos (+ 1 next-pos))\n (when (= spos slen)\n (setq spos 0)\n (incf count))))\n (let ((res (+ spos (* slen (- count 1)))))\n (println res)))))\n\n#-swank (main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &key (target #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes TARGET, and returns true if the\nstring output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall target)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input;\nstring: run #'MAIN using the string as input;\nsymbol: alias of FIVEAM:RUN!;\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"contest\nson\n\"\n \"10\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"contest\nprogramming\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"contest\nsentence\n\"\n \"33\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nGiven are two strings s and t consisting of lowercase English letters. Determine if there exists an integer i satisfying the following condition, and find the minimum such i if it exists.\n\nLet s' be the concatenation of 10^{100} copies of s. t is a subsequence of the string {s'}_1{s'}_2\\ldots{s'}_i (the first i characters in s').\n\nNotes\n\nA subsequence of a string a is a string obtained by deleting zero or more characters from a and concatenating the remaining characters without changing the relative order. For example, the subsequences of contest include net, c, and contest.\n\nConstraints\n\n1 \\leq |s| \\leq 10^5\n\n1 \\leq |t| \\leq 10^5\n\ns and t consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\nt\n\nOutput\n\nIf there exists an integer i satisfying the following condition, print the minimum such i; otherwise, print -1.\n\nSample Input 1\n\ncontest\nson\n\nSample Output 1\n\n10\n\nt = son is a subsequence of the string contestcon (the first 10 characters in s' = contestcontestcontest...), so i = 10 satisfies the condition.\n\nOn the other hand, t is not a subsequence of the string contestco (the first 9 characters in s'), so i = 9 does not satisfy the condition.\n\nSimilarly, any integer less than 9 does not satisfy the condition, either. Thus, the minimum integer i satisfying the condition is 10.\n\nSample Input 2\n\ncontest\nprogramming\n\nSample Output 2\n\n-1\n\nt = programming is not a substring of s' = contestcontestcontest.... Thus, there is no integer i satisfying the condition.\n\nSample Input 3\n\ncontest\nsentence\n\nSample Output 3\n\n33\n\nNote that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.", "sample_input": "contest\nson\n"}, "reference_outputs": ["10\n"], "source_document_id": "p02937", "source_text": "Score : 500 points\n\nProblem Statement\n\nGiven are two strings s and t consisting of lowercase English letters. Determine if there exists an integer i satisfying the following condition, and find the minimum such i if it exists.\n\nLet s' be the concatenation of 10^{100} copies of s. t is a subsequence of the string {s'}_1{s'}_2\\ldots{s'}_i (the first i characters in s').\n\nNotes\n\nA subsequence of a string a is a string obtained by deleting zero or more characters from a and concatenating the remaining characters without changing the relative order. For example, the subsequences of contest include net, c, and contest.\n\nConstraints\n\n1 \\leq |s| \\leq 10^5\n\n1 \\leq |t| \\leq 10^5\n\ns and t consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\nt\n\nOutput\n\nIf there exists an integer i satisfying the following condition, print the minimum such i; otherwise, print -1.\n\nSample Input 1\n\ncontest\nson\n\nSample Output 1\n\n10\n\nt = son is a subsequence of the string contestcon (the first 10 characters in s' = contestcontestcontest...), so i = 10 satisfies the condition.\n\nOn the other hand, t is not a subsequence of the string contestco (the first 9 characters in s'), so i = 9 does not satisfy the condition.\n\nSimilarly, any integer less than 9 does not satisfy the condition, either. Thus, the minimum integer i satisfying the condition is 10.\n\nSample Input 2\n\ncontest\nprogramming\n\nSample Output 2\n\n-1\n\nt = programming is not a substring of s' = contestcontestcontest.... Thus, there is no integer i satisfying the condition.\n\nSample Input 3\n\ncontest\nsentence\n\nSample Output 3\n\n33\n\nNote that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4505, "cpu_time_ms": 193, "memory_kb": 23016}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s257273005", "group_id": "codeNet:p02938", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n(defun main ()\n (let* ((l (read))\n (r (read))\n (dp (make-array '(62 2 2 2) :element-type 'uint32 :initial-element 0)))\n (setf (aref dp 61 0 0 0) 1)\n (loop\n for i from 61 above 0\n for li = (ldb (byte 1 (- i 1)) l)\n for ri = (ldb (byte 1 (- i 1)) r)\n do (dotimes (x 2)\n (dotimes (y 2)\n (dotimes (z 2)\n (macrolet ((inc (new-x new-y new-z)\n `(incfmod (aref dp (- i 1) ,new-x ,new-y ,new-z)\n (aref dp i x y z))))\n (cond ((and (= x 0) (= y 0) (= z 0))\n (cond ((and (= li 0) (= ri 0))\n (inc 0 0 0))\n ((and (= li 0) (= ri 1))\n (inc 0 1 0)\n (inc 1 0 1))\n ((and (= li 1) (= ri 0)))\n ((and (= li 1) (= ri 1))\n (inc 0 0 1))))\n ((and (= x 0) (= y 0) (= z 1))\n (cond ((and (= li 0) (= ri 0))\n (inc 0 0 1))\n ((and (= li 0) (= ri 1))\n (inc 0 1 1)\n (inc 0 0 1)\n (inc 1 0 1))\n ((and (= li 1) (= ri 0)))\n ((and (= li 1) (= ri 1))\n (inc 0 0 1))))\n ((and (= x 0) (= y 1) (= z 0))\n (cond ((and (= li 0) (= ri 0))\n (inc 0 1 0)\n (inc 1 1 1))\n ((and (= li 0) (= ri 1))\n (inc 0 1 0)\n (inc 1 1 1))\n ((and (= li 1) (= ri 0))\n (inc 0 1 1))\n ((and (= li 1) (= ri 1))\n (inc 0 1 1))))\n ((and (= x 0) (= y 1) (= z 1))\n (cond ((and (= li 0) (= ri 0))\n (inc 0 1 1)\n (inc 0 1 1)\n (inc 1 1 1))\n ((and (= li 0) (= ri 1))\n (inc 0 1 1)\n (inc 0 1 1)\n (inc 1 1 1))\n ((and (= li 1) (= ri 0))\n (inc 0 1 1))\n ((and (= li 1) (= ri 1))\n (inc 0 1 1))))\n ((and (= x 1) (= y 0) (= z 0))\n (cond ((and (= li 0) (= ri 0))\n (inc 1 0 0))\n ((and (= li 0) (= ri 1))\n (inc 1 1 0)\n (inc 1 0 1))\n ((and (= li 1) (= ri 0))\n (inc 1 0 0))\n ((and (= li 1) (= ri 1))\n (inc 1 1 0)\n (inc 1 0 1))))\n ((and (= x 1) (= y 0) (= z 1))\n (cond ((and (= li 0) (= ri 0))\n (inc 1 0 1))\n ((and (= li 0) (= ri 1))\n (inc 1 1 1)\n (inc 1 0 1)\n (inc 1 0 1))\n ((and (= li 1) (= ri 0))\n (inc 1 0 1))\n ((and (= li 1) (= ri 1))\n (inc 1 1 1)\n (inc 1 0 1)\n (inc 1 0 1))))\n ((and (= x 1) (= y 1) (= z 0))\n (inc 1 1 0)\n (inc 1 1 1))\n ((and (= x 1) (= y 1) (= z 1))\n (inc 1 1 1)\n (inc 1 1 1)\n (inc 1 1 1))))))))\n (dbg dp)\n (println\n (mod+ (aref dp 0 0 0 0)\n (aref dp 0 0 0 1)\n (aref dp 0 0 1 0)\n (aref dp 0 0 1 1)\n (aref dp 0 1 0 0)\n (aref dp 0 1 0 1)\n (aref dp 0 1 1 0)\n (aref dp 0 1 1 1)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 3\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 100\n\"\n \"604\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 1000000000000000000\n\"\n \"68038601\n\")))\n", "language": "Lisp", "metadata": {"date": 1574750020, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02938.html", "problem_id": "p02938", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02938/input.txt", "sample_output_relpath": "derived/input_output/data/p02938/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02938/Lisp/s257273005.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s257273005", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n(defun main ()\n (let* ((l (read))\n (r (read))\n (dp (make-array '(62 2 2 2) :element-type 'uint32 :initial-element 0)))\n (setf (aref dp 61 0 0 0) 1)\n (loop\n for i from 61 above 0\n for li = (ldb (byte 1 (- i 1)) l)\n for ri = (ldb (byte 1 (- i 1)) r)\n do (dotimes (x 2)\n (dotimes (y 2)\n (dotimes (z 2)\n (macrolet ((inc (new-x new-y new-z)\n `(incfmod (aref dp (- i 1) ,new-x ,new-y ,new-z)\n (aref dp i x y z))))\n (cond ((and (= x 0) (= y 0) (= z 0))\n (cond ((and (= li 0) (= ri 0))\n (inc 0 0 0))\n ((and (= li 0) (= ri 1))\n (inc 0 1 0)\n (inc 1 0 1))\n ((and (= li 1) (= ri 0)))\n ((and (= li 1) (= ri 1))\n (inc 0 0 1))))\n ((and (= x 0) (= y 0) (= z 1))\n (cond ((and (= li 0) (= ri 0))\n (inc 0 0 1))\n ((and (= li 0) (= ri 1))\n (inc 0 1 1)\n (inc 0 0 1)\n (inc 1 0 1))\n ((and (= li 1) (= ri 0)))\n ((and (= li 1) (= ri 1))\n (inc 0 0 1))))\n ((and (= x 0) (= y 1) (= z 0))\n (cond ((and (= li 0) (= ri 0))\n (inc 0 1 0)\n (inc 1 1 1))\n ((and (= li 0) (= ri 1))\n (inc 0 1 0)\n (inc 1 1 1))\n ((and (= li 1) (= ri 0))\n (inc 0 1 1))\n ((and (= li 1) (= ri 1))\n (inc 0 1 1))))\n ((and (= x 0) (= y 1) (= z 1))\n (cond ((and (= li 0) (= ri 0))\n (inc 0 1 1)\n (inc 0 1 1)\n (inc 1 1 1))\n ((and (= li 0) (= ri 1))\n (inc 0 1 1)\n (inc 0 1 1)\n (inc 1 1 1))\n ((and (= li 1) (= ri 0))\n (inc 0 1 1))\n ((and (= li 1) (= ri 1))\n (inc 0 1 1))))\n ((and (= x 1) (= y 0) (= z 0))\n (cond ((and (= li 0) (= ri 0))\n (inc 1 0 0))\n ((and (= li 0) (= ri 1))\n (inc 1 1 0)\n (inc 1 0 1))\n ((and (= li 1) (= ri 0))\n (inc 1 0 0))\n ((and (= li 1) (= ri 1))\n (inc 1 1 0)\n (inc 1 0 1))))\n ((and (= x 1) (= y 0) (= z 1))\n (cond ((and (= li 0) (= ri 0))\n (inc 1 0 1))\n ((and (= li 0) (= ri 1))\n (inc 1 1 1)\n (inc 1 0 1)\n (inc 1 0 1))\n ((and (= li 1) (= ri 0))\n (inc 1 0 1))\n ((and (= li 1) (= ri 1))\n (inc 1 1 1)\n (inc 1 0 1)\n (inc 1 0 1))))\n ((and (= x 1) (= y 1) (= z 0))\n (inc 1 1 0)\n (inc 1 1 1))\n ((and (= x 1) (= y 1) (= z 1))\n (inc 1 1 1)\n (inc 1 1 1)\n (inc 1 1 1))))))))\n (dbg dp)\n (println\n (mod+ (aref dp 0 0 0 0)\n (aref dp 0 0 0 1)\n (aref dp 0 0 1 0)\n (aref dp 0 0 1 1)\n (aref dp 0 1 0 0)\n (aref dp 0 1 0 1)\n (aref dp 0 1 1 0)\n (aref dp 0 1 1 1)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 3\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 100\n\"\n \"604\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 1000000000000000000\n\"\n \"68038601\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven are integers L and R. Find the number, modulo 10^9 + 7, of pairs of integers (x, y) (L \\leq x \\leq y \\leq R) such that the remainder when y is divided by x is equal to y \\mbox{ XOR } x.\n\nWhat is \\mbox{ XOR }?\n\nThe XOR of integers A and B, A \\mbox{ XOR } B, is defined as follows:\n\nWhen A \\mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \\geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.\n\nFor example, 3 \\mbox{ XOR } 5 = 6. (In base two: 011 \\mbox{ XOR } 101 = 110.)\n\nConstraints\n\n1 \\leq L \\leq R \\leq 10^{18}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL R\n\nOutput\n\nPrint the number of pairs of integers (x, y) (L \\leq x \\leq y \\leq R) satisfying the condition, modulo 10^9 + 7.\n\nSample Input 1\n\n2 3\n\nSample Output 1\n\n3\n\nThree pairs satisfy the condition: (2, 2), (2, 3), and (3, 3).\n\nSample Input 2\n\n10 100\n\nSample Output 2\n\n604\n\nSample Input 3\n\n1 1000000000000000000\n\nSample Output 3\n\n68038601\n\nBe sure to compute the number modulo 10^9 + 7.", "sample_input": "2 3\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02938", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are integers L and R. Find the number, modulo 10^9 + 7, of pairs of integers (x, y) (L \\leq x \\leq y \\leq R) such that the remainder when y is divided by x is equal to y \\mbox{ XOR } x.\n\nWhat is \\mbox{ XOR }?\n\nThe XOR of integers A and B, A \\mbox{ XOR } B, is defined as follows:\n\nWhen A \\mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \\geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.\n\nFor example, 3 \\mbox{ XOR } 5 = 6. (In base two: 011 \\mbox{ XOR } 101 = 110.)\n\nConstraints\n\n1 \\leq L \\leq R \\leq 10^{18}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL R\n\nOutput\n\nPrint the number of pairs of integers (x, y) (L \\leq x \\leq y \\leq R) satisfying the condition, modulo 10^9 + 7.\n\nSample Input 1\n\n2 3\n\nSample Output 1\n\n3\n\nThree pairs satisfy the condition: (2, 2), (2, 3), and (3, 3).\n\nSample Input 2\n\n10 100\n\nSample Output 2\n\n604\n\nSample Input 3\n\n1 1000000000000000000\n\nSample Output 3\n\n68038601\n\nBe sure to compute the number modulo 10^9 + 7.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8921, "cpu_time_ms": 619, "memory_kb": 68072}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s908836774", "group_id": "codeNet:p02938", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n(defun main ()\n (let* ((l (read))\n (r (read))\n (dp (make-array '(62 2 2 2) :element-type 'uint32 :initial-element 0)))\n (setf (aref dp 61 0 0 0) 1)\n (loop\n for i from 61 above 0\n for li = (ldb (byte 1 (- i 1)) l)\n for ri = (ldb (byte 1 (- i 1)) r)\n do (dotimes (x 2)\n (dotimes (y 2)\n (dotimes (z 2)\n (macrolet ((inc (new-x new-y new-z)\n `(incfmod (aref dp (- i 1) ,new-x ,new-y ,new-z)\n (aref dp i x y z))))\n (cond ((and (= x 0) (= y 0) (= z 0))\n (cond ((and (= li 0) (= ri 0))\n (inc 0 0 0))\n ((and (= li 0) (= ri 1))\n (inc 0 1 0)\n (inc 1 0 1))\n ((and (= li 1) (= ri 0)))\n ((and (= li 1) (= ri 1))\n (inc 0 0 1))))\n ((and (= x 0) (= y 0) (= z 1))\n (cond ((and (= li 0) (= ri 0))\n (inc 0 0 1))\n ((and (= li 0) (= ri 1))\n (inc 0 1 1)\n (inc 0 0 1)\n (inc 1 0 1))\n ((and (= li 1) (= ri 0)))\n ((and (= li 1) (= ri 1))\n (inc 0 0 1))))\n ((and (= x 0) (= y 1) (= z 0))\n (cond ((and (= li 0) (= ri 0))\n (inc 0 1 0)\n (inc 1 1 1))\n ((and (= li 0) (= ri 1))\n (inc 0 1 0)\n (inc 1 1 1))\n ((and (= li 1) (= ri 0))\n (inc 0 1 1))\n ((and (= li 1) (= ri 1))\n (inc 0 1 1))))\n ((and (= x 0) (= y 1) (= z 1))\n (cond ((and (= li 0) (= ri 0))\n (inc 0 1 1)\n (inc 0 1 1)\n (inc 1 1 1))\n ((and (= li 0) (= ri 1))\n (inc 0 1 1)\n (inc 0 1 1)\n (inc 1 1 1))\n ((and (= li 1) (= ri 0))\n (inc 1 1 1))\n ((and (= li 1) (= ri 1))\n (inc 0 1 1))))\n ((and (= x 1) (= y 0) (= z 0))\n (cond ((and (= li 0) (= ri 0))\n (inc 1 0 0))\n ((and (= li 0) (= ri 1))\n (inc 1 1 0)\n (inc 1 0 1))\n ((and (= li 1) (= ri 0))\n (inc 1 0 0))\n ((and (= li 1) (= ri 1))\n (inc 1 1 0)\n (inc 1 0 1))))\n ((and (= x 1) (= y 0) (= z 1))\n (cond ((and (= li 0) (= ri 0))\n (inc 1 0 1))\n ((and (= li 0) (= ri 1))\n (inc 1 1 1)\n (inc 1 0 1)\n (inc 1 0 1))\n ((and (= li 1) (= ri 0))\n (inc 1 0 1))\n ((and (= li 1) (= ri 1))\n (inc 1 1 1)\n (inc 1 0 1)\n (inc 1 0 1))))\n ((and (= x 1) (= y 1) (= z 0))\n (inc 1 1 0)\n (inc 1 1 1))\n ((and (= x 1) (= y 1) (= z 1))\n (inc 1 1 1)\n (inc 1 1 1)\n (inc 1 1 1))))))))\n (dbg dp)\n (println\n (mod+ (aref dp 0 0 0 0)\n (aref dp 0 0 0 1)\n (aref dp 0 0 1 0)\n (aref dp 0 0 1 1)\n (aref dp 0 1 0 0)\n (aref dp 0 1 0 1)\n (aref dp 0 1 1 0)\n (aref dp 0 1 1 1)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 3\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 100\n\"\n \"604\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 1000000000000000000\n\"\n \"68038601\n\")))\n", "language": "Lisp", "metadata": {"date": 1574749868, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02938.html", "problem_id": "p02938", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02938/input.txt", "sample_output_relpath": "derived/input_output/data/p02938/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02938/Lisp/s908836774.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s908836774", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n(defun main ()\n (let* ((l (read))\n (r (read))\n (dp (make-array '(62 2 2 2) :element-type 'uint32 :initial-element 0)))\n (setf (aref dp 61 0 0 0) 1)\n (loop\n for i from 61 above 0\n for li = (ldb (byte 1 (- i 1)) l)\n for ri = (ldb (byte 1 (- i 1)) r)\n do (dotimes (x 2)\n (dotimes (y 2)\n (dotimes (z 2)\n (macrolet ((inc (new-x new-y new-z)\n `(incfmod (aref dp (- i 1) ,new-x ,new-y ,new-z)\n (aref dp i x y z))))\n (cond ((and (= x 0) (= y 0) (= z 0))\n (cond ((and (= li 0) (= ri 0))\n (inc 0 0 0))\n ((and (= li 0) (= ri 1))\n (inc 0 1 0)\n (inc 1 0 1))\n ((and (= li 1) (= ri 0)))\n ((and (= li 1) (= ri 1))\n (inc 0 0 1))))\n ((and (= x 0) (= y 0) (= z 1))\n (cond ((and (= li 0) (= ri 0))\n (inc 0 0 1))\n ((and (= li 0) (= ri 1))\n (inc 0 1 1)\n (inc 0 0 1)\n (inc 1 0 1))\n ((and (= li 1) (= ri 0)))\n ((and (= li 1) (= ri 1))\n (inc 0 0 1))))\n ((and (= x 0) (= y 1) (= z 0))\n (cond ((and (= li 0) (= ri 0))\n (inc 0 1 0)\n (inc 1 1 1))\n ((and (= li 0) (= ri 1))\n (inc 0 1 0)\n (inc 1 1 1))\n ((and (= li 1) (= ri 0))\n (inc 0 1 1))\n ((and (= li 1) (= ri 1))\n (inc 0 1 1))))\n ((and (= x 0) (= y 1) (= z 1))\n (cond ((and (= li 0) (= ri 0))\n (inc 0 1 1)\n (inc 0 1 1)\n (inc 1 1 1))\n ((and (= li 0) (= ri 1))\n (inc 0 1 1)\n (inc 0 1 1)\n (inc 1 1 1))\n ((and (= li 1) (= ri 0))\n (inc 1 1 1))\n ((and (= li 1) (= ri 1))\n (inc 0 1 1))))\n ((and (= x 1) (= y 0) (= z 0))\n (cond ((and (= li 0) (= ri 0))\n (inc 1 0 0))\n ((and (= li 0) (= ri 1))\n (inc 1 1 0)\n (inc 1 0 1))\n ((and (= li 1) (= ri 0))\n (inc 1 0 0))\n ((and (= li 1) (= ri 1))\n (inc 1 1 0)\n (inc 1 0 1))))\n ((and (= x 1) (= y 0) (= z 1))\n (cond ((and (= li 0) (= ri 0))\n (inc 1 0 1))\n ((and (= li 0) (= ri 1))\n (inc 1 1 1)\n (inc 1 0 1)\n (inc 1 0 1))\n ((and (= li 1) (= ri 0))\n (inc 1 0 1))\n ((and (= li 1) (= ri 1))\n (inc 1 1 1)\n (inc 1 0 1)\n (inc 1 0 1))))\n ((and (= x 1) (= y 1) (= z 0))\n (inc 1 1 0)\n (inc 1 1 1))\n ((and (= x 1) (= y 1) (= z 1))\n (inc 1 1 1)\n (inc 1 1 1)\n (inc 1 1 1))))))))\n (dbg dp)\n (println\n (mod+ (aref dp 0 0 0 0)\n (aref dp 0 0 0 1)\n (aref dp 0 0 1 0)\n (aref dp 0 0 1 1)\n (aref dp 0 1 0 0)\n (aref dp 0 1 0 1)\n (aref dp 0 1 1 0)\n (aref dp 0 1 1 1)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 3\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 100\n\"\n \"604\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 1000000000000000000\n\"\n \"68038601\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven are integers L and R. Find the number, modulo 10^9 + 7, of pairs of integers (x, y) (L \\leq x \\leq y \\leq R) such that the remainder when y is divided by x is equal to y \\mbox{ XOR } x.\n\nWhat is \\mbox{ XOR }?\n\nThe XOR of integers A and B, A \\mbox{ XOR } B, is defined as follows:\n\nWhen A \\mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \\geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.\n\nFor example, 3 \\mbox{ XOR } 5 = 6. (In base two: 011 \\mbox{ XOR } 101 = 110.)\n\nConstraints\n\n1 \\leq L \\leq R \\leq 10^{18}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL R\n\nOutput\n\nPrint the number of pairs of integers (x, y) (L \\leq x \\leq y \\leq R) satisfying the condition, modulo 10^9 + 7.\n\nSample Input 1\n\n2 3\n\nSample Output 1\n\n3\n\nThree pairs satisfy the condition: (2, 2), (2, 3), and (3, 3).\n\nSample Input 2\n\n10 100\n\nSample Output 2\n\n604\n\nSample Input 3\n\n1 1000000000000000000\n\nSample Output 3\n\n68038601\n\nBe sure to compute the number modulo 10^9 + 7.", "sample_input": "2 3\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02938", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are integers L and R. Find the number, modulo 10^9 + 7, of pairs of integers (x, y) (L \\leq x \\leq y \\leq R) such that the remainder when y is divided by x is equal to y \\mbox{ XOR } x.\n\nWhat is \\mbox{ XOR }?\n\nThe XOR of integers A and B, A \\mbox{ XOR } B, is defined as follows:\n\nWhen A \\mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \\geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.\n\nFor example, 3 \\mbox{ XOR } 5 = 6. (In base two: 011 \\mbox{ XOR } 101 = 110.)\n\nConstraints\n\n1 \\leq L \\leq R \\leq 10^{18}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL R\n\nOutput\n\nPrint the number of pairs of integers (x, y) (L \\leq x \\leq y \\leq R) satisfying the condition, modulo 10^9 + 7.\n\nSample Input 1\n\n2 3\n\nSample Output 1\n\n3\n\nThree pairs satisfy the condition: (2, 2), (2, 3), and (3, 3).\n\nSample Input 2\n\n10 100\n\nSample Output 2\n\n604\n\nSample Input 3\n\n1 1000000000000000000\n\nSample Output 3\n\n68038601\n\nBe sure to compute the number modulo 10^9 + 7.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8921, "cpu_time_ms": 769, "memory_kb": 79972}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s630918348", "group_id": "codeNet:p02942", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun solve (n m as)\n (declare #.opt\n ((simple-array uint31 (100 100)) as)\n (uint8 n m))\n (let ((counts (make-array '(100 100) :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (dotimes (j m)\n (let ((a (aref as i j)))\n (incf (aref counts j (floor a m))))))\n (let ((score 0))\n (declare (uint31 score))\n (dotimes (i m)\n (dotimes (j n)\n (incf score (abs (- (aref counts i j) 1)))))\n (loop (when (zerop score)\n (return as))\n (let* ((y (random n))\n (x1 (random m))\n (x2 (random m))\n (a1 (floor (aref as y x1) m))\n (a2 (floor (aref as y x2) m))\n (delta (+ (if (= 0 (aref counts x1 a2)) -1 1)\n (if (= 1 (aref counts x1 a1)) 1 -1)\n (if (= 0 (aref counts x2 a1)) -1 1)\n (if (= 1 (aref counts x2 a2)) 1 -1))))\n (when (<= delta 0)\n (incf score delta)\n (incf (aref counts x1 a2))\n (incf (aref counts x2 a1))\n (decf (aref counts x1 a1))\n (decf (aref counts x2 a2))\n (rotatef (aref as y x1) (aref as y x2))))))))\n\n(defconstant +nan+ #x7fffffff)\n(defun main ()\n (declare #.opt)\n (let* ((n (read))\n (m (read))\n (as (make-array '(100 100) :element-type 'uint31 :initial-element 0)))\n (declare (uint8 n m)\n ((simple-array uint31 (* *)) as))\n (dotimes (i n)\n (dotimes (j m)\n (setf (aref as i j) (- (read-fixnum) 1))))\n (solve n m as)\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (i n)\n (let ((init t))\n (dotimes (j m (terpri))\n (if init\n (setq init nil)\n (write-char #\\ ))\n (princ (aref as i j)))))\n (dotimes (j m)\n (dotimes (i1 n)\n (loop for i2 from (+ i1 1) below n\n when (> (aref as i1 j) (aref as i2 j))\n do (rotatef (aref as i1 j) (aref as i2 j)))))\n (dotimes (i n)\n (let ((init t))\n (dotimes (j m (terpri))\n (if init\n (setq init nil)\n (write-char #\\ ))\n (princ (aref as i j)))))))))\n\n(defun test (n m sample)\n (dotimes (_ sample)\n (let ((as (make-array (list n m) :element-type 'uint31 :initial-element 0)))\n (dotimes (i (* n m))\n (setf (aref (array-storage-vector as) i) i))\n (shuffle! (array-storage-vector as))\n (solve as))))\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"2 6 \n4 3 \n5 1 \n2 1 \n4 3 \n5 6\n\"\n (run \"3 2\n2 6\n4 3\n1 5\n\" nil)))\n (it.bese.fiveam:is\n (equal \"1 4 7 10 \n5 8 11 2 \n9 12 3 6 \n1 4 3 2 \n5 8 7 6 \n9 12 11 10\n\"\n (run \"3 4\n1 4 7 10\n2 5 8 11\n3 6 9 12\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1596619415, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02942.html", "problem_id": "p02942", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02942/input.txt", "sample_output_relpath": "derived/input_output/data/p02942/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02942/Lisp/s630918348.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s630918348", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2 6\n4 3\n5 1\n2 1\n4 3\n5 6\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun solve (n m as)\n (declare #.opt\n ((simple-array uint31 (100 100)) as)\n (uint8 n m))\n (let ((counts (make-array '(100 100) :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (dotimes (j m)\n (let ((a (aref as i j)))\n (incf (aref counts j (floor a m))))))\n (let ((score 0))\n (declare (uint31 score))\n (dotimes (i m)\n (dotimes (j n)\n (incf score (abs (- (aref counts i j) 1)))))\n (loop (when (zerop score)\n (return as))\n (let* ((y (random n))\n (x1 (random m))\n (x2 (random m))\n (a1 (floor (aref as y x1) m))\n (a2 (floor (aref as y x2) m))\n (delta (+ (if (= 0 (aref counts x1 a2)) -1 1)\n (if (= 1 (aref counts x1 a1)) 1 -1)\n (if (= 0 (aref counts x2 a1)) -1 1)\n (if (= 1 (aref counts x2 a2)) 1 -1))))\n (when (<= delta 0)\n (incf score delta)\n (incf (aref counts x1 a2))\n (incf (aref counts x2 a1))\n (decf (aref counts x1 a1))\n (decf (aref counts x2 a2))\n (rotatef (aref as y x1) (aref as y x2))))))))\n\n(defconstant +nan+ #x7fffffff)\n(defun main ()\n (declare #.opt)\n (let* ((n (read))\n (m (read))\n (as (make-array '(100 100) :element-type 'uint31 :initial-element 0)))\n (declare (uint8 n m)\n ((simple-array uint31 (* *)) as))\n (dotimes (i n)\n (dotimes (j m)\n (setf (aref as i j) (- (read-fixnum) 1))))\n (solve n m as)\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (i n)\n (let ((init t))\n (dotimes (j m (terpri))\n (if init\n (setq init nil)\n (write-char #\\ ))\n (princ (aref as i j)))))\n (dotimes (j m)\n (dotimes (i1 n)\n (loop for i2 from (+ i1 1) below n\n when (> (aref as i1 j) (aref as i2 j))\n do (rotatef (aref as i1 j) (aref as i2 j)))))\n (dotimes (i n)\n (let ((init t))\n (dotimes (j m (terpri))\n (if init\n (setq init nil)\n (write-char #\\ ))\n (princ (aref as i j)))))))))\n\n(defun test (n m sample)\n (dotimes (_ sample)\n (let ((as (make-array (list n m) :element-type 'uint31 :initial-element 0)))\n (dotimes (i (* n m))\n (setf (aref (array-storage-vector as) i) i))\n (shuffle! (array-storage-vector as))\n (solve as))))\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"2 6 \n4 3 \n5 1 \n2 1 \n4 3 \n5 6\n\"\n (run \"3 2\n2 6\n4 3\n1 5\n\" nil)))\n (it.bese.fiveam:is\n (equal \"1 4 7 10 \n5 8 11 2 \n9 12 3 6 \n1 4 3 2 \n5 8 7 6 \n9 12 11 10\n\"\n (run \"3 4\n1 4 7 10\n2 5 8 11\n3 6 9 12\n\" nil))))\n", "problem_context": "Score : 1100 points\n\nProblem Statement\n\nWe have a grid with N rows and M columns of squares.\nEach integer from 1 to NM is written in this grid once.\nThe number written in the square at the i-th row from the top and the j-th column from the left is A_{ij}.\n\nYou need to rearrange these numbers as follows:\n\nFirst, for each of the N rows, rearrange the numbers written in it as you like.\n\nSecond, for each of the M columns, rearrange the numbers written in it as you like.\n\nFinally, for each of the N rows, rearrange the numbers written in it as you like.\n\nAfter rearranging the numbers, you want the number written in the square at the i-th row from the top and the j-th column from the left to be M\\times (i-1)+j.\nConstruct one such way to rearrange the numbers. The constraints guarantee that it is always possible to achieve the objective.\n\nConstraints\n\n1 \\leq N,M \\leq 100\n\n1 \\leq A_{ij} \\leq NM\n\nA_{ij} are distinct.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_{11} A_{12} ... A_{1M}\n:\nA_{N1} A_{N2} ... A_{NM}\n\nOutput\n\nPrint one way to rearrange the numbers in the following format:\n\nB_{11} B_{12} ... B_{1M}\n:\nB_{N1} B_{N2} ... B_{NM}\nC_{11} C_{12} ... C_{1M}\n:\nC_{N1} C_{N2} ... C_{NM}\n\nHere B_{ij} is the number written in the square at the i-th row from the top and the j-th column from the left after Step 1, and C_{ij} is the number written in that square after Step 2.\n\nSample Input 1\n\n3 2\n2 6\n4 3\n1 5\n\nSample Output 1\n\n2 6\n4 3\n5 1\n2 1\n4 3\n5 6\n\nSample Input 2\n\n3 4\n1 4 7 10\n2 5 8 11\n3 6 9 12\n\nSample Output 2\n\n1 4 7 10\n5 8 11 2\n9 12 3 6\n1 4 3 2\n5 8 7 6\n9 12 11 10", "sample_input": "3 2\n2 6\n4 3\n1 5\n"}, "reference_outputs": ["2 6\n4 3\n5 1\n2 1\n4 3\n5 6\n"], "source_document_id": "p02942", "source_text": "Score : 1100 points\n\nProblem Statement\n\nWe have a grid with N rows and M columns of squares.\nEach integer from 1 to NM is written in this grid once.\nThe number written in the square at the i-th row from the top and the j-th column from the left is A_{ij}.\n\nYou need to rearrange these numbers as follows:\n\nFirst, for each of the N rows, rearrange the numbers written in it as you like.\n\nSecond, for each of the M columns, rearrange the numbers written in it as you like.\n\nFinally, for each of the N rows, rearrange the numbers written in it as you like.\n\nAfter rearranging the numbers, you want the number written in the square at the i-th row from the top and the j-th column from the left to be M\\times (i-1)+j.\nConstruct one such way to rearrange the numbers. The constraints guarantee that it is always possible to achieve the objective.\n\nConstraints\n\n1 \\leq N,M \\leq 100\n\n1 \\leq A_{ij} \\leq NM\n\nA_{ij} are distinct.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_{11} A_{12} ... A_{1M}\n:\nA_{N1} A_{N2} ... A_{NM}\n\nOutput\n\nPrint one way to rearrange the numbers in the following format:\n\nB_{11} B_{12} ... B_{1M}\n:\nB_{N1} B_{N2} ... B_{NM}\nC_{11} C_{12} ... C_{1M}\n:\nC_{N1} C_{N2} ... C_{NM}\n\nHere B_{ij} is the number written in the square at the i-th row from the top and the j-th column from the left after Step 1, and C_{ij} is the number written in that square after Step 2.\n\nSample Input 1\n\n3 2\n2 6\n4 3\n1 5\n\nSample Output 1\n\n2 6\n4 3\n5 1\n2 1\n4 3\n5 6\n\nSample Input 2\n\n3 4\n1 4 7 10\n2 5 8 11\n3 6 9 12\n\nSample Output 2\n\n1 4 7 10\n5 8 11 2\n9 12 3 6\n1 4 3 2\n5 8 7 6\n9 12 11 10", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6996, "cpu_time_ms": 2206, "memory_kb": 25360}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s968107197", "group_id": "codeNet:p02945", "input_text": "(let ((a (read))\n (b (read)))\n (format t \"~A~%\" (max (+ a b) (- a b) (* a b))))\n", "language": "Lisp", "metadata": {"date": 1598138474, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02945.html", "problem_id": "p02945", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02945/input.txt", "sample_output_relpath": "derived/input_output/data/p02945/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02945/Lisp/s968107197.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s968107197", "user_id": "u608227593"}, "prompt_components": {"gold_output": "-10\n", "input_to_evaluate": "(let ((a (read))\n (b (read)))\n (format t \"~A~%\" (max (+ a b) (- a b) (* a b))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe have two integers: A and B.\n\nPrint the largest number among A + B, A - B, and A \\times B.\n\nConstraints\n\nAll values in input are integers.\n\n-100 \\leq A,\\ B \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the largest number among A + B, A - B, and A \\times B.\n\nSample Input 1\n\n-13 3\n\nSample Output 1\n\n-10\n\nThe largest number among A + B = -10, A - B = -16, and A \\times B = -39 is -10.\n\nSample Input 2\n\n1 -33\n\nSample Output 2\n\n34\n\nThe largest number among A + B = -32, A - B = 34, and A \\times B = -33 is 34.\n\nSample Input 3\n\n13 3\n\nSample Output 3\n\n39\n\nThe largest number among A + B = 16, A - B = 10, and A \\times B = 39 is 39.", "sample_input": "-13 3\n"}, "reference_outputs": ["-10\n"], "source_document_id": "p02945", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe have two integers: A and B.\n\nPrint the largest number among A + B, A - B, and A \\times B.\n\nConstraints\n\nAll values in input are integers.\n\n-100 \\leq A,\\ B \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the largest number among A + B, A - B, and A \\times B.\n\nSample Input 1\n\n-13 3\n\nSample Output 1\n\n-10\n\nThe largest number among A + B = -10, A - B = -16, and A \\times B = -39 is -10.\n\nSample Input 2\n\n1 -33\n\nSample Output 2\n\n34\n\nThe largest number among A + B = -32, A - B = 34, and A \\times B = -33 is 34.\n\nSample Input 3\n\n13 3\n\nSample Output 3\n\n39\n\nThe largest number among A + B = 16, A - B = 10, and A \\times B = 39 is 39.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 86, "cpu_time_ms": 19, "memory_kb": 24032}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s972731347", "group_id": "codeNet:p02945", "input_text": "(let* ((a (read)) (b (read))) (princ (max (+ a b) (- a b) (* a b))))", "language": "Lisp", "metadata": {"date": 1565585390, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02945.html", "problem_id": "p02945", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02945/input.txt", "sample_output_relpath": "derived/input_output/data/p02945/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02945/Lisp/s972731347.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s972731347", "user_id": "u610490393"}, "prompt_components": {"gold_output": "-10\n", "input_to_evaluate": "(let* ((a (read)) (b (read))) (princ (max (+ a b) (- a b) (* a b))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe have two integers: A and B.\n\nPrint the largest number among A + B, A - B, and A \\times B.\n\nConstraints\n\nAll values in input are integers.\n\n-100 \\leq A,\\ B \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the largest number among A + B, A - B, and A \\times B.\n\nSample Input 1\n\n-13 3\n\nSample Output 1\n\n-10\n\nThe largest number among A + B = -10, A - B = -16, and A \\times B = -39 is -10.\n\nSample Input 2\n\n1 -33\n\nSample Output 2\n\n34\n\nThe largest number among A + B = -32, A - B = 34, and A \\times B = -33 is 34.\n\nSample Input 3\n\n13 3\n\nSample Output 3\n\n39\n\nThe largest number among A + B = 16, A - B = 10, and A \\times B = 39 is 39.", "sample_input": "-13 3\n"}, "reference_outputs": ["-10\n"], "source_document_id": "p02945", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe have two integers: A and B.\n\nPrint the largest number among A + B, A - B, and A \\times B.\n\nConstraints\n\nAll values in input are integers.\n\n-100 \\leq A,\\ B \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the largest number among A + B, A - B, and A \\times B.\n\nSample Input 1\n\n-13 3\n\nSample Output 1\n\n-10\n\nThe largest number among A + B = -10, A - B = -16, and A \\times B = -39 is -10.\n\nSample Input 2\n\n1 -33\n\nSample Output 2\n\n34\n\nThe largest number among A + B = -32, A - B = 34, and A \\times B = -33 is 34.\n\nSample Input 3\n\n13 3\n\nSample Output 3\n\n39\n\nThe largest number among A + B = 16, A - B = 10, and A \\times B = 39 is 39.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 68, "cpu_time_ms": 118, "memory_kb": 11616}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s747088566", "group_id": "codeNet:p02946", "input_text": "(let ((k (read))\n (x (read)))\n (loop :for i :from (max -1000000 (- x k -1)) :to (min 1000000 (+ x k -1))\n :do (format t \"~A \" i))\n (format t \"~%\"))\n", "language": "Lisp", "metadata": {"date": 1598138705, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02946.html", "problem_id": "p02946", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02946/input.txt", "sample_output_relpath": "derived/input_output/data/p02946/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02946/Lisp/s747088566.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s747088566", "user_id": "u608227593"}, "prompt_components": {"gold_output": "5 6 7 8 9\n", "input_to_evaluate": "(let ((k (read))\n (x (read)))\n (loop :for i :from (max -1000000 (- x k -1)) :to (min 1000000 (+ x k -1))\n :do (format t \"~A \" i))\n (format t \"~%\"))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \\ldots, 999999, 1000000.\n\nAmong them, some K consecutive stones are painted black, and the others are painted white.\n\nAdditionally, we know that the stone at coordinate X is painted black.\n\nPrint all coordinates that potentially contain a stone painted black, in ascending order.\n\nConstraints\n\n1 \\leq K \\leq 100\n\n0 \\leq X \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK X\n\nOutput\n\nPrint all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.\n\nSample Input 1\n\n3 7\n\nSample Output 1\n\n5 6 7 8 9\n\nWe know that there are three stones painted black, and the stone at coordinate 7 is painted black. There are three possible cases:\n\nThe three stones painted black are placed at coordinates 5, 6, and 7.\n\nThe three stones painted black are placed at coordinates 6, 7, and 8.\n\nThe three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8, and 9.\n\nSample Input 2\n\n4 0\n\nSample Output 2\n\n-3 -2 -1 0 1 2 3\n\nNegative coordinates can also contain a stone painted black.\n\nSample Input 3\n\n1 100\n\nSample Output 3\n\n100", "sample_input": "3 7\n"}, "reference_outputs": ["5 6 7 8 9\n"], "source_document_id": "p02946", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \\ldots, 999999, 1000000.\n\nAmong them, some K consecutive stones are painted black, and the others are painted white.\n\nAdditionally, we know that the stone at coordinate X is painted black.\n\nPrint all coordinates that potentially contain a stone painted black, in ascending order.\n\nConstraints\n\n1 \\leq K \\leq 100\n\n0 \\leq X \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK X\n\nOutput\n\nPrint all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.\n\nSample Input 1\n\n3 7\n\nSample Output 1\n\n5 6 7 8 9\n\nWe know that there are three stones painted black, and the stone at coordinate 7 is painted black. There are three possible cases:\n\nThe three stones painted black are placed at coordinates 5, 6, and 7.\n\nThe three stones painted black are placed at coordinates 6, 7, and 8.\n\nThe three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8, and 9.\n\nSample Input 2\n\n4 0\n\nSample Output 2\n\n-3 -2 -1 0 1 2 3\n\nNegative coordinates can also contain a stone painted black.\n\nSample Input 3\n\n1 100\n\nSample Output 3\n\n100", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 162, "cpu_time_ms": 18, "memory_kb": 24412}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s683363612", "group_id": "codeNet:p02946", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((k (read))\n (x (read)))\n (loop with init = t\n for i from (+ 1 (- x k)) below (+ x k)\n do (if init (setq init nil) (write-char #\\ ))\n (princ i))\n (terpri)))\n\n#-swank (main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &key (target #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes TARGET, and returns true if the\nstring output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall target)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input;\nstring: run #'MAIN using the string as input;\nsymbol: alias of FIVEAM:RUN!;\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n", "language": "Lisp", "metadata": {"date": 1565485460, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02946.html", "problem_id": "p02946", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02946/input.txt", "sample_output_relpath": "derived/input_output/data/p02946/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02946/Lisp/s683363612.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s683363612", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5 6 7 8 9\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((k (read))\n (x (read)))\n (loop with init = t\n for i from (+ 1 (- x k)) below (+ x k)\n do (if init (setq init nil) (write-char #\\ ))\n (princ i))\n (terpri)))\n\n#-swank (main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &key (target #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes TARGET, and returns true if the\nstring output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall target)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input;\nstring: run #'MAIN using the string as input;\nsymbol: alias of FIVEAM:RUN!;\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \\ldots, 999999, 1000000.\n\nAmong them, some K consecutive stones are painted black, and the others are painted white.\n\nAdditionally, we know that the stone at coordinate X is painted black.\n\nPrint all coordinates that potentially contain a stone painted black, in ascending order.\n\nConstraints\n\n1 \\leq K \\leq 100\n\n0 \\leq X \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK X\n\nOutput\n\nPrint all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.\n\nSample Input 1\n\n3 7\n\nSample Output 1\n\n5 6 7 8 9\n\nWe know that there are three stones painted black, and the stone at coordinate 7 is painted black. There are three possible cases:\n\nThe three stones painted black are placed at coordinates 5, 6, and 7.\n\nThe three stones painted black are placed at coordinates 6, 7, and 8.\n\nThe three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8, and 9.\n\nSample Input 2\n\n4 0\n\nSample Output 2\n\n-3 -2 -1 0 1 2 3\n\nNegative coordinates can also contain a stone painted black.\n\nSample Input 3\n\n1 100\n\nSample Output 3\n\n100", "sample_input": "3 7\n"}, "reference_outputs": ["5 6 7 8 9\n"], "source_document_id": "p02946", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \\ldots, 999999, 1000000.\n\nAmong them, some K consecutive stones are painted black, and the others are painted white.\n\nAdditionally, we know that the stone at coordinate X is painted black.\n\nPrint all coordinates that potentially contain a stone painted black, in ascending order.\n\nConstraints\n\n1 \\leq K \\leq 100\n\n0 \\leq X \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK X\n\nOutput\n\nPrint all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.\n\nSample Input 1\n\n3 7\n\nSample Output 1\n\n5 6 7 8 9\n\nWe know that there are three stones painted black, and the stone at coordinate 7 is painted black. There are three possible cases:\n\nThe three stones painted black are placed at coordinates 5, 6, and 7.\n\nThe three stones painted black are placed at coordinates 6, 7, and 8.\n\nThe three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8, and 9.\n\nSample Input 2\n\n4 0\n\nSample Output 2\n\n-3 -2 -1 0 1 2 3\n\nNegative coordinates can also contain a stone painted black.\n\nSample Input 3\n\n1 100\n\nSample Output 3\n\n100", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3379, "cpu_time_ms": 24, "memory_kb": 6504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s533763564", "group_id": "codeNet:p02947", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline read-line-into))\n(defun read-line-into (buffer-string &key (in *standard-input*) (term-char #\\Space))\n \"Receives ASCII inputs and returns multiple values: the string and the end\nposition.\n\nThis function calls READ-BYTE to read characters though it calls READ-CHAR\ninstead on SLIME because SLIME's IO is not bivalent.\"\n (declare (inline read-byte)) ; declaring (sb-kernel:ansi-stream in) will be faster\n (loop for c of-type base-char =\n #-swank (code-char (read-byte in nil #.(char-code #\\Newline)))\n #+swank (read-char in nil #\\Newline)\n for idx from 0\n until (char= c #\\Newline)\n do (setf (char buffer-string idx) c)\n finally (when (< idx (length buffer-string))\n (setf (char buffer-string idx) term-char))\n (return (values buffer-string idx))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n(declaim (inline histogram=))\n(defun histogram= (h1 h2)\n (declare #.OPT)\n (and (= (sb-kernel:%vector-raw-bits h1 0)\n (sb-kernel:%vector-raw-bits h2 0))\n (= (sb-kernel:%vector-raw-bits h1 1)\n (sb-kernel:%vector-raw-bits h2 1))))\n\n(declaim (inline sxhash-histogram))\n(defun sxhash-histogram (h)\n (declare #.OPT\n ((simple-array uint4 (32)) h))\n (sb-int:mix (sb-kernel:%vector-raw-bits h 0)\n (sb-kernel:%vector-raw-bits h 1)))\n\n(sb-ext:define-hash-table-test histogram= sxhash-histogram)\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (line (make-string 10 :element-type 'base-char))\n (table (make-hash-table :test 'histogram= :size n))\n (res 0))\n (declare (uint32 n)\n (uint62 res))\n (dotimes (i n)\n (read-line-into line)\n (let ((histo (make-array 32 :element-type 'uint4 :initial-element 0)))\n (loop for c across line\n do (incf (aref histo (- (char-code c) 97))))\n (if (gethash histo table)\n (incf (the uint32 (gethash histo table)))\n (setf (gethash histo table) 1))))\n (loop for value of-type uint31 being each hash-value of table\n do (incf res (floor (* value (- value 1)) 2)))\n (println res)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1565499448, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02947.html", "problem_id": "p02947", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02947/input.txt", "sample_output_relpath": "derived/input_output/data/p02947/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02947/Lisp/s533763564.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s533763564", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline read-line-into))\n(defun read-line-into (buffer-string &key (in *standard-input*) (term-char #\\Space))\n \"Receives ASCII inputs and returns multiple values: the string and the end\nposition.\n\nThis function calls READ-BYTE to read characters though it calls READ-CHAR\ninstead on SLIME because SLIME's IO is not bivalent.\"\n (declare (inline read-byte)) ; declaring (sb-kernel:ansi-stream in) will be faster\n (loop for c of-type base-char =\n #-swank (code-char (read-byte in nil #.(char-code #\\Newline)))\n #+swank (read-char in nil #\\Newline)\n for idx from 0\n until (char= c #\\Newline)\n do (setf (char buffer-string idx) c)\n finally (when (< idx (length buffer-string))\n (setf (char buffer-string idx) term-char))\n (return (values buffer-string idx))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n(declaim (inline histogram=))\n(defun histogram= (h1 h2)\n (declare #.OPT)\n (and (= (sb-kernel:%vector-raw-bits h1 0)\n (sb-kernel:%vector-raw-bits h2 0))\n (= (sb-kernel:%vector-raw-bits h1 1)\n (sb-kernel:%vector-raw-bits h2 1))))\n\n(declaim (inline sxhash-histogram))\n(defun sxhash-histogram (h)\n (declare #.OPT\n ((simple-array uint4 (32)) h))\n (sb-int:mix (sb-kernel:%vector-raw-bits h 0)\n (sb-kernel:%vector-raw-bits h 1)))\n\n(sb-ext:define-hash-table-test histogram= sxhash-histogram)\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (line (make-string 10 :element-type 'base-char))\n (table (make-hash-table :test 'histogram= :size n))\n (res 0))\n (declare (uint32 n)\n (uint62 res))\n (dotimes (i n)\n (read-line-into line)\n (let ((histo (make-array 32 :element-type 'uint4 :initial-element 0)))\n (loop for c across line\n do (incf (aref histo (- (char-code c) 97))))\n (if (gethash histo table)\n (incf (the uint32 (gethash histo table)))\n (setf (gethash histo table) 1))))\n (loop for value of-type uint31 being each hash-value of table\n do (incf res (floor (* value (- value 1)) 2)))\n (println res)))\n\n#-swank (main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWe will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.\n\nFor example, greenbin is an anagram of beginner. As seen here, when the same character occurs multiple times, that character must be used that number of times.\n\nGiven are N strings s_1, s_2, \\ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \\leq i < j \\leq N) such that s_i is an anagram of s_j.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\ns_i is a string of length 10.\n\nEach character in s_i is a lowercase English letter.\n\ns_1, s_2, \\ldots, s_N are all distinct.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\ns_1\ns_2\n:\ns_N\n\nOutput\n\nPrint the number of pairs of integers i, j (1 \\leq i < j \\leq N) such that s_i is an anagram of s_j.\n\nSample Input 1\n\n3\nacornistnt\npeanutbomb\nconstraint\n\nSample Output 1\n\n1\n\ns_1 = acornistnt is an anagram of s_3 = constraint. There are no other pairs i, j such that s_i is an anagram of s_j, so the answer is 1.\n\nSample Input 2\n\n2\noneplustwo\nninemodsix\n\nSample Output 2\n\n0\n\nIf there is no pair i, j such that s_i is an anagram of s_j, print 0.\n\nSample Input 3\n\n5\nabaaaaaaaa\noneplustwo\naaaaaaaaba\ntwoplusone\naaaabaaaaa\n\nSample Output 3\n\n4\n\nNote that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.", "sample_input": "3\nacornistnt\npeanutbomb\nconstraint\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02947", "source_text": "Score : 300 points\n\nProblem Statement\n\nWe will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.\n\nFor example, greenbin is an anagram of beginner. As seen here, when the same character occurs multiple times, that character must be used that number of times.\n\nGiven are N strings s_1, s_2, \\ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \\leq i < j \\leq N) such that s_i is an anagram of s_j.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\ns_i is a string of length 10.\n\nEach character in s_i is a lowercase English letter.\n\ns_1, s_2, \\ldots, s_N are all distinct.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\ns_1\ns_2\n:\ns_N\n\nOutput\n\nPrint the number of pairs of integers i, j (1 \\leq i < j \\leq N) such that s_i is an anagram of s_j.\n\nSample Input 1\n\n3\nacornistnt\npeanutbomb\nconstraint\n\nSample Output 1\n\n1\n\ns_1 = acornistnt is an anagram of s_3 = constraint. There are no other pairs i, j such that s_i is an anagram of s_j, so the answer is 1.\n\nSample Input 2\n\n2\noneplustwo\nninemodsix\n\nSample Output 2\n\n0\n\nIf there is no pair i, j such that s_i is an anagram of s_j, print 0.\n\nSample Input 3\n\n5\nabaaaaaaaa\noneplustwo\naaaaaaaaba\ntwoplusone\naaaabaaaaa\n\nSample Output 3\n\n4\n\nNote that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3405, "cpu_time_ms": 122, "memory_kb": 23012}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s483939697", "group_id": "codeNet:p02950", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values (mod #.most-positive-fixnum) &optional)) %mod-inverse))\n(defun %mod-inverse (a modulus)\n \"Solves ax ≡ 1 mod m. A and M must be coprime.\"\n (declare (optimize (speed 3))\n (integer a)\n ((integer 1 #.most-positive-fixnum) modulus))\n (labels ((%gcd (a b)\n (declare (optimize (safety 0))\n ((integer 0 #.most-positive-fixnum) a b))\n (if (zerop b)\n (values 1 0)\n (multiple-value-bind (p q) (floor a b) ; a = pb + q\n (multiple-value-bind (v u) (%gcd b q)\n (declare (fixnum u v))\n (values u (the fixnum (- v (the fixnum (* p u))))))))))\n (mod (%gcd (mod a modulus) modulus) modulus)))\n\n;; Naive division\n;; Reference: http://web.cs.iastate.edu/~cs577/handouts/polydivide.pdf\n(declaim (inline poly-floor!))\n(defun poly-floor! (u v modulus &optional quotient)\n \"Returns the quotient q(x) and the remainder r(x) on Z/nZ: u(x) = q(x)v(x) + r(x),\ndeg(r) < deg(v). This function destructively modifies U. The time complexity is\nO((deg(u)-deg(v))deg(v)).\n\nThe quotient is stored in QUOTIENT if it is given, otherwise a new vector is\ncreated.\n\nNote that MODULUS and V[deg(V)] must be coprime.\"\n (declare (vector u v)\n ((integer 1 #.most-positive-fixnum) modulus))\n ;; (assert (and (>= (length u) 1) (>= (length v) 1)))\n (let* ((m (loop for i from (- (length u) 1) downto 0\n while (zerop (aref u i))\n finally (return i)))\n (n (loop for i from (- (length v) 1) downto 0\n unless (zerop (aref v i))\n do (return i)\n finally (error 'division-by-zero\n :operation #'poly-floor!\n :operands (list u v))))\n (quot (or quotient\n (make-array (max 0 (+ 1 (- m n)))\n :element-type (array-element-type u)))))\n (declare ((integer -1 (#.array-total-size-limit)) m n))\n (loop for k from (- m n) downto 0\n do (setf (aref quot k)\n (mod (* (aref u (+ n k))\n ;; FIXME: better to signal an error in non-coprime case?\n (%mod-inverse (aref v n) modulus))\n modulus))\n (loop for j from (+ n k -1) downto k\n do (setf (aref u j)\n (mod (- (aref u j)\n (mod (* (aref quot k) (aref v (- j k))) modulus))\n modulus))))\n (loop for i from (- (length u) 1) downto n\n do (setf (aref u i) 0)\n finally (return (values quot u)))))\n\n;;;\n;;; Modular arithmetic\n;;;\n\n(declaim (ftype (function * (values fixnum fixnum &optional)) %gcd))\n(defun %gcd (a b)\n (declare (optimize (speed 3) (safety 0))\n (fixnum a b))\n (if (zerop b)\n (values 1 0)\n (multiple-value-bind (p q) (floor a b) ; a = pb + q\n (multiple-value-bind (v u) (%gcd b q)\n (declare (fixnum u v))\n (values u (the fixnum (- v (the fixnum (* p u)))))))))\n\n(declaim (ftype (function * (values (mod #.most-positive-fixnum) &optional)) mod-inverse))\n(defun mod-inverse (a modulus)\n \"Solves ax ≡ 1 mod m. A and M must be coprime.\"\n (declare #.OPT\n ((unsigned-byte 32) a modulus))\n (mod (%gcd (mod a modulus) modulus) modulus))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(declaim (inline poly-value))\n(defun poly-value (poly input divisor)\n (let ((x^i 1)\n (res 0))\n (declare (fixnum x^i res))\n (dotimes (i (length poly))\n (setq res (mod (+ res (* x^i (aref poly i))) divisor))\n (setq x^i (mod (* x^i input) divisor)))\n res))\n\n(defun main ()\n (declare #.OPT)\n (let* ((p (read))\n (as (make-array p :element-type 'bit)))\n (declare (uint16 p))\n (dotimes (i p)\n (setf (aref as i) (read)))\n (let ((res (make-array p :element-type 'uint32 :initial-element 0))\n (base (make-array (+ p 1) :element-type 'uint16 :initial-element 0))\n (quot (make-array p :element-type 'uint16)))\n (setf (aref base 0) 1)\n (dotimes (i p)\n (loop for j from (+ i 1) above 0\n do (setf (aref base j)\n (mod (- (aref base (- j 1))\n (* i (aref base j)))\n p)))\n (setf (aref base 0) (mod (- (* i (aref base 0))) p)))\n (dotimes (pivot p)\n (when (= 1 (aref as pivot))\n (fill quot 0)\n (poly-floor! (copy-seq base)\n (make-array 2 :element-type 'uint16\n :initial-contents `(,(- p pivot) 1))\n p\n quot)\n (let ((factor (mod-inverse (poly-value quot pivot p) p)))\n (declare (uint16 factor))\n (dotimes (i p)\n (setf (aref quot i)\n (mod (* factor (aref quot i)) p))))\n (dotimes (i p)\n (incf (aref res i) (aref quot i)))))\n (dotimes (i p)\n (setf (aref res i) (mod (aref res i) p)))\n (let ((init t))\n (dotimes (i p)\n (if init (setq init nil) (write-char #\\ ))\n (princ (aref res i)))\n (terpri)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1565652705, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02950.html", "problem_id": "p02950", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02950/input.txt", "sample_output_relpath": "derived/input_output/data/p02950/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02950/Lisp/s483939697.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s483939697", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1 1\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values (mod #.most-positive-fixnum) &optional)) %mod-inverse))\n(defun %mod-inverse (a modulus)\n \"Solves ax ≡ 1 mod m. A and M must be coprime.\"\n (declare (optimize (speed 3))\n (integer a)\n ((integer 1 #.most-positive-fixnum) modulus))\n (labels ((%gcd (a b)\n (declare (optimize (safety 0))\n ((integer 0 #.most-positive-fixnum) a b))\n (if (zerop b)\n (values 1 0)\n (multiple-value-bind (p q) (floor a b) ; a = pb + q\n (multiple-value-bind (v u) (%gcd b q)\n (declare (fixnum u v))\n (values u (the fixnum (- v (the fixnum (* p u))))))))))\n (mod (%gcd (mod a modulus) modulus) modulus)))\n\n;; Naive division\n;; Reference: http://web.cs.iastate.edu/~cs577/handouts/polydivide.pdf\n(declaim (inline poly-floor!))\n(defun poly-floor! (u v modulus &optional quotient)\n \"Returns the quotient q(x) and the remainder r(x) on Z/nZ: u(x) = q(x)v(x) + r(x),\ndeg(r) < deg(v). This function destructively modifies U. The time complexity is\nO((deg(u)-deg(v))deg(v)).\n\nThe quotient is stored in QUOTIENT if it is given, otherwise a new vector is\ncreated.\n\nNote that MODULUS and V[deg(V)] must be coprime.\"\n (declare (vector u v)\n ((integer 1 #.most-positive-fixnum) modulus))\n ;; (assert (and (>= (length u) 1) (>= (length v) 1)))\n (let* ((m (loop for i from (- (length u) 1) downto 0\n while (zerop (aref u i))\n finally (return i)))\n (n (loop for i from (- (length v) 1) downto 0\n unless (zerop (aref v i))\n do (return i)\n finally (error 'division-by-zero\n :operation #'poly-floor!\n :operands (list u v))))\n (quot (or quotient\n (make-array (max 0 (+ 1 (- m n)))\n :element-type (array-element-type u)))))\n (declare ((integer -1 (#.array-total-size-limit)) m n))\n (loop for k from (- m n) downto 0\n do (setf (aref quot k)\n (mod (* (aref u (+ n k))\n ;; FIXME: better to signal an error in non-coprime case?\n (%mod-inverse (aref v n) modulus))\n modulus))\n (loop for j from (+ n k -1) downto k\n do (setf (aref u j)\n (mod (- (aref u j)\n (mod (* (aref quot k) (aref v (- j k))) modulus))\n modulus))))\n (loop for i from (- (length u) 1) downto n\n do (setf (aref u i) 0)\n finally (return (values quot u)))))\n\n;;;\n;;; Modular arithmetic\n;;;\n\n(declaim (ftype (function * (values fixnum fixnum &optional)) %gcd))\n(defun %gcd (a b)\n (declare (optimize (speed 3) (safety 0))\n (fixnum a b))\n (if (zerop b)\n (values 1 0)\n (multiple-value-bind (p q) (floor a b) ; a = pb + q\n (multiple-value-bind (v u) (%gcd b q)\n (declare (fixnum u v))\n (values u (the fixnum (- v (the fixnum (* p u)))))))))\n\n(declaim (ftype (function * (values (mod #.most-positive-fixnum) &optional)) mod-inverse))\n(defun mod-inverse (a modulus)\n \"Solves ax ≡ 1 mod m. A and M must be coprime.\"\n (declare #.OPT\n ((unsigned-byte 32) a modulus))\n (mod (%gcd (mod a modulus) modulus) modulus))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(declaim (inline poly-value))\n(defun poly-value (poly input divisor)\n (let ((x^i 1)\n (res 0))\n (declare (fixnum x^i res))\n (dotimes (i (length poly))\n (setq res (mod (+ res (* x^i (aref poly i))) divisor))\n (setq x^i (mod (* x^i input) divisor)))\n res))\n\n(defun main ()\n (declare #.OPT)\n (let* ((p (read))\n (as (make-array p :element-type 'bit)))\n (declare (uint16 p))\n (dotimes (i p)\n (setf (aref as i) (read)))\n (let ((res (make-array p :element-type 'uint32 :initial-element 0))\n (base (make-array (+ p 1) :element-type 'uint16 :initial-element 0))\n (quot (make-array p :element-type 'uint16)))\n (setf (aref base 0) 1)\n (dotimes (i p)\n (loop for j from (+ i 1) above 0\n do (setf (aref base j)\n (mod (- (aref base (- j 1))\n (* i (aref base j)))\n p)))\n (setf (aref base 0) (mod (- (* i (aref base 0))) p)))\n (dotimes (pivot p)\n (when (= 1 (aref as pivot))\n (fill quot 0)\n (poly-floor! (copy-seq base)\n (make-array 2 :element-type 'uint16\n :initial-contents `(,(- p pivot) 1))\n p\n quot)\n (let ((factor (mod-inverse (poly-value quot pivot p) p)))\n (declare (uint16 factor))\n (dotimes (i p)\n (setf (aref quot i)\n (mod (* factor (aref quot i)) p))))\n (dotimes (i p)\n (incf (aref res i) (aref quot i)))))\n (dotimes (i p)\n (setf (aref res i) (mod (aref res i) p)))\n (let ((init t))\n (dotimes (i p)\n (if init (setq init nil) (write-char #\\ ))\n (princ (aref res i)))\n (terpri)))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven are a prime number p and a sequence of p integers a_0, \\ldots, a_{p-1} consisting of zeros and ones.\n\nFind a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \\ldots + b_0, satisfying the following conditions:\n\nFor each i (0 \\leq i \\leq p-1), b_i is an integer such that 0 \\leq b_i \\leq p-1.\n\nFor each i (0 \\leq i \\leq p-1), f(i) \\equiv a_i \\pmod p.\n\nConstraints\n\n2 \\leq p \\leq 2999\n\np is a prime number.\n\n0 \\leq a_i \\leq 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\np\na_0 a_1 \\ldots a_{p-1}\n\nOutput\n\nPrint b_0, b_1, \\ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.\n\nIt can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.\n\nSample Input 1\n\n2\n1 0\n\nSample Output 1\n\n1 1\n\nf(x) = x + 1 satisfies the conditions, as follows:\n\nf(0) = 0 + 1 = 1 \\equiv 1 \\pmod 2\n\nf(1) = 1 + 1 = 2 \\equiv 0 \\pmod 2\n\nSample Input 2\n\n3\n0 0 0\n\nSample Output 2\n\n0 0 0\n\nf(x) = 0 is also valid.\n\nSample Input 3\n\n5\n0 1 0 1 0\n\nSample Output 3\n\n0 2 0 1 3", "sample_input": "2\n1 0\n"}, "reference_outputs": ["1 1\n"], "source_document_id": "p02950", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are a prime number p and a sequence of p integers a_0, \\ldots, a_{p-1} consisting of zeros and ones.\n\nFind a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \\ldots + b_0, satisfying the following conditions:\n\nFor each i (0 \\leq i \\leq p-1), b_i is an integer such that 0 \\leq b_i \\leq p-1.\n\nFor each i (0 \\leq i \\leq p-1), f(i) \\equiv a_i \\pmod p.\n\nConstraints\n\n2 \\leq p \\leq 2999\n\np is a prime number.\n\n0 \\leq a_i \\leq 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\np\na_0 a_1 \\ldots a_{p-1}\n\nOutput\n\nPrint b_0, b_1, \\ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.\n\nIt can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.\n\nSample Input 1\n\n2\n1 0\n\nSample Output 1\n\n1 1\n\nf(x) = x + 1 satisfies the conditions, as follows:\n\nf(0) = 0 + 1 = 1 \\equiv 1 \\pmod 2\n\nf(1) = 1 + 1 = 2 \\equiv 0 \\pmod 2\n\nSample Input 2\n\n3\n0 0 0\n\nSample Output 2\n\n0 0 0\n\nf(x) = 0 is also valid.\n\nSample Input 3\n\n5\n0 1 0 1 0\n\nSample Output 3\n\n0 2 0 1 3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6569, "cpu_time_ms": 1507, "memory_kb": 49640}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s905689632", "group_id": "codeNet:p02950", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Modular arithmetic\n;;;\n\n(declaim (ftype (function * (values fixnum fixnum &optional)) %gcd))\n(defun %gcd (a b)\n (declare (optimize (speed 3) (safety 0))\n (fixnum a b))\n (if (zerop b)\n (values 1 0)\n (multiple-value-bind (p q) (floor a b) ; a = pb + q\n (multiple-value-bind (v u) (%gcd b q)\n (declare (fixnum u v))\n (values u (the fixnum (- v (the fixnum (* p u)))))))))\n\n(declaim (ftype (function * (values (mod #.most-positive-fixnum) &optional)) mod-inverse))\n(defun mod-inverse (a modulus)\n \"Solves ax ≡ 1 mod m. A and M must be coprime.\"\n (declare #.OPT\n ((unsigned-byte 32) a modulus))\n (mod (%gcd (mod a modulus) modulus) modulus))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(declaim (inline poly-value))\n(defun poly-value (poly input divisor)\n (let ((x^i 1)\n (res 0))\n (declare (fixnum x^i res))\n (dotimes (i (length poly))\n (setq res (mod (+ res (* x^i (aref poly i))) divisor))\n (setq x^i (mod (* x^i input) divisor)))\n res))\n\n(defconstant +fft-size+ 4096)\n(defun main ()\n (declare #.OPT)\n (let* ((p (read))\n ;; table of the indices such that a_i = 1\n (table1 (make-hash-table)))\n (declare (uint16 p))\n (dotimes (i p)\n (when (= (the bit (read)) 1)\n (setf (gethash i table1) t)))\n (let ((res (make-array p :element-type 'uint16 :initial-element 0))\n (base (make-array (+ p 1) :element-type 'uint16 :initial-element 0))\n (quot (make-array p :element-type 'uint16)))\n (setf (aref base 0) 1)\n (dotimes (i p)\n (loop for j from p above 0\n do (setf (aref base j)\n (mod (- (aref base (- j 1))\n (* i (aref base j)))\n p)))\n (setf (aref base 0) (mod (- (* i (aref base 0))) p)))\n (dotimes (pivot p)\n (when (gethash pivot table1)\n (fill quot 0)\n (setf (aref quot (- p 1)) (aref base p))\n (loop for i from (- p 2) downto 0\n do (setf (aref quot i)\n (mod (+ (aref base (+ i 1))\n (* pivot (aref quot (+ i 1))))\n p)))\n (let ((factor (mod-inverse (poly-value quot pivot p) p)))\n (declare (uint16 factor))\n (dotimes (i p)\n (setf (aref quot i)\n (mod (* factor (aref quot i)) p))))\n (dotimes (i p)\n (setf (aref res i)\n (mod (+ (aref res i) (aref quot i)) p)))))\n (let ((init t))\n (dotimes (i p)\n (if init (setq init nil) (write-char #\\ ))\n (princ (aref res i)))\n (terpri)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1565572453, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02950.html", "problem_id": "p02950", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02950/input.txt", "sample_output_relpath": "derived/input_output/data/p02950/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02950/Lisp/s905689632.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s905689632", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1 1\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Modular arithmetic\n;;;\n\n(declaim (ftype (function * (values fixnum fixnum &optional)) %gcd))\n(defun %gcd (a b)\n (declare (optimize (speed 3) (safety 0))\n (fixnum a b))\n (if (zerop b)\n (values 1 0)\n (multiple-value-bind (p q) (floor a b) ; a = pb + q\n (multiple-value-bind (v u) (%gcd b q)\n (declare (fixnum u v))\n (values u (the fixnum (- v (the fixnum (* p u)))))))))\n\n(declaim (ftype (function * (values (mod #.most-positive-fixnum) &optional)) mod-inverse))\n(defun mod-inverse (a modulus)\n \"Solves ax ≡ 1 mod m. A and M must be coprime.\"\n (declare #.OPT\n ((unsigned-byte 32) a modulus))\n (mod (%gcd (mod a modulus) modulus) modulus))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(declaim (inline poly-value))\n(defun poly-value (poly input divisor)\n (let ((x^i 1)\n (res 0))\n (declare (fixnum x^i res))\n (dotimes (i (length poly))\n (setq res (mod (+ res (* x^i (aref poly i))) divisor))\n (setq x^i (mod (* x^i input) divisor)))\n res))\n\n(defconstant +fft-size+ 4096)\n(defun main ()\n (declare #.OPT)\n (let* ((p (read))\n ;; table of the indices such that a_i = 1\n (table1 (make-hash-table)))\n (declare (uint16 p))\n (dotimes (i p)\n (when (= (the bit (read)) 1)\n (setf (gethash i table1) t)))\n (let ((res (make-array p :element-type 'uint16 :initial-element 0))\n (base (make-array (+ p 1) :element-type 'uint16 :initial-element 0))\n (quot (make-array p :element-type 'uint16)))\n (setf (aref base 0) 1)\n (dotimes (i p)\n (loop for j from p above 0\n do (setf (aref base j)\n (mod (- (aref base (- j 1))\n (* i (aref base j)))\n p)))\n (setf (aref base 0) (mod (- (* i (aref base 0))) p)))\n (dotimes (pivot p)\n (when (gethash pivot table1)\n (fill quot 0)\n (setf (aref quot (- p 1)) (aref base p))\n (loop for i from (- p 2) downto 0\n do (setf (aref quot i)\n (mod (+ (aref base (+ i 1))\n (* pivot (aref quot (+ i 1))))\n p)))\n (let ((factor (mod-inverse (poly-value quot pivot p) p)))\n (declare (uint16 factor))\n (dotimes (i p)\n (setf (aref quot i)\n (mod (* factor (aref quot i)) p))))\n (dotimes (i p)\n (setf (aref res i)\n (mod (+ (aref res i) (aref quot i)) p)))))\n (let ((init t))\n (dotimes (i p)\n (if init (setq init nil) (write-char #\\ ))\n (princ (aref res i)))\n (terpri)))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven are a prime number p and a sequence of p integers a_0, \\ldots, a_{p-1} consisting of zeros and ones.\n\nFind a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \\ldots + b_0, satisfying the following conditions:\n\nFor each i (0 \\leq i \\leq p-1), b_i is an integer such that 0 \\leq b_i \\leq p-1.\n\nFor each i (0 \\leq i \\leq p-1), f(i) \\equiv a_i \\pmod p.\n\nConstraints\n\n2 \\leq p \\leq 2999\n\np is a prime number.\n\n0 \\leq a_i \\leq 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\np\na_0 a_1 \\ldots a_{p-1}\n\nOutput\n\nPrint b_0, b_1, \\ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.\n\nIt can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.\n\nSample Input 1\n\n2\n1 0\n\nSample Output 1\n\n1 1\n\nf(x) = x + 1 satisfies the conditions, as follows:\n\nf(0) = 0 + 1 = 1 \\equiv 1 \\pmod 2\n\nf(1) = 1 + 1 = 2 \\equiv 0 \\pmod 2\n\nSample Input 2\n\n3\n0 0 0\n\nSample Output 2\n\n0 0 0\n\nf(x) = 0 is also valid.\n\nSample Input 3\n\n5\n0 1 0 1 0\n\nSample Output 3\n\n0 2 0 1 3", "sample_input": "2\n1 0\n"}, "reference_outputs": ["1 1\n"], "source_document_id": "p02950", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are a prime number p and a sequence of p integers a_0, \\ldots, a_{p-1} consisting of zeros and ones.\n\nFind a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \\ldots + b_0, satisfying the following conditions:\n\nFor each i (0 \\leq i \\leq p-1), b_i is an integer such that 0 \\leq b_i \\leq p-1.\n\nFor each i (0 \\leq i \\leq p-1), f(i) \\equiv a_i \\pmod p.\n\nConstraints\n\n2 \\leq p \\leq 2999\n\np is a prime number.\n\n0 \\leq a_i \\leq 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\np\na_0 a_1 \\ldots a_{p-1}\n\nOutput\n\nPrint b_0, b_1, \\ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.\n\nIt can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.\n\nSample Input 1\n\n2\n1 0\n\nSample Output 1\n\n1 1\n\nf(x) = x + 1 satisfies the conditions, as follows:\n\nf(0) = 0 + 1 = 1 \\equiv 1 \\pmod 2\n\nf(1) = 1 + 1 = 2 \\equiv 0 \\pmod 2\n\nSample Input 2\n\n3\n0 0 0\n\nSample Output 2\n\n0 0 0\n\nf(x) = 0 is also valid.\n\nSample Input 3\n\n5\n0 1 0 1 0\n\nSample Output 3\n\n0 2 0 1 3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3956, "cpu_time_ms": 719, "memory_kb": 18920}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s207962504", "group_id": "codeNet:p02950", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Modular arithmetic\n;;;\n\n(declaim (ftype (function * (values fixnum fixnum &optional)) %gcd))\n(defun %gcd (a b)\n (declare (optimize (speed 3) (safety 0))\n (fixnum a b))\n (if (zerop b)\n (values 1 0)\n (multiple-value-bind (p q) (floor a b) ; a = pb + q\n (multiple-value-bind (v u) (%gcd b q)\n (declare (fixnum u v))\n (values u (the fixnum (- v (the fixnum (* p u)))))))))\n\n(declaim (ftype (function * (values (mod #.most-positive-fixnum) &optional)) mod-inverse))\n(defun mod-inverse (a modulus)\n \"Solves ax ≡ 1 mod m. A and M must be coprime.\"\n (declare #.OPT\n ((unsigned-byte 32) a modulus))\n (mod (%gcd (mod a modulus) modulus) modulus))\n\n(deftype fft-float () 'single-float)\n\n(declaim (inline power2-p))\n(defun power2-p (x)\n \"Checks if X is a power of 2.\"\n (zerop (logand x (- x 1))))\n\n;; For FFT of fixed length, preparing the table of cos(i*theta) and sin\n;; (i*theta) will be efficient.\n(defun %make-trifunc-table (n)\n (declare (optimize (speed 3) (safety 0))\n ((integer 0 #.most-positive-fixnum) n))\n (assert (power2-p n))\n (let* ((cos-table (make-array (ash n -2) :element-type 'fft-float))\n (sin-table (make-array (ash n -2) :element-type 'fft-float))\n (theta (/ (coerce (* 2 pi) 'fft-float) n)))\n (dotimes (i (ash n -2))\n (setf (aref cos-table i) (cos (* i theta))\n (aref sin-table i) (sin (* i theta))))\n (values cos-table sin-table)))\n\n(defparameter *cos-table* nil)\n(defparameter *sin-table* nil)\n\n(defmacro with-fixed-length-fft (size &body body)\n \"Makes FFT faster when the SIZE of target vectors is fixed in BODY. This macro\ncomputes and holds the roots of unity for SIZE, which DFT! and INVERSE-DFT!\ncalled in BODY automatically detects; they will signal an error when they\nreceive a vector of different size.\"\n (let ((s (gensym)))\n `(let ((,s ,size))\n (multiple-value-bind (*cos-table* *sin-table*) (%make-trifunc-table ,s)\n ,@body))))\n\n(defun %dft-fixed-base! (f)\n (declare (optimize (speed 3) (safety 0))\n ((simple-array fft-float (*)) f))\n (prog1 f\n (let* ((n (length f))\n (cos-table *cos-table*)\n (sin-table *sin-table*)\n (factor n))\n (declare ((integer 0 #.most-positive-fixnum) factor)\n ((simple-array fft-float (*)) cos-table sin-table))\n (assert (power2-p n))\n (assert (= (ash n -2) (length cos-table)))\n ;; bit-reverse ordering\n (let ((i 0))\n (declare ((integer 0 #.most-positive-fixnum) i))\n (loop for j from 1 below (- n 1)\n do (loop for k of-type (integer 0 #.most-positive-fixnum)\n = (ash n -1) then (ash k -1)\n while (> k (setq i (logxor i k))))\n (when (< j i)\n (rotatef (aref f i) (aref f j)))))\n (do* ((mh 1 m)\n (m (ash mh 1) (ash mh 1)))\n ((> m n))\n (declare ((integer 0 #.most-positive-fixnum) mh m))\n (let ((mq (ash mh -1)))\n (setq factor (ash factor -1))\n (do ((jr 0 (+ jr m)))\n ((>= jr n))\n (declare ((integer 0 #.most-positive-fixnum) jr))\n (let ((xreal (aref f (+ jr mh))))\n (setf (aref f (+ jr mh)) (- (aref f jr) xreal))\n (incf (aref f jr) xreal)))\n (do ((i 1 (+ i 1)))\n ((>= i mq))\n (declare ((integer 0 #.most-positive-fixnum) i))\n (let* ((index (the fixnum (* factor i)))\n (wreal (aref cos-table index))\n (wimag (- (aref sin-table index))))\n (do ((j 0 (+ j m)))\n ((>= j n))\n (let* ((j+mh (+ j mh))\n (j+m-i (- (+ j m) i))\n (xreal (+ (* wreal (aref f (+ j+mh i)))\n (* wimag (aref f j+m-i))))\n (ximag (- (* wreal (aref f j+m-i))\n (* wimag (aref f (+ j+mh i))))))\n (declare ((integer 0 #.most-positive-fixnum) j+mh j+m-i))\n (setf (aref f (+ j+mh i))\n (+ (- (aref f (- j+mh i))) ximag))\n (setf (aref f j+m-i)\n (+ (aref f (- j+mh i)) ximag))\n (setf (aref f (- j+mh i))\n (+ (aref f (+ j i)) (- xreal)))\n (incf (aref f (+ j i)) xreal))))))))))\n\n(defun %inverse-dft-fixed-base! (f)\n (declare (optimize (speed 3) (safety 0))\n ((simple-array fft-float (*)) f))\n (prog1 f\n (let* ((n (length f))\n (cos-table *cos-table*)\n (sin-table *sin-table*)\n (factor 1))\n (declare ((integer 0 #.most-positive-fixnum) factor)\n ((simple-array fft-float (*)) cos-table sin-table))\n (assert (power2-p n))\n (assert (= (ash n -2) (length cos-table)))\n (setf (aref f 0)\n (/ (aref f 0) 2))\n (setf (aref f (ash n -1))\n (/ (aref f (ash n -1)) 2))\n (do* ((m n mh)\n (mh (ash m -1) (ash m -1)))\n ((zerop mh))\n (declare ((integer 0 #.most-positive-fixnum) m mh))\n (let ((mq (ash mh -1)))\n (do ((jr 0 (+ jr m)))\n ((>= jr n))\n (declare ((integer 0 #.most-positive-fixnum) jr))\n (let ((xreal (- (aref f jr) (aref f (+ jr mh)))))\n (incf (aref f jr) (aref f (+ jr mh)))\n (setf (aref f (+ jr mh)) xreal)))\n (do ((i 1 (+ i 1)))\n ((>= i mq))\n (let* ((index (the fixnum (* factor i)))\n (wreal (aref cos-table index))\n (wimag (aref sin-table index)))\n (do ((j 0 (+ j m)))\n ((>= j n))\n (let* ((j+mh (+ j mh))\n (j+m-i (- (+ j m) i))\n (xreal (- (aref f (+ j i)) (aref f (- j+mh i))))\n (ximag (+ (aref f j+m-i) (aref f (+ j+mh i)))))\n (declare ((integer 0 #.most-positive-fixnum) j+mh j+m-i))\n (incf (aref f (+ j i)) (aref f (- j+mh i)))\n (setf (aref f (- j+mh i))\n (- (aref f j+m-i) (aref f (+ j+mh i))))\n (setf (aref f (+ j+mh i))\n (+ (* wreal xreal) (* wimag ximag)))\n (setf (aref f j+m-i)\n (- (* wreal ximag) (* wimag xreal))))))))\n (setq factor (ash factor 1)))\n ;; bit-reverse ordering\n (let ((i 0))\n (declare ((integer 0 #.most-positive-fixnum) i))\n (loop for j from 1 below (- n 1)\n do (loop for k of-type (integer 0 #.most-positive-fixnum)\n = (ash n -1) then (ash k -1)\n while (> k (setq i (logxor i k))))\n (when (< j i)\n (rotatef (aref f i) (aref f j))))))))\n\n(declaim (inline dft!))\n(defun dft! (f)\n (declare ((simple-array fft-float (*)) f))\n (if (zerop (length f))\n f\n (if *cos-table*\n (%dft-fixed-base! f)\n (error \"Huh?\"))))\n\n(declaim (inline inverse-dft!))\n(defun inverse-dft! (f)\n (declare ((simple-array fft-float (*)) f))\n (prog1 f\n (let ((n (length f)))\n (unless (zerop n)\n (let ((factor (* 2 (/ (coerce n 'fft-float)))))\n (if *cos-table*\n (%inverse-dft-fixed-base! f)\n (error \"Huh?\"))\n (dotimes (i n)\n (setf (aref f i) (* (aref f i) factor))))))))\n\n(declaim (inline convolute!))\n(defun convolute! (g h &optional result-vector)\n \"Returns the convolution of two vectors G and H. A new vector is created when\nRESULT-VECTOR is null. This function destructively modifies G and H. (They can\nbe restored by INVERSE-DFT!.)\"\n (declare ((simple-array fft-float (*)) g h)\n ((or null (simple-array fft-float (*))) result-vector))\n (let ((n (length g)))\n (assert (and (power2-p n)\n (= n (length h))))\n (dft! g)\n (dft! h)\n (let ((f (or result-vector (make-array n :element-type 'fft-float))))\n (unless (zerop n)\n (setf (aref f 0)\n (* (aref g 0) (aref h 0)))\n (setf (aref f (ash n -1))\n (* (aref g (ash n -1)) (aref h (ash n -1)))))\n (loop for i from 1 below (ash n -1)\n for value1 of-type fft-float\n = (- (* (aref g i) (aref h i))\n (* (aref g (- n i)) (aref h (- n i))))\n for value2 of-type fft-float\n = (+ (* (aref g i) (aref h (- n i)))\n (* (aref g (- n i)) (aref h i)))\n do (setf (aref f i) value1)\n (setf (aref f (- n i)) value2))\n (inverse-dft! f))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(declaim (inline poly-value))\n(defun poly-value (poly input divisor)\n (let ((x^i 1)\n (res 0))\n (declare (fixnum x^i res))\n (dotimes (i (length poly))\n (setq res (mod (+ res (* x^i (aref poly i))) divisor))\n (setq x^i (mod (* x^i input) divisor)))\n res))\n\n(defconstant +fft-size+ 4096)\n(defun main ()\n (declare #.OPT)\n (let* ((p (read))\n ;; table of the indices such that a_i = 1\n (table1 (make-hash-table)))\n (declare (uint16 p))\n (dotimes (i p)\n (when (= (the bit (read)) 1)\n (setf (gethash i table1) t)))\n (let ((res (make-array +fft-size+ :element-type 'uint16 :initial-element 0))\n (basef (make-array +fft-size+ :element-type 'fft-float :initial-element 0f0))\n (base (make-array +fft-size+ :element-type 'uint16 :initial-element 0))\n (multiplier (make-array +fft-size+ :element-type 'fft-float))\n (quot (make-array p :element-type 'uint16)))\n (setf (aref basef 0) 1f0)\n (with-fixed-length-fft +fft-size+\n (dotimes (i p)\n (fill multiplier 0f0)\n (setf (aref multiplier 0) (float (- i) 1f0))\n (setf (aref multiplier 1) 1f0)\n (convolute! basef multiplier basef)\n (dotimes (i +fft-size+)\n (setf (aref basef i)\n (float (mod (the fixnum (round (aref basef i))) p) 1f0)))))\n (dotimes (i +fft-size+)\n (setf (aref base i) (round (aref basef i))))\n (dotimes (pivot p)\n (when (gethash pivot table1)\n (fill quot 0)\n (setf (aref quot (- p 1)) (aref base p))\n (loop for i from (- p 2) downto 0\n do (setf (aref quot i)\n (mod (+ (aref base (+ i 1))\n (* pivot (aref quot (+ i 1))))\n p)))\n (let ((factor (mod-inverse (poly-value quot pivot p) p)))\n (declare (uint16 factor))\n (dotimes (i p)\n (setf (aref quot i)\n (mod (* factor (aref quot i)) p))))\n (dotimes (i p)\n (setf (aref res i)\n (mod (+ (aref res i) (aref quot i)) p)))))\n (let ((init t))\n (dotimes (i p)\n (if init (setq init nil) (write-char #\\ ))\n (princ (aref res i)))\n (terpri)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1565509521, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02950.html", "problem_id": "p02950", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02950/input.txt", "sample_output_relpath": "derived/input_output/data/p02950/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02950/Lisp/s207962504.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s207962504", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1 1\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Modular arithmetic\n;;;\n\n(declaim (ftype (function * (values fixnum fixnum &optional)) %gcd))\n(defun %gcd (a b)\n (declare (optimize (speed 3) (safety 0))\n (fixnum a b))\n (if (zerop b)\n (values 1 0)\n (multiple-value-bind (p q) (floor a b) ; a = pb + q\n (multiple-value-bind (v u) (%gcd b q)\n (declare (fixnum u v))\n (values u (the fixnum (- v (the fixnum (* p u)))))))))\n\n(declaim (ftype (function * (values (mod #.most-positive-fixnum) &optional)) mod-inverse))\n(defun mod-inverse (a modulus)\n \"Solves ax ≡ 1 mod m. A and M must be coprime.\"\n (declare #.OPT\n ((unsigned-byte 32) a modulus))\n (mod (%gcd (mod a modulus) modulus) modulus))\n\n(deftype fft-float () 'single-float)\n\n(declaim (inline power2-p))\n(defun power2-p (x)\n \"Checks if X is a power of 2.\"\n (zerop (logand x (- x 1))))\n\n;; For FFT of fixed length, preparing the table of cos(i*theta) and sin\n;; (i*theta) will be efficient.\n(defun %make-trifunc-table (n)\n (declare (optimize (speed 3) (safety 0))\n ((integer 0 #.most-positive-fixnum) n))\n (assert (power2-p n))\n (let* ((cos-table (make-array (ash n -2) :element-type 'fft-float))\n (sin-table (make-array (ash n -2) :element-type 'fft-float))\n (theta (/ (coerce (* 2 pi) 'fft-float) n)))\n (dotimes (i (ash n -2))\n (setf (aref cos-table i) (cos (* i theta))\n (aref sin-table i) (sin (* i theta))))\n (values cos-table sin-table)))\n\n(defparameter *cos-table* nil)\n(defparameter *sin-table* nil)\n\n(defmacro with-fixed-length-fft (size &body body)\n \"Makes FFT faster when the SIZE of target vectors is fixed in BODY. This macro\ncomputes and holds the roots of unity for SIZE, which DFT! and INVERSE-DFT!\ncalled in BODY automatically detects; they will signal an error when they\nreceive a vector of different size.\"\n (let ((s (gensym)))\n `(let ((,s ,size))\n (multiple-value-bind (*cos-table* *sin-table*) (%make-trifunc-table ,s)\n ,@body))))\n\n(defun %dft-fixed-base! (f)\n (declare (optimize (speed 3) (safety 0))\n ((simple-array fft-float (*)) f))\n (prog1 f\n (let* ((n (length f))\n (cos-table *cos-table*)\n (sin-table *sin-table*)\n (factor n))\n (declare ((integer 0 #.most-positive-fixnum) factor)\n ((simple-array fft-float (*)) cos-table sin-table))\n (assert (power2-p n))\n (assert (= (ash n -2) (length cos-table)))\n ;; bit-reverse ordering\n (let ((i 0))\n (declare ((integer 0 #.most-positive-fixnum) i))\n (loop for j from 1 below (- n 1)\n do (loop for k of-type (integer 0 #.most-positive-fixnum)\n = (ash n -1) then (ash k -1)\n while (> k (setq i (logxor i k))))\n (when (< j i)\n (rotatef (aref f i) (aref f j)))))\n (do* ((mh 1 m)\n (m (ash mh 1) (ash mh 1)))\n ((> m n))\n (declare ((integer 0 #.most-positive-fixnum) mh m))\n (let ((mq (ash mh -1)))\n (setq factor (ash factor -1))\n (do ((jr 0 (+ jr m)))\n ((>= jr n))\n (declare ((integer 0 #.most-positive-fixnum) jr))\n (let ((xreal (aref f (+ jr mh))))\n (setf (aref f (+ jr mh)) (- (aref f jr) xreal))\n (incf (aref f jr) xreal)))\n (do ((i 1 (+ i 1)))\n ((>= i mq))\n (declare ((integer 0 #.most-positive-fixnum) i))\n (let* ((index (the fixnum (* factor i)))\n (wreal (aref cos-table index))\n (wimag (- (aref sin-table index))))\n (do ((j 0 (+ j m)))\n ((>= j n))\n (let* ((j+mh (+ j mh))\n (j+m-i (- (+ j m) i))\n (xreal (+ (* wreal (aref f (+ j+mh i)))\n (* wimag (aref f j+m-i))))\n (ximag (- (* wreal (aref f j+m-i))\n (* wimag (aref f (+ j+mh i))))))\n (declare ((integer 0 #.most-positive-fixnum) j+mh j+m-i))\n (setf (aref f (+ j+mh i))\n (+ (- (aref f (- j+mh i))) ximag))\n (setf (aref f j+m-i)\n (+ (aref f (- j+mh i)) ximag))\n (setf (aref f (- j+mh i))\n (+ (aref f (+ j i)) (- xreal)))\n (incf (aref f (+ j i)) xreal))))))))))\n\n(defun %inverse-dft-fixed-base! (f)\n (declare (optimize (speed 3) (safety 0))\n ((simple-array fft-float (*)) f))\n (prog1 f\n (let* ((n (length f))\n (cos-table *cos-table*)\n (sin-table *sin-table*)\n (factor 1))\n (declare ((integer 0 #.most-positive-fixnum) factor)\n ((simple-array fft-float (*)) cos-table sin-table))\n (assert (power2-p n))\n (assert (= (ash n -2) (length cos-table)))\n (setf (aref f 0)\n (/ (aref f 0) 2))\n (setf (aref f (ash n -1))\n (/ (aref f (ash n -1)) 2))\n (do* ((m n mh)\n (mh (ash m -1) (ash m -1)))\n ((zerop mh))\n (declare ((integer 0 #.most-positive-fixnum) m mh))\n (let ((mq (ash mh -1)))\n (do ((jr 0 (+ jr m)))\n ((>= jr n))\n (declare ((integer 0 #.most-positive-fixnum) jr))\n (let ((xreal (- (aref f jr) (aref f (+ jr mh)))))\n (incf (aref f jr) (aref f (+ jr mh)))\n (setf (aref f (+ jr mh)) xreal)))\n (do ((i 1 (+ i 1)))\n ((>= i mq))\n (let* ((index (the fixnum (* factor i)))\n (wreal (aref cos-table index))\n (wimag (aref sin-table index)))\n (do ((j 0 (+ j m)))\n ((>= j n))\n (let* ((j+mh (+ j mh))\n (j+m-i (- (+ j m) i))\n (xreal (- (aref f (+ j i)) (aref f (- j+mh i))))\n (ximag (+ (aref f j+m-i) (aref f (+ j+mh i)))))\n (declare ((integer 0 #.most-positive-fixnum) j+mh j+m-i))\n (incf (aref f (+ j i)) (aref f (- j+mh i)))\n (setf (aref f (- j+mh i))\n (- (aref f j+m-i) (aref f (+ j+mh i))))\n (setf (aref f (+ j+mh i))\n (+ (* wreal xreal) (* wimag ximag)))\n (setf (aref f j+m-i)\n (- (* wreal ximag) (* wimag xreal))))))))\n (setq factor (ash factor 1)))\n ;; bit-reverse ordering\n (let ((i 0))\n (declare ((integer 0 #.most-positive-fixnum) i))\n (loop for j from 1 below (- n 1)\n do (loop for k of-type (integer 0 #.most-positive-fixnum)\n = (ash n -1) then (ash k -1)\n while (> k (setq i (logxor i k))))\n (when (< j i)\n (rotatef (aref f i) (aref f j))))))))\n\n(declaim (inline dft!))\n(defun dft! (f)\n (declare ((simple-array fft-float (*)) f))\n (if (zerop (length f))\n f\n (if *cos-table*\n (%dft-fixed-base! f)\n (error \"Huh?\"))))\n\n(declaim (inline inverse-dft!))\n(defun inverse-dft! (f)\n (declare ((simple-array fft-float (*)) f))\n (prog1 f\n (let ((n (length f)))\n (unless (zerop n)\n (let ((factor (* 2 (/ (coerce n 'fft-float)))))\n (if *cos-table*\n (%inverse-dft-fixed-base! f)\n (error \"Huh?\"))\n (dotimes (i n)\n (setf (aref f i) (* (aref f i) factor))))))))\n\n(declaim (inline convolute!))\n(defun convolute! (g h &optional result-vector)\n \"Returns the convolution of two vectors G and H. A new vector is created when\nRESULT-VECTOR is null. This function destructively modifies G and H. (They can\nbe restored by INVERSE-DFT!.)\"\n (declare ((simple-array fft-float (*)) g h)\n ((or null (simple-array fft-float (*))) result-vector))\n (let ((n (length g)))\n (assert (and (power2-p n)\n (= n (length h))))\n (dft! g)\n (dft! h)\n (let ((f (or result-vector (make-array n :element-type 'fft-float))))\n (unless (zerop n)\n (setf (aref f 0)\n (* (aref g 0) (aref h 0)))\n (setf (aref f (ash n -1))\n (* (aref g (ash n -1)) (aref h (ash n -1)))))\n (loop for i from 1 below (ash n -1)\n for value1 of-type fft-float\n = (- (* (aref g i) (aref h i))\n (* (aref g (- n i)) (aref h (- n i))))\n for value2 of-type fft-float\n = (+ (* (aref g i) (aref h (- n i)))\n (* (aref g (- n i)) (aref h i)))\n do (setf (aref f i) value1)\n (setf (aref f (- n i)) value2))\n (inverse-dft! f))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(declaim (inline poly-value))\n(defun poly-value (poly input divisor)\n (let ((x^i 1)\n (res 0))\n (declare (fixnum x^i res))\n (dotimes (i (length poly))\n (setq res (mod (+ res (* x^i (aref poly i))) divisor))\n (setq x^i (mod (* x^i input) divisor)))\n res))\n\n(defconstant +fft-size+ 4096)\n(defun main ()\n (declare #.OPT)\n (let* ((p (read))\n ;; table of the indices such that a_i = 1\n (table1 (make-hash-table)))\n (declare (uint16 p))\n (dotimes (i p)\n (when (= (the bit (read)) 1)\n (setf (gethash i table1) t)))\n (let ((res (make-array +fft-size+ :element-type 'uint16 :initial-element 0))\n (basef (make-array +fft-size+ :element-type 'fft-float :initial-element 0f0))\n (base (make-array +fft-size+ :element-type 'uint16 :initial-element 0))\n (multiplier (make-array +fft-size+ :element-type 'fft-float))\n (quot (make-array p :element-type 'uint16)))\n (setf (aref basef 0) 1f0)\n (with-fixed-length-fft +fft-size+\n (dotimes (i p)\n (fill multiplier 0f0)\n (setf (aref multiplier 0) (float (- i) 1f0))\n (setf (aref multiplier 1) 1f0)\n (convolute! basef multiplier basef)\n (dotimes (i +fft-size+)\n (setf (aref basef i)\n (float (mod (the fixnum (round (aref basef i))) p) 1f0)))))\n (dotimes (i +fft-size+)\n (setf (aref base i) (round (aref basef i))))\n (dotimes (pivot p)\n (when (gethash pivot table1)\n (fill quot 0)\n (setf (aref quot (- p 1)) (aref base p))\n (loop for i from (- p 2) downto 0\n do (setf (aref quot i)\n (mod (+ (aref base (+ i 1))\n (* pivot (aref quot (+ i 1))))\n p)))\n (let ((factor (mod-inverse (poly-value quot pivot p) p)))\n (declare (uint16 factor))\n (dotimes (i p)\n (setf (aref quot i)\n (mod (* factor (aref quot i)) p))))\n (dotimes (i p)\n (setf (aref res i)\n (mod (+ (aref res i) (aref quot i)) p)))))\n (let ((init t))\n (dotimes (i p)\n (if init (setq init nil) (write-char #\\ ))\n (princ (aref res i)))\n (terpri)))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven are a prime number p and a sequence of p integers a_0, \\ldots, a_{p-1} consisting of zeros and ones.\n\nFind a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \\ldots + b_0, satisfying the following conditions:\n\nFor each i (0 \\leq i \\leq p-1), b_i is an integer such that 0 \\leq b_i \\leq p-1.\n\nFor each i (0 \\leq i \\leq p-1), f(i) \\equiv a_i \\pmod p.\n\nConstraints\n\n2 \\leq p \\leq 2999\n\np is a prime number.\n\n0 \\leq a_i \\leq 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\np\na_0 a_1 \\ldots a_{p-1}\n\nOutput\n\nPrint b_0, b_1, \\ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.\n\nIt can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.\n\nSample Input 1\n\n2\n1 0\n\nSample Output 1\n\n1 1\n\nf(x) = x + 1 satisfies the conditions, as follows:\n\nf(0) = 0 + 1 = 1 \\equiv 1 \\pmod 2\n\nf(1) = 1 + 1 = 2 \\equiv 0 \\pmod 2\n\nSample Input 2\n\n3\n0 0 0\n\nSample Output 2\n\n0 0 0\n\nf(x) = 0 is also valid.\n\nSample Input 3\n\n5\n0 1 0 1 0\n\nSample Output 3\n\n0 2 0 1 3", "sample_input": "2\n1 0\n"}, "reference_outputs": ["1 1\n"], "source_document_id": "p02950", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are a prime number p and a sequence of p integers a_0, \\ldots, a_{p-1} consisting of zeros and ones.\n\nFind a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \\ldots + b_0, satisfying the following conditions:\n\nFor each i (0 \\leq i \\leq p-1), b_i is an integer such that 0 \\leq b_i \\leq p-1.\n\nFor each i (0 \\leq i \\leq p-1), f(i) \\equiv a_i \\pmod p.\n\nConstraints\n\n2 \\leq p \\leq 2999\n\np is a prime number.\n\n0 \\leq a_i \\leq 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\np\na_0 a_1 \\ldots a_{p-1}\n\nOutput\n\nPrint b_0, b_1, \\ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.\n\nIt can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.\n\nSample Input 1\n\n2\n1 0\n\nSample Output 1\n\n1 1\n\nf(x) = x + 1 satisfies the conditions, as follows:\n\nf(0) = 0 + 1 = 1 \\equiv 1 \\pmod 2\n\nf(1) = 1 + 1 = 2 \\equiv 0 \\pmod 2\n\nSample Input 2\n\n3\n0 0 0\n\nSample Output 2\n\n0 0 0\n\nf(x) = 0 is also valid.\n\nSample Input 3\n\n5\n0 1 0 1 0\n\nSample Output 3\n\n0 2 0 1 3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 12298, "cpu_time_ms": 1639, "memory_kb": 35304}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s558955627", "group_id": "codeNet:p02950", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Modular arithmetic\n;;;\n\n(declaim (ftype (function * (values fixnum fixnum &optional)) %gcd))\n(defun %gcd (a b)\n (declare (optimize (speed 3) (safety 0))\n (fixnum a b))\n (if (zerop b)\n (values 1 0)\n (multiple-value-bind (p q) (floor a b) ; a = pb + q\n (multiple-value-bind (v u) (%gcd b q)\n (declare (fixnum u v))\n (values u (the fixnum (- v (the fixnum (* p u)))))))))\n\n(declaim (ftype (function * (values (mod #.most-positive-fixnum) &optional)) mod-inverse))\n(defun mod-inverse (a modulus)\n \"Solves ax ≡ 1 mod m. A and M must be coprime.\"\n (declare #.OPT\n ((unsigned-byte 32) a modulus))\n (mod (%gcd (mod a modulus) modulus) modulus))\n\n(deftype fft-float () 'double-float)\n\n(declaim (inline power2-p))\n(defun power2-p (x)\n \"Checks if X is a power of 2.\"\n (zerop (logand x (- x 1))))\n\n;; For FFT of fixed length, preparing the table of cos(i*theta) and sin\n;; (i*theta) will be efficient.\n(defun %make-trifunc-table (n)\n (declare (optimize (speed 3) (safety 0))\n ((integer 0 #.most-positive-fixnum) n))\n (assert (power2-p n))\n (let* ((cos-table (make-array (ash n -2) :element-type 'fft-float))\n (sin-table (make-array (ash n -2) :element-type 'fft-float))\n (theta (/ (coerce (* 2 pi) 'fft-float) n)))\n (dotimes (i (ash n -2))\n (setf (aref cos-table i) (cos (* i theta))\n (aref sin-table i) (sin (* i theta))))\n (values cos-table sin-table)))\n\n(defparameter *cos-table* nil)\n(defparameter *sin-table* nil)\n\n(defmacro with-fixed-length-fft (size &body body)\n \"Makes FFT faster when the SIZE of target vectors is fixed in BODY. This macro\ncomputes and holds the roots of unity for SIZE, which DFT! and INVERSE-DFT!\ncalled in BODY automatically detects; they will signal an error when they\nreceive a vector of different size.\"\n (let ((s (gensym)))\n `(let ((,s ,size))\n (multiple-value-bind (*cos-table* *sin-table*) (%make-trifunc-table ,s)\n ,@body))))\n\n(defun %dft-fixed-base! (f)\n (declare (optimize (speed 3) (safety 0))\n ((simple-array fft-float (*)) f))\n (prog1 f\n (let* ((n (length f))\n (cos-table *cos-table*)\n (sin-table *sin-table*)\n (factor n))\n (declare ((integer 0 #.most-positive-fixnum) factor)\n ((simple-array fft-float (*)) cos-table sin-table))\n (assert (power2-p n))\n (assert (= (ash n -2) (length cos-table)))\n ;; bit-reverse ordering\n (let ((i 0))\n (declare ((integer 0 #.most-positive-fixnum) i))\n (loop for j from 1 below (- n 1)\n do (loop for k of-type (integer 0 #.most-positive-fixnum)\n = (ash n -1) then (ash k -1)\n while (> k (setq i (logxor i k))))\n (when (< j i)\n (rotatef (aref f i) (aref f j)))))\n (do* ((mh 1 m)\n (m (ash mh 1) (ash mh 1)))\n ((> m n))\n (declare ((integer 0 #.most-positive-fixnum) mh m))\n (let ((mq (ash mh -1)))\n (setq factor (ash factor -1))\n (do ((jr 0 (+ jr m)))\n ((>= jr n))\n (declare ((integer 0 #.most-positive-fixnum) jr))\n (let ((xreal (aref f (+ jr mh))))\n (setf (aref f (+ jr mh)) (- (aref f jr) xreal))\n (incf (aref f jr) xreal)))\n (do ((i 1 (+ i 1)))\n ((>= i mq))\n (declare ((integer 0 #.most-positive-fixnum) i))\n (let* ((index (the fixnum (* factor i)))\n (wreal (aref cos-table index))\n (wimag (- (aref sin-table index))))\n (do ((j 0 (+ j m)))\n ((>= j n))\n (let* ((j+mh (+ j mh))\n (j+m-i (- (+ j m) i))\n (xreal (+ (* wreal (aref f (+ j+mh i)))\n (* wimag (aref f j+m-i))))\n (ximag (- (* wreal (aref f j+m-i))\n (* wimag (aref f (+ j+mh i))))))\n (declare ((integer 0 #.most-positive-fixnum) j+mh j+m-i))\n (setf (aref f (+ j+mh i))\n (+ (- (aref f (- j+mh i))) ximag))\n (setf (aref f j+m-i)\n (+ (aref f (- j+mh i)) ximag))\n (setf (aref f (- j+mh i))\n (+ (aref f (+ j i)) (- xreal)))\n (incf (aref f (+ j i)) xreal))))))))))\n\n(defun %inverse-dft-fixed-base! (f)\n (declare (optimize (speed 3) (safety 0))\n ((simple-array fft-float (*)) f))\n (prog1 f\n (let* ((n (length f))\n (cos-table *cos-table*)\n (sin-table *sin-table*)\n (factor 1))\n (declare ((integer 0 #.most-positive-fixnum) factor)\n ((simple-array fft-float (*)) cos-table sin-table))\n (assert (power2-p n))\n (assert (= (ash n -2) (length cos-table)))\n (setf (aref f 0)\n (/ (aref f 0) 2))\n (setf (aref f (ash n -1))\n (/ (aref f (ash n -1)) 2))\n (do* ((m n mh)\n (mh (ash m -1) (ash m -1)))\n ((zerop mh))\n (declare ((integer 0 #.most-positive-fixnum) m mh))\n (let ((mq (ash mh -1)))\n (do ((jr 0 (+ jr m)))\n ((>= jr n))\n (declare ((integer 0 #.most-positive-fixnum) jr))\n (let ((xreal (- (aref f jr) (aref f (+ jr mh)))))\n (incf (aref f jr) (aref f (+ jr mh)))\n (setf (aref f (+ jr mh)) xreal)))\n (do ((i 1 (+ i 1)))\n ((>= i mq))\n (let* ((index (the fixnum (* factor i)))\n (wreal (aref cos-table index))\n (wimag (aref sin-table index)))\n (do ((j 0 (+ j m)))\n ((>= j n))\n (let* ((j+mh (+ j mh))\n (j+m-i (- (+ j m) i))\n (xreal (- (aref f (+ j i)) (aref f (- j+mh i))))\n (ximag (+ (aref f j+m-i) (aref f (+ j+mh i)))))\n (declare ((integer 0 #.most-positive-fixnum) j+mh j+m-i))\n (incf (aref f (+ j i)) (aref f (- j+mh i)))\n (setf (aref f (- j+mh i))\n (- (aref f j+m-i) (aref f (+ j+mh i))))\n (setf (aref f (+ j+mh i))\n (+ (* wreal xreal) (* wimag ximag)))\n (setf (aref f j+m-i)\n (- (* wreal ximag) (* wimag xreal))))))))\n (setq factor (ash factor 1)))\n ;; bit-reverse ordering\n (let ((i 0))\n (declare ((integer 0 #.most-positive-fixnum) i))\n (loop for j from 1 below (- n 1)\n do (loop for k of-type (integer 0 #.most-positive-fixnum)\n = (ash n -1) then (ash k -1)\n while (> k (setq i (logxor i k))))\n (when (< j i)\n (rotatef (aref f i) (aref f j))))))))\n\n(declaim (inline dft!))\n(defun dft! (f)\n (declare ((simple-array fft-float (*)) f))\n (if (zerop (length f))\n f\n (if *cos-table*\n (%dft-fixed-base! f)\n (error \"Huh?\"))))\n\n(declaim (inline inverse-dft!))\n(defun inverse-dft! (f)\n (declare ((simple-array fft-float (*)) f))\n (prog1 f\n (let ((n (length f)))\n (unless (zerop n)\n (let ((factor (* 2 (/ (coerce n 'fft-float)))))\n (if *cos-table*\n (%inverse-dft-fixed-base! f)\n (error \"Huh?\"))\n (dotimes (i n)\n (setf (aref f i) (* (aref f i) factor))))))))\n\n(declaim (inline convolute!))\n(defun convolute! (g h &optional result-vector)\n \"Returns the convolution of two vectors G and H. A new vector is created when\nRESULT-VECTOR is null. This function destructively modifies G and H. (They can\nbe restored by INVERSE-DFT!.)\"\n (declare ((simple-array fft-float (*)) g h)\n ((or null (simple-array fft-float (*))) result-vector))\n (let ((n (length g)))\n (assert (and (power2-p n)\n (= n (length h))))\n (dft! g)\n (dft! h)\n (let ((f (or result-vector (make-array n :element-type 'fft-float))))\n (unless (zerop n)\n (setf (aref f 0)\n (* (aref g 0) (aref h 0)))\n (setf (aref f (ash n -1))\n (* (aref g (ash n -1)) (aref h (ash n -1)))))\n (loop for i from 1 below (ash n -1)\n for value1 of-type fft-float\n = (- (* (aref g i) (aref h i))\n (* (aref g (- n i)) (aref h (- n i))))\n for value2 of-type fft-float\n = (+ (* (aref g i) (aref h (- n i)))\n (* (aref g (- n i)) (aref h i)))\n do (setf (aref f i) value1)\n (setf (aref f (- n i)) value2))\n (inverse-dft! f))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(declaim (inline poly-value))\n(defun poly-value (poly input divisor)\n (let ((x^i 1)\n (res 0))\n (declare (fixnum x^i res))\n (dotimes (i (length poly))\n (setq res (mod (+ res (* x^i (aref poly i))) divisor))\n (setq x^i (mod (* x^i input) divisor)))\n res))\n\n(defconstant +fft-size+ 4096)\n(defun main ()\n (declare #.OPT)\n (let* ((p (read))\n ;; table of the indices such that a_i = 1\n (table1 (make-hash-table)))\n (declare (uint16 p))\n (dotimes (i p)\n (when (= (the bit (read)) 1)\n (setf (gethash i table1) t)))\n (let ((res (make-array +fft-size+ :element-type 'uint16 :initial-element 0))\n (basef (make-array +fft-size+ :element-type 'double-float :initial-element 0d0))\n (base (make-array +fft-size+ :element-type 'uint16 :initial-element 0))\n (multiplier (make-array +fft-size+ :element-type 'double-float))\n (quot (make-array p :element-type 'uint16)))\n (setf (aref basef 0) 1d0)\n (with-fixed-length-fft +fft-size+\n (dotimes (i p)\n (fill multiplier 0d0)\n (setf (aref multiplier 0) (float (- i) 1d0))\n (setf (aref multiplier 1) 1d0)\n (convolute! basef multiplier basef)\n (dotimes (i +fft-size+)\n (setf (aref basef i)\n (float (mod (the fixnum (round (aref basef i))) p) 1d0)))))\n (dotimes (i +fft-size+)\n (setf (aref base i) (round (aref basef i))))\n (dotimes (pivot p)\n (when (gethash pivot table1)\n (fill quot 0)\n (setf (aref quot (- p 1)) (aref base p))\n (loop for i from (- p 2) downto 0\n do (setf (aref quot i)\n (mod (+ (aref base (+ i 1))\n (* pivot (aref quot (+ i 1))))\n p)))\n (let ((factor (mod-inverse (poly-value quot pivot p) p)))\n (declare (uint16 factor))\n (dotimes (i p)\n (setf (aref quot i)\n (mod (* factor (aref quot i)) p))))\n (dotimes (i p)\n (setf (aref res i)\n (mod (+ (aref res i) (aref quot i)) p)))))\n (let ((init t))\n (dotimes (i p)\n (if init (setq init nil) (write-char #\\ ))\n (princ (aref res i)))\n (terpri)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1565509165, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02950.html", "problem_id": "p02950", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02950/input.txt", "sample_output_relpath": "derived/input_output/data/p02950/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02950/Lisp/s558955627.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s558955627", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1 1\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Modular arithmetic\n;;;\n\n(declaim (ftype (function * (values fixnum fixnum &optional)) %gcd))\n(defun %gcd (a b)\n (declare (optimize (speed 3) (safety 0))\n (fixnum a b))\n (if (zerop b)\n (values 1 0)\n (multiple-value-bind (p q) (floor a b) ; a = pb + q\n (multiple-value-bind (v u) (%gcd b q)\n (declare (fixnum u v))\n (values u (the fixnum (- v (the fixnum (* p u)))))))))\n\n(declaim (ftype (function * (values (mod #.most-positive-fixnum) &optional)) mod-inverse))\n(defun mod-inverse (a modulus)\n \"Solves ax ≡ 1 mod m. A and M must be coprime.\"\n (declare #.OPT\n ((unsigned-byte 32) a modulus))\n (mod (%gcd (mod a modulus) modulus) modulus))\n\n(deftype fft-float () 'double-float)\n\n(declaim (inline power2-p))\n(defun power2-p (x)\n \"Checks if X is a power of 2.\"\n (zerop (logand x (- x 1))))\n\n;; For FFT of fixed length, preparing the table of cos(i*theta) and sin\n;; (i*theta) will be efficient.\n(defun %make-trifunc-table (n)\n (declare (optimize (speed 3) (safety 0))\n ((integer 0 #.most-positive-fixnum) n))\n (assert (power2-p n))\n (let* ((cos-table (make-array (ash n -2) :element-type 'fft-float))\n (sin-table (make-array (ash n -2) :element-type 'fft-float))\n (theta (/ (coerce (* 2 pi) 'fft-float) n)))\n (dotimes (i (ash n -2))\n (setf (aref cos-table i) (cos (* i theta))\n (aref sin-table i) (sin (* i theta))))\n (values cos-table sin-table)))\n\n(defparameter *cos-table* nil)\n(defparameter *sin-table* nil)\n\n(defmacro with-fixed-length-fft (size &body body)\n \"Makes FFT faster when the SIZE of target vectors is fixed in BODY. This macro\ncomputes and holds the roots of unity for SIZE, which DFT! and INVERSE-DFT!\ncalled in BODY automatically detects; they will signal an error when they\nreceive a vector of different size.\"\n (let ((s (gensym)))\n `(let ((,s ,size))\n (multiple-value-bind (*cos-table* *sin-table*) (%make-trifunc-table ,s)\n ,@body))))\n\n(defun %dft-fixed-base! (f)\n (declare (optimize (speed 3) (safety 0))\n ((simple-array fft-float (*)) f))\n (prog1 f\n (let* ((n (length f))\n (cos-table *cos-table*)\n (sin-table *sin-table*)\n (factor n))\n (declare ((integer 0 #.most-positive-fixnum) factor)\n ((simple-array fft-float (*)) cos-table sin-table))\n (assert (power2-p n))\n (assert (= (ash n -2) (length cos-table)))\n ;; bit-reverse ordering\n (let ((i 0))\n (declare ((integer 0 #.most-positive-fixnum) i))\n (loop for j from 1 below (- n 1)\n do (loop for k of-type (integer 0 #.most-positive-fixnum)\n = (ash n -1) then (ash k -1)\n while (> k (setq i (logxor i k))))\n (when (< j i)\n (rotatef (aref f i) (aref f j)))))\n (do* ((mh 1 m)\n (m (ash mh 1) (ash mh 1)))\n ((> m n))\n (declare ((integer 0 #.most-positive-fixnum) mh m))\n (let ((mq (ash mh -1)))\n (setq factor (ash factor -1))\n (do ((jr 0 (+ jr m)))\n ((>= jr n))\n (declare ((integer 0 #.most-positive-fixnum) jr))\n (let ((xreal (aref f (+ jr mh))))\n (setf (aref f (+ jr mh)) (- (aref f jr) xreal))\n (incf (aref f jr) xreal)))\n (do ((i 1 (+ i 1)))\n ((>= i mq))\n (declare ((integer 0 #.most-positive-fixnum) i))\n (let* ((index (the fixnum (* factor i)))\n (wreal (aref cos-table index))\n (wimag (- (aref sin-table index))))\n (do ((j 0 (+ j m)))\n ((>= j n))\n (let* ((j+mh (+ j mh))\n (j+m-i (- (+ j m) i))\n (xreal (+ (* wreal (aref f (+ j+mh i)))\n (* wimag (aref f j+m-i))))\n (ximag (- (* wreal (aref f j+m-i))\n (* wimag (aref f (+ j+mh i))))))\n (declare ((integer 0 #.most-positive-fixnum) j+mh j+m-i))\n (setf (aref f (+ j+mh i))\n (+ (- (aref f (- j+mh i))) ximag))\n (setf (aref f j+m-i)\n (+ (aref f (- j+mh i)) ximag))\n (setf (aref f (- j+mh i))\n (+ (aref f (+ j i)) (- xreal)))\n (incf (aref f (+ j i)) xreal))))))))))\n\n(defun %inverse-dft-fixed-base! (f)\n (declare (optimize (speed 3) (safety 0))\n ((simple-array fft-float (*)) f))\n (prog1 f\n (let* ((n (length f))\n (cos-table *cos-table*)\n (sin-table *sin-table*)\n (factor 1))\n (declare ((integer 0 #.most-positive-fixnum) factor)\n ((simple-array fft-float (*)) cos-table sin-table))\n (assert (power2-p n))\n (assert (= (ash n -2) (length cos-table)))\n (setf (aref f 0)\n (/ (aref f 0) 2))\n (setf (aref f (ash n -1))\n (/ (aref f (ash n -1)) 2))\n (do* ((m n mh)\n (mh (ash m -1) (ash m -1)))\n ((zerop mh))\n (declare ((integer 0 #.most-positive-fixnum) m mh))\n (let ((mq (ash mh -1)))\n (do ((jr 0 (+ jr m)))\n ((>= jr n))\n (declare ((integer 0 #.most-positive-fixnum) jr))\n (let ((xreal (- (aref f jr) (aref f (+ jr mh)))))\n (incf (aref f jr) (aref f (+ jr mh)))\n (setf (aref f (+ jr mh)) xreal)))\n (do ((i 1 (+ i 1)))\n ((>= i mq))\n (let* ((index (the fixnum (* factor i)))\n (wreal (aref cos-table index))\n (wimag (aref sin-table index)))\n (do ((j 0 (+ j m)))\n ((>= j n))\n (let* ((j+mh (+ j mh))\n (j+m-i (- (+ j m) i))\n (xreal (- (aref f (+ j i)) (aref f (- j+mh i))))\n (ximag (+ (aref f j+m-i) (aref f (+ j+mh i)))))\n (declare ((integer 0 #.most-positive-fixnum) j+mh j+m-i))\n (incf (aref f (+ j i)) (aref f (- j+mh i)))\n (setf (aref f (- j+mh i))\n (- (aref f j+m-i) (aref f (+ j+mh i))))\n (setf (aref f (+ j+mh i))\n (+ (* wreal xreal) (* wimag ximag)))\n (setf (aref f j+m-i)\n (- (* wreal ximag) (* wimag xreal))))))))\n (setq factor (ash factor 1)))\n ;; bit-reverse ordering\n (let ((i 0))\n (declare ((integer 0 #.most-positive-fixnum) i))\n (loop for j from 1 below (- n 1)\n do (loop for k of-type (integer 0 #.most-positive-fixnum)\n = (ash n -1) then (ash k -1)\n while (> k (setq i (logxor i k))))\n (when (< j i)\n (rotatef (aref f i) (aref f j))))))))\n\n(declaim (inline dft!))\n(defun dft! (f)\n (declare ((simple-array fft-float (*)) f))\n (if (zerop (length f))\n f\n (if *cos-table*\n (%dft-fixed-base! f)\n (error \"Huh?\"))))\n\n(declaim (inline inverse-dft!))\n(defun inverse-dft! (f)\n (declare ((simple-array fft-float (*)) f))\n (prog1 f\n (let ((n (length f)))\n (unless (zerop n)\n (let ((factor (* 2 (/ (coerce n 'fft-float)))))\n (if *cos-table*\n (%inverse-dft-fixed-base! f)\n (error \"Huh?\"))\n (dotimes (i n)\n (setf (aref f i) (* (aref f i) factor))))))))\n\n(declaim (inline convolute!))\n(defun convolute! (g h &optional result-vector)\n \"Returns the convolution of two vectors G and H. A new vector is created when\nRESULT-VECTOR is null. This function destructively modifies G and H. (They can\nbe restored by INVERSE-DFT!.)\"\n (declare ((simple-array fft-float (*)) g h)\n ((or null (simple-array fft-float (*))) result-vector))\n (let ((n (length g)))\n (assert (and (power2-p n)\n (= n (length h))))\n (dft! g)\n (dft! h)\n (let ((f (or result-vector (make-array n :element-type 'fft-float))))\n (unless (zerop n)\n (setf (aref f 0)\n (* (aref g 0) (aref h 0)))\n (setf (aref f (ash n -1))\n (* (aref g (ash n -1)) (aref h (ash n -1)))))\n (loop for i from 1 below (ash n -1)\n for value1 of-type fft-float\n = (- (* (aref g i) (aref h i))\n (* (aref g (- n i)) (aref h (- n i))))\n for value2 of-type fft-float\n = (+ (* (aref g i) (aref h (- n i)))\n (* (aref g (- n i)) (aref h i)))\n do (setf (aref f i) value1)\n (setf (aref f (- n i)) value2))\n (inverse-dft! f))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(declaim (inline poly-value))\n(defun poly-value (poly input divisor)\n (let ((x^i 1)\n (res 0))\n (declare (fixnum x^i res))\n (dotimes (i (length poly))\n (setq res (mod (+ res (* x^i (aref poly i))) divisor))\n (setq x^i (mod (* x^i input) divisor)))\n res))\n\n(defconstant +fft-size+ 4096)\n(defun main ()\n (declare #.OPT)\n (let* ((p (read))\n ;; table of the indices such that a_i = 1\n (table1 (make-hash-table)))\n (declare (uint16 p))\n (dotimes (i p)\n (when (= (the bit (read)) 1)\n (setf (gethash i table1) t)))\n (let ((res (make-array +fft-size+ :element-type 'uint16 :initial-element 0))\n (basef (make-array +fft-size+ :element-type 'double-float :initial-element 0d0))\n (base (make-array +fft-size+ :element-type 'uint16 :initial-element 0))\n (multiplier (make-array +fft-size+ :element-type 'double-float))\n (quot (make-array p :element-type 'uint16)))\n (setf (aref basef 0) 1d0)\n (with-fixed-length-fft +fft-size+\n (dotimes (i p)\n (fill multiplier 0d0)\n (setf (aref multiplier 0) (float (- i) 1d0))\n (setf (aref multiplier 1) 1d0)\n (convolute! basef multiplier basef)\n (dotimes (i +fft-size+)\n (setf (aref basef i)\n (float (mod (the fixnum (round (aref basef i))) p) 1d0)))))\n (dotimes (i +fft-size+)\n (setf (aref base i) (round (aref basef i))))\n (dotimes (pivot p)\n (when (gethash pivot table1)\n (fill quot 0)\n (setf (aref quot (- p 1)) (aref base p))\n (loop for i from (- p 2) downto 0\n do (setf (aref quot i)\n (mod (+ (aref base (+ i 1))\n (* pivot (aref quot (+ i 1))))\n p)))\n (let ((factor (mod-inverse (poly-value quot pivot p) p)))\n (declare (uint16 factor))\n (dotimes (i p)\n (setf (aref quot i)\n (mod (* factor (aref quot i)) p))))\n (dotimes (i p)\n (setf (aref res i)\n (mod (+ (aref res i) (aref quot i)) p)))))\n (let ((init t))\n (dotimes (i p)\n (if init (setq init nil) (write-char #\\ ))\n (princ (aref res i)))\n (terpri)))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven are a prime number p and a sequence of p integers a_0, \\ldots, a_{p-1} consisting of zeros and ones.\n\nFind a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \\ldots + b_0, satisfying the following conditions:\n\nFor each i (0 \\leq i \\leq p-1), b_i is an integer such that 0 \\leq b_i \\leq p-1.\n\nFor each i (0 \\leq i \\leq p-1), f(i) \\equiv a_i \\pmod p.\n\nConstraints\n\n2 \\leq p \\leq 2999\n\np is a prime number.\n\n0 \\leq a_i \\leq 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\np\na_0 a_1 \\ldots a_{p-1}\n\nOutput\n\nPrint b_0, b_1, \\ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.\n\nIt can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.\n\nSample Input 1\n\n2\n1 0\n\nSample Output 1\n\n1 1\n\nf(x) = x + 1 satisfies the conditions, as follows:\n\nf(0) = 0 + 1 = 1 \\equiv 1 \\pmod 2\n\nf(1) = 1 + 1 = 2 \\equiv 0 \\pmod 2\n\nSample Input 2\n\n3\n0 0 0\n\nSample Output 2\n\n0 0 0\n\nf(x) = 0 is also valid.\n\nSample Input 3\n\n5\n0 1 0 1 0\n\nSample Output 3\n\n0 2 0 1 3", "sample_input": "2\n1 0\n"}, "reference_outputs": ["1 1\n"], "source_document_id": "p02950", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are a prime number p and a sequence of p integers a_0, \\ldots, a_{p-1} consisting of zeros and ones.\n\nFind a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \\ldots + b_0, satisfying the following conditions:\n\nFor each i (0 \\leq i \\leq p-1), b_i is an integer such that 0 \\leq b_i \\leq p-1.\n\nFor each i (0 \\leq i \\leq p-1), f(i) \\equiv a_i \\pmod p.\n\nConstraints\n\n2 \\leq p \\leq 2999\n\np is a prime number.\n\n0 \\leq a_i \\leq 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\np\na_0 a_1 \\ldots a_{p-1}\n\nOutput\n\nPrint b_0, b_1, \\ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.\n\nIt can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.\n\nSample Input 1\n\n2\n1 0\n\nSample Output 1\n\n1 1\n\nf(x) = x + 1 satisfies the conditions, as follows:\n\nf(0) = 0 + 1 = 1 \\equiv 1 \\pmod 2\n\nf(1) = 1 + 1 = 2 \\equiv 0 \\pmod 2\n\nSample Input 2\n\n3\n0 0 0\n\nSample Output 2\n\n0 0 0\n\nf(x) = 0 is also valid.\n\nSample Input 3\n\n5\n0 1 0 1 0\n\nSample Output 3\n\n0 2 0 1 3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 12304, "cpu_time_ms": 1679, "memory_kb": 44392}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s695139677", "group_id": "codeNet:p02951", "input_text": "(defun f(a b c)\n (let ((r (- c (- a b))))\n\t(if (< r 0)\n\t 0\n\t r)))\n\n(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(defun g()\n (let* ((line (read-line nil nil))\n\t\t (splited (mapcar #'parse-integer (splitat #\\space line))))\n (format t \"~A~%\" (f (car splited) (cadr splited) (caddr splited)))))\n(g)\n", "language": "Lisp", "metadata": {"date": 1564967148, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02951.html", "problem_id": "p02951", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02951/input.txt", "sample_output_relpath": "derived/input_output/data/p02951/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02951/Lisp/s695139677.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s695139677", "user_id": "u254205055"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun f(a b c)\n (let ((r (- c (- a b))))\n\t(if (< r 0)\n\t 0\n\t r)))\n\n(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(defun g()\n (let* ((line (read-line nil nil))\n\t\t (splited (mapcar #'parse-integer (splitat #\\space line))))\n (format t \"~A~%\" (f (car splited) (cadr splited) (caddr splited)))))\n(g)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe have two bottles for holding water.\n\nBottle 1 can hold up to A milliliters of water, and now it contains B milliliters of water.\n\nBottle 2 contains C milliliters of water.\n\nWe will transfer water from Bottle 2 to Bottle 1 as much as possible.\n\nHow much amount of water will remain in Bottle 2?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq B \\leq A \\leq 20\n\n1 \\leq C \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the integer representing the amount of water, in milliliters, that will remain in Bottle 2.\n\nSample Input 1\n\n6 4 3\n\nSample Output 1\n\n1\n\nWe will transfer two milliliters of water from Bottle 2 to Bottle 1, and one milliliter of water will remain in Bottle 2.\n\nSample Input 2\n\n8 3 9\n\nSample Output 2\n\n4\n\nSample Input 3\n\n12 3 7\n\nSample Output 3\n\n0", "sample_input": "6 4 3\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02951", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe have two bottles for holding water.\n\nBottle 1 can hold up to A milliliters of water, and now it contains B milliliters of water.\n\nBottle 2 contains C milliliters of water.\n\nWe will transfer water from Bottle 2 to Bottle 1 as much as possible.\n\nHow much amount of water will remain in Bottle 2?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq B \\leq A \\leq 20\n\n1 \\leq C \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the integer representing the amount of water, in milliliters, that will remain in Bottle 2.\n\nSample Input 1\n\n6 4 3\n\nSample Output 1\n\n1\n\nWe will transfer two milliliters of water from Bottle 2 to Bottle 1, and one milliliter of water will remain in Bottle 2.\n\nSample Input 2\n\n8 3 9\n\nSample Output 2\n\n4\n\nSample Input 3\n\n12 3 7\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 502, "cpu_time_ms": 134, "memory_kb": 13024}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s398586193", "group_id": "codeNet:p02951", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((a (read))\n (b (read))\n (c (read)))\n (println (max 0 (- c (- a b))))))\n\n#-swank (main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &optional (func #'main))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNC, and returns true if the\nstring output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (equal (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall func)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n (let ((*standard-output* out))\n (etypecase thing\n (null ; Runs #'MAIN with the string on clipboard\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname ; Runs #'MAIN with the string in a text file\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n", "language": "Lisp", "metadata": {"date": 1564966867, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02951.html", "problem_id": "p02951", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02951/input.txt", "sample_output_relpath": "derived/input_output/data/p02951/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02951/Lisp/s398586193.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s398586193", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((a (read))\n (b (read))\n (c (read)))\n (println (max 0 (- c (- a b))))))\n\n#-swank (main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &optional (func #'main))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNC, and returns true if the\nstring output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (equal (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall func)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n (let ((*standard-output* out))\n (etypecase thing\n (null ; Runs #'MAIN with the string on clipboard\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname ; Runs #'MAIN with the string in a text file\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe have two bottles for holding water.\n\nBottle 1 can hold up to A milliliters of water, and now it contains B milliliters of water.\n\nBottle 2 contains C milliliters of water.\n\nWe will transfer water from Bottle 2 to Bottle 1 as much as possible.\n\nHow much amount of water will remain in Bottle 2?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq B \\leq A \\leq 20\n\n1 \\leq C \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the integer representing the amount of water, in milliliters, that will remain in Bottle 2.\n\nSample Input 1\n\n6 4 3\n\nSample Output 1\n\n1\n\nWe will transfer two milliliters of water from Bottle 2 to Bottle 1, and one milliliter of water will remain in Bottle 2.\n\nSample Input 2\n\n8 3 9\n\nSample Output 2\n\n4\n\nSample Input 3\n\n12 3 7\n\nSample Output 3\n\n0", "sample_input": "6 4 3\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02951", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe have two bottles for holding water.\n\nBottle 1 can hold up to A milliliters of water, and now it contains B milliliters of water.\n\nBottle 2 contains C milliliters of water.\n\nWe will transfer water from Bottle 2 to Bottle 1 as much as possible.\n\nHow much amount of water will remain in Bottle 2?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq B \\leq A \\leq 20\n\n1 \\leq C \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the integer representing the amount of water, in milliliters, that will remain in Bottle 2.\n\nSample Input 1\n\n6 4 3\n\nSample Output 1\n\n1\n\nWe will transfer two milliliters of water from Bottle 2 to Bottle 1, and one milliliter of water will remain in Bottle 2.\n\nSample Input 2\n\n8 3 9\n\nSample Output 2\n\n4\n\nSample Input 3\n\n12 3 7\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3083, "cpu_time_ms": 230, "memory_kb": 15204}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s188265838", "group_id": "codeNet:p02952", "input_text": "(let ((n (read))\n (ans 0))\n (loop :for i :from 1 :to n\n :if (oddp (1+ (floor (log i 10))))\n :do (incf ans))\n (format t \"~A~%\" ans))\n", "language": "Lisp", "metadata": {"date": 1598139590, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02952.html", "problem_id": "p02952", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02952/input.txt", "sample_output_relpath": "derived/input_output/data/p02952/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02952/Lisp/s188265838.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s188265838", "user_id": "u608227593"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(let ((n (read))\n (ans 0))\n (loop :for i :from 1 :to n\n :if (oddp (1+ (floor (log i 10))))\n :do (incf ans))\n (format t \"~A~%\" ans))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros).\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the number of positive integers less than or equal to N that have an odd number of digits.\n\nSample Input 1\n\n11\n\nSample Output 1\n\n9\n\nAmong the positive integers less than or equal to 11, nine integers have an odd number of digits: 1, 2, \\ldots, 9.\n\nSample Input 2\n\n136\n\nSample Output 2\n\n46\n\nIn addition to 1, 2, \\ldots, 9, another 37 integers also have an odd number of digits: 100, 101, \\ldots, 136.\n\nSample Input 3\n\n100000\n\nSample Output 3\n\n90909", "sample_input": "11\n"}, "reference_outputs": ["9\n"], "source_document_id": "p02952", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros).\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the number of positive integers less than or equal to N that have an odd number of digits.\n\nSample Input 1\n\n11\n\nSample Output 1\n\n9\n\nAmong the positive integers less than or equal to 11, nine integers have an odd number of digits: 1, 2, \\ldots, 9.\n\nSample Input 2\n\n136\n\nSample Output 2\n\n46\n\nIn addition to 1, 2, \\ldots, 9, another 37 integers also have an odd number of digits: 100, 101, \\ldots, 136.\n\nSample Input 3\n\n100000\n\nSample Output 3\n\n90909", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 153, "cpu_time_ms": 50, "memory_kb": 38924}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s375261368", "group_id": "codeNet:p02952", "input_text": "\n(defun f(s)\n (let ((l (length s)))\n\t(cond ((= l 1) (parse-integer s))\n\t\t ((= l 2) 9)\n\t\t ((= l 3) (+ 9 (- (parse-integer s) 99)))\n\t\t ((= l 4) (+ 9 (- 999 99)))\n\t\t ((= l 5) (+ 9 (- 999 99) (- (parse-integer s) 9999)))\n\t\t (t (+ 9 (- 999 99) (- 99999 9999)))\n\t\t )))\n\n(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(defun g()\n (let* ((line (read-line nil nil)))\n (format t \"~A~%\" (f line))))\n(g)\n", "language": "Lisp", "metadata": {"date": 1564967990, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02952.html", "problem_id": "p02952", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02952/input.txt", "sample_output_relpath": "derived/input_output/data/p02952/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02952/Lisp/s375261368.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s375261368", "user_id": "u254205055"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "\n(defun f(s)\n (let ((l (length s)))\n\t(cond ((= l 1) (parse-integer s))\n\t\t ((= l 2) 9)\n\t\t ((= l 3) (+ 9 (- (parse-integer s) 99)))\n\t\t ((= l 4) (+ 9 (- 999 99)))\n\t\t ((= l 5) (+ 9 (- 999 99) (- (parse-integer s) 9999)))\n\t\t (t (+ 9 (- 999 99) (- 99999 9999)))\n\t\t )))\n\n(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(defun g()\n (let* ((line (read-line nil nil)))\n (format t \"~A~%\" (f line))))\n(g)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nGiven is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros).\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the number of positive integers less than or equal to N that have an odd number of digits.\n\nSample Input 1\n\n11\n\nSample Output 1\n\n9\n\nAmong the positive integers less than or equal to 11, nine integers have an odd number of digits: 1, 2, \\ldots, 9.\n\nSample Input 2\n\n136\n\nSample Output 2\n\n46\n\nIn addition to 1, 2, \\ldots, 9, another 37 integers also have an odd number of digits: 100, 101, \\ldots, 136.\n\nSample Input 3\n\n100000\n\nSample Output 3\n\n90909", "sample_input": "11\n"}, "reference_outputs": ["9\n"], "source_document_id": "p02952", "source_text": "Score : 200 points\n\nProblem Statement\n\nGiven is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros).\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the number of positive integers less than or equal to N that have an odd number of digits.\n\nSample Input 1\n\n11\n\nSample Output 1\n\n9\n\nAmong the positive integers less than or equal to 11, nine integers have an odd number of digits: 1, 2, \\ldots, 9.\n\nSample Input 2\n\n136\n\nSample Output 2\n\n46\n\nIn addition to 1, 2, \\ldots, 9, another 37 integers also have an odd number of digits: 100, 101, \\ldots, 136.\n\nSample Input 3\n\n100000\n\nSample Output 3\n\n90909", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 602, "cpu_time_ms": 218, "memory_kb": 12904}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s601010346", "group_id": "codeNet:p02955", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values (vector (integer 0 #.most-positive-fixnum)) &optional))\n enum-divisors))\n(defun enum-divisors (x)\n \"Enumerates all the divisors of X in O(sqrt(X)). Note that the resultant\nvector is NOT sorted.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) x))\n (let* ((sqrt (isqrt x))\n (res (make-array (isqrt sqrt) ; FIXME: sets the initial size to x^1/4\n :element-type '(integer 0 #.most-positive-fixnum)\n :fill-pointer 0)))\n (loop for i from 1 to sqrt\n do (multiple-value-bind (quot rem) (floor x i)\n (when (zerop rem)\n (vector-push-extend i res)\n (unless (= i quot)\n (vector-push-extend quot res)))))\n res))\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun calc-distance (div sum as)\n (declare ((simple-array uint32 (*)) as)\n (uint32 div sum)\n (inline sort))\n (let ((as (copy-seq as))\n (n (length as))\n (cumuls1 (make-array 501 :element-type 'uint62 :initial-element 0))\n (cumuls2 (make-array 501 :element-type 'uint62 :initial-element 0)))\n (declare (dynamic-extent cumuls1 cumuls2))\n (setf as (sort as (lambda (x y) (< (mod x div) (mod y div)))))\n (dotimes (i n)\n (setf (aref cumuls1 (+ i 1))\n (+ (aref cumuls1 i) (* div (floor (aref as i) div)))))\n (loop for i from (- n 1) downto 0\n do (setf (aref cumuls2 i)\n (+ (aref cumuls2 (+ i 1)) (* div (ceiling (aref as i) div)))))\n (loop for i to n\n when (= sum (+ (aref cumuls1 i) (aref cumuls2 i)))\n do (return (- (reduce #'+ as :end i) (aref cumuls1 i)))\n finally (error \"Huh?\"))))\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'uint32))\n (sum 0))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum))\n (incf sum (aref as i)))\n (let ((divs (enum-divisors sum)))\n (setf divs (sort divs #'>))\n (loop for d across divs\n when (<= (calc-distance d sum as) k)\n do (println d)\n (return-from main)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1565031755, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02955.html", "problem_id": "p02955", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02955/input.txt", "sample_output_relpath": "derived/input_output/data/p02955/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02955/Lisp/s601010346.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s601010346", "user_id": "u352600849"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values (vector (integer 0 #.most-positive-fixnum)) &optional))\n enum-divisors))\n(defun enum-divisors (x)\n \"Enumerates all the divisors of X in O(sqrt(X)). Note that the resultant\nvector is NOT sorted.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) x))\n (let* ((sqrt (isqrt x))\n (res (make-array (isqrt sqrt) ; FIXME: sets the initial size to x^1/4\n :element-type '(integer 0 #.most-positive-fixnum)\n :fill-pointer 0)))\n (loop for i from 1 to sqrt\n do (multiple-value-bind (quot rem) (floor x i)\n (when (zerop rem)\n (vector-push-extend i res)\n (unless (= i quot)\n (vector-push-extend quot res)))))\n res))\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun calc-distance (div sum as)\n (declare ((simple-array uint32 (*)) as)\n (uint32 div sum)\n (inline sort))\n (let ((as (copy-seq as))\n (n (length as))\n (cumuls1 (make-array 501 :element-type 'uint62 :initial-element 0))\n (cumuls2 (make-array 501 :element-type 'uint62 :initial-element 0)))\n (declare (dynamic-extent cumuls1 cumuls2))\n (setf as (sort as (lambda (x y) (< (mod x div) (mod y div)))))\n (dotimes (i n)\n (setf (aref cumuls1 (+ i 1))\n (+ (aref cumuls1 i) (* div (floor (aref as i) div)))))\n (loop for i from (- n 1) downto 0\n do (setf (aref cumuls2 i)\n (+ (aref cumuls2 (+ i 1)) (* div (ceiling (aref as i) div)))))\n (loop for i to n\n when (= sum (+ (aref cumuls1 i) (aref cumuls2 i)))\n do (return (- (reduce #'+ as :end i) (aref cumuls1 i)))\n finally (error \"Huh?\"))))\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'uint32))\n (sum 0))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum))\n (incf sum (aref as i)))\n (let ((divs (enum-divisors sum)))\n (setf divs (sort divs #'>))\n (loop for d across divs\n when (<= (calc-distance d sum as) k)\n do (println d)\n (return-from main)))))\n\n#-swank (main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nWe have a sequence of N integers: A_1, A_2, \\cdots, A_N.\n\nYou can perform the following operation between 0 and K times (inclusive):\n\nChoose two integers i and j such that i \\neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element.\n\nCompute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.\n\nConstraints\n\n2 \\leq N \\leq 500\n\n1 \\leq A_i \\leq 10^6\n\n0 \\leq K \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 \\cdots A_{N-1} A_{N}\n\nOutput\n\nPrint the maximum possible positive integer that divides every element of A after the operations.\n\nSample Input 1\n\n2 3\n8 20\n\nSample Output 1\n\n7\n\n7 will divide every element of A if, for example, we perform the following operation:\n\nChoose i = 2, j = 1. A becomes (7, 21).\n\nWe cannot reach the situation where 8 or greater integer divides every element of A.\n\nSample Input 2\n\n2 10\n3 5\n\nSample Output 2\n\n8\n\nConsider performing the following five operations:\n\nChoose i = 2, j = 1. A becomes (2, 6).\n\nChoose i = 2, j = 1. A becomes (1, 7).\n\nChoose i = 2, j = 1. A becomes (0, 8).\n\nChoose i = 2, j = 1. A becomes (-1, 9).\n\nChoose i = 1, j = 2. A becomes (0, 8).\n\nThen, 0 = 8 \\times 0 and 8 = 8 \\times 1, so 8 divides every element of A. We cannot reach the situation where 9 or greater integer divides every element of A.\n\nSample Input 3\n\n4 5\n10 1 2 22\n\nSample Output 3\n\n7\n\nSample Input 4\n\n8 7\n1 7 5 6 8 2 6 5\n\nSample Output 4\n\n5", "sample_input": "2 3\n8 20\n"}, "reference_outputs": ["7\n"], "source_document_id": "p02955", "source_text": "Score : 500 points\n\nProblem Statement\n\nWe have a sequence of N integers: A_1, A_2, \\cdots, A_N.\n\nYou can perform the following operation between 0 and K times (inclusive):\n\nChoose two integers i and j such that i \\neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element.\n\nCompute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.\n\nConstraints\n\n2 \\leq N \\leq 500\n\n1 \\leq A_i \\leq 10^6\n\n0 \\leq K \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 \\cdots A_{N-1} A_{N}\n\nOutput\n\nPrint the maximum possible positive integer that divides every element of A after the operations.\n\nSample Input 1\n\n2 3\n8 20\n\nSample Output 1\n\n7\n\n7 will divide every element of A if, for example, we perform the following operation:\n\nChoose i = 2, j = 1. A becomes (7, 21).\n\nWe cannot reach the situation where 8 or greater integer divides every element of A.\n\nSample Input 2\n\n2 10\n3 5\n\nSample Output 2\n\n8\n\nConsider performing the following five operations:\n\nChoose i = 2, j = 1. A becomes (2, 6).\n\nChoose i = 2, j = 1. A becomes (1, 7).\n\nChoose i = 2, j = 1. A becomes (0, 8).\n\nChoose i = 2, j = 1. A becomes (-1, 9).\n\nChoose i = 1, j = 2. A becomes (0, 8).\n\nThen, 0 = 8 \\times 0 and 8 = 8 \\times 1, so 8 divides every element of A. We cannot reach the situation where 9 or greater integer divides every element of A.\n\nSample Input 3\n\n4 5\n10 1 2 22\n\nSample Output 3\n\n7\n\nSample Input 4\n\n8 7\n1 7 5 6 8 2 6 5\n\nSample Output 4\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4541, "cpu_time_ms": 541, "memory_kb": 42084}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s875208259", "group_id": "codeNet:p02956", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; Treap accessible by index (O(log(n))).\n;; Virtually it works like std::set of C++ or TreeSet of Java. \n\n;; Note:\n;; - You shouldn't insert duplicate keys into a treap unless you know what you\n;; are doing.\n;; - You cannot rely on the side effect when you call any destructive operations\n;; on a treap. Always use the returned value.\n;; - An empty treap is NIL.\n\n(defstruct (treap (:constructor %make-treap (key priority &key left right (count 1)))\n (:copier nil)\n (:conc-name %treap-))\n (key 0 :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 0 :type (integer 0 #.most-positive-fixnum))\n (left nil :type (or null treap))\n (right nil :type (or null treap)))\n\n(declaim (inline treap-count))\n(defun treap-count (treap)\n \"Returns the size of the (nullable) TREAP.\"\n (declare ((or null treap) treap))\n (if (null treap)\n 0\n (%treap-count treap)))\n\n(declaim (inline update-count))\n(defun update-count (treap)\n (declare (treap treap))\n (setf (%treap-count treap)\n (+ 1\n (treap-count (%treap-left treap))\n (treap-count (%treap-right treap)))))\n\n(declaim (inline treap-bisect-left)\n (ftype (function * (values (integer 0 #.most-positive-fixnum) t &optional)) treap-bisect-left))\n(defun treap-bisect-left (value treap &key (order #'<))\n \"Returns the smallest index and the corresponding key that satisfies\nTREAP[index] >= VALUE. Returns the size of TREAP and VALUE if TREAP[size-1] <\nVALUE.\"\n (declare (function order))\n (labels ((recur (count treap)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null treap) (values nil nil))\n ((funcall order (%treap-key treap) value)\n (recur count (%treap-right treap)))\n (t (let ((left-count (- count (treap-count (%treap-right treap)) 1)))\n (multiple-value-bind (idx key)\n (recur left-count (%treap-left treap))\n (if idx\n (values idx key)\n (values left-count (%treap-key treap)))))))))\n (declare (ftype (function * (values t t &optional)) recur))\n (multiple-value-bind (idx key)\n (recur (treap-count treap) treap)\n (if idx\n (values idx key)\n (values (treap-count treap) value)))))\n\n(declaim (inline treap-split)\n (ftype (function * (values (or null treap) (or null treap) &optional)) treap-split))\n(defun treap-split (key treap &key (order #'<))\n \"Destructively splits the TREAP with reference to KEY and returns two treaps,\nthe smaller sub-treap (< KEY) and the larger one (>= KEY).\"\n (declare (function order)\n ((or null treap) treap))\n (labels ((recur (treap)\n (cond ((null treap)\n (values nil nil))\n ((funcall order (%treap-key treap) key)\n (multiple-value-bind (left right) (recur (%treap-right treap))\n (setf (%treap-right treap) left)\n (update-count treap)\n (values treap right)))\n (t\n (multiple-value-bind (left right) (recur (%treap-left treap))\n (setf (%treap-left treap) right)\n (update-count treap)\n (values left treap))))))\n (recur treap)))\n\n(declaim (inline treap-insert))\n(defun treap-insert (key treap &key (order #'<))\n \"Destructively inserts KEY into TREAP and returns the resultant treap.\"\n (declare ((or null treap) treap)\n (function order))\n (let ((node (%make-treap key (random most-positive-fixnum))))\n (labels ((recur (treap)\n (declare (treap node))\n (cond ((null treap) node)\n ((> (%treap-priority node) (%treap-priority treap))\n (setf (values (%treap-left node) (%treap-right node))\n (treap-split (%treap-key node) treap :order order))\n (update-count node)\n node)\n (t\n (if (funcall order (%treap-key node) (%treap-key treap))\n (setf (%treap-left treap)\n (recur (%treap-left treap)))\n (setf (%treap-right treap)\n (recur (%treap-right treap))))\n (update-count treap)\n treap))))\n (recur treap))))\n\n(defun treap-map (function treap)\n \"Successively applies FUNCTION to TREAP[0], ..., TREAP[SIZE-1]. FUNCTION must\ntake one argument.\"\n (declare (function function))\n (when treap\n (treap-map function (%treap-left treap))\n (funcall function (%treap-key treap))\n (treap-map function (%treap-right treap))))\n\n(defmethod print-object ((object treap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (treap-map (lambda (key)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write key :stream stream))\n object))))\n\n(define-condition invalid-treap-index-error (type-error)\n ((treap :initarg :treap :reader invalid-treap-index-error-treap)\n (index :initarg :index :reader invalid-treap-index-error-index))\n (:report\n (lambda (condition stream)\n (format stream \"Invalid index ~W for treap ~W.\"\n (invalid-treap-index-error-index condition)\n (invalid-treap-index-error-treap condition)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of lower_bound of C++ or bisect_left of Python: Returns the smallest\nindex (or input) i that fulfills TARGET[i] >= VALUE, where '>=' is the\ncomplement of ORDER. In other words, this function returns the leftmost index at\nwhich VALUE can be inserted with keeping the order. Therefore, TARGET must be\nmonotonically non-decreasing with respect to ORDER.\n\nThis function returns END if VALUE exceeds TARGET[END-1]. Note that the range\n[START, END) is half-open. END must be explicitly specified if TARGET is\nfunction. KEY is applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((body (accessor &optional declaration)\n `(progn\n (assert (<= start end))\n (if (= start end) end\n (labels\n ((%bisect-left (left ok)\n ;; TARGET[OK] >= VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(list declaration)\n (let ((mid (ash (+ left ok) -1)))\n (if (= mid left)\n (if (funcall order (funcall key (,accessor target left)) value)\n ok\n left)\n (if (funcall order (funcall key (,accessor target mid)) value)\n (%bisect-left mid ok)\n (%bisect-left left mid))))))\n (%bisect-left start end))))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (body aref (declare ((integer 0 #.most-positive-fixnum) left ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (body funcall (declare ((integer 0 #.most-positive-fixnum) left ok)))))))\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of upper_bound of C++ or bisect_right of Python: Returns the smallest\nindex (or input) i that fulfills TARGET[i] > VALUE. In other words, this\nfunction returns the rightmost index at which VALUE can be inserted with keeping\nthe order. TARGET must be monotonically non-decreasing with respect to ORDER.\n\nThis function returns END if VALUE >= TARGET[END-1]. Note that the range [START,\nEND) is half-open. END must be explicitly specified if TARGET is function. KEY\nis applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((body (accessor &optional declaration)\n `(progn\n (assert (<= start end))\n (if (= start end)\n end\n (labels\n ((%bisect-right (left ok)\n ;; TARGET[OK] > VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(list declaration)\n (let ((mid (ash (+ left ok) -1)))\n (if (= mid left)\n (if (funcall order value (funcall key (,accessor target left)))\n left\n ok)\n (if (funcall order value (funcall key (,accessor target mid)))\n (%bisect-right left mid)\n (%bisect-right mid ok))))))\n \n (%bisect-right start end))))))\n (etypecase target\n (vector\n (when (null end)\n (setf end (length target)))\n (body aref (declare ((integer 0 #.most-positive-fixnum) left ok))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (body funcall (declare ((integer 0 #.most-positive-fixnum) left ok)))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 998244353)\n\n;; Body\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (&optional (divisor 1000000007))\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta divisor)\n (lambda (x y divisor) (mod (+ x y) divisor)))\n\n (define-modify-macro decfmod (delta divisor)\n (lambda (x y divisor) (mod (- x y) divisor)))))\n\n(define-mod-operations 998244353)\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (xs (make-array n :element-type 'int32))\n (ys (make-array n :element-type 'int32))\n (powers (make-array 400000 :element-type 'uint32))\n (ord-xs (make-array n :element-type 'uint32))\n (res 0))\n (declare (uint32 n res)\n ((simple-array uint32 (*)) ord-xs))\n (setf (aref powers 0) 1)\n (loop for i from 1 below (length powers)\n do (setf (aref powers i)\n (mod* 2 (aref powers (- i 1)))))\n (dotimes (i n)\n (setf (aref xs i) (read-fixnum)\n (aref ys i) (read-fixnum)))\n (dotimes (i n)\n (setf (aref ord-xs i) i))\n (setf ord-xs (sort ord-xs (lambda (i j) (< (aref xs i) (aref xs j)))))\n (incfmod res (mod* (- (aref powers n) 1) n) +mod+)\n ;; L R U D\n (dotimes (i n)\n (let ((lower i)\n (upper (- n i 1)))\n (decfmod res (* 2 (aref powers lower)) +mod+)\n (decfmod res (* 2 (aref powers upper)) +mod+)))\n ;; LU LD\n (let (treap)\n (dotimes (i n)\n (let* ((ord (aref ord-xs i))\n (y (aref ys ord))\n (ld (treap-bisect-left y treap))\n (lu (- (treap-count treap) ld)))\n (incfmod res (aref powers ld) +mod+)\n (incfmod res (aref powers lu) +mod+)\n (setq treap (treap-insert y treap)))))\n ;; RU RD\n (let (treap)\n (loop for i from (- n 1) downto 0\n do (let* ((ord (aref ord-xs i))\n (y (aref ys ord))\n (rd (treap-bisect-left y treap))\n (ru (- (treap-count treap) rd)))\n (incfmod res (aref powers rd) +mod+)\n (incfmod res (aref powers ru) +mod+)\n (setq treap (treap-insert y treap)))))\n (println res)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1564996562, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02956.html", "problem_id": "p02956", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02956/input.txt", "sample_output_relpath": "derived/input_output/data/p02956/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02956/Lisp/s875208259.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s875208259", "user_id": "u352600849"}, "prompt_components": {"gold_output": "13\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; Treap accessible by index (O(log(n))).\n;; Virtually it works like std::set of C++ or TreeSet of Java. \n\n;; Note:\n;; - You shouldn't insert duplicate keys into a treap unless you know what you\n;; are doing.\n;; - You cannot rely on the side effect when you call any destructive operations\n;; on a treap. Always use the returned value.\n;; - An empty treap is NIL.\n\n(defstruct (treap (:constructor %make-treap (key priority &key left right (count 1)))\n (:copier nil)\n (:conc-name %treap-))\n (key 0 :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 0 :type (integer 0 #.most-positive-fixnum))\n (left nil :type (or null treap))\n (right nil :type (or null treap)))\n\n(declaim (inline treap-count))\n(defun treap-count (treap)\n \"Returns the size of the (nullable) TREAP.\"\n (declare ((or null treap) treap))\n (if (null treap)\n 0\n (%treap-count treap)))\n\n(declaim (inline update-count))\n(defun update-count (treap)\n (declare (treap treap))\n (setf (%treap-count treap)\n (+ 1\n (treap-count (%treap-left treap))\n (treap-count (%treap-right treap)))))\n\n(declaim (inline treap-bisect-left)\n (ftype (function * (values (integer 0 #.most-positive-fixnum) t &optional)) treap-bisect-left))\n(defun treap-bisect-left (value treap &key (order #'<))\n \"Returns the smallest index and the corresponding key that satisfies\nTREAP[index] >= VALUE. Returns the size of TREAP and VALUE if TREAP[size-1] <\nVALUE.\"\n (declare (function order))\n (labels ((recur (count treap)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null treap) (values nil nil))\n ((funcall order (%treap-key treap) value)\n (recur count (%treap-right treap)))\n (t (let ((left-count (- count (treap-count (%treap-right treap)) 1)))\n (multiple-value-bind (idx key)\n (recur left-count (%treap-left treap))\n (if idx\n (values idx key)\n (values left-count (%treap-key treap)))))))))\n (declare (ftype (function * (values t t &optional)) recur))\n (multiple-value-bind (idx key)\n (recur (treap-count treap) treap)\n (if idx\n (values idx key)\n (values (treap-count treap) value)))))\n\n(declaim (inline treap-split)\n (ftype (function * (values (or null treap) (or null treap) &optional)) treap-split))\n(defun treap-split (key treap &key (order #'<))\n \"Destructively splits the TREAP with reference to KEY and returns two treaps,\nthe smaller sub-treap (< KEY) and the larger one (>= KEY).\"\n (declare (function order)\n ((or null treap) treap))\n (labels ((recur (treap)\n (cond ((null treap)\n (values nil nil))\n ((funcall order (%treap-key treap) key)\n (multiple-value-bind (left right) (recur (%treap-right treap))\n (setf (%treap-right treap) left)\n (update-count treap)\n (values treap right)))\n (t\n (multiple-value-bind (left right) (recur (%treap-left treap))\n (setf (%treap-left treap) right)\n (update-count treap)\n (values left treap))))))\n (recur treap)))\n\n(declaim (inline treap-insert))\n(defun treap-insert (key treap &key (order #'<))\n \"Destructively inserts KEY into TREAP and returns the resultant treap.\"\n (declare ((or null treap) treap)\n (function order))\n (let ((node (%make-treap key (random most-positive-fixnum))))\n (labels ((recur (treap)\n (declare (treap node))\n (cond ((null treap) node)\n ((> (%treap-priority node) (%treap-priority treap))\n (setf (values (%treap-left node) (%treap-right node))\n (treap-split (%treap-key node) treap :order order))\n (update-count node)\n node)\n (t\n (if (funcall order (%treap-key node) (%treap-key treap))\n (setf (%treap-left treap)\n (recur (%treap-left treap)))\n (setf (%treap-right treap)\n (recur (%treap-right treap))))\n (update-count treap)\n treap))))\n (recur treap))))\n\n(defun treap-map (function treap)\n \"Successively applies FUNCTION to TREAP[0], ..., TREAP[SIZE-1]. FUNCTION must\ntake one argument.\"\n (declare (function function))\n (when treap\n (treap-map function (%treap-left treap))\n (funcall function (%treap-key treap))\n (treap-map function (%treap-right treap))))\n\n(defmethod print-object ((object treap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (treap-map (lambda (key)\n (if init\n (setq init nil)\n (write-char #\\ stream))\n (write key :stream stream))\n object))))\n\n(define-condition invalid-treap-index-error (type-error)\n ((treap :initarg :treap :reader invalid-treap-index-error-treap)\n (index :initarg :index :reader invalid-treap-index-error-index))\n (:report\n (lambda (condition stream)\n (format stream \"Invalid index ~W for treap ~W.\"\n (invalid-treap-index-error-index condition)\n (invalid-treap-index-error-treap condition)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of lower_bound of C++ or bisect_left of Python: Returns the smallest\nindex (or input) i that fulfills TARGET[i] >= VALUE, where '>=' is the\ncomplement of ORDER. In other words, this function returns the leftmost index at\nwhich VALUE can be inserted with keeping the order. Therefore, TARGET must be\nmonotonically non-decreasing with respect to ORDER.\n\nThis function returns END if VALUE exceeds TARGET[END-1]. Note that the range\n[START, END) is half-open. END must be explicitly specified if TARGET is\nfunction. KEY is applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((body (accessor &optional declaration)\n `(progn\n (assert (<= start end))\n (if (= start end) end\n (labels\n ((%bisect-left (left ok)\n ;; TARGET[OK] >= VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(list declaration)\n (let ((mid (ash (+ left ok) -1)))\n (if (= mid left)\n (if (funcall order (funcall key (,accessor target left)) value)\n ok\n left)\n (if (funcall order (funcall key (,accessor target mid)) value)\n (%bisect-left mid ok)\n (%bisect-left left mid))))))\n (%bisect-left start end))))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (body aref (declare ((integer 0 #.most-positive-fixnum) left ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (body funcall (declare ((integer 0 #.most-positive-fixnum) left ok)))))))\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of upper_bound of C++ or bisect_right of Python: Returns the smallest\nindex (or input) i that fulfills TARGET[i] > VALUE. In other words, this\nfunction returns the rightmost index at which VALUE can be inserted with keeping\nthe order. TARGET must be monotonically non-decreasing with respect to ORDER.\n\nThis function returns END if VALUE >= TARGET[END-1]. Note that the range [START,\nEND) is half-open. END must be explicitly specified if TARGET is function. KEY\nis applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((body (accessor &optional declaration)\n `(progn\n (assert (<= start end))\n (if (= start end)\n end\n (labels\n ((%bisect-right (left ok)\n ;; TARGET[OK] > VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(list declaration)\n (let ((mid (ash (+ left ok) -1)))\n (if (= mid left)\n (if (funcall order value (funcall key (,accessor target left)))\n left\n ok)\n (if (funcall order value (funcall key (,accessor target mid)))\n (%bisect-right left mid)\n (%bisect-right mid ok))))))\n \n (%bisect-right start end))))))\n (etypecase target\n (vector\n (when (null end)\n (setf end (length target)))\n (body aref (declare ((integer 0 #.most-positive-fixnum) left ok))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (body funcall (declare ((integer 0 #.most-positive-fixnum) left ok)))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 998244353)\n\n;; Body\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (&optional (divisor 1000000007))\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta divisor)\n (lambda (x y divisor) (mod (+ x y) divisor)))\n\n (define-modify-macro decfmod (delta divisor)\n (lambda (x y divisor) (mod (- x y) divisor)))))\n\n(define-mod-operations 998244353)\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (xs (make-array n :element-type 'int32))\n (ys (make-array n :element-type 'int32))\n (powers (make-array 400000 :element-type 'uint32))\n (ord-xs (make-array n :element-type 'uint32))\n (res 0))\n (declare (uint32 n res)\n ((simple-array uint32 (*)) ord-xs))\n (setf (aref powers 0) 1)\n (loop for i from 1 below (length powers)\n do (setf (aref powers i)\n (mod* 2 (aref powers (- i 1)))))\n (dotimes (i n)\n (setf (aref xs i) (read-fixnum)\n (aref ys i) (read-fixnum)))\n (dotimes (i n)\n (setf (aref ord-xs i) i))\n (setf ord-xs (sort ord-xs (lambda (i j) (< (aref xs i) (aref xs j)))))\n (incfmod res (mod* (- (aref powers n) 1) n) +mod+)\n ;; L R U D\n (dotimes (i n)\n (let ((lower i)\n (upper (- n i 1)))\n (decfmod res (* 2 (aref powers lower)) +mod+)\n (decfmod res (* 2 (aref powers upper)) +mod+)))\n ;; LU LD\n (let (treap)\n (dotimes (i n)\n (let* ((ord (aref ord-xs i))\n (y (aref ys ord))\n (ld (treap-bisect-left y treap))\n (lu (- (treap-count treap) ld)))\n (incfmod res (aref powers ld) +mod+)\n (incfmod res (aref powers lu) +mod+)\n (setq treap (treap-insert y treap)))))\n ;; RU RD\n (let (treap)\n (loop for i from (- n 1) downto 0\n do (let* ((ord (aref ord-xs i))\n (y (aref ys ord))\n (rd (treap-bisect-left y treap))\n (ru (- (treap-count treap) rd)))\n (incfmod res (aref powers rd) +mod+)\n (incfmod res (aref powers ru) +mod+)\n (setq treap (treap-insert y treap)))))\n (println res)))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nWe have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates.\n\nFor a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows:\n\nf(T) := (the number of integers i (1 \\leq i \\leq N) such that a \\leq x_i \\leq b and c \\leq y_i \\leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T)\n\nFind the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n-10^9 \\leq x_i, y_i \\leq 10^9\n\nx_i \\neq x_j (i \\neq j)\n\ny_i \\neq y_j (i \\neq j)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\n:\nx_N y_N\n\nOutput\n\nPrint the sum of f(T) over all non-empty subset T of S, modulo 998244353.\n\nSample Input 1\n\n3\n-1 3\n2 1\n3 -2\n\nSample Output 1\n\n13\n\nLet the first, second, and third points be P_1, P_2, and P_3, respectively. S = \\{P_1, P_2, P_3\\} has seven non-empty subsets, and f has the following values for each of them:\n\nf(\\{P_1\\}) = 1\n\nf(\\{P_2\\}) = 1\n\nf(\\{P_3\\}) = 1\n\nf(\\{P_1, P_2\\}) = 2\n\nf(\\{P_2, P_3\\}) = 2\n\nf(\\{P_3, P_1\\}) = 3\n\nf(\\{P_1, P_2, P_3\\}) = 3\n\nThe sum of these is 13.\n\nSample Input 2\n\n4\n1 4\n2 1\n3 3\n4 2\n\nSample Output 2\n\n34\n\nSample Input 3\n\n10\n19 -11\n-3 -12\n5 3\n3 -15\n8 -14\n-9 -20\n10 -9\n0 2\n-7 17\n6 -6\n\nSample Output 3\n\n7222\n\nBe sure to print the sum modulo 998244353.", "sample_input": "3\n-1 3\n2 1\n3 -2\n"}, "reference_outputs": ["13\n"], "source_document_id": "p02956", "source_text": "Score : 600 points\n\nProblem Statement\n\nWe have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates.\n\nFor a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows:\n\nf(T) := (the number of integers i (1 \\leq i \\leq N) such that a \\leq x_i \\leq b and c \\leq y_i \\leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T)\n\nFind the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n-10^9 \\leq x_i, y_i \\leq 10^9\n\nx_i \\neq x_j (i \\neq j)\n\ny_i \\neq y_j (i \\neq j)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\n:\nx_N y_N\n\nOutput\n\nPrint the sum of f(T) over all non-empty subset T of S, modulo 998244353.\n\nSample Input 1\n\n3\n-1 3\n2 1\n3 -2\n\nSample Output 1\n\n13\n\nLet the first, second, and third points be P_1, P_2, and P_3, respectively. S = \\{P_1, P_2, P_3\\} has seven non-empty subsets, and f has the following values for each of them:\n\nf(\\{P_1\\}) = 1\n\nf(\\{P_2\\}) = 1\n\nf(\\{P_3\\}) = 1\n\nf(\\{P_1, P_2\\}) = 2\n\nf(\\{P_2, P_3\\}) = 2\n\nf(\\{P_3, P_1\\}) = 3\n\nf(\\{P_1, P_2, P_3\\}) = 3\n\nThe sum of these is 13.\n\nSample Input 2\n\n4\n1 4\n2 1\n3 3\n4 2\n\nSample Output 2\n\n34\n\nSample Input 3\n\n10\n19 -11\n-3 -12\n5 3\n3 -15\n8 -14\n-9 -20\n10 -9\n0 2\n-7 17\n6 -6\n\nSample Output 3\n\n7222\n\nBe sure to print the sum modulo 998244353.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 14904, "cpu_time_ms": 739, "memory_kb": 62440}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s018528956", "group_id": "codeNet:p02957", "input_text": "(let* ((n (read))\n (m (read)))\n (princ (if (evenp (+ n m))\n (/ (+ n m) 2)\n \"IMPOSSIBLE\")))", "language": "Lisp", "metadata": {"date": 1564778532, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02957.html", "problem_id": "p02957", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02957/input.txt", "sample_output_relpath": "derived/input_output/data/p02957/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02957/Lisp/s018528956.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s018528956", "user_id": "u610490393"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(let* ((n (read))\n (m (read)))\n (princ (if (evenp (+ n m))\n (/ (+ n m) 2)\n \"IMPOSSIBLE\")))", "problem_context": "Score: 100 points\n\nProblem Statement\n\nWe have two distinct integers A and B.\n\nPrint the integer K such that |A - K| = |B - K|.\n\nIf such an integer does not exist, print IMPOSSIBLE instead.\n\nConstraints\n\nAll values in input are integers.\n\n0 \\leq A,\\ B \\leq 10^9\n\nA and B are distinct.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the integer K satisfying the condition.\n\nIf such an integer does not exist, print IMPOSSIBLE instead.\n\nSample Input 1\n\n2 16\n\nSample Output 1\n\n9\n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\nSample Input 2\n\n0 3\n\nSample Output 2\n\nIMPOSSIBLE\n\nNo integer satisfies the condition.\n\nSample Input 3\n\n998244353 99824435\n\nSample Output 3\n\n549034394", "sample_input": "2 16\n"}, "reference_outputs": ["9\n"], "source_document_id": "p02957", "source_text": "Score: 100 points\n\nProblem Statement\n\nWe have two distinct integers A and B.\n\nPrint the integer K such that |A - K| = |B - K|.\n\nIf such an integer does not exist, print IMPOSSIBLE instead.\n\nConstraints\n\nAll values in input are integers.\n\n0 \\leq A,\\ B \\leq 10^9\n\nA and B are distinct.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the integer K satisfying the condition.\n\nIf such an integer does not exist, print IMPOSSIBLE instead.\n\nSample Input 1\n\n2 16\n\nSample Output 1\n\n9\n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\nSample Input 2\n\n0 3\n\nSample Output 2\n\nIMPOSSIBLE\n\nNo integer satisfies the condition.\n\nSample Input 3\n\n998244353 99824435\n\nSample Output 3\n\n549034394", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 121, "cpu_time_ms": 11, "memory_kb": 3552}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s901439724", "group_id": "codeNet:p02958", "input_text": "(let* ((n (read))\n (p (make-array `(,n)))\n (q (make-array `(,n))))\n (loop :for i :from 0 :to (1- n)\n :for x := (read)\n :do (setf (aref p i) x)\n :do (setf (aref q i) x))\n (setf q (sort q #'<))\n (if (<= (loop :for i :from 0 :to (1- n)\n :if (/= (aref p i) (aref q i))\n :sum 1) 2)\n (format t \"YES~%\")\n (format t \"NO~%\")))\n", "language": "Lisp", "metadata": {"date": 1598810017, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02958.html", "problem_id": "p02958", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02958/input.txt", "sample_output_relpath": "derived/input_output/data/p02958/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02958/Lisp/s901439724.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s901439724", "user_id": "u608227593"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(let* ((n (read))\n (p (make-array `(,n)))\n (q (make-array `(,n))))\n (loop :for i :from 0 :to (1- n)\n :for x := (read)\n :do (setf (aref p i) x)\n :do (setf (aref q i) x))\n (setf q (sort q #'<))\n (if (<= (loop :for i :from 0 :to (1- n)\n :if (/= (aref p i) (aref q i))\n :sum 1) 2)\n (format t \"YES~%\")\n (format t \"NO~%\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have a sequence p = {p_1,\\ p_2,\\ ...,\\ p_N} which is a permutation of {1,\\ 2,\\ ...,\\ N}.\n\nYou can perform the following operation at most once: choose integers i and j (1 \\leq i < j \\leq N), and swap p_i and p_j. Note that you can also choose not to perform it.\n\nPrint YES if you can sort p in ascending order in this way, and NO otherwise.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 50\n\np is a permutation of {1,\\ 2,\\ ...,\\ N}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\np_1 p_2 ... p_N\n\nOutput\n\nPrint YES if you can sort p in ascending order in the way stated in the problem statement, and NO otherwise.\n\nSample Input 1\n\n5\n5 2 3 4 1\n\nSample Output 1\n\nYES\n\nYou can sort p in ascending order by swapping p_1 and p_5.\n\nSample Input 2\n\n5\n2 4 3 5 1\n\nSample Output 2\n\nNO\n\nIn this case, swapping any two elements does not sort p in ascending order.\n\nSample Input 3\n\n7\n1 2 3 4 5 6 7\n\nSample Output 3\n\nYES\n\np is already sorted in ascending order, so no operation is needed.", "sample_input": "5\n5 2 3 4 1\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p02958", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have a sequence p = {p_1,\\ p_2,\\ ...,\\ p_N} which is a permutation of {1,\\ 2,\\ ...,\\ N}.\n\nYou can perform the following operation at most once: choose integers i and j (1 \\leq i < j \\leq N), and swap p_i and p_j. Note that you can also choose not to perform it.\n\nPrint YES if you can sort p in ascending order in this way, and NO otherwise.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 50\n\np is a permutation of {1,\\ 2,\\ ...,\\ N}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\np_1 p_2 ... p_N\n\nOutput\n\nPrint YES if you can sort p in ascending order in the way stated in the problem statement, and NO otherwise.\n\nSample Input 1\n\n5\n5 2 3 4 1\n\nSample Output 1\n\nYES\n\nYou can sort p in ascending order by swapping p_1 and p_5.\n\nSample Input 2\n\n5\n2 4 3 5 1\n\nSample Output 2\n\nNO\n\nIn this case, swapping any two elements does not sort p in ascending order.\n\nSample Input 3\n\n7\n1 2 3 4 5 6 7\n\nSample Output 3\n\nYES\n\np is already sorted in ascending order, so no operation is needed.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 394, "cpu_time_ms": 17, "memory_kb": 23796}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s899169978", "group_id": "codeNet:p02958", "input_text": "(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(setq *n* (read))\n(setq *ps* (mapcar #'parse-integer (split \" \" (read-line))))\n\n(defun count-transposition (l i)\n (if (equal l nil)\n 0\n (if (equal (car l) i)\n (count-transposition (cdr l) (1+ i))\n (1+ (count-transposition (cdr l) (1+ i))))))\n\n(format t \"~a~%\"\n (if (<= (count-transposition *ps* 1) 2)\n \"YES\"\n \"NO\"))", "language": "Lisp", "metadata": {"date": 1569464357, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02958.html", "problem_id": "p02958", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02958/input.txt", "sample_output_relpath": "derived/input_output/data/p02958/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02958/Lisp/s899169978.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s899169978", "user_id": "u358554431"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(setq *n* (read))\n(setq *ps* (mapcar #'parse-integer (split \" \" (read-line))))\n\n(defun count-transposition (l i)\n (if (equal l nil)\n 0\n (if (equal (car l) i)\n (count-transposition (cdr l) (1+ i))\n (1+ (count-transposition (cdr l) (1+ i))))))\n\n(format t \"~a~%\"\n (if (<= (count-transposition *ps* 1) 2)\n \"YES\"\n \"NO\"))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have a sequence p = {p_1,\\ p_2,\\ ...,\\ p_N} which is a permutation of {1,\\ 2,\\ ...,\\ N}.\n\nYou can perform the following operation at most once: choose integers i and j (1 \\leq i < j \\leq N), and swap p_i and p_j. Note that you can also choose not to perform it.\n\nPrint YES if you can sort p in ascending order in this way, and NO otherwise.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 50\n\np is a permutation of {1,\\ 2,\\ ...,\\ N}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\np_1 p_2 ... p_N\n\nOutput\n\nPrint YES if you can sort p in ascending order in the way stated in the problem statement, and NO otherwise.\n\nSample Input 1\n\n5\n5 2 3 4 1\n\nSample Output 1\n\nYES\n\nYou can sort p in ascending order by swapping p_1 and p_5.\n\nSample Input 2\n\n5\n2 4 3 5 1\n\nSample Output 2\n\nNO\n\nIn this case, swapping any two elements does not sort p in ascending order.\n\nSample Input 3\n\n7\n1 2 3 4 5 6 7\n\nSample Output 3\n\nYES\n\np is already sorted in ascending order, so no operation is needed.", "sample_input": "5\n5 2 3 4 1\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p02958", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have a sequence p = {p_1,\\ p_2,\\ ...,\\ p_N} which is a permutation of {1,\\ 2,\\ ...,\\ N}.\n\nYou can perform the following operation at most once: choose integers i and j (1 \\leq i < j \\leq N), and swap p_i and p_j. Note that you can also choose not to perform it.\n\nPrint YES if you can sort p in ascending order in this way, and NO otherwise.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 50\n\np is a permutation of {1,\\ 2,\\ ...,\\ N}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\np_1 p_2 ... p_N\n\nOutput\n\nPrint YES if you can sort p in ascending order in the way stated in the problem statement, and NO otherwise.\n\nSample Input 1\n\n5\n5 2 3 4 1\n\nSample Output 1\n\nYES\n\nYou can sort p in ascending order by swapping p_1 and p_5.\n\nSample Input 2\n\n5\n2 4 3 5 1\n\nSample Output 2\n\nNO\n\nIn this case, swapping any two elements does not sort p in ascending order.\n\nSample Input 3\n\n7\n1 2 3 4 5 6 7\n\nSample Output 3\n\nYES\n\np is already sorted in ascending order, so no operation is needed.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 526, "cpu_time_ms": 59, "memory_kb": 7008}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s626322302", "group_id": "codeNet:p02962", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Rolling hash (62-bit)\n;;;\n\n;; Reference:\n;; https://www.mii.lt/olympiads_in_informatics/pdf/INFOL119.pdf\n;; https://ei1333.github.io/luzhiled/snippets/string/rolling-hash.html\n\n(defstruct (rhash (:constructor %make-rhash (mod1 base1 cumul1 powers1 mod2 base2 cumul2 powers2)))\n ;; lower 31-bit value\n (mod1 2147483647 :type (unsigned-byte 31))\n (base1 1059428526 :type (unsigned-byte 31))\n (cumul1 nil :type (simple-array (unsigned-byte 31) (*)))\n (powers1 nil :type (simple-array (unsigned-byte 31) (*)))\n ;; upper 31-bit value\n (mod2 2147483629 :type (unsigned-byte 31))\n (base2 2090066834 :type (unsigned-byte 31))\n (cumul2 nil :type (simple-array (unsigned-byte 31) (*)))\n (powers2 nil :type (simple-array (unsigned-byte 31) (*))))\n\n;; This table consists of pairs of primes less than 2^31 and the random\n;; primitive roots modulo them larger than 10^9. We randomly choose a pair and\n;; adopt the prime as modulus and the primitive root as base.\n(declaim ((simple-array (unsigned-byte 31) (100)) *moduli-table* *base-table*))\n(defparameter *moduli-table*\n (make-array 100 :element-type '(unsigned-byte 31)\n :initial-contents '(2147483647 2147483629 2147483587 2147483579 2147483563 2147483549 2147483543\n 2147483497 2147483489 2147483477 2147483423 2147483399 2147483353 2147483323\n 2147483269 2147483249 2147483237 2147483179 2147483171 2147483137 2147483123\n 2147483077 2147483069 2147483059 2147483053 2147483033 2147483029 2147482951\n 2147482949 2147482943 2147482937 2147482921 2147482877 2147482873 2147482867\n 2147482859 2147482819 2147482817 2147482811 2147482801 2147482763 2147482739\n 2147482697 2147482693 2147482681 2147482663 2147482661 2147482621 2147482591\n 2147482583 2147482577 2147482507 2147482501 2147482481 2147482417 2147482409\n 2147482367 2147482361 2147482349 2147482343 2147482327 2147482291 2147482273\n 2147482237 2147482231 2147482223 2147482121 2147482093 2147482091 2147482081\n 2147482063 2147482021 2147481997 2147481967 2147481949 2147481937 2147481907\n 2147481901 2147481899 2147481893 2147481883 2147481863 2147481827 2147481811\n 2147481797 2147481793 2147481673 2147481629 2147481571 2147481563 2147481529\n 2147481509 2147481499 2147481491 2147481487 2147481373 2147481367 2147481359\n 2147481353 2147481337)))\n(defparameter *base-table*\n (make-array 100 :element-type '(unsigned-byte 31)\n :initial-contents '(1059428526 2090066834 1772913519 1695158082 1516083910 1622025757 1248368302\n 1894391153 2094976878 1193495823 1783230399 1520742486 1748395380 1703688443\n 2138630366 1942049269 2066548889 1890950855 1480056952 1792721876 1092797280\n 1204851872 1035383130 1002272185 1319736653 1980774767 1748793187 1866963602\n 1200445534 1732959733 1214706585 1957228822 1479411729 1323155655 1052714514\n 1989821027 1163834549 1095622874 2087901566 1670886084 1191975321 2091468260\n 1429690292 1116037844 1420457779 1937649612 1552519679 1328604092 2090326292\n 1397132095 1316705322 1664351025 1391513321 1851038917 1556301575 1928956735\n 1764506480 1449537491 2119470570 1793768237 1831208371 1723755364 1643456516\n 1993819805 1419297891 1755252963 1775153034 1388979165 2144586633 1501222238\n 1872274033 1143076711 1229125474 1483974015 1997206147 1593231852 1632083893\n 1601537043 2012194627 1299923971 1566635240 1814404069 1619988648 2072686565\n 2014361572 1213868607 1166967329 1009325840 1306167671 1915239658 1223190075\n 1821151471 2037700892 1646950698 1517859810 1099233635 1004913731 1653443892\n 1782112665 1018916580)))\n\n(defun %choose-moduli (mod1 mod2 base1 base2 rhash)\n \"Chooses two appropriate pairs of moduli and bases.\"\n (declare ((or null (unsigned-byte 31)) mod1 mod2 base1 base2))\n (when rhash\n (return-from %choose-moduli\n (values (rhash-mod1 rhash)\n (rhash-mod2 rhash)\n (rhash-base1 rhash)\n (rhash-base2 rhash))))\n (let* ((rand1 (random (length *moduli-table*)))\n (rand2 (loop (let ((tmp (random (length *moduli-table*))))\n (unless (= tmp rand1)\n (return tmp))))))\n (if mod1\n (progn\n (assert (sb-int:positive-primep mod1))\n (setq base1 (or base1 (+ 1 (random (- mod1 1))))))\n (progn\n (setq mod1 (or mod1 (aref *moduli-table* rand1)))\n (if base1\n (assert (<= 1 base1 (- mod1 1)))\n (setq base1 (aref *base-table* rand1)))))\n (if mod2\n (progn\n (assert (sb-int:positive-primep mod2))\n (setq base2 (or base2 (+ 1 (random (- mod2 1))))))\n (progn\n (setq mod2 (or mod2 (aref *moduli-table* rand2)))\n (if base2\n (assert (<= 1 base2 (- mod2 1)))\n (setq base2 (aref *base-table* rand2))))))\n (values mod1 mod2 base1 base2))\n\n(defun make-rhash (vector &key (key #'char-code) mod1 mod2 base1 base2 rhash)\n \"Returns the table of rolling-hash of VECTOR modulo MOD1 and MOD2. KEY is\napplied to each element of VECTOR prior to computing the hash value. If moduli\nand bases are NIL, this function randomly chooses them. If RHASH is specified,\nthe same moduli and bases as RHASH is adopted.\n\nMOD[1|2] := NIL | unsigned 31-bit prime number\nBASE1 := NIL | 1 | 2 | ... | MOD1 - 1\nBASE2 := NIL | 1 | 2 | ... | MOD2 - 1\nKEY := FUNCTION returning FIXNUM\nRHASH := NIL | RHASH\"\n (declare (optimize (speed 3))\n (vector vector)\n ((or null (unsigned-byte 31)) mod1 mod2 base1 base2)\n (function key))\n (multiple-value-bind (mod1 mod2 base1 base2) (%choose-moduli mod1 mod2 base1 base2 rhash)\n (declare ((unsigned-byte 31) mod1 mod2 base1 base2))\n (let* ((size (length vector))\n (cumul1 (make-array (+ 1 size) :element-type '(unsigned-byte 31)))\n (powers1 (make-array (+ 1 size) :element-type '(unsigned-byte 31)))\n (cumul2 (make-array (+ 1 size) :element-type '(unsigned-byte 31)))\n (powers2 (make-array (+ 1 size) :element-type '(unsigned-byte 31))))\n (setf (aref powers1 0) 1\n (aref powers2 0) 1)\n (dotimes (i size)\n (setf (aref powers1 (+ i 1))\n (mod (* (aref powers1 i) base1) mod1)\n (aref powers2 (+ i 1))\n (mod (* (aref powers2 i) base2) mod2))\n (let ((sum1 (+ (mod (* base1 (aref cumul1 i)) mod1)\n (mod (the fixnum (funcall key (aref vector i))) mod1)))\n (sum2 (+ (mod (* base2 (aref cumul2 i)) mod2)\n (mod (the fixnum (funcall key (aref vector i))) mod2))))\n (setf (aref cumul1 (+ i 1)) (if (> sum1 mod1)\n (- sum1 mod1)\n sum1)\n (aref cumul2 (+ i 1)) (if (> sum2 mod2)\n (- sum2 mod2)\n sum2))))\n (%make-rhash mod1 base1 cumul1 powers1 mod2 base2 cumul2 powers2))))\n\n(declaim (ftype (function * (values (unsigned-byte 62) &optional)) rhash-vector-hash)\n (inline rhash-vector-hash))\n(defun rhash-vector-hash (rhash vector &key (key #'char-code))\n \"Returns the hash code of VECTOR w.r.t. the moduli and bases of RHASH.\"\n (declare (optimize (speed 3))\n (vector vector)\n (function key))\n (let* ((mod1 (rhash-mod1 rhash))\n (mod2 (rhash-mod2 rhash))\n (base1 (rhash-base1 rhash))\n (base2 (rhash-base2 rhash))\n (size (length vector))\n (lower 0)\n (upper 0))\n (declare ((unsigned-byte 31) lower upper))\n (dotimes (i size)\n (setf lower (+ (mod (* base1 lower) mod1)\n (mod (the fixnum (funcall key (aref vector i))) mod1)))\n (setf upper (+ (mod (* base2 upper) mod2)\n (mod (the fixnum (funcall key (aref vector i))) mod2))))\n (dpb upper (byte 31 31) lower)))\n\n(declaim (inline rhash-query)\n (ftype (function * (values (unsigned-byte 62) &optional)) rhash-query))\n(defun rhash-query (rhash l r)\n \"Returns the hash value of the interval [L, R).\"\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (assert (<= l r))\n (let ((cumul1 (rhash-cumul1 rhash))\n (powers1 (rhash-powers1 rhash))\n (mod1 (rhash-mod1 rhash))\n (cumul2 (rhash-cumul2 rhash))\n (powers2 (rhash-powers2 rhash))\n (mod2 (rhash-mod2 rhash)))\n (let ((lower (+ (aref cumul1 r)\n (- mod1 (mod (* (aref cumul1 l) (aref powers1 (- r l))) mod1))))\n (upper (+ (aref cumul2 r)\n (- mod2 (mod (* (aref cumul2 l) (aref powers2 (- r l))) mod2)))))\n (let ((lower (if (> lower mod1) (- lower mod1) lower))\n (upper (if (> upper mod2) (- upper mod2) upper)))\n (declare ((unsigned-byte 31) lower upper))\n (dpb upper (byte 31 31) lower)))))\n\n(declaim (inline rhash-concat))\n(defun rhash-concat (rhash hash1 hash2 length2)\n \"Returns the hash value of the concatenated sequence.\n\nHASH1 := hash value of the first sequence\nHASH2 := hash value of the second sequence\nLENGTH2 := length of the second sequence.\"\n (declare ((unsigned-byte 62) hash1 hash2)\n ((integer 0 #.most-positive-fixnum) length2))\n (let* ((hash1-lower (ldb (byte 31 0) hash1))\n (hash1-upper (ldb (byte 31 31) hash1))\n (hash2-lower (ldb (byte 31 0) hash2))\n (hash2-upper (ldb (byte 31 31) hash2))\n (mod1 (rhash-mod1 rhash))\n (mod2 (rhash-mod2 rhash))\n (res-lower (mod (+ hash2-lower\n (mod (* hash1-lower\n (aref (rhash-powers1 rhash) length2))\n mod1))\n mod1))\n (res-upper (mod (+ hash2-upper\n (mod (* hash1-upper\n (aref (rhash-powers2 rhash) length2))\n mod2))\n mod2)))\n (declare ((unsigned-byte 31) res-lower res-upper))\n (dpb res-upper (byte 31 31) res-lower)))\n\n(declaim (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) rhash-get-lcp))\n(defun rhash-get-lcp (rhash1 start1 rhash2 start2)\n \"Returns the length of the longest common prefix of two suffixes which begin\nat START1 and START2.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) start1 start2))\n (assert (and (= (rhash-mod1 rhash1) (rhash-mod1 rhash2))\n (= (rhash-mod2 rhash1) (rhash-mod2 rhash2))))\n (assert (and (< start1 (length (rhash-cumul1 rhash1)))\n (< start2 (length (rhash-cumul1 rhash2)))))\n (let ((max-length (min (- (length (rhash-cumul1 rhash1)) start1 1)\n (- (length (rhash-cumul1 rhash2)) start2 1))))\n (declare (optimize (safety 0)))\n (if (= (rhash-query rhash1 start1 (+ start1 max-length))\n (rhash-query rhash2 start2 (+ start2 max-length)))\n max-length\n (labels ((bisect (ok ng)\n (declare ((integer 0 #.most-positive-fixnum) ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (= (rhash-query rhash1 start1 (+ start1 mid))\n (rhash-query rhash2 start2 (+ start2 mid)))\n (bisect mid ng)\n (bisect ok mid))))))\n (bisect 0 max-length)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((ss (coerce (read-line) 'simple-base-string))\n (ts (coerce (read-line) 'simple-base-string))\n (slen (length ss))\n (tlen (length ts))\n (snum (max 3 (ceiling (* tlen 4) slen)))\n (ex-ss (make-string (* snum slen) :element-type 'base-char))\n (tnum (floor (* snum slen) tlen))\n (ex-ts (make-string (* tnum tlen) :element-type 'base-char)))\n (declare (uint31 slen tlen snum tnum))\n (dotimes (i slen)\n (dotimes (fac snum)\n (setf (aref ex-ss (+ i (* fac slen)))\n (aref ss i))))\n (dotimes (i tlen)\n (dotimes (fac tnum)\n (setf (aref ex-ts (+ i (* fac tlen)))\n (aref ts i))))\n (let* ((rhash (make-rhash ex-ss))\n (total-len (* snum slen))\n (thash (rhash-vector-hash rhash ts))\n (base 0))\n (block maybe-infinite\n (loop (unless (<= (+ base tlen) total-len)\n (return))\n (when (= thash (rhash-query rhash base (+ base tlen)))\n ;; possibly infinite\n (loop for i from base by tlen\n while (<= (+ i tlen) total-len)\n do (unless (= thash (rhash-query rhash i (+ i tlen)))\n (return-from maybe-infinite))\n finally (let* ((l base)\n (r i)\n (dif (+ l (- total-len r))))\n (if (<= dif (* 2 (- tlen 1)))\n (progn (println -1)\n (return-from main))\n (return-from maybe-infinite)))))\n (incf base)))\n #>total-len\n ;; not infinite\n (let ((base 0)\n (res 0)\n (rhash2 (make-rhash ex-ts :rhash rhash)))\n (declare (uint31 res))\n (dotimes (pos total-len)\n (let ((length (rhash-get-lcp rhash pos rhash2 0)))\n (setf res (max res (floor length tlen)))))\n (println res)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1564280962, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02962.html", "problem_id": "p02962", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02962/input.txt", "sample_output_relpath": "derived/input_output/data/p02962/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02962/Lisp/s626322302.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s626322302", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Rolling hash (62-bit)\n;;;\n\n;; Reference:\n;; https://www.mii.lt/olympiads_in_informatics/pdf/INFOL119.pdf\n;; https://ei1333.github.io/luzhiled/snippets/string/rolling-hash.html\n\n(defstruct (rhash (:constructor %make-rhash (mod1 base1 cumul1 powers1 mod2 base2 cumul2 powers2)))\n ;; lower 31-bit value\n (mod1 2147483647 :type (unsigned-byte 31))\n (base1 1059428526 :type (unsigned-byte 31))\n (cumul1 nil :type (simple-array (unsigned-byte 31) (*)))\n (powers1 nil :type (simple-array (unsigned-byte 31) (*)))\n ;; upper 31-bit value\n (mod2 2147483629 :type (unsigned-byte 31))\n (base2 2090066834 :type (unsigned-byte 31))\n (cumul2 nil :type (simple-array (unsigned-byte 31) (*)))\n (powers2 nil :type (simple-array (unsigned-byte 31) (*))))\n\n;; This table consists of pairs of primes less than 2^31 and the random\n;; primitive roots modulo them larger than 10^9. We randomly choose a pair and\n;; adopt the prime as modulus and the primitive root as base.\n(declaim ((simple-array (unsigned-byte 31) (100)) *moduli-table* *base-table*))\n(defparameter *moduli-table*\n (make-array 100 :element-type '(unsigned-byte 31)\n :initial-contents '(2147483647 2147483629 2147483587 2147483579 2147483563 2147483549 2147483543\n 2147483497 2147483489 2147483477 2147483423 2147483399 2147483353 2147483323\n 2147483269 2147483249 2147483237 2147483179 2147483171 2147483137 2147483123\n 2147483077 2147483069 2147483059 2147483053 2147483033 2147483029 2147482951\n 2147482949 2147482943 2147482937 2147482921 2147482877 2147482873 2147482867\n 2147482859 2147482819 2147482817 2147482811 2147482801 2147482763 2147482739\n 2147482697 2147482693 2147482681 2147482663 2147482661 2147482621 2147482591\n 2147482583 2147482577 2147482507 2147482501 2147482481 2147482417 2147482409\n 2147482367 2147482361 2147482349 2147482343 2147482327 2147482291 2147482273\n 2147482237 2147482231 2147482223 2147482121 2147482093 2147482091 2147482081\n 2147482063 2147482021 2147481997 2147481967 2147481949 2147481937 2147481907\n 2147481901 2147481899 2147481893 2147481883 2147481863 2147481827 2147481811\n 2147481797 2147481793 2147481673 2147481629 2147481571 2147481563 2147481529\n 2147481509 2147481499 2147481491 2147481487 2147481373 2147481367 2147481359\n 2147481353 2147481337)))\n(defparameter *base-table*\n (make-array 100 :element-type '(unsigned-byte 31)\n :initial-contents '(1059428526 2090066834 1772913519 1695158082 1516083910 1622025757 1248368302\n 1894391153 2094976878 1193495823 1783230399 1520742486 1748395380 1703688443\n 2138630366 1942049269 2066548889 1890950855 1480056952 1792721876 1092797280\n 1204851872 1035383130 1002272185 1319736653 1980774767 1748793187 1866963602\n 1200445534 1732959733 1214706585 1957228822 1479411729 1323155655 1052714514\n 1989821027 1163834549 1095622874 2087901566 1670886084 1191975321 2091468260\n 1429690292 1116037844 1420457779 1937649612 1552519679 1328604092 2090326292\n 1397132095 1316705322 1664351025 1391513321 1851038917 1556301575 1928956735\n 1764506480 1449537491 2119470570 1793768237 1831208371 1723755364 1643456516\n 1993819805 1419297891 1755252963 1775153034 1388979165 2144586633 1501222238\n 1872274033 1143076711 1229125474 1483974015 1997206147 1593231852 1632083893\n 1601537043 2012194627 1299923971 1566635240 1814404069 1619988648 2072686565\n 2014361572 1213868607 1166967329 1009325840 1306167671 1915239658 1223190075\n 1821151471 2037700892 1646950698 1517859810 1099233635 1004913731 1653443892\n 1782112665 1018916580)))\n\n(defun %choose-moduli (mod1 mod2 base1 base2 rhash)\n \"Chooses two appropriate pairs of moduli and bases.\"\n (declare ((or null (unsigned-byte 31)) mod1 mod2 base1 base2))\n (when rhash\n (return-from %choose-moduli\n (values (rhash-mod1 rhash)\n (rhash-mod2 rhash)\n (rhash-base1 rhash)\n (rhash-base2 rhash))))\n (let* ((rand1 (random (length *moduli-table*)))\n (rand2 (loop (let ((tmp (random (length *moduli-table*))))\n (unless (= tmp rand1)\n (return tmp))))))\n (if mod1\n (progn\n (assert (sb-int:positive-primep mod1))\n (setq base1 (or base1 (+ 1 (random (- mod1 1))))))\n (progn\n (setq mod1 (or mod1 (aref *moduli-table* rand1)))\n (if base1\n (assert (<= 1 base1 (- mod1 1)))\n (setq base1 (aref *base-table* rand1)))))\n (if mod2\n (progn\n (assert (sb-int:positive-primep mod2))\n (setq base2 (or base2 (+ 1 (random (- mod2 1))))))\n (progn\n (setq mod2 (or mod2 (aref *moduli-table* rand2)))\n (if base2\n (assert (<= 1 base2 (- mod2 1)))\n (setq base2 (aref *base-table* rand2))))))\n (values mod1 mod2 base1 base2))\n\n(defun make-rhash (vector &key (key #'char-code) mod1 mod2 base1 base2 rhash)\n \"Returns the table of rolling-hash of VECTOR modulo MOD1 and MOD2. KEY is\napplied to each element of VECTOR prior to computing the hash value. If moduli\nand bases are NIL, this function randomly chooses them. If RHASH is specified,\nthe same moduli and bases as RHASH is adopted.\n\nMOD[1|2] := NIL | unsigned 31-bit prime number\nBASE1 := NIL | 1 | 2 | ... | MOD1 - 1\nBASE2 := NIL | 1 | 2 | ... | MOD2 - 1\nKEY := FUNCTION returning FIXNUM\nRHASH := NIL | RHASH\"\n (declare (optimize (speed 3))\n (vector vector)\n ((or null (unsigned-byte 31)) mod1 mod2 base1 base2)\n (function key))\n (multiple-value-bind (mod1 mod2 base1 base2) (%choose-moduli mod1 mod2 base1 base2 rhash)\n (declare ((unsigned-byte 31) mod1 mod2 base1 base2))\n (let* ((size (length vector))\n (cumul1 (make-array (+ 1 size) :element-type '(unsigned-byte 31)))\n (powers1 (make-array (+ 1 size) :element-type '(unsigned-byte 31)))\n (cumul2 (make-array (+ 1 size) :element-type '(unsigned-byte 31)))\n (powers2 (make-array (+ 1 size) :element-type '(unsigned-byte 31))))\n (setf (aref powers1 0) 1\n (aref powers2 0) 1)\n (dotimes (i size)\n (setf (aref powers1 (+ i 1))\n (mod (* (aref powers1 i) base1) mod1)\n (aref powers2 (+ i 1))\n (mod (* (aref powers2 i) base2) mod2))\n (let ((sum1 (+ (mod (* base1 (aref cumul1 i)) mod1)\n (mod (the fixnum (funcall key (aref vector i))) mod1)))\n (sum2 (+ (mod (* base2 (aref cumul2 i)) mod2)\n (mod (the fixnum (funcall key (aref vector i))) mod2))))\n (setf (aref cumul1 (+ i 1)) (if (> sum1 mod1)\n (- sum1 mod1)\n sum1)\n (aref cumul2 (+ i 1)) (if (> sum2 mod2)\n (- sum2 mod2)\n sum2))))\n (%make-rhash mod1 base1 cumul1 powers1 mod2 base2 cumul2 powers2))))\n\n(declaim (ftype (function * (values (unsigned-byte 62) &optional)) rhash-vector-hash)\n (inline rhash-vector-hash))\n(defun rhash-vector-hash (rhash vector &key (key #'char-code))\n \"Returns the hash code of VECTOR w.r.t. the moduli and bases of RHASH.\"\n (declare (optimize (speed 3))\n (vector vector)\n (function key))\n (let* ((mod1 (rhash-mod1 rhash))\n (mod2 (rhash-mod2 rhash))\n (base1 (rhash-base1 rhash))\n (base2 (rhash-base2 rhash))\n (size (length vector))\n (lower 0)\n (upper 0))\n (declare ((unsigned-byte 31) lower upper))\n (dotimes (i size)\n (setf lower (+ (mod (* base1 lower) mod1)\n (mod (the fixnum (funcall key (aref vector i))) mod1)))\n (setf upper (+ (mod (* base2 upper) mod2)\n (mod (the fixnum (funcall key (aref vector i))) mod2))))\n (dpb upper (byte 31 31) lower)))\n\n(declaim (inline rhash-query)\n (ftype (function * (values (unsigned-byte 62) &optional)) rhash-query))\n(defun rhash-query (rhash l r)\n \"Returns the hash value of the interval [L, R).\"\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (assert (<= l r))\n (let ((cumul1 (rhash-cumul1 rhash))\n (powers1 (rhash-powers1 rhash))\n (mod1 (rhash-mod1 rhash))\n (cumul2 (rhash-cumul2 rhash))\n (powers2 (rhash-powers2 rhash))\n (mod2 (rhash-mod2 rhash)))\n (let ((lower (+ (aref cumul1 r)\n (- mod1 (mod (* (aref cumul1 l) (aref powers1 (- r l))) mod1))))\n (upper (+ (aref cumul2 r)\n (- mod2 (mod (* (aref cumul2 l) (aref powers2 (- r l))) mod2)))))\n (let ((lower (if (> lower mod1) (- lower mod1) lower))\n (upper (if (> upper mod2) (- upper mod2) upper)))\n (declare ((unsigned-byte 31) lower upper))\n (dpb upper (byte 31 31) lower)))))\n\n(declaim (inline rhash-concat))\n(defun rhash-concat (rhash hash1 hash2 length2)\n \"Returns the hash value of the concatenated sequence.\n\nHASH1 := hash value of the first sequence\nHASH2 := hash value of the second sequence\nLENGTH2 := length of the second sequence.\"\n (declare ((unsigned-byte 62) hash1 hash2)\n ((integer 0 #.most-positive-fixnum) length2))\n (let* ((hash1-lower (ldb (byte 31 0) hash1))\n (hash1-upper (ldb (byte 31 31) hash1))\n (hash2-lower (ldb (byte 31 0) hash2))\n (hash2-upper (ldb (byte 31 31) hash2))\n (mod1 (rhash-mod1 rhash))\n (mod2 (rhash-mod2 rhash))\n (res-lower (mod (+ hash2-lower\n (mod (* hash1-lower\n (aref (rhash-powers1 rhash) length2))\n mod1))\n mod1))\n (res-upper (mod (+ hash2-upper\n (mod (* hash1-upper\n (aref (rhash-powers2 rhash) length2))\n mod2))\n mod2)))\n (declare ((unsigned-byte 31) res-lower res-upper))\n (dpb res-upper (byte 31 31) res-lower)))\n\n(declaim (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) rhash-get-lcp))\n(defun rhash-get-lcp (rhash1 start1 rhash2 start2)\n \"Returns the length of the longest common prefix of two suffixes which begin\nat START1 and START2.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) start1 start2))\n (assert (and (= (rhash-mod1 rhash1) (rhash-mod1 rhash2))\n (= (rhash-mod2 rhash1) (rhash-mod2 rhash2))))\n (assert (and (< start1 (length (rhash-cumul1 rhash1)))\n (< start2 (length (rhash-cumul1 rhash2)))))\n (let ((max-length (min (- (length (rhash-cumul1 rhash1)) start1 1)\n (- (length (rhash-cumul1 rhash2)) start2 1))))\n (declare (optimize (safety 0)))\n (if (= (rhash-query rhash1 start1 (+ start1 max-length))\n (rhash-query rhash2 start2 (+ start2 max-length)))\n max-length\n (labels ((bisect (ok ng)\n (declare ((integer 0 #.most-positive-fixnum) ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (= (rhash-query rhash1 start1 (+ start1 mid))\n (rhash-query rhash2 start2 (+ start2 mid)))\n (bisect mid ng)\n (bisect ok mid))))))\n (bisect 0 max-length)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((ss (coerce (read-line) 'simple-base-string))\n (ts (coerce (read-line) 'simple-base-string))\n (slen (length ss))\n (tlen (length ts))\n (snum (max 3 (ceiling (* tlen 4) slen)))\n (ex-ss (make-string (* snum slen) :element-type 'base-char))\n (tnum (floor (* snum slen) tlen))\n (ex-ts (make-string (* tnum tlen) :element-type 'base-char)))\n (declare (uint31 slen tlen snum tnum))\n (dotimes (i slen)\n (dotimes (fac snum)\n (setf (aref ex-ss (+ i (* fac slen)))\n (aref ss i))))\n (dotimes (i tlen)\n (dotimes (fac tnum)\n (setf (aref ex-ts (+ i (* fac tlen)))\n (aref ts i))))\n (let* ((rhash (make-rhash ex-ss))\n (total-len (* snum slen))\n (thash (rhash-vector-hash rhash ts))\n (base 0))\n (block maybe-infinite\n (loop (unless (<= (+ base tlen) total-len)\n (return))\n (when (= thash (rhash-query rhash base (+ base tlen)))\n ;; possibly infinite\n (loop for i from base by tlen\n while (<= (+ i tlen) total-len)\n do (unless (= thash (rhash-query rhash i (+ i tlen)))\n (return-from maybe-infinite))\n finally (let* ((l base)\n (r i)\n (dif (+ l (- total-len r))))\n (if (<= dif (* 2 (- tlen 1)))\n (progn (println -1)\n (return-from main))\n (return-from maybe-infinite)))))\n (incf base)))\n #>total-len\n ;; not infinite\n (let ((base 0)\n (res 0)\n (rhash2 (make-rhash ex-ts :rhash rhash)))\n (declare (uint31 res))\n (dotimes (pos total-len)\n (let ((length (rhash-get-lcp rhash pos rhash2 0)))\n (setf res (max res (floor length tlen)))))\n (println res)))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven are two strings s and t consisting of lowercase English letters. Determine if the number of non-negative integers i satisfying the following condition is finite, and find the maximum value of such i if the number is finite.\n\nThere exists a non-negative integer j such that the concatenation of i copies of t is a substring of the concatenation of j copies of s.\n\nNotes\n\nA string a is a substring of another string b if and only if there exists an integer x (0 \\leq x \\leq |b| - |a|) such that, for any y (1 \\leq y \\leq |a|), a_y = b_{x+y} holds.\n\nWe assume that the concatenation of zero copies of any string is the empty string. From the definition above, the empty string is a substring of any string. Thus, for any two strings s and t, i = 0 satisfies the condition in the problem statement.\n\nConstraints\n\n1 \\leq |s| \\leq 5 \\times 10^5\n\n1 \\leq |t| \\leq 5 \\times 10^5\n\ns and t consist of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\nt\n\nOutput\n\nIf the number of non-negative integers i satisfying the following condition is finite, print the maximum value of such i; if the number is infinite, print -1.\n\nSample Input 1\n\nabcabab\nab\n\nSample Output 1\n\n3\n\nThe concatenation of three copies of t, ababab, is a substring of the concatenation of two copies of s, abcabababcabab, so i = 3 satisfies the condition.\n\nOn the other hand, the concatenation of four copies of t, abababab, is not a substring of the concatenation of any number of copies of s, so i = 4 does not satisfy the condition.\n\nSimilarly, any integer greater than 4 does not satisfy the condition, either. Thus, the number of non-negative integers i satisfying the condition is finite, and the maximum value of such i is 3.\n\nSample Input 2\n\naa\naaaaaaa\n\nSample Output 2\n\n-1\n\nFor any non-negative integer i, the concatenation of i copies of t is a substring of the concatenation of 4i copies of s. Thus, there are infinitely many non-negative integers i that satisfy the condition.\n\nSample Input 3\n\naba\nbaaab\n\nSample Output 3\n\n0\n\nAs stated in Notes, i = 0 always satisfies the condition.", "sample_input": "abcabab\nab\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02962", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are two strings s and t consisting of lowercase English letters. Determine if the number of non-negative integers i satisfying the following condition is finite, and find the maximum value of such i if the number is finite.\n\nThere exists a non-negative integer j such that the concatenation of i copies of t is a substring of the concatenation of j copies of s.\n\nNotes\n\nA string a is a substring of another string b if and only if there exists an integer x (0 \\leq x \\leq |b| - |a|) such that, for any y (1 \\leq y \\leq |a|), a_y = b_{x+y} holds.\n\nWe assume that the concatenation of zero copies of any string is the empty string. From the definition above, the empty string is a substring of any string. Thus, for any two strings s and t, i = 0 satisfies the condition in the problem statement.\n\nConstraints\n\n1 \\leq |s| \\leq 5 \\times 10^5\n\n1 \\leq |t| \\leq 5 \\times 10^5\n\ns and t consist of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\nt\n\nOutput\n\nIf the number of non-negative integers i satisfying the following condition is finite, print the maximum value of such i; if the number is infinite, print -1.\n\nSample Input 1\n\nabcabab\nab\n\nSample Output 1\n\n3\n\nThe concatenation of three copies of t, ababab, is a substring of the concatenation of two copies of s, abcabababcabab, so i = 3 satisfies the condition.\n\nOn the other hand, the concatenation of four copies of t, abababab, is not a substring of the concatenation of any number of copies of s, so i = 4 does not satisfy the condition.\n\nSimilarly, any integer greater than 4 does not satisfy the condition, either. Thus, the number of non-negative integers i satisfying the condition is finite, and the maximum value of such i is 3.\n\nSample Input 2\n\naa\naaaaaaa\n\nSample Output 2\n\n-1\n\nFor any non-negative integer i, the concatenation of i copies of t is a substring of the concatenation of 4i copies of s. Thus, there are infinitely many non-negative integers i that satisfy the condition.\n\nSample Input 3\n\naba\nbaaab\n\nSample Output 3\n\n0\n\nAs stated in Notes, i = 0 always satisfies the condition.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 14771, "cpu_time_ms": 2105, "memory_kb": 105064}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s485306228", "group_id": "codeNet:p02962", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Rolling hash (62-bit)\n;;;\n\n;; Reference:\n;; https://www.mii.lt/olympiads_in_informatics/pdf/INFOL119.pdf\n;; https://ei1333.github.io/luzhiled/snippets/string/rolling-hash.html\n\n(defstruct (rhash (:constructor %make-rhash (mod1 base1 cumul1 powers1 mod2 base2 cumul2 powers2)))\n ;; lower 31-bit value\n (mod1 2147483647 :type (unsigned-byte 31))\n (base1 1059428526 :type (unsigned-byte 31))\n (cumul1 nil :type (simple-array (unsigned-byte 31) (*)))\n (powers1 nil :type (simple-array (unsigned-byte 31) (*)))\n ;; upper 31-bit value\n (mod2 2147483629 :type (unsigned-byte 31))\n (base2 2090066834 :type (unsigned-byte 31))\n (cumul2 nil :type (simple-array (unsigned-byte 31) (*)))\n (powers2 nil :type (simple-array (unsigned-byte 31) (*))))\n\n;; This table consists of pairs of primes less than 2^31 and the random\n;; primitive roots modulo them larger than 10^9. We randomly choose a pair and\n;; adopt the prime as modulus and the primitive root as base.\n(declaim ((simple-array (unsigned-byte 31) (100)) *moduli-table* *base-table*))\n(defparameter *moduli-table*\n (make-array 100 :element-type '(unsigned-byte 31)\n :initial-contents '(2147483647 2147483629 2147483587 2147483579 2147483563 2147483549 2147483543\n 2147483497 2147483489 2147483477 2147483423 2147483399 2147483353 2147483323\n 2147483269 2147483249 2147483237 2147483179 2147483171 2147483137 2147483123\n 2147483077 2147483069 2147483059 2147483053 2147483033 2147483029 2147482951\n 2147482949 2147482943 2147482937 2147482921 2147482877 2147482873 2147482867\n 2147482859 2147482819 2147482817 2147482811 2147482801 2147482763 2147482739\n 2147482697 2147482693 2147482681 2147482663 2147482661 2147482621 2147482591\n 2147482583 2147482577 2147482507 2147482501 2147482481 2147482417 2147482409\n 2147482367 2147482361 2147482349 2147482343 2147482327 2147482291 2147482273\n 2147482237 2147482231 2147482223 2147482121 2147482093 2147482091 2147482081\n 2147482063 2147482021 2147481997 2147481967 2147481949 2147481937 2147481907\n 2147481901 2147481899 2147481893 2147481883 2147481863 2147481827 2147481811\n 2147481797 2147481793 2147481673 2147481629 2147481571 2147481563 2147481529\n 2147481509 2147481499 2147481491 2147481487 2147481373 2147481367 2147481359\n 2147481353 2147481337)))\n(defparameter *base-table*\n (make-array 100 :element-type '(unsigned-byte 31)\n :initial-contents '(1059428526 2090066834 1772913519 1695158082 1516083910 1622025757 1248368302\n 1894391153 2094976878 1193495823 1783230399 1520742486 1748395380 1703688443\n 2138630366 1942049269 2066548889 1890950855 1480056952 1792721876 1092797280\n 1204851872 1035383130 1002272185 1319736653 1980774767 1748793187 1866963602\n 1200445534 1732959733 1214706585 1957228822 1479411729 1323155655 1052714514\n 1989821027 1163834549 1095622874 2087901566 1670886084 1191975321 2091468260\n 1429690292 1116037844 1420457779 1937649612 1552519679 1328604092 2090326292\n 1397132095 1316705322 1664351025 1391513321 1851038917 1556301575 1928956735\n 1764506480 1449537491 2119470570 1793768237 1831208371 1723755364 1643456516\n 1993819805 1419297891 1755252963 1775153034 1388979165 2144586633 1501222238\n 1872274033 1143076711 1229125474 1483974015 1997206147 1593231852 1632083893\n 1601537043 2012194627 1299923971 1566635240 1814404069 1619988648 2072686565\n 2014361572 1213868607 1166967329 1009325840 1306167671 1915239658 1223190075\n 1821151471 2037700892 1646950698 1517859810 1099233635 1004913731 1653443892\n 1782112665 1018916580)))\n\n(defun %choose-moduli (mod1 mod2 base1 base2 rhash)\n \"Chooses two appropriate pairs of moduli and bases.\"\n (declare ((or null (unsigned-byte 31)) mod1 mod2 base1 base2))\n (when rhash\n (return-from %choose-moduli\n (values (rhash-mod1 rhash)\n (rhash-mod2 rhash)\n (rhash-base1 rhash)\n (rhash-base2 rhash))))\n (let* ((rand1 (random (length *moduli-table*)))\n (rand2 (loop (let ((tmp (random (length *moduli-table*))))\n (unless (= tmp rand1)\n (return tmp))))))\n (if mod1\n (progn\n (assert (sb-int:positive-primep mod1))\n (setq base1 (or base1 (+ 1 (random (- mod1 1))))))\n (progn\n (setq mod1 (or mod1 (aref *moduli-table* rand1)))\n (if base1\n (assert (<= 1 base1 (- mod1 1)))\n (setq base1 (aref *base-table* rand1)))))\n (if mod2\n (progn\n (assert (sb-int:positive-primep mod2))\n (setq base2 (or base2 (+ 1 (random (- mod2 1))))))\n (progn\n (setq mod2 (or mod2 (aref *moduli-table* rand2)))\n (if base2\n (assert (<= 1 base2 (- mod2 1)))\n (setq base2 (aref *base-table* rand2))))))\n (values mod1 mod2 base1 base2))\n\n(defun make-rhash (vector &key (key #'char-code) mod1 mod2 base1 base2 rhash)\n \"Returns the table of rolling-hash of VECTOR modulo MOD1 and MOD2. KEY is\napplied to each element of VECTOR prior to computing the hash value. If moduli\nand bases are NIL, this function randomly chooses them. If RHASH is specified,\nthe same moduli and bases as RHASH is adopted.\n\nMOD[1|2] := NIL | unsigned 31-bit prime number\nBASE1 := NIL | 1 | 2 | ... | MOD1 - 1\nBASE2 := NIL | 1 | 2 | ... | MOD2 - 1\nKEY := FUNCTION returning FIXNUM\nRHASH := NIL | RHASH\"\n (declare (optimize (speed 3))\n (vector vector)\n ((or null (unsigned-byte 31)) mod1 mod2 base1 base2)\n (function key))\n (multiple-value-bind (mod1 mod2 base1 base2) (%choose-moduli mod1 mod2 base1 base2 rhash)\n (declare ((unsigned-byte 31) mod1 mod2 base1 base2))\n (let* ((size (length vector))\n (cumul1 (make-array (+ 1 size) :element-type '(unsigned-byte 31)))\n (powers1 (make-array (+ 1 size) :element-type '(unsigned-byte 31)))\n (cumul2 (make-array (+ 1 size) :element-type '(unsigned-byte 31)))\n (powers2 (make-array (+ 1 size) :element-type '(unsigned-byte 31))))\n (setf (aref powers1 0) 1\n (aref powers2 0) 1)\n (dotimes (i size)\n (setf (aref powers1 (+ i 1))\n (mod (* (aref powers1 i) base1) mod1)\n (aref powers2 (+ i 1))\n (mod (* (aref powers2 i) base2) mod2))\n (let ((sum1 (+ (mod (* base1 (aref cumul1 i)) mod1)\n (mod (the fixnum (funcall key (aref vector i))) mod1)))\n (sum2 (+ (mod (* base2 (aref cumul2 i)) mod2)\n (mod (the fixnum (funcall key (aref vector i))) mod2))))\n (setf (aref cumul1 (+ i 1)) (if (> sum1 mod1)\n (- sum1 mod1)\n sum1)\n (aref cumul2 (+ i 1)) (if (> sum2 mod2)\n (- sum2 mod2)\n sum2))))\n (%make-rhash mod1 base1 cumul1 powers1 mod2 base2 cumul2 powers2))))\n\n(declaim (ftype (function * (values (unsigned-byte 62) &optional)) rhash-vector-hash)\n (inline rhash-vector-hash))\n(defun rhash-vector-hash (rhash vector &key (key #'char-code))\n \"Returns the hash code of VECTOR w.r.t. the moduli and bases of RHASH.\"\n (declare (optimize (speed 3))\n (vector vector)\n (function key))\n (let* ((mod1 (rhash-mod1 rhash))\n (mod2 (rhash-mod2 rhash))\n (base1 (rhash-base1 rhash))\n (base2 (rhash-base2 rhash))\n (size (length vector))\n (lower 0)\n (upper 0))\n (declare ((unsigned-byte 31) lower upper))\n (dotimes (i size)\n (setf lower (+ (mod (* base1 lower) mod1)\n (mod (the fixnum (funcall key (aref vector i))) mod1)))\n (setf upper (+ (mod (* base2 upper) mod2)\n (mod (the fixnum (funcall key (aref vector i))) mod2))))\n (dpb upper (byte 31 31) lower)))\n\n(declaim (inline rhash-query)\n (ftype (function * (values (unsigned-byte 62) &optional)) rhash-query))\n(defun rhash-query (rhash l r)\n \"Returns the hash value of the interval [L, R).\"\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (assert (<= l r))\n (let ((cumul1 (rhash-cumul1 rhash))\n (powers1 (rhash-powers1 rhash))\n (mod1 (rhash-mod1 rhash))\n (cumul2 (rhash-cumul2 rhash))\n (powers2 (rhash-powers2 rhash))\n (mod2 (rhash-mod2 rhash)))\n (let ((lower (+ (aref cumul1 r)\n (- mod1 (mod (* (aref cumul1 l) (aref powers1 (- r l))) mod1))))\n (upper (+ (aref cumul2 r)\n (- mod2 (mod (* (aref cumul2 l) (aref powers2 (- r l))) mod2)))))\n (let ((lower (if (> lower mod1) (- lower mod1) lower))\n (upper (if (> upper mod2) (- upper mod2) upper)))\n (declare ((unsigned-byte 31) lower upper))\n (dpb upper (byte 31 31) lower)))))\n\n(declaim (inline rhash-concat))\n(defun rhash-concat (rhash hash1 hash2 length2)\n \"Returns the hash value of the concatenated sequence.\n\nHASH1 := hash value of the first sequence\nHASH2 := hash value of the second sequence\nLENGTH2 := length of the second sequence.\"\n (declare ((unsigned-byte 62) hash1 hash2)\n ((integer 0 #.most-positive-fixnum) length2))\n (let* ((hash1-lower (ldb (byte 31 0) hash1))\n (hash1-upper (ldb (byte 31 31) hash1))\n (hash2-lower (ldb (byte 31 0) hash2))\n (hash2-upper (ldb (byte 31 31) hash2))\n (mod1 (rhash-mod1 rhash))\n (mod2 (rhash-mod2 rhash))\n (res-lower (mod (+ hash2-lower\n (mod (* hash1-lower\n (aref (rhash-powers1 rhash) length2))\n mod1))\n mod1))\n (res-upper (mod (+ hash2-upper\n (mod (* hash1-upper\n (aref (rhash-powers2 rhash) length2))\n mod2))\n mod2)))\n (declare ((unsigned-byte 31) res-lower res-upper))\n (dpb res-upper (byte 31 31) res-lower)))\n\n(declaim (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) rhash-get-lcp))\n(defun rhash-get-lcp (rhash1 start1 rhash2 start2)\n \"Returns the length of the longest common prefix of two suffixes which begin\nat START1 and START2.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) start1 start2))\n (assert (and (= (rhash-mod1 rhash1) (rhash-mod1 rhash2))\n (= (rhash-mod2 rhash1) (rhash-mod2 rhash2))))\n (assert (and (< start1 (length (rhash-cumul1 rhash1)))\n (< start2 (length (rhash-cumul1 rhash2)))))\n (let ((max-length (min (- (length (rhash-cumul1 rhash1)) start1 1)\n (- (length (rhash-cumul1 rhash2)) start2 1))))\n (declare (optimize (safety 0)))\n (if (= (rhash-query rhash1 start1 (+ start1 max-length))\n (rhash-query rhash2 start2 (+ start2 max-length)))\n max-length\n (labels ((bisect (ok ng)\n (declare ((integer 0 #.most-positive-fixnum) ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (= (rhash-query rhash1 start1 (+ start1 mid))\n (rhash-query rhash2 start2 (+ start2 mid)))\n (bisect mid ng)\n (bisect ok mid))))))\n (bisect 0 max-length)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((ss (coerce (read-line) 'simple-base-string))\n (ts (coerce (read-line) 'simple-base-string))\n (slen (length ss))\n (tlen (length ts))\n (snum (max 3 (ceiling (* tlen 4) slen)))\n (ex-ss (make-string (* snum slen) :element-type 'base-char)))\n (declare (uint31 slen tlen snum))\n (dotimes (i slen)\n (dotimes (fac snum)\n (setf (aref ex-ss (+ i (* fac slen)))\n (aref ss i))))\n (let* ((rhash (make-rhash ex-ss))\n (total-len (* snum slen))\n (thash (rhash-vector-hash rhash ts))\n (base 0))\n (block maybe-infinite\n (loop (unless (<= (+ base tlen) total-len)\n (return))\n (when (= thash (rhash-query rhash base (+ base tlen)))\n ;; possibly infinite\n (loop for i from base by tlen\n while (<= (+ i tlen) total-len)\n do (unless (= thash (rhash-query rhash i (+ i tlen)))\n (return-from maybe-infinite))\n finally (let* ((l base)\n (r i)\n (dif (+ l (- total-len r))))\n (if (<= dif (* 2 (- tlen 1)))\n (progn (println -1)\n (return-from main))\n (return-from maybe-infinite)))))\n (incf base)))\n #>total-len\n ;; not infinite\n (let ((base 0)\n (res 0))\n (loop \n (unless (<= (+ base tlen) total-len)\n (return))\n (if (= thash (rhash-query rhash base (+ base tlen)))\n (loop for i from base by tlen\n do (unless (<= (+ i tlen) total-len)\n (setf base i)\n (setf res (max res (floor (- i base) tlen)))\n (loop-finish))\n (unless (= thash (rhash-query rhash i (+ i tlen)))\n (setf res (max res (floor (- i base) tlen)))\n (setf base i)\n (loop-finish)))\n (incf base)))\n (println res)))))\n\n#-swank (main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &optional (func #'main))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNC, and returns true if the\nstring output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (and (> (length s) 0)\n (eql (char s (- (length s) 1)) #\\Linefeed))\n s\n (uiop:strcat s uiop:+lf+))))\n (equal (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall func)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n (let ((*standard-output* out))\n (etypecase thing\n (null ; Runs #'MAIN with the string on clipboard\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname ; Runs #'MAIN with the string in a text file\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"abcabab\nab\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"aa\naaaaaaa\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"aba\nbaaab\n\"\n \"0\n\")))\n", "language": "Lisp", "metadata": {"date": 1564280594, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02962.html", "problem_id": "p02962", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02962/input.txt", "sample_output_relpath": "derived/input_output/data/p02962/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02962/Lisp/s485306228.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s485306228", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Rolling hash (62-bit)\n;;;\n\n;; Reference:\n;; https://www.mii.lt/olympiads_in_informatics/pdf/INFOL119.pdf\n;; https://ei1333.github.io/luzhiled/snippets/string/rolling-hash.html\n\n(defstruct (rhash (:constructor %make-rhash (mod1 base1 cumul1 powers1 mod2 base2 cumul2 powers2)))\n ;; lower 31-bit value\n (mod1 2147483647 :type (unsigned-byte 31))\n (base1 1059428526 :type (unsigned-byte 31))\n (cumul1 nil :type (simple-array (unsigned-byte 31) (*)))\n (powers1 nil :type (simple-array (unsigned-byte 31) (*)))\n ;; upper 31-bit value\n (mod2 2147483629 :type (unsigned-byte 31))\n (base2 2090066834 :type (unsigned-byte 31))\n (cumul2 nil :type (simple-array (unsigned-byte 31) (*)))\n (powers2 nil :type (simple-array (unsigned-byte 31) (*))))\n\n;; This table consists of pairs of primes less than 2^31 and the random\n;; primitive roots modulo them larger than 10^9. We randomly choose a pair and\n;; adopt the prime as modulus and the primitive root as base.\n(declaim ((simple-array (unsigned-byte 31) (100)) *moduli-table* *base-table*))\n(defparameter *moduli-table*\n (make-array 100 :element-type '(unsigned-byte 31)\n :initial-contents '(2147483647 2147483629 2147483587 2147483579 2147483563 2147483549 2147483543\n 2147483497 2147483489 2147483477 2147483423 2147483399 2147483353 2147483323\n 2147483269 2147483249 2147483237 2147483179 2147483171 2147483137 2147483123\n 2147483077 2147483069 2147483059 2147483053 2147483033 2147483029 2147482951\n 2147482949 2147482943 2147482937 2147482921 2147482877 2147482873 2147482867\n 2147482859 2147482819 2147482817 2147482811 2147482801 2147482763 2147482739\n 2147482697 2147482693 2147482681 2147482663 2147482661 2147482621 2147482591\n 2147482583 2147482577 2147482507 2147482501 2147482481 2147482417 2147482409\n 2147482367 2147482361 2147482349 2147482343 2147482327 2147482291 2147482273\n 2147482237 2147482231 2147482223 2147482121 2147482093 2147482091 2147482081\n 2147482063 2147482021 2147481997 2147481967 2147481949 2147481937 2147481907\n 2147481901 2147481899 2147481893 2147481883 2147481863 2147481827 2147481811\n 2147481797 2147481793 2147481673 2147481629 2147481571 2147481563 2147481529\n 2147481509 2147481499 2147481491 2147481487 2147481373 2147481367 2147481359\n 2147481353 2147481337)))\n(defparameter *base-table*\n (make-array 100 :element-type '(unsigned-byte 31)\n :initial-contents '(1059428526 2090066834 1772913519 1695158082 1516083910 1622025757 1248368302\n 1894391153 2094976878 1193495823 1783230399 1520742486 1748395380 1703688443\n 2138630366 1942049269 2066548889 1890950855 1480056952 1792721876 1092797280\n 1204851872 1035383130 1002272185 1319736653 1980774767 1748793187 1866963602\n 1200445534 1732959733 1214706585 1957228822 1479411729 1323155655 1052714514\n 1989821027 1163834549 1095622874 2087901566 1670886084 1191975321 2091468260\n 1429690292 1116037844 1420457779 1937649612 1552519679 1328604092 2090326292\n 1397132095 1316705322 1664351025 1391513321 1851038917 1556301575 1928956735\n 1764506480 1449537491 2119470570 1793768237 1831208371 1723755364 1643456516\n 1993819805 1419297891 1755252963 1775153034 1388979165 2144586633 1501222238\n 1872274033 1143076711 1229125474 1483974015 1997206147 1593231852 1632083893\n 1601537043 2012194627 1299923971 1566635240 1814404069 1619988648 2072686565\n 2014361572 1213868607 1166967329 1009325840 1306167671 1915239658 1223190075\n 1821151471 2037700892 1646950698 1517859810 1099233635 1004913731 1653443892\n 1782112665 1018916580)))\n\n(defun %choose-moduli (mod1 mod2 base1 base2 rhash)\n \"Chooses two appropriate pairs of moduli and bases.\"\n (declare ((or null (unsigned-byte 31)) mod1 mod2 base1 base2))\n (when rhash\n (return-from %choose-moduli\n (values (rhash-mod1 rhash)\n (rhash-mod2 rhash)\n (rhash-base1 rhash)\n (rhash-base2 rhash))))\n (let* ((rand1 (random (length *moduli-table*)))\n (rand2 (loop (let ((tmp (random (length *moduli-table*))))\n (unless (= tmp rand1)\n (return tmp))))))\n (if mod1\n (progn\n (assert (sb-int:positive-primep mod1))\n (setq base1 (or base1 (+ 1 (random (- mod1 1))))))\n (progn\n (setq mod1 (or mod1 (aref *moduli-table* rand1)))\n (if base1\n (assert (<= 1 base1 (- mod1 1)))\n (setq base1 (aref *base-table* rand1)))))\n (if mod2\n (progn\n (assert (sb-int:positive-primep mod2))\n (setq base2 (or base2 (+ 1 (random (- mod2 1))))))\n (progn\n (setq mod2 (or mod2 (aref *moduli-table* rand2)))\n (if base2\n (assert (<= 1 base2 (- mod2 1)))\n (setq base2 (aref *base-table* rand2))))))\n (values mod1 mod2 base1 base2))\n\n(defun make-rhash (vector &key (key #'char-code) mod1 mod2 base1 base2 rhash)\n \"Returns the table of rolling-hash of VECTOR modulo MOD1 and MOD2. KEY is\napplied to each element of VECTOR prior to computing the hash value. If moduli\nand bases are NIL, this function randomly chooses them. If RHASH is specified,\nthe same moduli and bases as RHASH is adopted.\n\nMOD[1|2] := NIL | unsigned 31-bit prime number\nBASE1 := NIL | 1 | 2 | ... | MOD1 - 1\nBASE2 := NIL | 1 | 2 | ... | MOD2 - 1\nKEY := FUNCTION returning FIXNUM\nRHASH := NIL | RHASH\"\n (declare (optimize (speed 3))\n (vector vector)\n ((or null (unsigned-byte 31)) mod1 mod2 base1 base2)\n (function key))\n (multiple-value-bind (mod1 mod2 base1 base2) (%choose-moduli mod1 mod2 base1 base2 rhash)\n (declare ((unsigned-byte 31) mod1 mod2 base1 base2))\n (let* ((size (length vector))\n (cumul1 (make-array (+ 1 size) :element-type '(unsigned-byte 31)))\n (powers1 (make-array (+ 1 size) :element-type '(unsigned-byte 31)))\n (cumul2 (make-array (+ 1 size) :element-type '(unsigned-byte 31)))\n (powers2 (make-array (+ 1 size) :element-type '(unsigned-byte 31))))\n (setf (aref powers1 0) 1\n (aref powers2 0) 1)\n (dotimes (i size)\n (setf (aref powers1 (+ i 1))\n (mod (* (aref powers1 i) base1) mod1)\n (aref powers2 (+ i 1))\n (mod (* (aref powers2 i) base2) mod2))\n (let ((sum1 (+ (mod (* base1 (aref cumul1 i)) mod1)\n (mod (the fixnum (funcall key (aref vector i))) mod1)))\n (sum2 (+ (mod (* base2 (aref cumul2 i)) mod2)\n (mod (the fixnum (funcall key (aref vector i))) mod2))))\n (setf (aref cumul1 (+ i 1)) (if (> sum1 mod1)\n (- sum1 mod1)\n sum1)\n (aref cumul2 (+ i 1)) (if (> sum2 mod2)\n (- sum2 mod2)\n sum2))))\n (%make-rhash mod1 base1 cumul1 powers1 mod2 base2 cumul2 powers2))))\n\n(declaim (ftype (function * (values (unsigned-byte 62) &optional)) rhash-vector-hash)\n (inline rhash-vector-hash))\n(defun rhash-vector-hash (rhash vector &key (key #'char-code))\n \"Returns the hash code of VECTOR w.r.t. the moduli and bases of RHASH.\"\n (declare (optimize (speed 3))\n (vector vector)\n (function key))\n (let* ((mod1 (rhash-mod1 rhash))\n (mod2 (rhash-mod2 rhash))\n (base1 (rhash-base1 rhash))\n (base2 (rhash-base2 rhash))\n (size (length vector))\n (lower 0)\n (upper 0))\n (declare ((unsigned-byte 31) lower upper))\n (dotimes (i size)\n (setf lower (+ (mod (* base1 lower) mod1)\n (mod (the fixnum (funcall key (aref vector i))) mod1)))\n (setf upper (+ (mod (* base2 upper) mod2)\n (mod (the fixnum (funcall key (aref vector i))) mod2))))\n (dpb upper (byte 31 31) lower)))\n\n(declaim (inline rhash-query)\n (ftype (function * (values (unsigned-byte 62) &optional)) rhash-query))\n(defun rhash-query (rhash l r)\n \"Returns the hash value of the interval [L, R).\"\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (assert (<= l r))\n (let ((cumul1 (rhash-cumul1 rhash))\n (powers1 (rhash-powers1 rhash))\n (mod1 (rhash-mod1 rhash))\n (cumul2 (rhash-cumul2 rhash))\n (powers2 (rhash-powers2 rhash))\n (mod2 (rhash-mod2 rhash)))\n (let ((lower (+ (aref cumul1 r)\n (- mod1 (mod (* (aref cumul1 l) (aref powers1 (- r l))) mod1))))\n (upper (+ (aref cumul2 r)\n (- mod2 (mod (* (aref cumul2 l) (aref powers2 (- r l))) mod2)))))\n (let ((lower (if (> lower mod1) (- lower mod1) lower))\n (upper (if (> upper mod2) (- upper mod2) upper)))\n (declare ((unsigned-byte 31) lower upper))\n (dpb upper (byte 31 31) lower)))))\n\n(declaim (inline rhash-concat))\n(defun rhash-concat (rhash hash1 hash2 length2)\n \"Returns the hash value of the concatenated sequence.\n\nHASH1 := hash value of the first sequence\nHASH2 := hash value of the second sequence\nLENGTH2 := length of the second sequence.\"\n (declare ((unsigned-byte 62) hash1 hash2)\n ((integer 0 #.most-positive-fixnum) length2))\n (let* ((hash1-lower (ldb (byte 31 0) hash1))\n (hash1-upper (ldb (byte 31 31) hash1))\n (hash2-lower (ldb (byte 31 0) hash2))\n (hash2-upper (ldb (byte 31 31) hash2))\n (mod1 (rhash-mod1 rhash))\n (mod2 (rhash-mod2 rhash))\n (res-lower (mod (+ hash2-lower\n (mod (* hash1-lower\n (aref (rhash-powers1 rhash) length2))\n mod1))\n mod1))\n (res-upper (mod (+ hash2-upper\n (mod (* hash1-upper\n (aref (rhash-powers2 rhash) length2))\n mod2))\n mod2)))\n (declare ((unsigned-byte 31) res-lower res-upper))\n (dpb res-upper (byte 31 31) res-lower)))\n\n(declaim (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) rhash-get-lcp))\n(defun rhash-get-lcp (rhash1 start1 rhash2 start2)\n \"Returns the length of the longest common prefix of two suffixes which begin\nat START1 and START2.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) start1 start2))\n (assert (and (= (rhash-mod1 rhash1) (rhash-mod1 rhash2))\n (= (rhash-mod2 rhash1) (rhash-mod2 rhash2))))\n (assert (and (< start1 (length (rhash-cumul1 rhash1)))\n (< start2 (length (rhash-cumul1 rhash2)))))\n (let ((max-length (min (- (length (rhash-cumul1 rhash1)) start1 1)\n (- (length (rhash-cumul1 rhash2)) start2 1))))\n (declare (optimize (safety 0)))\n (if (= (rhash-query rhash1 start1 (+ start1 max-length))\n (rhash-query rhash2 start2 (+ start2 max-length)))\n max-length\n (labels ((bisect (ok ng)\n (declare ((integer 0 #.most-positive-fixnum) ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (= (rhash-query rhash1 start1 (+ start1 mid))\n (rhash-query rhash2 start2 (+ start2 mid)))\n (bisect mid ng)\n (bisect ok mid))))))\n (bisect 0 max-length)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((ss (coerce (read-line) 'simple-base-string))\n (ts (coerce (read-line) 'simple-base-string))\n (slen (length ss))\n (tlen (length ts))\n (snum (max 3 (ceiling (* tlen 4) slen)))\n (ex-ss (make-string (* snum slen) :element-type 'base-char)))\n (declare (uint31 slen tlen snum))\n (dotimes (i slen)\n (dotimes (fac snum)\n (setf (aref ex-ss (+ i (* fac slen)))\n (aref ss i))))\n (let* ((rhash (make-rhash ex-ss))\n (total-len (* snum slen))\n (thash (rhash-vector-hash rhash ts))\n (base 0))\n (block maybe-infinite\n (loop (unless (<= (+ base tlen) total-len)\n (return))\n (when (= thash (rhash-query rhash base (+ base tlen)))\n ;; possibly infinite\n (loop for i from base by tlen\n while (<= (+ i tlen) total-len)\n do (unless (= thash (rhash-query rhash i (+ i tlen)))\n (return-from maybe-infinite))\n finally (let* ((l base)\n (r i)\n (dif (+ l (- total-len r))))\n (if (<= dif (* 2 (- tlen 1)))\n (progn (println -1)\n (return-from main))\n (return-from maybe-infinite)))))\n (incf base)))\n #>total-len\n ;; not infinite\n (let ((base 0)\n (res 0))\n (loop \n (unless (<= (+ base tlen) total-len)\n (return))\n (if (= thash (rhash-query rhash base (+ base tlen)))\n (loop for i from base by tlen\n do (unless (<= (+ i tlen) total-len)\n (setf base i)\n (setf res (max res (floor (- i base) tlen)))\n (loop-finish))\n (unless (= thash (rhash-query rhash i (+ i tlen)))\n (setf res (max res (floor (- i base) tlen)))\n (setf base i)\n (loop-finish)))\n (incf base)))\n (println res)))))\n\n#-swank (main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &optional (func #'main))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNC, and returns true if the\nstring output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (and (> (length s) 0)\n (eql (char s (- (length s) 1)) #\\Linefeed))\n s\n (uiop:strcat s uiop:+lf+))))\n (equal (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall func)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n (let ((*standard-output* out))\n (etypecase thing\n (null ; Runs #'MAIN with the string on clipboard\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname ; Runs #'MAIN with the string in a text file\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"abcabab\nab\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"aa\naaaaaaa\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"aba\nbaaab\n\"\n \"0\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven are two strings s and t consisting of lowercase English letters. Determine if the number of non-negative integers i satisfying the following condition is finite, and find the maximum value of such i if the number is finite.\n\nThere exists a non-negative integer j such that the concatenation of i copies of t is a substring of the concatenation of j copies of s.\n\nNotes\n\nA string a is a substring of another string b if and only if there exists an integer x (0 \\leq x \\leq |b| - |a|) such that, for any y (1 \\leq y \\leq |a|), a_y = b_{x+y} holds.\n\nWe assume that the concatenation of zero copies of any string is the empty string. From the definition above, the empty string is a substring of any string. Thus, for any two strings s and t, i = 0 satisfies the condition in the problem statement.\n\nConstraints\n\n1 \\leq |s| \\leq 5 \\times 10^5\n\n1 \\leq |t| \\leq 5 \\times 10^5\n\ns and t consist of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\nt\n\nOutput\n\nIf the number of non-negative integers i satisfying the following condition is finite, print the maximum value of such i; if the number is infinite, print -1.\n\nSample Input 1\n\nabcabab\nab\n\nSample Output 1\n\n3\n\nThe concatenation of three copies of t, ababab, is a substring of the concatenation of two copies of s, abcabababcabab, so i = 3 satisfies the condition.\n\nOn the other hand, the concatenation of four copies of t, abababab, is not a substring of the concatenation of any number of copies of s, so i = 4 does not satisfy the condition.\n\nSimilarly, any integer greater than 4 does not satisfy the condition, either. Thus, the number of non-negative integers i satisfying the condition is finite, and the maximum value of such i is 3.\n\nSample Input 2\n\naa\naaaaaaa\n\nSample Output 2\n\n-1\n\nFor any non-negative integer i, the concatenation of i copies of t is a substring of the concatenation of 4i copies of s. Thus, there are infinitely many non-negative integers i that satisfy the condition.\n\nSample Input 3\n\naba\nbaaab\n\nSample Output 3\n\n0\n\nAs stated in Notes, i = 0 always satisfies the condition.", "sample_input": "abcabab\nab\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02962", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are two strings s and t consisting of lowercase English letters. Determine if the number of non-negative integers i satisfying the following condition is finite, and find the maximum value of such i if the number is finite.\n\nThere exists a non-negative integer j such that the concatenation of i copies of t is a substring of the concatenation of j copies of s.\n\nNotes\n\nA string a is a substring of another string b if and only if there exists an integer x (0 \\leq x \\leq |b| - |a|) such that, for any y (1 \\leq y \\leq |a|), a_y = b_{x+y} holds.\n\nWe assume that the concatenation of zero copies of any string is the empty string. From the definition above, the empty string is a substring of any string. Thus, for any two strings s and t, i = 0 satisfies the condition in the problem statement.\n\nConstraints\n\n1 \\leq |s| \\leq 5 \\times 10^5\n\n1 \\leq |t| \\leq 5 \\times 10^5\n\ns and t consist of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\nt\n\nOutput\n\nIf the number of non-negative integers i satisfying the following condition is finite, print the maximum value of such i; if the number is infinite, print -1.\n\nSample Input 1\n\nabcabab\nab\n\nSample Output 1\n\n3\n\nThe concatenation of three copies of t, ababab, is a substring of the concatenation of two copies of s, abcabababcabab, so i = 3 satisfies the condition.\n\nOn the other hand, the concatenation of four copies of t, abababab, is not a substring of the concatenation of any number of copies of s, so i = 4 does not satisfy the condition.\n\nSimilarly, any integer greater than 4 does not satisfy the condition, either. Thus, the number of non-negative integers i satisfying the condition is finite, and the maximum value of such i is 3.\n\nSample Input 2\n\naa\naaaaaaa\n\nSample Output 2\n\n-1\n\nFor any non-negative integer i, the concatenation of i copies of t is a substring of the concatenation of 4i copies of s. Thus, there are infinitely many non-negative integers i that satisfy the condition.\n\nSample Input 3\n\naba\nbaaab\n\nSample Output 3\n\n0\n\nAs stated in Notes, i = 0 always satisfies the condition.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 16960, "cpu_time_ms": 774, "memory_kb": 84584}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s765626985", "group_id": "codeNet:p02964", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (inline println-sequence))\n(defun println-sequence (sequence &key (out *standard-output*) (key #'identity))\n (let ((init t))\n (sequence:dosequence (x sequence)\n (if init\n (setq init nil)\n (write-char #\\ out))\n (princ (funcall key x) out))\n (terpri out)))\n\n;;;\n;;; Calculate a^n on any monoids in O(log(n)) time\n;;;\n\n(declaim (inline power))\n(defun power (base exponent op identity)\n \"OP := binary operation (on a monoid)\nIDENTITY := identity element w.r.t. OP\"\n (declare ((integer 0) exponent)\n (function op))\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) p))\n (cond ((= 0 p) identity)\n ((evenp p) (recur (funcall op x x) (ash p -1)))\n (t (nth-value 0 (funcall op x (recur x (- p 1)))))))\n (recur-big (x p)\n (declare ((integer 0) p))\n (cond ((zerop p) identity)\n ((evenp p) (recur-big (funcall op x x) (ash p -1)))\n (t (nth-value 0 (funcall op x (recur-big x (- p 1))))))))\n (typecase exponent\n (fixnum (recur base exponent))\n (otherwise (recur-big base exponent)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'uint32 :initial-element 0))\n (last-table (make-array 200001 :element-type 'uint32 :initial-element 0))\n (nexts (make-array (+ n 1) :element-type 'uint32 :initial-element 0))\n (iden (make-array (+ n 1) :element-type 'uint32 :initial-element 0)))\n (declare (uint62 n k))\n (dotimes (i n) (setf (aref as i) (read-fixnum)))\n (dotimes (i (+ n 1)) (setf (aref iden i) i))\n (loop for i from (- (* 2 n) 1) downto 0\n do (when (< i n)\n (setf (aref nexts i) (+ 1 (aref last-table (aref as i)))))\n (setf (aref last-table (aref as (mod i n))) i))\n (let ((perm (copy-seq nexts)))\n (loop for i from (- n 1) downto 0\n do (when (< (aref perm i) n)\n (setf (aref perm i) (aref perm (aref perm i)))))\n (dotimes (i n)\n (setf (aref perm i) (- (aref perm i) n)))\n (let* ((final-perm\n (power perm (- k 1)\n (lambda (x y)\n (declare ((simple-array uint32 (*)) x y))\n (let ((new (make-array (+ n 1) :element-type 'uint32)))\n (dotimes (i (+ n 1))\n (setf (aref new i) (aref y (aref x i))))\n new))\n iden))\n (pos (aref final-perm 0))\n (res (make-array 0 :fill-pointer 0)))\n ;; #>final-perm\n (loop (when (= pos n)\n (with-buffered-stdout\n (println-sequence res))\n (return-from main))\n (if (<= (aref nexts pos) n)\n (setq pos (aref nexts pos))\n (progn\n (vector-push-extend (aref as pos) res)\n (incf pos))))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1563780513, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02964.html", "problem_id": "p02964", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02964/input.txt", "sample_output_relpath": "derived/input_output/data/p02964/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02964/Lisp/s765626985.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s765626985", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2 3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (inline println-sequence))\n(defun println-sequence (sequence &key (out *standard-output*) (key #'identity))\n (let ((init t))\n (sequence:dosequence (x sequence)\n (if init\n (setq init nil)\n (write-char #\\ out))\n (princ (funcall key x) out))\n (terpri out)))\n\n;;;\n;;; Calculate a^n on any monoids in O(log(n)) time\n;;;\n\n(declaim (inline power))\n(defun power (base exponent op identity)\n \"OP := binary operation (on a monoid)\nIDENTITY := identity element w.r.t. OP\"\n (declare ((integer 0) exponent)\n (function op))\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) p))\n (cond ((= 0 p) identity)\n ((evenp p) (recur (funcall op x x) (ash p -1)))\n (t (nth-value 0 (funcall op x (recur x (- p 1)))))))\n (recur-big (x p)\n (declare ((integer 0) p))\n (cond ((zerop p) identity)\n ((evenp p) (recur-big (funcall op x x) (ash p -1)))\n (t (nth-value 0 (funcall op x (recur-big x (- p 1))))))))\n (typecase exponent\n (fixnum (recur base exponent))\n (otherwise (recur-big base exponent)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'uint32 :initial-element 0))\n (last-table (make-array 200001 :element-type 'uint32 :initial-element 0))\n (nexts (make-array (+ n 1) :element-type 'uint32 :initial-element 0))\n (iden (make-array (+ n 1) :element-type 'uint32 :initial-element 0)))\n (declare (uint62 n k))\n (dotimes (i n) (setf (aref as i) (read-fixnum)))\n (dotimes (i (+ n 1)) (setf (aref iden i) i))\n (loop for i from (- (* 2 n) 1) downto 0\n do (when (< i n)\n (setf (aref nexts i) (+ 1 (aref last-table (aref as i)))))\n (setf (aref last-table (aref as (mod i n))) i))\n (let ((perm (copy-seq nexts)))\n (loop for i from (- n 1) downto 0\n do (when (< (aref perm i) n)\n (setf (aref perm i) (aref perm (aref perm i)))))\n (dotimes (i n)\n (setf (aref perm i) (- (aref perm i) n)))\n (let* ((final-perm\n (power perm (- k 1)\n (lambda (x y)\n (declare ((simple-array uint32 (*)) x y))\n (let ((new (make-array (+ n 1) :element-type 'uint32)))\n (dotimes (i (+ n 1))\n (setf (aref new i) (aref y (aref x i))))\n new))\n iden))\n (pos (aref final-perm 0))\n (res (make-array 0 :fill-pointer 0)))\n ;; #>final-perm\n (loop (when (= pos n)\n (with-buffered-stdout\n (println-sequence res))\n (return-from main))\n (if (<= (aref nexts pos) n)\n (setq pos (aref nexts pos))\n (progn\n (vector-push-extend (aref as pos) res)\n (incf pos))))))))\n\n#-swank (main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nWe have a sequence of N \\times K integers: X=(X_0,X_1,\\cdots,X_{N \\times K-1}).\nIts elements are represented by another sequence of N integers: A=(A_0,A_1,\\cdots,A_{N-1}). For each pair i, j (0 \\leq i \\leq K-1,\\ 0 \\leq j \\leq N-1), X_{i \\times N + j}=A_j holds.\n\nSnuke has an integer sequence s, which is initially empty.\nFor each i=0,1,2,\\cdots,N \\times K-1, in this order, he will perform the following operation:\n\nIf s does not contain X_i: add X_i to the end of s.\n\nIf s does contain X_i: repeatedly delete the element at the end of s until s no longer contains X_i. Note that, in this case, we do not add X_i to the end of s.\n\nFind the elements of s after Snuke finished the operations.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq K \\leq 10^{12}\n\n1 \\leq A_i \\leq 2 \\times 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_0 A_1 \\cdots A_{N-1}\n\nOutput\n\nPrint the elements of s after Snuke finished the operations, in order from beginning to end, with spaces in between.\n\nSample Input 1\n\n3 2\n1 2 3\n\nSample Output 1\n\n2 3\n\nIn this case, X=(1,2,3,1,2,3).\nWe will perform the operations as follows:\n\ni=0: s does not contain 1, so we add 1 to the end of s, resulting in s=(1).\n\ni=1: s does not contain 2, so we add 2 to the end of s, resulting in s=(1,2).\n\ni=2: s does not contain 3, so we add 3 to the end of s, resulting in s=(1,2,3).\n\ni=3: s does contain 1, so we repeatedly delete the element at the end of s as long as s contains 1, which causes the following changes to s: (1,2,3)→(1,2)→(1)→().\n\ni=4: s does not contain 2, so we add 2 to the end of s, resulting in s=(2).\n\ni=5: s does not contain 3, so we add 3 to the end of s, resulting in s=(2,3).\n\nSample Input 2\n\n5 10\n1 2 3 2 3\n\nSample Output 2\n\n3\n\nSample Input 3\n\n6 1000000000000\n1 1 2 2 3 3\n\nSample Output 3\n\ns may be empty in the end.\n\nSample Input 4\n\n11 97\n3 1 4 1 5 9 2 6 5 3 5\n\nSample Output 4\n\n9 2 6", "sample_input": "3 2\n1 2 3\n"}, "reference_outputs": ["2 3\n"], "source_document_id": "p02964", "source_text": "Score : 700 points\n\nProblem Statement\n\nWe have a sequence of N \\times K integers: X=(X_0,X_1,\\cdots,X_{N \\times K-1}).\nIts elements are represented by another sequence of N integers: A=(A_0,A_1,\\cdots,A_{N-1}). For each pair i, j (0 \\leq i \\leq K-1,\\ 0 \\leq j \\leq N-1), X_{i \\times N + j}=A_j holds.\n\nSnuke has an integer sequence s, which is initially empty.\nFor each i=0,1,2,\\cdots,N \\times K-1, in this order, he will perform the following operation:\n\nIf s does not contain X_i: add X_i to the end of s.\n\nIf s does contain X_i: repeatedly delete the element at the end of s until s no longer contains X_i. Note that, in this case, we do not add X_i to the end of s.\n\nFind the elements of s after Snuke finished the operations.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq K \\leq 10^{12}\n\n1 \\leq A_i \\leq 2 \\times 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_0 A_1 \\cdots A_{N-1}\n\nOutput\n\nPrint the elements of s after Snuke finished the operations, in order from beginning to end, with spaces in between.\n\nSample Input 1\n\n3 2\n1 2 3\n\nSample Output 1\n\n2 3\n\nIn this case, X=(1,2,3,1,2,3).\nWe will perform the operations as follows:\n\ni=0: s does not contain 1, so we add 1 to the end of s, resulting in s=(1).\n\ni=1: s does not contain 2, so we add 2 to the end of s, resulting in s=(1,2).\n\ni=2: s does not contain 3, so we add 3 to the end of s, resulting in s=(1,2,3).\n\ni=3: s does contain 1, so we repeatedly delete the element at the end of s as long as s contains 1, which causes the following changes to s: (1,2,3)→(1,2)→(1)→().\n\ni=4: s does not contain 2, so we add 2 to the end of s, resulting in s=(2).\n\ni=5: s does not contain 3, so we add 3 to the end of s, resulting in s=(2,3).\n\nSample Input 2\n\n5 10\n1 2 3 2 3\n\nSample Output 2\n\n3\n\nSample Input 3\n\n6 1000000000000\n1 1 2 2 3 3\n\nSample Output 3\n\ns may be empty in the end.\n\nSample Input 4\n\n11 97\n3 1 4 1 5 9 2 6 5 3 5\n\nSample Output 4\n\n9 2 6", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5859, "cpu_time_ms": 269, "memory_kb": 67048}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s433328283", "group_id": "codeNet:p02964", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Calculate a^n on any monoids in O(log(n)) time\n;;;\n\n(declaim (inline power))\n(defun power (base exponent op identity)\n \"OP := binary operation (on a monoid)\nIDENTITY := identity element w.r.t. OP\"\n (declare ((integer 0) exponent)\n (function op))\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) p))\n (cond ((zerop p) identity)\n ((evenp p) (recur (funcall op x x) (ash p -1)))\n (t (nth-value 0 (funcall op x (recur x (- p 1)))))))\n (recur-big (x p)\n (declare ((integer 0) p))\n (cond ((zerop p) identity)\n ((evenp p) (recur-big (funcall op x x) (ash p -1)))\n (t (nth-value 0 (funcall op x (recur-big x (- p 1))))))))\n (typecase exponent\n (fixnum (recur base exponent))\n (otherwise (recur-big base exponent)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'uint32 :initial-element 0))\n (last-table (make-array 200001 :element-type 'uint32 :initial-element 0))\n (nexts (make-array n :element-type 'uint32 :initial-element 0))\n (iden (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum))\n (setf (aref iden i) i))\n (loop for i from (- (* 2 n) 1) downto 0\n do (when (< i n)\n (setf (aref nexts i) (+ 1 (aref last-table (aref as i)))))\n (setf (aref last-table (aref as (mod i n))) i))\n #>nexts\n (let ((perm (copy-seq nexts)))\n (loop for i from (- n 1) downto 0\n do (when (< (aref perm i) n)\n (setf (aref perm i) (aref perm (aref perm i)))))\n (dotimes (i n)\n (setf (aref perm i) (mod (aref perm i) n)))\n (let* ((final-perm (power perm (- k 1)\n (lambda (x y)\n (let ((new (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (setf (aref new i) (aref y (aref x i))))\n new))\n iden))\n (pos (aref final-perm 0))\n (res (make-array 0 :fill-pointer 0)))\n (loop (when (= pos n)\n (loop with init = t\n for i below (length res)\n do (if init\n (setq init nil)\n (write-char #\\ ))\n (princ (aref res i)))\n (terpri)\n (return-from main))\n (if (<= (aref nexts pos) n)\n (setq pos (aref nexts pos))\n (progn\n (vector-push-extend (aref as pos) res)\n (incf pos))))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1563767701, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02964.html", "problem_id": "p02964", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02964/input.txt", "sample_output_relpath": "derived/input_output/data/p02964/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02964/Lisp/s433328283.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s433328283", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2 3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Calculate a^n on any monoids in O(log(n)) time\n;;;\n\n(declaim (inline power))\n(defun power (base exponent op identity)\n \"OP := binary operation (on a monoid)\nIDENTITY := identity element w.r.t. OP\"\n (declare ((integer 0) exponent)\n (function op))\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) p))\n (cond ((zerop p) identity)\n ((evenp p) (recur (funcall op x x) (ash p -1)))\n (t (nth-value 0 (funcall op x (recur x (- p 1)))))))\n (recur-big (x p)\n (declare ((integer 0) p))\n (cond ((zerop p) identity)\n ((evenp p) (recur-big (funcall op x x) (ash p -1)))\n (t (nth-value 0 (funcall op x (recur-big x (- p 1))))))))\n (typecase exponent\n (fixnum (recur base exponent))\n (otherwise (recur-big base exponent)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'uint32 :initial-element 0))\n (last-table (make-array 200001 :element-type 'uint32 :initial-element 0))\n (nexts (make-array n :element-type 'uint32 :initial-element 0))\n (iden (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum))\n (setf (aref iden i) i))\n (loop for i from (- (* 2 n) 1) downto 0\n do (when (< i n)\n (setf (aref nexts i) (+ 1 (aref last-table (aref as i)))))\n (setf (aref last-table (aref as (mod i n))) i))\n #>nexts\n (let ((perm (copy-seq nexts)))\n (loop for i from (- n 1) downto 0\n do (when (< (aref perm i) n)\n (setf (aref perm i) (aref perm (aref perm i)))))\n (dotimes (i n)\n (setf (aref perm i) (mod (aref perm i) n)))\n (let* ((final-perm (power perm (- k 1)\n (lambda (x y)\n (let ((new (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (setf (aref new i) (aref y (aref x i))))\n new))\n iden))\n (pos (aref final-perm 0))\n (res (make-array 0 :fill-pointer 0)))\n (loop (when (= pos n)\n (loop with init = t\n for i below (length res)\n do (if init\n (setq init nil)\n (write-char #\\ ))\n (princ (aref res i)))\n (terpri)\n (return-from main))\n (if (<= (aref nexts pos) n)\n (setq pos (aref nexts pos))\n (progn\n (vector-push-extend (aref as pos) res)\n (incf pos))))))))\n\n#-swank (main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nWe have a sequence of N \\times K integers: X=(X_0,X_1,\\cdots,X_{N \\times K-1}).\nIts elements are represented by another sequence of N integers: A=(A_0,A_1,\\cdots,A_{N-1}). For each pair i, j (0 \\leq i \\leq K-1,\\ 0 \\leq j \\leq N-1), X_{i \\times N + j}=A_j holds.\n\nSnuke has an integer sequence s, which is initially empty.\nFor each i=0,1,2,\\cdots,N \\times K-1, in this order, he will perform the following operation:\n\nIf s does not contain X_i: add X_i to the end of s.\n\nIf s does contain X_i: repeatedly delete the element at the end of s until s no longer contains X_i. Note that, in this case, we do not add X_i to the end of s.\n\nFind the elements of s after Snuke finished the operations.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq K \\leq 10^{12}\n\n1 \\leq A_i \\leq 2 \\times 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_0 A_1 \\cdots A_{N-1}\n\nOutput\n\nPrint the elements of s after Snuke finished the operations, in order from beginning to end, with spaces in between.\n\nSample Input 1\n\n3 2\n1 2 3\n\nSample Output 1\n\n2 3\n\nIn this case, X=(1,2,3,1,2,3).\nWe will perform the operations as follows:\n\ni=0: s does not contain 1, so we add 1 to the end of s, resulting in s=(1).\n\ni=1: s does not contain 2, so we add 2 to the end of s, resulting in s=(1,2).\n\ni=2: s does not contain 3, so we add 3 to the end of s, resulting in s=(1,2,3).\n\ni=3: s does contain 1, so we repeatedly delete the element at the end of s as long as s contains 1, which causes the following changes to s: (1,2,3)→(1,2)→(1)→().\n\ni=4: s does not contain 2, so we add 2 to the end of s, resulting in s=(2).\n\ni=5: s does not contain 3, so we add 3 to the end of s, resulting in s=(2,3).\n\nSample Input 2\n\n5 10\n1 2 3 2 3\n\nSample Output 2\n\n3\n\nSample Input 3\n\n6 1000000000000\n1 1 2 2 3 3\n\nSample Output 3\n\ns may be empty in the end.\n\nSample Input 4\n\n11 97\n3 1 4 1 5 9 2 6 5 3 5\n\nSample Output 4\n\n9 2 6", "sample_input": "3 2\n1 2 3\n"}, "reference_outputs": ["2 3\n"], "source_document_id": "p02964", "source_text": "Score : 700 points\n\nProblem Statement\n\nWe have a sequence of N \\times K integers: X=(X_0,X_1,\\cdots,X_{N \\times K-1}).\nIts elements are represented by another sequence of N integers: A=(A_0,A_1,\\cdots,A_{N-1}). For each pair i, j (0 \\leq i \\leq K-1,\\ 0 \\leq j \\leq N-1), X_{i \\times N + j}=A_j holds.\n\nSnuke has an integer sequence s, which is initially empty.\nFor each i=0,1,2,\\cdots,N \\times K-1, in this order, he will perform the following operation:\n\nIf s does not contain X_i: add X_i to the end of s.\n\nIf s does contain X_i: repeatedly delete the element at the end of s until s no longer contains X_i. Note that, in this case, we do not add X_i to the end of s.\n\nFind the elements of s after Snuke finished the operations.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq K \\leq 10^{12}\n\n1 \\leq A_i \\leq 2 \\times 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_0 A_1 \\cdots A_{N-1}\n\nOutput\n\nPrint the elements of s after Snuke finished the operations, in order from beginning to end, with spaces in between.\n\nSample Input 1\n\n3 2\n1 2 3\n\nSample Output 1\n\n2 3\n\nIn this case, X=(1,2,3,1,2,3).\nWe will perform the operations as follows:\n\ni=0: s does not contain 1, so we add 1 to the end of s, resulting in s=(1).\n\ni=1: s does not contain 2, so we add 2 to the end of s, resulting in s=(1,2).\n\ni=2: s does not contain 3, so we add 3 to the end of s, resulting in s=(1,2,3).\n\ni=3: s does contain 1, so we repeatedly delete the element at the end of s as long as s contains 1, which causes the following changes to s: (1,2,3)→(1,2)→(1)→().\n\ni=4: s does not contain 2, so we add 2 to the end of s, resulting in s=(2).\n\ni=5: s does not contain 3, so we add 3 to the end of s, resulting in s=(2,3).\n\nSample Input 2\n\n5 10\n1 2 3 2 3\n\nSample Output 2\n\n3\n\nSample Input 3\n\n6 1000000000000\n1 1 2 2 3 3\n\nSample Output 3\n\ns may be empty in the end.\n\nSample Input 4\n\n11 97\n3 1 4 1 5 9 2 6 5 3 5\n\nSample Output 4\n\n9 2 6", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5224, "cpu_time_ms": 430, "memory_kb": 62816}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s003483870", "group_id": "codeNet:p02969", "input_text": "(print (ceiling (/ (read) (1+ (* 2 (read))))))", "language": "Lisp", "metadata": {"date": 1569460433, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02969.html", "problem_id": "p02969", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02969/input.txt", "sample_output_relpath": "derived/input_output/data/p02969/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02969/Lisp/s003483870.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s003483870", "user_id": "u358554431"}, "prompt_components": {"gold_output": "48\n", "input_to_evaluate": "(print (ceiling (/ (read) (1+ (* 2 (read))))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIt is known that the area of a regular dodecagon inscribed in a circle of radius a is 3a^2.\n\nGiven an integer r, find the area of a regular dodecagon inscribed in a circle of radius r.\n\nConstraints\n\n1 \\leq r \\leq 100\n\nr is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr\n\nOutput\n\nPrint an integer representing the area of the regular dodecagon.\n\nSample Input 1\n\n4\n\nSample Output 1\n\n48\n\nThe area of the regular dodecagon is 3 \\times 4^2 = 48.\n\nSample Input 2\n\n15\n\nSample Output 2\n\n675\n\nSample Input 3\n\n80\n\nSample Output 3\n\n19200", "sample_input": "4\n"}, "reference_outputs": ["48\n"], "source_document_id": "p02969", "source_text": "Score : 100 points\n\nProblem Statement\n\nIt is known that the area of a regular dodecagon inscribed in a circle of radius a is 3a^2.\n\nGiven an integer r, find the area of a regular dodecagon inscribed in a circle of radius r.\n\nConstraints\n\n1 \\leq r \\leq 100\n\nr is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr\n\nOutput\n\nPrint an integer representing the area of the regular dodecagon.\n\nSample Input 1\n\n4\n\nSample Output 1\n\n48\n\nThe area of the regular dodecagon is 3 \\times 4^2 = 48.\n\nSample Input 2\n\n15\n\nSample Output 2\n\n675\n\nSample Input 3\n\n80\n\nSample Output 3\n\n19200", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 46, "cpu_time_ms": 6, "memory_kb": 2788}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s171350074", "group_id": "codeNet:p02969", "input_text": "(let ((value (read)))\n (format t \"~a\" (* 3 value value)))\n", "language": "Lisp", "metadata": {"date": 1565210098, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02969.html", "problem_id": "p02969", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02969/input.txt", "sample_output_relpath": "derived/input_output/data/p02969/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02969/Lisp/s171350074.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s171350074", "user_id": "u425317134"}, "prompt_components": {"gold_output": "48\n", "input_to_evaluate": "(let ((value (read)))\n (format t \"~a\" (* 3 value value)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIt is known that the area of a regular dodecagon inscribed in a circle of radius a is 3a^2.\n\nGiven an integer r, find the area of a regular dodecagon inscribed in a circle of radius r.\n\nConstraints\n\n1 \\leq r \\leq 100\n\nr is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr\n\nOutput\n\nPrint an integer representing the area of the regular dodecagon.\n\nSample Input 1\n\n4\n\nSample Output 1\n\n48\n\nThe area of the regular dodecagon is 3 \\times 4^2 = 48.\n\nSample Input 2\n\n15\n\nSample Output 2\n\n675\n\nSample Input 3\n\n80\n\nSample Output 3\n\n19200", "sample_input": "4\n"}, "reference_outputs": ["48\n"], "source_document_id": "p02969", "source_text": "Score : 100 points\n\nProblem Statement\n\nIt is known that the area of a regular dodecagon inscribed in a circle of radius a is 3a^2.\n\nGiven an integer r, find the area of a regular dodecagon inscribed in a circle of radius r.\n\nConstraints\n\n1 \\leq r \\leq 100\n\nr is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr\n\nOutput\n\nPrint an integer representing the area of the regular dodecagon.\n\nSample Input 1\n\n4\n\nSample Output 1\n\n48\n\nThe area of the regular dodecagon is 3 \\times 4^2 = 48.\n\nSample Input 2\n\n15\n\nSample Output 2\n\n675\n\nSample Input 3\n\n80\n\nSample Output 3\n\n19200", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 62, "cpu_time_ms": 143, "memory_kb": 11488}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s555604719", "group_id": "codeNet:p02969", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((r (read)))\n (println (* 3 r r))))\n\n#-swank (main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &optional (func #'main))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNC, and returns true if the\nstring output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (and (> (length s) 0)\n (eql (char s (- (length s) 1)) #\\Linefeed))\n s\n (uiop:strcat s uiop:+lf+))))\n (equal (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall func)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n (let ((*standard-output* out))\n (etypecase thing\n (null ; Runs #'MAIN with the string on clipboard\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname ; Runs #'MAIN with the string in a text file\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n", "language": "Lisp", "metadata": {"date": 1563670865, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02969.html", "problem_id": "p02969", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02969/input.txt", "sample_output_relpath": "derived/input_output/data/p02969/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02969/Lisp/s555604719.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s555604719", "user_id": "u352600849"}, "prompt_components": {"gold_output": "48\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((r (read)))\n (println (* 3 r r))))\n\n#-swank (main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &optional (func #'main))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNC, and returns true if the\nstring output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (and (> (length s) 0)\n (eql (char s (- (length s) 1)) #\\Linefeed))\n s\n (uiop:strcat s uiop:+lf+))))\n (equal (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall func)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n (let ((*standard-output* out))\n (etypecase thing\n (null ; Runs #'MAIN with the string on clipboard\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname ; Runs #'MAIN with the string in a text file\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIt is known that the area of a regular dodecagon inscribed in a circle of radius a is 3a^2.\n\nGiven an integer r, find the area of a regular dodecagon inscribed in a circle of radius r.\n\nConstraints\n\n1 \\leq r \\leq 100\n\nr is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr\n\nOutput\n\nPrint an integer representing the area of the regular dodecagon.\n\nSample Input 1\n\n4\n\nSample Output 1\n\n48\n\nThe area of the regular dodecagon is 3 \\times 4^2 = 48.\n\nSample Input 2\n\n15\n\nSample Output 2\n\n675\n\nSample Input 3\n\n80\n\nSample Output 3\n\n19200", "sample_input": "4\n"}, "reference_outputs": ["48\n"], "source_document_id": "p02969", "source_text": "Score : 100 points\n\nProblem Statement\n\nIt is known that the area of a regular dodecagon inscribed in a circle of radius a is 3a^2.\n\nGiven an integer r, find the area of a regular dodecagon inscribed in a circle of radius r.\n\nConstraints\n\n1 \\leq r \\leq 100\n\nr is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr\n\nOutput\n\nPrint an integer representing the area of the regular dodecagon.\n\nSample Input 1\n\n4\n\nSample Output 1\n\n48\n\nThe area of the regular dodecagon is 3 \\times 4^2 = 48.\n\nSample Input 2\n\n15\n\nSample Output 2\n\n675\n\nSample Input 3\n\n80\n\nSample Output 3\n\n19200", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3083, "cpu_time_ms": 174, "memory_kb": 15592}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s522413913", "group_id": "codeNet:p02970", "input_text": "(let ((n (read))\n (d (read)))\n (format t \"~A~%\" (ceiling (/ n (+ d d 1)))))\n", "language": "Lisp", "metadata": {"date": 1598816713, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02970.html", "problem_id": "p02970", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02970/input.txt", "sample_output_relpath": "derived/input_output/data/p02970/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02970/Lisp/s522413913.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s522413913", "user_id": "u608227593"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((n (read))\n (d (read)))\n (format t \"~A~%\" (ceiling (/ n (+ d d 1)))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N apple trees in a row. People say that one of them will bear golden apples.\n\nWe want to deploy some number of inspectors so that each of these trees will be inspected.\n\nEach inspector will be deployed under one of the trees. For convenience, we will assign numbers from 1 through N to the trees. An inspector deployed under the i-th tree (1 \\leq i \\leq N) will inspect the trees with numbers between i-D and i+D (inclusive).\n\nFind the minimum number of inspectors that we need to deploy to achieve the objective.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 20\n\n1 \\leq D \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN D\n\nOutput\n\nPrint the minimum number of inspectors that we need to deploy to achieve the objective.\n\nSample Input 1\n\n6 2\n\nSample Output 1\n\n2\n\nWe can achieve the objective by, for example, placing an inspector under Tree 3 and Tree 4.\n\nSample Input 2\n\n14 3\n\nSample Output 2\n\n2\n\nSample Input 3\n\n20 4\n\nSample Output 3\n\n3", "sample_input": "6 2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02970", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N apple trees in a row. People say that one of them will bear golden apples.\n\nWe want to deploy some number of inspectors so that each of these trees will be inspected.\n\nEach inspector will be deployed under one of the trees. For convenience, we will assign numbers from 1 through N to the trees. An inspector deployed under the i-th tree (1 \\leq i \\leq N) will inspect the trees with numbers between i-D and i+D (inclusive).\n\nFind the minimum number of inspectors that we need to deploy to achieve the objective.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 20\n\n1 \\leq D \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN D\n\nOutput\n\nPrint the minimum number of inspectors that we need to deploy to achieve the objective.\n\nSample Input 1\n\n6 2\n\nSample Output 1\n\n2\n\nWe can achieve the objective by, for example, placing an inspector under Tree 3 and Tree 4.\n\nSample Input 2\n\n14 3\n\nSample Output 2\n\n2\n\nSample Input 3\n\n20 4\n\nSample Output 3\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 82, "cpu_time_ms": 18, "memory_kb": 24140}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s296488578", "group_id": "codeNet:p02971", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Disjoint sparse table\n;;;\n\n;;; Reference:\n;;; https://discuss.codechef.com/questions/117696/tutorial-disjoint-sparse-table\n;;; http://noshi91.hatenablog.com/entry/2018/05/08/183946 (Japanese)\n;;; http://drken1215.hatenablog.com/entry/2018/09/08/162600 (Japanese)\n\n(declaim (inline make-disjoint-sparse-table))\n(defun make-disjoint-sparse-table (vector binop)\n (let* ((n (length vector))\n (height (integer-length (- n 1)))\n (table (make-array (list height n) :element-type '(unsigned-byte 32))))\n (dotimes (j n)\n (setf (aref table 0 j) (aref vector j)))\n (do ((i 1 (+ i 1)))\n ((>= i height))\n (let* ((width/2 (ash i 1))\n (width (* width/2 2)))\n (do ((j 0 (+ j width)))\n ((>= j n))\n (let ((mid (min (+ j width/2) n)))\n ;; fill the first half\n (setf (aref table i (- mid 1))\n (aref vector (- mid 1)))\n (do ((k (- mid 2) (- k 1)))\n ((< k j))\n (setf (aref table i k)\n (funcall binop (aref vector k) (aref table i (+ k 1)))))\n (when (>= mid n)\n (return))\n ;; fill the second half\n (setf (aref table i mid)\n (aref vector mid))\n (let ((end (min n (+ mid width/2))))\n (do ((k (+ mid 1) (+ k 1)))\n ((>= k end))\n (setf (aref table i k)\n (funcall binop (aref table i (- k 1)) (aref vector k)))))))))\n table))\n\n(declaim (inline dst-query))\n(defun dst-query (table binop left right)\n \"Queries the interval [LEFT, RIGHT). Note that a null interval [x, x) is not\nallowed as disjoint sparse table deals with a semigroup.\"\n (declare ((integer 0 #.most-positive-fixnum) left right)\n ((simple-array (unsigned-byte 32) (* *)) table))\n (assert (< left right))\n (setq right (- right 1)) ;; change to closed interval\n (if (= left right)\n (aref table 0 left)\n (let ((h (- (integer-length (logxor left right)) 1)))\n (funcall binop\n (aref table h left)\n (aref table h right)))))\n\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (let ((table (make-disjoint-sparse-table as #'max)))\n (with-buffered-stdout\n (dotimes (i n)\n (println (max (if (zerop i)\n 0\n (dst-query table #'max 0 i))\n (if (= (+ i 1) n)\n 0\n (dst-query table #'max (+ i 1) n)))))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1564890438, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02971.html", "problem_id": "p02971", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02971/input.txt", "sample_output_relpath": "derived/input_output/data/p02971/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02971/Lisp/s296488578.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s296488578", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n3\n4\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Disjoint sparse table\n;;;\n\n;;; Reference:\n;;; https://discuss.codechef.com/questions/117696/tutorial-disjoint-sparse-table\n;;; http://noshi91.hatenablog.com/entry/2018/05/08/183946 (Japanese)\n;;; http://drken1215.hatenablog.com/entry/2018/09/08/162600 (Japanese)\n\n(declaim (inline make-disjoint-sparse-table))\n(defun make-disjoint-sparse-table (vector binop)\n (let* ((n (length vector))\n (height (integer-length (- n 1)))\n (table (make-array (list height n) :element-type '(unsigned-byte 32))))\n (dotimes (j n)\n (setf (aref table 0 j) (aref vector j)))\n (do ((i 1 (+ i 1)))\n ((>= i height))\n (let* ((width/2 (ash i 1))\n (width (* width/2 2)))\n (do ((j 0 (+ j width)))\n ((>= j n))\n (let ((mid (min (+ j width/2) n)))\n ;; fill the first half\n (setf (aref table i (- mid 1))\n (aref vector (- mid 1)))\n (do ((k (- mid 2) (- k 1)))\n ((< k j))\n (setf (aref table i k)\n (funcall binop (aref vector k) (aref table i (+ k 1)))))\n (when (>= mid n)\n (return))\n ;; fill the second half\n (setf (aref table i mid)\n (aref vector mid))\n (let ((end (min n (+ mid width/2))))\n (do ((k (+ mid 1) (+ k 1)))\n ((>= k end))\n (setf (aref table i k)\n (funcall binop (aref table i (- k 1)) (aref vector k)))))))))\n table))\n\n(declaim (inline dst-query))\n(defun dst-query (table binop left right)\n \"Queries the interval [LEFT, RIGHT). Note that a null interval [x, x) is not\nallowed as disjoint sparse table deals with a semigroup.\"\n (declare ((integer 0 #.most-positive-fixnum) left right)\n ((simple-array (unsigned-byte 32) (* *)) table))\n (assert (< left right))\n (setq right (- right 1)) ;; change to closed interval\n (if (= left right)\n (aref table 0 left)\n (let ((h (- (integer-length (logxor left right)) 1)))\n (funcall binop\n (aref table h left)\n (aref table h right)))))\n\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (let ((table (make-disjoint-sparse-table as #'max)))\n (with-buffered-stdout\n (dotimes (i n)\n (println (max (if (zerop i)\n 0\n (dst-query table #'max 0 i))\n (if (= (+ i 1) n)\n 0\n (dst-query table #'max (+ i 1) n)))))))))\n\n#-swank (main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given a sequence of length N: A_1, A_2, ..., A_N.\nFor each integer i between 1 and N (inclusive), answer the following question:\n\nFind the maximum value among the N-1 elements other than A_i in the sequence.\n\nConstraints\n\n2 \\leq N \\leq 200000\n\n1 \\leq A_i \\leq 200000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1\n:\nA_N\n\nOutput\n\nPrint N lines. The i-th line (1 \\leq i \\leq N) should contain the maximum value among the N-1 elements other than A_i in the sequence.\n\nSample Input 1\n\n3\n1\n4\n3\n\nSample Output 1\n\n4\n3\n4\n\nThe maximum value among the two elements other than A_1, that is, A_2 = 4 and A_3 = 3, is 4.\n\nThe maximum value among the two elements other than A_2, that is, A_1 = 1 and A_3 = 3, is 3.\n\nThe maximum value among the two elements other than A_3, that is, A_1 = 1 and A_2 = 4, is 4.\n\nSample Input 2\n\n2\n5\n5\n\nSample Output 2\n\n5\n5", "sample_input": "3\n1\n4\n3\n"}, "reference_outputs": ["4\n3\n4\n"], "source_document_id": "p02971", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given a sequence of length N: A_1, A_2, ..., A_N.\nFor each integer i between 1 and N (inclusive), answer the following question:\n\nFind the maximum value among the N-1 elements other than A_i in the sequence.\n\nConstraints\n\n2 \\leq N \\leq 200000\n\n1 \\leq A_i \\leq 200000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1\n:\nA_N\n\nOutput\n\nPrint N lines. The i-th line (1 \\leq i \\leq N) should contain the maximum value among the N-1 elements other than A_i in the sequence.\n\nSample Input 1\n\n3\n1\n4\n3\n\nSample Output 1\n\n4\n3\n4\n\nThe maximum value among the two elements other than A_1, that is, A_2 = 4 and A_3 = 3, is 4.\n\nThe maximum value among the two elements other than A_2, that is, A_1 = 1 and A_3 = 3, is 3.\n\nThe maximum value among the two elements other than A_3, that is, A_1 = 1 and A_2 = 4, is 4.\n\nSample Input 2\n\n2\n5\n5\n\nSample Output 2\n\n5\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5470, "cpu_time_ms": 287, "memory_kb": 48868}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s582647932", "group_id": "codeNet:p02971", "input_text": "(defun c ()\n (let* ((n (read))\n (m (list (list -1 -1))))\n (dotimes (i n)\n (let ((x (read)))\n (cond ((> x (caar m))\n (push (list x i) m))\n ((> x (caadr m))\n (setf (cdr m) (list (list x i)))))))\n (dotimes (i n)\n (format t \"~a~%\"\n (if (= i (cadar m))\n (caadr m)\n (caar m))))))\n(c)", "language": "Lisp", "metadata": {"date": 1564324010, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02971.html", "problem_id": "p02971", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02971/input.txt", "sample_output_relpath": "derived/input_output/data/p02971/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02971/Lisp/s582647932.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s582647932", "user_id": "u100932207"}, "prompt_components": {"gold_output": "4\n3\n4\n", "input_to_evaluate": "(defun c ()\n (let* ((n (read))\n (m (list (list -1 -1))))\n (dotimes (i n)\n (let ((x (read)))\n (cond ((> x (caar m))\n (push (list x i) m))\n ((> x (caadr m))\n (setf (cdr m) (list (list x i)))))))\n (dotimes (i n)\n (format t \"~a~%\"\n (if (= i (cadar m))\n (caadr m)\n (caar m))))))\n(c)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given a sequence of length N: A_1, A_2, ..., A_N.\nFor each integer i between 1 and N (inclusive), answer the following question:\n\nFind the maximum value among the N-1 elements other than A_i in the sequence.\n\nConstraints\n\n2 \\leq N \\leq 200000\n\n1 \\leq A_i \\leq 200000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1\n:\nA_N\n\nOutput\n\nPrint N lines. The i-th line (1 \\leq i \\leq N) should contain the maximum value among the N-1 elements other than A_i in the sequence.\n\nSample Input 1\n\n3\n1\n4\n3\n\nSample Output 1\n\n4\n3\n4\n\nThe maximum value among the two elements other than A_1, that is, A_2 = 4 and A_3 = 3, is 4.\n\nThe maximum value among the two elements other than A_2, that is, A_1 = 1 and A_3 = 3, is 3.\n\nThe maximum value among the two elements other than A_3, that is, A_1 = 1 and A_2 = 4, is 4.\n\nSample Input 2\n\n2\n5\n5\n\nSample Output 2\n\n5\n5", "sample_input": "3\n1\n4\n3\n"}, "reference_outputs": ["4\n3\n4\n"], "source_document_id": "p02971", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given a sequence of length N: A_1, A_2, ..., A_N.\nFor each integer i between 1 and N (inclusive), answer the following question:\n\nFind the maximum value among the N-1 elements other than A_i in the sequence.\n\nConstraints\n\n2 \\leq N \\leq 200000\n\n1 \\leq A_i \\leq 200000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1\n:\nA_N\n\nOutput\n\nPrint N lines. The i-th line (1 \\leq i \\leq N) should contain the maximum value among the N-1 elements other than A_i in the sequence.\n\nSample Input 1\n\n3\n1\n4\n3\n\nSample Output 1\n\n4\n3\n4\n\nThe maximum value among the two elements other than A_1, that is, A_2 = 4 and A_3 = 3, is 4.\n\nThe maximum value among the two elements other than A_2, that is, A_1 = 1 and A_3 = 3, is 3.\n\nThe maximum value among the two elements other than A_3, that is, A_1 = 1 and A_2 = 4, is 4.\n\nSample Input 2\n\n2\n5\n5\n\nSample Output 2\n\n5\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 397, "cpu_time_ms": 906, "memory_kb": 59112}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s643642069", "group_id": "codeNet:p02972", "input_text": "(let ((n (read))\n (a (make-array 1 :element-type 'integer\n :initial-element 0 \n :adjustable t\n :fill-pointer 1))\n (ans (make-array 0 :element-type 'integer\n :adjustable t\n :fill-pointer 0))\n (ans-c 0))\n (dotimes (i n)\n (vector-push-extend (read) a))\n (loop for i from n downto 1\n do (loop for j from 2 upto n\n while (<= (* i j) n)\n do (setf (aref a i) (logxor (aref a i) (aref a (* i j)))))\n (if (= (aref a i) 1) (progn (incf ans-c)\n (vector-push-extend i ans))))\n (format t \"~A~%\" ans-c)\n (if (not (= 0 ans-c)) (format t \"~{~A~%~}\" (coerce ans 'list))))", "language": "Lisp", "metadata": {"date": 1566267877, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02972.html", "problem_id": "p02972", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02972/input.txt", "sample_output_relpath": "derived/input_output/data/p02972/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02972/Lisp/s643642069.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s643642069", "user_id": "u994767958"}, "prompt_components": {"gold_output": "1\n1\n", "input_to_evaluate": "(let ((n (read))\n (a (make-array 1 :element-type 'integer\n :initial-element 0 \n :adjustable t\n :fill-pointer 1))\n (ans (make-array 0 :element-type 'integer\n :adjustable t\n :fill-pointer 0))\n (ans-c 0))\n (dotimes (i n)\n (vector-push-extend (read) a))\n (loop for i from n downto 1\n do (loop for j from 2 upto n\n while (<= (* i j) n)\n do (setf (aref a i) (logxor (aref a i) (aref a (* i j)))))\n (if (= (aref a i) 1) (progn (incf ans-c)\n (vector-push-extend i ans))))\n (format t \"~A~%\" ans-c)\n (if (not (= 0 ans-c)) (format t \"~{~A~%~}\" (coerce ans 'list))))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are N empty boxes arranged in a row from left to right.\nThe integer i is written on the i-th box from the left (1 \\leq i \\leq N).\n\nFor each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it.\n\nWe say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied:\n\nFor every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2.\n\nDoes there exist a good set of choices? If the answer is yes, find one good set of choices.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 2 \\times 10^5\n\na_i is 0 or 1.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nIf a good set of choices does not exist, print -1.\n\nIf a good set of choices exists, print one such set of choices in the following format:\n\nM\nb_1 b_2 ... b_M\n\nwhere M denotes the number of boxes that will contain a ball, and b_1,\\ b_2,\\ ...,\\ b_M are the integers written on these boxes, in any order.\n\nSample Input 1\n\n3\n1 0 0\n\nSample Output 1\n\n1\n1\n\nConsider putting a ball only in the box with 1 written on it.\n\nThere are three boxes with multiples of 1 written on them: the boxes with 1, 2, and 3. The total number of balls contained in these boxes is 1.\n\nThere is only one box with a multiple of 2 written on it: the box with 2. The total number of balls contained in these boxes is 0.\n\nThere is only one box with a multiple of 3 written on it: the box with 3. The total number of balls contained in these boxes is 0.\n\nThus, the condition is satisfied, so this set of choices is good.\n\nSample Input 2\n\n5\n0 0 0 0 0\n\nSample Output 2\n\n0\n\nPutting nothing in the boxes can be a good set of choices.", "sample_input": "3\n1 0 0\n"}, "reference_outputs": ["1\n1\n"], "source_document_id": "p02972", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are N empty boxes arranged in a row from left to right.\nThe integer i is written on the i-th box from the left (1 \\leq i \\leq N).\n\nFor each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it.\n\nWe say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied:\n\nFor every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2.\n\nDoes there exist a good set of choices? If the answer is yes, find one good set of choices.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 2 \\times 10^5\n\na_i is 0 or 1.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nIf a good set of choices does not exist, print -1.\n\nIf a good set of choices exists, print one such set of choices in the following format:\n\nM\nb_1 b_2 ... b_M\n\nwhere M denotes the number of boxes that will contain a ball, and b_1,\\ b_2,\\ ...,\\ b_M are the integers written on these boxes, in any order.\n\nSample Input 1\n\n3\n1 0 0\n\nSample Output 1\n\n1\n1\n\nConsider putting a ball only in the box with 1 written on it.\n\nThere are three boxes with multiples of 1 written on them: the boxes with 1, 2, and 3. The total number of balls contained in these boxes is 1.\n\nThere is only one box with a multiple of 2 written on it: the box with 2. The total number of balls contained in these boxes is 0.\n\nThere is only one box with a multiple of 3 written on it: the box with 3. The total number of balls contained in these boxes is 0.\n\nThus, the condition is satisfied, so this set of choices is good.\n\nSample Input 2\n\n5\n0 0 0 0 0\n\nSample Output 2\n\n0\n\nPutting nothing in the boxes can be a good set of choices.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 808, "cpu_time_ms": 619, "memory_kb": 60640}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s643210302", "group_id": "codeNet:p02976", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read-fixnum))\n (m (read-fixnum))\n (graph (make-array n :element-type 'list :initial-element nil))\n ;; 1: tmp. marked, 2: fixed\n (marked (make-array n :element-type 'uint8 :initial-element 0))\n (out (make-string-output-stream :element-type 'base-char)))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (labels ((%print (a b)\n (format out \"~D ~D~%\" (+ a 1) (+ b 1)))\n (dfs (v)\n #>v\n (setf (aref marked v) 1)\n (let ((parity 0))\n (dolist (child (aref graph v))\n (cond ((= 1 (aref marked child)))\n ((= 2 (aref marked child))\n (%print v child)\n (xorf parity 1))\n ((zerop (dfs child))\n (%print v child)\n (xorf parity 1))\n (t (%print child v))))\n (dbg v parity)\n (setf (aref marked v) 2)\n parity)))\n (let ((parity (dfs 0)))\n (if (zerop parity)\n (write-string (get-output-stream-string out))\n (println -1))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 4\n1 2\n2 3\n3 4\n4 1\n\"\n \"1 2\n1 4\n3 2\n3 4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 5\n1 2\n2 3\n3 4\n2 5\n4 5\n\"\n \"-1\n\")))\n", "language": "Lisp", "metadata": {"date": 1593518240, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02976.html", "problem_id": "p02976", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02976/input.txt", "sample_output_relpath": "derived/input_output/data/p02976/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02976/Lisp/s643210302.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s643210302", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1 2\n1 4\n3 2\n3 4\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read-fixnum))\n (m (read-fixnum))\n (graph (make-array n :element-type 'list :initial-element nil))\n ;; 1: tmp. marked, 2: fixed\n (marked (make-array n :element-type 'uint8 :initial-element 0))\n (out (make-string-output-stream :element-type 'base-char)))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (labels ((%print (a b)\n (format out \"~D ~D~%\" (+ a 1) (+ b 1)))\n (dfs (v)\n #>v\n (setf (aref marked v) 1)\n (let ((parity 0))\n (dolist (child (aref graph v))\n (cond ((= 1 (aref marked child)))\n ((= 2 (aref marked child))\n (%print v child)\n (xorf parity 1))\n ((zerop (dfs child))\n (%print v child)\n (xorf parity 1))\n (t (%print child v))))\n (dbg v parity)\n (setf (aref marked v) 2)\n parity)))\n (let ((parity (dfs 0)))\n (if (zerop parity)\n (write-string (get-output-stream-string out))\n (println -1))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 4\n1 2\n2 3\n3 4\n4 1\n\"\n \"1 2\n1 4\n3 2\n3 4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 5\n1 2\n2 3\n3 4\n2 5\n4 5\n\"\n \"-1\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nYou are given a simple connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the i-th edge connects Vertex A_i and Vertex B_i.\nTakahashi will assign one of the two possible directions to each of the edges in the graph to make a directed graph.\nDetermine if it is possible to make a directed graph with an even number of edges going out from every vertex. If the answer is yes, construct one such graph.\n\nNotes\n\nAn undirected graph is said to be simple when it contains no self-loops or multiple edges.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\nN-1 \\leq M \\leq 10^5\n\n1 \\leq A_i,B_i \\leq N (1\\leq i\\leq M)\n\nThe given graph is simple and connected.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\n:\nA_M B_M\n\nOutput\n\nIf it is impossible to assign directions\b to satisfy the requirement, print -1.\nOtherwise, print an assignment of directions that satisfies the requirement, in the following format:\n\nC_1 D_1\n:\nC_M D_M\n\nHere each pair (C_i, D_i) means that there is an edge directed from Vertex C_i to Vertex D_i. The edges may be printed in any order.\n\nSample Input 1\n\n4 4\n1 2\n2 3\n3 4\n4 1\n\nSample Output 1\n\n1 2\n1 4\n3 2\n3 4\n\nAfter this assignment of directions, Vertex 1 and 3 will each have two outgoing edges, and Vertex 2 and 4 will each have zero outgoing edges.\n\nSample Input 2\n\n5 5\n1 2\n2 3\n3 4\n2 5\n4 5\n\nSample Output 2\n\n-1", "sample_input": "4 4\n1 2\n2 3\n3 4\n4 1\n"}, "reference_outputs": ["1 2\n1 4\n3 2\n3 4\n"], "source_document_id": "p02976", "source_text": "Score : 700 points\n\nProblem Statement\n\nYou are given a simple connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the i-th edge connects Vertex A_i and Vertex B_i.\nTakahashi will assign one of the two possible directions to each of the edges in the graph to make a directed graph.\nDetermine if it is possible to make a directed graph with an even number of edges going out from every vertex. If the answer is yes, construct one such graph.\n\nNotes\n\nAn undirected graph is said to be simple when it contains no self-loops or multiple edges.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\nN-1 \\leq M \\leq 10^5\n\n1 \\leq A_i,B_i \\leq N (1\\leq i\\leq M)\n\nThe given graph is simple and connected.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\n:\nA_M B_M\n\nOutput\n\nIf it is impossible to assign directions\b to satisfy the requirement, print -1.\nOtherwise, print an assignment of directions that satisfies the requirement, in the following format:\n\nC_1 D_1\n:\nC_M D_M\n\nHere each pair (C_i, D_i) means that there is an edge directed from Vertex C_i to Vertex D_i. The edges may be printed in any order.\n\nSample Input 1\n\n4 4\n1 2\n2 3\n3 4\n4 1\n\nSample Output 1\n\n1 2\n1 4\n3 2\n3 4\n\nAfter this assignment of directions, Vertex 1 and 3 will each have two outgoing edges, and Vertex 2 and 4 will each have zero outgoing edges.\n\nSample Input 2\n\n5 5\n1 2\n2 3\n3 4\n2 5\n4 5\n\nSample Output 2\n\n-1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6682, "cpu_time_ms": 99, "memory_kb": 43068}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s530657363", "group_id": "codeNet:p02978", "input_text": "(defun min-index(lst)\n (labels ((rec (lst i n minvalue)\n\t\t\t\t(if (null (cdr lst))\n\t\t\t\t n\n\t\t\t\t (if (< (car lst) minvalue)\n\t\t\t\t\t(rec (cdr lst) (1+ i) i (car lst))\n\t\t\t\t\t(rec (cdr lst) (1+ i) n minvalue)))))\n\t(rec (cdr lst) 1 1 (cadr lst))))\n(defun skip-n(lst n)\n (let ((a (nth n lst)))\n\t(labels ((rec (lst i acc)\n\t\t\t\t (if (null lst)\n\t\t\t\t\t(nreverse acc)\n\t\t\t\t\t(if (= i n)\n\t\t\t\t\t (rec (cdr lst) (1+ i) acc)\n\t\t\t\t\t (if (or (= (1+ i) n)\n\t\t\t\t\t\t\t (= (1- i) n))\n\t\t\t\t\t\t(rec (cdr lst) (1+ i) (cons (+ a (car lst)) acc))\n\t\t\t\t\t\t(rec (cdr lst) (1+ i) (cons (car lst) acc)))))))\n\t (rec lst 0 nil))))\n(defun f(lst)\n (let ((llsstt (skip-n lst (min-index lst))))\n\t(if (null (cddr llsstt))\n\t (+ (car llsstt) (cadr llsstt))\n\t (f llsstt))))\n\n(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n\n(let* ((n (parse-integer (read-line nil nil)))\n\t (lst (mapcar #'parse-integer (splitat #\\space (read-line nil nil)))))\n (format t \"~A\" (f lst)))\n", "language": "Lisp", "metadata": {"date": 1563157702, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02978.html", "problem_id": "p02978", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02978/input.txt", "sample_output_relpath": "derived/input_output/data/p02978/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02978/Lisp/s530657363.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s530657363", "user_id": "u254205055"}, "prompt_components": {"gold_output": "16\n", "input_to_evaluate": "(defun min-index(lst)\n (labels ((rec (lst i n minvalue)\n\t\t\t\t(if (null (cdr lst))\n\t\t\t\t n\n\t\t\t\t (if (< (car lst) minvalue)\n\t\t\t\t\t(rec (cdr lst) (1+ i) i (car lst))\n\t\t\t\t\t(rec (cdr lst) (1+ i) n minvalue)))))\n\t(rec (cdr lst) 1 1 (cadr lst))))\n(defun skip-n(lst n)\n (let ((a (nth n lst)))\n\t(labels ((rec (lst i acc)\n\t\t\t\t (if (null lst)\n\t\t\t\t\t(nreverse acc)\n\t\t\t\t\t(if (= i n)\n\t\t\t\t\t (rec (cdr lst) (1+ i) acc)\n\t\t\t\t\t (if (or (= (1+ i) n)\n\t\t\t\t\t\t\t (= (1- i) n))\n\t\t\t\t\t\t(rec (cdr lst) (1+ i) (cons (+ a (car lst)) acc))\n\t\t\t\t\t\t(rec (cdr lst) (1+ i) (cons (car lst) acc)))))))\n\t (rec lst 0 nil))))\n(defun f(lst)\n (let ((llsstt (skip-n lst (min-index lst))))\n\t(if (null (cddr llsstt))\n\t (+ (car llsstt) (cadr llsstt))\n\t (f llsstt))))\n\n(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n\n(let* ((n (parse-integer (read-line nil nil)))\n\t (lst (mapcar #'parse-integer (splitat #\\space (read-line nil nil)))))\n (format t \"~A\" (f lst)))\n", "problem_context": "Score : 1000 points\n\nProblem Statement\n\nThere is a stack of N cards, each of which has a non-negative integer written on it. The integer written on the i-th card from the top is A_i.\n\nSnuke will repeat the following operation until two cards remain:\n\nChoose three consecutive cards from the stack.\n\nEat the middle card of the three.\n\nFor each of the other two cards, replace the integer written on it by the sum of that integer and the integer written on the card eaten.\n\nReturn the two cards to the original position in the stack, without swapping them.\n\nFind the minimum possible sum of the integers written on the last two cards remaining.\n\nConstraints\n\n2 \\leq N \\leq 18\n\n0 \\leq A_i \\leq 10^9 (1\\leq i\\leq N)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum possible sum of the integers written on the last two cards remaining.\n\nSample Input 1\n\n4\n3 1 4 2\n\nSample Output 1\n\n16\n\nWe can minimize the sum of the integers written on the last two cards remaining by doing as follows:\n\nInitially, the integers written on the cards are 3, 1, 4, and 2 from top to bottom.\n\nChoose the first, second, and third card from the top. Eat the second card with 1 written on it, add 1 to each of the other two cards, and return them to the original position in the stack. The integers written on the cards are now 4, 5, and 2 from top to bottom.\n\nChoose the first, second, and third card from the top. Eat the second card with 5 written on it, add 5 to each of the other two cards, and return them to the original position in the stack. The integers written on the cards are now 9 and 7 from top to bottom.\n\nThe sum of the integers written on the last two cards remaining is 16.\n\nSample Input 2\n\n6\n5 2 4 1 6 9\n\nSample Output 2\n\n51\n\nSample Input 3\n\n10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 3\n\n115", "sample_input": "4\n3 1 4 2\n"}, "reference_outputs": ["16\n"], "source_document_id": "p02978", "source_text": "Score : 1000 points\n\nProblem Statement\n\nThere is a stack of N cards, each of which has a non-negative integer written on it. The integer written on the i-th card from the top is A_i.\n\nSnuke will repeat the following operation until two cards remain:\n\nChoose three consecutive cards from the stack.\n\nEat the middle card of the three.\n\nFor each of the other two cards, replace the integer written on it by the sum of that integer and the integer written on the card eaten.\n\nReturn the two cards to the original position in the stack, without swapping them.\n\nFind the minimum possible sum of the integers written on the last two cards remaining.\n\nConstraints\n\n2 \\leq N \\leq 18\n\n0 \\leq A_i \\leq 10^9 (1\\leq i\\leq N)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum possible sum of the integers written on the last two cards remaining.\n\nSample Input 1\n\n4\n3 1 4 2\n\nSample Output 1\n\n16\n\nWe can minimize the sum of the integers written on the last two cards remaining by doing as follows:\n\nInitially, the integers written on the cards are 3, 1, 4, and 2 from top to bottom.\n\nChoose the first, second, and third card from the top. Eat the second card with 1 written on it, add 1 to each of the other two cards, and return them to the original position in the stack. The integers written on the cards are now 4, 5, and 2 from top to bottom.\n\nChoose the first, second, and third card from the top. Eat the second card with 5 written on it, add 5 to each of the other two cards, and return them to the original position in the stack. The integers written on the cards are now 9 and 7 from top to bottom.\n\nThe sum of the integers written on the last two cards remaining is 16.\n\nSample Input 2\n\n6\n5 2 4 1 6 9\n\nSample Output 2\n\n51\n\nSample Input 3\n\n10\n3 1 4 1 5 9 2 6 5 3\n\nSample Output 3\n\n115", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1125, "cpu_time_ms": 130, "memory_kb": 15584}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s883119643", "group_id": "codeNet:p02981", "input_text": "(princ(min(*(read)(read))(read)))", "language": "Lisp", "metadata": {"date": 1562603584, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02981.html", "problem_id": "p02981", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02981/input.txt", "sample_output_relpath": "derived/input_output/data/p02981/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02981/Lisp/s883119643.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s883119643", "user_id": "u994767958"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(princ(min(*(read)(read))(read)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nN of us are going on a trip, by train or taxi.\n\nThe train will cost each of us A yen (the currency of Japan).\n\nThe taxi will cost us a total of B yen.\n\nHow much is our minimum total travel expense?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 20\n\n1 \\leq A \\leq 50\n\n1 \\leq B \\leq 50\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint an integer representing the minimum total travel expense.\n\nSample Input 1\n\n4 2 9\n\nSample Output 1\n\n8\n\nThe train will cost us 4 \\times 2 = 8 yen, and the taxi will cost us 9 yen, so the minimum total travel expense is 8 yen.\n\nSample Input 2\n\n4 2 7\n\nSample Output 2\n\n7\n\nSample Input 3\n\n4 2 8\n\nSample Output 3\n\n8", "sample_input": "4 2 9\n"}, "reference_outputs": ["8\n"], "source_document_id": "p02981", "source_text": "Score : 100 points\n\nProblem Statement\n\nN of us are going on a trip, by train or taxi.\n\nThe train will cost each of us A yen (the currency of Japan).\n\nThe taxi will cost us a total of B yen.\n\nHow much is our minimum total travel expense?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 20\n\n1 \\leq A \\leq 50\n\n1 \\leq B \\leq 50\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint an integer representing the minimum total travel expense.\n\nSample Input 1\n\n4 2 9\n\nSample Output 1\n\n8\n\nThe train will cost us 4 \\times 2 = 8 yen, and the taxi will cost us 9 yen, so the minimum total travel expense is 8 yen.\n\nSample Input 2\n\n4 2 7\n\nSample Output 2\n\n7\n\nSample Input 3\n\n4 2 8\n\nSample Output 3\n\n8", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 33, "cpu_time_ms": 20, "memory_kb": 3812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s878183281", "group_id": "codeNet:p02982", "input_text": "(let* ((n (read))\n (d (read))\n (lst (loop :repeat n :collect(loop :repeat d :collect (read))))\n (ans '()))\n (mapcar (lambda (pos1)\n (mapcar (lambda (pos2)\n (push (reduce #'+ (mapcar (lambda (p q) (expt (- p q) 2)) pos1 pos2)) ans)) lst)) lst)\n (princ (floor (length (remove-if-not (lambda (x) (= (expt (isqrt x) 2) x)) ans)) 2)))", "language": "Lisp", "metadata": {"date": 1562549124, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02982.html", "problem_id": "p02982", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02982/input.txt", "sample_output_relpath": "derived/input_output/data/p02982/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02982/Lisp/s878183281.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s878183281", "user_id": "u610490393"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let* ((n (read))\n (d (read))\n (lst (loop :repeat n :collect(loop :repeat d :collect (read))))\n (ans '()))\n (mapcar (lambda (pos1)\n (mapcar (lambda (pos2)\n (push (reduce #'+ (mapcar (lambda (p q) (expt (- p q) 2)) pos1 pos2)) ans)) lst)) lst)\n (princ (floor (length (remove-if-not (lambda (x) (= (expt (isqrt x) 2) x)) ans)) 2)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N points in a D-dimensional space.\n\nThe coordinates of the i-th point are (X_{i1}, X_{i2}, ..., X_{iD}).\n\nThe distance between two points with coordinates (y_1, y_2, ..., y_D) and (z_1, z_2, ..., z_D) is \\sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... + (y_D - z_D)^2}.\n\nHow many pairs (i, j) (i < j) are there such that the distance between the i-th point and the j-th point is an integer?\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10\n\n1 \\leq D \\leq 10\n\n-20 \\leq X_{ij} \\leq 20\n\nNo two given points have the same coordinates. That is, if i \\neq j, there exists k such that X_{ik} \\neq X_{jk}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN D\nX_{11} X_{12} ... X_{1D}\nX_{21} X_{22} ... X_{2D}\n\\vdots\nX_{N1} X_{N2} ... X_{ND}\n\nOutput\n\nPrint the number of pairs (i, j) (i < j) such that the distance between the i-th point and the j-th point is an integer.\n\nSample Input 1\n\n3 2\n1 2\n5 5\n-2 8\n\nSample Output 1\n\n1\n\nThe number of pairs with an integer distance is one, as follows:\n\nThe distance between the first point and the second point is \\sqrt{|1-5|^2 + |2-5|^2} = 5, which is an integer.\n\nThe distance between the second point and the third point is \\sqrt{|5-(-2)|^2 + |5-8|^2} = \\sqrt{58}, which is not an integer.\n\nThe distance between the third point and the first point is \\sqrt{|-2-1|^2+|8-2|^2} = 3\\sqrt{5}, which is not an integer.\n\nSample Input 2\n\n3 4\n-3 7 8 2\n-12 1 10 2\n-2 8 9 3\n\nSample Output 2\n\n2\n\nSample Input 3\n\n5 1\n1\n2\n3\n4\n5\n\nSample Output 3\n\n10", "sample_input": "3 2\n1 2\n5 5\n-2 8\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02982", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N points in a D-dimensional space.\n\nThe coordinates of the i-th point are (X_{i1}, X_{i2}, ..., X_{iD}).\n\nThe distance between two points with coordinates (y_1, y_2, ..., y_D) and (z_1, z_2, ..., z_D) is \\sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... + (y_D - z_D)^2}.\n\nHow many pairs (i, j) (i < j) are there such that the distance between the i-th point and the j-th point is an integer?\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10\n\n1 \\leq D \\leq 10\n\n-20 \\leq X_{ij} \\leq 20\n\nNo two given points have the same coordinates. That is, if i \\neq j, there exists k such that X_{ik} \\neq X_{jk}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN D\nX_{11} X_{12} ... X_{1D}\nX_{21} X_{22} ... X_{2D}\n\\vdots\nX_{N1} X_{N2} ... X_{ND}\n\nOutput\n\nPrint the number of pairs (i, j) (i < j) such that the distance between the i-th point and the j-th point is an integer.\n\nSample Input 1\n\n3 2\n1 2\n5 5\n-2 8\n\nSample Output 1\n\n1\n\nThe number of pairs with an integer distance is one, as follows:\n\nThe distance between the first point and the second point is \\sqrt{|1-5|^2 + |2-5|^2} = 5, which is an integer.\n\nThe distance between the second point and the third point is \\sqrt{|5-(-2)|^2 + |5-8|^2} = \\sqrt{58}, which is not an integer.\n\nThe distance between the third point and the first point is \\sqrt{|-2-1|^2+|8-2|^2} = 3\\sqrt{5}, which is not an integer.\n\nSample Input 2\n\n3 4\n-3 7 8 2\n-12 1 10 2\n-2 8 9 3\n\nSample Output 2\n\n2\n\nSample Input 3\n\n5 1\n1\n2\n3\n4\n5\n\nSample Output 3\n\n10", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 381, "cpu_time_ms": 129, "memory_kb": 16996}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s484270807", "group_id": "codeNet:p02988", "input_text": "(let* ((n (read))\n (p (make-array n))\n (ans 0))\n\n (loop for i below n do\n (setf (aref p i) (read))\n )\n\n (loop for i from 1 below (- n 1) do\n (let ((a (make-array 3)))\n (setf (aref a 0) (aref p (- i 1)))\n (setf (aref a 1) (aref p i))\n (setf (aref a 2) (aref p (+ i 1)))\n (setf a (sort a #'<))\n (if (= (aref p i) (aref a 1))\n (incf ans)\n )\n )\n )\n (princ ans)\n)", "language": "Lisp", "metadata": {"date": 1596113435, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02988.html", "problem_id": "p02988", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02988/input.txt", "sample_output_relpath": "derived/input_output/data/p02988/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02988/Lisp/s484270807.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s484270807", "user_id": "u136500538"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (read))\n (p (make-array n))\n (ans 0))\n\n (loop for i below n do\n (setf (aref p i) (read))\n )\n\n (loop for i from 1 below (- n 1) do\n (let ((a (make-array 3)))\n (setf (aref a 0) (aref p (- i 1)))\n (setf (aref a 1) (aref p i))\n (setf (aref a 2) (aref p (+ i 1)))\n (setf a (sort a #'<))\n (if (= (aref p i) (aref a 1))\n (incf ans)\n )\n )\n )\n (princ ans)\n)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have a permutation p = {p_1,\\ p_2,\\ ...,\\ p_n} of {1,\\ 2,\\ ...,\\ n}.\n\nPrint the number of elements p_i (1 < i < n) that satisfy the following condition:\n\np_i is the second smallest number among the three numbers p_{i - 1}, p_i, and p_{i + 1}.\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq n \\leq 20\n\np is a permutation of {1,\\ 2,\\ ...,\\ n}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\np_1 p_2 ... p_n\n\nOutput\n\nPrint the number of elements p_i (1 < i < n) that satisfy the condition.\n\nSample Input 1\n\n5\n1 3 5 4 2\n\nSample Output 1\n\n2\n\np_2 = 3 is the second smallest number among p_1 = 1, p_2 = 3, and p_3 = 5. Also, p_4 = 4 is the second smallest number among p_3 = 5, p_4 = 4, and p_5 = 2. These two elements satisfy the condition.\n\nSample Input 2\n\n9\n9 6 3 2 5 8 7 4 1\n\nSample Output 2\n\n5", "sample_input": "5\n1 3 5 4 2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02988", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have a permutation p = {p_1,\\ p_2,\\ ...,\\ p_n} of {1,\\ 2,\\ ...,\\ n}.\n\nPrint the number of elements p_i (1 < i < n) that satisfy the following condition:\n\np_i is the second smallest number among the three numbers p_{i - 1}, p_i, and p_{i + 1}.\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq n \\leq 20\n\np is a permutation of {1,\\ 2,\\ ...,\\ n}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\np_1 p_2 ... p_n\n\nOutput\n\nPrint the number of elements p_i (1 < i < n) that satisfy the condition.\n\nSample Input 1\n\n5\n1 3 5 4 2\n\nSample Output 1\n\n2\n\np_2 = 3 is the second smallest number among p_1 = 1, p_2 = 3, and p_3 = 5. Also, p_4 = 4 is the second smallest number among p_3 = 5, p_4 = 4, and p_5 = 2. These two elements satisfy the condition.\n\nSample Input 2\n\n9\n9 6 3 2 5 8 7 4 1\n\nSample Output 2\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 481, "cpu_time_ms": 17, "memory_kb": 24512}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s095691952", "group_id": "codeNet:p02988", "input_text": "(defun solve(a &optional (ans 0))\n (cond\n ((<= (length a) 2) ans)\n (t\n (when\n\t (or (< (first a) (second a) (third a))\n\t (> (first a) (second a) (third a)))\n\t (incf ans))\n (solve (rest a) ans))))\n\n(defun main()\n (let ((n (read))\n\t(a (read-from-string (concatenate 'string \"(\" (read-line) \")\"))))\n (princ (solve a))\n (fresh-line)))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1593705916, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02988.html", "problem_id": "p02988", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02988/input.txt", "sample_output_relpath": "derived/input_output/data/p02988/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02988/Lisp/s095691952.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s095691952", "user_id": "u425762225"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun solve(a &optional (ans 0))\n (cond\n ((<= (length a) 2) ans)\n (t\n (when\n\t (or (< (first a) (second a) (third a))\n\t (> (first a) (second a) (third a)))\n\t (incf ans))\n (solve (rest a) ans))))\n\n(defun main()\n (let ((n (read))\n\t(a (read-from-string (concatenate 'string \"(\" (read-line) \")\"))))\n (princ (solve a))\n (fresh-line)))\n\n(main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have a permutation p = {p_1,\\ p_2,\\ ...,\\ p_n} of {1,\\ 2,\\ ...,\\ n}.\n\nPrint the number of elements p_i (1 < i < n) that satisfy the following condition:\n\np_i is the second smallest number among the three numbers p_{i - 1}, p_i, and p_{i + 1}.\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq n \\leq 20\n\np is a permutation of {1,\\ 2,\\ ...,\\ n}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\np_1 p_2 ... p_n\n\nOutput\n\nPrint the number of elements p_i (1 < i < n) that satisfy the condition.\n\nSample Input 1\n\n5\n1 3 5 4 2\n\nSample Output 1\n\n2\n\np_2 = 3 is the second smallest number among p_1 = 1, p_2 = 3, and p_3 = 5. Also, p_4 = 4 is the second smallest number among p_3 = 5, p_4 = 4, and p_5 = 2. These two elements satisfy the condition.\n\nSample Input 2\n\n9\n9 6 3 2 5 8 7 4 1\n\nSample Output 2\n\n5", "sample_input": "5\n1 3 5 4 2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02988", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have a permutation p = {p_1,\\ p_2,\\ ...,\\ p_n} of {1,\\ 2,\\ ...,\\ n}.\n\nPrint the number of elements p_i (1 < i < n) that satisfy the following condition:\n\np_i is the second smallest number among the three numbers p_{i - 1}, p_i, and p_{i + 1}.\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq n \\leq 20\n\np is a permutation of {1,\\ 2,\\ ...,\\ n}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\np_1 p_2 ... p_n\n\nOutput\n\nPrint the number of elements p_i (1 < i < n) that satisfy the condition.\n\nSample Input 1\n\n5\n1 3 5 4 2\n\nSample Output 1\n\n2\n\np_2 = 3 is the second smallest number among p_1 = 1, p_2 = 3, and p_3 = 5. Also, p_4 = 4 is the second smallest number among p_3 = 5, p_4 = 4, and p_5 = 2. These two elements satisfy the condition.\n\nSample Input 2\n\n9\n9 6 3 2 5 8 7 4 1\n\nSample Output 2\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 378, "cpu_time_ms": 19, "memory_kb": 24456}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s145765958", "group_id": "codeNet:p02988", "input_text": "(defmacro defsolver (name vars &body body)\n `(defun ,name ()\n (let (,@(mapcar #'list\n vars\n (mapcar (constantly '(read))\n vars)))\n ,@body)))\n\n(defsolver solution-b (n)\n (let ((l (loop for i below n collect (read))))\n (princ\n (loop for i from 1 below (- n 1)\n\tcount (let ((ll\n\t\t (sort (list (nth (1- i) l)\n\t\t\t\t (nth i l)\n\t\t\t\t (nth (1+ i) l))\n\t\t\t #'<)))\n\t\t(= (nth i l)\n\t\t (nth 1 ll)))))))\n\n(solution-b)", "language": "Lisp", "metadata": {"date": 1561859024, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02988.html", "problem_id": "p02988", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02988/input.txt", "sample_output_relpath": "derived/input_output/data/p02988/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02988/Lisp/s145765958.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s145765958", "user_id": "u100932207"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defmacro defsolver (name vars &body body)\n `(defun ,name ()\n (let (,@(mapcar #'list\n vars\n (mapcar (constantly '(read))\n vars)))\n ,@body)))\n\n(defsolver solution-b (n)\n (let ((l (loop for i below n collect (read))))\n (princ\n (loop for i from 1 below (- n 1)\n\tcount (let ((ll\n\t\t (sort (list (nth (1- i) l)\n\t\t\t\t (nth i l)\n\t\t\t\t (nth (1+ i) l))\n\t\t\t #'<)))\n\t\t(= (nth i l)\n\t\t (nth 1 ll)))))))\n\n(solution-b)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have a permutation p = {p_1,\\ p_2,\\ ...,\\ p_n} of {1,\\ 2,\\ ...,\\ n}.\n\nPrint the number of elements p_i (1 < i < n) that satisfy the following condition:\n\np_i is the second smallest number among the three numbers p_{i - 1}, p_i, and p_{i + 1}.\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq n \\leq 20\n\np is a permutation of {1,\\ 2,\\ ...,\\ n}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\np_1 p_2 ... p_n\n\nOutput\n\nPrint the number of elements p_i (1 < i < n) that satisfy the condition.\n\nSample Input 1\n\n5\n1 3 5 4 2\n\nSample Output 1\n\n2\n\np_2 = 3 is the second smallest number among p_1 = 1, p_2 = 3, and p_3 = 5. Also, p_4 = 4 is the second smallest number among p_3 = 5, p_4 = 4, and p_5 = 2. These two elements satisfy the condition.\n\nSample Input 2\n\n9\n9 6 3 2 5 8 7 4 1\n\nSample Output 2\n\n5", "sample_input": "5\n1 3 5 4 2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02988", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have a permutation p = {p_1,\\ p_2,\\ ...,\\ p_n} of {1,\\ 2,\\ ...,\\ n}.\n\nPrint the number of elements p_i (1 < i < n) that satisfy the following condition:\n\np_i is the second smallest number among the three numbers p_{i - 1}, p_i, and p_{i + 1}.\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq n \\leq 20\n\np is a permutation of {1,\\ 2,\\ ...,\\ n}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\np_1 p_2 ... p_n\n\nOutput\n\nPrint the number of elements p_i (1 < i < n) that satisfy the condition.\n\nSample Input 1\n\n5\n1 3 5 4 2\n\nSample Output 1\n\n2\n\np_2 = 3 is the second smallest number among p_1 = 1, p_2 = 3, and p_3 = 5. Also, p_4 = 4 is the second smallest number among p_3 = 5, p_4 = 4, and p_5 = 2. These two elements satisfy the condition.\n\nSample Input 2\n\n9\n9 6 3 2 5 8 7 4 1\n\nSample Output 2\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 464, "cpu_time_ms": 112, "memory_kb": 15456}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s429062686", "group_id": "codeNet:p02988", "input_text": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(defun f (ns line)\n (let* ((n (parse-integer ns))\n\t\t (arr (map 'vector (lambda(a) (parse-integer a)) (splitat #\\space line))))\n\t(labels ((rec (i acc)\n\t\t\t\t (if (< i (- n 2))\n\t\t\t\t\t(progn\n\t\t\t\t\t (let ((a0 (elt arr i))\n\t\t\t\t\t\t\t(a1 (elt arr (1+ i)))\n\t\t\t\t\t\t\t(a2 (elt arr (+ i 2))))\n\t\t\t\t\t\t(rec (1+ i) (if (or (and (<= a0 a1) (<= a1 a2))\n\t\t\t\t\t\t\t\t\t\t\t(and (>= a0 a1) (>= a1 a2))\n\t\t\t\t\t\t\t\t\t\t\t)(1+ acc) acc))))\n\t\t\t\t\tacc)))\n\t (format t \"~A\" (rec 0 0)))))\n\n(let (\n\t (line0 (read-line nil nil))\n\t (line1 (read-line nil nil))\n\t )\n (f line0 line1))\n", "language": "Lisp", "metadata": {"date": 1561857728, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02988.html", "problem_id": "p02988", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02988/input.txt", "sample_output_relpath": "derived/input_output/data/p02988/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02988/Lisp/s429062686.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s429062686", "user_id": "u254205055"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(defun f (ns line)\n (let* ((n (parse-integer ns))\n\t\t (arr (map 'vector (lambda(a) (parse-integer a)) (splitat #\\space line))))\n\t(labels ((rec (i acc)\n\t\t\t\t (if (< i (- n 2))\n\t\t\t\t\t(progn\n\t\t\t\t\t (let ((a0 (elt arr i))\n\t\t\t\t\t\t\t(a1 (elt arr (1+ i)))\n\t\t\t\t\t\t\t(a2 (elt arr (+ i 2))))\n\t\t\t\t\t\t(rec (1+ i) (if (or (and (<= a0 a1) (<= a1 a2))\n\t\t\t\t\t\t\t\t\t\t\t(and (>= a0 a1) (>= a1 a2))\n\t\t\t\t\t\t\t\t\t\t\t)(1+ acc) acc))))\n\t\t\t\t\tacc)))\n\t (format t \"~A\" (rec 0 0)))))\n\n(let (\n\t (line0 (read-line nil nil))\n\t (line1 (read-line nil nil))\n\t )\n (f line0 line1))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have a permutation p = {p_1,\\ p_2,\\ ...,\\ p_n} of {1,\\ 2,\\ ...,\\ n}.\n\nPrint the number of elements p_i (1 < i < n) that satisfy the following condition:\n\np_i is the second smallest number among the three numbers p_{i - 1}, p_i, and p_{i + 1}.\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq n \\leq 20\n\np is a permutation of {1,\\ 2,\\ ...,\\ n}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\np_1 p_2 ... p_n\n\nOutput\n\nPrint the number of elements p_i (1 < i < n) that satisfy the condition.\n\nSample Input 1\n\n5\n1 3 5 4 2\n\nSample Output 1\n\n2\n\np_2 = 3 is the second smallest number among p_1 = 1, p_2 = 3, and p_3 = 5. Also, p_4 = 4 is the second smallest number among p_3 = 5, p_4 = 4, and p_5 = 2. These two elements satisfy the condition.\n\nSample Input 2\n\n9\n9 6 3 2 5 8 7 4 1\n\nSample Output 2\n\n5", "sample_input": "5\n1 3 5 4 2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02988", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have a permutation p = {p_1,\\ p_2,\\ ...,\\ p_n} of {1,\\ 2,\\ ...,\\ n}.\n\nPrint the number of elements p_i (1 < i < n) that satisfy the following condition:\n\np_i is the second smallest number among the three numbers p_{i - 1}, p_i, and p_{i + 1}.\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq n \\leq 20\n\np is a permutation of {1,\\ 2,\\ ...,\\ n}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\np_1 p_2 ... p_n\n\nOutput\n\nPrint the number of elements p_i (1 < i < n) that satisfy the condition.\n\nSample Input 1\n\n5\n1 3 5 4 2\n\nSample Output 1\n\n2\n\np_2 = 3 is the second smallest number among p_1 = 1, p_2 = 3, and p_3 = 5. Also, p_4 = 4 is the second smallest number among p_3 = 5, p_4 = 4, and p_5 = 2. These two elements satisfy the condition.\n\nSample Input 2\n\n9\n9 6 3 2 5 8 7 4 1\n\nSample Output 2\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 785, "cpu_time_ms": 173, "memory_kb": 17000}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s315712616", "group_id": "codeNet:p02990", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(deftype int32 () '(signed-byte 32))\n(deftype int64 () '(signed-byte 64))\n\n\n;;macros\n(defmacro println (n)\n `(format t \"~a~%\" ,n))\n(defmacro vint-out (vec)\n `(progn\n (rep i (length ,vec)\n (princ (vref ,vec i))\n (princ \" \"))\n (fresh-line)))\n(defmacro aif (test-form then-form &optional else-form)\n `(let ((it ,test-form))\n (if it ,then-form ,else-form)))\n\n;;vector\n(defmacro vec (type &optional (num 100) (val 0))\n (let* ((g (gensym)))\n `(let* ((,g ,num))\n (make-array ,g :element-type ',type :initial-element ,val\n :adjustable nil :fill-pointer ,g))))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vint (&optional (num 0) (val 0))\n `(vec int32 ,num ,val))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vref (vector pos &optional value)\n (let ((g (gensym)))\n `(let ((,g ,value))\n (if ,g\n (setf (aref ,vector ,pos) ,g)\n (aref ,vector ,pos)))))\n\n(defmacro chvar (sym comp predicate)\n (let ((g (gensym)))\n `(let ((,g ,comp))\n (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))\n (setf ,sym ,g)))))\n\n(defmacro chmax (sym comp &optional (predicate #'>))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro chmin (sym comp &optional (predicate #'<))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro defchangef (name op default-val)\n `(defmacro ,name (var &optional (val ,default-val))\n `(setq ,var (,',op ,val ,var))))\n(defmacro read-str () ;readを使う都合上0000などは文字列として読み込むことができない\n `(write-to-string (read)))\n(defmacro print-float (r)\n `(format t \"~,9F~%\" (coerce ,r 'double-float)))\n(defmacro tlet (bindings &body body)\n `(let (,@(mapcar (lambda (binding)\n (subseq binding 0 2))\n bindings))\n (declare ,@(mapcar (lambda (binding)\n (list 'type (caddr binding) (car binding)))\n bindings))\n ,@body))\n\n;;本体\n(define-symbol-macro *mod* (+ 7 (expt 10 9)))\n\n(defmacro product (start end)\n `(do ((i ,start (1+ i))\n (res 1))\n ((= i ,end) res)\n (setq res (* res i))))\n\n(defun div (n r)\n (declare (optimize (speed 3) (safety 0)))\n (declare (integer n r))\n (the integer\n (mod (/ (product (1+ n) (+ n r))\n (product 1 r))\n *mod*)))\n\n(defun main()\n (declare (optimize (speed 3) (safety 0)))\n (tlet ((n (read) integer) (k (read) integer))\n (dotimes (i k)\n (println\n (mod (* (div (- k i 1) (1+ i))\n (div (- n k i) (+ i 2)))\n *mod*)))))\n\n#-swank(main)\n\n\n\n", "language": "Lisp", "metadata": {"date": 1561868209, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02990.html", "problem_id": "p02990", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02990/input.txt", "sample_output_relpath": "derived/input_output/data/p02990/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02990/Lisp/s315712616.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s315712616", "user_id": "u432998668"}, "prompt_components": {"gold_output": "3\n6\n1\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(deftype int32 () '(signed-byte 32))\n(deftype int64 () '(signed-byte 64))\n\n\n;;macros\n(defmacro println (n)\n `(format t \"~a~%\" ,n))\n(defmacro vint-out (vec)\n `(progn\n (rep i (length ,vec)\n (princ (vref ,vec i))\n (princ \" \"))\n (fresh-line)))\n(defmacro aif (test-form then-form &optional else-form)\n `(let ((it ,test-form))\n (if it ,then-form ,else-form)))\n\n;;vector\n(defmacro vec (type &optional (num 100) (val 0))\n (let* ((g (gensym)))\n `(let* ((,g ,num))\n (make-array ,g :element-type ',type :initial-element ,val\n :adjustable nil :fill-pointer ,g))))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vint (&optional (num 0) (val 0))\n `(vec int32 ,num ,val))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vref (vector pos &optional value)\n (let ((g (gensym)))\n `(let ((,g ,value))\n (if ,g\n (setf (aref ,vector ,pos) ,g)\n (aref ,vector ,pos)))))\n\n(defmacro chvar (sym comp predicate)\n (let ((g (gensym)))\n `(let ((,g ,comp))\n (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))\n (setf ,sym ,g)))))\n\n(defmacro chmax (sym comp &optional (predicate #'>))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro chmin (sym comp &optional (predicate #'<))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro defchangef (name op default-val)\n `(defmacro ,name (var &optional (val ,default-val))\n `(setq ,var (,',op ,val ,var))))\n(defmacro read-str () ;readを使う都合上0000などは文字列として読み込むことができない\n `(write-to-string (read)))\n(defmacro print-float (r)\n `(format t \"~,9F~%\" (coerce ,r 'double-float)))\n(defmacro tlet (bindings &body body)\n `(let (,@(mapcar (lambda (binding)\n (subseq binding 0 2))\n bindings))\n (declare ,@(mapcar (lambda (binding)\n (list 'type (caddr binding) (car binding)))\n bindings))\n ,@body))\n\n;;本体\n(define-symbol-macro *mod* (+ 7 (expt 10 9)))\n\n(defmacro product (start end)\n `(do ((i ,start (1+ i))\n (res 1))\n ((= i ,end) res)\n (setq res (* res i))))\n\n(defun div (n r)\n (declare (optimize (speed 3) (safety 0)))\n (declare (integer n r))\n (the integer\n (mod (/ (product (1+ n) (+ n r))\n (product 1 r))\n *mod*)))\n\n(defun main()\n (declare (optimize (speed 3) (safety 0)))\n (tlet ((n (read) integer) (k (read) integer))\n (dotimes (i k)\n (println\n (mod (* (div (- k i 1) (1+ i))\n (div (- n k i) (+ i 2)))\n *mod*)))))\n\n#-swank(main)\n\n\n\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.\n\nFirst, Snuke will arrange the N balls in a row from left to right.\n\nThen, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.\n\nHow many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \\leq i \\leq K.\n\nConstraints\n\n1 \\leq K \\leq N \\leq 2000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint K lines. The i-th line (1 \\leq i \\leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.\n\nSample Input 1\n\n5 3\n\nSample Output 1\n\n3\n6\n1\n\nThere are three ways to arrange the balls so that Takahashi will need exactly one move: (B, B, B, R, R), (R, B, B, B, R), and (R, R, B, B, B). (R and B stands for red and blue, respectively).\n\nThere are six ways to arrange the balls so that Takahashi will need exactly two moves: (B, B, R, B, R), (B, B, R, R, B), (R, B, B, R, B), (R, B, R, B, B), (B, R, B, B, R), and (B, R, R, B, B).\n\nThere is one way to arrange the balls so that Takahashi will need exactly three moves: (B, R, B, R, B).\n\nSample Input 2\n\n2000 3\n\nSample Output 2\n\n1998\n3990006\n327341989\n\nBe sure to print the numbers of arrangements modulo 10^9+7.", "sample_input": "5 3\n"}, "reference_outputs": ["3\n6\n1\n"], "source_document_id": "p02990", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.\n\nFirst, Snuke will arrange the N balls in a row from left to right.\n\nThen, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.\n\nHow many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \\leq i \\leq K.\n\nConstraints\n\n1 \\leq K \\leq N \\leq 2000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint K lines. The i-th line (1 \\leq i \\leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.\n\nSample Input 1\n\n5 3\n\nSample Output 1\n\n3\n6\n1\n\nThere are three ways to arrange the balls so that Takahashi will need exactly one move: (B, B, B, R, R), (R, B, B, B, R), and (R, R, B, B, B). (R and B stands for red and blue, respectively).\n\nThere are six ways to arrange the balls so that Takahashi will need exactly two moves: (B, B, R, B, R), (B, B, R, R, B), (R, B, B, R, B), (R, B, R, B, B), (B, R, B, B, R), and (B, R, R, B, B).\n\nThere is one way to arrange the balls so that Takahashi will need exactly three moves: (B, R, B, R, B).\n\nSample Input 2\n\n2000 3\n\nSample Output 2\n\n1998\n3990006\n327341989\n\nBe sure to print the numbers of arrangements modulo 10^9+7.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3091, "cpu_time_ms": 2105, "memory_kb": 63812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s847638347", "group_id": "codeNet:p02990", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\n\n(defconstant +binom-size+ 10000)\n(defconstant +binom-mod+ #.(+ (expt 10 9) 7))\n\n(declaim ((simple-array (unsigned-byte 32) (*)) *fact* *fact-inv* *inv*))\n(defparameter *fact* (make-array +binom-size+ :element-type '(unsigned-byte 32)))\n(defparameter *fact-inv* (make-array +binom-size+ :element-type '(unsigned-byte 32)))\n(defparameter *inv* (make-array +binom-size+ :element-type '(unsigned-byte 32)))\n\n(defun initialize-binom ()\n (setf (aref *fact* 0) 1\n (aref *fact* 1) 1\n (aref *fact-inv* 0) 1\n (aref *fact-inv* 1) 1\n (aref *inv* 1) 1)\n (loop for i from 2 below +binom-size+\n do (setf (aref *fact* i) (mod (* i (aref *fact* (- i 1))) +binom-mod+)\n (aref *inv* i) (mod (- (* (aref *inv* (rem +binom-mod+ i))\n (floor +binom-mod+ i)))\n +binom-mod+)\n (aref *fact-inv* i) (mod (* (aref *inv* i)\n (aref *fact-inv* (- i 1)))\n +binom-mod+))))\n\n(initialize-binom)\n\n(declaim (inline binom))\n(defun binom (n k)\n \"Returns nCk.\"\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (mod (* (aref *fact* n)\n (mod (* (aref *fact-inv* k) (aref *fact-inv* (- n k))) +binom-mod+))\n +binom-mod+)))\n\n(defun multinomial (&rest ks)\n \"Returns the multinomial coefficient K!/k_1!k_2!...k_n! for K = k_1 + k_2 +\n... + k_n. K must be equal or smaller than MOST-POSITIVE-FIXNUM. (multinomial)\nreturns 1.\"\n (let ((sum 0)\n (result 1))\n (declare ((integer 0 #.most-positive-fixnum) result sum))\n (dolist (k ks)\n (incf sum k)\n (setq result\n (mod (* result (aref *fact-inv* k)) +binom-mod+)))\n (mod (* result (aref *fact* sum)) +binom-mod+)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (k (read)))\n (loop for i from 1 to k\n do (println (mod (* (binom (+ n (- k) 1) i) (binom (- k 1) (- i 1))) +mod+)))))\n\n#-swank(main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &optional (func #'main))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNC, and returns true if the\nstring output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (and (> (length s) 0)\n (eql (char s (- (length s) 1)) #\\Linefeed))\n s\n (uiop:strcat s uiop:+lf+))))\n (equal (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall func)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n (let ((*standard-output* out))\n (etypecase thing\n (null ; Runs #'MAIN with the string on clipboard\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname ; Runs #'MAIN with the string in a text file\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 3\n\"\n \"3\n6\n1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2000 3\n\"\n \"1998\n3990006\n327341989\n\")))\n", "language": "Lisp", "metadata": {"date": 1561857762, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02990.html", "problem_id": "p02990", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02990/input.txt", "sample_output_relpath": "derived/input_output/data/p02990/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02990/Lisp/s847638347.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s847638347", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n6\n1\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\n\n(defconstant +binom-size+ 10000)\n(defconstant +binom-mod+ #.(+ (expt 10 9) 7))\n\n(declaim ((simple-array (unsigned-byte 32) (*)) *fact* *fact-inv* *inv*))\n(defparameter *fact* (make-array +binom-size+ :element-type '(unsigned-byte 32)))\n(defparameter *fact-inv* (make-array +binom-size+ :element-type '(unsigned-byte 32)))\n(defparameter *inv* (make-array +binom-size+ :element-type '(unsigned-byte 32)))\n\n(defun initialize-binom ()\n (setf (aref *fact* 0) 1\n (aref *fact* 1) 1\n (aref *fact-inv* 0) 1\n (aref *fact-inv* 1) 1\n (aref *inv* 1) 1)\n (loop for i from 2 below +binom-size+\n do (setf (aref *fact* i) (mod (* i (aref *fact* (- i 1))) +binom-mod+)\n (aref *inv* i) (mod (- (* (aref *inv* (rem +binom-mod+ i))\n (floor +binom-mod+ i)))\n +binom-mod+)\n (aref *fact-inv* i) (mod (* (aref *inv* i)\n (aref *fact-inv* (- i 1)))\n +binom-mod+))))\n\n(initialize-binom)\n\n(declaim (inline binom))\n(defun binom (n k)\n \"Returns nCk.\"\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (mod (* (aref *fact* n)\n (mod (* (aref *fact-inv* k) (aref *fact-inv* (- n k))) +binom-mod+))\n +binom-mod+)))\n\n(defun multinomial (&rest ks)\n \"Returns the multinomial coefficient K!/k_1!k_2!...k_n! for K = k_1 + k_2 +\n... + k_n. K must be equal or smaller than MOST-POSITIVE-FIXNUM. (multinomial)\nreturns 1.\"\n (let ((sum 0)\n (result 1))\n (declare ((integer 0 #.most-positive-fixnum) result sum))\n (dolist (k ks)\n (incf sum k)\n (setq result\n (mod (* result (aref *fact-inv* k)) +binom-mod+)))\n (mod (* result (aref *fact* sum)) +binom-mod+)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (k (read)))\n (loop for i from 1 to k\n do (println (mod (* (binom (+ n (- k) 1) i) (binom (- k 1) (- i 1))) +mod+)))))\n\n#-swank(main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &optional (func #'main))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNC, and returns true if the\nstring output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (and (> (length s) 0)\n (eql (char s (- (length s) 1)) #\\Linefeed))\n s\n (uiop:strcat s uiop:+lf+))))\n (equal (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall func)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n (let ((*standard-output* out))\n (etypecase thing\n (null ; Runs #'MAIN with the string on clipboard\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname ; Runs #'MAIN with the string in a text file\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 3\n\"\n \"3\n6\n1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2000 3\n\"\n \"1998\n3990006\n327341989\n\")))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.\n\nFirst, Snuke will arrange the N balls in a row from left to right.\n\nThen, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.\n\nHow many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \\leq i \\leq K.\n\nConstraints\n\n1 \\leq K \\leq N \\leq 2000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint K lines. The i-th line (1 \\leq i \\leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.\n\nSample Input 1\n\n5 3\n\nSample Output 1\n\n3\n6\n1\n\nThere are three ways to arrange the balls so that Takahashi will need exactly one move: (B, B, B, R, R), (R, B, B, B, R), and (R, R, B, B, B). (R and B stands for red and blue, respectively).\n\nThere are six ways to arrange the balls so that Takahashi will need exactly two moves: (B, B, R, B, R), (B, B, R, R, B), (R, B, B, R, B), (R, B, R, B, B), (B, R, B, B, R), and (B, R, R, B, B).\n\nThere is one way to arrange the balls so that Takahashi will need exactly three moves: (B, R, B, R, B).\n\nSample Input 2\n\n2000 3\n\nSample Output 2\n\n1998\n3990006\n327341989\n\nBe sure to print the numbers of arrangements modulo 10^9+7.", "sample_input": "5 3\n"}, "reference_outputs": ["3\n6\n1\n"], "source_document_id": "p02990", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.\n\nFirst, Snuke will arrange the N balls in a row from left to right.\n\nThen, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.\n\nHow many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \\leq i \\leq K.\n\nConstraints\n\n1 \\leq K \\leq N \\leq 2000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint K lines. The i-th line (1 \\leq i \\leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.\n\nSample Input 1\n\n5 3\n\nSample Output 1\n\n3\n6\n1\n\nThere are three ways to arrange the balls so that Takahashi will need exactly one move: (B, B, B, R, R), (R, B, B, B, R), and (R, R, B, B, B). (R and B stands for red and blue, respectively).\n\nThere are six ways to arrange the balls so that Takahashi will need exactly two moves: (B, B, R, B, R), (B, B, R, R, B), (R, B, B, R, B), (R, B, R, B, B), (B, R, B, B, R), and (B, R, R, B, B).\n\nThere is one way to arrange the balls so that Takahashi will need exactly three moves: (B, R, B, R, B).\n\nSample Input 2\n\n2000 3\n\nSample Output 2\n\n1998\n3990006\n327341989\n\nBe sure to print the numbers of arrangements modulo 10^9+7.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5347, "cpu_time_ms": 176, "memory_kb": 23656}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s845537647", "group_id": "codeNet:p02991", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Pops OBJ from the front of QUEUE.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (graph (make-array (* 3 n) :element-type 'list :initial-element nil)))\n (declare (uint32 n m))\n (labels ((calc (i mod)\n (declare (uint32 mod i))\n (+ mod (* 3 i))))\n (dotimes (i m)\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1)))\n (push (calc v 1) (aref graph (calc u 0)))\n (push (calc v 2) (aref graph (calc u 1)))\n (push (calc v 0) (aref graph (calc u 2)))))\n (let ((start (calc (- (read) 1) 0))\n (goal (calc (- (read) 1) 0))\n (dist (make-array (* 3 n) :element-type 'uint32 :initial-element #xffffffff))\n (q (make-queue)))\n (declare (uint32 start goal))\n (enqueue start q)\n (setf (aref dist start) 0)\n (loop until (queue-empty-p q)\n for v of-type uint32 = (dequeue q)\n do (when (= v goal)\n (println (floor (aref dist v) 3))\n (return-from main))\n (dolist (neighbor (aref graph v))\n (when (= #xffffffff (aref dist neighbor))\n (setf (aref dist neighbor)\n (+ 1 (aref dist v)))\n (enqueue neighbor q))))\n (println -1)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1561883840, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02991.html", "problem_id": "p02991", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02991/input.txt", "sample_output_relpath": "derived/input_output/data/p02991/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02991/Lisp/s845537647.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s845537647", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Pops OBJ from the front of QUEUE.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (graph (make-array (* 3 n) :element-type 'list :initial-element nil)))\n (declare (uint32 n m))\n (labels ((calc (i mod)\n (declare (uint32 mod i))\n (+ mod (* 3 i))))\n (dotimes (i m)\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1)))\n (push (calc v 1) (aref graph (calc u 0)))\n (push (calc v 2) (aref graph (calc u 1)))\n (push (calc v 0) (aref graph (calc u 2)))))\n (let ((start (calc (- (read) 1) 0))\n (goal (calc (- (read) 1) 0))\n (dist (make-array (* 3 n) :element-type 'uint32 :initial-element #xffffffff))\n (q (make-queue)))\n (declare (uint32 start goal))\n (enqueue start q)\n (setf (aref dist start) 0)\n (loop until (queue-empty-p q)\n for v of-type uint32 = (dequeue q)\n do (when (= v goal)\n (println (floor (aref dist v) 3))\n (return-from main))\n (dolist (neighbor (aref graph v))\n (when (= #xffffffff (aref dist neighbor))\n (setf (aref dist neighbor)\n (+ 1 (aref dist v)))\n (enqueue neighbor q))))\n (println -1)))))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nKen loves ken-ken-pa (Japanese version of hopscotch). Today, he will play it on a directed graph G.\nG consists of N vertices numbered 1 to N, and M edges. The i-th edge points from Vertex u_i to Vertex v_i.\n\nFirst, Ken stands on Vertex S. He wants to reach Vertex T by repeating ken-ken-pa. In one ken-ken-pa, he does the following exactly three times: follow an edge pointing from the vertex on which he is standing.\n\nDetermine if he can reach Vertex T by repeating ken-ken-pa. If the answer is yes, find the minimum number of ken-ken-pa needed to reach Vertex T. Note that visiting Vertex T in the middle of a ken-ken-pa does not count as reaching Vertex T by repeating ken-ken-pa.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n0 \\leq M \\leq \\min(10^5, N (N-1))\n\n1 \\leq u_i, v_i \\leq N(1 \\leq i \\leq M)\n\nu_i \\neq v_i (1 \\leq i \\leq M)\n\nIf i \\neq j, (u_i, v_i) \\neq (u_j, v_j).\n\n1 \\leq S, T \\leq N\n\nS \\neq T\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nu_1 v_1\n:\nu_M v_M\nS T\n\nOutput\n\nIf Ken cannot reach Vertex T from Vertex S by repeating ken-ken-pa, print -1.\nIf he can, print the minimum number of ken-ken-pa needed to reach vertex T.\n\nSample Input 1\n\n4 4\n1 2\n2 3\n3 4\n4 1\n1 3\n\nSample Output 1\n\n2\n\nKen can reach Vertex 3 from Vertex 1 in two ken-ken-pa, as follows: 1 \\rightarrow 2 \\rightarrow 3 \\rightarrow 4 in the first ken-ken-pa, then 4 \\rightarrow 1 \\rightarrow 2 \\rightarrow 3 in the second ken-ken-pa. This is the minimum number of ken-ken-pa needed.\n\nSample Input 2\n\n3 3\n1 2\n2 3\n3 1\n1 2\n\nSample Output 2\n\n-1\n\nAny number of ken-ken-pa will bring Ken back to Vertex 1, so he cannot reach Vertex 2, though he can pass through it in the middle of a ken-ken-pa.\n\nSample Input 3\n\n2 0\n1 2\n\nSample Output 3\n\n-1\n\nVertex S and Vertex T may be disconnected.\n\nSample Input 4\n\n6 8\n1 2\n2 3\n3 4\n4 5\n5 1\n1 4\n1 5\n4 6\n1 6\n\nSample Output 4\n\n2", "sample_input": "4 4\n1 2\n2 3\n3 4\n4 1\n1 3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02991", "source_text": "Score : 500 points\n\nProblem Statement\n\nKen loves ken-ken-pa (Japanese version of hopscotch). Today, he will play it on a directed graph G.\nG consists of N vertices numbered 1 to N, and M edges. The i-th edge points from Vertex u_i to Vertex v_i.\n\nFirst, Ken stands on Vertex S. He wants to reach Vertex T by repeating ken-ken-pa. In one ken-ken-pa, he does the following exactly three times: follow an edge pointing from the vertex on which he is standing.\n\nDetermine if he can reach Vertex T by repeating ken-ken-pa. If the answer is yes, find the minimum number of ken-ken-pa needed to reach Vertex T. Note that visiting Vertex T in the middle of a ken-ken-pa does not count as reaching Vertex T by repeating ken-ken-pa.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n0 \\leq M \\leq \\min(10^5, N (N-1))\n\n1 \\leq u_i, v_i \\leq N(1 \\leq i \\leq M)\n\nu_i \\neq v_i (1 \\leq i \\leq M)\n\nIf i \\neq j, (u_i, v_i) \\neq (u_j, v_j).\n\n1 \\leq S, T \\leq N\n\nS \\neq T\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nu_1 v_1\n:\nu_M v_M\nS T\n\nOutput\n\nIf Ken cannot reach Vertex T from Vertex S by repeating ken-ken-pa, print -1.\nIf he can, print the minimum number of ken-ken-pa needed to reach vertex T.\n\nSample Input 1\n\n4 4\n1 2\n2 3\n3 4\n4 1\n1 3\n\nSample Output 1\n\n2\n\nKen can reach Vertex 3 from Vertex 1 in two ken-ken-pa, as follows: 1 \\rightarrow 2 \\rightarrow 3 \\rightarrow 4 in the first ken-ken-pa, then 4 \\rightarrow 1 \\rightarrow 2 \\rightarrow 3 in the second ken-ken-pa. This is the minimum number of ken-ken-pa needed.\n\nSample Input 2\n\n3 3\n1 2\n2 3\n3 1\n1 2\n\nSample Output 2\n\n-1\n\nAny number of ken-ken-pa will bring Ken back to Vertex 1, so he cannot reach Vertex 2, though he can pass through it in the middle of a ken-ken-pa.\n\nSample Input 3\n\n2 0\n1 2\n\nSample Output 3\n\n-1\n\nVertex S and Vertex T may be disconnected.\n\nSample Input 4\n\n6 8\n1 2\n2 3\n3 4\n4 5\n5 1\n1 4\n1 5\n4 6\n1 6\n\nSample Output 4\n\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4749, "cpu_time_ms": 269, "memory_kb": 37984}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s293574843", "group_id": "codeNet:p02991", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Pops OBJ from the front of QUEUE.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (graph (make-array (* 3 n) :element-type 'list :initial-element nil)))\n (labels ((calc (i mod)\n (+ mod (* 3 i))))\n (dotimes (i m)\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1)))\n (push (calc v 1) (aref graph (calc u 0)))\n (push (calc v 2) (aref graph (calc u 1)))\n (push (calc v 0) (aref graph (calc u 2)))))\n (let ((start (calc (- (read) 1) 0))\n (goal (calc (- (read) 1) 0))\n (marked (make-array (* 3 n) :element-type 'bit :initial-element 0))\n (q (make-queue)))\n (enqueue (cons start 0) q)\n (setf (aref marked start) 1)\n (loop until (queue-empty-p q)\n for (v . dist) = (dequeue q)\n do (when (= v goal)\n (println (floor dist 3))\n (return-from main))\n (dolist (neighbor (aref graph v))\n (when (zerop (aref marked neighbor))\n (setf (aref marked neighbor) 1)\n (enqueue (cons neighbor (+ dist 1)) q))))\n (println -1)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1561860042, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02991.html", "problem_id": "p02991", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02991/input.txt", "sample_output_relpath": "derived/input_output/data/p02991/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02991/Lisp/s293574843.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s293574843", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Pops OBJ from the front of QUEUE.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (graph (make-array (* 3 n) :element-type 'list :initial-element nil)))\n (labels ((calc (i mod)\n (+ mod (* 3 i))))\n (dotimes (i m)\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1)))\n (push (calc v 1) (aref graph (calc u 0)))\n (push (calc v 2) (aref graph (calc u 1)))\n (push (calc v 0) (aref graph (calc u 2)))))\n (let ((start (calc (- (read) 1) 0))\n (goal (calc (- (read) 1) 0))\n (marked (make-array (* 3 n) :element-type 'bit :initial-element 0))\n (q (make-queue)))\n (enqueue (cons start 0) q)\n (setf (aref marked start) 1)\n (loop until (queue-empty-p q)\n for (v . dist) = (dequeue q)\n do (when (= v goal)\n (println (floor dist 3))\n (return-from main))\n (dolist (neighbor (aref graph v))\n (when (zerop (aref marked neighbor))\n (setf (aref marked neighbor) 1)\n (enqueue (cons neighbor (+ dist 1)) q))))\n (println -1)))))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nKen loves ken-ken-pa (Japanese version of hopscotch). Today, he will play it on a directed graph G.\nG consists of N vertices numbered 1 to N, and M edges. The i-th edge points from Vertex u_i to Vertex v_i.\n\nFirst, Ken stands on Vertex S. He wants to reach Vertex T by repeating ken-ken-pa. In one ken-ken-pa, he does the following exactly three times: follow an edge pointing from the vertex on which he is standing.\n\nDetermine if he can reach Vertex T by repeating ken-ken-pa. If the answer is yes, find the minimum number of ken-ken-pa needed to reach Vertex T. Note that visiting Vertex T in the middle of a ken-ken-pa does not count as reaching Vertex T by repeating ken-ken-pa.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n0 \\leq M \\leq \\min(10^5, N (N-1))\n\n1 \\leq u_i, v_i \\leq N(1 \\leq i \\leq M)\n\nu_i \\neq v_i (1 \\leq i \\leq M)\n\nIf i \\neq j, (u_i, v_i) \\neq (u_j, v_j).\n\n1 \\leq S, T \\leq N\n\nS \\neq T\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nu_1 v_1\n:\nu_M v_M\nS T\n\nOutput\n\nIf Ken cannot reach Vertex T from Vertex S by repeating ken-ken-pa, print -1.\nIf he can, print the minimum number of ken-ken-pa needed to reach vertex T.\n\nSample Input 1\n\n4 4\n1 2\n2 3\n3 4\n4 1\n1 3\n\nSample Output 1\n\n2\n\nKen can reach Vertex 3 from Vertex 1 in two ken-ken-pa, as follows: 1 \\rightarrow 2 \\rightarrow 3 \\rightarrow 4 in the first ken-ken-pa, then 4 \\rightarrow 1 \\rightarrow 2 \\rightarrow 3 in the second ken-ken-pa. This is the minimum number of ken-ken-pa needed.\n\nSample Input 2\n\n3 3\n1 2\n2 3\n3 1\n1 2\n\nSample Output 2\n\n-1\n\nAny number of ken-ken-pa will bring Ken back to Vertex 1, so he cannot reach Vertex 2, though he can pass through it in the middle of a ken-ken-pa.\n\nSample Input 3\n\n2 0\n1 2\n\nSample Output 3\n\n-1\n\nVertex S and Vertex T may be disconnected.\n\nSample Input 4\n\n6 8\n1 2\n2 3\n3 4\n4 5\n5 1\n1 4\n1 5\n4 6\n1 6\n\nSample Output 4\n\n2", "sample_input": "4 4\n1 2\n2 3\n3 4\n4 1\n1 3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02991", "source_text": "Score : 500 points\n\nProblem Statement\n\nKen loves ken-ken-pa (Japanese version of hopscotch). Today, he will play it on a directed graph G.\nG consists of N vertices numbered 1 to N, and M edges. The i-th edge points from Vertex u_i to Vertex v_i.\n\nFirst, Ken stands on Vertex S. He wants to reach Vertex T by repeating ken-ken-pa. In one ken-ken-pa, he does the following exactly three times: follow an edge pointing from the vertex on which he is standing.\n\nDetermine if he can reach Vertex T by repeating ken-ken-pa. If the answer is yes, find the minimum number of ken-ken-pa needed to reach Vertex T. Note that visiting Vertex T in the middle of a ken-ken-pa does not count as reaching Vertex T by repeating ken-ken-pa.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n0 \\leq M \\leq \\min(10^5, N (N-1))\n\n1 \\leq u_i, v_i \\leq N(1 \\leq i \\leq M)\n\nu_i \\neq v_i (1 \\leq i \\leq M)\n\nIf i \\neq j, (u_i, v_i) \\neq (u_j, v_j).\n\n1 \\leq S, T \\leq N\n\nS \\neq T\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nu_1 v_1\n:\nu_M v_M\nS T\n\nOutput\n\nIf Ken cannot reach Vertex T from Vertex S by repeating ken-ken-pa, print -1.\nIf he can, print the minimum number of ken-ken-pa needed to reach vertex T.\n\nSample Input 1\n\n4 4\n1 2\n2 3\n3 4\n4 1\n1 3\n\nSample Output 1\n\n2\n\nKen can reach Vertex 3 from Vertex 1 in two ken-ken-pa, as follows: 1 \\rightarrow 2 \\rightarrow 3 \\rightarrow 4 in the first ken-ken-pa, then 4 \\rightarrow 1 \\rightarrow 2 \\rightarrow 3 in the second ken-ken-pa. This is the minimum number of ken-ken-pa needed.\n\nSample Input 2\n\n3 3\n1 2\n2 3\n3 1\n1 2\n\nSample Output 2\n\n-1\n\nAny number of ken-ken-pa will bring Ken back to Vertex 1, so he cannot reach Vertex 2, though he can pass through it in the middle of a ken-ken-pa.\n\nSample Input 3\n\n2 0\n1 2\n\nSample Output 3\n\n-1\n\nVertex S and Vertex T may be disconnected.\n\nSample Input 4\n\n6 8\n1 2\n2 3\n3 4\n4 5\n5 1\n1 4\n1 5\n4 6\n1 6\n\nSample Output 4\n\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4625, "cpu_time_ms": 276, "memory_kb": 37728}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s403981095", "group_id": "codeNet:p02991", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Pops OBJ from the front of QUEUE.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (graph0 (make-array n :element-type 'list :initial-element nil))\n (graph (make-array n :element-type 'hash-table :initial-element nil)))\n (dotimes (i m)\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1)))\n (push v (aref graph0 u))))\n (labels ((dfs (v dist table)\n (declare (uint8 dist))\n (if (= dist 3)\n (setf (gethash v table) t)\n (dolist (next (aref graph0 v))\n (dfs next (+ dist 1) table)))))\n (dotimes (i n)\n (let ((table (make-hash-table)))\n (dfs i 0 table)\n (setf (aref graph i) table)))\n (let ((start (- (read) 1))\n (goal (- (read) 1))\n (marked (make-array n :element-type 'bit :initial-element 0))\n (q (make-queue)))\n (enqueue (cons start 0) q)\n (setf (aref marked start) 1)\n (loop until (queue-empty-p q)\n for (v . dist) = (dequeue q)\n do (when (= v goal)\n (println dist)\n (return-from main))\n (loop for neighbor being each hash-key of (aref graph v)\n do (when (zerop (aref marked neighbor))\n (setf (aref marked neighbor) 1)\n (enqueue (cons neighbor (+ dist 1)) q))))\n (println -1)))))\n\n#-swank(main)\n\n", "language": "Lisp", "metadata": {"date": 1561859799, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02991.html", "problem_id": "p02991", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02991/input.txt", "sample_output_relpath": "derived/input_output/data/p02991/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02991/Lisp/s403981095.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s403981095", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Pops OBJ from the front of QUEUE.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (graph0 (make-array n :element-type 'list :initial-element nil))\n (graph (make-array n :element-type 'hash-table :initial-element nil)))\n (dotimes (i m)\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1)))\n (push v (aref graph0 u))))\n (labels ((dfs (v dist table)\n (declare (uint8 dist))\n (if (= dist 3)\n (setf (gethash v table) t)\n (dolist (next (aref graph0 v))\n (dfs next (+ dist 1) table)))))\n (dotimes (i n)\n (let ((table (make-hash-table)))\n (dfs i 0 table)\n (setf (aref graph i) table)))\n (let ((start (- (read) 1))\n (goal (- (read) 1))\n (marked (make-array n :element-type 'bit :initial-element 0))\n (q (make-queue)))\n (enqueue (cons start 0) q)\n (setf (aref marked start) 1)\n (loop until (queue-empty-p q)\n for (v . dist) = (dequeue q)\n do (when (= v goal)\n (println dist)\n (return-from main))\n (loop for neighbor being each hash-key of (aref graph v)\n do (when (zerop (aref marked neighbor))\n (setf (aref marked neighbor) 1)\n (enqueue (cons neighbor (+ dist 1)) q))))\n (println -1)))))\n\n#-swank(main)\n\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nKen loves ken-ken-pa (Japanese version of hopscotch). Today, he will play it on a directed graph G.\nG consists of N vertices numbered 1 to N, and M edges. The i-th edge points from Vertex u_i to Vertex v_i.\n\nFirst, Ken stands on Vertex S. He wants to reach Vertex T by repeating ken-ken-pa. In one ken-ken-pa, he does the following exactly three times: follow an edge pointing from the vertex on which he is standing.\n\nDetermine if he can reach Vertex T by repeating ken-ken-pa. If the answer is yes, find the minimum number of ken-ken-pa needed to reach Vertex T. Note that visiting Vertex T in the middle of a ken-ken-pa does not count as reaching Vertex T by repeating ken-ken-pa.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n0 \\leq M \\leq \\min(10^5, N (N-1))\n\n1 \\leq u_i, v_i \\leq N(1 \\leq i \\leq M)\n\nu_i \\neq v_i (1 \\leq i \\leq M)\n\nIf i \\neq j, (u_i, v_i) \\neq (u_j, v_j).\n\n1 \\leq S, T \\leq N\n\nS \\neq T\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nu_1 v_1\n:\nu_M v_M\nS T\n\nOutput\n\nIf Ken cannot reach Vertex T from Vertex S by repeating ken-ken-pa, print -1.\nIf he can, print the minimum number of ken-ken-pa needed to reach vertex T.\n\nSample Input 1\n\n4 4\n1 2\n2 3\n3 4\n4 1\n1 3\n\nSample Output 1\n\n2\n\nKen can reach Vertex 3 from Vertex 1 in two ken-ken-pa, as follows: 1 \\rightarrow 2 \\rightarrow 3 \\rightarrow 4 in the first ken-ken-pa, then 4 \\rightarrow 1 \\rightarrow 2 \\rightarrow 3 in the second ken-ken-pa. This is the minimum number of ken-ken-pa needed.\n\nSample Input 2\n\n3 3\n1 2\n2 3\n3 1\n1 2\n\nSample Output 2\n\n-1\n\nAny number of ken-ken-pa will bring Ken back to Vertex 1, so he cannot reach Vertex 2, though he can pass through it in the middle of a ken-ken-pa.\n\nSample Input 3\n\n2 0\n1 2\n\nSample Output 3\n\n-1\n\nVertex S and Vertex T may be disconnected.\n\nSample Input 4\n\n6 8\n1 2\n2 3\n3 4\n4 5\n5 1\n1 4\n1 5\n4 6\n1 6\n\nSample Output 4\n\n2", "sample_input": "4 4\n1 2\n2 3\n3 4\n4 1\n1 3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02991", "source_text": "Score : 500 points\n\nProblem Statement\n\nKen loves ken-ken-pa (Japanese version of hopscotch). Today, he will play it on a directed graph G.\nG consists of N vertices numbered 1 to N, and M edges. The i-th edge points from Vertex u_i to Vertex v_i.\n\nFirst, Ken stands on Vertex S. He wants to reach Vertex T by repeating ken-ken-pa. In one ken-ken-pa, he does the following exactly three times: follow an edge pointing from the vertex on which he is standing.\n\nDetermine if he can reach Vertex T by repeating ken-ken-pa. If the answer is yes, find the minimum number of ken-ken-pa needed to reach Vertex T. Note that visiting Vertex T in the middle of a ken-ken-pa does not count as reaching Vertex T by repeating ken-ken-pa.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n0 \\leq M \\leq \\min(10^5, N (N-1))\n\n1 \\leq u_i, v_i \\leq N(1 \\leq i \\leq M)\n\nu_i \\neq v_i (1 \\leq i \\leq M)\n\nIf i \\neq j, (u_i, v_i) \\neq (u_j, v_j).\n\n1 \\leq S, T \\leq N\n\nS \\neq T\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nu_1 v_1\n:\nu_M v_M\nS T\n\nOutput\n\nIf Ken cannot reach Vertex T from Vertex S by repeating ken-ken-pa, print -1.\nIf he can, print the minimum number of ken-ken-pa needed to reach vertex T.\n\nSample Input 1\n\n4 4\n1 2\n2 3\n3 4\n4 1\n1 3\n\nSample Output 1\n\n2\n\nKen can reach Vertex 3 from Vertex 1 in two ken-ken-pa, as follows: 1 \\rightarrow 2 \\rightarrow 3 \\rightarrow 4 in the first ken-ken-pa, then 4 \\rightarrow 1 \\rightarrow 2 \\rightarrow 3 in the second ken-ken-pa. This is the minimum number of ken-ken-pa needed.\n\nSample Input 2\n\n3 3\n1 2\n2 3\n3 1\n1 2\n\nSample Output 2\n\n-1\n\nAny number of ken-ken-pa will bring Ken back to Vertex 1, so he cannot reach Vertex 2, though he can pass through it in the middle of a ken-ken-pa.\n\nSample Input 3\n\n2 0\n1 2\n\nSample Output 3\n\n-1\n\nVertex S and Vertex T may be disconnected.\n\nSample Input 4\n\n6 8\n1 2\n2 3\n3 4\n4 5\n5 1\n1 4\n1 5\n4 6\n1 6\n\nSample Output 4\n\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4899, "cpu_time_ms": 2104, "memory_kb": 991424}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s041236756", "group_id": "codeNet:p02993", "input_text": "(let ((s (make-array 4))\n (ans \"Good\"))\n (loop for i below 4 do\n (setf (aref s i) (read-char))\n )\n (if (char= (aref s 0) (aref s 1))\n (setq ans \"Bad\")\n )\n (if (char= (aref s 1) (aref s 2))\n (setq ans \"Bad\")\n )\n (if (char= (aref s 2) (aref s 3))\n (setq ans \"Bad\")\n )\n (princ ans)\n)", "language": "Lisp", "metadata": {"date": 1596737300, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02993.html", "problem_id": "p02993", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02993/input.txt", "sample_output_relpath": "derived/input_output/data/p02993/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02993/Lisp/s041236756.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s041236756", "user_id": "u136500538"}, "prompt_components": {"gold_output": "Bad\n", "input_to_evaluate": "(let ((s (make-array 4))\n (ans \"Good\"))\n (loop for i below 4 do\n (setf (aref s i) (read-char))\n )\n (if (char= (aref s 0) (aref s 1))\n (setq ans \"Bad\")\n )\n (if (char= (aref s 1) (aref s 2))\n (setq ans \"Bad\")\n )\n (if (char= (aref s 2) (aref s 3))\n (setq ans \"Bad\")\n )\n (princ ans)\n)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThe door of Snuke's laboratory is locked with a security code.\n\nThe security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.\n\nYou are given the current security code S. If S is hard to enter, print Bad; otherwise, print Good.\n\nConstraints\n\nS is a 4-character string consisting of digits.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S is hard to enter, print Bad; otherwise, print Good.\n\nSample Input 1\n\n3776\n\nSample Output 1\n\nBad\n\nThe second and third digits are the same, so 3776 is hard to enter.\n\nSample Input 2\n\n8080\n\nSample Output 2\n\nGood\n\nThere are no two consecutive digits that are the same, so 8080 is not hard to enter.\n\nSample Input 3\n\n1333\n\nSample Output 3\n\nBad\n\nSample Input 4\n\n0024\n\nSample Output 4\n\nBad", "sample_input": "3776\n"}, "reference_outputs": ["Bad\n"], "source_document_id": "p02993", "source_text": "Score : 100 points\n\nProblem Statement\n\nThe door of Snuke's laboratory is locked with a security code.\n\nThe security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.\n\nYou are given the current security code S. If S is hard to enter, print Bad; otherwise, print Good.\n\nConstraints\n\nS is a 4-character string consisting of digits.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S is hard to enter, print Bad; otherwise, print Good.\n\nSample Input 1\n\n3776\n\nSample Output 1\n\nBad\n\nThe second and third digits are the same, so 3776 is hard to enter.\n\nSample Input 2\n\n8080\n\nSample Output 2\n\nGood\n\nThere are no two consecutive digits that are the same, so 8080 is not hard to enter.\n\nSample Input 3\n\n1333\n\nSample Output 3\n\nBad\n\nSample Input 4\n\n0024\n\nSample Output 4\n\nBad", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 338, "cpu_time_ms": 20, "memory_kb": 23508}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s139181793", "group_id": "codeNet:p02996", "input_text": "(defun solve ()\n (let* ((n (read))\n (v (make-array n :element-type '(cons fixnum fixnum))))\n (dotimes (i n)\n (setf (aref v i) (cons (read) (read))))\n (sort v (lambda (c1 c2) (> (cdr c1) (cdr c2))))\n (let ((x (cdr (aref v 0))))\n (dotimes (i n)\n (setf x (- (min x (cdr (aref v i))) (car (aref v i)))))\n (if (< x 0)\n \"No\"\n \"Yes\"))))\n(format t \"~A~%\" (solve))", "language": "Lisp", "metadata": {"date": 1573603597, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02996.html", "problem_id": "p02996", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02996/input.txt", "sample_output_relpath": "derived/input_output/data/p02996/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02996/Lisp/s139181793.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s139181793", "user_id": "u672956630"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun solve ()\n (let* ((n (read))\n (v (make-array n :element-type '(cons fixnum fixnum))))\n (dotimes (i n)\n (setf (aref v i) (cons (read) (read))))\n (sort v (lambda (c1 c2) (> (cdr c1) (cdr c2))))\n (let ((x (cdr (aref v 0))))\n (dotimes (i n)\n (setf x (- (min x (cdr (aref v i))) (car (aref v i)))))\n (if (< x 0)\n \"No\"\n \"Yes\"))))\n(format t \"~A~%\" (solve))", "problem_context": "Score: 400 points\n\nProblem Statement\n\nKizahashi, who was appointed as the administrator of ABC at National Problem Workshop in the Kingdom of AtCoder, got too excited and took on too many jobs.\n\nLet the current time be time 0. Kizahashi has N jobs numbered 1 to N.\n\nIt takes A_i units of time for Kizahashi to complete Job i. The deadline for Job i is time B_i, and he must complete the job before or at this time.\n\nKizahashi cannot work on two or more jobs simultaneously, but when he completes a job, he can start working on another immediately.\n\nCan Kizahashi complete all the jobs in time? If he can, print Yes; if he cannot, print No.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i, B_i \\leq 10^9 (1 \\leq i \\leq N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 B_1\n.\n.\n.\nA_N B_N\n\nOutput\n\nIf Kizahashi can complete all the jobs in time, print Yes; if he cannot, print No.\n\nSample Input 1\n\n5\n2 4\n1 9\n1 8\n4 9\n3 12\n\nSample Output 1\n\nYes\n\nHe can complete all the jobs in time by, for example, doing them in the following order:\n\nDo Job 2 from time 0 to 1.\n\nDo Job 1 from time 1 to 3.\n\nDo Job 4 from time 3 to 7.\n\nDo Job 3 from time 7 to 8.\n\nDo Job 5 from time 8 to 11.\n\nNote that it is fine to complete Job 3 exactly at the deadline, time 8.\n\nSample Input 2\n\n3\n334 1000\n334 1000\n334 1000\n\nSample Output 2\n\nNo\n\nHe cannot complete all the jobs in time, no matter what order he does them in.\n\nSample Input 3\n\n30\n384 8895\n1725 9791\n170 1024\n4 11105\n2 6\n578 1815\n702 3352\n143 5141\n1420 6980\n24 1602\n849 999\n76 7586\n85 5570\n444 4991\n719 11090\n470 10708\n1137 4547\n455 9003\n110 9901\n15 8578\n368 3692\n104 1286\n3 4\n366 12143\n7 6649\n610 2374\n152 7324\n4 7042\n292 11386\n334 5720\n\nSample Output 3\n\nYes", "sample_input": "5\n2 4\n1 9\n1 8\n4 9\n3 12\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02996", "source_text": "Score: 400 points\n\nProblem Statement\n\nKizahashi, who was appointed as the administrator of ABC at National Problem Workshop in the Kingdom of AtCoder, got too excited and took on too many jobs.\n\nLet the current time be time 0. Kizahashi has N jobs numbered 1 to N.\n\nIt takes A_i units of time for Kizahashi to complete Job i. The deadline for Job i is time B_i, and he must complete the job before or at this time.\n\nKizahashi cannot work on two or more jobs simultaneously, but when he completes a job, he can start working on another immediately.\n\nCan Kizahashi complete all the jobs in time? If he can, print Yes; if he cannot, print No.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i, B_i \\leq 10^9 (1 \\leq i \\leq N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 B_1\n.\n.\n.\nA_N B_N\n\nOutput\n\nIf Kizahashi can complete all the jobs in time, print Yes; if he cannot, print No.\n\nSample Input 1\n\n5\n2 4\n1 9\n1 8\n4 9\n3 12\n\nSample Output 1\n\nYes\n\nHe can complete all the jobs in time by, for example, doing them in the following order:\n\nDo Job 2 from time 0 to 1.\n\nDo Job 1 from time 1 to 3.\n\nDo Job 4 from time 3 to 7.\n\nDo Job 3 from time 7 to 8.\n\nDo Job 5 from time 8 to 11.\n\nNote that it is fine to complete Job 3 exactly at the deadline, time 8.\n\nSample Input 2\n\n3\n334 1000\n334 1000\n334 1000\n\nSample Output 2\n\nNo\n\nHe cannot complete all the jobs in time, no matter what order he does them in.\n\nSample Input 3\n\n30\n384 8895\n1725 9791\n170 1024\n4 11105\n2 6\n578 1815\n702 3352\n143 5141\n1420 6980\n24 1602\n849 999\n76 7586\n85 5570\n444 4991\n719 11090\n470 10708\n1137 4547\n455 9003\n110 9901\n15 8578\n368 3692\n104 1286\n3 4\n366 12143\n7 6649\n610 2374\n152 7324\n4 7042\n292 11386\n334 5720\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 413, "cpu_time_ms": 949, "memory_kb": 63908}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s165004118", "group_id": "codeNet:p02997", "input_text": "(let ((n (read))\n (k (read))\n (ans (list)))\n (if (> k (floor (* (1- n) (- n 2)) 2))\n (princ -1)\n (progn (dotimes (i (1- n))\n (setf ans (append ans (list (1+ i) n))))\n (loop for i from 1 upto (1- n) while (> k 0) do\n (loop for j from (1+ i) upto (1- n) while (> k 0) do\n (setf ans (append ans (list i j)))\n (decf k)))\n (format t \"~a~%~{~a ~a~%~}\" (floor (length ans) 2) ans))))\n", "language": "Lisp", "metadata": {"date": 1561296650, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02997.html", "problem_id": "p02997", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02997/input.txt", "sample_output_relpath": "derived/input_output/data/p02997/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02997/Lisp/s165004118.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s165004118", "user_id": "u994767958"}, "prompt_components": {"gold_output": "5\n4 3\n1 2\n3 1\n4 5\n2 3\n", "input_to_evaluate": "(let ((n (read))\n (k (read))\n (ans (list)))\n (if (> k (floor (* (1- n) (- n 2)) 2))\n (princ -1)\n (progn (dotimes (i (1- n))\n (setf ans (append ans (list (1+ i) n))))\n (loop for i from 1 upto (1- n) while (> k 0) do\n (loop for j from (1+ i) upto (1- n) while (> k 0) do\n (setf ans (append ans (list i j)))\n (decf k)))\n (format t \"~a~%~{~a ~a~%~}\" (floor (length ans) 2) ans))))\n", "problem_context": "Score: 500 points\n\nProblem Statement\n\nDoes there exist an undirected graph with N vertices satisfying the following conditions?\n\nThe graph is simple and connected.\n\nThe vertices are numbered 1, 2, ..., N.\n\nLet M be the number of edges in the graph. The edges are numbered 1, 2, ..., M, the length of each edge is 1, and Edge i connects Vertex u_i and Vertex v_i.\n\nThere are exactly K pairs of vertices (i,\\ j)\\ (i < j) such that the shortest distance between them is 2.\n\nIf there exists such a graph, construct an example.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 100\n\n0 \\leq K \\leq \\frac{N(N - 1)}{2}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nIf there does not exist an undirected graph with N vertices satisfying the conditions, print -1.\n\nIf there exists such a graph, print an example in the following format (refer to Problem Statement for what the symbols stand for):\n\nM\nu_1 v_1\n:\nu_M v_M\n\nIf there exist multiple graphs satisfying the conditions, any of them will be accepted.\n\nSample Input 1\n\n5 3\n\nSample Output 1\n\n5\n4 3\n1 2\n3 1\n4 5\n2 3\n\nThis graph has three pairs of vertices such that the shortest distance between them is 2: (1,\\ 4), (2,\\ 4), and (3,\\ 5). Thus, the condition is satisfied.\n\nSample Input 2\n\n5 8\n\nSample Output 2\n\n-1\n\nThere is no graph satisfying the conditions.", "sample_input": "5 3\n"}, "reference_outputs": ["5\n4 3\n1 2\n3 1\n4 5\n2 3\n"], "source_document_id": "p02997", "source_text": "Score: 500 points\n\nProblem Statement\n\nDoes there exist an undirected graph with N vertices satisfying the following conditions?\n\nThe graph is simple and connected.\n\nThe vertices are numbered 1, 2, ..., N.\n\nLet M be the number of edges in the graph. The edges are numbered 1, 2, ..., M, the length of each edge is 1, and Edge i connects Vertex u_i and Vertex v_i.\n\nThere are exactly K pairs of vertices (i,\\ j)\\ (i < j) such that the shortest distance between them is 2.\n\nIf there exists such a graph, construct an example.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 100\n\n0 \\leq K \\leq \\frac{N(N - 1)}{2}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nIf there does not exist an undirected graph with N vertices satisfying the conditions, print -1.\n\nIf there exists such a graph, print an example in the following format (refer to Problem Statement for what the symbols stand for):\n\nM\nu_1 v_1\n:\nu_M v_M\n\nIf there exist multiple graphs satisfying the conditions, any of them will be accepted.\n\nSample Input 1\n\n5 3\n\nSample Output 1\n\n5\n4 3\n1 2\n3 1\n4 5\n2 3\n\nThis graph has three pairs of vertices such that the shortest distance between them is 2: (1,\\ 4), (2,\\ 4), and (3,\\ 5). Thus, the condition is satisfied.\n\nSample Input 2\n\n5 8\n\nSample Output 2\n\n-1\n\nThere is no graph satisfying the conditions.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 502, "cpu_time_ms": 208, "memory_kb": 59876}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s366015495", "group_id": "codeNet:p02997", "input_text": "(let ((n (read))\n (k (read))\n (ans (list)))\n (if (> k (floor (* (1- n) (- n 2)) 2))\n (princ -1)\n (progn (dotimes (i (1- n))\n (setf ans (append ans (list (1+ i) n))))\n (princ ans)\n (loop for i from 1 upto (1- n) while (> k 0) do\n (loop for j from (1+ i) upto (1- n) while (> k 0) do\n (setf ans (append ans (list i j)))\n (decf k)))\n (format t \"~a~%~{~a ~a~%~}\" (floor (length ans) 2) ans))))\n", "language": "Lisp", "metadata": {"date": 1561296572, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02997.html", "problem_id": "p02997", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02997/input.txt", "sample_output_relpath": "derived/input_output/data/p02997/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02997/Lisp/s366015495.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s366015495", "user_id": "u994767958"}, "prompt_components": {"gold_output": "5\n4 3\n1 2\n3 1\n4 5\n2 3\n", "input_to_evaluate": "(let ((n (read))\n (k (read))\n (ans (list)))\n (if (> k (floor (* (1- n) (- n 2)) 2))\n (princ -1)\n (progn (dotimes (i (1- n))\n (setf ans (append ans (list (1+ i) n))))\n (princ ans)\n (loop for i from 1 upto (1- n) while (> k 0) do\n (loop for j from (1+ i) upto (1- n) while (> k 0) do\n (setf ans (append ans (list i j)))\n (decf k)))\n (format t \"~a~%~{~a ~a~%~}\" (floor (length ans) 2) ans))))\n", "problem_context": "Score: 500 points\n\nProblem Statement\n\nDoes there exist an undirected graph with N vertices satisfying the following conditions?\n\nThe graph is simple and connected.\n\nThe vertices are numbered 1, 2, ..., N.\n\nLet M be the number of edges in the graph. The edges are numbered 1, 2, ..., M, the length of each edge is 1, and Edge i connects Vertex u_i and Vertex v_i.\n\nThere are exactly K pairs of vertices (i,\\ j)\\ (i < j) such that the shortest distance between them is 2.\n\nIf there exists such a graph, construct an example.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 100\n\n0 \\leq K \\leq \\frac{N(N - 1)}{2}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nIf there does not exist an undirected graph with N vertices satisfying the conditions, print -1.\n\nIf there exists such a graph, print an example in the following format (refer to Problem Statement for what the symbols stand for):\n\nM\nu_1 v_1\n:\nu_M v_M\n\nIf there exist multiple graphs satisfying the conditions, any of them will be accepted.\n\nSample Input 1\n\n5 3\n\nSample Output 1\n\n5\n4 3\n1 2\n3 1\n4 5\n2 3\n\nThis graph has three pairs of vertices such that the shortest distance between them is 2: (1,\\ 4), (2,\\ 4), and (3,\\ 5). Thus, the condition is satisfied.\n\nSample Input 2\n\n5 8\n\nSample Output 2\n\n-1\n\nThere is no graph satisfying the conditions.", "sample_input": "5 3\n"}, "reference_outputs": ["5\n4 3\n1 2\n3 1\n4 5\n2 3\n"], "source_document_id": "p02997", "source_text": "Score: 500 points\n\nProblem Statement\n\nDoes there exist an undirected graph with N vertices satisfying the following conditions?\n\nThe graph is simple and connected.\n\nThe vertices are numbered 1, 2, ..., N.\n\nLet M be the number of edges in the graph. The edges are numbered 1, 2, ..., M, the length of each edge is 1, and Edge i connects Vertex u_i and Vertex v_i.\n\nThere are exactly K pairs of vertices (i,\\ j)\\ (i < j) such that the shortest distance between them is 2.\n\nIf there exists such a graph, construct an example.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 100\n\n0 \\leq K \\leq \\frac{N(N - 1)}{2}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nIf there does not exist an undirected graph with N vertices satisfying the conditions, print -1.\n\nIf there exists such a graph, print an example in the following format (refer to Problem Statement for what the symbols stand for):\n\nM\nu_1 v_1\n:\nu_M v_M\n\nIf there exist multiple graphs satisfying the conditions, any of them will be accepted.\n\nSample Input 1\n\n5 3\n\nSample Output 1\n\n5\n4 3\n1 2\n3 1\n4 5\n2 3\n\nThis graph has three pairs of vertices such that the shortest distance between them is 2: (1,\\ 4), (2,\\ 4), and (3,\\ 5). Thus, the condition is satisfied.\n\nSample Input 2\n\n5 8\n\nSample Output 2\n\n-1\n\nThere is no graph satisfying the conditions.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 527, "cpu_time_ms": 205, "memory_kb": 59876}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s712945728", "group_id": "codeNet:p02999", "input_text": "(setq x (read) a (read))\n(if (>= x a) (princ 10) (princ 0))", "language": "Lisp", "metadata": {"date": 1563226328, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02999.html", "problem_id": "p02999", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02999/input.txt", "sample_output_relpath": "derived/input_output/data/p02999/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02999/Lisp/s712945728.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s712945728", "user_id": "u480300350"}, "prompt_components": {"gold_output": "0\n", "input_to_evaluate": "(setq x (read) a (read))\n(if (>= x a) (princ 10) (princ 0))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nX and A are integers between 0 and 9 (inclusive).\n\nIf X is less than A, print 0; if X is not less than A, print 10.\n\nConstraints\n\n0 \\leq X, A \\leq 9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX A\n\nOutput\n\nIf X is less than A, print 0; if X is not less than A, print 10.\n\nSample Input 1\n\n3 5\n\nSample Output 1\n\n0\n\n3 is less than 5, so we should print 0.\n\nSample Input 2\n\n7 5\n\nSample Output 2\n\n10\n\n7 is not less than 5, so we should print 10.\n\nSample Input 3\n\n6 6\n\nSample Output 3\n\n10\n\n6 is not less than 6, so we should print 10.", "sample_input": "3 5\n"}, "reference_outputs": ["0\n"], "source_document_id": "p02999", "source_text": "Score : 100 points\n\nProblem Statement\n\nX and A are integers between 0 and 9 (inclusive).\n\nIf X is less than A, print 0; if X is not less than A, print 10.\n\nConstraints\n\n0 \\leq X, A \\leq 9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX A\n\nOutput\n\nIf X is less than A, print 0; if X is not less than A, print 10.\n\nSample Input 1\n\n3 5\n\nSample Output 1\n\n0\n\n3 is less than 5, so we should print 0.\n\nSample Input 2\n\n7 5\n\nSample Output 2\n\n10\n\n7 is not less than 5, so we should print 10.\n\nSample Input 3\n\n6 6\n\nSample Output 3\n\n10\n\n6 is not less than 6, so we should print 10.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 59, "cpu_time_ms": 76, "memory_kb": 8676}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s502919623", "group_id": "codeNet:p02999", "input_text": " (format t \"~A~%\" (if (< (read)(read)) 0 10))", "language": "Lisp", "metadata": {"date": 1561164983, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02999.html", "problem_id": "p02999", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02999/input.txt", "sample_output_relpath": "derived/input_output/data/p02999/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02999/Lisp/s502919623.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s502919623", "user_id": "u794246018"}, "prompt_components": {"gold_output": "0\n", "input_to_evaluate": " (format t \"~A~%\" (if (< (read)(read)) 0 10))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nX and A are integers between 0 and 9 (inclusive).\n\nIf X is less than A, print 0; if X is not less than A, print 10.\n\nConstraints\n\n0 \\leq X, A \\leq 9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX A\n\nOutput\n\nIf X is less than A, print 0; if X is not less than A, print 10.\n\nSample Input 1\n\n3 5\n\nSample Output 1\n\n0\n\n3 is less than 5, so we should print 0.\n\nSample Input 2\n\n7 5\n\nSample Output 2\n\n10\n\n7 is not less than 5, so we should print 10.\n\nSample Input 3\n\n6 6\n\nSample Output 3\n\n10\n\n6 is not less than 6, so we should print 10.", "sample_input": "3 5\n"}, "reference_outputs": ["0\n"], "source_document_id": "p02999", "source_text": "Score : 100 points\n\nProblem Statement\n\nX and A are integers between 0 and 9 (inclusive).\n\nIf X is less than A, print 0; if X is not less than A, print 10.\n\nConstraints\n\n0 \\leq X, A \\leq 9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX A\n\nOutput\n\nIf X is less than A, print 0; if X is not less than A, print 10.\n\nSample Input 1\n\n3 5\n\nSample Output 1\n\n0\n\n3 is less than 5, so we should print 0.\n\nSample Input 2\n\n7 5\n\nSample Output 2\n\n10\n\n7 is not less than 5, so we should print 10.\n\nSample Input 3\n\n6 6\n\nSample Output 3\n\n10\n\n6 is not less than 6, so we should print 10.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 45, "cpu_time_ms": 20, "memory_kb": 3812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s256206742", "group_id": "codeNet:p02999", "input_text": "(let ((x (read)) (y (read))) (princ (if (< x y) 0 10)))", "language": "Lisp", "metadata": {"date": 1560714549, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02999.html", "problem_id": "p02999", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02999/input.txt", "sample_output_relpath": "derived/input_output/data/p02999/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02999/Lisp/s256206742.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s256206742", "user_id": "u100932207"}, "prompt_components": {"gold_output": "0\n", "input_to_evaluate": "(let ((x (read)) (y (read))) (princ (if (< x y) 0 10)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nX and A are integers between 0 and 9 (inclusive).\n\nIf X is less than A, print 0; if X is not less than A, print 10.\n\nConstraints\n\n0 \\leq X, A \\leq 9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX A\n\nOutput\n\nIf X is less than A, print 0; if X is not less than A, print 10.\n\nSample Input 1\n\n3 5\n\nSample Output 1\n\n0\n\n3 is less than 5, so we should print 0.\n\nSample Input 2\n\n7 5\n\nSample Output 2\n\n10\n\n7 is not less than 5, so we should print 10.\n\nSample Input 3\n\n6 6\n\nSample Output 3\n\n10\n\n6 is not less than 6, so we should print 10.", "sample_input": "3 5\n"}, "reference_outputs": ["0\n"], "source_document_id": "p02999", "source_text": "Score : 100 points\n\nProblem Statement\n\nX and A are integers between 0 and 9 (inclusive).\n\nIf X is less than A, print 0; if X is not less than A, print 10.\n\nConstraints\n\n0 \\leq X, A \\leq 9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX A\n\nOutput\n\nIf X is less than A, print 0; if X is not less than A, print 10.\n\nSample Input 1\n\n3 5\n\nSample Output 1\n\n0\n\n3 is less than 5, so we should print 0.\n\nSample Input 2\n\n7 5\n\nSample Output 2\n\n10\n\n7 is not less than 5, so we should print 10.\n\nSample Input 3\n\n6 6\n\nSample Output 3\n\n10\n\n6 is not less than 6, so we should print 10.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 55, "cpu_time_ms": 85, "memory_kb": 8936}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s470625348", "group_id": "codeNet:p03000", "input_text": "\n(defun rec (acc lst x i)\n (if (<= acc x)\n\t(if (null lst)\n\t i\n\t(rec (+ acc (car lst)) (cdr lst) x (1+ i)))\n\t(1- i)))\n(compile 'rec)\n(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(let* ((line0 (read-line nil nil))\n\t (splited0 (mapcar #'parse-integer (splitat #\\space line0)))\n\t (line1 (read-line nil nil))\n\t (splited1 (mapcar #'parse-integer (splitat #\\space line1)))\n\t )\n (format t \"~A~%\" (rec 0 splited1 (cadr splited0) 1)))\n", "language": "Lisp", "metadata": {"date": 1560715100, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03000.html", "problem_id": "p03000", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03000/input.txt", "sample_output_relpath": "derived/input_output/data/p03000/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03000/Lisp/s470625348.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s470625348", "user_id": "u254205055"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "\n(defun rec (acc lst x i)\n (if (<= acc x)\n\t(if (null lst)\n\t i\n\t(rec (+ acc (car lst)) (cdr lst) x (1+ i)))\n\t(1- i)))\n(compile 'rec)\n(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(let* ((line0 (read-line nil nil))\n\t (splited0 (mapcar #'parse-integer (splitat #\\space line0)))\n\t (line1 (read-line nil nil))\n\t (splited1 (mapcar #'parse-integer (splitat #\\space line1)))\n\t )\n (format t \"~A~%\" (rec 0 splited1 (cadr splited0) 1)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nA ball will bounce along a number line, making N + 1 bounces. It will make the first bounce at coordinate D_1 = 0, and the i-th bounce (2 \\leq i \\leq N+1) at coordinate D_i = D_{i-1} + L_{i-1}.\n\nHow many times will the ball make a bounce where the coordinate is at most X?\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq L_i \\leq 100\n\n1 \\leq X \\leq 10000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X\nL_1 L_2 ... L_{N-1} L_N\n\nOutput\n\nPrint the number of times the ball will make a bounce where the coordinate is at most X.\n\nSample Input 1\n\n3 6\n3 4 5\n\nSample Output 1\n\n2\n\nThe ball will make a bounce at the coordinates 0, 3, 7 and 12, among which two are less than or equal to 6.\n\nSample Input 2\n\n4 9\n3 3 3 3\n\nSample Output 2\n\n4\n\nThe ball will make a bounce at the coordinates 0, 3, 6, 9 and 12, among which four are less than or equal to 9.", "sample_input": "3 6\n3 4 5\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03000", "source_text": "Score : 200 points\n\nProblem Statement\n\nA ball will bounce along a number line, making N + 1 bounces. It will make the first bounce at coordinate D_1 = 0, and the i-th bounce (2 \\leq i \\leq N+1) at coordinate D_i = D_{i-1} + L_{i-1}.\n\nHow many times will the ball make a bounce where the coordinate is at most X?\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq L_i \\leq 100\n\n1 \\leq X \\leq 10000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X\nL_1 L_2 ... L_{N-1} L_N\n\nOutput\n\nPrint the number of times the ball will make a bounce where the coordinate is at most X.\n\nSample Input 1\n\n3 6\n3 4 5\n\nSample Output 1\n\n2\n\nThe ball will make a bounce at the coordinates 0, 3, 7 and 12, among which two are less than or equal to 6.\n\nSample Input 2\n\n4 9\n3 3 3 3\n\nSample Output 2\n\n4\n\nThe ball will make a bounce at the coordinates 0, 3, 6, 9 and 12, among which four are less than or equal to 9.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 639, "cpu_time_ms": 130, "memory_kb": 15716}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s891090947", "group_id": "codeNet:p03000", "input_text": "\n(defun rec (acc lst x i)\n (if (null lst)\n\ti\n (if (<= acc x)\n\t(rec (+ acc (car lst)) (cdr lst) x (1+ i))\n\t(1- i))))\n(compile 'rec)\n(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(let* ((line0 (read-line nil nil))\n\t (splited0 (mapcar #'parse-integer (splitat #\\space line0)))\n\t (line1 (read-line nil nil))\n\t (splited1 (mapcar #'parse-integer (splitat #\\space line1)))\n\t )\n (format t \"~A~%\" (rec 0 splited1 (cadr splited0) 1)))\n\n", "language": "Lisp", "metadata": {"date": 1560714981, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03000.html", "problem_id": "p03000", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03000/input.txt", "sample_output_relpath": "derived/input_output/data/p03000/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03000/Lisp/s891090947.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s891090947", "user_id": "u254205055"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "\n(defun rec (acc lst x i)\n (if (null lst)\n\ti\n (if (<= acc x)\n\t(rec (+ acc (car lst)) (cdr lst) x (1+ i))\n\t(1- i))))\n(compile 'rec)\n(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(let* ((line0 (read-line nil nil))\n\t (splited0 (mapcar #'parse-integer (splitat #\\space line0)))\n\t (line1 (read-line nil nil))\n\t (splited1 (mapcar #'parse-integer (splitat #\\space line1)))\n\t )\n (format t \"~A~%\" (rec 0 splited1 (cadr splited0) 1)))\n\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nA ball will bounce along a number line, making N + 1 bounces. It will make the first bounce at coordinate D_1 = 0, and the i-th bounce (2 \\leq i \\leq N+1) at coordinate D_i = D_{i-1} + L_{i-1}.\n\nHow many times will the ball make a bounce where the coordinate is at most X?\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq L_i \\leq 100\n\n1 \\leq X \\leq 10000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X\nL_1 L_2 ... L_{N-1} L_N\n\nOutput\n\nPrint the number of times the ball will make a bounce where the coordinate is at most X.\n\nSample Input 1\n\n3 6\n3 4 5\n\nSample Output 1\n\n2\n\nThe ball will make a bounce at the coordinates 0, 3, 7 and 12, among which two are less than or equal to 6.\n\nSample Input 2\n\n4 9\n3 3 3 3\n\nSample Output 2\n\n4\n\nThe ball will make a bounce at the coordinates 0, 3, 6, 9 and 12, among which four are less than or equal to 9.", "sample_input": "3 6\n3 4 5\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03000", "source_text": "Score : 200 points\n\nProblem Statement\n\nA ball will bounce along a number line, making N + 1 bounces. It will make the first bounce at coordinate D_1 = 0, and the i-th bounce (2 \\leq i \\leq N+1) at coordinate D_i = D_{i-1} + L_{i-1}.\n\nHow many times will the ball make a bounce where the coordinate is at most X?\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq L_i \\leq 100\n\n1 \\leq X \\leq 10000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X\nL_1 L_2 ... L_{N-1} L_N\n\nOutput\n\nPrint the number of times the ball will make a bounce where the coordinate is at most X.\n\nSample Input 1\n\n3 6\n3 4 5\n\nSample Output 1\n\n2\n\nThe ball will make a bounce at the coordinates 0, 3, 7 and 12, among which two are less than or equal to 6.\n\nSample Input 2\n\n4 9\n3 3 3 3\n\nSample Output 2\n\n4\n\nThe ball will make a bounce at the coordinates 0, 3, 6, 9 and 12, among which four are less than or equal to 9.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 639, "cpu_time_ms": 123, "memory_kb": 15716}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s921219074", "group_id": "codeNet:p03000", "input_text": "\n(defun rec (acc lst x i)\n (if (<= acc x)\n\t(rec (+ acc (car lst)) (cdr lst) x (1+ i))\n\t(1- i)))\n(compile 'rec)\n(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(let* ((line0 (read-line nil nil))\n\t (splited0 (mapcar #'parse-integer (splitat #\\space line0)))\n\t (line1 (read-line nil nil))\n\t (splited1 (mapcar #'parse-integer (splitat #\\space line1)))\n\t )\n (format t \"~A~%\" (rec 0 splited1 (cadr splited0) 1)))\n", "language": "Lisp", "metadata": {"date": 1560714761, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03000.html", "problem_id": "p03000", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03000/input.txt", "sample_output_relpath": "derived/input_output/data/p03000/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03000/Lisp/s921219074.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s921219074", "user_id": "u254205055"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "\n(defun rec (acc lst x i)\n (if (<= acc x)\n\t(rec (+ acc (car lst)) (cdr lst) x (1+ i))\n\t(1- i)))\n(compile 'rec)\n(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(let* ((line0 (read-line nil nil))\n\t (splited0 (mapcar #'parse-integer (splitat #\\space line0)))\n\t (line1 (read-line nil nil))\n\t (splited1 (mapcar #'parse-integer (splitat #\\space line1)))\n\t )\n (format t \"~A~%\" (rec 0 splited1 (cadr splited0) 1)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nA ball will bounce along a number line, making N + 1 bounces. It will make the first bounce at coordinate D_1 = 0, and the i-th bounce (2 \\leq i \\leq N+1) at coordinate D_i = D_{i-1} + L_{i-1}.\n\nHow many times will the ball make a bounce where the coordinate is at most X?\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq L_i \\leq 100\n\n1 \\leq X \\leq 10000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X\nL_1 L_2 ... L_{N-1} L_N\n\nOutput\n\nPrint the number of times the ball will make a bounce where the coordinate is at most X.\n\nSample Input 1\n\n3 6\n3 4 5\n\nSample Output 1\n\n2\n\nThe ball will make a bounce at the coordinates 0, 3, 7 and 12, among which two are less than or equal to 6.\n\nSample Input 2\n\n4 9\n3 3 3 3\n\nSample Output 2\n\n4\n\nThe ball will make a bounce at the coordinates 0, 3, 6, 9 and 12, among which four are less than or equal to 9.", "sample_input": "3 6\n3 4 5\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03000", "source_text": "Score : 200 points\n\nProblem Statement\n\nA ball will bounce along a number line, making N + 1 bounces. It will make the first bounce at coordinate D_1 = 0, and the i-th bounce (2 \\leq i \\leq N+1) at coordinate D_i = D_{i-1} + L_{i-1}.\n\nHow many times will the ball make a bounce where the coordinate is at most X?\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq L_i \\leq 100\n\n1 \\leq X \\leq 10000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X\nL_1 L_2 ... L_{N-1} L_N\n\nOutput\n\nPrint the number of times the ball will make a bounce where the coordinate is at most X.\n\nSample Input 1\n\n3 6\n3 4 5\n\nSample Output 1\n\n2\n\nThe ball will make a bounce at the coordinates 0, 3, 7 and 12, among which two are less than or equal to 6.\n\nSample Input 2\n\n4 9\n3 3 3 3\n\nSample Output 2\n\n4\n\nThe ball will make a bounce at the coordinates 0, 3, 6, 9 and 12, among which four are less than or equal to 9.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 617, "cpu_time_ms": 125, "memory_kb": 15588}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s918458821", "group_id": "codeNet:p03001", "input_text": "(defmacro defsolver (name vars &body body)\n `(defun ,name ()\n (let (,@(mapcar #'list\n vars\n (mapcar (constantly '(read))\n vars)))\n ,@body)))\n\n(defsolver solution-c (w h x y)\n (let ((gx (/ w 2))\n\t(gy (/ h 2)))\n (format t \"~,6F ~:[0~;1~]\"\n\t (/ (* w h) 2)\n\t (and (= gx x) (= gy y)))))\n\n(solution-c)", "language": "Lisp", "metadata": {"date": 1560719979, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03001.html", "problem_id": "p03001", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03001/input.txt", "sample_output_relpath": "derived/input_output/data/p03001/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03001/Lisp/s918458821.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s918458821", "user_id": "u100932207"}, "prompt_components": {"gold_output": "3.000000 0\n", "input_to_evaluate": "(defmacro defsolver (name vars &body body)\n `(defun ,name ()\n (let (,@(mapcar #'list\n vars\n (mapcar (constantly '(read))\n vars)))\n ,@body)))\n\n(defsolver solution-c (w h x y)\n (let ((gx (/ w 2))\n\t(gy (/ h 2)))\n (format t \"~,6F ~:[0~;1~]\"\n\t (/ (* w h) 2)\n\t (and (= gx x) (= gy y)))))\n\n(solution-c)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H).\nYou are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.\n\nConstraints\n\n1 \\leq W,H \\leq 10^9\n\n0\\leq x\\leq W\n\n0\\leq y\\leq H\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nW H x y\n\nOutput\n\nPrint the maximum possible area of the part whose area is not larger than that of the other, followed by 1 if there are multiple ways to cut the rectangle and achieve that maximum, and 0 otherwise.\n\nThe area printed will be judged correct when its absolute or relative error is at most 10^{-9}.\n\nSample Input 1\n\n2 3 1 2\n\nSample Output 1\n\n3.000000 0\n\nThe line x=1 gives the optimal cut, and no other line does.\n\nSample Input 2\n\n2 2 1 1\n\nSample Output 2\n\n2.000000 1", "sample_input": "2 3 1 2\n"}, "reference_outputs": ["3.000000 0\n"], "source_document_id": "p03001", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H).\nYou are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.\n\nConstraints\n\n1 \\leq W,H \\leq 10^9\n\n0\\leq x\\leq W\n\n0\\leq y\\leq H\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nW H x y\n\nOutput\n\nPrint the maximum possible area of the part whose area is not larger than that of the other, followed by 1 if there are multiple ways to cut the rectangle and achieve that maximum, and 0 otherwise.\n\nThe area printed will be judged correct when its absolute or relative error is at most 10^{-9}.\n\nSample Input 1\n\n2 3 1 2\n\nSample Output 1\n\n3.000000 0\n\nThe line x=1 gives the optimal cut, and no other line does.\n\nSample Input 2\n\n2 2 1 1\n\nSample Output 2\n\n2.000000 1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 353, "cpu_time_ms": 126, "memory_kb": 12900}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s717522304", "group_id": "codeNet:p03001", "input_text": "(defun computearea(w h x y)\n (let* ((splith0 (* w (- h y)))\n\t\t (splith1 (- (* w h) splith0))\n\t\t (splitv0 (* (- w x) h))\n\t\t (splitv1 (- (* w h) splitv0))\n\t\t (splith (if (< splith0 splith1) splith0 splith1))\n\t\t (splitv (if (< splitv0 splitv1) splitv0 splitv1)))\n\t(if (= splith splitv)\n\t (list splith 1)\n\t (if (< splith splitv)\n\t\t(list splitv 0)\n\t\t(list splith 0)))))\n\n(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(let* (( line (read-line nil nil))\n\t (splited (mapcar #'parse-integer (splitat #\\space line))))\n (let ((result (computearea (car splited) (cadr splited) (caddr splited) (cadddr splited))))\n\t(format t \"~D ~D\" (car result) (cadr result))))\n\n", "language": "Lisp", "metadata": {"date": 1560715586, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03001.html", "problem_id": "p03001", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03001/input.txt", "sample_output_relpath": "derived/input_output/data/p03001/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03001/Lisp/s717522304.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s717522304", "user_id": "u254205055"}, "prompt_components": {"gold_output": "3.000000 0\n", "input_to_evaluate": "(defun computearea(w h x y)\n (let* ((splith0 (* w (- h y)))\n\t\t (splith1 (- (* w h) splith0))\n\t\t (splitv0 (* (- w x) h))\n\t\t (splitv1 (- (* w h) splitv0))\n\t\t (splith (if (< splith0 splith1) splith0 splith1))\n\t\t (splitv (if (< splitv0 splitv1) splitv0 splitv1)))\n\t(if (= splith splitv)\n\t (list splith 1)\n\t (if (< splith splitv)\n\t\t(list splitv 0)\n\t\t(list splith 0)))))\n\n(defun splitat (c line)\n (labels ((rec (line acc)\n\t\t\t\t(let ((pos (position-if (lambda(cc) (char= c cc)) line)))\n\t\t\t\t (if pos\n\t\t\t\t\t (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))\n\t\t\t\t\t(nreverse (cons line acc))))))\n\t(rec line nil)))\n(let* (( line (read-line nil nil))\n\t (splited (mapcar #'parse-integer (splitat #\\space line))))\n (let ((result (computearea (car splited) (cadr splited) (caddr splited) (cadddr splited))))\n\t(format t \"~D ~D\" (car result) (cadr result))))\n\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H).\nYou are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.\n\nConstraints\n\n1 \\leq W,H \\leq 10^9\n\n0\\leq x\\leq W\n\n0\\leq y\\leq H\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nW H x y\n\nOutput\n\nPrint the maximum possible area of the part whose area is not larger than that of the other, followed by 1 if there are multiple ways to cut the rectangle and achieve that maximum, and 0 otherwise.\n\nThe area printed will be judged correct when its absolute or relative error is at most 10^{-9}.\n\nSample Input 1\n\n2 3 1 2\n\nSample Output 1\n\n3.000000 0\n\nThe line x=1 gives the optimal cut, and no other line does.\n\nSample Input 2\n\n2 2 1 1\n\nSample Output 2\n\n2.000000 1", "sample_input": "2 3 1 2\n"}, "reference_outputs": ["3.000000 0\n"], "source_document_id": "p03001", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H).\nYou are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.\n\nConstraints\n\n1 \\leq W,H \\leq 10^9\n\n0\\leq x\\leq W\n\n0\\leq y\\leq H\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nW H x y\n\nOutput\n\nPrint the maximum possible area of the part whose area is not larger than that of the other, followed by 1 if there are multiple ways to cut the rectangle and achieve that maximum, and 0 otherwise.\n\nThe area printed will be judged correct when its absolute or relative error is at most 10^{-9}.\n\nSample Input 1\n\n2 3 1 2\n\nSample Output 1\n\n3.000000 0\n\nThe line x=1 gives the optimal cut, and no other line does.\n\nSample Input 2\n\n2 2 1 1\n\nSample Output 2\n\n2.000000 1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 859, "cpu_time_ms": 142, "memory_kb": 15464}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s651490125", "group_id": "codeNet:p03006", "input_text": "(let* ((n (read))\n (lst (loop :repeat n :collect (cons (read) (read))))\n (lst-a nil)\n (pp nil)\n (p nil)\n (stk (cons 0 0)))\n (if (cdr lst)\n (progn\n (setf lst-a (mapcar (lambda (x y)\n (cons (- (car x) (car y)) (- (cdr x) (cdr y)))) lst (cdr lst)))\n (setf pp (mapcar (lambda (k)\n (cons k (count k lst-a))) lst-a))\n (setf p (car (find (reduce #'max pp :key #'cdr) pp :key #'cdr)))\n (princ\n (loop :for x :in (reverse lst) :summing (prog1\n (if (equal p\n (cons (- (car x) (car stk))\n (- (cdr x) (cdr stk))))\n 0 1)\n (setf stk x))))\n )\n )\n )", "language": "Lisp", "metadata": {"date": 1560650639, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03006.html", "problem_id": "p03006", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03006/input.txt", "sample_output_relpath": "derived/input_output/data/p03006/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03006/Lisp/s651490125.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s651490125", "user_id": "u610490393"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let* ((n (read))\n (lst (loop :repeat n :collect (cons (read) (read))))\n (lst-a nil)\n (pp nil)\n (p nil)\n (stk (cons 0 0)))\n (if (cdr lst)\n (progn\n (setf lst-a (mapcar (lambda (x y)\n (cons (- (car x) (car y)) (- (cdr x) (cdr y)))) lst (cdr lst)))\n (setf pp (mapcar (lambda (k)\n (cons k (count k lst-a))) lst-a))\n (setf p (car (find (reduce #'max pp :key #'cdr) pp :key #'cdr)))\n (princ\n (loop :for x :in (reverse lst) :summing (prog1\n (if (equal p\n (cons (- (car x) (car stk))\n (- (cdr x) (cdr stk))))\n 0 1)\n (setf stk x))))\n )\n )\n )", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i).\n\nWe will collect all of these balls, by choosing two integers p and q such that p \\neq 0 or q \\neq 0 and then repeating the following operation:\n\nChoose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1.\n\nFind the minimum total cost required to collect all the balls when we optimally choose p and q.\n\nConstraints\n\n1 \\leq N \\leq 50\n\n|x_i|, |y_i| \\leq 10^9\n\nIf i \\neq j, x_i \\neq x_j or y_i \\neq y_j.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\n:\nx_N y_N\n\nOutput\n\nPrint the minimum total cost required to collect all the balls.\n\nSample Input 1\n\n2\n1 1\n2 2\n\nSample Output 1\n\n1\n\nIf we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by collecting them in the order (1, 1), (2, 2).\n\nSample Input 2\n\n3\n1 4\n4 6\n7 8\n\nSample Output 2\n\n1\n\nIf we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by collecting them in the order (7, 8), (4, 6), (1, 4).\n\nSample Input 3\n\n4\n1 1\n1 2\n2 1\n2 2\n\nSample Output 3\n\n2", "sample_input": "2\n1 1\n2 2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03006", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i).\n\nWe will collect all of these balls, by choosing two integers p and q such that p \\neq 0 or q \\neq 0 and then repeating the following operation:\n\nChoose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1.\n\nFind the minimum total cost required to collect all the balls when we optimally choose p and q.\n\nConstraints\n\n1 \\leq N \\leq 50\n\n|x_i|, |y_i| \\leq 10^9\n\nIf i \\neq j, x_i \\neq x_j or y_i \\neq y_j.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\n:\nx_N y_N\n\nOutput\n\nPrint the minimum total cost required to collect all the balls.\n\nSample Input 1\n\n2\n1 1\n2 2\n\nSample Output 1\n\n1\n\nIf we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by collecting them in the order (1, 1), (2, 2).\n\nSample Input 2\n\n3\n1 4\n4 6\n7 8\n\nSample Output 2\n\n1\n\nIf we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by collecting them in the order (7, 8), (4, 6), (1, 4).\n\nSample Input 3\n\n4\n1 1\n1 2\n2 1\n2 2\n\nSample Output 3\n\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 962, "cpu_time_ms": 162, "memory_kb": 16104}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s641785928", "group_id": "codeNet:p03006", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (xs (make-array n :element-type 'int32))\n (ys (make-array n :element-type 'int32))\n (res n))\n (labels ((calc-cost (p q)\n (if (= p q 0)\n most-positive-fixnum\n (let ((table (make-array n :element-type 'bit :initial-element 1)))\n (dotimes (i1 n)\n (dotimes (i2 n)\n (when (and (= p (- (aref xs i2) (aref xs i1)))\n (= q (- (aref ys i2) (aref ys i1))))\n (setf (aref table i2) 0))))\n (count 1 table)))))\n (dotimes (i n)\n (setf (aref xs i) (read) (aref ys i) (read)))\n (dotimes (i1 n)\n (dotimes (i2 n)\n (let ((p (- (aref xs i2) (aref xs i1)))\n (q (- (aref ys i2) (aref ys i1))))\n (setf res (min res (calc-cost p q))))))\n (println res))))\n\n#-swank(main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &optional (func #'main))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNC, and checks the string\noutput to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (and (> (length s) 0)\n (eql (char s (- (length s) 1)) #\\Linefeed))\n s\n (uiop:strcat s uiop:+lf+))))\n (equal (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall func)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n (let ((*standard-output* out))\n (etypecase thing\n (null ; Runs #'MAIN with the string on clipboard\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname ; Runs #'MAIN with the string in a text file\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 1\n2 2\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 4\n4 6\n7 8\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 1\n1 2\n2 1\n2 2\n\"\n \"2\n\")))\n", "language": "Lisp", "metadata": {"date": 1560647636, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03006.html", "problem_id": "p03006", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03006/input.txt", "sample_output_relpath": "derived/input_output/data/p03006/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03006/Lisp/s641785928.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s641785928", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (xs (make-array n :element-type 'int32))\n (ys (make-array n :element-type 'int32))\n (res n))\n (labels ((calc-cost (p q)\n (if (= p q 0)\n most-positive-fixnum\n (let ((table (make-array n :element-type 'bit :initial-element 1)))\n (dotimes (i1 n)\n (dotimes (i2 n)\n (when (and (= p (- (aref xs i2) (aref xs i1)))\n (= q (- (aref ys i2) (aref ys i1))))\n (setf (aref table i2) 0))))\n (count 1 table)))))\n (dotimes (i n)\n (setf (aref xs i) (read) (aref ys i) (read)))\n (dotimes (i1 n)\n (dotimes (i2 n)\n (let ((p (- (aref xs i2) (aref xs i1)))\n (q (- (aref ys i2) (aref ys i1))))\n (setf res (min res (calc-cost p q))))))\n (println res))))\n\n#-swank(main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &optional (func #'main))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNC, and checks the string\noutput to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (and (> (length s) 0)\n (eql (char s (- (length s) 1)) #\\Linefeed))\n s\n (uiop:strcat s uiop:+lf+))))\n (equal (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall func)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n (let ((*standard-output* out))\n (etypecase thing\n (null ; Runs #'MAIN with the string on clipboard\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname ; Runs #'MAIN with the string in a text file\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 1\n2 2\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 4\n4 6\n7 8\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 1\n1 2\n2 1\n2 2\n\"\n \"2\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i).\n\nWe will collect all of these balls, by choosing two integers p and q such that p \\neq 0 or q \\neq 0 and then repeating the following operation:\n\nChoose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1.\n\nFind the minimum total cost required to collect all the balls when we optimally choose p and q.\n\nConstraints\n\n1 \\leq N \\leq 50\n\n|x_i|, |y_i| \\leq 10^9\n\nIf i \\neq j, x_i \\neq x_j or y_i \\neq y_j.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\n:\nx_N y_N\n\nOutput\n\nPrint the minimum total cost required to collect all the balls.\n\nSample Input 1\n\n2\n1 1\n2 2\n\nSample Output 1\n\n1\n\nIf we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by collecting them in the order (1, 1), (2, 2).\n\nSample Input 2\n\n3\n1 4\n4 6\n7 8\n\nSample Output 2\n\n1\n\nIf we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by collecting them in the order (7, 8), (4, 6), (1, 4).\n\nSample Input 3\n\n4\n1 1\n1 2\n2 1\n2 2\n\nSample Output 3\n\n2", "sample_input": "2\n1 1\n2 2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03006", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i).\n\nWe will collect all of these balls, by choosing two integers p and q such that p \\neq 0 or q \\neq 0 and then repeating the following operation:\n\nChoose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1.\n\nFind the minimum total cost required to collect all the balls when we optimally choose p and q.\n\nConstraints\n\n1 \\leq N \\leq 50\n\n|x_i|, |y_i| \\leq 10^9\n\nIf i \\neq j, x_i \\neq x_j or y_i \\neq y_j.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\n:\nx_N y_N\n\nOutput\n\nPrint the minimum total cost required to collect all the balls.\n\nSample Input 1\n\n2\n1 1\n2 2\n\nSample Output 1\n\n1\n\nIf we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by collecting them in the order (1, 1), (2, 2).\n\nSample Input 2\n\n3\n1 4\n4 6\n7 8\n\nSample Output 2\n\n1\n\nIf we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by collecting them in the order (7, 8), (4, 6), (1, 4).\n\nSample Input 3\n\n4\n1 1\n1 2\n2 1\n2 2\n\nSample Output 3\n\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4307, "cpu_time_ms": 225, "memory_kb": 24296}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s709151694", "group_id": "codeNet:p03007", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defun bisect-left (target value &key (start 0) end (predicate #'<) (key #'identity))\n \"TARGET := vector | function\nPREDICATE := strict order\n\nReturns the smallest index (or input) i that fulfills TARGET[i] >= VALUE, where\n'>=' is the complement of PREDICATE. TARGET must be monotonically non-decreasing with\nrespect to PREDICATE. This function returns END if VALUE exceeds TARGET[END-1]. Note\nthat the range [START, END) is half-open. END must be explicitly specified if\nTARGET is function. KEY is applied to each element of TARGET before comparison.\"\n (declare (function key predicate)\n ((integer 0 #.most-positive-fixnum) start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (macrolet\n ((body (accessor &optional declaration)\n `(cond ((assert (<= start end)))\n ((= start end) end)\n ((funcall predicate (funcall key (,accessor target (- end 1))) value)\n end)\n (t (labels ((%bisect-left (l r)\n ,@(list declaration)\n (let ((mid (ash (+ l r) -1)))\n (if (= mid l)\n (if (funcall predicate (funcall key (,accessor target l)) value)\n r\n l)\n (if (funcall predicate (funcall key (,accessor target mid)) value)\n (%bisect-left mid r)\n (%bisect-left l mid))))))\n (%bisect-left start (- end 1)))))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (body aref (declare ((integer 0 #.most-positive-fixnum) l r)))))\n (function\n (assert end)\n (body funcall)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT (inline sort))\n (let* ((n (read))\n (as (make-array n :element-type 'fixnum)))\n (dotimes (i n) (setf (aref as i) (read-fixnum)))\n (setf as (sort as #'<))\n (let ((a-min (aref as 0))\n (a-max (aref as (- n 1)))\n (pivot (bisect-left as 0))\n (out (make-string-output-stream :element-type 'base-char)))\n (declare (int32 a-min a-max))\n (loop for i from (max pivot 1) below (- n 1)\n do (format out \"~D ~D~%\" a-min (aref as i))\n (setf a-min (- a-min (aref as i))))\n (loop for i from 1 below (min pivot (- n 1))\n do (format out \"~D ~D~%\" a-max (aref as i))\n (setf a-max (- a-max (aref as i))))\n (format out \"~D ~D~%\" a-max a-min)\n (println (- a-max a-min))\n (write-string (get-output-stream-string out)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1560654472, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03007.html", "problem_id": "p03007", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03007/input.txt", "sample_output_relpath": "derived/input_output/data/p03007/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03007/Lisp/s709151694.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s709151694", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n-1 1\n2 -2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defun bisect-left (target value &key (start 0) end (predicate #'<) (key #'identity))\n \"TARGET := vector | function\nPREDICATE := strict order\n\nReturns the smallest index (or input) i that fulfills TARGET[i] >= VALUE, where\n'>=' is the complement of PREDICATE. TARGET must be monotonically non-decreasing with\nrespect to PREDICATE. This function returns END if VALUE exceeds TARGET[END-1]. Note\nthat the range [START, END) is half-open. END must be explicitly specified if\nTARGET is function. KEY is applied to each element of TARGET before comparison.\"\n (declare (function key predicate)\n ((integer 0 #.most-positive-fixnum) start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (macrolet\n ((body (accessor &optional declaration)\n `(cond ((assert (<= start end)))\n ((= start end) end)\n ((funcall predicate (funcall key (,accessor target (- end 1))) value)\n end)\n (t (labels ((%bisect-left (l r)\n ,@(list declaration)\n (let ((mid (ash (+ l r) -1)))\n (if (= mid l)\n (if (funcall predicate (funcall key (,accessor target l)) value)\n r\n l)\n (if (funcall predicate (funcall key (,accessor target mid)) value)\n (%bisect-left mid r)\n (%bisect-left l mid))))))\n (%bisect-left start (- end 1)))))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (body aref (declare ((integer 0 #.most-positive-fixnum) l r)))))\n (function\n (assert end)\n (body funcall)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT (inline sort))\n (let* ((n (read))\n (as (make-array n :element-type 'fixnum)))\n (dotimes (i n) (setf (aref as i) (read-fixnum)))\n (setf as (sort as #'<))\n (let ((a-min (aref as 0))\n (a-max (aref as (- n 1)))\n (pivot (bisect-left as 0))\n (out (make-string-output-stream :element-type 'base-char)))\n (declare (int32 a-min a-max))\n (loop for i from (max pivot 1) below (- n 1)\n do (format out \"~D ~D~%\" a-min (aref as i))\n (setf a-min (- a-min (aref as i))))\n (loop for i from 1 below (min pivot (- n 1))\n do (format out \"~D ~D~%\" a-max (aref as i))\n (setf a-max (- a-max (aref as i))))\n (format out \"~D ~D~%\" a-max a-min)\n (println (- a-max a-min))\n (write-string (get-output-stream-string out)))))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere are N integers, A_1, A_2, ..., A_N, written on a blackboard.\n\nWe will repeat the following operation N-1 times so that we have only one integer on the blackboard.\n\nChoose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.\n\nFind the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n-10^4 \\leq A_i \\leq 10^4\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible value M of the final integer on the blackboard, and a sequence of operations x_i, y_i that maximizes the final integer, in the format below.\n\nHere x_i and y_i represent the integers x and y chosen in the i-th operation, respectively.\n\nIf there are multiple sequences of operations that maximize the final integer, any of them will be accepted.\n\nM\nx_1 y_1\n:\nx_{N-1} y_{N-1}\n\nSample Input 1\n\n3\n1 -1 2\n\nSample Output 1\n\n4\n-1 1\n2 -2\n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers written on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of integers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater integer, so the answer is 4.\n\nSample Input 2\n\n3\n1 1 1\n\nSample Output 2\n\n1\n1 1\n1 0", "sample_input": "3\n1 -1 2\n"}, "reference_outputs": ["4\n-1 1\n2 -2\n"], "source_document_id": "p03007", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere are N integers, A_1, A_2, ..., A_N, written on a blackboard.\n\nWe will repeat the following operation N-1 times so that we have only one integer on the blackboard.\n\nChoose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.\n\nFind the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n-10^4 \\leq A_i \\leq 10^4\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible value M of the final integer on the blackboard, and a sequence of operations x_i, y_i that maximizes the final integer, in the format below.\n\nHere x_i and y_i represent the integers x and y chosen in the i-th operation, respectively.\n\nIf there are multiple sequences of operations that maximize the final integer, any of them will be accepted.\n\nM\nx_1 y_1\n:\nx_{N-1} y_{N-1}\n\nSample Input 1\n\n3\n1 -1 2\n\nSample Output 1\n\n4\n-1 1\n2 -2\n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers written on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of integers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater integer, so the answer is 4.\n\nSample Input 2\n\n3\n1 1 1\n\nSample Output 2\n\n1\n1 1\n1 0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5114, "cpu_time_ms": 244, "memory_kb": 36964}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s896001418", "group_id": "codeNet:p03007", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (predicate #'<) (key #'identity))\n \"TARGET := vector | function\nPREDICATE := strict order\n\nReturns the smallest index (or input) i that fulfills TARGET[i] >= VALUE, where\n'>=' is the complement of PREDICATE. TARGET must be monotonically non-decreasing with\nrespect to PREDICATE. This function returns END if VALUE exceeds TARGET[END-1]. Note\nthat the range [START, END) is half-open. END must be explicitly specified if\nTARGET is function. KEY is applied to each element of TARGET before comparison.\"\n (declare (function key predicate)\n ((integer 0 #.most-positive-fixnum) start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (macrolet\n ((body (accessor &optional declaration)\n `(cond ((assert (<= start end)))\n ((= start end) end)\n ((funcall predicate (funcall key (,accessor target (- end 1))) value)\n end)\n (t (labels ((%bisect-left (l r)\n ,@(list declaration)\n (let ((mid (ash (+ l r) -1)))\n (if (= mid l)\n (if (funcall predicate (funcall key (,accessor target l)) value)\n r\n l)\n (if (funcall predicate (funcall key (,accessor target mid)) value)\n (%bisect-left mid r)\n (%bisect-left l mid))))))\n (%bisect-left start (- end 1)))))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (body aref (declare ((integer 0 #.most-positive-fixnum) l r)))))\n (function\n (assert end)\n (body funcall)))))\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (predicate #'<) (key #'identity))\n \"TARGET := vector | function\nPREDICATE := strict order\n\nReturns the smallest index (or input) i that fulfills TARGET[i] > VALUE. TARGET\nmust be monotonically non-decreasing with respect to PREDICATE. This function returns\nEND if VALUE exceeds TARGET[END-1]. Note that the range [START, END) is\nhalf-open. END must be explicitly specified if TARGET is function. KEY is\napplied to each element of TARGET before comparison.\"\n (declare (function key predicate)\n ((integer 0 #.most-positive-fixnum) start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (macrolet\n ((body (accessor &optional declaration)\n `(cond ((assert (<= start end)))\n ((= start end) end)\n ((funcall predicate value (funcall key (,accessor target (- end 1))))\n (labels ((%bisect-right (l r)\n ,@(list declaration)\n (let ((mid (ash (+ l r) -1)))\n (if (= mid l)\n (if (funcall predicate value (funcall key (,accessor target l)))\n l\n r)\n (if (funcall predicate value (funcall key (,accessor target mid)))\n (%bisect-right l mid)\n (%bisect-right mid r))))))\n \n (%bisect-right start (- end 1))))\n (t end))))\n (etypecase target\n (vector\n (when (null end)\n (setf end (length target)))\n (body aref (declare ((integer 0 #.most-positive-fixnum) l r))))\n (function\n (assert end)\n (body funcall)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'fixnum)))\n (dotimes (i n) (setf (aref as i) (read-fixnum)))\n (setf as (sort as #'<))\n (let ((a-min (aref as 0))\n (a-max (aref as (- n 1)))\n (pivot (bisect-left as 0)))\n (loop for i from (max pivot 1) below (- n 1)\n do (setf a-min (- a-min (aref as i))))\n (loop for i from 1 below (min pivot (- n 1))\n do (setf a-max (- a-max (aref as i))))\n (println (- a-max a-min)))\n (let ((a-min (aref as 0))\n (a-max (aref as (- n 1)))\n (pivot (bisect-left as 0)))\n (loop for i from (max pivot 1) below (- n 1)\n do (format t \"~D ~D~%\" a-min (aref as i))\n (setf a-min (- a-min (aref as i))))\n (loop for i from 1 below (min pivot (- n 1))\n do (format t \"~D ~D~%\" a-max (aref as i))\n (setf a-max (- a-max (aref as i))))\n (format t \"~D ~D~%\" a-max a-min))))\n\n#-swank(main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &optional (func #'main))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNC, and checks the string\noutput to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (and (> (length s) 0)\n (eql (char s (- (length s) 1)) #\\Linefeed))\n s\n (uiop:strcat s uiop:+lf+))))\n (equal (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall func)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n (let ((*standard-output* out))\n (etypecase thing\n (null ; Runs #'MAIN with the string on clipboard\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname ; Runs #'MAIN with the string in a text file\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 -1 2\n\"\n \"4\n-1 1\n2 -2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 1 1\n\"\n \"1\n1 1\n1 0\n\")))\n", "language": "Lisp", "metadata": {"date": 1560649102, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03007.html", "problem_id": "p03007", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03007/input.txt", "sample_output_relpath": "derived/input_output/data/p03007/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03007/Lisp/s896001418.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s896001418", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n-1 1\n2 -2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (predicate #'<) (key #'identity))\n \"TARGET := vector | function\nPREDICATE := strict order\n\nReturns the smallest index (or input) i that fulfills TARGET[i] >= VALUE, where\n'>=' is the complement of PREDICATE. TARGET must be monotonically non-decreasing with\nrespect to PREDICATE. This function returns END if VALUE exceeds TARGET[END-1]. Note\nthat the range [START, END) is half-open. END must be explicitly specified if\nTARGET is function. KEY is applied to each element of TARGET before comparison.\"\n (declare (function key predicate)\n ((integer 0 #.most-positive-fixnum) start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (macrolet\n ((body (accessor &optional declaration)\n `(cond ((assert (<= start end)))\n ((= start end) end)\n ((funcall predicate (funcall key (,accessor target (- end 1))) value)\n end)\n (t (labels ((%bisect-left (l r)\n ,@(list declaration)\n (let ((mid (ash (+ l r) -1)))\n (if (= mid l)\n (if (funcall predicate (funcall key (,accessor target l)) value)\n r\n l)\n (if (funcall predicate (funcall key (,accessor target mid)) value)\n (%bisect-left mid r)\n (%bisect-left l mid))))))\n (%bisect-left start (- end 1)))))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (body aref (declare ((integer 0 #.most-positive-fixnum) l r)))))\n (function\n (assert end)\n (body funcall)))))\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (predicate #'<) (key #'identity))\n \"TARGET := vector | function\nPREDICATE := strict order\n\nReturns the smallest index (or input) i that fulfills TARGET[i] > VALUE. TARGET\nmust be monotonically non-decreasing with respect to PREDICATE. This function returns\nEND if VALUE exceeds TARGET[END-1]. Note that the range [START, END) is\nhalf-open. END must be explicitly specified if TARGET is function. KEY is\napplied to each element of TARGET before comparison.\"\n (declare (function key predicate)\n ((integer 0 #.most-positive-fixnum) start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (macrolet\n ((body (accessor &optional declaration)\n `(cond ((assert (<= start end)))\n ((= start end) end)\n ((funcall predicate value (funcall key (,accessor target (- end 1))))\n (labels ((%bisect-right (l r)\n ,@(list declaration)\n (let ((mid (ash (+ l r) -1)))\n (if (= mid l)\n (if (funcall predicate value (funcall key (,accessor target l)))\n l\n r)\n (if (funcall predicate value (funcall key (,accessor target mid)))\n (%bisect-right l mid)\n (%bisect-right mid r))))))\n \n (%bisect-right start (- end 1))))\n (t end))))\n (etypecase target\n (vector\n (when (null end)\n (setf end (length target)))\n (body aref (declare ((integer 0 #.most-positive-fixnum) l r))))\n (function\n (assert end)\n (body funcall)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'fixnum)))\n (dotimes (i n) (setf (aref as i) (read-fixnum)))\n (setf as (sort as #'<))\n (let ((a-min (aref as 0))\n (a-max (aref as (- n 1)))\n (pivot (bisect-left as 0)))\n (loop for i from (max pivot 1) below (- n 1)\n do (setf a-min (- a-min (aref as i))))\n (loop for i from 1 below (min pivot (- n 1))\n do (setf a-max (- a-max (aref as i))))\n (println (- a-max a-min)))\n (let ((a-min (aref as 0))\n (a-max (aref as (- n 1)))\n (pivot (bisect-left as 0)))\n (loop for i from (max pivot 1) below (- n 1)\n do (format t \"~D ~D~%\" a-min (aref as i))\n (setf a-min (- a-min (aref as i))))\n (loop for i from 1 below (min pivot (- n 1))\n do (format t \"~D ~D~%\" a-max (aref as i))\n (setf a-max (- a-max (aref as i))))\n (format t \"~D ~D~%\" a-max a-min))))\n\n#-swank(main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &optional (func #'main))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNC, and checks the string\noutput to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (and (> (length s) 0)\n (eql (char s (- (length s) 1)) #\\Linefeed))\n s\n (uiop:strcat s uiop:+lf+))))\n (equal (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall func)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n (let ((*standard-output* out))\n (etypecase thing\n (null ; Runs #'MAIN with the string on clipboard\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname ; Runs #'MAIN with the string in a text file\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 -1 2\n\"\n \"4\n-1 1\n2 -2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 1 1\n\"\n \"1\n1 1\n1 0\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere are N integers, A_1, A_2, ..., A_N, written on a blackboard.\n\nWe will repeat the following operation N-1 times so that we have only one integer on the blackboard.\n\nChoose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.\n\nFind the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n-10^4 \\leq A_i \\leq 10^4\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible value M of the final integer on the blackboard, and a sequence of operations x_i, y_i that maximizes the final integer, in the format below.\n\nHere x_i and y_i represent the integers x and y chosen in the i-th operation, respectively.\n\nIf there are multiple sequences of operations that maximize the final integer, any of them will be accepted.\n\nM\nx_1 y_1\n:\nx_{N-1} y_{N-1}\n\nSample Input 1\n\n3\n1 -1 2\n\nSample Output 1\n\n4\n-1 1\n2 -2\n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers written on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of integers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater integer, so the answer is 4.\n\nSample Input 2\n\n3\n1 1 1\n\nSample Output 2\n\n1\n1 1\n1 0", "sample_input": "3\n1 -1 2\n"}, "reference_outputs": ["4\n-1 1\n2 -2\n"], "source_document_id": "p03007", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere are N integers, A_1, A_2, ..., A_N, written on a blackboard.\n\nWe will repeat the following operation N-1 times so that we have only one integer on the blackboard.\n\nChoose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.\n\nFind the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n-10^4 \\leq A_i \\leq 10^4\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible value M of the final integer on the blackboard, and a sequence of operations x_i, y_i that maximizes the final integer, in the format below.\n\nHere x_i and y_i represent the integers x and y chosen in the i-th operation, respectively.\n\nIf there are multiple sequences of operations that maximize the final integer, any of them will be accepted.\n\nM\nx_1 y_1\n:\nx_{N-1} y_{N-1}\n\nSample Input 1\n\n3\n1 -1 2\n\nSample Output 1\n\n4\n-1 1\n2 -2\n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers written on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of integers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater integer, so the answer is 4.\n\nSample Input 2\n\n3\n1 1 1\n\nSample Output 2\n\n1\n1 1\n1 0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9053, "cpu_time_ms": 587, "memory_kb": 37224}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s411151096", "group_id": "codeNet:p03011", "input_text": "(princ\n ((lambda (a b c)\n (- (+ a b c) (max a b c))) (read) (read) (read)))", "language": "Lisp", "metadata": {"date": 1584447712, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03011.html", "problem_id": "p03011", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03011/input.txt", "sample_output_relpath": "derived/input_output/data/p03011/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03011/Lisp/s411151096.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s411151096", "user_id": "u334552723"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(princ\n ((lambda (a b c)\n (- (+ a b c) (max a b c))) (read) (read) (read)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are three airports A, B and C, and flights between each pair of airports in both directions.\n\nA one-way flight between airports A and B takes P hours, a one-way flight between airports B and C takes Q hours, and a one-way flight between airports C and A takes R hours.\n\nConsider a route where we start at one of the airports, fly to another airport and then fly to the other airport.\n\nWhat is the minimum possible sum of the flight times?\n\nConstraints\n\n1 \\leq P,Q,R \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nP Q R\n\nOutput\n\nPrint the minimum possible sum of the flight times.\n\nSample Input 1\n\n1 3 4\n\nSample Output 1\n\n4\n\nThe sum of the flight times in the route A \\rightarrow B \\rightarrow C: 1 + 3 = 4 hours\n\nThe sum of the flight times in the route A \\rightarrow C \\rightarrow C: 4 + 3 = 7 hours\n\nThe sum of the flight times in the route B \\rightarrow A \\rightarrow C: 1 + 4 = 5 hours\n\nThe sum of the flight times in the route B \\rightarrow C \\rightarrow A: 3 + 4 = 7 hours\n\nThe sum of the flight times in the route C \\rightarrow A \\rightarrow B: 4 + 1 = 5 hours\n\nThe sum of the flight times in the route C \\rightarrow B \\rightarrow A: 3 + 1 = 4 hours\n\nThe minimum of these is 4 hours.\n\nSample Input 2\n\n3 2 3\n\nSample Output 2\n\n5", "sample_input": "1 3 4\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03011", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are three airports A, B and C, and flights between each pair of airports in both directions.\n\nA one-way flight between airports A and B takes P hours, a one-way flight between airports B and C takes Q hours, and a one-way flight between airports C and A takes R hours.\n\nConsider a route where we start at one of the airports, fly to another airport and then fly to the other airport.\n\nWhat is the minimum possible sum of the flight times?\n\nConstraints\n\n1 \\leq P,Q,R \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nP Q R\n\nOutput\n\nPrint the minimum possible sum of the flight times.\n\nSample Input 1\n\n1 3 4\n\nSample Output 1\n\n4\n\nThe sum of the flight times in the route A \\rightarrow B \\rightarrow C: 1 + 3 = 4 hours\n\nThe sum of the flight times in the route A \\rightarrow C \\rightarrow C: 4 + 3 = 7 hours\n\nThe sum of the flight times in the route B \\rightarrow A \\rightarrow C: 1 + 4 = 5 hours\n\nThe sum of the flight times in the route B \\rightarrow C \\rightarrow A: 3 + 4 = 7 hours\n\nThe sum of the flight times in the route C \\rightarrow A \\rightarrow B: 4 + 1 = 5 hours\n\nThe sum of the flight times in the route C \\rightarrow B \\rightarrow A: 3 + 1 = 4 hours\n\nThe minimum of these is 4 hours.\n\nSample Input 2\n\n3 2 3\n\nSample Output 2\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 78, "cpu_time_ms": 127, "memory_kb": 11360}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s554240061", "group_id": "codeNet:p03011", "input_text": "(let((p(read))\n (q(read))\n (r(read)))\n (princ(-(+ p q r)(max p q r))))", "language": "Lisp", "metadata": {"date": 1566404686, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03011.html", "problem_id": "p03011", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03011/input.txt", "sample_output_relpath": "derived/input_output/data/p03011/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03011/Lisp/s554240061.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s554240061", "user_id": "u994767958"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let((p(read))\n (q(read))\n (r(read)))\n (princ(-(+ p q r)(max p q r))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are three airports A, B and C, and flights between each pair of airports in both directions.\n\nA one-way flight between airports A and B takes P hours, a one-way flight between airports B and C takes Q hours, and a one-way flight between airports C and A takes R hours.\n\nConsider a route where we start at one of the airports, fly to another airport and then fly to the other airport.\n\nWhat is the minimum possible sum of the flight times?\n\nConstraints\n\n1 \\leq P,Q,R \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nP Q R\n\nOutput\n\nPrint the minimum possible sum of the flight times.\n\nSample Input 1\n\n1 3 4\n\nSample Output 1\n\n4\n\nThe sum of the flight times in the route A \\rightarrow B \\rightarrow C: 1 + 3 = 4 hours\n\nThe sum of the flight times in the route A \\rightarrow C \\rightarrow C: 4 + 3 = 7 hours\n\nThe sum of the flight times in the route B \\rightarrow A \\rightarrow C: 1 + 4 = 5 hours\n\nThe sum of the flight times in the route B \\rightarrow C \\rightarrow A: 3 + 4 = 7 hours\n\nThe sum of the flight times in the route C \\rightarrow A \\rightarrow B: 4 + 1 = 5 hours\n\nThe sum of the flight times in the route C \\rightarrow B \\rightarrow A: 3 + 1 = 4 hours\n\nThe minimum of these is 4 hours.\n\nSample Input 2\n\n3 2 3\n\nSample Output 2\n\n5", "sample_input": "1 3 4\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03011", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are three airports A, B and C, and flights between each pair of airports in both directions.\n\nA one-way flight between airports A and B takes P hours, a one-way flight between airports B and C takes Q hours, and a one-way flight between airports C and A takes R hours.\n\nConsider a route where we start at one of the airports, fly to another airport and then fly to the other airport.\n\nWhat is the minimum possible sum of the flight times?\n\nConstraints\n\n1 \\leq P,Q,R \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nP Q R\n\nOutput\n\nPrint the minimum possible sum of the flight times.\n\nSample Input 1\n\n1 3 4\n\nSample Output 1\n\n4\n\nThe sum of the flight times in the route A \\rightarrow B \\rightarrow C: 1 + 3 = 4 hours\n\nThe sum of the flight times in the route A \\rightarrow C \\rightarrow C: 4 + 3 = 7 hours\n\nThe sum of the flight times in the route B \\rightarrow A \\rightarrow C: 1 + 4 = 5 hours\n\nThe sum of the flight times in the route B \\rightarrow C \\rightarrow A: 3 + 4 = 7 hours\n\nThe sum of the flight times in the route C \\rightarrow A \\rightarrow B: 4 + 1 = 5 hours\n\nThe sum of the flight times in the route C \\rightarrow B \\rightarrow A: 3 + 1 = 4 hours\n\nThe minimum of these is 4 hours.\n\nSample Input 2\n\n3 2 3\n\nSample Output 2\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 81, "cpu_time_ms": 20, "memory_kb": 3940}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s432699109", "group_id": "codeNet:p03011", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(deftype int32 () '(signed-byte 32))\n(deftype int64 () '(signed-byte 64))\n\n\n;;macros\n(defmacro println (n)\n `(format t \"~a~%\" ,n))\n(defmacro vint-out (vec)\n `(progn\n (rep i (length ,vec)\n (princ (vref ,vec i))\n (princ \" \"))\n (fresh-line)))\n(defmacro aif (test-form then-form &optional else-form)\n `(let ((it ,test-form))\n (if it ,then-form ,else-form)))\n\n;;vector\n(defmacro vec (type &optional (num 100) (val 0))\n (let* ((g (gensym)))\n `(let* ((,g ,num))\n (make-array ,g :element-type ',type :initial-element ,val\n :adjustable nil :fill-pointer ,g))))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vint (&optional (num 0) (val 0))\n `(vec int32 ,num ,val))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vref (vector pos &optional value)\n (let ((g (gensym)))\n `(let ((,g ,value))\n (if ,g\n (setf (aref ,vector ,pos) ,g)\n (aref ,vector ,pos)))))\n\n(defmacro chvar (sym comp predicate)\n (let ((g (gensym)))\n `(let ((,g ,comp))\n (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))\n (setf ,sym ,g)))))\n\n(defmacro chmax (sym comp &optional (predicate #'>))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro chmin (sym comp &optional (predicate #'<))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro defchangef (name op default-val)\n `(defmacro ,name (var &optional (val ,default-val))\n `(setq ,var (,',op ,val ,var))))\n(defmacro read-str ()\n `(write-to-string (read)))\n\n;;本体\n(defun main ()\n (let ((p (read)) (q (read)) (r (read)))\n (println\n (min (+ p q) (+ q r) (+ r p)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1560128584, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03011.html", "problem_id": "p03011", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03011/input.txt", "sample_output_relpath": "derived/input_output/data/p03011/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03011/Lisp/s432699109.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s432699109", "user_id": "u432998668"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(deftype int32 () '(signed-byte 32))\n(deftype int64 () '(signed-byte 64))\n\n\n;;macros\n(defmacro println (n)\n `(format t \"~a~%\" ,n))\n(defmacro vint-out (vec)\n `(progn\n (rep i (length ,vec)\n (princ (vref ,vec i))\n (princ \" \"))\n (fresh-line)))\n(defmacro aif (test-form then-form &optional else-form)\n `(let ((it ,test-form))\n (if it ,then-form ,else-form)))\n\n;;vector\n(defmacro vec (type &optional (num 100) (val 0))\n (let* ((g (gensym)))\n `(let* ((,g ,num))\n (make-array ,g :element-type ',type :initial-element ,val\n :adjustable nil :fill-pointer ,g))))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vint (&optional (num 0) (val 0))\n `(vec int32 ,num ,val))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vref (vector pos &optional value)\n (let ((g (gensym)))\n `(let ((,g ,value))\n (if ,g\n (setf (aref ,vector ,pos) ,g)\n (aref ,vector ,pos)))))\n\n(defmacro chvar (sym comp predicate)\n (let ((g (gensym)))\n `(let ((,g ,comp))\n (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))\n (setf ,sym ,g)))))\n\n(defmacro chmax (sym comp &optional (predicate #'>))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro chmin (sym comp &optional (predicate #'<))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro defchangef (name op default-val)\n `(defmacro ,name (var &optional (val ,default-val))\n `(setq ,var (,',op ,val ,var))))\n(defmacro read-str ()\n `(write-to-string (read)))\n\n;;本体\n(defun main ()\n (let ((p (read)) (q (read)) (r (read)))\n (println\n (min (+ p q) (+ q r) (+ r p)))))\n\n#-swank(main)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are three airports A, B and C, and flights between each pair of airports in both directions.\n\nA one-way flight between airports A and B takes P hours, a one-way flight between airports B and C takes Q hours, and a one-way flight between airports C and A takes R hours.\n\nConsider a route where we start at one of the airports, fly to another airport and then fly to the other airport.\n\nWhat is the minimum possible sum of the flight times?\n\nConstraints\n\n1 \\leq P,Q,R \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nP Q R\n\nOutput\n\nPrint the minimum possible sum of the flight times.\n\nSample Input 1\n\n1 3 4\n\nSample Output 1\n\n4\n\nThe sum of the flight times in the route A \\rightarrow B \\rightarrow C: 1 + 3 = 4 hours\n\nThe sum of the flight times in the route A \\rightarrow C \\rightarrow C: 4 + 3 = 7 hours\n\nThe sum of the flight times in the route B \\rightarrow A \\rightarrow C: 1 + 4 = 5 hours\n\nThe sum of the flight times in the route B \\rightarrow C \\rightarrow A: 3 + 4 = 7 hours\n\nThe sum of the flight times in the route C \\rightarrow A \\rightarrow B: 4 + 1 = 5 hours\n\nThe sum of the flight times in the route C \\rightarrow B \\rightarrow A: 3 + 1 = 4 hours\n\nThe minimum of these is 4 hours.\n\nSample Input 2\n\n3 2 3\n\nSample Output 2\n\n5", "sample_input": "1 3 4\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03011", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are three airports A, B and C, and flights between each pair of airports in both directions.\n\nA one-way flight between airports A and B takes P hours, a one-way flight between airports B and C takes Q hours, and a one-way flight between airports C and A takes R hours.\n\nConsider a route where we start at one of the airports, fly to another airport and then fly to the other airport.\n\nWhat is the minimum possible sum of the flight times?\n\nConstraints\n\n1 \\leq P,Q,R \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nP Q R\n\nOutput\n\nPrint the minimum possible sum of the flight times.\n\nSample Input 1\n\n1 3 4\n\nSample Output 1\n\n4\n\nThe sum of the flight times in the route A \\rightarrow B \\rightarrow C: 1 + 3 = 4 hours\n\nThe sum of the flight times in the route A \\rightarrow C \\rightarrow C: 4 + 3 = 7 hours\n\nThe sum of the flight times in the route B \\rightarrow A \\rightarrow C: 1 + 4 = 5 hours\n\nThe sum of the flight times in the route B \\rightarrow C \\rightarrow A: 3 + 4 = 7 hours\n\nThe sum of the flight times in the route C \\rightarrow A \\rightarrow B: 4 + 1 = 5 hours\n\nThe sum of the flight times in the route C \\rightarrow B \\rightarrow A: 3 + 1 = 4 hours\n\nThe minimum of these is 4 hours.\n\nSample Input 2\n\n3 2 3\n\nSample Output 2\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2119, "cpu_time_ms": 157, "memory_kb": 19172}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s513802135", "group_id": "codeNet:p03012", "input_text": "(defun split (lst count)\n (values (subseq lst 0 count) (nthcdr count lst)))\n\n(defmacro lst-sum (lst)\n `(reduce #'+ ,lst))\n\n(defun calc-abs (f-lst b-lst)\n (abs (- (lst-sum f-lst) (lst-sum b-lst))))\n\n(defun solve (n lst)\n (let ((min-number 1000000))\n (dotimes (i n)\n (multiple-value-bind (f-lst b-lst) (split lst i)\n (cond ((< (calc-abs f-lst b-lst) min-number)\n (setq min-number (calc-abs f-lst b-lst))))))\n (print min-number)))\n\n(let ((n (read))\n (lst '()))\n (dotimes (i n)\n (append lst (read)))\n (solve n lst))\n", "language": "Lisp", "metadata": {"date": 1560218890, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03012.html", "problem_id": "p03012", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03012/input.txt", "sample_output_relpath": "derived/input_output/data/p03012/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03012/Lisp/s513802135.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s513802135", "user_id": "u761519515"}, "prompt_components": {"gold_output": "0\n", "input_to_evaluate": "(defun split (lst count)\n (values (subseq lst 0 count) (nthcdr count lst)))\n\n(defmacro lst-sum (lst)\n `(reduce #'+ ,lst))\n\n(defun calc-abs (f-lst b-lst)\n (abs (- (lst-sum f-lst) (lst-sum b-lst))))\n\n(defun solve (n lst)\n (let ((min-number 1000000))\n (dotimes (i n)\n (multiple-value-bind (f-lst b-lst) (split lst i)\n (cond ((< (calc-abs f-lst b-lst) min-number)\n (setq min-number (calc-abs f-lst b-lst))))))\n (print min-number)))\n\n(let ((n (read))\n (lst '()))\n (dotimes (i n)\n (append lst (read)))\n (solve n lst))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have N weights indexed 1 to N. The \bmass of the weight indexed i is W_i.\n\nWe will divide these weights into two groups: the weights with indices not greater than T, and those with indices greater than T, for some integer 1 \\leq T < N. Let S_1 be the sum of the masses of the weights in the former group, and S_2 be the sum of the masses of the weights in the latter group.\n\nConsider all possible such divisions and find the minimum possible absolute difference of S_1 and S_2.\n\nConstraints\n\n2 \\leq N \\leq 100\n\n1 \\leq W_i \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nW_1 W_2 ... W_{N-1} W_N\n\nOutput\n\nPrint the minimum possible absolute difference of S_1 and S_2.\n\nSample Input 1\n\n3\n1 2 3\n\nSample Output 1\n\n0\n\nIf T = 2, S_1 = 1 + 2 = 3 and S_2 = 3, with the absolute difference of 0.\n\nSample Input 2\n\n4\n1 3 1 1\n\nSample Output 2\n\n2\n\nIf T = 2, S_1 = 1 + 3 = 4 and S_2 = 1 + 1 = 2, with the absolute difference of 2. We cannot have a smaller absolute difference.\n\nSample Input 3\n\n8\n27 23 76 2 3 5 62 52\n\nSample Output 3\n\n2", "sample_input": "3\n1 2 3\n"}, "reference_outputs": ["0\n"], "source_document_id": "p03012", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have N weights indexed 1 to N. The \bmass of the weight indexed i is W_i.\n\nWe will divide these weights into two groups: the weights with indices not greater than T, and those with indices greater than T, for some integer 1 \\leq T < N. Let S_1 be the sum of the masses of the weights in the former group, and S_2 be the sum of the masses of the weights in the latter group.\n\nConsider all possible such divisions and find the minimum possible absolute difference of S_1 and S_2.\n\nConstraints\n\n2 \\leq N \\leq 100\n\n1 \\leq W_i \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nW_1 W_2 ... W_{N-1} W_N\n\nOutput\n\nPrint the minimum possible absolute difference of S_1 and S_2.\n\nSample Input 1\n\n3\n1 2 3\n\nSample Output 1\n\n0\n\nIf T = 2, S_1 = 1 + 2 = 3 and S_2 = 3, with the absolute difference of 0.\n\nSample Input 2\n\n4\n1 3 1 1\n\nSample Output 2\n\n2\n\nIf T = 2, S_1 = 1 + 3 = 4 and S_2 = 1 + 1 = 2, with the absolute difference of 2. We cannot have a smaller absolute difference.\n\nSample Input 3\n\n8\n27 23 76 2 3 5 62 52\n\nSample Output 3\n\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 610, "cpu_time_ms": 30, "memory_kb": 7392}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s826653461", "group_id": "codeNet:p03013", "input_text": "(let* ((n (read))\n (m (read))\n (lst (loop :repeat m :collect (read)))\n (arr (make-array (+ 2 n) :element-type 'fixnum :initial-element 0)))\n (setf (aref arr 0) 1)\n (loop :for k :from 0 :upto (1- n)\n :do (if (or (not lst) (not (= k (car lst))))\n (progn (setf (aref arr (+ 1 k))\n (mod (+ (aref arr (+ 1 k)) (aref arr k)) 1000000007))\n (setf (aref arr (+ 2 k))\n (mod (+ (aref arr (+ 2 k)) (aref arr k)) 1000000007)))\n (progn (setf lst (cdr lst))\n (setf (aref arr k) 0))))\n (princ (aref arr n)))", "language": "Lisp", "metadata": {"date": 1581897995, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03013.html", "problem_id": "p03013", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03013/input.txt", "sample_output_relpath": "derived/input_output/data/p03013/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03013/Lisp/s826653461.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s826653461", "user_id": "u610490393"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (lst (loop :repeat m :collect (read)))\n (arr (make-array (+ 2 n) :element-type 'fixnum :initial-element 0)))\n (setf (aref arr 0) 1)\n (loop :for k :from 0 :upto (1- n)\n :do (if (or (not lst) (not (= k (car lst))))\n (progn (setf (aref arr (+ 1 k))\n (mod (+ (aref arr (+ 1 k)) (aref arr k)) 1000000007))\n (setf (aref arr (+ 2 k))\n (mod (+ (aref arr (+ 2 k)) (aref arr k)) 1000000007)))\n (progn (setf lst (cdr lst))\n (setf (aref arr k) 0))))\n (princ (aref arr n)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step.\nHe can climb up one or two steps at a time.\n\nHowever, the treads of the a_1-th, a_2-th, a_3-th, \\ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps.\n\nHow many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps?\nFind the count modulo 1\\ 000\\ 000\\ 007.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n0 \\leq M \\leq N-1\n\n1 \\leq a_1 < a_2 < ... < a_M \\leq N-1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1\na_2\n.\n.\n.\na_M\n\nOutput\n\nPrint the number of ways to climb up the stairs under the condition, modulo 1\\ 000\\ 000\\ 007.\n\nSample Input 1\n\n6 1\n3\n\nSample Output 1\n\n4\n\nThere are four ways to climb up the stairs, as follows:\n\n0 \\to 1 \\to 2 \\to 4 \\to 5 \\to 6\n\n0 \\to 1 \\to 2 \\to 4 \\to 6\n\n0 \\to 2 \\to 4 \\to 5 \\to 6\n\n0 \\to 2 \\to 4 \\to 6\n\nSample Input 2\n\n10 2\n4\n5\n\nSample Output 2\n\n0\n\nThere may be no way to climb up the stairs without setting foot on the broken steps.\n\nSample Input 3\n\n100 5\n1\n23\n45\n67\n89\n\nSample Output 3\n\n608200469\n\nBe sure to print the count modulo 1\\ 000\\ 000\\ 007.", "sample_input": "6 1\n3\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03013", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step.\nHe can climb up one or two steps at a time.\n\nHowever, the treads of the a_1-th, a_2-th, a_3-th, \\ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps.\n\nHow many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps?\nFind the count modulo 1\\ 000\\ 000\\ 007.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n0 \\leq M \\leq N-1\n\n1 \\leq a_1 < a_2 < ... < a_M \\leq N-1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1\na_2\n.\n.\n.\na_M\n\nOutput\n\nPrint the number of ways to climb up the stairs under the condition, modulo 1\\ 000\\ 000\\ 007.\n\nSample Input 1\n\n6 1\n3\n\nSample Output 1\n\n4\n\nThere are four ways to climb up the stairs, as follows:\n\n0 \\to 1 \\to 2 \\to 4 \\to 5 \\to 6\n\n0 \\to 1 \\to 2 \\to 4 \\to 6\n\n0 \\to 2 \\to 4 \\to 5 \\to 6\n\n0 \\to 2 \\to 4 \\to 6\n\nSample Input 2\n\n10 2\n4\n5\n\nSample Output 2\n\n0\n\nThere may be no way to climb up the stairs without setting foot on the broken steps.\n\nSample Input 3\n\n100 5\n1\n23\n45\n67\n89\n\nSample Output 3\n\n608200469\n\nBe sure to print the count modulo 1\\ 000\\ 000\\ 007.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 649, "cpu_time_ms": 220, "memory_kb": 59752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s246763842", "group_id": "codeNet:p03016", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline power-mod))\n(defun power-mod (base power &optional (divisor 1000000007))\n \"BASE := integer\nPOWER, DIVISOR := non-negative fixnum\"\n (declare ((unsigned-byte 32) divisor)\n (integer base))\n (labels ((recur (x p)\n (declare ((unsigned-byte 32) x)\n ((unsigned-byte 62) p))\n (cond ((zerop p) 1)\n ((evenp p) (recur (mod (* x x) divisor) (ash p -1)))\n (t (mod (* x (recur x (- p 1))) divisor)))))\n (declare (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional))\n recur))\n (recur (mod base divisor) power)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun sum10 (k width divisor)\n (declare (uint62 k width)\n (uint31 divisor))\n (let ((factor (mod (expt 10 width) divisor)))\n (labels ((recur (k)\n (declare (uint62 k)\n (values uint31))\n (cond ((zerop k) 0)\n ((evenp k)\n (mod (* (recur (ash k -1))\n (+ 1 (power-mod factor (ash k -1) divisor)))\n divisor))\n (t\n (mod (+ 1 (* factor (recur (- k 1))))\n divisor)))))\n (recur k))))\n\n(defun calc (k init delta width divisor)\n (declare (uint31 divisor)\n (uint62 k init delta width))\n (let ((factor (mod (expt 10 width) divisor)))\n (labels ((mod+ (x y) (mod (+ x y) divisor))\n (mod* (x y) (mod (* x y) divisor))\n (recur (k)\n (declare (uint62 k))\n (cond ((zerop k) 0)\n ((evenp k)\n (mod+ (mod* (mod* (ash k -1) delta)\n (sum10 (ash k -1) width divisor))\n (mod* (+ 1 (power-mod factor (ash k -1) divisor))\n (recur (ash k -1)))))\n (t (mod+ (mod* factor (recur (- k 1)))\n (mod+ init (mod* (- k 1) delta)))))))\n (declare (inline mod+ mod*))\n (recur k))))\n\n(defun main ()\n (let* ((l (read))\n (a (read))\n (b (read))\n (m (read))\n (boundaries (make-array 19 :element-type 'uint62 :initial-element 0)))\n (declare (uint62 l a b)\n (uint31 m)\n ((simple-array uint62 (*)) boundaries))\n (dotimes (d 19)\n (setf (aref boundaries d)\n (max 0 (ceiling (- (expt 10 d) a) b))))\n (dotimes (d 19)\n (when (>= (aref boundaries d) l)\n (setf (aref boundaries d) l)\n (setf boundaries (adjust-array boundaries (+ d 1)))\n (return)))\n (let ((res 0))\n (loop for d from (position-if #'plusp boundaries) below (length boundaries)\n for length = (- (aref boundaries d) (aref boundaries (- d 1)))\n do (setf res\n (mod\n (+ (mod (* res (power-mod (expt 10 d) length m)) m)\n (calc length (+ a (* b (aref boundaries (- d 1)))) b d m))\n m)))\n (println res))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1560212917, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03016.html", "problem_id": "p03016", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03016/input.txt", "sample_output_relpath": "derived/input_output/data/p03016/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03016/Lisp/s246763842.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s246763842", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5563\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline power-mod))\n(defun power-mod (base power &optional (divisor 1000000007))\n \"BASE := integer\nPOWER, DIVISOR := non-negative fixnum\"\n (declare ((unsigned-byte 32) divisor)\n (integer base))\n (labels ((recur (x p)\n (declare ((unsigned-byte 32) x)\n ((unsigned-byte 62) p))\n (cond ((zerop p) 1)\n ((evenp p) (recur (mod (* x x) divisor) (ash p -1)))\n (t (mod (* x (recur x (- p 1))) divisor)))))\n (declare (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional))\n recur))\n (recur (mod base divisor) power)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun sum10 (k width divisor)\n (declare (uint62 k width)\n (uint31 divisor))\n (let ((factor (mod (expt 10 width) divisor)))\n (labels ((recur (k)\n (declare (uint62 k)\n (values uint31))\n (cond ((zerop k) 0)\n ((evenp k)\n (mod (* (recur (ash k -1))\n (+ 1 (power-mod factor (ash k -1) divisor)))\n divisor))\n (t\n (mod (+ 1 (* factor (recur (- k 1))))\n divisor)))))\n (recur k))))\n\n(defun calc (k init delta width divisor)\n (declare (uint31 divisor)\n (uint62 k init delta width))\n (let ((factor (mod (expt 10 width) divisor)))\n (labels ((mod+ (x y) (mod (+ x y) divisor))\n (mod* (x y) (mod (* x y) divisor))\n (recur (k)\n (declare (uint62 k))\n (cond ((zerop k) 0)\n ((evenp k)\n (mod+ (mod* (mod* (ash k -1) delta)\n (sum10 (ash k -1) width divisor))\n (mod* (+ 1 (power-mod factor (ash k -1) divisor))\n (recur (ash k -1)))))\n (t (mod+ (mod* factor (recur (- k 1)))\n (mod+ init (mod* (- k 1) delta)))))))\n (declare (inline mod+ mod*))\n (recur k))))\n\n(defun main ()\n (let* ((l (read))\n (a (read))\n (b (read))\n (m (read))\n (boundaries (make-array 19 :element-type 'uint62 :initial-element 0)))\n (declare (uint62 l a b)\n (uint31 m)\n ((simple-array uint62 (*)) boundaries))\n (dotimes (d 19)\n (setf (aref boundaries d)\n (max 0 (ceiling (- (expt 10 d) a) b))))\n (dotimes (d 19)\n (when (>= (aref boundaries d) l)\n (setf (aref boundaries d) l)\n (setf boundaries (adjust-array boundaries (+ d 1)))\n (return)))\n (let ((res 0))\n (loop for d from (position-if #'plusp boundaries) below (length boundaries)\n for length = (- (aref boundaries d) (aref boundaries (- d 1)))\n do (setf res\n (mod\n (+ (mod (* res (power-mod (expt 10 d) length m)) m)\n (calc length (+ a (* b (aref boundaries (- d 1)))) b d m))\n m)))\n (println res))))\n\n#-swank(main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere is an arithmetic progression with L terms: s_0, s_1, s_2, ... , s_{L-1}.\n\nThe initial term is A, and the common difference is B. That is, s_i = A + B \\times i holds.\n\nConsider the integer obtained by concatenating the terms written in base ten without leading zeros. For example, the sequence 3, 7, 11, 15, 19 would be concatenated into 37111519. What is the remainder when that integer is divided by M?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq L, A, B < 10^{18}\n\n2 \\leq M \\leq 10^9\n\nAll terms in the arithmetic progression are less than 10^{18}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL A B M\n\nOutput\n\nPrint the remainder when the integer obtained by concatenating the terms is divided by M.\n\nSample Input 1\n\n5 3 4 10007\n\nSample Output 1\n\n5563\n\nOur arithmetic progression is 3, 7, 11, 15, 19, so the answer is 37111519 mod 10007, that is, 5563.\n\nSample Input 2\n\n4 8 1 1000000\n\nSample Output 2\n\n891011\n\nSample Input 3\n\n107 10000000000007 1000000000000007 998244353\n\nSample Output 3\n\n39122908", "sample_input": "5 3 4 10007\n"}, "reference_outputs": ["5563\n"], "source_document_id": "p03016", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere is an arithmetic progression with L terms: s_0, s_1, s_2, ... , s_{L-1}.\n\nThe initial term is A, and the common difference is B. That is, s_i = A + B \\times i holds.\n\nConsider the integer obtained by concatenating the terms written in base ten without leading zeros. For example, the sequence 3, 7, 11, 15, 19 would be concatenated into 37111519. What is the remainder when that integer is divided by M?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq L, A, B < 10^{18}\n\n2 \\leq M \\leq 10^9\n\nAll terms in the arithmetic progression are less than 10^{18}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL A B M\n\nOutput\n\nPrint the remainder when the integer obtained by concatenating the terms is divided by M.\n\nSample Input 1\n\n5 3 4 10007\n\nSample Output 1\n\n5563\n\nOur arithmetic progression is 3, 7, 11, 15, 19, so the answer is 37111519 mod 10007, that is, 5563.\n\nSample Input 2\n\n4 8 1 1000000\n\nSample Output 2\n\n891011\n\nSample Input 3\n\n107 10000000000007 1000000000000007 998244353\n\nSample Output 3\n\n39122908", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4401, "cpu_time_ms": 240, "memory_kb": 30308}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s136633964", "group_id": "codeNet:p03025", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(defparameter +mod+ (+ (expt 10 9) 7))\n\n(defun mod+(&rest exp)\n (reduce (lambda (a b)\n (mod (+ a b) +mod+))\n exp))\n\n(defun mod-(&rest exp)\n (reducce (lambda (a b)\n (mod (- a b) +mod+))\n exp))\n\n(defun mod*(&rest exp)\n (reduce (lambda (a b)\n (mod (* a b) +mod+))\n exp))\n\n(defun modpow (x y);x^y\n (if (zerop y) 1\n (mod* (if (oddp y) x 1)\n (modpow (mod* x x) (ash y -1)))))\n\n(defun modinv (x)\n (modpow x (- +mod+ 2)))\n\n(defun mod/(&rest exp)\n (reduce (lambda (a b)\n (mod (* a (modinv b)) +mod+))\n exp))\n\n(defparameter N_MAX 100010)\n\n(defvar factorial-memo (make-array N_MAX :initial-element nil))\n(defvar factorial-inv-memo (make-array N_MAX :initial-element nil))\n(defun factorial (x)\n (if (<= x 1) 1\n (if (aref factorial-memo x)\n (aref factorial-memo x)\n (setf (aref factorial-memo x) (mod* x (factorial (1- x)))))))\n\n(defun factorial-inv (x)\n (if (= x (1- N_MAX))\n (modinv (factorial x))\n (if (aref factorial-inv-memo x)\n (aref factorial-inv-memo x)\n (setf (aref factorial-inv-memo x) (mod* (1+ x) (factorial-inv (1+ x)))))))\n\n(defun combination (a b)\n (mod* (factorial a) (factorial-inv b) (factorial-inv (- a b))))\n\n(defun main (n a b c)\n (let*\n ((need-one-win (mod/ 100 (- 100 c)))\n (win-a-p (mod/ a (+ a b)))\n (win-b-p (mod/ b (+ a b)))\n (ans 0))\n (dotimes (i n)\n (let* ((turn (+ n i))\n (way (combination (1- turn) i)))\n (setf ans (mod+ ans\n (mod* turn need-one-win way\n (modpow win-a-p n)\n (modpow win-b-p i))))\n (setf ans (mod+ ans\n (mod* turn need-one-win way\n (modpow win-b-p n)\n (modpow win-a-p i))))))\n (write ans)))\n\n\n(main (read) (read) (read) (read))\n", "language": "Lisp", "metadata": {"date": 1583998059, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03025.html", "problem_id": "p03025", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03025/input.txt", "sample_output_relpath": "derived/input_output/data/p03025/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03025/Lisp/s136633964.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s136633964", "user_id": "u493610446"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(defparameter +mod+ (+ (expt 10 9) 7))\n\n(defun mod+(&rest exp)\n (reduce (lambda (a b)\n (mod (+ a b) +mod+))\n exp))\n\n(defun mod-(&rest exp)\n (reducce (lambda (a b)\n (mod (- a b) +mod+))\n exp))\n\n(defun mod*(&rest exp)\n (reduce (lambda (a b)\n (mod (* a b) +mod+))\n exp))\n\n(defun modpow (x y);x^y\n (if (zerop y) 1\n (mod* (if (oddp y) x 1)\n (modpow (mod* x x) (ash y -1)))))\n\n(defun modinv (x)\n (modpow x (- +mod+ 2)))\n\n(defun mod/(&rest exp)\n (reduce (lambda (a b)\n (mod (* a (modinv b)) +mod+))\n exp))\n\n(defparameter N_MAX 100010)\n\n(defvar factorial-memo (make-array N_MAX :initial-element nil))\n(defvar factorial-inv-memo (make-array N_MAX :initial-element nil))\n(defun factorial (x)\n (if (<= x 1) 1\n (if (aref factorial-memo x)\n (aref factorial-memo x)\n (setf (aref factorial-memo x) (mod* x (factorial (1- x)))))))\n\n(defun factorial-inv (x)\n (if (= x (1- N_MAX))\n (modinv (factorial x))\n (if (aref factorial-inv-memo x)\n (aref factorial-inv-memo x)\n (setf (aref factorial-inv-memo x) (mod* (1+ x) (factorial-inv (1+ x)))))))\n\n(defun combination (a b)\n (mod* (factorial a) (factorial-inv b) (factorial-inv (- a b))))\n\n(defun main (n a b c)\n (let*\n ((need-one-win (mod/ 100 (- 100 c)))\n (win-a-p (mod/ a (+ a b)))\n (win-b-p (mod/ b (+ a b)))\n (ans 0))\n (dotimes (i n)\n (let* ((turn (+ n i))\n (way (combination (1- turn) i)))\n (setf ans (mod+ ans\n (mod* turn need-one-win way\n (modpow win-a-p n)\n (modpow win-b-p i))))\n (setf ans (mod+ ans\n (mod* turn need-one-win way\n (modpow win-b-p n)\n (modpow win-a-p i))))))\n (write ans)))\n\n\n(main (read) (read) (read) (read))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nTakahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total.\n\nWhen they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %.\nFind the expected number of games that will be played, and print it as follows.\n\nWe can represent the expected value as P/Q with coprime integers P and Q.\nPrint the integer R between 0 and 10^9+6 (inclusive) such that R \\times Q \\equiv P\\pmod {10^9+7}.\n(Such an integer R always uniquely exists under the constraints of this problem.)\n\nConstraints\n\n1 \\leq N \\leq 100000\n\n0 \\leq A,B,C \\leq 100\n\n1 \\leq A+B\n\nA+B+C=100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B C\n\nOutput\n\nPrint the expected number of games that will be played, in the manner specified in the statement.\n\nSample Input 1\n\n1 25 25 50\n\nSample Output 1\n\n2\n\nSince N=1, they will repeat the game until one of them wins.\nThe expected number of games played is 2.\n\nSample Input 2\n\n4 50 50 0\n\nSample Output 2\n\n312500008\n\nC may be 0.\n\nSample Input 3\n\n1 100 0 0\n\nSample Output 3\n\n1\n\nB may also be 0.\n\nSample Input 4\n\n100000 31 41 28\n\nSample Output 4\n\n104136146", "sample_input": "1 25 25 50\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03025", "source_text": "Score : 500 points\n\nProblem Statement\n\nTakahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total.\n\nWhen they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %.\nFind the expected number of games that will be played, and print it as follows.\n\nWe can represent the expected value as P/Q with coprime integers P and Q.\nPrint the integer R between 0 and 10^9+6 (inclusive) such that R \\times Q \\equiv P\\pmod {10^9+7}.\n(Such an integer R always uniquely exists under the constraints of this problem.)\n\nConstraints\n\n1 \\leq N \\leq 100000\n\n0 \\leq A,B,C \\leq 100\n\n1 \\leq A+B\n\nA+B+C=100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B C\n\nOutput\n\nPrint the expected number of games that will be played, in the manner specified in the statement.\n\nSample Input 1\n\n1 25 25 50\n\nSample Output 1\n\n2\n\nSince N=1, they will repeat the game until one of them wins.\nThe expected number of games played is 2.\n\nSample Input 2\n\n4 50 50 0\n\nSample Output 2\n\n312500008\n\nC may be 0.\n\nSample Input 3\n\n1 100 0 0\n\nSample Output 3\n\n1\n\nB may also be 0.\n\nSample Input 4\n\n100000 31 41 28\n\nSample Output 4\n\n104136146", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2905, "cpu_time_ms": 315, "memory_kb": 76216}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s559139400", "group_id": "codeNet:p03025", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n\n(declaim (inline power-mod))\n(defun power-mod (base power &optional (divisor 1000000007))\n \"BASE := integer\nPOWER, DIVISOR := non-negative fixnum\"\n (declare ((integer 0 #.most-positive-fixnum) divisor)\n (integer base))\n (labels ((recur (x p)\n (cond ((zerop p) 1)\n ((evenp p) (recur (mod (* x x) divisor) (ash p -1)))\n (t (mod (* x (recur x (- p 1))) divisor)))))\n (declare (ftype (function ((unsigned-byte 32) (integer 0 #.most-positive-fixnum))\n (values (integer 0 #.most-positive-fixnum) &optional))\n recur))\n (recur (mod base divisor) power)))\n\n;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\n\n(defconstant +binom-size+ 210000)\n(defconstant +binom-mod+ #.(+ (expt 10 9) 7))\n\n(declaim ((simple-array (unsigned-byte 32) (*)) *fact* *fact-inv* *inv*))\n(defparameter *fact* (make-array +binom-size+ :element-type '(unsigned-byte 32)))\n(defparameter *fact-inv* (make-array +binom-size+ :element-type '(unsigned-byte 32)))\n(defparameter *inv* (make-array +binom-size+ :element-type '(unsigned-byte 32)))\n\n(defun initialize-binom ()\n (setf (aref *fact* 0) 1\n (aref *fact* 1) 1\n (aref *fact-inv* 0) 1\n (aref *fact-inv* 1) 1\n (aref *inv* 1) 1)\n (loop for i from 2 below +binom-size+\n do (setf (aref *fact* i) (mod (* i (aref *fact* (- i 1))) +binom-mod+)\n (aref *inv* i) (mod (- (* (aref *inv* (rem +binom-mod+ i))\n (floor +binom-mod+ i)))\n +binom-mod+)\n (aref *fact-inv* i) (mod (* (aref *inv* i)\n (aref *fact-inv* (- i 1)))\n +binom-mod+))))\n\n(initialize-binom)\n\n(declaim (inline binom))\n(defun binom (n k)\n \"Returns nCk.\"\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (mod (* (aref *fact* n)\n (mod (* (aref *fact-inv* k) (aref *fact-inv* (- n k))) +binom-mod+))\n +binom-mod+)))\n\n(defun multinomial (&rest ks)\n \"Returns the multinomial coefficient K!/k_1!k_2!...k_n! for K = k_1 + k_2 +\n... + k_n. K must be equal or smaller than MOST-POSITIVE-FIXNUM. (multinomial)\nreturns 1.\"\n (let ((sum 0)\n (result 1))\n (declare ((integer 0 #.most-positive-fixnum) result sum))\n (dolist (k ks)\n (incf sum k)\n (setq result\n (mod (* result (aref *fact-inv* k)) +binom-mod+)))\n (mod (* result (aref *fact* sum)) +binom-mod+)))\n\n;; TODO: deal with bignums\n(declaim (inline ext-gcd))\n(defun ext-gcd (a b)\n \"Returns two integers X and Y where AX + BY = gcd(A, B) holds.\"\n (declare (fixnum a b))\n (labels ((%gcd (a b)\n (declare (fixnum a b))\n (if (zerop b)\n (values 1 0)\n (multiple-value-bind (p q) (floor a b) ; a = pb + q\n (multiple-value-bind (v u) (%gcd b q)\n (declare (fixnum u v))\n (values u (the fixnum (- v (the fixnum (* p u))))))))))\n (if (>= a 0)\n (if (>= b 0)\n (%gcd a b)\n (multiple-value-bind (x y) (%gcd a (- b))\n (declare (fixnum x y))\n (values x (- y))))\n (if (>= b 0)\n (multiple-value-bind (x y) (%gcd (- a) b)\n (declare (fixnum x y))\n (values (- x) y))\n (multiple-value-bind (x y) (%gcd (- a) (- b))\n (declare (fixnum x y))\n (values (- x) (- y)))))))\n\n(declaim (inline mod-inverse))\n(defun mod-inverse (a m)\n \"Solves ax ≡ 1 mod m. A and M must be coprime.\"\n (declare (integer a)\n ((integer 1 #.most-positive-fixnum) m))\n (mod (ext-gcd (mod a m) m) m))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n;; (defun %test2 (size n a)\n;; (setf a (/ a 100d0))\n;; (loop for m below size\n;; sum (* (exp (log-binomial (- m 1) (- n 1)))\n;; (expt a m)\n;; (expt (- 1 a) m))))\n\n;; (defun %test (n a b c size)\n;; (let ((a (/ a 100d0))\n;; (b (/ b 100d0))\n;; (c (/ c 100d0)))\n;; (+\n;; (loop for m below size\n;; sum (* m\n;; (exp (log-binomial (- m 1) (- n 1)))\n;; (expt a n)\n;; (loop for q to (- n 1)\n;; sum (* (exp (log-binomial (- m n) q))\n;; (expt b q)\n;; (if (>= (- m n q) 0)\n;; (expt c (- m n q))\n;; 0)))))\n;; (loop for m below size\n;; sum (* m\n;; (exp (log-binomial (- m 1) (- n 1)))\n;; (expt b n)\n;; (loop for q to (- n 1)\n;; sum (* (exp (log-binomial (- m n) q))\n;; (expt a q)\n;; (if (>= (- m n q) 0)\n;; (expt c (- m n q))\n;; 0))))))))\n\n(defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) +mod+)) args))\n\n(define-compiler-macro mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) +mod+)) args)))\n\n(defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) +mod+)) args))\n\n(define-compiler-macro mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) +mod+)) args)))\n\n(define-modify-macro incfmod (delta divisor)\n (lambda (x y divisor) (mod (+ x y) divisor)))\n\n(defun main ()\n (let* ((n (read))\n (a (read))\n (b (read))\n (a+b (+ a b))\n (inv-a+b (mod-inverse a+b +mod+))\n (c (read))\n (res 0))\n (declare ((integer 0 100) a b c)\n (uint32 n res inv-a+b)\n (ignore c))\n (loop for m from n to (- (* 2 n) 1)\n do (incfmod res\n (mod* m\n (binom (- m 1) (- n 1))\n (mod+ (mod* (power-mod a n +mod+)\n (power-mod b (- m n) +mod+))\n (mod* (power-mod b n +mod+)\n (power-mod a (- m n) +mod+)))\n (power-mod inv-a+b m +mod+))\n +mod+))\n (println (mod* res 100 inv-a+b))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1559447628, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03025.html", "problem_id": "p03025", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03025/input.txt", "sample_output_relpath": "derived/input_output/data/p03025/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03025/Lisp/s559139400.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s559139400", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n\n(declaim (inline power-mod))\n(defun power-mod (base power &optional (divisor 1000000007))\n \"BASE := integer\nPOWER, DIVISOR := non-negative fixnum\"\n (declare ((integer 0 #.most-positive-fixnum) divisor)\n (integer base))\n (labels ((recur (x p)\n (cond ((zerop p) 1)\n ((evenp p) (recur (mod (* x x) divisor) (ash p -1)))\n (t (mod (* x (recur x (- p 1))) divisor)))))\n (declare (ftype (function ((unsigned-byte 32) (integer 0 #.most-positive-fixnum))\n (values (integer 0 #.most-positive-fixnum) &optional))\n recur))\n (recur (mod base divisor) power)))\n\n;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\n\n(defconstant +binom-size+ 210000)\n(defconstant +binom-mod+ #.(+ (expt 10 9) 7))\n\n(declaim ((simple-array (unsigned-byte 32) (*)) *fact* *fact-inv* *inv*))\n(defparameter *fact* (make-array +binom-size+ :element-type '(unsigned-byte 32)))\n(defparameter *fact-inv* (make-array +binom-size+ :element-type '(unsigned-byte 32)))\n(defparameter *inv* (make-array +binom-size+ :element-type '(unsigned-byte 32)))\n\n(defun initialize-binom ()\n (setf (aref *fact* 0) 1\n (aref *fact* 1) 1\n (aref *fact-inv* 0) 1\n (aref *fact-inv* 1) 1\n (aref *inv* 1) 1)\n (loop for i from 2 below +binom-size+\n do (setf (aref *fact* i) (mod (* i (aref *fact* (- i 1))) +binom-mod+)\n (aref *inv* i) (mod (- (* (aref *inv* (rem +binom-mod+ i))\n (floor +binom-mod+ i)))\n +binom-mod+)\n (aref *fact-inv* i) (mod (* (aref *inv* i)\n (aref *fact-inv* (- i 1)))\n +binom-mod+))))\n\n(initialize-binom)\n\n(declaim (inline binom))\n(defun binom (n k)\n \"Returns nCk.\"\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (mod (* (aref *fact* n)\n (mod (* (aref *fact-inv* k) (aref *fact-inv* (- n k))) +binom-mod+))\n +binom-mod+)))\n\n(defun multinomial (&rest ks)\n \"Returns the multinomial coefficient K!/k_1!k_2!...k_n! for K = k_1 + k_2 +\n... + k_n. K must be equal or smaller than MOST-POSITIVE-FIXNUM. (multinomial)\nreturns 1.\"\n (let ((sum 0)\n (result 1))\n (declare ((integer 0 #.most-positive-fixnum) result sum))\n (dolist (k ks)\n (incf sum k)\n (setq result\n (mod (* result (aref *fact-inv* k)) +binom-mod+)))\n (mod (* result (aref *fact* sum)) +binom-mod+)))\n\n;; TODO: deal with bignums\n(declaim (inline ext-gcd))\n(defun ext-gcd (a b)\n \"Returns two integers X and Y where AX + BY = gcd(A, B) holds.\"\n (declare (fixnum a b))\n (labels ((%gcd (a b)\n (declare (fixnum a b))\n (if (zerop b)\n (values 1 0)\n (multiple-value-bind (p q) (floor a b) ; a = pb + q\n (multiple-value-bind (v u) (%gcd b q)\n (declare (fixnum u v))\n (values u (the fixnum (- v (the fixnum (* p u))))))))))\n (if (>= a 0)\n (if (>= b 0)\n (%gcd a b)\n (multiple-value-bind (x y) (%gcd a (- b))\n (declare (fixnum x y))\n (values x (- y))))\n (if (>= b 0)\n (multiple-value-bind (x y) (%gcd (- a) b)\n (declare (fixnum x y))\n (values (- x) y))\n (multiple-value-bind (x y) (%gcd (- a) (- b))\n (declare (fixnum x y))\n (values (- x) (- y)))))))\n\n(declaim (inline mod-inverse))\n(defun mod-inverse (a m)\n \"Solves ax ≡ 1 mod m. A and M must be coprime.\"\n (declare (integer a)\n ((integer 1 #.most-positive-fixnum) m))\n (mod (ext-gcd (mod a m) m) m))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n;; (defun %test2 (size n a)\n;; (setf a (/ a 100d0))\n;; (loop for m below size\n;; sum (* (exp (log-binomial (- m 1) (- n 1)))\n;; (expt a m)\n;; (expt (- 1 a) m))))\n\n;; (defun %test (n a b c size)\n;; (let ((a (/ a 100d0))\n;; (b (/ b 100d0))\n;; (c (/ c 100d0)))\n;; (+\n;; (loop for m below size\n;; sum (* m\n;; (exp (log-binomial (- m 1) (- n 1)))\n;; (expt a n)\n;; (loop for q to (- n 1)\n;; sum (* (exp (log-binomial (- m n) q))\n;; (expt b q)\n;; (if (>= (- m n q) 0)\n;; (expt c (- m n q))\n;; 0)))))\n;; (loop for m below size\n;; sum (* m\n;; (exp (log-binomial (- m 1) (- n 1)))\n;; (expt b n)\n;; (loop for q to (- n 1)\n;; sum (* (exp (log-binomial (- m n) q))\n;; (expt a q)\n;; (if (>= (- m n q) 0)\n;; (expt c (- m n q))\n;; 0))))))))\n\n(defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) +mod+)) args))\n\n(define-compiler-macro mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) +mod+)) args)))\n\n(defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) +mod+)) args))\n\n(define-compiler-macro mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) +mod+)) args)))\n\n(define-modify-macro incfmod (delta divisor)\n (lambda (x y divisor) (mod (+ x y) divisor)))\n\n(defun main ()\n (let* ((n (read))\n (a (read))\n (b (read))\n (a+b (+ a b))\n (inv-a+b (mod-inverse a+b +mod+))\n (c (read))\n (res 0))\n (declare ((integer 0 100) a b c)\n (uint32 n res inv-a+b)\n (ignore c))\n (loop for m from n to (- (* 2 n) 1)\n do (incfmod res\n (mod* m\n (binom (- m 1) (- n 1))\n (mod+ (mod* (power-mod a n +mod+)\n (power-mod b (- m n) +mod+))\n (mod* (power-mod b n +mod+)\n (power-mod a (- m n) +mod+)))\n (power-mod inv-a+b m +mod+))\n +mod+))\n (println (mod* res 100 inv-a+b))))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nTakahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total.\n\nWhen they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %.\nFind the expected number of games that will be played, and print it as follows.\n\nWe can represent the expected value as P/Q with coprime integers P and Q.\nPrint the integer R between 0 and 10^9+6 (inclusive) such that R \\times Q \\equiv P\\pmod {10^9+7}.\n(Such an integer R always uniquely exists under the constraints of this problem.)\n\nConstraints\n\n1 \\leq N \\leq 100000\n\n0 \\leq A,B,C \\leq 100\n\n1 \\leq A+B\n\nA+B+C=100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B C\n\nOutput\n\nPrint the expected number of games that will be played, in the manner specified in the statement.\n\nSample Input 1\n\n1 25 25 50\n\nSample Output 1\n\n2\n\nSince N=1, they will repeat the game until one of them wins.\nThe expected number of games played is 2.\n\nSample Input 2\n\n4 50 50 0\n\nSample Output 2\n\n312500008\n\nC may be 0.\n\nSample Input 3\n\n1 100 0 0\n\nSample Output 3\n\n1\n\nB may also be 0.\n\nSample Input 4\n\n100000 31 41 28\n\nSample Output 4\n\n104136146", "sample_input": "1 25 25 50\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03025", "source_text": "Score : 500 points\n\nProblem Statement\n\nTakahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total.\n\nWhen they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %.\nFind the expected number of games that will be played, and print it as follows.\n\nWe can represent the expected value as P/Q with coprime integers P and Q.\nPrint the integer R between 0 and 10^9+6 (inclusive) such that R \\times Q \\equiv P\\pmod {10^9+7}.\n(Such an integer R always uniquely exists under the constraints of this problem.)\n\nConstraints\n\n1 \\leq N \\leq 100000\n\n0 \\leq A,B,C \\leq 100\n\n1 \\leq A+B\n\nA+B+C=100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B C\n\nOutput\n\nPrint the expected number of games that will be played, in the manner specified in the statement.\n\nSample Input 1\n\n1 25 25 50\n\nSample Output 1\n\n2\n\nSince N=1, they will repeat the game until one of them wins.\nThe expected number of games played is 2.\n\nSample Input 2\n\n4 50 50 0\n\nSample Output 2\n\n312500008\n\nC may be 0.\n\nSample Input 3\n\n1 100 0 0\n\nSample Output 3\n\n1\n\nB may also be 0.\n\nSample Input 4\n\n100000 31 41 28\n\nSample Output 4\n\n104136146", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7528, "cpu_time_ms": 348, "memory_kb": 29160}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s715931110", "group_id": "codeNet:p03027", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro with-output-buffer (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (inline power-mod))\n(defun power-mod (base power &optional (divisor 1000000007))\n \"BASE := integer\nPOWER, DIVISOR := non-negative fixnum\"\n (declare ((integer 0 #.most-positive-fixnum) divisor)\n (integer base))\n (labels ((recur (x p)\n (cond ((zerop p) 1)\n ((evenp p) (recur (mod (* x x) divisor) (ash p -1)))\n (t (mod (* x (recur x (- p 1))) divisor)))))\n (declare (ftype (function ((unsigned-byte 32) (integer 0 #.most-positive-fixnum))\n (values (integer 0 #.most-positive-fixnum) &optional))\n recur))\n (recur (mod base divisor) power)))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;; TODO: deal with bignums\n(declaim (inline ext-gcd))\n(defun ext-gcd (a b)\n \"Returns two integers X and Y where AX + BY = gcd(A, B) holds.\"\n (declare (fixnum a b))\n (labels ((%gcd (a b)\n (declare (fixnum a b))\n (if (zerop b)\n (values 1 0)\n (multiple-value-bind (p q) (floor a b) ; a = pb + q\n (multiple-value-bind (v u) (%gcd b q)\n (declare (fixnum u v))\n (values u (the fixnum (- v (the fixnum (* p u))))))))))\n (if (>= a 0)\n (if (>= b 0)\n (%gcd a b)\n (multiple-value-bind (x y) (%gcd a (- b))\n (declare (fixnum x y))\n (values x (- y))))\n (if (>= b 0)\n (multiple-value-bind (x y) (%gcd (- a) b)\n (declare (fixnum x y))\n (values (- x) y))\n (multiple-value-bind (x y) (%gcd (- a) (- b))\n (declare (fixnum x y))\n (values (- x) (- y)))))))\n\n(declaim (inline mod-inverse))\n(defun mod-inverse (a m)\n \"Solves ax ≡ 1 mod m. A and M must be coprime.\"\n (declare (integer a)\n ((integer 1 #.most-positive-fixnum) m))\n (mod (ext-gcd (mod a m) m) m))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000003)\n\n;; Body\n(declaim ((simple-array uint32 (*)) *fact*))\n(defparameter *fact* (make-array 1100000 :element-type 'uint32 :initial-element 0))\n(setf (aref *fact* 0) 1)\n(loop for x from 1 below (length *fact*)\n do (setf (aref *fact* x)\n (mod (* x (aref *fact* (- x 1))) +mod+)))\n\n(defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) +mod+)) args))\n\n(define-compiler-macro mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) +mod+)) args)))\n\n(defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) +mod+)) args))\n\n(define-compiler-macro mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) +mod+)) args)))\n\n(define-modify-macro incfmod (delta divisor)\n (lambda (x y divisor) (mod (+ x y) divisor)))\n\n(defun main ()\n (let* ((q (read)))\n (declare (uint32 q))\n (dotimes (_ q)\n (let ((x (read-fixnum))\n (d (read-fixnum))\n (n (read-fixnum)))\n (declare (uint32 x d n))\n (with-output-buffer\n (if (zerop d)\n (println (power-mod x n +mod+))\n (let ((x/d (mod* x (mod-inverse d +mod+))))\n (if (or (>= n +mod+)\n (zerop x/d)\n (> (+ x/d n) +mod+))\n (println 0)\n (println\n (mod* (aref *fact* (+ x/d n -1))\n (the uint32 (mod-inverse (aref *fact* (- x/d 1)) +mod+))\n (power-mod d n +mod+)))))))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1559458140, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03027.html", "problem_id": "p03027", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03027/input.txt", "sample_output_relpath": "derived/input_output/data/p03027/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03027/Lisp/s715931110.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s715931110", "user_id": "u352600849"}, "prompt_components": {"gold_output": "9009\n916936\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro with-output-buffer (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (inline power-mod))\n(defun power-mod (base power &optional (divisor 1000000007))\n \"BASE := integer\nPOWER, DIVISOR := non-negative fixnum\"\n (declare ((integer 0 #.most-positive-fixnum) divisor)\n (integer base))\n (labels ((recur (x p)\n (cond ((zerop p) 1)\n ((evenp p) (recur (mod (* x x) divisor) (ash p -1)))\n (t (mod (* x (recur x (- p 1))) divisor)))))\n (declare (ftype (function ((unsigned-byte 32) (integer 0 #.most-positive-fixnum))\n (values (integer 0 #.most-positive-fixnum) &optional))\n recur))\n (recur (mod base divisor) power)))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;; TODO: deal with bignums\n(declaim (inline ext-gcd))\n(defun ext-gcd (a b)\n \"Returns two integers X and Y where AX + BY = gcd(A, B) holds.\"\n (declare (fixnum a b))\n (labels ((%gcd (a b)\n (declare (fixnum a b))\n (if (zerop b)\n (values 1 0)\n (multiple-value-bind (p q) (floor a b) ; a = pb + q\n (multiple-value-bind (v u) (%gcd b q)\n (declare (fixnum u v))\n (values u (the fixnum (- v (the fixnum (* p u))))))))))\n (if (>= a 0)\n (if (>= b 0)\n (%gcd a b)\n (multiple-value-bind (x y) (%gcd a (- b))\n (declare (fixnum x y))\n (values x (- y))))\n (if (>= b 0)\n (multiple-value-bind (x y) (%gcd (- a) b)\n (declare (fixnum x y))\n (values (- x) y))\n (multiple-value-bind (x y) (%gcd (- a) (- b))\n (declare (fixnum x y))\n (values (- x) (- y)))))))\n\n(declaim (inline mod-inverse))\n(defun mod-inverse (a m)\n \"Solves ax ≡ 1 mod m. A and M must be coprime.\"\n (declare (integer a)\n ((integer 1 #.most-positive-fixnum) m))\n (mod (ext-gcd (mod a m) m) m))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000003)\n\n;; Body\n(declaim ((simple-array uint32 (*)) *fact*))\n(defparameter *fact* (make-array 1100000 :element-type 'uint32 :initial-element 0))\n(setf (aref *fact* 0) 1)\n(loop for x from 1 below (length *fact*)\n do (setf (aref *fact* x)\n (mod (* x (aref *fact* (- x 1))) +mod+)))\n\n(defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) +mod+)) args))\n\n(define-compiler-macro mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) +mod+)) args)))\n\n(defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) +mod+)) args))\n\n(define-compiler-macro mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) +mod+)) args)))\n\n(define-modify-macro incfmod (delta divisor)\n (lambda (x y divisor) (mod (+ x y) divisor)))\n\n(defun main ()\n (let* ((q (read)))\n (declare (uint32 q))\n (dotimes (_ q)\n (let ((x (read-fixnum))\n (d (read-fixnum))\n (n (read-fixnum)))\n (declare (uint32 x d n))\n (with-output-buffer\n (if (zerop d)\n (println (power-mod x n +mod+))\n (let ((x/d (mod* x (mod-inverse d +mod+))))\n (if (or (>= n +mod+)\n (zerop x/d)\n (> (+ x/d n) +mod+))\n (println 0)\n (println\n (mod* (aref *fact* (+ x/d n -1))\n (the uint32 (mod-inverse (aref *fact* (- x/d 1)) +mod+))\n (power-mod d n +mod+)))))))))))\n\n#-swank(main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nConsider the following arithmetic progression with n terms:\n\nx, x + d, x + 2d, \\ldots, x + (n-1)d\n\nWhat is the product of all terms in this sequence?\nCompute the answer modulo 1\\ 000\\ 003.\n\nYou are given Q queries of this form.\nIn the i-th query, compute the answer in case x = x_i, d = d_i, n = n_i.\n\nConstraints\n\n1 \\leq Q \\leq 10^5\n\n0 \\leq x_i, d_i \\leq 1\\ 000\\ 002\n\n1 \\leq n_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nQ\nx_1 d_1 n_1\n:\nx_Q d_Q n_Q\n\nOutput\n\nPrint Q lines.\n\nIn the i-th line, print the answer for the i-th query.\n\nSample Input 1\n\n2\n7 2 4\n12345 67890 2019\n\nSample Output 1\n\n9009\n916936\n\nFor the first query, the answer is 7 \\times 9 \\times 11 \\times 13 = 9009.\nDon't forget to compute the answer modulo 1\\ 000\\ 003.", "sample_input": "2\n7 2 4\n12345 67890 2019\n"}, "reference_outputs": ["9009\n916936\n"], "source_document_id": "p03027", "source_text": "Score : 600 points\n\nProblem Statement\n\nConsider the following arithmetic progression with n terms:\n\nx, x + d, x + 2d, \\ldots, x + (n-1)d\n\nWhat is the product of all terms in this sequence?\nCompute the answer modulo 1\\ 000\\ 003.\n\nYou are given Q queries of this form.\nIn the i-th query, compute the answer in case x = x_i, d = d_i, n = n_i.\n\nConstraints\n\n1 \\leq Q \\leq 10^5\n\n0 \\leq x_i, d_i \\leq 1\\ 000\\ 002\n\n1 \\leq n_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nQ\nx_1 d_1 n_1\n:\nx_Q d_Q n_Q\n\nOutput\n\nPrint Q lines.\n\nIn the i-th line, print the answer for the i-th query.\n\nSample Input 1\n\n2\n7 2 4\n12345 67890 2019\n\nSample Output 1\n\n9009\n916936\n\nFor the first query, the answer is 7 \\times 9 \\times 11 \\times 13 = 9009.\nDon't forget to compute the answer modulo 1\\ 000\\ 003.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6165, "cpu_time_ms": 755, "memory_kb": 72164}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s929913783", "group_id": "codeNet:p03029", "input_text": "(princ (floor (/ (+ (* (read) 3) (read)) 2)))", "language": "Lisp", "metadata": {"date": 1597684191, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03029.html", "problem_id": "p03029", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03029/input.txt", "sample_output_relpath": "derived/input_output/data/p03029/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03029/Lisp/s929913783.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s929913783", "user_id": "u136500538"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(princ (floor (/ (+ (* (read) 3) (read)) 2)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe have A apples and P pieces of apple.\n\nWe can cut an apple into three pieces of apple, and make one apple pie by simmering two pieces of apple in a pan.\n\nFind the maximum number of apple pies we can make with what we have now.\n\nConstraints\n\nAll values in input are integers.\n\n0 \\leq A, P \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA P\n\nOutput\n\nPrint the maximum number of apple pies we can make with what we have.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\n3\n\nWe can first make one apple pie by simmering two of the three pieces of apple. Then, we can make two more by simmering the remaining piece and three more pieces obtained by cutting the whole apple.\n\nSample Input 2\n\n0 1\n\nSample Output 2\n\n0\n\nWe cannot make an apple pie in this case, unfortunately.\n\nSample Input 3\n\n32 21\n\nSample Output 3\n\n58", "sample_input": "1 3\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03029", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe have A apples and P pieces of apple.\n\nWe can cut an apple into three pieces of apple, and make one apple pie by simmering two pieces of apple in a pan.\n\nFind the maximum number of apple pies we can make with what we have now.\n\nConstraints\n\nAll values in input are integers.\n\n0 \\leq A, P \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA P\n\nOutput\n\nPrint the maximum number of apple pies we can make with what we have.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\n3\n\nWe can first make one apple pie by simmering two of the three pieces of apple. Then, we can make two more by simmering the remaining piece and three more pieces obtained by cutting the whole apple.\n\nSample Input 2\n\n0 1\n\nSample Output 2\n\n0\n\nWe cannot make an apple pie in this case, unfortunately.\n\nSample Input 3\n\n32 21\n\nSample Output 3\n\n58", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 45, "cpu_time_ms": 17, "memory_kb": 24296}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s558633748", "group_id": "codeNet:p03029", "input_text": "(setq a (read) p (read))\n\n(format t \"~a~%\" (floor (/ (+ p (* a 3)) 2)))", "language": "Lisp", "metadata": {"date": 1568778857, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03029.html", "problem_id": "p03029", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03029/input.txt", "sample_output_relpath": "derived/input_output/data/p03029/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03029/Lisp/s558633748.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s558633748", "user_id": "u358554431"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(setq a (read) p (read))\n\n(format t \"~a~%\" (floor (/ (+ p (* a 3)) 2)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe have A apples and P pieces of apple.\n\nWe can cut an apple into three pieces of apple, and make one apple pie by simmering two pieces of apple in a pan.\n\nFind the maximum number of apple pies we can make with what we have now.\n\nConstraints\n\nAll values in input are integers.\n\n0 \\leq A, P \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA P\n\nOutput\n\nPrint the maximum number of apple pies we can make with what we have.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\n3\n\nWe can first make one apple pie by simmering two of the three pieces of apple. Then, we can make two more by simmering the remaining piece and three more pieces obtained by cutting the whole apple.\n\nSample Input 2\n\n0 1\n\nSample Output 2\n\n0\n\nWe cannot make an apple pie in this case, unfortunately.\n\nSample Input 3\n\n32 21\n\nSample Output 3\n\n58", "sample_input": "1 3\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03029", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe have A apples and P pieces of apple.\n\nWe can cut an apple into three pieces of apple, and make one apple pie by simmering two pieces of apple in a pan.\n\nFind the maximum number of apple pies we can make with what we have now.\n\nConstraints\n\nAll values in input are integers.\n\n0 \\leq A, P \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA P\n\nOutput\n\nPrint the maximum number of apple pies we can make with what we have.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\n3\n\nWe can first make one apple pie by simmering two of the three pieces of apple. Then, we can make two more by simmering the remaining piece and three more pieces obtained by cutting the whole apple.\n\nSample Input 2\n\n0 1\n\nSample Output 2\n\n0\n\nWe cannot make an apple pie in this case, unfortunately.\n\nSample Input 3\n\n32 21\n\nSample Output 3\n\n58", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 71, "cpu_time_ms": 10, "memory_kb": 3176}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s376467745", "group_id": "codeNet:p03029", "input_text": "(setq a (read) p (read))\n(princ (nth-value 0 (floor (+ (* 3 a) p) 2)))", "language": "Lisp", "metadata": {"date": 1563246658, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03029.html", "problem_id": "p03029", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03029/input.txt", "sample_output_relpath": "derived/input_output/data/p03029/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03029/Lisp/s376467745.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s376467745", "user_id": "u480300350"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(setq a (read) p (read))\n(princ (nth-value 0 (floor (+ (* 3 a) p) 2)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe have A apples and P pieces of apple.\n\nWe can cut an apple into three pieces of apple, and make one apple pie by simmering two pieces of apple in a pan.\n\nFind the maximum number of apple pies we can make with what we have now.\n\nConstraints\n\nAll values in input are integers.\n\n0 \\leq A, P \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA P\n\nOutput\n\nPrint the maximum number of apple pies we can make with what we have.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\n3\n\nWe can first make one apple pie by simmering two of the three pieces of apple. Then, we can make two more by simmering the remaining piece and three more pieces obtained by cutting the whole apple.\n\nSample Input 2\n\n0 1\n\nSample Output 2\n\n0\n\nWe cannot make an apple pie in this case, unfortunately.\n\nSample Input 3\n\n32 21\n\nSample Output 3\n\n58", "sample_input": "1 3\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03029", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe have A apples and P pieces of apple.\n\nWe can cut an apple into three pieces of apple, and make one apple pie by simmering two pieces of apple in a pan.\n\nFind the maximum number of apple pies we can make with what we have now.\n\nConstraints\n\nAll values in input are integers.\n\n0 \\leq A, P \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA P\n\nOutput\n\nPrint the maximum number of apple pies we can make with what we have.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\n3\n\nWe can first make one apple pie by simmering two of the three pieces of apple. Then, we can make two more by simmering the remaining piece and three more pieces obtained by cutting the whole apple.\n\nSample Input 2\n\n0 1\n\nSample Output 2\n\n0\n\nWe cannot make an apple pie in this case, unfortunately.\n\nSample Input 3\n\n32 21\n\nSample Output 3\n\n58", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 70, "cpu_time_ms": 45, "memory_kb": 5988}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s598744213", "group_id": "codeNet:p03029", "input_text": "(let ((in (read-from-string (format nil \"(~A)\" (read-line)))))\n (format t \"~A~%\" (floor (+ (* (car in) 3) (cadr in)) 2)))", "language": "Lisp", "metadata": {"date": 1558919230, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03029.html", "problem_id": "p03029", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03029/input.txt", "sample_output_relpath": "derived/input_output/data/p03029/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03029/Lisp/s598744213.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s598744213", "user_id": "u608227593"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((in (read-from-string (format nil \"(~A)\" (read-line)))))\n (format t \"~A~%\" (floor (+ (* (car in) 3) (cadr in)) 2)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe have A apples and P pieces of apple.\n\nWe can cut an apple into three pieces of apple, and make one apple pie by simmering two pieces of apple in a pan.\n\nFind the maximum number of apple pies we can make with what we have now.\n\nConstraints\n\nAll values in input are integers.\n\n0 \\leq A, P \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA P\n\nOutput\n\nPrint the maximum number of apple pies we can make with what we have.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\n3\n\nWe can first make one apple pie by simmering two of the three pieces of apple. Then, we can make two more by simmering the remaining piece and three more pieces obtained by cutting the whole apple.\n\nSample Input 2\n\n0 1\n\nSample Output 2\n\n0\n\nWe cannot make an apple pie in this case, unfortunately.\n\nSample Input 3\n\n32 21\n\nSample Output 3\n\n58", "sample_input": "1 3\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03029", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe have A apples and P pieces of apple.\n\nWe can cut an apple into three pieces of apple, and make one apple pie by simmering two pieces of apple in a pan.\n\nFind the maximum number of apple pies we can make with what we have now.\n\nConstraints\n\nAll values in input are integers.\n\n0 \\leq A, P \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA P\n\nOutput\n\nPrint the maximum number of apple pies we can make with what we have.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\n3\n\nWe can first make one apple pie by simmering two of the three pieces of apple. Then, we can make two more by simmering the remaining piece and three more pieces obtained by cutting the whole apple.\n\nSample Input 2\n\n0 1\n\nSample Output 2\n\n0\n\nWe cannot make an apple pie in this case, unfortunately.\n\nSample Input 3\n\n32 21\n\nSample Output 3\n\n58", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 122, "cpu_time_ms": 236, "memory_kb": 13796}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s578504820", "group_id": "codeNet:p03030", "input_text": "(defun read-alist(N &optional (i 1) (l nil))\n (if (< N i) l\n (let ((str (format nil \"~A~13D\" (read) (- 100 (read)))))\n (read-alist N (1+ i) (cons (cons str i) l)))))\n\n(princ (mapcar #'cdr (sort (read-alist (read)) #'string< :key #'car)))", "language": "Lisp", "metadata": {"date": 1584412398, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03030.html", "problem_id": "p03030", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03030/input.txt", "sample_output_relpath": "derived/input_output/data/p03030/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03030/Lisp/s578504820.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s578504820", "user_id": "u334552723"}, "prompt_components": {"gold_output": "3\n4\n6\n1\n5\n2\n", "input_to_evaluate": "(defun read-alist(N &optional (i 1) (l nil))\n (if (< N i) l\n (let ((str (format nil \"~A~13D\" (read) (- 100 (read)))))\n (read-alist N (1+ i) (cons (cons str i) l)))))\n\n(princ (mapcar #'cdr (sort (read-alist (read)) #'string< :key #'car)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou have decided to write a book introducing good restaurants.\nThere are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i.\nNo two restaurants have the same score.\n\nYou want to introduce the restaurants in the following order:\n\nThe restaurants are arranged in lexicographical order of the names of their cities.\n\nIf there are multiple restaurants in the same city, they are arranged in descending order of score.\n\nPrint the identification numbers of the restaurants in the order they are introduced in the book.\n\nConstraints\n\n1 ≤ N ≤ 100\n\nS is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.\n\n0 ≤ P_i ≤ 100\n\nP_i is an integer.\n\nP_i ≠ P_j (1 ≤ i < j ≤ N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1 P_1\n:\nS_N P_N\n\nOutput\n\nPrint N lines. The i-th line (1 ≤ i ≤ N) should contain the identification number of the restaurant that is introduced i-th in the book.\n\nSample Input 1\n\n6\nkhabarovsk 20\nmoscow 10\nkazan 50\nkazan 35\nmoscow 60\nkhabarovsk 40\n\nSample Output 1\n\n3\n4\n6\n1\n5\n2\n\nThe lexicographical order of the names of the three cities is kazan < khabarovsk < moscow. For each of these cities, the restaurants in it are introduced in descending order of score. Thus, the restaurants are introduced in the order 3,4,6,1,5,2.\n\nSample Input 2\n\n10\nyakutsk 10\nyakutsk 20\nyakutsk 30\nyakutsk 40\nyakutsk 50\nyakutsk 60\nyakutsk 70\nyakutsk 80\nyakutsk 90\nyakutsk 100\n\nSample Output 2\n\n10\n9\n8\n7\n6\n5\n4\n3\n2\n1", "sample_input": "6\nkhabarovsk 20\nmoscow 10\nkazan 50\nkazan 35\nmoscow 60\nkhabarovsk 40\n"}, "reference_outputs": ["3\n4\n6\n1\n5\n2\n"], "source_document_id": "p03030", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou have decided to write a book introducing good restaurants.\nThere are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i.\nNo two restaurants have the same score.\n\nYou want to introduce the restaurants in the following order:\n\nThe restaurants are arranged in lexicographical order of the names of their cities.\n\nIf there are multiple restaurants in the same city, they are arranged in descending order of score.\n\nPrint the identification numbers of the restaurants in the order they are introduced in the book.\n\nConstraints\n\n1 ≤ N ≤ 100\n\nS is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.\n\n0 ≤ P_i ≤ 100\n\nP_i is an integer.\n\nP_i ≠ P_j (1 ≤ i < j ≤ N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1 P_1\n:\nS_N P_N\n\nOutput\n\nPrint N lines. The i-th line (1 ≤ i ≤ N) should contain the identification number of the restaurant that is introduced i-th in the book.\n\nSample Input 1\n\n6\nkhabarovsk 20\nmoscow 10\nkazan 50\nkazan 35\nmoscow 60\nkhabarovsk 40\n\nSample Output 1\n\n3\n4\n6\n1\n5\n2\n\nThe lexicographical order of the names of the three cities is kazan < khabarovsk < moscow. For each of these cities, the restaurants in it are introduced in descending order of score. Thus, the restaurants are introduced in the order 3,4,6,1,5,2.\n\nSample Input 2\n\n10\nyakutsk 10\nyakutsk 20\nyakutsk 30\nyakutsk 40\nyakutsk 50\nyakutsk 60\nyakutsk 70\nyakutsk 80\nyakutsk 90\nyakutsk 100\n\nSample Output 2\n\n10\n9\n8\n7\n6\n5\n4\n3\n2\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 246, "cpu_time_ms": 140, "memory_kb": 12256}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s536364873", "group_id": "codeNet:p03030", "input_text": "(defparameter N (read))\n(defparameter *lst* '())\n\n(loop for i from 1 to N do\n (defparameter name (read))\n (defparameter value (read))\n \n (push `(,name ,value ,i) *lst*))\n\n(defun tuple-compare (comparison-functions)\n (lambda (left right)\n (loop for fn in comparison-functions\n for x in left\n for y in right\n thereis (funcall fn x y)\n until (funcall fn y x))))\n\n(defparameter answer\n (sort (copy-list *lst*)\n (tuple-compare #'string-lessp #'<)))\n\n(dolist (v answer) (print (third v))", "language": "Lisp", "metadata": {"date": 1559099700, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03030.html", "problem_id": "p03030", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03030/input.txt", "sample_output_relpath": "derived/input_output/data/p03030/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03030/Lisp/s536364873.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s536364873", "user_id": "u425317134"}, "prompt_components": {"gold_output": "3\n4\n6\n1\n5\n2\n", "input_to_evaluate": "(defparameter N (read))\n(defparameter *lst* '())\n\n(loop for i from 1 to N do\n (defparameter name (read))\n (defparameter value (read))\n \n (push `(,name ,value ,i) *lst*))\n\n(defun tuple-compare (comparison-functions)\n (lambda (left right)\n (loop for fn in comparison-functions\n for x in left\n for y in right\n thereis (funcall fn x y)\n until (funcall fn y x))))\n\n(defparameter answer\n (sort (copy-list *lst*)\n (tuple-compare #'string-lessp #'<)))\n\n(dolist (v answer) (print (third v))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou have decided to write a book introducing good restaurants.\nThere are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i.\nNo two restaurants have the same score.\n\nYou want to introduce the restaurants in the following order:\n\nThe restaurants are arranged in lexicographical order of the names of their cities.\n\nIf there are multiple restaurants in the same city, they are arranged in descending order of score.\n\nPrint the identification numbers of the restaurants in the order they are introduced in the book.\n\nConstraints\n\n1 ≤ N ≤ 100\n\nS is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.\n\n0 ≤ P_i ≤ 100\n\nP_i is an integer.\n\nP_i ≠ P_j (1 ≤ i < j ≤ N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1 P_1\n:\nS_N P_N\n\nOutput\n\nPrint N lines. The i-th line (1 ≤ i ≤ N) should contain the identification number of the restaurant that is introduced i-th in the book.\n\nSample Input 1\n\n6\nkhabarovsk 20\nmoscow 10\nkazan 50\nkazan 35\nmoscow 60\nkhabarovsk 40\n\nSample Output 1\n\n3\n4\n6\n1\n5\n2\n\nThe lexicographical order of the names of the three cities is kazan < khabarovsk < moscow. For each of these cities, the restaurants in it are introduced in descending order of score. Thus, the restaurants are introduced in the order 3,4,6,1,5,2.\n\nSample Input 2\n\n10\nyakutsk 10\nyakutsk 20\nyakutsk 30\nyakutsk 40\nyakutsk 50\nyakutsk 60\nyakutsk 70\nyakutsk 80\nyakutsk 90\nyakutsk 100\n\nSample Output 2\n\n10\n9\n8\n7\n6\n5\n4\n3\n2\n1", "sample_input": "6\nkhabarovsk 20\nmoscow 10\nkazan 50\nkazan 35\nmoscow 60\nkhabarovsk 40\n"}, "reference_outputs": ["3\n4\n6\n1\n5\n2\n"], "source_document_id": "p03030", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou have decided to write a book introducing good restaurants.\nThere are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i.\nNo two restaurants have the same score.\n\nYou want to introduce the restaurants in the following order:\n\nThe restaurants are arranged in lexicographical order of the names of their cities.\n\nIf there are multiple restaurants in the same city, they are arranged in descending order of score.\n\nPrint the identification numbers of the restaurants in the order they are introduced in the book.\n\nConstraints\n\n1 ≤ N ≤ 100\n\nS is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.\n\n0 ≤ P_i ≤ 100\n\nP_i is an integer.\n\nP_i ≠ P_j (1 ≤ i < j ≤ N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1 P_1\n:\nS_N P_N\n\nOutput\n\nPrint N lines. The i-th line (1 ≤ i ≤ N) should contain the identification number of the restaurant that is introduced i-th in the book.\n\nSample Input 1\n\n6\nkhabarovsk 20\nmoscow 10\nkazan 50\nkazan 35\nmoscow 60\nkhabarovsk 40\n\nSample Output 1\n\n3\n4\n6\n1\n5\n2\n\nThe lexicographical order of the names of the three cities is kazan < khabarovsk < moscow. For each of these cities, the restaurants in it are introduced in descending order of score. Thus, the restaurants are introduced in the order 3,4,6,1,5,2.\n\nSample Input 2\n\n10\nyakutsk 10\nyakutsk 20\nyakutsk 30\nyakutsk 40\nyakutsk 50\nyakutsk 60\nyakutsk 70\nyakutsk 80\nyakutsk 90\nyakutsk 100\n\nSample Output 2\n\n10\n9\n8\n7\n6\n5\n4\n3\n2\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 549, "cpu_time_ms": 138, "memory_kb": 13928}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s040938359", "group_id": "codeNet:p03030", "input_text": "(defun main ()\n (let ((N (read))\n (lst (list nil))\n (count 1))\n (dotimes (x N)\n (let ((S (read))\n (P (read)))\n (push (cons S (cons P count)) lst)\n (incf count)))\n (setq lst (cdr (reverse lst)))\n (sort lst (lambda (x y) (string-lessp (car x) (car y))))\n (sort lst (lambda (x y) (and (string= (car x) (car y)) (> (cadr x) (cadr y)))))\n (dolist (x lst)\n (print (cddr x)))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1558920681, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03030.html", "problem_id": "p03030", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03030/input.txt", "sample_output_relpath": "derived/input_output/data/p03030/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03030/Lisp/s040938359.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s040938359", "user_id": "u631655863"}, "prompt_components": {"gold_output": "3\n4\n6\n1\n5\n2\n", "input_to_evaluate": "(defun main ()\n (let ((N (read))\n (lst (list nil))\n (count 1))\n (dotimes (x N)\n (let ((S (read))\n (P (read)))\n (push (cons S (cons P count)) lst)\n (incf count)))\n (setq lst (cdr (reverse lst)))\n (sort lst (lambda (x y) (string-lessp (car x) (car y))))\n (sort lst (lambda (x y) (and (string= (car x) (car y)) (> (cadr x) (cadr y)))))\n (dolist (x lst)\n (print (cddr x)))))\n\n(main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou have decided to write a book introducing good restaurants.\nThere are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i.\nNo two restaurants have the same score.\n\nYou want to introduce the restaurants in the following order:\n\nThe restaurants are arranged in lexicographical order of the names of their cities.\n\nIf there are multiple restaurants in the same city, they are arranged in descending order of score.\n\nPrint the identification numbers of the restaurants in the order they are introduced in the book.\n\nConstraints\n\n1 ≤ N ≤ 100\n\nS is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.\n\n0 ≤ P_i ≤ 100\n\nP_i is an integer.\n\nP_i ≠ P_j (1 ≤ i < j ≤ N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1 P_1\n:\nS_N P_N\n\nOutput\n\nPrint N lines. The i-th line (1 ≤ i ≤ N) should contain the identification number of the restaurant that is introduced i-th in the book.\n\nSample Input 1\n\n6\nkhabarovsk 20\nmoscow 10\nkazan 50\nkazan 35\nmoscow 60\nkhabarovsk 40\n\nSample Output 1\n\n3\n4\n6\n1\n5\n2\n\nThe lexicographical order of the names of the three cities is kazan < khabarovsk < moscow. For each of these cities, the restaurants in it are introduced in descending order of score. Thus, the restaurants are introduced in the order 3,4,6,1,5,2.\n\nSample Input 2\n\n10\nyakutsk 10\nyakutsk 20\nyakutsk 30\nyakutsk 40\nyakutsk 50\nyakutsk 60\nyakutsk 70\nyakutsk 80\nyakutsk 90\nyakutsk 100\n\nSample Output 2\n\n10\n9\n8\n7\n6\n5\n4\n3\n2\n1", "sample_input": "6\nkhabarovsk 20\nmoscow 10\nkazan 50\nkazan 35\nmoscow 60\nkhabarovsk 40\n"}, "reference_outputs": ["3\n4\n6\n1\n5\n2\n"], "source_document_id": "p03030", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou have decided to write a book introducing good restaurants.\nThere are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i.\nNo two restaurants have the same score.\n\nYou want to introduce the restaurants in the following order:\n\nThe restaurants are arranged in lexicographical order of the names of their cities.\n\nIf there are multiple restaurants in the same city, they are arranged in descending order of score.\n\nPrint the identification numbers of the restaurants in the order they are introduced in the book.\n\nConstraints\n\n1 ≤ N ≤ 100\n\nS is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.\n\n0 ≤ P_i ≤ 100\n\nP_i is an integer.\n\nP_i ≠ P_j (1 ≤ i < j ≤ N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1 P_1\n:\nS_N P_N\n\nOutput\n\nPrint N lines. The i-th line (1 ≤ i ≤ N) should contain the identification number of the restaurant that is introduced i-th in the book.\n\nSample Input 1\n\n6\nkhabarovsk 20\nmoscow 10\nkazan 50\nkazan 35\nmoscow 60\nkhabarovsk 40\n\nSample Output 1\n\n3\n4\n6\n1\n5\n2\n\nThe lexicographical order of the names of the three cities is kazan < khabarovsk < moscow. For each of these cities, the restaurants in it are introduced in descending order of score. Thus, the restaurants are introduced in the order 3,4,6,1,5,2.\n\nSample Input 2\n\n10\nyakutsk 10\nyakutsk 20\nyakutsk 30\nyakutsk 40\nyakutsk 50\nyakutsk 60\nyakutsk 70\nyakutsk 80\nyakutsk 90\nyakutsk 100\n\nSample Output 2\n\n10\n9\n8\n7\n6\n5\n4\n3\n2\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 444, "cpu_time_ms": 115, "memory_kb": 12388}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s766894553", "group_id": "codeNet:p03033", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(setf *print-circle* t)\n\n(defconstant +op-identity+ most-positive-fixnum)\n\n(declaim (inline op))\n(defun op (x y)\n (min x y))\n\n(defconstant +updater-identity+ most-positive-fixnum)\n\n(declaim (inline updater-op))\n(defun updater-op (a b)\n \"Is the operator to compute and update LAZY value.\"\n (declare (fixnum a b))\n (min a b))\n\n(declaim (inline modifier-op))\n(defun modifier-op (a b size)\n \"Is the operator to update ACCUMULATOR based on LAZY value.\"\n (declare (ignore size))\n (declare (fixnum a b))\n (min a b))\n\n(declaim (inline treap-order))\n(defun treap-order (x y)\n (declare (fixnum x y))\n (< x y))\n\n;; Treap with explicit key\n(defstruct (treap (:constructor %make-treap (key priority value accumulator &key left right lazy (count 1)))\n (:copier nil)\n (:conc-name %treap-))\n (key 0 :type fixnum)\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum)\n (lazy +updater-identity+ :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 0 :type (integer 0 #.most-positive-fixnum))\n (left nil :type (or null treap))\n (right nil :type (or null treap)))\n\n(declaim (inline treap-count))\n(defun treap-count (treap)\n \"Returns the size of the (nullable) TREAP.\"\n (declare ((or null treap) treap))\n (if (null treap)\n 0\n (%treap-count treap)))\n\n(declaim (inline treap-accumulator))\n(defun treap-accumulator (treap)\n (declare ((or null treap) treap))\n (if (null treap)\n +op-identity+\n (%treap-accumulator treap)))\n\n(declaim (inline update-count))\n(defun update-count (treap)\n (declare (treap treap))\n (setf (%treap-count treap)\n (+ 1\n (treap-count (%treap-left treap))\n (treap-count (%treap-right treap)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (treap)\n (declare (treap treap))\n (setf (%treap-accumulator treap)\n (if (%treap-left treap)\n (if (%treap-right treap)\n (let ((mid-res (op (%treap-accumulator (%treap-left treap))\n (%treap-value treap))))\n (declare (dynamic-extent mid-res))\n (op mid-res (%treap-accumulator (%treap-right treap))))\n (op (%treap-accumulator (%treap-left treap))\n (%treap-value treap)))\n (if (%treap-right treap)\n (op (%treap-value treap)\n (%treap-accumulator (%treap-right treap)))\n (%treap-value treap)))))\n\n(declaim (inline force-self))\n(defun force-self (treap)\n (declare (treap treap))\n (update-count treap)\n (update-accumulator treap))\n\n(declaim (inline force-down))\n(defun force-down (treap)\n (declare (treap treap))\n (unless (eql +updater-identity+ (%treap-lazy treap))\n (when (%treap-left treap)\n (setf (%treap-lazy (%treap-left treap))\n (updater-op (%treap-lazy (%treap-left treap))\n (%treap-lazy treap)))\n (setf (%treap-accumulator (%treap-left treap))\n (modifier-op (%treap-accumulator (%treap-left treap))\n (%treap-lazy treap)\n (%treap-count (%treap-left treap)))))\n (when (%treap-right treap)\n (setf (%treap-lazy (%treap-right treap))\n (updater-op (%treap-lazy (%treap-right treap))\n (%treap-lazy treap)))\n (setf (%treap-accumulator (%treap-right treap))\n (modifier-op (%treap-accumulator (%treap-right treap))\n (%treap-lazy treap)\n (%treap-count (%treap-right treap)))))\n (setf (%treap-value treap)\n (modifier-op (%treap-value treap)\n (%treap-lazy treap)\n 1))\n (setf (%treap-lazy treap) +updater-identity+)))\n\n(defun treap-find (key treap)\n \"Finds the key that satisfies (and (not (funcall test key (%treap-key\nsub-treap))) (not (funcall test (%treap-key sub-treap) key))) and returns\nthe corresponding value. Returns NIL if KEY is not contained.\"\n (declare #.OPT ((or null treap) treap))\n (labels ((recur (treap)\n (unless treap (return-from treap-find nil))\n (force-down treap)\n (prog1\n (cond ((treap-order key (%treap-key treap))\n (recur (%treap-left treap)))\n ((treap-order (%treap-key treap) key)\n (recur (%treap-right treap)))\n (t (%treap-value treap)))\n (force-self treap))))\n (recur treap)))\n\n(defun treap-split (key treap)\n \"Destructively splits the TREAP with reference to KEY and returns two treaps,\nthe smaller sub-treap (< KEY) and the larger one (>= KEY).\"\n (declare #.OPT ((or null treap) treap))\n (labels ((recur (treap)\n (if (null treap)\n (values nil nil)\n (progn\n (force-down treap)\n (if (treap-order (%treap-key treap) key)\n (multiple-value-bind (left right)\n (recur (%treap-right treap))\n (setf (%treap-right treap) left)\n (force-self treap)\n (values treap right))\n (multiple-value-bind (left right)\n (recur (%treap-left treap))\n (setf (%treap-left treap) right)\n (force-self treap)\n (values left treap)))))))\n (recur treap)))\n\n(defun treap-insert (key value treap)\n \"Destructively inserts KEY into TREAP and returns the resultant treap. You\ncannot rely on the side effect. Use the returned value.\n\nThe behavior is undefined when duplicated keys are inserted.\"\n (declare ((or null treap) treap))\n (labels ((recur (node treap)\n (declare (treap node))\n (unless treap (return-from recur node))\n (force-down treap)\n (if (> (%treap-priority node) (%treap-priority treap))\n (progn\n (setf (values (%treap-left node) (%treap-right node))\n (treap-split (%treap-key node) treap))\n (force-self node)\n node)\n (progn\n (if (treap-order (%treap-key node) (%treap-key treap))\n (setf (%treap-left treap)\n (recur node (%treap-left treap)))\n (setf (%treap-right treap)\n (recur node (%treap-right treap))))\n (force-self treap)\n treap))))\n (recur (%make-treap key (random most-positive-fixnum) value value) treap)))\n\n(declaim (inline treap-ensure-key))\n(defun treap-ensure-key (key value treap &key if-exists)\n \"IF-EXISTS := nil | function\n\nEnsures that TREAP contains KEY and assigns VALUE to it if IF-EXISTS is\nfalse. If IF-EXISTS is function and TREAP contains KEY, TREAP-ENSURE-KEY updates\nthe value by the function instead of overwriting it with VALUE.\"\n (declare #.OPT\n ((or null function) if-exists)\n ((or null treap) treap))\n (labels ((find-and-update (treap)\n ;; Updates the value slot and returns T if KEY exists\n (unless treap (return-from find-and-update nil))\n (force-down treap)\n (cond ((treap-order key (%treap-key treap))\n (when (find-and-update (%treap-left treap))\n (force-self treap)\n t))\n ((treap-order (%treap-key treap) key)\n (when (find-and-update (%treap-right treap))\n (force-self treap)\n t))\n (t (setf (%treap-value treap)\n (if if-exists\n (funcall if-exists (%treap-value treap))\n value))\n (force-self treap)\n t))))\n (if (find-and-update treap)\n treap\n (treap-insert key value treap))))\n\n(defun treap-merge (left right)\n \"Destructively merges two treaps. Assumes that all keys of LEFT are smaller\n (or larger, depending on the order) than those of RIGHT.\"\n (declare #.OPT ((or null treap) left right))\n (cond ((null left) (when right (force-down right) (force-self right)) right)\n ((null right) (when left (force-down left) (force-self left)) left)\n (t (force-down left)\n (force-down right)\n (if (> (%treap-priority left) (%treap-priority right))\n (progn\n (setf (%treap-right left)\n (treap-merge (%treap-right left) right))\n (force-self left)\n left)\n (progn\n (setf (%treap-left right)\n (treap-merge left (%treap-left right)))\n (force-self right)\n right)))))\n\n(defun treap-map (function treap)\n \"Successively applies FUNCTION to TREAP[0], ..., TREAP[SIZE-1]. FUNCTION must\ntake two arguments: KEY and VALUE.\"\n (declare (function function))\n (when treap\n (force-down treap)\n (treap-map function (%treap-left treap))\n (funcall function (%treap-key treap) (%treap-value treap))\n (treap-map function (%treap-right treap))\n (force-self treap)))\n\n(defmethod print-object ((object treap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (treap-map (lambda (key value)\n (if init\n (setf init nil)\n (write-char #\\ stream))\n (format stream \"<~A . ~A>\" key value))\n object))))\n\n\n(defun treap-update (treap x left right)\n \"Updates TREAP[KEY] := (OP TREAP[KEY] X) for all KEY in [l, r)\"\n (declare #.OPT ((or null treap) treap))\n (assert (not (treap-order right left)))\n (multiple-value-bind (treap-0-l treap-l-n)\n (treap-split left treap)\n (multiple-value-bind (treap-l-r treap-r-n)\n (treap-split right treap-l-n)\n (when treap-l-r\n (setf (%treap-lazy treap-l-r)\n (updater-op (%treap-lazy treap-l-r) x)))\n (treap-merge treap-0-l (treap-merge treap-l-r treap-r-n)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT (inline sort))\n (let* ((n (read))\n (q (read))\n (ds (make-array q :element-type 'uint32))\n (ss (make-array n :element-type 'uint32))\n (ts (make-array n :element-type 'uint32))\n (xs (make-array n :element-type 'uint32))\n treap)\n (declare (uint31 n q))\n (dotimes (i n)\n (let ((s (read-fixnum))\n (end (read-fixnum))\n (x (read-fixnum)))\n (setf (aref ss i) s\n (aref ts i) end\n (aref xs i) x)\n (setf treap (treap-ensure-key (- s x) most-positive-fixnum treap))\n (setf treap (treap-ensure-key (- end x) most-positive-fixnum treap))))\n (dotimes (i q)\n (let ((d (read-fixnum)))\n (setf (aref ds i) d)\n (setf treap (treap-ensure-key d most-positive-fixnum treap))))\n (dotimes (i n)\n (setf treap\n (treap-update treap\n (aref xs i)\n (- (aref ss i) (aref xs i))\n (- (aref ts i) (aref xs i)))))\n (dotimes (i q)\n (let ((d (aref ds i)))\n (let ((res (treap-find d treap)))\n (if (< (the fixnum res) most-positive-fixnum)\n (println res)\n (println -1)))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1558928612, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03033.html", "problem_id": "p03033", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03033/input.txt", "sample_output_relpath": "derived/input_output/data/p03033/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03033/Lisp/s766894553.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s766894553", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n2\n10\n-1\n13\n-1\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(setf *print-circle* t)\n\n(defconstant +op-identity+ most-positive-fixnum)\n\n(declaim (inline op))\n(defun op (x y)\n (min x y))\n\n(defconstant +updater-identity+ most-positive-fixnum)\n\n(declaim (inline updater-op))\n(defun updater-op (a b)\n \"Is the operator to compute and update LAZY value.\"\n (declare (fixnum a b))\n (min a b))\n\n(declaim (inline modifier-op))\n(defun modifier-op (a b size)\n \"Is the operator to update ACCUMULATOR based on LAZY value.\"\n (declare (ignore size))\n (declare (fixnum a b))\n (min a b))\n\n(declaim (inline treap-order))\n(defun treap-order (x y)\n (declare (fixnum x y))\n (< x y))\n\n;; Treap with explicit key\n(defstruct (treap (:constructor %make-treap (key priority value accumulator &key left right lazy (count 1)))\n (:copier nil)\n (:conc-name %treap-))\n (key 0 :type fixnum)\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum)\n (lazy +updater-identity+ :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 0 :type (integer 0 #.most-positive-fixnum))\n (left nil :type (or null treap))\n (right nil :type (or null treap)))\n\n(declaim (inline treap-count))\n(defun treap-count (treap)\n \"Returns the size of the (nullable) TREAP.\"\n (declare ((or null treap) treap))\n (if (null treap)\n 0\n (%treap-count treap)))\n\n(declaim (inline treap-accumulator))\n(defun treap-accumulator (treap)\n (declare ((or null treap) treap))\n (if (null treap)\n +op-identity+\n (%treap-accumulator treap)))\n\n(declaim (inline update-count))\n(defun update-count (treap)\n (declare (treap treap))\n (setf (%treap-count treap)\n (+ 1\n (treap-count (%treap-left treap))\n (treap-count (%treap-right treap)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (treap)\n (declare (treap treap))\n (setf (%treap-accumulator treap)\n (if (%treap-left treap)\n (if (%treap-right treap)\n (let ((mid-res (op (%treap-accumulator (%treap-left treap))\n (%treap-value treap))))\n (declare (dynamic-extent mid-res))\n (op mid-res (%treap-accumulator (%treap-right treap))))\n (op (%treap-accumulator (%treap-left treap))\n (%treap-value treap)))\n (if (%treap-right treap)\n (op (%treap-value treap)\n (%treap-accumulator (%treap-right treap)))\n (%treap-value treap)))))\n\n(declaim (inline force-self))\n(defun force-self (treap)\n (declare (treap treap))\n (update-count treap)\n (update-accumulator treap))\n\n(declaim (inline force-down))\n(defun force-down (treap)\n (declare (treap treap))\n (unless (eql +updater-identity+ (%treap-lazy treap))\n (when (%treap-left treap)\n (setf (%treap-lazy (%treap-left treap))\n (updater-op (%treap-lazy (%treap-left treap))\n (%treap-lazy treap)))\n (setf (%treap-accumulator (%treap-left treap))\n (modifier-op (%treap-accumulator (%treap-left treap))\n (%treap-lazy treap)\n (%treap-count (%treap-left treap)))))\n (when (%treap-right treap)\n (setf (%treap-lazy (%treap-right treap))\n (updater-op (%treap-lazy (%treap-right treap))\n (%treap-lazy treap)))\n (setf (%treap-accumulator (%treap-right treap))\n (modifier-op (%treap-accumulator (%treap-right treap))\n (%treap-lazy treap)\n (%treap-count (%treap-right treap)))))\n (setf (%treap-value treap)\n (modifier-op (%treap-value treap)\n (%treap-lazy treap)\n 1))\n (setf (%treap-lazy treap) +updater-identity+)))\n\n(defun treap-find (key treap)\n \"Finds the key that satisfies (and (not (funcall test key (%treap-key\nsub-treap))) (not (funcall test (%treap-key sub-treap) key))) and returns\nthe corresponding value. Returns NIL if KEY is not contained.\"\n (declare #.OPT ((or null treap) treap))\n (labels ((recur (treap)\n (unless treap (return-from treap-find nil))\n (force-down treap)\n (prog1\n (cond ((treap-order key (%treap-key treap))\n (recur (%treap-left treap)))\n ((treap-order (%treap-key treap) key)\n (recur (%treap-right treap)))\n (t (%treap-value treap)))\n (force-self treap))))\n (recur treap)))\n\n(defun treap-split (key treap)\n \"Destructively splits the TREAP with reference to KEY and returns two treaps,\nthe smaller sub-treap (< KEY) and the larger one (>= KEY).\"\n (declare #.OPT ((or null treap) treap))\n (labels ((recur (treap)\n (if (null treap)\n (values nil nil)\n (progn\n (force-down treap)\n (if (treap-order (%treap-key treap) key)\n (multiple-value-bind (left right)\n (recur (%treap-right treap))\n (setf (%treap-right treap) left)\n (force-self treap)\n (values treap right))\n (multiple-value-bind (left right)\n (recur (%treap-left treap))\n (setf (%treap-left treap) right)\n (force-self treap)\n (values left treap)))))))\n (recur treap)))\n\n(defun treap-insert (key value treap)\n \"Destructively inserts KEY into TREAP and returns the resultant treap. You\ncannot rely on the side effect. Use the returned value.\n\nThe behavior is undefined when duplicated keys are inserted.\"\n (declare ((or null treap) treap))\n (labels ((recur (node treap)\n (declare (treap node))\n (unless treap (return-from recur node))\n (force-down treap)\n (if (> (%treap-priority node) (%treap-priority treap))\n (progn\n (setf (values (%treap-left node) (%treap-right node))\n (treap-split (%treap-key node) treap))\n (force-self node)\n node)\n (progn\n (if (treap-order (%treap-key node) (%treap-key treap))\n (setf (%treap-left treap)\n (recur node (%treap-left treap)))\n (setf (%treap-right treap)\n (recur node (%treap-right treap))))\n (force-self treap)\n treap))))\n (recur (%make-treap key (random most-positive-fixnum) value value) treap)))\n\n(declaim (inline treap-ensure-key))\n(defun treap-ensure-key (key value treap &key if-exists)\n \"IF-EXISTS := nil | function\n\nEnsures that TREAP contains KEY and assigns VALUE to it if IF-EXISTS is\nfalse. If IF-EXISTS is function and TREAP contains KEY, TREAP-ENSURE-KEY updates\nthe value by the function instead of overwriting it with VALUE.\"\n (declare #.OPT\n ((or null function) if-exists)\n ((or null treap) treap))\n (labels ((find-and-update (treap)\n ;; Updates the value slot and returns T if KEY exists\n (unless treap (return-from find-and-update nil))\n (force-down treap)\n (cond ((treap-order key (%treap-key treap))\n (when (find-and-update (%treap-left treap))\n (force-self treap)\n t))\n ((treap-order (%treap-key treap) key)\n (when (find-and-update (%treap-right treap))\n (force-self treap)\n t))\n (t (setf (%treap-value treap)\n (if if-exists\n (funcall if-exists (%treap-value treap))\n value))\n (force-self treap)\n t))))\n (if (find-and-update treap)\n treap\n (treap-insert key value treap))))\n\n(defun treap-merge (left right)\n \"Destructively merges two treaps. Assumes that all keys of LEFT are smaller\n (or larger, depending on the order) than those of RIGHT.\"\n (declare #.OPT ((or null treap) left right))\n (cond ((null left) (when right (force-down right) (force-self right)) right)\n ((null right) (when left (force-down left) (force-self left)) left)\n (t (force-down left)\n (force-down right)\n (if (> (%treap-priority left) (%treap-priority right))\n (progn\n (setf (%treap-right left)\n (treap-merge (%treap-right left) right))\n (force-self left)\n left)\n (progn\n (setf (%treap-left right)\n (treap-merge left (%treap-left right)))\n (force-self right)\n right)))))\n\n(defun treap-map (function treap)\n \"Successively applies FUNCTION to TREAP[0], ..., TREAP[SIZE-1]. FUNCTION must\ntake two arguments: KEY and VALUE.\"\n (declare (function function))\n (when treap\n (force-down treap)\n (treap-map function (%treap-left treap))\n (funcall function (%treap-key treap) (%treap-value treap))\n (treap-map function (%treap-right treap))\n (force-self treap)))\n\n(defmethod print-object ((object treap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((init t))\n (treap-map (lambda (key value)\n (if init\n (setf init nil)\n (write-char #\\ stream))\n (format stream \"<~A . ~A>\" key value))\n object))))\n\n\n(defun treap-update (treap x left right)\n \"Updates TREAP[KEY] := (OP TREAP[KEY] X) for all KEY in [l, r)\"\n (declare #.OPT ((or null treap) treap))\n (assert (not (treap-order right left)))\n (multiple-value-bind (treap-0-l treap-l-n)\n (treap-split left treap)\n (multiple-value-bind (treap-l-r treap-r-n)\n (treap-split right treap-l-n)\n (when treap-l-r\n (setf (%treap-lazy treap-l-r)\n (updater-op (%treap-lazy treap-l-r) x)))\n (treap-merge treap-0-l (treap-merge treap-l-r treap-r-n)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT (inline sort))\n (let* ((n (read))\n (q (read))\n (ds (make-array q :element-type 'uint32))\n (ss (make-array n :element-type 'uint32))\n (ts (make-array n :element-type 'uint32))\n (xs (make-array n :element-type 'uint32))\n treap)\n (declare (uint31 n q))\n (dotimes (i n)\n (let ((s (read-fixnum))\n (end (read-fixnum))\n (x (read-fixnum)))\n (setf (aref ss i) s\n (aref ts i) end\n (aref xs i) x)\n (setf treap (treap-ensure-key (- s x) most-positive-fixnum treap))\n (setf treap (treap-ensure-key (- end x) most-positive-fixnum treap))))\n (dotimes (i q)\n (let ((d (read-fixnum)))\n (setf (aref ds i) d)\n (setf treap (treap-ensure-key d most-positive-fixnum treap))))\n (dotimes (i n)\n (setf treap\n (treap-update treap\n (aref xs i)\n (- (aref ss i) (aref xs i))\n (- (aref ts i) (aref xs i)))))\n (dotimes (i q)\n (let ((d (aref ds i)))\n (let ((res (treap-find d treap)))\n (if (< (the fixnum res) most-positive-fixnum)\n (println res)\n (println -1)))))))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere is an infinitely long street that runs west to east, which we consider as a number line.\n\nThere are N roadworks scheduled on this street.\nThe i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5.\n\nQ people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point.\n\nFind the distance each of the Q people will walk.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N, Q \\leq 2 \\times 10^5\n\n0 \\leq S_i < T_i \\leq 10^9\n\n1 \\leq X_i \\leq 10^9\n\n0 \\leq D_1 < D_2 < ... < D_Q \\leq 10^9\n\nIf i \\neq j and X_i = X_j, the intervals [S_i, T_i) and [S_j, T_j) do not overlap.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nS_1 T_1 X_1\n:\nS_N T_N X_N\nD_1\n:\nD_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever.\n\nSample Input 1\n\n4 6\n1 3 2\n7 13 10\n18 20 13\n3 4 2\n0\n1\n2\n3\n5\n8\n\nSample Output 1\n\n2\n2\n10\n-1\n13\n-1\n\nThe first person starts coordinate 0 at time 0 and stops walking at coordinate 2 when reaching a point blocked by the first roadwork at time 2.\n\nThe second person starts coordinate 0 at time 1 and reaches coordinate 2 at time 3. The first roadwork has ended, but the fourth roadwork has begun, so this person also stops walking at coordinate 2.\n\nThe fourth and sixth persons encounter no roadworks while walking, so they walk forever. The output for these cases is -1.", "sample_input": "4 6\n1 3 2\n7 13 10\n18 20 13\n3 4 2\n0\n1\n2\n3\n5\n8\n"}, "reference_outputs": ["2\n2\n10\n-1\n13\n-1\n"], "source_document_id": "p03033", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere is an infinitely long street that runs west to east, which we consider as a number line.\n\nThere are N roadworks scheduled on this street.\nThe i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5.\n\nQ people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point.\n\nFind the distance each of the Q people will walk.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N, Q \\leq 2 \\times 10^5\n\n0 \\leq S_i < T_i \\leq 10^9\n\n1 \\leq X_i \\leq 10^9\n\n0 \\leq D_1 < D_2 < ... < D_Q \\leq 10^9\n\nIf i \\neq j and X_i = X_j, the intervals [S_i, T_i) and [S_j, T_j) do not overlap.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nS_1 T_1 X_1\n:\nS_N T_N X_N\nD_1\n:\nD_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever.\n\nSample Input 1\n\n4 6\n1 3 2\n7 13 10\n18 20 13\n3 4 2\n0\n1\n2\n3\n5\n8\n\nSample Output 1\n\n2\n2\n10\n-1\n13\n-1\n\nThe first person starts coordinate 0 at time 0 and stops walking at coordinate 2 when reaching a point blocked by the first roadwork at time 2.\n\nThe second person starts coordinate 0 at time 1 and reaches coordinate 2 at time 3. The first roadwork has ended, but the fourth roadwork has begun, so this person also stops walking at coordinate 2.\n\nThe fourth and sixth persons encounter no roadworks while walking, so they walk forever. The output for these cases is -1.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 13853, "cpu_time_ms": 1946, "memory_kb": 79840}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s420188159", "group_id": "codeNet:p03035", "input_text": "(defun solve (a b)\n (cond\n ((< a 6) 0)\n ((<= 6 a 12) (floor b 2))\n (t b)))\n\n(let ((a (read))\n (b (read)))\n (cond\n (princ (solve a b))))", "language": "Lisp", "metadata": {"date": 1590712906, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03035.html", "problem_id": "p03035", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03035/input.txt", "sample_output_relpath": "derived/input_output/data/p03035/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03035/Lisp/s420188159.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s420188159", "user_id": "u425762225"}, "prompt_components": {"gold_output": "100\n", "input_to_evaluate": "(defun solve (a b)\n (cond\n ((< a 6) 0)\n ((<= 6 a 12) (floor b 2))\n (t b)))\n\n(let ((a (read))\n (b (read)))\n (cond\n (princ (solve a b))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi, who is A years old, is riding a Ferris wheel.\n\nIt costs B yen (B is an even number) to ride the Ferris wheel if you are 13 years old or older, but children between 6 and 12 years old (inclusive) can ride it for half the cost, and children who are 5 years old or younger are free of charge. (Yen is the currency of Japan.)\n\nFind the cost of the Ferris wheel for Takahashi.\n\nConstraints\n\n0 ≤ A ≤ 100\n\n2 ≤ B ≤ 1000\n\nB is an even number.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the cost of the Ferris wheel for Takahashi.\n\nSample Input 1\n\n30 100\n\nSample Output 1\n\n100\n\nTakahashi is 30 years old now, and the cost of the Ferris wheel is 100 yen.\n\nSample Input 2\n\n12 100\n\nSample Output 2\n\n50\n\nTakahashi is 12 years old, and the cost of the Ferris wheel is the half of 100 yen, that is, 50 yen.\n\nSample Input 3\n\n0 100\n\nSample Output 3\n\n0\n\nTakahashi is 0 years old, and he can ride the Ferris wheel for free.", "sample_input": "30 100\n"}, "reference_outputs": ["100\n"], "source_document_id": "p03035", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi, who is A years old, is riding a Ferris wheel.\n\nIt costs B yen (B is an even number) to ride the Ferris wheel if you are 13 years old or older, but children between 6 and 12 years old (inclusive) can ride it for half the cost, and children who are 5 years old or younger are free of charge. (Yen is the currency of Japan.)\n\nFind the cost of the Ferris wheel for Takahashi.\n\nConstraints\n\n0 ≤ A ≤ 100\n\n2 ≤ B ≤ 1000\n\nB is an even number.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the cost of the Ferris wheel for Takahashi.\n\nSample Input 1\n\n30 100\n\nSample Output 1\n\n100\n\nTakahashi is 30 years old now, and the cost of the Ferris wheel is 100 yen.\n\nSample Input 2\n\n12 100\n\nSample Output 2\n\n50\n\nTakahashi is 12 years old, and the cost of the Ferris wheel is the half of 100 yen, that is, 50 yen.\n\nSample Input 3\n\n0 100\n\nSample Output 3\n\n0\n\nTakahashi is 0 years old, and he can ride the Ferris wheel for free.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 170, "cpu_time_ms": 64, "memory_kb": 7144}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s491816003", "group_id": "codeNet:p03035", "input_text": "(defun answer (age price)\n (if (< age 6)\n 0\n (if (< age 13)\n (/ price 2)\n price)))\n\n(defparameter a (car (read)))\n(defparameter b (second (read)))\n\n(print (answer a b))", "language": "Lisp", "metadata": {"date": 1558902538, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03035.html", "problem_id": "p03035", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03035/input.txt", "sample_output_relpath": "derived/input_output/data/p03035/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03035/Lisp/s491816003.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s491816003", "user_id": "u425317134"}, "prompt_components": {"gold_output": "100\n", "input_to_evaluate": "(defun answer (age price)\n (if (< age 6)\n 0\n (if (< age 13)\n (/ price 2)\n price)))\n\n(defparameter a (car (read)))\n(defparameter b (second (read)))\n\n(print (answer a b))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi, who is A years old, is riding a Ferris wheel.\n\nIt costs B yen (B is an even number) to ride the Ferris wheel if you are 13 years old or older, but children between 6 and 12 years old (inclusive) can ride it for half the cost, and children who are 5 years old or younger are free of charge. (Yen is the currency of Japan.)\n\nFind the cost of the Ferris wheel for Takahashi.\n\nConstraints\n\n0 ≤ A ≤ 100\n\n2 ≤ B ≤ 1000\n\nB is an even number.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the cost of the Ferris wheel for Takahashi.\n\nSample Input 1\n\n30 100\n\nSample Output 1\n\n100\n\nTakahashi is 30 years old now, and the cost of the Ferris wheel is 100 yen.\n\nSample Input 2\n\n12 100\n\nSample Output 2\n\n50\n\nTakahashi is 12 years old, and the cost of the Ferris wheel is the half of 100 yen, that is, 50 yen.\n\nSample Input 3\n\n0 100\n\nSample Output 3\n\n0\n\nTakahashi is 0 years old, and he can ride the Ferris wheel for free.", "sample_input": "30 100\n"}, "reference_outputs": ["100\n"], "source_document_id": "p03035", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi, who is A years old, is riding a Ferris wheel.\n\nIt costs B yen (B is an even number) to ride the Ferris wheel if you are 13 years old or older, but children between 6 and 12 years old (inclusive) can ride it for half the cost, and children who are 5 years old or younger are free of charge. (Yen is the currency of Japan.)\n\nFind the cost of the Ferris wheel for Takahashi.\n\nConstraints\n\n0 ≤ A ≤ 100\n\n2 ≤ B ≤ 1000\n\nB is an even number.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the cost of the Ferris wheel for Takahashi.\n\nSample Input 1\n\n30 100\n\nSample Output 1\n\n100\n\nTakahashi is 30 years old now, and the cost of the Ferris wheel is 100 yen.\n\nSample Input 2\n\n12 100\n\nSample Output 2\n\n50\n\nTakahashi is 12 years old, and the cost of the Ferris wheel is the half of 100 yen, that is, 50 yen.\n\nSample Input 3\n\n0 100\n\nSample Output 3\n\n0\n\nTakahashi is 0 years old, and he can ride the Ferris wheel for free.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 197, "cpu_time_ms": 144, "memory_kb": 12640}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s402262086", "group_id": "codeNet:p03036", "input_text": "(setq r(read))(setq d(read))(setq x(read))\n(loop for i from 1 to 10 do(princ(setq x(-(* x r)d))))", "language": "Lisp", "metadata": {"date": 1558862124, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03036.html", "problem_id": "p03036", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03036/input.txt", "sample_output_relpath": "derived/input_output/data/p03036/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03036/Lisp/s402262086.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s402262086", "user_id": "u657913472"}, "prompt_components": {"gold_output": "30\n50\n90\n170\n330\n650\n1290\n2570\n5130\n10250\n", "input_to_evaluate": "(setq r(read))(setq d(read))(setq x(read))\n(loop for i from 1 to 10 do(princ(setq x(-(* x r)d))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThe development of algae in a pond is as follows.\n\nLet the total weight of the algae at the beginning of the year i be x_i gram. For i≥2000, the following formula holds:\n\nx_{i+1} = rx_i - D\n\nYou are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print them in order.\n\nConstraints\n\n2 ≤ r ≤ 5\n\n1 ≤ D ≤ 100\n\nD < x_{2000} ≤ 200\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr D x_{2000}\n\nOutput\n\nPrint 10 lines. The i-th line (1 ≤ i ≤ 10) should contain x_{2000+i} as an integer.\n\nSample Input 1\n\n2 10 20\n\nSample Output 1\n\n30\n50\n90\n170\n330\n650\n1290\n2570\n5130\n10250\n\nFor example, x_{2001} = rx_{2000} - D = 2 \\times 20 - 10 = 30 and x_{2002} = rx_{2001} - D = 2 \\times 30 - 10 = 50.\n\nSample Input 2\n\n4 40 60\n\nSample Output 2\n\n200\n760\n3000\n11960\n47800\n191160\n764600\n3058360\n12233400\n48933560", "sample_input": "2 10 20\n"}, "reference_outputs": ["30\n50\n90\n170\n330\n650\n1290\n2570\n5130\n10250\n"], "source_document_id": "p03036", "source_text": "Score : 200 points\n\nProblem Statement\n\nThe development of algae in a pond is as follows.\n\nLet the total weight of the algae at the beginning of the year i be x_i gram. For i≥2000, the following formula holds:\n\nx_{i+1} = rx_i - D\n\nYou are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print them in order.\n\nConstraints\n\n2 ≤ r ≤ 5\n\n1 ≤ D ≤ 100\n\nD < x_{2000} ≤ 200\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr D x_{2000}\n\nOutput\n\nPrint 10 lines. The i-th line (1 ≤ i ≤ 10) should contain x_{2000+i} as an integer.\n\nSample Input 1\n\n2 10 20\n\nSample Output 1\n\n30\n50\n90\n170\n330\n650\n1290\n2570\n5130\n10250\n\nFor example, x_{2001} = rx_{2000} - D = 2 \\times 20 - 10 = 30 and x_{2002} = rx_{2001} - D = 2 \\times 30 - 10 = 50.\n\nSample Input 2\n\n4 40 60\n\nSample Output 2\n\n200\n760\n3000\n11960\n47800\n191160\n764600\n3058360\n12233400\n48933560", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 97, "cpu_time_ms": 27, "memory_kb": 4840}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s361409893", "group_id": "codeNet:p03037", "input_text": "(defparameter mod-number 1000000007)\n\n(defun unfold (p f g seed &optional (tail-gen (lambda () '())))\n (if (p seed)\n (tail-gen seed)\n\t (cons (f seed)\n\t (unfold p f g (g seed) tail-gen))))\n \n(defun iota (c &optional (s 0) (step 1) (acc nil))\n (if (zerop c)\n (reverse acc)\n (iota (1- c) (+ s step) step (cons s acc))))\n \n(defun sum (list &optional (init 0))\n (reduce #'+ list :initial-value init))\n \n(defmacro debug-print (x)\n `(let ((y ,x))\n (format t \"~A: ~A~%\" ',x y)\n\ty))\n\n(defparameter n (read))\n(defparameter m (read))\n\n(defparameter l nil)\n(defparameter r nil)\n\n(dotimes (i m)\n (push (read) l)\n (push (read) r))\n\n(let ((l-max (apply #'max l))\n (r-min (apply #'min r)))\n (format t \"~A~%\" (max 0 (1+ (- r-min l-max)))))\n", "language": "Lisp", "metadata": {"date": 1591579116, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03037.html", "problem_id": "p03037", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03037/input.txt", "sample_output_relpath": "derived/input_output/data/p03037/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03037/Lisp/s361409893.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s361409893", "user_id": "u684901760"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defparameter mod-number 1000000007)\n\n(defun unfold (p f g seed &optional (tail-gen (lambda () '())))\n (if (p seed)\n (tail-gen seed)\n\t (cons (f seed)\n\t (unfold p f g (g seed) tail-gen))))\n \n(defun iota (c &optional (s 0) (step 1) (acc nil))\n (if (zerop c)\n (reverse acc)\n (iota (1- c) (+ s step) step (cons s acc))))\n \n(defun sum (list &optional (init 0))\n (reduce #'+ list :initial-value init))\n \n(defmacro debug-print (x)\n `(let ((y ,x))\n (format t \"~A: ~A~%\" ',x y)\n\ty))\n\n(defparameter n (read))\n(defparameter m (read))\n\n(defparameter l nil)\n(defparameter r nil)\n\n(dotimes (i m)\n (push (read) l)\n (push (read) r))\n\n(let ((l-max (apply #'max l))\n (r-min (apply #'min r)))\n (format t \"~A~%\" (max 0 (1+ (- r-min l-max)))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWe have N ID cards, and there are M gates.\n\nWe can pass the i-th gate if we have one of the following ID cards: the L_i-th, (L_i+1)-th, ..., and R_i-th ID cards.\n\nHow many of the ID cards allow us to pass all the gates alone?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq L_i \\leq R_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nL_1 R_1\nL_2 R_2\n\\vdots\nL_M R_M\n\nOutput\n\nPrint the number of ID cards that allow us to pass all the gates alone.\n\nSample Input 1\n\n4 2\n1 3\n2 4\n\nSample Output 1\n\n2\n\nTwo ID cards allow us to pass all the gates alone, as follows:\n\nThe first ID card does not allow us to pass the second gate.\n\nThe second ID card allows us to pass all the gates.\n\nThe third ID card allows us to pass all the gates.\n\nThe fourth ID card does not allow us to pass the first gate.\n\nSample Input 2\n\n10 3\n3 6\n5 7\n6 9\n\nSample Output 2\n\n1\n\nSample Input 3\n\n100000 1\n1 100000\n\nSample Output 3\n\n100000", "sample_input": "4 2\n1 3\n2 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03037", "source_text": "Score : 300 points\n\nProblem Statement\n\nWe have N ID cards, and there are M gates.\n\nWe can pass the i-th gate if we have one of the following ID cards: the L_i-th, (L_i+1)-th, ..., and R_i-th ID cards.\n\nHow many of the ID cards allow us to pass all the gates alone?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq L_i \\leq R_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nL_1 R_1\nL_2 R_2\n\\vdots\nL_M R_M\n\nOutput\n\nPrint the number of ID cards that allow us to pass all the gates alone.\n\nSample Input 1\n\n4 2\n1 3\n2 4\n\nSample Output 1\n\n2\n\nTwo ID cards allow us to pass all the gates alone, as follows:\n\nThe first ID card does not allow us to pass the second gate.\n\nThe second ID card allows us to pass all the gates.\n\nThe third ID card allows us to pass all the gates.\n\nThe fourth ID card does not allow us to pass the first gate.\n\nSample Input 2\n\n10 3\n3 6\n5 7\n6 9\n\nSample Output 2\n\n1\n\nSample Input 3\n\n100000 1\n1 100000\n\nSample Output 3\n\n100000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 762, "cpu_time_ms": 396, "memory_kb": 61928}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s118064774", "group_id": "codeNet:p03037", "input_text": "(defparameter mod-number 1000000007)\n\n(defun unfold (p f g seed &optional (tail-gen (lambda () '())))\n (if (p seed)\n (tail-gen seed)\n\t (cons (f seed)\n\t (unfold p f g (g seed) tail-gen))))\n \n(defun iota (c &optional (s 0) (step 1) (acc nil))\n (if (zerop c)\n (reverse acc)\n (iota (1- c) (+ s step) step (cons s acc))))\n \n(defun sum (list &optional (init 0))\n (reduce #'+ list :initial-value init))\n \n(defmacro debug-print (x)\n `(let ((y ,x))\n (format t \"~A: ~A~%\" ',x y)\n\ty))\n\n(defparameter n (read))\n(defparameter m (read))\n\n(defparameter l nil)\n(defparameter r nil)\n\n(dotimes (i m)\n (push (read) l)\n (push (read) r))\n\n(defparameter l-max (apply #'max l))\n(defparameter r-mix (apply #'min r))\n\n(format t \"~A~%\" (1+ (- r-mix l-max)))\n", "language": "Lisp", "metadata": {"date": 1591578394, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03037.html", "problem_id": "p03037", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03037/input.txt", "sample_output_relpath": "derived/input_output/data/p03037/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03037/Lisp/s118064774.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s118064774", "user_id": "u684901760"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defparameter mod-number 1000000007)\n\n(defun unfold (p f g seed &optional (tail-gen (lambda () '())))\n (if (p seed)\n (tail-gen seed)\n\t (cons (f seed)\n\t (unfold p f g (g seed) tail-gen))))\n \n(defun iota (c &optional (s 0) (step 1) (acc nil))\n (if (zerop c)\n (reverse acc)\n (iota (1- c) (+ s step) step (cons s acc))))\n \n(defun sum (list &optional (init 0))\n (reduce #'+ list :initial-value init))\n \n(defmacro debug-print (x)\n `(let ((y ,x))\n (format t \"~A: ~A~%\" ',x y)\n\ty))\n\n(defparameter n (read))\n(defparameter m (read))\n\n(defparameter l nil)\n(defparameter r nil)\n\n(dotimes (i m)\n (push (read) l)\n (push (read) r))\n\n(defparameter l-max (apply #'max l))\n(defparameter r-mix (apply #'min r))\n\n(format t \"~A~%\" (1+ (- r-mix l-max)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWe have N ID cards, and there are M gates.\n\nWe can pass the i-th gate if we have one of the following ID cards: the L_i-th, (L_i+1)-th, ..., and R_i-th ID cards.\n\nHow many of the ID cards allow us to pass all the gates alone?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq L_i \\leq R_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nL_1 R_1\nL_2 R_2\n\\vdots\nL_M R_M\n\nOutput\n\nPrint the number of ID cards that allow us to pass all the gates alone.\n\nSample Input 1\n\n4 2\n1 3\n2 4\n\nSample Output 1\n\n2\n\nTwo ID cards allow us to pass all the gates alone, as follows:\n\nThe first ID card does not allow us to pass the second gate.\n\nThe second ID card allows us to pass all the gates.\n\nThe third ID card allows us to pass all the gates.\n\nThe fourth ID card does not allow us to pass the first gate.\n\nSample Input 2\n\n10 3\n3 6\n5 7\n6 9\n\nSample Output 2\n\n1\n\nSample Input 3\n\n100000 1\n1 100000\n\nSample Output 3\n\n100000", "sample_input": "4 2\n1 3\n2 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03037", "source_text": "Score : 300 points\n\nProblem Statement\n\nWe have N ID cards, and there are M gates.\n\nWe can pass the i-th gate if we have one of the following ID cards: the L_i-th, (L_i+1)-th, ..., and R_i-th ID cards.\n\nHow many of the ID cards allow us to pass all the gates alone?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq L_i \\leq R_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nL_1 R_1\nL_2 R_2\n\\vdots\nL_M R_M\n\nOutput\n\nPrint the number of ID cards that allow us to pass all the gates alone.\n\nSample Input 1\n\n4 2\n1 3\n2 4\n\nSample Output 1\n\n2\n\nTwo ID cards allow us to pass all the gates alone, as follows:\n\nThe first ID card does not allow us to pass the second gate.\n\nThe second ID card allows us to pass all the gates.\n\nThe third ID card allows us to pass all the gates.\n\nThe fourth ID card does not allow us to pass the first gate.\n\nSample Input 2\n\n10 3\n3 6\n5 7\n6 9\n\nSample Output 2\n\n1\n\nSample Input 3\n\n100000 1\n1 100000\n\nSample Output 3\n\n100000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 765, "cpu_time_ms": 394, "memory_kb": 61928}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s858414761", "group_id": "codeNet:p03038", "input_text": "(let* ((n (read))\n (m (read))\n (lst (sort (loop :repeat n :collect (read)) #'<))\n (lst-l (sort (loop :repeat m :collect (cons (read) (read))) #'> :key #'cdr))\n (fil 0))\n (loop :for k :in lst-l :do (loop :for j :from fil :upto (+ fil (car k) -1)\n :do (cond ((< (1- (length lst)) j))\n ((< (elt lst j) (cdr k)) (setf (elt lst j) (cdr k))))\n :do (incf fil)))\n (princ (reduce #'+ lst)))", "language": "Lisp", "metadata": {"date": 1574375115, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03038.html", "problem_id": "p03038", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03038/input.txt", "sample_output_relpath": "derived/input_output/data/p03038/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03038/Lisp/s858414761.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s858414761", "user_id": "u610490393"}, "prompt_components": {"gold_output": "14\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (lst (sort (loop :repeat n :collect (read)) #'<))\n (lst-l (sort (loop :repeat m :collect (cons (read) (read))) #'> :key #'cdr))\n (fil 0))\n (loop :for k :in lst-l :do (loop :for j :from fil :upto (+ fil (car k) -1)\n :do (cond ((< (1- (length lst)) j))\n ((< (elt lst j) (cdr k)) (setf (elt lst j) (cdr k))))\n :do (incf fil)))\n (princ (reduce #'+ lst)))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYou have N cards. On the i-th card, an integer A_i is written.\n\nFor each j = 1, 2, ..., M in this order, you will perform the following operation once:\n\nOperation: Choose at most B_j cards (possibly zero). Replace the integer written on each chosen card with C_j.\n\nFind the maximum possible sum of the integers written on the N cards after the M operations.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq A_i, C_i \\leq 10^9\n\n1 \\leq B_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 A_2 ... A_N\nB_1 C_1\nB_2 C_2\n\\vdots\nB_M C_M\n\nOutput\n\nPrint the maximum possible sum of the integers written on the N cards after the M operations.\n\nSample Input 1\n\n3 2\n5 1 4\n2 3\n1 5\n\nSample Output 1\n\n14\n\nBy replacing the integer on the second card with 5, the sum of the integers written on the three cards becomes 5 + 5 + 4 = 14, which is the maximum result.\n\nSample Input 2\n\n10 3\n1 8 5 7 100 4 52 33 13 5\n3 10\n4 30\n1 4\n\nSample Output 2\n\n338\n\nSample Input 3\n\n3 2\n100 100 100\n3 99\n3 99\n\nSample Output 3\n\n300\n\nSample Input 4\n\n11 3\n1 1 1 1 1 1 1 1 1 1 1\n3 1000000000\n4 1000000000\n3 1000000000\n\nSample Output 4\n\n10000000001\n\nThe output may not fit into a 32-bit integer type.", "sample_input": "3 2\n5 1 4\n2 3\n1 5\n"}, "reference_outputs": ["14\n"], "source_document_id": "p03038", "source_text": "Score : 400 points\n\nProblem Statement\n\nYou have N cards. On the i-th card, an integer A_i is written.\n\nFor each j = 1, 2, ..., M in this order, you will perform the following operation once:\n\nOperation: Choose at most B_j cards (possibly zero). Replace the integer written on each chosen card with C_j.\n\nFind the maximum possible sum of the integers written on the N cards after the M operations.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq A_i, C_i \\leq 10^9\n\n1 \\leq B_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 A_2 ... A_N\nB_1 C_1\nB_2 C_2\n\\vdots\nB_M C_M\n\nOutput\n\nPrint the maximum possible sum of the integers written on the N cards after the M operations.\n\nSample Input 1\n\n3 2\n5 1 4\n2 3\n1 5\n\nSample Output 1\n\n14\n\nBy replacing the integer on the second card with 5, the sum of the integers written on the three cards becomes 5 + 5 + 4 = 14, which is the maximum result.\n\nSample Input 2\n\n10 3\n1 8 5 7 100 4 52 33 13 5\n3 10\n4 30\n1 4\n\nSample Output 2\n\n338\n\nSample Input 3\n\n3 2\n100 100 100\n3 99\n3 99\n\nSample Output 3\n\n300\n\nSample Input 4\n\n11 3\n1 1 1 1 1 1 1 1 1 1 1\n3 1000000000\n4 1000000000\n3 1000000000\n\nSample Output 4\n\n10000000001\n\nThe output may not fit into a 32-bit integer type.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 519, "cpu_time_ms": 2105, "memory_kb": 61800}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s374322834", "group_id": "codeNet:p03038", "input_text": "(defun calc (l v count current)\n (if (= count 0)\n (values l current)\n (let ((tmp l))\n (if (< (nth current tmp) v)\n (progn (setf (nth current tmp) v)\n (calc tmp v (- count 1) (incf current)))\n (calc l v (- count 1) current)))))\n\n(defun main ()\n (let ((N (read))\n (M (read))\n (A (list nil))\n (CB (list nil))\n (current 0))\n (dotimes (n N)\n (push (read) A))\n (setq A (sort (cdr (reverse A)) #'<))\n (dotimes (n M)\n (let ((B (read))\n (C (read)))\n (push (cons C B) CB)))\n (setq CB (sort (cdr (reverse CB)) (lambda (x y) (> (car x) (car y)))))\n (dolist (i CB)\n (multiple-value-bind (a c) (calc A (car i) (cdr i) current)\n (setq A a)\n (setq current c)))\n (print (reduce '+ A))))\n\n(main)\n \n", "language": "Lisp", "metadata": {"date": 1558878645, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03038.html", "problem_id": "p03038", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03038/input.txt", "sample_output_relpath": "derived/input_output/data/p03038/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03038/Lisp/s374322834.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s374322834", "user_id": "u631655863"}, "prompt_components": {"gold_output": "14\n", "input_to_evaluate": "(defun calc (l v count current)\n (if (= count 0)\n (values l current)\n (let ((tmp l))\n (if (< (nth current tmp) v)\n (progn (setf (nth current tmp) v)\n (calc tmp v (- count 1) (incf current)))\n (calc l v (- count 1) current)))))\n\n(defun main ()\n (let ((N (read))\n (M (read))\n (A (list nil))\n (CB (list nil))\n (current 0))\n (dotimes (n N)\n (push (read) A))\n (setq A (sort (cdr (reverse A)) #'<))\n (dotimes (n M)\n (let ((B (read))\n (C (read)))\n (push (cons C B) CB)))\n (setq CB (sort (cdr (reverse CB)) (lambda (x y) (> (car x) (car y)))))\n (dolist (i CB)\n (multiple-value-bind (a c) (calc A (car i) (cdr i) current)\n (setq A a)\n (setq current c)))\n (print (reduce '+ A))))\n\n(main)\n \n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYou have N cards. On the i-th card, an integer A_i is written.\n\nFor each j = 1, 2, ..., M in this order, you will perform the following operation once:\n\nOperation: Choose at most B_j cards (possibly zero). Replace the integer written on each chosen card with C_j.\n\nFind the maximum possible sum of the integers written on the N cards after the M operations.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq A_i, C_i \\leq 10^9\n\n1 \\leq B_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 A_2 ... A_N\nB_1 C_1\nB_2 C_2\n\\vdots\nB_M C_M\n\nOutput\n\nPrint the maximum possible sum of the integers written on the N cards after the M operations.\n\nSample Input 1\n\n3 2\n5 1 4\n2 3\n1 5\n\nSample Output 1\n\n14\n\nBy replacing the integer on the second card with 5, the sum of the integers written on the three cards becomes 5 + 5 + 4 = 14, which is the maximum result.\n\nSample Input 2\n\n10 3\n1 8 5 7 100 4 52 33 13 5\n3 10\n4 30\n1 4\n\nSample Output 2\n\n338\n\nSample Input 3\n\n3 2\n100 100 100\n3 99\n3 99\n\nSample Output 3\n\n300\n\nSample Input 4\n\n11 3\n1 1 1 1 1 1 1 1 1 1 1\n3 1000000000\n4 1000000000\n3 1000000000\n\nSample Output 4\n\n10000000001\n\nThe output may not fit into a 32-bit integer type.", "sample_input": "3 2\n5 1 4\n2 3\n1 5\n"}, "reference_outputs": ["14\n"], "source_document_id": "p03038", "source_text": "Score : 400 points\n\nProblem Statement\n\nYou have N cards. On the i-th card, an integer A_i is written.\n\nFor each j = 1, 2, ..., M in this order, you will perform the following operation once:\n\nOperation: Choose at most B_j cards (possibly zero). Replace the integer written on each chosen card with C_j.\n\nFind the maximum possible sum of the integers written on the N cards after the M operations.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq A_i, C_i \\leq 10^9\n\n1 \\leq B_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 A_2 ... A_N\nB_1 C_1\nB_2 C_2\n\\vdots\nB_M C_M\n\nOutput\n\nPrint the maximum possible sum of the integers written on the N cards after the M operations.\n\nSample Input 1\n\n3 2\n5 1 4\n2 3\n1 5\n\nSample Output 1\n\n14\n\nBy replacing the integer on the second card with 5, the sum of the integers written on the three cards becomes 5 + 5 + 4 = 14, which is the maximum result.\n\nSample Input 2\n\n10 3\n1 8 5 7 100 4 52 33 13 5\n3 10\n4 30\n1 4\n\nSample Output 2\n\n338\n\nSample Input 3\n\n3 2\n100 100 100\n3 99\n3 99\n\nSample Output 3\n\n300\n\nSample Input 4\n\n11 3\n1 1 1 1 1 1 1 1 1 1 1\n3 1000000000\n4 1000000000\n3 1000000000\n\nSample Output 4\n\n10000000001\n\nThe output may not fit into a 32-bit integer type.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 833, "cpu_time_ms": 2105, "memory_kb": 63848}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s872630524", "group_id": "codeNet:p03038", "input_text": "(defmacro defsolver (name vars &body body)\n `(defun ,name ()\n (let (,@(mapcar #'list\n vars\n (mapcar (constantly '(read))\n vars)))\n ,@body)))\n\n(defsolver after-solution-d (n m)\n (let ((l (loop repeat n collect (read))))\n (dotimes (i m l)\n (let ((max (read))\n\t (num (read)))\n\t(nconc l (loop repeat max collect num))\n\t(setf l (sort l #'<))\n\t(setf l (last l n))))\n (princ (loop for x in l sum x))))", "language": "Lisp", "metadata": {"date": 1558842059, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03038.html", "problem_id": "p03038", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03038/input.txt", "sample_output_relpath": "derived/input_output/data/p03038/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03038/Lisp/s872630524.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s872630524", "user_id": "u100932207"}, "prompt_components": {"gold_output": "14\n", "input_to_evaluate": "(defmacro defsolver (name vars &body body)\n `(defun ,name ()\n (let (,@(mapcar #'list\n vars\n (mapcar (constantly '(read))\n vars)))\n ,@body)))\n\n(defsolver after-solution-d (n m)\n (let ((l (loop repeat n collect (read))))\n (dotimes (i m l)\n (let ((max (read))\n\t (num (read)))\n\t(nconc l (loop repeat max collect num))\n\t(setf l (sort l #'<))\n\t(setf l (last l n))))\n (princ (loop for x in l sum x))))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYou have N cards. On the i-th card, an integer A_i is written.\n\nFor each j = 1, 2, ..., M in this order, you will perform the following operation once:\n\nOperation: Choose at most B_j cards (possibly zero). Replace the integer written on each chosen card with C_j.\n\nFind the maximum possible sum of the integers written on the N cards after the M operations.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq A_i, C_i \\leq 10^9\n\n1 \\leq B_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 A_2 ... A_N\nB_1 C_1\nB_2 C_2\n\\vdots\nB_M C_M\n\nOutput\n\nPrint the maximum possible sum of the integers written on the N cards after the M operations.\n\nSample Input 1\n\n3 2\n5 1 4\n2 3\n1 5\n\nSample Output 1\n\n14\n\nBy replacing the integer on the second card with 5, the sum of the integers written on the three cards becomes 5 + 5 + 4 = 14, which is the maximum result.\n\nSample Input 2\n\n10 3\n1 8 5 7 100 4 52 33 13 5\n3 10\n4 30\n1 4\n\nSample Output 2\n\n338\n\nSample Input 3\n\n3 2\n100 100 100\n3 99\n3 99\n\nSample Output 3\n\n300\n\nSample Input 4\n\n11 3\n1 1 1 1 1 1 1 1 1 1 1\n3 1000000000\n4 1000000000\n3 1000000000\n\nSample Output 4\n\n10000000001\n\nThe output may not fit into a 32-bit integer type.", "sample_input": "3 2\n5 1 4\n2 3\n1 5\n"}, "reference_outputs": ["14\n"], "source_document_id": "p03038", "source_text": "Score : 400 points\n\nProblem Statement\n\nYou have N cards. On the i-th card, an integer A_i is written.\n\nFor each j = 1, 2, ..., M in this order, you will perform the following operation once:\n\nOperation: Choose at most B_j cards (possibly zero). Replace the integer written on each chosen card with C_j.\n\nFind the maximum possible sum of the integers written on the N cards after the M operations.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq A_i, C_i \\leq 10^9\n\n1 \\leq B_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 A_2 ... A_N\nB_1 C_1\nB_2 C_2\n\\vdots\nB_M C_M\n\nOutput\n\nPrint the maximum possible sum of the integers written on the N cards after the M operations.\n\nSample Input 1\n\n3 2\n5 1 4\n2 3\n1 5\n\nSample Output 1\n\n14\n\nBy replacing the integer on the second card with 5, the sum of the integers written on the three cards becomes 5 + 5 + 4 = 14, which is the maximum result.\n\nSample Input 2\n\n10 3\n1 8 5 7 100 4 52 33 13 5\n3 10\n4 30\n1 4\n\nSample Output 2\n\n338\n\nSample Input 3\n\n3 2\n100 100 100\n3 99\n3 99\n\nSample Output 3\n\n300\n\nSample Input 4\n\n11 3\n1 1 1 1 1 1 1 1 1 1 1\n3 1000000000\n4 1000000000\n3 1000000000\n\nSample Output 4\n\n10000000001\n\nThe output may not fit into a 32-bit integer type.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 457, "cpu_time_ms": 151, "memory_kb": 15968}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s338241917", "group_id": "codeNet:p03038", "input_text": "(defmacro defsolver (name vars &body body)\n `(defun ,name ()\n (let (,@(mapcar #'list\n vars\n (mapcar (constantly '(read))\n vars)))\n ,@body)))\n\n(defsolver solution-d (n m)\n (let ((a (make-array n)))\n (dotimes (i n a)\n (setf (svref a i) (read)))\n (dotimes (i m a)\n (sort a #'<)\n (let* ((max (read))\n\t (num (read))\n\t (p (position-if #'(lambda (x) (>= x num)) a)))\n\t(dotimes (j (if (> p max) max p) a)\n\t (let ((val (svref a j)))\n\t (when (< val num)\n\t (setf (svref a j) num))))))\n (let ((sum 0))\n (dotimes (i n sum)\n\t(incf sum (svref a i))))))\n\n(solution-d)", "language": "Lisp", "metadata": {"date": 1558836710, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03038.html", "problem_id": "p03038", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03038/input.txt", "sample_output_relpath": "derived/input_output/data/p03038/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03038/Lisp/s338241917.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s338241917", "user_id": "u100932207"}, "prompt_components": {"gold_output": "14\n", "input_to_evaluate": "(defmacro defsolver (name vars &body body)\n `(defun ,name ()\n (let (,@(mapcar #'list\n vars\n (mapcar (constantly '(read))\n vars)))\n ,@body)))\n\n(defsolver solution-d (n m)\n (let ((a (make-array n)))\n (dotimes (i n a)\n (setf (svref a i) (read)))\n (dotimes (i m a)\n (sort a #'<)\n (let* ((max (read))\n\t (num (read))\n\t (p (position-if #'(lambda (x) (>= x num)) a)))\n\t(dotimes (j (if (> p max) max p) a)\n\t (let ((val (svref a j)))\n\t (when (< val num)\n\t (setf (svref a j) num))))))\n (let ((sum 0))\n (dotimes (i n sum)\n\t(incf sum (svref a i))))))\n\n(solution-d)", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYou have N cards. On the i-th card, an integer A_i is written.\n\nFor each j = 1, 2, ..., M in this order, you will perform the following operation once:\n\nOperation: Choose at most B_j cards (possibly zero). Replace the integer written on each chosen card with C_j.\n\nFind the maximum possible sum of the integers written on the N cards after the M operations.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq A_i, C_i \\leq 10^9\n\n1 \\leq B_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 A_2 ... A_N\nB_1 C_1\nB_2 C_2\n\\vdots\nB_M C_M\n\nOutput\n\nPrint the maximum possible sum of the integers written on the N cards after the M operations.\n\nSample Input 1\n\n3 2\n5 1 4\n2 3\n1 5\n\nSample Output 1\n\n14\n\nBy replacing the integer on the second card with 5, the sum of the integers written on the three cards becomes 5 + 5 + 4 = 14, which is the maximum result.\n\nSample Input 2\n\n10 3\n1 8 5 7 100 4 52 33 13 5\n3 10\n4 30\n1 4\n\nSample Output 2\n\n338\n\nSample Input 3\n\n3 2\n100 100 100\n3 99\n3 99\n\nSample Output 3\n\n300\n\nSample Input 4\n\n11 3\n1 1 1 1 1 1 1 1 1 1 1\n3 1000000000\n4 1000000000\n3 1000000000\n\nSample Output 4\n\n10000000001\n\nThe output may not fit into a 32-bit integer type.", "sample_input": "3 2\n5 1 4\n2 3\n1 5\n"}, "reference_outputs": ["14\n"], "source_document_id": "p03038", "source_text": "Score : 400 points\n\nProblem Statement\n\nYou have N cards. On the i-th card, an integer A_i is written.\n\nFor each j = 1, 2, ..., M in this order, you will perform the following operation once:\n\nOperation: Choose at most B_j cards (possibly zero). Replace the integer written on each chosen card with C_j.\n\nFind the maximum possible sum of the integers written on the N cards after the M operations.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq A_i, C_i \\leq 10^9\n\n1 \\leq B_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 A_2 ... A_N\nB_1 C_1\nB_2 C_2\n\\vdots\nB_M C_M\n\nOutput\n\nPrint the maximum possible sum of the integers written on the N cards after the M operations.\n\nSample Input 1\n\n3 2\n5 1 4\n2 3\n1 5\n\nSample Output 1\n\n14\n\nBy replacing the integer on the second card with 5, the sum of the integers written on the three cards becomes 5 + 5 + 4 = 14, which is the maximum result.\n\nSample Input 2\n\n10 3\n1 8 5 7 100 4 52 33 13 5\n3 10\n4 30\n1 4\n\nSample Output 2\n\n338\n\nSample Input 3\n\n3 2\n100 100 100\n3 99\n3 99\n\nSample Output 3\n\n300\n\nSample Input 4\n\n11 3\n1 1 1 1 1 1 1 1 1 1 1\n3 1000000000\n4 1000000000\n3 1000000000\n\nSample Output 4\n\n10000000001\n\nThe output may not fit into a 32-bit integer type.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 646, "cpu_time_ms": 2104, "memory_kb": 59880}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s031060891", "group_id": "codeNet:p03040", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(setf *print-circle* t)\n\n;; Treap with implicit key for updating and querying interval.\n\n(declaim (inline op))\n(defun op (a b)\n (+ a b))\n\n(defconstant +op-identity+ 0)\n\n(defstruct (inode (:constructor %make-inode (value priority &key left right (count 1) (accumulator +op-identity+)))\n (:copier nil)\n (:conc-name %inode-))\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (integer 0 #.most-positive-fixnum))\n (left nil :type (or null inode))\n (right nil :type (or null inode)))\n\n(declaim (inline inode-count))\n(defun inode-count (inode)\n (declare ((or null inode) inode))\n (if inode\n (%inode-count inode)\n 0))\n\n(declaim (inline inode-accumulator))\n(defun inode-accumulator (inode)\n (declare ((or null inode) inode))\n (if inode\n (%inode-accumulator inode)\n +op-identity+))\n\n(declaim (inline update-count))\n(defun update-count (inode)\n (declare (inode inode))\n (setf (%inode-count inode)\n (+ 1\n (inode-count (%inode-left inode))\n (inode-count (%inode-right inode)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (inode)\n (declare (inode inode))\n (setf (%inode-accumulator inode)\n (if (%inode-left inode)\n (if (%inode-right inode)\n (let ((mid (op (%inode-accumulator (%inode-left inode))\n (%inode-value inode))))\n (declare (dynamic-extent mid))\n (op mid (%inode-accumulator (%inode-right inode))))\n (op (%inode-accumulator (%inode-left inode))\n (%inode-value inode)))\n (if (%inode-right inode)\n (op (%inode-value inode)\n (%inode-accumulator (%inode-right inode)))\n (%inode-value inode)))))\n\n(declaim (inline force-self))\n(defun force-self (inode)\n (declare (inode inode))\n (update-count inode)\n (update-accumulator inode))\n\n\n(defun inode-split (inode index)\n \"Destructively splits the INODE into two nodes [0, INDEX) and [INDEX, N), where N\n is the number of elements of the INODE.\"\n (declare #.OPT ((integer 0 #.most-positive-fixnum) index))\n (unless inode\n (return-from inode-split (values nil nil)))\n (let ((implicit-key (1+ (inode-count (%inode-left inode)))))\n (if (< index implicit-key)\n (multiple-value-bind (left right)\n (inode-split (%inode-left inode) index)\n (setf (%inode-left inode) right)\n (force-self inode)\n (values left inode))\n (multiple-value-bind (left right)\n (inode-split (%inode-right inode) (- index implicit-key))\n (setf (%inode-right inode) left)\n (force-self inode)\n (values inode right)))))\n\n(defun inode-merge (left right)\n \"Destructively merges two INODEs.\"\n (declare #.OPT ((or null inode) left right))\n (cond ((null left) (when right (force-self right)) right)\n ((null right) (when left (force-self left)) left)\n (t (if (> (%inode-priority left) (%inode-priority right))\n (progn\n (setf (%inode-right left)\n (inode-merge (%inode-right left) right))\n (force-self left)\n left)\n (progn\n (setf (%inode-left right)\n (inode-merge left (%inode-left right)))\n (force-self right)\n right)))))\n\n(declaim (inline inode-insert))\n(defun inode-insert (inode index obj)\n \"Destructively inserts OBJ into INODE at INDEX.\"\n (declare ((or null inode) inode)\n ((integer 0 #.most-positive-fixnum) index))\n (assert (<= index (inode-count inode)))\n (let ((obj-inode (%make-inode obj (random most-positive-fixnum))))\n (multiple-value-bind (left right)\n (inode-split inode index)\n (inode-merge (inode-merge left obj-inode) right))))\n\n(defun inode-map (function inode)\n \"Successively applies FUNCTION to INODE[0], ..., INODE[SIZE-1].\"\n (declare (function function))\n (when inode\n (inode-map function (%inode-left inode))\n (funcall function (%inode-value inode))\n (inode-map function (%inode-right inode))\n (force-self inode)))\n\n(defmethod print-object ((object inode) stream)\n (print-unreadable-object (object stream :type t)\n (let ((size (inode-count object))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) index))\n (inode-map (lambda (x)\n (princ x stream)\n (incf index)\n (when (< index size)\n (write-char #\\ stream)))\n object))))\n\n(declaim (inline inode-ref))\n(defun inode-ref (inode index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (assert (< index (inode-count inode)))\n (labels ((%ref (inode index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (prog1\n (let ((left-count (inode-count (%inode-left inode))))\n (cond ((< index left-count)\n (%ref (%inode-left inode) index))\n ((> index left-count)\n (%ref (%inode-right inode) (- index left-count 1)))\n (t (%inode-value inode))))\n (force-self inode))))\n (%ref inode index)))\n\n(defun inode-bisect-left (threshold treap &key (test #'<))\n \"Returns the smallest index and the corresponding key that satisfies\nKEY[index] >= THRESHOLD. Returns the size of TREAP and THRESHOLD if KEY[size-1]\n< THRESHOLD.\"\n (declare #.OPT (function test))\n (labels ((recur (count treap)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null treap) nil)\n ((funcall test (%inode-value treap) threshold)\n (recur count (%inode-right treap)))\n (t (let ((left-count (- count (inode-count (%inode-right treap)) 1)))\n (let ((idx (recur left-count (%inode-left treap))))\n (if idx\n idx\n left-count)))))))\n (or (recur (inode-count treap) treap)\n (inode-count treap))))\n\n;; FIXME: might be problematic when two priorities collide.\n(declaim (inline inode-query))\n(defun inode-query (inode l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless (< l r)\n (return-from inode-query 0))\n (assert (<= r (inode-count inode)))\n (multiple-value-bind (inode-0-l inode-l-n)\n (inode-split inode l)\n (multiple-value-bind (inode-l-r inode-r-n)\n (inode-split inode-l-n (- r l))\n (prog1 (%inode-accumulator inode-l-r)\n (inode-merge inode-0-l (inode-merge inode-l-r inode-r-n))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((q (read))\n (const 0)\n inode)\n (declare (uint32 q) (fixnum const))\n (dotimes (i q)\n (let ((id (read-fixnum)))\n (if (= id 1)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (setf inode (inode-insert inode (inode-bisect-left a inode) a))\n (incf const b))\n (let ((count (inode-count inode)))\n (if (oddp count)\n (let* ((mid (floor count 2))\n (at (inode-ref inode mid)))\n (format t\n \"~D ~D~%\"\n at\n (+ const\n (inode-query inode (+ mid 1) (inode-count inode))\n (- (inode-query inode 0 mid)))))\n (let* ((mid (floor count 2))\n (at (inode-ref inode (- mid 1))))\n (format t\n \"~D ~D~%\"\n at\n (+ const\n (inode-query inode mid (inode-count inode))\n (- (inode-query inode 0 mid))))))))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1558837934, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03040.html", "problem_id": "p03040", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03040/input.txt", "sample_output_relpath": "derived/input_output/data/p03040/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03040/Lisp/s031060891.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s031060891", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4 2\n1 -3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(setf *print-circle* t)\n\n;; Treap with implicit key for updating and querying interval.\n\n(declaim (inline op))\n(defun op (a b)\n (+ a b))\n\n(defconstant +op-identity+ 0)\n\n(defstruct (inode (:constructor %make-inode (value priority &key left right (count 1) (accumulator +op-identity+)))\n (:copier nil)\n (:conc-name %inode-))\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (integer 0 #.most-positive-fixnum))\n (left nil :type (or null inode))\n (right nil :type (or null inode)))\n\n(declaim (inline inode-count))\n(defun inode-count (inode)\n (declare ((or null inode) inode))\n (if inode\n (%inode-count inode)\n 0))\n\n(declaim (inline inode-accumulator))\n(defun inode-accumulator (inode)\n (declare ((or null inode) inode))\n (if inode\n (%inode-accumulator inode)\n +op-identity+))\n\n(declaim (inline update-count))\n(defun update-count (inode)\n (declare (inode inode))\n (setf (%inode-count inode)\n (+ 1\n (inode-count (%inode-left inode))\n (inode-count (%inode-right inode)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (inode)\n (declare (inode inode))\n (setf (%inode-accumulator inode)\n (if (%inode-left inode)\n (if (%inode-right inode)\n (let ((mid (op (%inode-accumulator (%inode-left inode))\n (%inode-value inode))))\n (declare (dynamic-extent mid))\n (op mid (%inode-accumulator (%inode-right inode))))\n (op (%inode-accumulator (%inode-left inode))\n (%inode-value inode)))\n (if (%inode-right inode)\n (op (%inode-value inode)\n (%inode-accumulator (%inode-right inode)))\n (%inode-value inode)))))\n\n(declaim (inline force-self))\n(defun force-self (inode)\n (declare (inode inode))\n (update-count inode)\n (update-accumulator inode))\n\n\n(defun inode-split (inode index)\n \"Destructively splits the INODE into two nodes [0, INDEX) and [INDEX, N), where N\n is the number of elements of the INODE.\"\n (declare #.OPT ((integer 0 #.most-positive-fixnum) index))\n (unless inode\n (return-from inode-split (values nil nil)))\n (let ((implicit-key (1+ (inode-count (%inode-left inode)))))\n (if (< index implicit-key)\n (multiple-value-bind (left right)\n (inode-split (%inode-left inode) index)\n (setf (%inode-left inode) right)\n (force-self inode)\n (values left inode))\n (multiple-value-bind (left right)\n (inode-split (%inode-right inode) (- index implicit-key))\n (setf (%inode-right inode) left)\n (force-self inode)\n (values inode right)))))\n\n(defun inode-merge (left right)\n \"Destructively merges two INODEs.\"\n (declare #.OPT ((or null inode) left right))\n (cond ((null left) (when right (force-self right)) right)\n ((null right) (when left (force-self left)) left)\n (t (if (> (%inode-priority left) (%inode-priority right))\n (progn\n (setf (%inode-right left)\n (inode-merge (%inode-right left) right))\n (force-self left)\n left)\n (progn\n (setf (%inode-left right)\n (inode-merge left (%inode-left right)))\n (force-self right)\n right)))))\n\n(declaim (inline inode-insert))\n(defun inode-insert (inode index obj)\n \"Destructively inserts OBJ into INODE at INDEX.\"\n (declare ((or null inode) inode)\n ((integer 0 #.most-positive-fixnum) index))\n (assert (<= index (inode-count inode)))\n (let ((obj-inode (%make-inode obj (random most-positive-fixnum))))\n (multiple-value-bind (left right)\n (inode-split inode index)\n (inode-merge (inode-merge left obj-inode) right))))\n\n(defun inode-map (function inode)\n \"Successively applies FUNCTION to INODE[0], ..., INODE[SIZE-1].\"\n (declare (function function))\n (when inode\n (inode-map function (%inode-left inode))\n (funcall function (%inode-value inode))\n (inode-map function (%inode-right inode))\n (force-self inode)))\n\n(defmethod print-object ((object inode) stream)\n (print-unreadable-object (object stream :type t)\n (let ((size (inode-count object))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) index))\n (inode-map (lambda (x)\n (princ x stream)\n (incf index)\n (when (< index size)\n (write-char #\\ stream)))\n object))))\n\n(declaim (inline inode-ref))\n(defun inode-ref (inode index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (assert (< index (inode-count inode)))\n (labels ((%ref (inode index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (prog1\n (let ((left-count (inode-count (%inode-left inode))))\n (cond ((< index left-count)\n (%ref (%inode-left inode) index))\n ((> index left-count)\n (%ref (%inode-right inode) (- index left-count 1)))\n (t (%inode-value inode))))\n (force-self inode))))\n (%ref inode index)))\n\n(defun inode-bisect-left (threshold treap &key (test #'<))\n \"Returns the smallest index and the corresponding key that satisfies\nKEY[index] >= THRESHOLD. Returns the size of TREAP and THRESHOLD if KEY[size-1]\n< THRESHOLD.\"\n (declare #.OPT (function test))\n (labels ((recur (count treap)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null treap) nil)\n ((funcall test (%inode-value treap) threshold)\n (recur count (%inode-right treap)))\n (t (let ((left-count (- count (inode-count (%inode-right treap)) 1)))\n (let ((idx (recur left-count (%inode-left treap))))\n (if idx\n idx\n left-count)))))))\n (or (recur (inode-count treap) treap)\n (inode-count treap))))\n\n;; FIXME: might be problematic when two priorities collide.\n(declaim (inline inode-query))\n(defun inode-query (inode l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless (< l r)\n (return-from inode-query 0))\n (assert (<= r (inode-count inode)))\n (multiple-value-bind (inode-0-l inode-l-n)\n (inode-split inode l)\n (multiple-value-bind (inode-l-r inode-r-n)\n (inode-split inode-l-n (- r l))\n (prog1 (%inode-accumulator inode-l-r)\n (inode-merge inode-0-l (inode-merge inode-l-r inode-r-n))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((q (read))\n (const 0)\n inode)\n (declare (uint32 q) (fixnum const))\n (dotimes (i q)\n (let ((id (read-fixnum)))\n (if (= id 1)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (setf inode (inode-insert inode (inode-bisect-left a inode) a))\n (incf const b))\n (let ((count (inode-count inode)))\n (if (oddp count)\n (let* ((mid (floor count 2))\n (at (inode-ref inode mid)))\n (format t\n \"~D ~D~%\"\n at\n (+ const\n (inode-query inode (+ mid 1) (inode-count inode))\n (- (inode-query inode 0 mid)))))\n (let* ((mid (floor count 2))\n (at (inode-ref inode (- mid 1))))\n (format t\n \"~D ~D~%\"\n at\n (+ const\n (inode-query inode mid (inode-count inode))\n (- (inode-query inode 0 mid))))))))))))\n\n#-swank(main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere is a function f(x), which is initially a constant function f(x) = 0.\n\nWe will ask you to process Q queries in order. There are two kinds of queries, update queries and evaluation queries, as follows:\n\nAn update query 1 a b: Given two integers a and b, let g(x) = f(x) + |x - a| + b and replace f(x) with g(x).\n\nAn evaluation query 2: Print x that minimizes f(x), and the minimum value of f(x). If there are multiple such values of x, choose the minimum such value.\n\nWe can show that the values to be output in an evaluation query are always integers, so we ask you to print those values as integers without decimal points.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq Q \\leq 2 \\times 10^5\n\n-10^9 \\leq a, b \\leq 10^9\n\nThe first query is an update query.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nQ\nQuery_1\n:\nQuery_Q\n\nSee Sample Input 1 for an example.\n\nOutput\n\nFor each evaluation query, print a line containing the response, in the order in which the queries are given.\n\nThe response to each evaluation query should be the minimum value of x that minimizes f(x), and the minimum value of f(x), in this order, with space in between.\n\nSample Input 1\n\n4\n1 4 2\n2\n1 1 -8\n2\n\nSample Output 1\n\n4 2\n1 -3\n\nIn the first evaluation query, f(x) = |x - 4| + 2, which attains the minimum value of 2 at x = 4.\n\nIn the second evaluation query, f(x) = |x - 1| + |x - 4| - 6, which attains the minimum value of -3 when 1 \\leq x \\leq 4. Among the multiple values of x that minimize f(x), we ask you to print the minimum, that is, 1.\n\nSample Input 2\n\n4\n1 -1000000000 1000000000\n1 -1000000000 1000000000\n1 -1000000000 1000000000\n2\n\nSample Output 2\n\n-1000000000 3000000000", "sample_input": "4\n1 4 2\n2\n1 1 -8\n2\n"}, "reference_outputs": ["4 2\n1 -3\n"], "source_document_id": "p03040", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere is a function f(x), which is initially a constant function f(x) = 0.\n\nWe will ask you to process Q queries in order. There are two kinds of queries, update queries and evaluation queries, as follows:\n\nAn update query 1 a b: Given two integers a and b, let g(x) = f(x) + |x - a| + b and replace f(x) with g(x).\n\nAn evaluation query 2: Print x that minimizes f(x), and the minimum value of f(x). If there are multiple such values of x, choose the minimum such value.\n\nWe can show that the values to be output in an evaluation query are always integers, so we ask you to print those values as integers without decimal points.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq Q \\leq 2 \\times 10^5\n\n-10^9 \\leq a, b \\leq 10^9\n\nThe first query is an update query.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nQ\nQuery_1\n:\nQuery_Q\n\nSee Sample Input 1 for an example.\n\nOutput\n\nFor each evaluation query, print a line containing the response, in the order in which the queries are given.\n\nThe response to each evaluation query should be the minimum value of x that minimizes f(x), and the minimum value of f(x), in this order, with space in between.\n\nSample Input 1\n\n4\n1 4 2\n2\n1 1 -8\n2\n\nSample Output 1\n\n4 2\n1 -3\n\nIn the first evaluation query, f(x) = |x - 4| + 2, which attains the minimum value of 2 at x = 4.\n\nIn the second evaluation query, f(x) = |x - 1| + |x - 4| - 6, which attains the minimum value of -3 when 1 \\leq x \\leq 4. Among the multiple values of x that minimize f(x), we ask you to print the minimum, that is, 1.\n\nSample Input 2\n\n4\n1 -1000000000 1000000000\n1 -1000000000 1000000000\n1 -1000000000 1000000000\n2\n\nSample Output 2\n\n-1000000000 3000000000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10395, "cpu_time_ms": 1204, "memory_kb": 53348}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s486670519", "group_id": "codeNet:p03040", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(setf *print-circle* t)\n\n;; Treap with implicit key for updating and querying interval.\n\n(declaim (inline op))\n(defun op (a b)\n (+ a b))\n\n(defconstant +op-identity+ 0)\n\n(defconstant +updater-identity+ 0)\n\n(declaim (inline updater-op))\n(defun updater-op (a b)\n \"Is the operator to compute and update LAZY value.\"\n (+ a b))\n\n(declaim (inline modifier-op))\n(defun modifier-op (a b size)\n \"Is the operator to update ACCUMULATOR based on LAZY value.\"\n (declare (ignore size))\n (+ a b))\n\n(defstruct (inode (:constructor %make-inode (value priority &key left right (count 1) (accumulator +op-identity+) (lazy +updater-identity+) reversed))\n (:copier nil)\n (:conc-name %inode-))\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum) ; e.g. MIN, MAX, SUM, ...\n (lazy +updater-identity+ :type fixnum)\n (reversed nil :type boolean)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (integer 0 #.most-positive-fixnum))\n (left nil :type (or null inode))\n (right nil :type (or null inode)))\n\n(declaim (inline inode-count))\n(defun inode-count (inode)\n (declare ((or null inode) inode))\n (if inode\n (%inode-count inode)\n 0))\n\n(declaim (inline inode-accumulator))\n(defun inode-accumulator (inode)\n (declare ((or null inode) inode))\n (if inode\n (%inode-accumulator inode)\n +op-identity+))\n\n(declaim (inline update-count))\n(defun update-count (inode)\n (declare (inode inode))\n (setf (%inode-count inode)\n (+ 1\n (inode-count (%inode-left inode))\n (inode-count (%inode-right inode)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (inode)\n (declare (inode inode))\n (setf (%inode-accumulator inode)\n (if (%inode-left inode)\n (if (%inode-right inode)\n (let ((mid (op (%inode-accumulator (%inode-left inode))\n (%inode-value inode))))\n (declare (dynamic-extent mid))\n (op mid (%inode-accumulator (%inode-right inode))))\n (op (%inode-accumulator (%inode-left inode))\n (%inode-value inode)))\n (if (%inode-right inode)\n (op (%inode-value inode)\n (%inode-accumulator (%inode-right inode)))\n (%inode-value inode)))))\n\n(declaim (inline force-self))\n(defun force-self (inode)\n (declare (inode inode))\n (update-count inode)\n (update-accumulator inode))\n\n(declaim (inline force-down))\n(defun force-down (inode)\n (declare (inode inode))\n (when (%inode-reversed inode)\n (setf (%inode-reversed inode) nil)\n (rotatef (%inode-left inode) (%inode-right inode))\n (let ((left (%inode-left inode)))\n (when left\n (setf (%inode-reversed left) (not (%inode-reversed left)))))\n (let ((right (%inode-right inode)))\n (when right\n (setf (%inode-reversed right) (not (%inode-reversed right))))))\n (unless (eql +updater-identity+ (%inode-lazy inode))\n (when (%inode-left inode)\n (setf (%inode-lazy (%inode-left inode))\n (updater-op (%inode-lazy (%inode-left inode))\n (%inode-lazy inode)))\n (setf (%inode-accumulator (%inode-left inode))\n (modifier-op (%inode-accumulator (%inode-left inode))\n (%inode-lazy inode)\n (%inode-count (%inode-left inode)))))\n (when (%inode-right inode)\n (setf (%inode-lazy (%inode-right inode))\n (updater-op (%inode-lazy (%inode-right inode))\n (%inode-lazy inode)))\n (setf (%inode-accumulator (%inode-right inode))\n (modifier-op (%inode-accumulator (%inode-right inode))\n (%inode-lazy inode)\n (%inode-count (%inode-right inode)))))\n (setf (%inode-value inode)\n (modifier-op (%inode-value inode)\n (%inode-lazy inode)\n 1))\n (setf (%inode-lazy inode) +updater-identity+)))\n\n(defun inode-split (inode index)\n \"Destructively splits the INODE into two nodes [0, INDEX) and [INDEX, N), where N\n is the number of elements of the INODE.\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless inode\n (return-from inode-split (values nil nil)))\n (force-down inode)\n (let ((implicit-key (1+ (inode-count (%inode-left inode)))))\n (if (< index implicit-key)\n (multiple-value-bind (left right)\n (inode-split (%inode-left inode) index)\n (setf (%inode-left inode) right)\n (force-self inode)\n (values left inode))\n (multiple-value-bind (left right)\n (inode-split (%inode-right inode) (- index implicit-key))\n (setf (%inode-right inode) left)\n (force-self inode)\n (values inode right)))))\n\n(defun inode-merge (left right)\n \"Destructively merges two INODEs.\"\n (declare ((or null inode) left right))\n (cond ((null left) (when right (force-down right) (force-self right)) right)\n ((null right) (when left (force-down left) (force-self left)) left)\n (t (force-down left)\n (force-down right)\n (if (> (%inode-priority left) (%inode-priority right))\n (progn\n (setf (%inode-right left)\n (inode-merge (%inode-right left) right))\n (force-self left)\n left)\n (progn\n (setf (%inode-left right)\n (inode-merge left (%inode-left right)))\n (force-self right)\n right)))))\n\n;; (define-condition invalid-itreap-index-error (type-error)\n;; ((itreap :initarg :itreap :reader invalid-itreap-index-error-itreap)\n;; (index :initarg :index :reader invalid-itreap-index-error-index))\n;; (:report\n;; (lambda (condition stream)\n;; (format stream \"Invalid index ~W for itreap ~S.\"\n;; (invalid-itreap-index-error-index condition)\n;; (invalid-itreap-index-error-itreap condition)))))\n\n(declaim (inline inode-insert))\n(defun inode-insert (inode index obj)\n \"Destructively inserts OBJ into INODE at INDEX.\"\n (declare ((or null inode) inode)\n ((integer 0 #.most-positive-fixnum) index))\n (assert (<= index (inode-count inode)))\n (let ((obj-inode (%make-inode obj (random most-positive-fixnum))))\n (multiple-value-bind (left right)\n (inode-split inode index)\n (inode-merge (inode-merge left obj-inode) right))))\n\n(defun inode-map (function inode)\n \"Successively applies FUNCTION to INODE[0], ..., INODE[SIZE-1].\"\n (declare (function function))\n (when inode\n (force-down inode)\n (inode-map function (%inode-left inode))\n (funcall function (%inode-value inode))\n (inode-map function (%inode-right inode))\n (force-self inode)))\n\n(defmethod print-object ((object inode) stream)\n (print-unreadable-object (object stream :type t)\n (let ((size (inode-count object))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) index))\n (inode-map (lambda (x)\n (princ x stream)\n (incf index)\n (when (< index size)\n (write-char #\\ stream)))\n object))))\n\n(defmacro do-inode ((var inode &optional result) &body body)\n \"Successively binds INODE[0], ..., INODE[SIZE-1] to VAR and executes BODY.\"\n `(block nil\n (inode-map (lambda (,var) ,@body) ,inode)\n ,result))\n\n(defun inode (&rest args)\n ;; TODO: Currently takes O(nlog(n)) time though it can be reduced to O(n).\n (labels ((recurse (list position inode)\n (declare ((integer 0 #.most-positive-fixnum) position))\n (if (null list)\n inode\n (recurse (cdr list)\n (1+ position)\n (inode-insert inode position (car list))))))\n (recurse args 0 nil)))\n\n(declaim (inline make-inode))\n(defun make-inode (size)\n \"Makes a treap of SIZE in O(SIZE). The values are filled with the identity\nelement.\"\n (labels ((heapify (top)\n (when top\n (let ((prioritized-node top))\n (when (and (%inode-left top)\n (> (%inode-priority (%inode-left top))\n (%inode-priority prioritized-node)))\n (setq prioritized-node (%inode-left top)))\n (when (and (%inode-right top)\n (> (%inode-priority (%inode-right top))\n (%inode-priority prioritized-node)))\n (setq prioritized-node (%inode-right top)))\n (unless (eql prioritized-node top)\n (rotatef (%inode-priority prioritized-node)\n (%inode-priority top))\n (heapify prioritized-node)))))\n (build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-inode +op-identity+\n (random most-positive-fixnum))))\n (setf (%inode-left node) (build l mid))\n (setf (%inode-right node) (build (+ mid 1) r))\n (heapify node)\n (update-count node)\n node))))\n (build 0 size)))\n\n(declaim (inline inode-delete))\n(defun inode-delete (inode index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (assert (< index (inode-count inode)))\n (multiple-value-bind (inode1 inode2)\n (inode-split inode (1+ index))\n (multiple-value-bind (inode1 _)\n (inode-split inode1 index)\n (declare (ignore _))\n (inode-merge inode1 inode2))))\n\n(declaim (inline inode-ref))\n(defun inode-ref (inode index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (assert (< index (inode-count inode)))\n (labels ((%ref (inode index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (force-down inode)\n (prog1\n (let ((left-count (inode-count (%inode-left inode))))\n (cond ((< index left-count)\n (%ref (%inode-left inode) index))\n ((> index left-count)\n (%ref (%inode-right inode) (- index left-count 1)))\n (t (%inode-value inode))))\n (force-self inode))))\n (%ref inode index)))\n\n(declaim (inline (setf inode-ref)))\n(defun (setf inode-ref) (new-value inode index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (assert (< index (inode-count inode)))\n (labels ((%set (inode index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (force-down inode)\n (prog1\n (let ((left-count (inode-count (%inode-left inode))))\n (cond ((< index left-count)\n (%set (%inode-left inode) index))\n ((> index left-count)\n (%set (%inode-right inode) (- index left-count 1)))\n (t (setf (%inode-value inode) new-value))))\n (force-self inode))))\n (%set inode index)\n new-value))\n\n(defun copy-inode (inode)\n \"For development. Recursively copies the whole INODEs.\"\n (if (null inode)\n nil\n (%make-inode (%inode-value inode)\n (%inode-priority inode)\n :left (copy-inode (%inode-left inode))\n :right (copy-inode (%inode-right inode))\n :count (%inode-count inode)\n :accumulator (%inode-accumulator inode)\n :lazy (%inode-lazy inode)\n :reversed (%inode-reversed inode))))\n\n(defun inode-bisect-left (threshold treap &key (test #'<))\n \"Returns the smallest index and the corresponding key that satisfies\nKEY[index] >= THRESHOLD. Returns the size of TREAP and THRESHOLD if KEY[size-1]\n< THRESHOLD.\"\n (declare (function test))\n (labels ((recur (count treap)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null treap) nil)\n ((funcall test (%inode-value treap) threshold)\n (recur count (%inode-right treap)))\n (t (let ((left-count (- count (inode-count (%inode-right treap)) 1)))\n (let ((idx (recur left-count (%inode-left treap))))\n (if idx\n idx\n left-count)))))))\n (or (recur (inode-count treap) treap)\n (inode-count treap))))\n\n;; FIXME: might be problematic when two priorities collide.\n(declaim (inline inode-query))\n(defun inode-query (inode l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless (< l r)\n (return-from inode-query 0))\n (assert (<= r (inode-count inode)))\n (multiple-value-bind (inode-0-l inode-l-n)\n (inode-split inode l)\n (multiple-value-bind (inode-l-r inode-r-n)\n (inode-split inode-l-n (- r l))\n (prog1 (%inode-accumulator inode-l-r)\n (inode-merge inode-0-l (inode-merge inode-l-r inode-r-n))))))\n\n(declaim (inline inode-reverse))\n(defun inode-reverse (inode l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (assert (and (<= l r) (<= r (inode-count inode))))\n (multiple-value-bind (inode-0-l inode-l-n)\n (inode-split inode l)\n (multiple-value-bind (inode-l-r inode-r-n)\n (inode-split inode-l-n (- r l))\n (setf (%inode-reversed inode-l-r) (not (%inode-reversed inode-l-r)))\n (inode-merge inode-0-l (inode-merge inode-l-r inode-r-n)))))\n\n(declaim (inline inode-update))\n(defun inode-update (inode x l r)\n \"Updates INODE[i] := (OP INODE[i] X) for all i in [l, r)\"\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (assert (and (<= l r) (<= r (inode-count inode))))\n (multiple-value-bind (inode-0-l inode-l-n)\n (inode-split inode l)\n (multiple-value-bind (inode-l-r inode-r-n)\n (inode-split inode-l-n (- r l))\n (when inode-l-r\n (setf (%inode-lazy inode-l-r)\n (updater-op (%inode-lazy inode-l-r) x)))\n (inode-merge inode-0-l (inode-merge inode-l-r inode-r-n)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((q (read))\n (const 0)\n inode)\n (declare (uint32 q))\n (dotimes (i q)\n (let ((id (read-fixnum)))\n (if (= id 1)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (setf inode (inode-insert inode (inode-bisect-left a inode) a))\n (incf const b))\n (let ((count (inode-count inode)))\n (if (oddp count)\n (let* ((mid (floor count 2))\n (at (inode-ref inode mid)))\n (format t\n \"~D ~D~%\"\n at\n (+ const\n (inode-query inode (+ mid 1) (inode-count inode))\n (- (inode-query inode 0 mid)))))\n (let* ((mid (floor count 2))\n (at (inode-ref inode (- mid 1))))\n (format t\n \"~D ~D~%\"\n at\n (+ const\n (inode-query inode mid (inode-count inode))\n (- (inode-query inode 0 mid))))))))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1558837630, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03040.html", "problem_id": "p03040", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03040/input.txt", "sample_output_relpath": "derived/input_output/data/p03040/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03040/Lisp/s486670519.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s486670519", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4 2\n1 -3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(setf *print-circle* t)\n\n;; Treap with implicit key for updating and querying interval.\n\n(declaim (inline op))\n(defun op (a b)\n (+ a b))\n\n(defconstant +op-identity+ 0)\n\n(defconstant +updater-identity+ 0)\n\n(declaim (inline updater-op))\n(defun updater-op (a b)\n \"Is the operator to compute and update LAZY value.\"\n (+ a b))\n\n(declaim (inline modifier-op))\n(defun modifier-op (a b size)\n \"Is the operator to update ACCUMULATOR based on LAZY value.\"\n (declare (ignore size))\n (+ a b))\n\n(defstruct (inode (:constructor %make-inode (value priority &key left right (count 1) (accumulator +op-identity+) (lazy +updater-identity+) reversed))\n (:copier nil)\n (:conc-name %inode-))\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum) ; e.g. MIN, MAX, SUM, ...\n (lazy +updater-identity+ :type fixnum)\n (reversed nil :type boolean)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (integer 0 #.most-positive-fixnum))\n (left nil :type (or null inode))\n (right nil :type (or null inode)))\n\n(declaim (inline inode-count))\n(defun inode-count (inode)\n (declare ((or null inode) inode))\n (if inode\n (%inode-count inode)\n 0))\n\n(declaim (inline inode-accumulator))\n(defun inode-accumulator (inode)\n (declare ((or null inode) inode))\n (if inode\n (%inode-accumulator inode)\n +op-identity+))\n\n(declaim (inline update-count))\n(defun update-count (inode)\n (declare (inode inode))\n (setf (%inode-count inode)\n (+ 1\n (inode-count (%inode-left inode))\n (inode-count (%inode-right inode)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (inode)\n (declare (inode inode))\n (setf (%inode-accumulator inode)\n (if (%inode-left inode)\n (if (%inode-right inode)\n (let ((mid (op (%inode-accumulator (%inode-left inode))\n (%inode-value inode))))\n (declare (dynamic-extent mid))\n (op mid (%inode-accumulator (%inode-right inode))))\n (op (%inode-accumulator (%inode-left inode))\n (%inode-value inode)))\n (if (%inode-right inode)\n (op (%inode-value inode)\n (%inode-accumulator (%inode-right inode)))\n (%inode-value inode)))))\n\n(declaim (inline force-self))\n(defun force-self (inode)\n (declare (inode inode))\n (update-count inode)\n (update-accumulator inode))\n\n(declaim (inline force-down))\n(defun force-down (inode)\n (declare (inode inode))\n (when (%inode-reversed inode)\n (setf (%inode-reversed inode) nil)\n (rotatef (%inode-left inode) (%inode-right inode))\n (let ((left (%inode-left inode)))\n (when left\n (setf (%inode-reversed left) (not (%inode-reversed left)))))\n (let ((right (%inode-right inode)))\n (when right\n (setf (%inode-reversed right) (not (%inode-reversed right))))))\n (unless (eql +updater-identity+ (%inode-lazy inode))\n (when (%inode-left inode)\n (setf (%inode-lazy (%inode-left inode))\n (updater-op (%inode-lazy (%inode-left inode))\n (%inode-lazy inode)))\n (setf (%inode-accumulator (%inode-left inode))\n (modifier-op (%inode-accumulator (%inode-left inode))\n (%inode-lazy inode)\n (%inode-count (%inode-left inode)))))\n (when (%inode-right inode)\n (setf (%inode-lazy (%inode-right inode))\n (updater-op (%inode-lazy (%inode-right inode))\n (%inode-lazy inode)))\n (setf (%inode-accumulator (%inode-right inode))\n (modifier-op (%inode-accumulator (%inode-right inode))\n (%inode-lazy inode)\n (%inode-count (%inode-right inode)))))\n (setf (%inode-value inode)\n (modifier-op (%inode-value inode)\n (%inode-lazy inode)\n 1))\n (setf (%inode-lazy inode) +updater-identity+)))\n\n(defun inode-split (inode index)\n \"Destructively splits the INODE into two nodes [0, INDEX) and [INDEX, N), where N\n is the number of elements of the INODE.\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless inode\n (return-from inode-split (values nil nil)))\n (force-down inode)\n (let ((implicit-key (1+ (inode-count (%inode-left inode)))))\n (if (< index implicit-key)\n (multiple-value-bind (left right)\n (inode-split (%inode-left inode) index)\n (setf (%inode-left inode) right)\n (force-self inode)\n (values left inode))\n (multiple-value-bind (left right)\n (inode-split (%inode-right inode) (- index implicit-key))\n (setf (%inode-right inode) left)\n (force-self inode)\n (values inode right)))))\n\n(defun inode-merge (left right)\n \"Destructively merges two INODEs.\"\n (declare ((or null inode) left right))\n (cond ((null left) (when right (force-down right) (force-self right)) right)\n ((null right) (when left (force-down left) (force-self left)) left)\n (t (force-down left)\n (force-down right)\n (if (> (%inode-priority left) (%inode-priority right))\n (progn\n (setf (%inode-right left)\n (inode-merge (%inode-right left) right))\n (force-self left)\n left)\n (progn\n (setf (%inode-left right)\n (inode-merge left (%inode-left right)))\n (force-self right)\n right)))))\n\n;; (define-condition invalid-itreap-index-error (type-error)\n;; ((itreap :initarg :itreap :reader invalid-itreap-index-error-itreap)\n;; (index :initarg :index :reader invalid-itreap-index-error-index))\n;; (:report\n;; (lambda (condition stream)\n;; (format stream \"Invalid index ~W for itreap ~S.\"\n;; (invalid-itreap-index-error-index condition)\n;; (invalid-itreap-index-error-itreap condition)))))\n\n(declaim (inline inode-insert))\n(defun inode-insert (inode index obj)\n \"Destructively inserts OBJ into INODE at INDEX.\"\n (declare ((or null inode) inode)\n ((integer 0 #.most-positive-fixnum) index))\n (assert (<= index (inode-count inode)))\n (let ((obj-inode (%make-inode obj (random most-positive-fixnum))))\n (multiple-value-bind (left right)\n (inode-split inode index)\n (inode-merge (inode-merge left obj-inode) right))))\n\n(defun inode-map (function inode)\n \"Successively applies FUNCTION to INODE[0], ..., INODE[SIZE-1].\"\n (declare (function function))\n (when inode\n (force-down inode)\n (inode-map function (%inode-left inode))\n (funcall function (%inode-value inode))\n (inode-map function (%inode-right inode))\n (force-self inode)))\n\n(defmethod print-object ((object inode) stream)\n (print-unreadable-object (object stream :type t)\n (let ((size (inode-count object))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) index))\n (inode-map (lambda (x)\n (princ x stream)\n (incf index)\n (when (< index size)\n (write-char #\\ stream)))\n object))))\n\n(defmacro do-inode ((var inode &optional result) &body body)\n \"Successively binds INODE[0], ..., INODE[SIZE-1] to VAR and executes BODY.\"\n `(block nil\n (inode-map (lambda (,var) ,@body) ,inode)\n ,result))\n\n(defun inode (&rest args)\n ;; TODO: Currently takes O(nlog(n)) time though it can be reduced to O(n).\n (labels ((recurse (list position inode)\n (declare ((integer 0 #.most-positive-fixnum) position))\n (if (null list)\n inode\n (recurse (cdr list)\n (1+ position)\n (inode-insert inode position (car list))))))\n (recurse args 0 nil)))\n\n(declaim (inline make-inode))\n(defun make-inode (size)\n \"Makes a treap of SIZE in O(SIZE). The values are filled with the identity\nelement.\"\n (labels ((heapify (top)\n (when top\n (let ((prioritized-node top))\n (when (and (%inode-left top)\n (> (%inode-priority (%inode-left top))\n (%inode-priority prioritized-node)))\n (setq prioritized-node (%inode-left top)))\n (when (and (%inode-right top)\n (> (%inode-priority (%inode-right top))\n (%inode-priority prioritized-node)))\n (setq prioritized-node (%inode-right top)))\n (unless (eql prioritized-node top)\n (rotatef (%inode-priority prioritized-node)\n (%inode-priority top))\n (heapify prioritized-node)))))\n (build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-inode +op-identity+\n (random most-positive-fixnum))))\n (setf (%inode-left node) (build l mid))\n (setf (%inode-right node) (build (+ mid 1) r))\n (heapify node)\n (update-count node)\n node))))\n (build 0 size)))\n\n(declaim (inline inode-delete))\n(defun inode-delete (inode index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (assert (< index (inode-count inode)))\n (multiple-value-bind (inode1 inode2)\n (inode-split inode (1+ index))\n (multiple-value-bind (inode1 _)\n (inode-split inode1 index)\n (declare (ignore _))\n (inode-merge inode1 inode2))))\n\n(declaim (inline inode-ref))\n(defun inode-ref (inode index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (assert (< index (inode-count inode)))\n (labels ((%ref (inode index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (force-down inode)\n (prog1\n (let ((left-count (inode-count (%inode-left inode))))\n (cond ((< index left-count)\n (%ref (%inode-left inode) index))\n ((> index left-count)\n (%ref (%inode-right inode) (- index left-count 1)))\n (t (%inode-value inode))))\n (force-self inode))))\n (%ref inode index)))\n\n(declaim (inline (setf inode-ref)))\n(defun (setf inode-ref) (new-value inode index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (assert (< index (inode-count inode)))\n (labels ((%set (inode index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (force-down inode)\n (prog1\n (let ((left-count (inode-count (%inode-left inode))))\n (cond ((< index left-count)\n (%set (%inode-left inode) index))\n ((> index left-count)\n (%set (%inode-right inode) (- index left-count 1)))\n (t (setf (%inode-value inode) new-value))))\n (force-self inode))))\n (%set inode index)\n new-value))\n\n(defun copy-inode (inode)\n \"For development. Recursively copies the whole INODEs.\"\n (if (null inode)\n nil\n (%make-inode (%inode-value inode)\n (%inode-priority inode)\n :left (copy-inode (%inode-left inode))\n :right (copy-inode (%inode-right inode))\n :count (%inode-count inode)\n :accumulator (%inode-accumulator inode)\n :lazy (%inode-lazy inode)\n :reversed (%inode-reversed inode))))\n\n(defun inode-bisect-left (threshold treap &key (test #'<))\n \"Returns the smallest index and the corresponding key that satisfies\nKEY[index] >= THRESHOLD. Returns the size of TREAP and THRESHOLD if KEY[size-1]\n< THRESHOLD.\"\n (declare (function test))\n (labels ((recur (count treap)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null treap) nil)\n ((funcall test (%inode-value treap) threshold)\n (recur count (%inode-right treap)))\n (t (let ((left-count (- count (inode-count (%inode-right treap)) 1)))\n (let ((idx (recur left-count (%inode-left treap))))\n (if idx\n idx\n left-count)))))))\n (or (recur (inode-count treap) treap)\n (inode-count treap))))\n\n;; FIXME: might be problematic when two priorities collide.\n(declaim (inline inode-query))\n(defun inode-query (inode l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (unless (< l r)\n (return-from inode-query 0))\n (assert (<= r (inode-count inode)))\n (multiple-value-bind (inode-0-l inode-l-n)\n (inode-split inode l)\n (multiple-value-bind (inode-l-r inode-r-n)\n (inode-split inode-l-n (- r l))\n (prog1 (%inode-accumulator inode-l-r)\n (inode-merge inode-0-l (inode-merge inode-l-r inode-r-n))))))\n\n(declaim (inline inode-reverse))\n(defun inode-reverse (inode l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (assert (and (<= l r) (<= r (inode-count inode))))\n (multiple-value-bind (inode-0-l inode-l-n)\n (inode-split inode l)\n (multiple-value-bind (inode-l-r inode-r-n)\n (inode-split inode-l-n (- r l))\n (setf (%inode-reversed inode-l-r) (not (%inode-reversed inode-l-r)))\n (inode-merge inode-0-l (inode-merge inode-l-r inode-r-n)))))\n\n(declaim (inline inode-update))\n(defun inode-update (inode x l r)\n \"Updates INODE[i] := (OP INODE[i] X) for all i in [l, r)\"\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (assert (and (<= l r) (<= r (inode-count inode))))\n (multiple-value-bind (inode-0-l inode-l-n)\n (inode-split inode l)\n (multiple-value-bind (inode-l-r inode-r-n)\n (inode-split inode-l-n (- r l))\n (when inode-l-r\n (setf (%inode-lazy inode-l-r)\n (updater-op (%inode-lazy inode-l-r) x)))\n (inode-merge inode-0-l (inode-merge inode-l-r inode-r-n)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((q (read))\n (const 0)\n inode)\n (declare (uint32 q))\n (dotimes (i q)\n (let ((id (read-fixnum)))\n (if (= id 1)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (setf inode (inode-insert inode (inode-bisect-left a inode) a))\n (incf const b))\n (let ((count (inode-count inode)))\n (if (oddp count)\n (let* ((mid (floor count 2))\n (at (inode-ref inode mid)))\n (format t\n \"~D ~D~%\"\n at\n (+ const\n (inode-query inode (+ mid 1) (inode-count inode))\n (- (inode-query inode 0 mid)))))\n (let* ((mid (floor count 2))\n (at (inode-ref inode (- mid 1))))\n (format t\n \"~D ~D~%\"\n at\n (+ const\n (inode-query inode mid (inode-count inode))\n (- (inode-query inode 0 mid))))))))))))\n\n#-swank(main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere is a function f(x), which is initially a constant function f(x) = 0.\n\nWe will ask you to process Q queries in order. There are two kinds of queries, update queries and evaluation queries, as follows:\n\nAn update query 1 a b: Given two integers a and b, let g(x) = f(x) + |x - a| + b and replace f(x) with g(x).\n\nAn evaluation query 2: Print x that minimizes f(x), and the minimum value of f(x). If there are multiple such values of x, choose the minimum such value.\n\nWe can show that the values to be output in an evaluation query are always integers, so we ask you to print those values as integers without decimal points.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq Q \\leq 2 \\times 10^5\n\n-10^9 \\leq a, b \\leq 10^9\n\nThe first query is an update query.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nQ\nQuery_1\n:\nQuery_Q\n\nSee Sample Input 1 for an example.\n\nOutput\n\nFor each evaluation query, print a line containing the response, in the order in which the queries are given.\n\nThe response to each evaluation query should be the minimum value of x that minimizes f(x), and the minimum value of f(x), in this order, with space in between.\n\nSample Input 1\n\n4\n1 4 2\n2\n1 1 -8\n2\n\nSample Output 1\n\n4 2\n1 -3\n\nIn the first evaluation query, f(x) = |x - 4| + 2, which attains the minimum value of 2 at x = 4.\n\nIn the second evaluation query, f(x) = |x - 1| + |x - 4| - 6, which attains the minimum value of -3 when 1 \\leq x \\leq 4. Among the multiple values of x that minimize f(x), we ask you to print the minimum, that is, 1.\n\nSample Input 2\n\n4\n1 -1000000000 1000000000\n1 -1000000000 1000000000\n1 -1000000000 1000000000\n2\n\nSample Output 2\n\n-1000000000 3000000000", "sample_input": "4\n1 4 2\n2\n1 1 -8\n2\n"}, "reference_outputs": ["4 2\n1 -3\n"], "source_document_id": "p03040", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere is a function f(x), which is initially a constant function f(x) = 0.\n\nWe will ask you to process Q queries in order. There are two kinds of queries, update queries and evaluation queries, as follows:\n\nAn update query 1 a b: Given two integers a and b, let g(x) = f(x) + |x - a| + b and replace f(x) with g(x).\n\nAn evaluation query 2: Print x that minimizes f(x), and the minimum value of f(x). If there are multiple such values of x, choose the minimum such value.\n\nWe can show that the values to be output in an evaluation query are always integers, so we ask you to print those values as integers without decimal points.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq Q \\leq 2 \\times 10^5\n\n-10^9 \\leq a, b \\leq 10^9\n\nThe first query is an update query.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nQ\nQuery_1\n:\nQuery_Q\n\nSee Sample Input 1 for an example.\n\nOutput\n\nFor each evaluation query, print a line containing the response, in the order in which the queries are given.\n\nThe response to each evaluation query should be the minimum value of x that minimizes f(x), and the minimum value of f(x), in this order, with space in between.\n\nSample Input 1\n\n4\n1 4 2\n2\n1 1 -8\n2\n\nSample Output 1\n\n4 2\n1 -3\n\nIn the first evaluation query, f(x) = |x - 4| + 2, which attains the minimum value of 2 at x = 4.\n\nIn the second evaluation query, f(x) = |x - 1| + |x - 4| - 6, which attains the minimum value of -3 when 1 \\leq x \\leq 4. Among the multiple values of x that minimize f(x), we ask you to print the minimum, that is, 1.\n\nSample Input 2\n\n4\n1 -1000000000 1000000000\n1 -1000000000 1000000000\n1 -1000000000 1000000000\n2\n\nSample Output 2\n\n-1000000000 3000000000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 17807, "cpu_time_ms": 1508, "memory_kb": 76264}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s093241628", "group_id": "codeNet:p03041", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (s (read-line)))\n (setf (aref s (- k 1)) (char-downcase (aref s (- k 1))))\n (write-line s)))\n\n#-swank(main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &optional (func #'main))\n (labels ((ensure-last-lf (s)\n (if (and (> (length s) 0)\n (eql (char s (- (length s) 1)) #\\Linefeed))\n s\n (uiop:strcat s uiop:+lf+))))\n (equal (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall func)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n (let ((*standard-output* out))\n (etypecase thing\n (null ; Runs #'MAIN with the string on clipboard\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname ; Runs #'MAIN with the string in a text file\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n", "language": "Lisp", "metadata": {"date": 1558314233, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03041.html", "problem_id": "p03041", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03041/input.txt", "sample_output_relpath": "derived/input_output/data/p03041/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03041/Lisp/s093241628.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s093241628", "user_id": "u352600849"}, "prompt_components": {"gold_output": "aBC\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (s (read-line)))\n (setf (aref s (- k 1)) (char-downcase (aref s (- k 1))))\n (write-line s)))\n\n#-swank(main)\n\n\n;; For Test\n#+swank\n(defun io-equal (in-string out-string &optional (func #'main))\n (labels ((ensure-last-lf (s)\n (if (and (> (length s) 0)\n (eql (char s (- (length s) 1)) #\\Linefeed))\n s\n (uiop:strcat s uiop:+lf+))))\n (equal (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall func)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n (let ((*standard-output* out))\n (etypecase thing\n (null ; Runs #'MAIN with the string on clipboard\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname ; Runs #'MAIN with the string in a text file\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a string S of length N consisting of A, B and C, and an integer K which is between 1 and N (inclusive).\nPrint the string S after lowercasing the K-th character in it.\n\nConstraints\n\n1 ≤ N ≤ 50\n\n1 ≤ K ≤ N\n\nS is a string of length N consisting of A, B and C.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nS\n\nOutput\n\nPrint the string S after lowercasing the K-th character in it.\n\nSample Input 1\n\n3 1\nABC\n\nSample Output 1\n\naBC\n\nSample Input 2\n\n4 3\nCABA\n\nSample Output 2\n\nCAbA", "sample_input": "3 1\nABC\n"}, "reference_outputs": ["aBC\n"], "source_document_id": "p03041", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a string S of length N consisting of A, B and C, and an integer K which is between 1 and N (inclusive).\nPrint the string S after lowercasing the K-th character in it.\n\nConstraints\n\n1 ≤ N ≤ 50\n\n1 ≤ K ≤ N\n\nS is a string of length N consisting of A, B and C.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nS\n\nOutput\n\nPrint the string S after lowercasing the K-th character in it.\n\nSample Input 1\n\n3 1\nABC\n\nSample Output 1\n\naBC\n\nSample Input 2\n\n4 3\nCABA\n\nSample Output 2\n\nCAbA", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2964, "cpu_time_ms": 160, "memory_kb": 15460}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s487401738", "group_id": "codeNet:p03042", "input_text": "(defun answer-word (YYMM MMYY)\n (cond ((and YYMM MMYY) \"AMBIGUOUS\")\n ((and (not YYMM) MMYY) \"MMYY\")\n ((and YYMM (not MMYY)) \"YYMM\")\n (t \"NA\")))\n\n(defun is-MM (n)\n (and (< 0 n)\n (< n 13)))\n\n;(defun is-YY (n) t)\n\n(defun can-YYMM (str)\n (is-MM (parse-integer (subseq str 2))))\n(defun can-MMYY (str)\n (is-MM (parse-integer (subseq str 0 2))))\n\n(let ((str (read-line)))\n (princ (answer-word (can-YYMM str) (can-MMYY str))))", "language": "Lisp", "metadata": {"date": 1585521921, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03042.html", "problem_id": "p03042", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03042/input.txt", "sample_output_relpath": "derived/input_output/data/p03042/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03042/Lisp/s487401738.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s487401738", "user_id": "u606976120"}, "prompt_components": {"gold_output": "YYMM\n", "input_to_evaluate": "(defun answer-word (YYMM MMYY)\n (cond ((and YYMM MMYY) \"AMBIGUOUS\")\n ((and (not YYMM) MMYY) \"MMYY\")\n ((and YYMM (not MMYY)) \"YYMM\")\n (t \"NA\")))\n\n(defun is-MM (n)\n (and (< 0 n)\n (< n 13)))\n\n;(defun is-YY (n) t)\n\n(defun can-YYMM (str)\n (is-MM (parse-integer (subseq str 2))))\n(defun can-MMYY (str)\n (is-MM (parse-integer (subseq str 0 2))))\n\n(let ((str (read-line)))\n (princ (answer-word (can-YYMM str) (can-MMYY str))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou have a digit sequence S of length 4. You are wondering which of the following formats S is in:\n\nYYMM format: the last two digits of the year and the two-digit representation of the month (example: 01 for January), concatenated in this order\n\nMMYY format: the two-digit representation of the month and the last two digits of the year, concatenated in this order\n\nIf S is valid in only YYMM format, print YYMM; if S is valid in only MMYY format, print MMYY; if S is valid in both formats, print AMBIGUOUS; if S is valid in neither format, print NA.\n\nConstraints\n\nS is a digit sequence of length 4.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the specified string: YYMM, MMYY, AMBIGUOUS or NA.\n\nSample Input 1\n\n1905\n\nSample Output 1\n\nYYMM\n\nMay XX19 is a valid date, but 19 is not valid as a month. Thus, this string is only valid in YYMM format.\n\nSample Input 2\n\n0112\n\nSample Output 2\n\nAMBIGUOUS\n\nBoth December XX01 and January XX12 are valid dates. Thus, this string is valid in both formats.\n\nSample Input 3\n\n1700\n\nSample Output 3\n\nNA\n\nNeither 0 nor 17 is valid as a month. Thus, this string is valid in neither format.", "sample_input": "1905\n"}, "reference_outputs": ["YYMM\n"], "source_document_id": "p03042", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou have a digit sequence S of length 4. You are wondering which of the following formats S is in:\n\nYYMM format: the last two digits of the year and the two-digit representation of the month (example: 01 for January), concatenated in this order\n\nMMYY format: the two-digit representation of the month and the last two digits of the year, concatenated in this order\n\nIf S is valid in only YYMM format, print YYMM; if S is valid in only MMYY format, print MMYY; if S is valid in both formats, print AMBIGUOUS; if S is valid in neither format, print NA.\n\nConstraints\n\nS is a digit sequence of length 4.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the specified string: YYMM, MMYY, AMBIGUOUS or NA.\n\nSample Input 1\n\n1905\n\nSample Output 1\n\nYYMM\n\nMay XX19 is a valid date, but 19 is not valid as a month. Thus, this string is only valid in YYMM format.\n\nSample Input 2\n\n0112\n\nSample Output 2\n\nAMBIGUOUS\n\nBoth December XX01 and January XX12 are valid dates. Thus, this string is valid in both formats.\n\nSample Input 3\n\n1700\n\nSample Output 3\n\nNA\n\nNeither 0 nor 17 is valid as a month. Thus, this string is valid in neither format.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 450, "cpu_time_ms": 29, "memory_kb": 4708}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s975327333", "group_id": "codeNet:p03042", "input_text": "(defun yymm (aa bb)\n (let ((am (and (<= 1 aa) (<= aa 12)))\n (bm (and (<= 1 bb) (<= bb 12))))\n (cond ((and am bm) \"AMBIGUOUS\")\n (am \"MMYY\")\n (bm \"YYMM\")\n (t \"NA\"))))\n\n(defun w_yymm (str)\n (if (not (= (length str) 4)) \"NA\"\n (let ((num (read-from-string str)))\n (if (not (numberp num)) \"NA\"\n (multiple-value-bind (aa bb) (floor num 100)\n (yymm aa bb))))))\n#|\n(print (yymm 17 00))\n(print (yymm 01 12))\n(print (yymm 19 05))\n(print (w_yymm \"abc\"))\n(print (w_yymm \"123\"))\n(print (w_yymm \"1700\"))\n(print (w_yymm \"0112\"))\n(print (w_yymm \"1905\"))\n(print (w_yymm \"0000\"))\n|#\n\n(let ((str (read-line)))\n (format t (w_yymm str)))\n", "language": "Lisp", "metadata": {"date": 1558322171, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03042.html", "problem_id": "p03042", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03042/input.txt", "sample_output_relpath": "derived/input_output/data/p03042/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03042/Lisp/s975327333.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s975327333", "user_id": "u788952094"}, "prompt_components": {"gold_output": "YYMM\n", "input_to_evaluate": "(defun yymm (aa bb)\n (let ((am (and (<= 1 aa) (<= aa 12)))\n (bm (and (<= 1 bb) (<= bb 12))))\n (cond ((and am bm) \"AMBIGUOUS\")\n (am \"MMYY\")\n (bm \"YYMM\")\n (t \"NA\"))))\n\n(defun w_yymm (str)\n (if (not (= (length str) 4)) \"NA\"\n (let ((num (read-from-string str)))\n (if (not (numberp num)) \"NA\"\n (multiple-value-bind (aa bb) (floor num 100)\n (yymm aa bb))))))\n#|\n(print (yymm 17 00))\n(print (yymm 01 12))\n(print (yymm 19 05))\n(print (w_yymm \"abc\"))\n(print (w_yymm \"123\"))\n(print (w_yymm \"1700\"))\n(print (w_yymm \"0112\"))\n(print (w_yymm \"1905\"))\n(print (w_yymm \"0000\"))\n|#\n\n(let ((str (read-line)))\n (format t (w_yymm str)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou have a digit sequence S of length 4. You are wondering which of the following formats S is in:\n\nYYMM format: the last two digits of the year and the two-digit representation of the month (example: 01 for January), concatenated in this order\n\nMMYY format: the two-digit representation of the month and the last two digits of the year, concatenated in this order\n\nIf S is valid in only YYMM format, print YYMM; if S is valid in only MMYY format, print MMYY; if S is valid in both formats, print AMBIGUOUS; if S is valid in neither format, print NA.\n\nConstraints\n\nS is a digit sequence of length 4.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the specified string: YYMM, MMYY, AMBIGUOUS or NA.\n\nSample Input 1\n\n1905\n\nSample Output 1\n\nYYMM\n\nMay XX19 is a valid date, but 19 is not valid as a month. Thus, this string is only valid in YYMM format.\n\nSample Input 2\n\n0112\n\nSample Output 2\n\nAMBIGUOUS\n\nBoth December XX01 and January XX12 are valid dates. Thus, this string is valid in both formats.\n\nSample Input 3\n\n1700\n\nSample Output 3\n\nNA\n\nNeither 0 nor 17 is valid as a month. Thus, this string is valid in neither format.", "sample_input": "1905\n"}, "reference_outputs": ["YYMM\n"], "source_document_id": "p03042", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou have a digit sequence S of length 4. You are wondering which of the following formats S is in:\n\nYYMM format: the last two digits of the year and the two-digit representation of the month (example: 01 for January), concatenated in this order\n\nMMYY format: the two-digit representation of the month and the last two digits of the year, concatenated in this order\n\nIf S is valid in only YYMM format, print YYMM; if S is valid in only MMYY format, print MMYY; if S is valid in both formats, print AMBIGUOUS; if S is valid in neither format, print NA.\n\nConstraints\n\nS is a digit sequence of length 4.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the specified string: YYMM, MMYY, AMBIGUOUS or NA.\n\nSample Input 1\n\n1905\n\nSample Output 1\n\nYYMM\n\nMay XX19 is a valid date, but 19 is not valid as a month. Thus, this string is only valid in YYMM format.\n\nSample Input 2\n\n0112\n\nSample Output 2\n\nAMBIGUOUS\n\nBoth December XX01 and January XX12 are valid dates. Thus, this string is valid in both formats.\n\nSample Input 3\n\n1700\n\nSample Output 3\n\nNA\n\nNeither 0 nor 17 is valid as a month. Thus, this string is valid in neither format.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 680, "cpu_time_ms": 146, "memory_kb": 15844}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s693171458", "group_id": "codeNet:p03043", "input_text": "(let ((n (read))\n (k (read))\n temp\n (ans 0))\n (loop for i from 1 upto n do\n (setf temp 0)\n (loop for j from 0 upto 20\n while (< (* i (expt 2 j)) k) do (incf temp))\n (incf ans (/ 1 (* n (expt 2 temp)))))\n (format t \"~A~%\" (float ans)))\n", "language": "Lisp", "metadata": {"date": 1558315791, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03043.html", "problem_id": "p03043", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03043/input.txt", "sample_output_relpath": "derived/input_output/data/p03043/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03043/Lisp/s693171458.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s693171458", "user_id": "u994767958"}, "prompt_components": {"gold_output": "0.145833333333\n", "input_to_evaluate": "(let ((n (read))\n (k (read))\n temp\n (ans 0))\n (loop for i from 1 upto n do\n (setf temp 0)\n (loop for j from 0 upto 20\n while (< (* i (expt 2 j)) k) do (incf temp))\n (incf ans (/ 1 (* n (expt 2 temp)))))\n (format t \"~A~%\" (float ans)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:\n\nThrow the die. The current score is the result of the die.\n\nAs long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.\n\nThe game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.\n\nYou are given N and K. Find the probability that Snuke wins the game.\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n1 ≤ K ≤ 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.\n\nSample Input 1\n\n3 10\n\nSample Output 1\n\n0.145833333333\n\nIf the die shows 1, Snuke needs to get four consecutive heads from four coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^4 = \\frac{1}{48}.\n\nIf the die shows 2, Snuke needs to get three consecutive heads from three coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^3 = \\frac{1}{24}.\n\nIf the die shows 3, Snuke needs to get two consecutive heads from two coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^2 = \\frac{1}{12}.\n\nThus, the probability that Snuke wins is \\frac{1}{48} + \\frac{1}{24} + \\frac{1}{12} = \\frac{7}{48} \\simeq 0.1458333333.\n\nSample Input 2\n\n100000 5\n\nSample Output 2\n\n0.999973749998", "sample_input": "3 10\n"}, "reference_outputs": ["0.145833333333\n"], "source_document_id": "p03043", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:\n\nThrow the die. The current score is the result of the die.\n\nAs long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.\n\nThe game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.\n\nYou are given N and K. Find the probability that Snuke wins the game.\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n1 ≤ K ≤ 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.\n\nSample Input 1\n\n3 10\n\nSample Output 1\n\n0.145833333333\n\nIf the die shows 1, Snuke needs to get four consecutive heads from four coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^4 = \\frac{1}{48}.\n\nIf the die shows 2, Snuke needs to get three consecutive heads from three coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^3 = \\frac{1}{24}.\n\nIf the die shows 3, Snuke needs to get two consecutive heads from two coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^2 = \\frac{1}{12}.\n\nThus, the probability that Snuke wins is \\frac{1}{48} + \\frac{1}{24} + \\frac{1}{12} = \\frac{7}{48} \\simeq 0.1458333333.\n\nSample Input 2\n\n100000 5\n\nSample Output 2\n\n0.999973749998", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 287, "cpu_time_ms": 139, "memory_kb": 13664}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s994393236", "group_id": "codeNet:p03044", "input_text": "(defconstant +color-unknown+ -1)\n(defconstant +color-white+ 0)\n(defconstant +color-black+ 1)\n\n(defmacro next-int ()\n '(read))\n\n(defun solve ()\n (let* ((n (next-int)) ; 頂点の数\n ;; 根を除いて各頂点にはたった1つの親頂点があるので、辺の数は\n ;; 「頂点の数-1」になる。\n (from (make-array (1- n))) ; 番号が小さいほうの頂点\n (to (make-array (1- n))) ; 番号が大きいほうの頂点\n (w (make-array (1- n)))) ; 辺の長さ\n (loop for i below (1- n)\n do\n ;; 0ベース配列の添字にしたいので、各頂点番号をデクリメントしておく。\n (setf (aref from i) (1- (next-int)))\n (setf (aref to i) (1- (next-int)))\n (setf (aref w i) (next-int)))\n\n (let ((g (pack-wu n from to w))\n (color (make-array n :initial-element +color-unknown+))) ; 頂点の色。\n\n (dfs 0 color g +color-white+)\n\n (format t \"~{~A~^~%~}~%\" (coerce color 'list)))))\n\n(defun dfs (now ; 現在訪問している頂点\n color ; 色を出力する配列\n g ; 辺の接続先と長さの情報\n mod) ; 現在の頂点の色(0 か 1)\n (setf (aref color now) mod)\n (loop for edge across (aref g now)\n do\n (when (= (aref color (first edge)) +color-unknown+)\n (dfs (first edge) color g (mod (+ mod (second edge)) 2)))))\n\n;; 各頂点についてその接続情報を収めた表 g を生成して返す。\n;; g[頂点番号][各辺][+edge-other-vertex+] = 辺の長さ\n;; g[頂点番号][各辺][+edge-length+] = 接続先の頂点\n(defun pack-wu (n from to w)\n (let ((sup (length from)) ; 辺の数\n (g (make-array n))\n (p (make-array n :initial-element 0))) ; 各頂点の次数(接続している辺の数)\n\n ;; 各頂点の次数を数える。各辺は、2つの頂点の次数をそれぞれ1つずつ\n ;; 増やす。\n (loop for i below sup\n do\n (incf (aref p (aref from i)))\n (incf (aref p (aref to i))))\n\n (loop for i below n\n do\n ;; g[i] に頂点 i 接続している辺の情報を収める配列を割り当てる。\n (setf (aref g i) (make-array (aref p i))))\n\n ;; 各頂点の持つ辺の情報を配列の後ろから格納する。\n (loop for i below sup\n do\n (let ((v (aref from i))\n (u (aref to i))\n (len (aref w i)))\n\n (decf (aref p v))\n (setf (aref (aref g v) (aref p v)) (list u len))\n\n (decf (aref p u))\n (setf (aref (aref g u) (aref p u)) (list v len))))\n\n g))\n\n(solve)\n", "language": "Lisp", "metadata": {"date": 1558523449, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03044.html", "problem_id": "p03044", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03044/input.txt", "sample_output_relpath": "derived/input_output/data/p03044/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03044/Lisp/s994393236.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s994393236", "user_id": "u321226359"}, "prompt_components": {"gold_output": "0\n0\n1\n", "input_to_evaluate": "(defconstant +color-unknown+ -1)\n(defconstant +color-white+ 0)\n(defconstant +color-black+ 1)\n\n(defmacro next-int ()\n '(read))\n\n(defun solve ()\n (let* ((n (next-int)) ; 頂点の数\n ;; 根を除いて各頂点にはたった1つの親頂点があるので、辺の数は\n ;; 「頂点の数-1」になる。\n (from (make-array (1- n))) ; 番号が小さいほうの頂点\n (to (make-array (1- n))) ; 番号が大きいほうの頂点\n (w (make-array (1- n)))) ; 辺の長さ\n (loop for i below (1- n)\n do\n ;; 0ベース配列の添字にしたいので、各頂点番号をデクリメントしておく。\n (setf (aref from i) (1- (next-int)))\n (setf (aref to i) (1- (next-int)))\n (setf (aref w i) (next-int)))\n\n (let ((g (pack-wu n from to w))\n (color (make-array n :initial-element +color-unknown+))) ; 頂点の色。\n\n (dfs 0 color g +color-white+)\n\n (format t \"~{~A~^~%~}~%\" (coerce color 'list)))))\n\n(defun dfs (now ; 現在訪問している頂点\n color ; 色を出力する配列\n g ; 辺の接続先と長さの情報\n mod) ; 現在の頂点の色(0 か 1)\n (setf (aref color now) mod)\n (loop for edge across (aref g now)\n do\n (when (= (aref color (first edge)) +color-unknown+)\n (dfs (first edge) color g (mod (+ mod (second edge)) 2)))))\n\n;; 各頂点についてその接続情報を収めた表 g を生成して返す。\n;; g[頂点番号][各辺][+edge-other-vertex+] = 辺の長さ\n;; g[頂点番号][各辺][+edge-length+] = 接続先の頂点\n(defun pack-wu (n from to w)\n (let ((sup (length from)) ; 辺の数\n (g (make-array n))\n (p (make-array n :initial-element 0))) ; 各頂点の次数(接続している辺の数)\n\n ;; 各頂点の次数を数える。各辺は、2つの頂点の次数をそれぞれ1つずつ\n ;; 増やす。\n (loop for i below sup\n do\n (incf (aref p (aref from i)))\n (incf (aref p (aref to i))))\n\n (loop for i below n\n do\n ;; g[i] に頂点 i 接続している辺の情報を収める配列を割り当てる。\n (setf (aref g i) (make-array (aref p i))))\n\n ;; 各頂点の持つ辺の情報を配列の後ろから格納する。\n (loop for i below sup\n do\n (let ((v (aref from i))\n (u (aref to i))\n (len (aref w i)))\n\n (decf (aref p v))\n (setf (aref (aref g v) (aref p v)) (list u len))\n\n (decf (aref p u))\n (setf (aref (aref g u) (aref p u)) (list v len))))\n\n g))\n\n(solve)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have a tree with N vertices numbered 1 to N.\nThe i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i.\nYour objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:\n\nFor any two vertices painted in the same color, the distance between them is an even number.\n\nFind a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq u_i < v_i \\leq N\n\n1 \\leq w_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nu_1 v_1 w_1\nu_2 v_2 w_2\n.\n.\n.\nu_{N - 1} v_{N - 1} w_{N - 1}\n\nOutput\n\nPrint a coloring of the vertices that satisfies the condition, in N lines.\nThe i-th line should contain 0 if Vertex i is painted white and 1 if it is painted black.\n\nIf there are multiple colorings that satisfy the condition, any of them will be accepted.\n\nSample Input 1\n\n3\n1 2 2\n2 3 1\n\nSample Output 1\n\n0\n0\n1\n\nSample Input 2\n\n5\n2 5 2\n2 3 10\n1 3 8\n3 4 2\n\nSample Output 2\n\n1\n0\n1\n0\n1", "sample_input": "3\n1 2 2\n2 3 1\n"}, "reference_outputs": ["0\n0\n1\n"], "source_document_id": "p03044", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have a tree with N vertices numbered 1 to N.\nThe i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i.\nYour objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:\n\nFor any two vertices painted in the same color, the distance between them is an even number.\n\nFind a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq u_i < v_i \\leq N\n\n1 \\leq w_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nu_1 v_1 w_1\nu_2 v_2 w_2\n.\n.\n.\nu_{N - 1} v_{N - 1} w_{N - 1}\n\nOutput\n\nPrint a coloring of the vertices that satisfies the condition, in N lines.\nThe i-th line should contain 0 if Vertex i is painted white and 1 if it is painted black.\n\nIf there are multiple colorings that satisfy the condition, any of them will be accepted.\n\nSample Input 1\n\n3\n1 2 2\n2 3 1\n\nSample Output 1\n\n0\n0\n1\n\nSample Input 2\n\n5\n2 5 2\n2 3 10\n1 3 8\n3 4 2\n\nSample Output 2\n\n1\n0\n1\n0\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2700, "cpu_time_ms": 2107, "memory_kb": 163524}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s000709320", "group_id": "codeNet:p03044", "input_text": "(defconstant +color-unknown+ -1)\n(defconstant +color-white+ 0)\n(defconstant +color-black+ 1)\n\n(defmacro next-int ()\n '(read))\n\n(defun solve ()\n (let* ((n (next-int)) ; 頂点の数\n ;; 根を除いて各頂点にはたった1つの親頂点があるので、辺の数は\n ;; 「頂点の数-1」になる。\n (from (make-array (1- n))) ; 番号が小さいほうの頂点\n (to (make-array (1- n))) ; 番号が大きいほうの頂点\n (w (make-array (1- n)))) ; 辺の長さ\n (loop for i below (1- n)\n do\n ;; 0ベース配列の添字にしたいので、各頂点番号をデクリメントしておく。\n (setf (aref from i) (1- (next-int)))\n (setf (aref to i) (1- (next-int)))\n (setf (aref w i) (next-int)))\n\n (let ((g (pack-wu n from to w))\n (color (make-array n :initial-element +color-unknown+))) ; 頂点の色。\n\n (dfs 0 color g +color-white+)\n\n (format t \"~{~A~^~%~}~%\" (coerce color 'list)))))\n\n(defun dfs (now ; 現在訪問している頂点\n color ; 色を出力する配列\n g ; 辺の接続先と長さの情報\n mod) ; 現在の頂点の色(0 か 1)\n (setf (aref color now) mod)\n (loop for edge across (aref g now)\n do\n (destructuring-bind\n (next-vertex length) edge\n (when (= (aref color next-vertex) +color-unknown+)\n (dfs next-vertex color g (mod (+ mod length) 2))))))\n\n;; 各頂点についてその接続情報を収めた表 g を生成して返す。\n;; g[頂点番号][各辺][+edge-other-vertex+] = 辺の長さ\n;; g[頂点番号][各辺][+edge-length+] = 接続先の頂点\n(defun pack-wu (n from to w)\n (let ((sup (length from)) ; 辺の数\n (g (make-array n))\n (p (make-array n :initial-element 0))) ; 各頂点の次数(接続している辺の数)\n\n ;; 各頂点の次数を数える。各辺は、2つの頂点の次数をそれぞれ1つずつ\n ;; 増やす。\n (loop for i below sup\n do\n (incf (aref p (aref from i)))\n (incf (aref p (aref to i))))\n\n (loop for i below n\n do\n ;; g[i] に頂点 i 接続している辺の情報を収める配列を割り当てる。\n (setf (aref g i) (make-array (aref p i))))\n\n ;; 各頂点の持つ辺の情報を配列の後ろから格納する。\n (loop for i below sup\n do\n (let ((v (aref from i))\n (u (aref to i))\n (len (aref w i)))\n\n (decf (aref p v))\n (setf (aref (aref g v) (aref p v)) (list u len))\n\n (decf (aref p u))\n (setf (aref (aref g u) (aref p u)) (list v len))))\n\n g))\n\n(solve)", "language": "Lisp", "metadata": {"date": 1558522871, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03044.html", "problem_id": "p03044", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03044/input.txt", "sample_output_relpath": "derived/input_output/data/p03044/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03044/Lisp/s000709320.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s000709320", "user_id": "u321226359"}, "prompt_components": {"gold_output": "0\n0\n1\n", "input_to_evaluate": "(defconstant +color-unknown+ -1)\n(defconstant +color-white+ 0)\n(defconstant +color-black+ 1)\n\n(defmacro next-int ()\n '(read))\n\n(defun solve ()\n (let* ((n (next-int)) ; 頂点の数\n ;; 根を除いて各頂点にはたった1つの親頂点があるので、辺の数は\n ;; 「頂点の数-1」になる。\n (from (make-array (1- n))) ; 番号が小さいほうの頂点\n (to (make-array (1- n))) ; 番号が大きいほうの頂点\n (w (make-array (1- n)))) ; 辺の長さ\n (loop for i below (1- n)\n do\n ;; 0ベース配列の添字にしたいので、各頂点番号をデクリメントしておく。\n (setf (aref from i) (1- (next-int)))\n (setf (aref to i) (1- (next-int)))\n (setf (aref w i) (next-int)))\n\n (let ((g (pack-wu n from to w))\n (color (make-array n :initial-element +color-unknown+))) ; 頂点の色。\n\n (dfs 0 color g +color-white+)\n\n (format t \"~{~A~^~%~}~%\" (coerce color 'list)))))\n\n(defun dfs (now ; 現在訪問している頂点\n color ; 色を出力する配列\n g ; 辺の接続先と長さの情報\n mod) ; 現在の頂点の色(0 か 1)\n (setf (aref color now) mod)\n (loop for edge across (aref g now)\n do\n (destructuring-bind\n (next-vertex length) edge\n (when (= (aref color next-vertex) +color-unknown+)\n (dfs next-vertex color g (mod (+ mod length) 2))))))\n\n;; 各頂点についてその接続情報を収めた表 g を生成して返す。\n;; g[頂点番号][各辺][+edge-other-vertex+] = 辺の長さ\n;; g[頂点番号][各辺][+edge-length+] = 接続先の頂点\n(defun pack-wu (n from to w)\n (let ((sup (length from)) ; 辺の数\n (g (make-array n))\n (p (make-array n :initial-element 0))) ; 各頂点の次数(接続している辺の数)\n\n ;; 各頂点の次数を数える。各辺は、2つの頂点の次数をそれぞれ1つずつ\n ;; 増やす。\n (loop for i below sup\n do\n (incf (aref p (aref from i)))\n (incf (aref p (aref to i))))\n\n (loop for i below n\n do\n ;; g[i] に頂点 i 接続している辺の情報を収める配列を割り当てる。\n (setf (aref g i) (make-array (aref p i))))\n\n ;; 各頂点の持つ辺の情報を配列の後ろから格納する。\n (loop for i below sup\n do\n (let ((v (aref from i))\n (u (aref to i))\n (len (aref w i)))\n\n (decf (aref p v))\n (setf (aref (aref g v) (aref p v)) (list u len))\n\n (decf (aref p u))\n (setf (aref (aref g u) (aref p u)) (list v len))))\n\n g))\n\n(solve)", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have a tree with N vertices numbered 1 to N.\nThe i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i.\nYour objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:\n\nFor any two vertices painted in the same color, the distance between them is an even number.\n\nFind a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq u_i < v_i \\leq N\n\n1 \\leq w_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nu_1 v_1 w_1\nu_2 v_2 w_2\n.\n.\n.\nu_{N - 1} v_{N - 1} w_{N - 1}\n\nOutput\n\nPrint a coloring of the vertices that satisfies the condition, in N lines.\nThe i-th line should contain 0 if Vertex i is painted white and 1 if it is painted black.\n\nIf there are multiple colorings that satisfy the condition, any of them will be accepted.\n\nSample Input 1\n\n3\n1 2 2\n2 3 1\n\nSample Output 1\n\n0\n0\n1\n\nSample Input 2\n\n5\n2 5 2\n2 3 10\n1 3 8\n3 4 2\n\nSample Output 2\n\n1\n0\n1\n0\n1", "sample_input": "3\n1 2 2\n2 3 1\n"}, "reference_outputs": ["0\n0\n1\n"], "source_document_id": "p03044", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have a tree with N vertices numbered 1 to N.\nThe i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i.\nYour objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:\n\nFor any two vertices painted in the same color, the distance between them is an even number.\n\nFind a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq u_i < v_i \\leq N\n\n1 \\leq w_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nu_1 v_1 w_1\nu_2 v_2 w_2\n.\n.\n.\nu_{N - 1} v_{N - 1} w_{N - 1}\n\nOutput\n\nPrint a coloring of the vertices that satisfies the condition, in N lines.\nThe i-th line should contain 0 if Vertex i is painted white and 1 if it is painted black.\n\nIf there are multiple colorings that satisfy the condition, any of them will be accepted.\n\nSample Input 1\n\n3\n1 2 2\n2 3 1\n\nSample Output 1\n\n0\n0\n1\n\nSample Input 2\n\n5\n2 5 2\n2 3 10\n1 3 8\n3 4 2\n\nSample Output 2\n\n1\n0\n1\n0\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2761, "cpu_time_ms": 2107, "memory_kb": 161536}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s988831668", "group_id": "codeNet:p03045", "input_text": "(defun root (l)\n (if (null (cdr l)) l (setf (cdr l)(root (cdr l)))))\n\n(loop with ht = (make-hash-table) and N = (read) repeat (read)\n initially (loop for i from 1 to N \n do (setf (gethash i ht) (list i)))\n \n do (setf l1 (root (gethash (read) ht))\n l2 (root (gethash (read) ht)))\n (read)\n if (not (eq l1 l2)) do (rplacd (root l1) (root l2))\n \n ;do (loop for v being each hash-value of ht\n ; do (princ v) (terpri))\n ;(terpri)\n \n finally (princ (loop for v being each hash-value of ht\n count (null (cdr v)))))", "language": "Lisp", "metadata": {"date": 1600800038, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03045.html", "problem_id": "p03045", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03045/input.txt", "sample_output_relpath": "derived/input_output/data/p03045/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03045/Lisp/s988831668.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s988831668", "user_id": "u334552723"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun root (l)\n (if (null (cdr l)) l (setf (cdr l)(root (cdr l)))))\n\n(loop with ht = (make-hash-table) and N = (read) repeat (read)\n initially (loop for i from 1 to N \n do (setf (gethash i ht) (list i)))\n \n do (setf l1 (root (gethash (read) ht))\n l2 (root (gethash (read) ht)))\n (read)\n if (not (eq l1 l2)) do (rplacd (root l1) (root l2))\n \n ;do (loop for v being each hash-value of ht\n ; do (princ v) (terpri))\n ;(terpri)\n \n finally (princ (loop for v being each hash-value of ht\n count (null (cdr v)))))", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere are N cards placed face down in a row. On each card, an integer 1 or 2 is written.\n\nLet A_i be the integer written on the i-th card.\n\nYour objective is to guess A_1, A_2, ..., A_N correctly.\n\nYou know the following facts:\n\nFor each i = 1, 2, ..., M, the value A_{X_i} + A_{Y_i} + Z_i is an even number.\n\nYou are a magician and can use the following magic any number of times:\n\nMagic: Choose one card and know the integer A_i written on it. The cost of using this magic is 1.\n\nWhat is the minimum cost required to determine all of A_1, A_2, ..., A_N?\n\nIt is guaranteed that there is no contradiction in given input.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq X_i < Y_i \\leq N\n\n1 \\leq Z_i \\leq 100\n\nThe pairs (X_i, Y_i) are distinct.\n\nThere is no contradiction in input. (That is, there exist integers A_1, A_2, ..., A_N that satisfy the conditions.)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nX_1 Y_1 Z_1\nX_2 Y_2 Z_2\n\\vdots\nX_M Y_M Z_M\n\nOutput\n\nPrint the minimum total cost required to determine all of A_1, A_2, ..., A_N.\n\nSample Input 1\n\n3 1\n1 2 1\n\nSample Output 1\n\n2\n\nYou can determine all of A_1, A_2, A_3 by using the magic for the first and third cards.\n\nSample Input 2\n\n6 5\n1 2 1\n2 3 2\n1 3 3\n4 5 4\n5 6 5\n\nSample Output 2\n\n2\n\nSample Input 3\n\n100000 1\n1 100000 100\n\nSample Output 3\n\n99999", "sample_input": "3 1\n1 2 1\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03045", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere are N cards placed face down in a row. On each card, an integer 1 or 2 is written.\n\nLet A_i be the integer written on the i-th card.\n\nYour objective is to guess A_1, A_2, ..., A_N correctly.\n\nYou know the following facts:\n\nFor each i = 1, 2, ..., M, the value A_{X_i} + A_{Y_i} + Z_i is an even number.\n\nYou are a magician and can use the following magic any number of times:\n\nMagic: Choose one card and know the integer A_i written on it. The cost of using this magic is 1.\n\nWhat is the minimum cost required to determine all of A_1, A_2, ..., A_N?\n\nIt is guaranteed that there is no contradiction in given input.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq X_i < Y_i \\leq N\n\n1 \\leq Z_i \\leq 100\n\nThe pairs (X_i, Y_i) are distinct.\n\nThere is no contradiction in input. (That is, there exist integers A_1, A_2, ..., A_N that satisfy the conditions.)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nX_1 Y_1 Z_1\nX_2 Y_2 Z_2\n\\vdots\nX_M Y_M Z_M\n\nOutput\n\nPrint the minimum total cost required to determine all of A_1, A_2, ..., A_N.\n\nSample Input 1\n\n3 1\n1 2 1\n\nSample Output 1\n\n2\n\nYou can determine all of A_1, A_2, A_3 by using the magic for the first and third cards.\n\nSample Input 2\n\n6 5\n1 2 1\n2 3 2\n1 3 3\n4 5 4\n5 6 5\n\nSample Output 2\n\n2\n\nSample Input 3\n\n100000 1\n1 100000 100\n\nSample Output 3\n\n99999", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 631, "cpu_time_ms": 307, "memory_kb": 80940}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s355297192", "group_id": "codeNet:p03048", "input_text": "(defun solve (r g b n)\n (let ((ans 0))\n (loop :for ri :from 0 :to (floor (/ n r))\n :do\n (loop :for gi :from 0 :to (floor (/ (- n (* ri r)) g))\n :do\n (if (zerop (rem (- n (* ri r) (* gi g)) b))\n (setf ans (1+ ans)))))\n ans))\n\n(defun main ()\n (let ((r (read))\n (g (read))\n (b (read))\n (n (read)))\n (format t \"~A~%\" (solve r g b n))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1557627121, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03048.html", "problem_id": "p03048", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03048/input.txt", "sample_output_relpath": "derived/input_output/data/p03048/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03048/Lisp/s355297192.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s355297192", "user_id": "u736675286"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun solve (r g b n)\n (let ((ans 0))\n (loop :for ri :from 0 :to (floor (/ n r))\n :do\n (loop :for gi :from 0 :to (floor (/ (- n (* ri r)) g))\n :do\n (if (zerop (rem (- n (* ri r) (* gi g)) b))\n (setf ans (1+ ans)))))\n ans))\n\n(defun main ()\n (let ((r (read))\n (g (read))\n (b (read))\n (n (read)))\n (format t \"~A~%\" (solve r g b n))))\n\n(main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nSnuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes:\n\nRed boxes, each containing R red balls\n\nGreen boxes, each containing G green balls\n\nBlue boxes, each containing B blue balls\n\nSnuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes.\nHow many triples of non-negative integers (r,g,b) achieve this?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq R,G,B,N \\leq 3000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR G B N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n1 2 3 4\n\nSample Output 1\n\n4\n\nFour triples achieve the objective, as follows:\n\n(4,0,0)\n\n(2,1,0)\n\n(1,0,1)\n\n(0,2,0)\n\nSample Input 2\n\n13 1 4 3000\n\nSample Output 2\n\n87058", "sample_input": "1 2 3 4\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03048", "source_text": "Score : 200 points\n\nProblem Statement\n\nSnuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes:\n\nRed boxes, each containing R red balls\n\nGreen boxes, each containing G green balls\n\nBlue boxes, each containing B blue balls\n\nSnuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes.\nHow many triples of non-negative integers (r,g,b) achieve this?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq R,G,B,N \\leq 3000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR G B N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n1 2 3 4\n\nSample Output 1\n\n4\n\nFour triples achieve the objective, as follows:\n\n(4,0,0)\n\n(2,1,0)\n\n(1,0,1)\n\n(0,2,0)\n\nSample Input 2\n\n13 1 4 3000\n\nSample Output 2\n\n87058", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 457, "cpu_time_ms": 166, "memory_kb": 16360}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s317411098", "group_id": "codeNet:p03048", "input_text": "(defun solve (r g b n)\n (let ((sorted (sort (list r g b) #'<)))\n (setf r (third sorted))\n (setf g (second sorted))\n (setf b (first sorted)))\n (let ((ans 0))\n (loop :for ri :from 0 :to (ceiling (/ n r))\n :do\n (loop :for gi :from 0 :to (ceiling (/ (- n (* ri r)) g))\n :do\n (if (zerop (rem (- n (* ri r) (* gi g)) b))\n (setf ans (1+ ans)))))\n ans))\n\n(defun main ()\n (let ((r (read))\n (g (read))\n (b (read))\n (n (read)))\n (format t \"~A~%\" (solve r g b n))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1557626587, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03048.html", "problem_id": "p03048", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03048/input.txt", "sample_output_relpath": "derived/input_output/data/p03048/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03048/Lisp/s317411098.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s317411098", "user_id": "u736675286"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun solve (r g b n)\n (let ((sorted (sort (list r g b) #'<)))\n (setf r (third sorted))\n (setf g (second sorted))\n (setf b (first sorted)))\n (let ((ans 0))\n (loop :for ri :from 0 :to (ceiling (/ n r))\n :do\n (loop :for gi :from 0 :to (ceiling (/ (- n (* ri r)) g))\n :do\n (if (zerop (rem (- n (* ri r) (* gi g)) b))\n (setf ans (1+ ans)))))\n ans))\n\n(defun main ()\n (let ((r (read))\n (g (read))\n (b (read))\n (n (read)))\n (format t \"~A~%\" (solve r g b n))))\n\n(main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nSnuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes:\n\nRed boxes, each containing R red balls\n\nGreen boxes, each containing G green balls\n\nBlue boxes, each containing B blue balls\n\nSnuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes.\nHow many triples of non-negative integers (r,g,b) achieve this?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq R,G,B,N \\leq 3000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR G B N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n1 2 3 4\n\nSample Output 1\n\n4\n\nFour triples achieve the objective, as follows:\n\n(4,0,0)\n\n(2,1,0)\n\n(1,0,1)\n\n(0,2,0)\n\nSample Input 2\n\n13 1 4 3000\n\nSample Output 2\n\n87058", "sample_input": "1 2 3 4\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03048", "source_text": "Score : 200 points\n\nProblem Statement\n\nSnuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes:\n\nRed boxes, each containing R red balls\n\nGreen boxes, each containing G green balls\n\nBlue boxes, each containing B blue balls\n\nSnuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes.\nHow many triples of non-negative integers (r,g,b) achieve this?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq R,G,B,N \\leq 3000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR G B N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n1 2 3 4\n\nSample Output 1\n\n4\n\nFour triples achieve the objective, as follows:\n\n(4,0,0)\n\n(2,1,0)\n\n(1,0,1)\n\n(0,2,0)\n\nSample Input 2\n\n13 1 4 3000\n\nSample Output 2\n\n87058", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 589, "cpu_time_ms": 165, "memory_kb": 16228}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s591860241", "group_id": "codeNet:p03049", "input_text": "(defparameter *s* #())\n\n(defun last-char (s)\n (aref s (1- (length s))))\n\n(defun count-ab (str)\n (let ((prev-char #\\C))\n (loop :for c :across str\n :count (and (char= prev-char #\\A)\n (char= c #\\B))\n :do (setf prev-char c))))\n\n(defun solve ()\n (let* ((last-a (loop :for s :across *s*\n :count (char= (last-char s) #\\A)))\n (first-b (loop :for s :across *s*\n :count (char= (aref s 0) #\\B)))\n (both (loop :for s :across *s*\n :count (and (char= (last-char s) #\\A) (char= (aref s 0) #\\B))))\n (outer-ab (min last-a first-b (- (max last-a first-b) both)))\n (inner-ab (loop :for s :across *s*\n :sum (count-ab s))))\n (+ outer-ab inner-ab)))\n\n(defun main ()\n (let* ((n (read))\n (s (loop :repeat n :collect (read-line))))\n (setf *s* (make-array (length s) :initial-contents s))\n (format t \"~A~%\" (solve))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1557628745, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03049.html", "problem_id": "p03049", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03049/input.txt", "sample_output_relpath": "derived/input_output/data/p03049/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03049/Lisp/s591860241.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s591860241", "user_id": "u736675286"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defparameter *s* #())\n\n(defun last-char (s)\n (aref s (1- (length s))))\n\n(defun count-ab (str)\n (let ((prev-char #\\C))\n (loop :for c :across str\n :count (and (char= prev-char #\\A)\n (char= c #\\B))\n :do (setf prev-char c))))\n\n(defun solve ()\n (let* ((last-a (loop :for s :across *s*\n :count (char= (last-char s) #\\A)))\n (first-b (loop :for s :across *s*\n :count (char= (aref s 0) #\\B)))\n (both (loop :for s :across *s*\n :count (and (char= (last-char s) #\\A) (char= (aref s 0) #\\B))))\n (outer-ab (min last-a first-b (- (max last-a first-b) both)))\n (inner-ab (loop :for s :across *s*\n :sum (count-ab s))))\n (+ outer-ab inner-ab)))\n\n(defun main ()\n (let* ((n (read))\n (s (loop :repeat n :collect (read-line))))\n (setf *s* (make-array (length s) :initial-contents s))\n (format t \"~A~%\" (solve))))\n\n(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nSnuke has N strings. The i-th string is s_i.\n\nLet us concatenate these strings into one string after arranging them in some order.\nFind the maximum possible number of occurrences of AB in the resulting string.\n\nConstraints\n\n1 \\leq N \\leq 10^{4}\n\n2 \\leq |s_i| \\leq 10\n\ns_i consists of uppercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\ns_1\n\\vdots\ns_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3\nABCA\nXBAZ\nBAD\n\nSample Output 1\n\n2\n\nFor example, if we concatenate ABCA, BAD and XBAZ in this order, the resulting string ABCABADXBAZ has two occurrences of AB.\n\nSample Input 2\n\n9\nBEWPVCRWH\nZZNQYIJX\nBAVREA\nPA\nHJMYITEOX\nBCJHMRMNK\nBP\nQVFABZ\nPRGKSPUNA\n\nSample Output 2\n\n4\n\nSample Input 3\n\n7\nRABYBBE\nJOZ\nBMHQUVA\nBPA\nISU\nMCMABAOBHZ\nSZMEHMA\n\nSample Output 3\n\n4", "sample_input": "3\nABCA\nXBAZ\nBAD\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03049", "source_text": "Score : 400 points\n\nProblem Statement\n\nSnuke has N strings. The i-th string is s_i.\n\nLet us concatenate these strings into one string after arranging them in some order.\nFind the maximum possible number of occurrences of AB in the resulting string.\n\nConstraints\n\n1 \\leq N \\leq 10^{4}\n\n2 \\leq |s_i| \\leq 10\n\ns_i consists of uppercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\ns_1\n\\vdots\ns_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3\nABCA\nXBAZ\nBAD\n\nSample Output 1\n\n2\n\nFor example, if we concatenate ABCA, BAD and XBAZ in this order, the resulting string ABCABADXBAZ has two occurrences of AB.\n\nSample Input 2\n\n9\nBEWPVCRWH\nZZNQYIJX\nBAVREA\nPA\nHJMYITEOX\nBCJHMRMNK\nBP\nQVFABZ\nPRGKSPUNA\n\nSample Output 2\n\n4\n\nSample Input 3\n\n7\nRABYBBE\nJOZ\nBMHQUVA\nBPA\nISU\nMCMABAOBHZ\nSZMEHMA\n\nSample Output 3\n\n4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 992, "cpu_time_ms": 511, "memory_kb": 23652}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s823945923", "group_id": "codeNet:p03055", "input_text": ";; -*- coding: utf-8 -*-\n#-(or child-sbcl swank)\n(quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"32MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t)))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the fixnum (* result 10))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(declaim (inline find-optimal))\n(defun find-optimal (sequence predicate &key (start 0) end)\n \"Returns a index x that satisfies (FUNCALL PREDICATE SEQUENCE[x] SEQUENCE[y])\nfor all the index y and returns SEQUENCE[x] as the second value.\"\n (declare ((or null (integer 0 #.most-positive-fixnum)) end)\n ((integer 0 #.most-positive-fixnum) start)\n (function predicate)\n (sequence sequence))\n (etypecase sequence\n (list (error \"Not implemented yet.\"))\n (vector\n (let ((end (or end (length sequence))))\n (unless (<= start end)\n (error \"Can't find optimal value in null interval [~A, ~A)\" start end))\n (let ((optimal (aref sequence 0))\n (index 0))\n (dotimes (i (length sequence) (values index optimal))\n (unless (funcall predicate optimal (aref sequence i))\n (setq optimal (aref sequence i)\n index i))))))))\n\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (dist0 (make-array n :element-type 'uint32 :initial-element #xffffffff))\n (distv (make-array n :element-type 'uint32 :initial-element #xffffffff)))\n (setf (aref dist0 0) 0)\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (labels ((calc-length (pos prev-pos len dist-table)\n (declare (fixnum pos prev-pos len)\n ((simple-array uint32 (*)) dist-table))\n (setf (aref dist-table pos) len)\n (dolist (neighbor (aref graph pos))\n (declare (uint32 neighbor))\n (unless (= neighbor prev-pos)\n (calc-length neighbor pos (+ 1 len) dist-table)))))\n (calc-length 0 -1 0 dist0)\n (let ((init-v (find-optimal dist0 #'>)))\n (setf (aref distv init-v) 0)\n (calc-length init-v -1 0 distv)\n (let ((diam (reduce #'max distv)))\n (write-line (if (= 1 (mod diam 3)) \"Second\" \"First\")))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1557074521, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03055.html", "problem_id": "p03055", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03055/input.txt", "sample_output_relpath": "derived/input_output/data/p03055/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03055/Lisp/s823945923.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s823945923", "user_id": "u352600849"}, "prompt_components": {"gold_output": "First\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n#-(or child-sbcl swank)\n(quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"32MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t)))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the fixnum (* result 10))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(declaim (inline find-optimal))\n(defun find-optimal (sequence predicate &key (start 0) end)\n \"Returns a index x that satisfies (FUNCALL PREDICATE SEQUENCE[x] SEQUENCE[y])\nfor all the index y and returns SEQUENCE[x] as the second value.\"\n (declare ((or null (integer 0 #.most-positive-fixnum)) end)\n ((integer 0 #.most-positive-fixnum) start)\n (function predicate)\n (sequence sequence))\n (etypecase sequence\n (list (error \"Not implemented yet.\"))\n (vector\n (let ((end (or end (length sequence))))\n (unless (<= start end)\n (error \"Can't find optimal value in null interval [~A, ~A)\" start end))\n (let ((optimal (aref sequence 0))\n (index 0))\n (dotimes (i (length sequence) (values index optimal))\n (unless (funcall predicate optimal (aref sequence i))\n (setq optimal (aref sequence i)\n index i))))))))\n\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (dist0 (make-array n :element-type 'uint32 :initial-element #xffffffff))\n (distv (make-array n :element-type 'uint32 :initial-element #xffffffff)))\n (setf (aref dist0 0) 0)\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (labels ((calc-length (pos prev-pos len dist-table)\n (declare (fixnum pos prev-pos len)\n ((simple-array uint32 (*)) dist-table))\n (setf (aref dist-table pos) len)\n (dolist (neighbor (aref graph pos))\n (declare (uint32 neighbor))\n (unless (= neighbor prev-pos)\n (calc-length neighbor pos (+ 1 len) dist-table)))))\n (calc-length 0 -1 0 dist0)\n (let ((init-v (find-optimal dist0 #'>)))\n (setf (aref distv init-v) 0)\n (calc-length init-v -1 0 distv)\n (let ((diam (reduce #'max distv)))\n (write-line (if (= 1 (mod diam 3)) \"Second\" \"First\")))))))\n\n#-swank(main)\n", "problem_context": "Score : 800 points\n\nProblem Statement\n\nTakahashi and Aoki will play a game on a tree.\nThe tree has N vertices numbered 1 to N, and the i-th of the N-1 edges connects Vertex a_i and Vertex b_i.\n\nAt the beginning of the game, each vertex contains a coin.\nStarting from Takahashi, he and Aoki will alternately perform the following operation:\n\nChoose a vertex v that contains one or more coins, and remove all the coins from v.\n\nThen, move each coin remaining on the tree to the vertex that is nearest to v among the adjacent vertices of the coin's current vertex.\n\nThe player who becomes unable to play, loses the game.\nThat is, the player who takes his turn when there is no coin remaining on the tree, loses the game.\nDetermine the winner of the game when both players play optimally.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq a_i, b_i \\leq N\n\na_i \\neq b_i\n\nThe graph given as input is a tree.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 b_1\na_2 b_2\n:\na_{N-1} b_{N-1}\n\nOutput\n\nPrint First if Takahashi will win, and print Second if Aoki will win.\n\nSample Input 1\n\n3\n1 2\n2 3\n\nSample Output 1\n\nFirst\n\nHere is one possible progress of the game:\n\nTakahashi removes the coin from Vertex 1. Now, Vertex 1 and Vertex 2 contain one coin each.\n\nAoki removes the coin from Vertex 2. Now, Vertex 2 contains one coin.\n\nTakahashi removes the coin from Vertex 2. Now, there is no coin remaining on the tree.\n\nAoki takes his turn when there is no coin on the tree and loses.\n\nSample Input 2\n\n6\n1 2\n2 3\n2 4\n4 6\n5 6\n\nSample Output 2\n\nSecond\n\nSample Input 3\n\n7\n1 7\n7 4\n3 4\n7 5\n6 3\n2 1\n\nSample Output 3\n\nFirst", "sample_input": "3\n1 2\n2 3\n"}, "reference_outputs": ["First\n"], "source_document_id": "p03055", "source_text": "Score : 800 points\n\nProblem Statement\n\nTakahashi and Aoki will play a game on a tree.\nThe tree has N vertices numbered 1 to N, and the i-th of the N-1 edges connects Vertex a_i and Vertex b_i.\n\nAt the beginning of the game, each vertex contains a coin.\nStarting from Takahashi, he and Aoki will alternately perform the following operation:\n\nChoose a vertex v that contains one or more coins, and remove all the coins from v.\n\nThen, move each coin remaining on the tree to the vertex that is nearest to v among the adjacent vertices of the coin's current vertex.\n\nThe player who becomes unable to play, loses the game.\nThat is, the player who takes his turn when there is no coin remaining on the tree, loses the game.\nDetermine the winner of the game when both players play optimally.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq a_i, b_i \\leq N\n\na_i \\neq b_i\n\nThe graph given as input is a tree.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 b_1\na_2 b_2\n:\na_{N-1} b_{N-1}\n\nOutput\n\nPrint First if Takahashi will win, and print Second if Aoki will win.\n\nSample Input 1\n\n3\n1 2\n2 3\n\nSample Output 1\n\nFirst\n\nHere is one possible progress of the game:\n\nTakahashi removes the coin from Vertex 1. Now, Vertex 1 and Vertex 2 contain one coin each.\n\nAoki removes the coin from Vertex 2. Now, Vertex 2 contains one coin.\n\nTakahashi removes the coin from Vertex 2. Now, there is no coin remaining on the tree.\n\nAoki takes his turn when there is no coin on the tree and loses.\n\nSample Input 2\n\n6\n1 2\n2 3\n2 4\n4 6\n5 6\n\nSample Output 2\n\nSecond\n\nSample Input 3\n\n7\n1 7\n7 4\n3 4\n7 5\n6 3\n2 1\n\nSample Output 3\n\nFirst", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4839, "cpu_time_ms": 234, "memory_kb": 44084}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s427295213", "group_id": "codeNet:p03056", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline get-2dcumul))\n(defun get-2dcumul (cumul-table i0 j0 i1 j1)\n \"Returns the cumulative sum of the region given by the rectangle [i0, i1)*[j0,\nj1). CUMUL-TABLE must be appropriately initialized beforehand:\ni.e. CUMUL-TABLE[i][j] = sum of the region given by the regtangle [0, i)*[0,\nj).\"\n (+ (- (aref cumul-table i1 j1)\n (aref cumul-table i0 j1)\n (aref cumul-table i1 j0))\n (aref cumul-table i0 j0)))\n\n;;;\n;;; Memoization macro\n;;;\n\n;;\n;; Basic usage:\n;;\n;; (with-cache (:hash-table :test #'equal :key #'cons)\n;; (defun add (a b)\n;; (+ a b)))\n;; This function caches the returned values for already passed combinations of\n;; arguments. In this case ADD stores the key (CONS A B) and the return value to\n;; a hash-table when evaluating (ADD A B) for the first time. ADD returns the\n;; stored value when it is called with the same arguments (w.r.t. EQUAL) again.\n;;\n;; The storage for the cache is hash-table or array. Let's see an example for\n;; array:\n;; (with-cache (:array (10 20 30) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c) ... ))\n;; This form stores the value of FOO in the array created by (make-array (list\n;; 10 20 30) :initial-element -1 :element-type 'fixnum). Note that\n;; INITIAL-ELEMENT must always be given here as it is used as the flag for `not\n;; yet stored'. (Therefore INITIAL-ELEMENT should be a value FOO never takes.)\n;;\n;; If you want to ignore some arguments, you can put `*' in dimensions:\n;; (with-cache (:array (10 10 * 10) :initial-element -1)\n;; (defun foo (a b c d) ...)) ; then C is ignored when querying or storing cache\n;;\n;; Available definition forms in WITH-CACHE are DEFUN, LABELS, FLET, and\n;; SB-INT:NAMED-LET.\n;;\n;; You can trace the memoized function by :TRACE option:\n;; (with-cache (:array (10 10) :initial-element -1 :trace t)\n;; (defun foo (x y) ...))\n;; Then FOO is traced as with CL:TRACE.\n;;\n\n;; FIXME: *RECURSION-DEPTH* should be included within the macro.\n(declaim (type (integer 0 #.most-positive-fixnum) *recursion-depth*))\n(defparameter *recursion-depth* 0)\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun %enclose-with-tracing (fname args form)\n (let ((value (gensym)))\n `(progn\n (format t \"~&~A~A: (~A ~{~A~^ ~}) =>\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args))\n (let ((,value (let ((*recursion-depth* (1+ *recursion-depth*)))\n ,form)))\n (format t \"~&~A~A: (~A ~{~A~^ ~}) => ~A\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args)\n ,value)\n ,value))))\n\n (defun %extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car (if (listp form) form (list form)))))\n body))\n\n (defun %parse-cache-form (cache-specifier)\n (let ((cache-type (car cache-specifier))\n (cache-attribs (cdr cache-specifier)))\n (assert (member cache-type '(:hash-table :array)))\n (let* ((dims-with-* (when (eql cache-type :array) (first cache-attribs)))\n (dims (remove '* dims-with-*))\n (rank (length dims))\n (rest-attribs (ecase cache-type\n (:hash-table cache-attribs)\n (:array (cdr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (trace-p (prog1 (getf rest-attribs :trace) (remf rest-attribs :trace)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array (list ,@dims) ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym \"CACHE\"))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels\n ((make-cache-querier (cache-type name args)\n (let ((res (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dims-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value))))))))\n (if trace-p\n (%enclose-with-tracing name args res)\n res)))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name)))))\n (values cache cache-form cache-type name-alias\n #'make-reset-name\n #'make-reset-form\n #'make-cache-querier)))))))\n\n(defmacro with-caches (cache-specs def-form)\n \"DEF-FORM := definition form with LABELS or FLET.\n\n (with-caches (cache-spec1 cache-spec2)\n (labels ((f (x) ...) (g (y) ...))))\nis equivalent to the line up of\n (with-cache cache-spec1 (labels ((f (x) ...))))\nand\n (with-cache cache-spec2 (labels ((g (y) ...)))) \"\n (assert (member (car def-form) '(labels flet)))\n (let (cache-symbol-list cache-form-list cache-type-list name-alias-list make-reset-name-list make-reset-form-list make-cache-querier-list)\n (dolist (cache-spec (reverse cache-specs))\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form make-cache-querier)\n (%parse-cache-form cache-spec)\n (push cache-symbol cache-symbol-list)\n (push cache-form cache-form-list)\n (push cache-type cache-type-list)\n (push name-alias name-alias-list)\n (push make-reset-name make-reset-name-list)\n (push make-reset-form make-reset-form-list)\n (push make-cache-querier make-cache-querier-list)))\n (labels ((def-name (def) (first def))\n (def-args (def) (second def))\n (def-body (def) (cddr def)))\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n `(let ,(loop for cache-symbol in cache-symbol-list\n for cache-form in cache-form-list\n collect `(,cache-symbol ,cache-form))\n (,(car def-form)\n (,@(loop for def in definitions\n for cache-type in cache-type-list\n for make-reset-name in make-reset-name-list\n for make-reset-form in make-reset-form-list\n collect `(,(funcall make-reset-name (def-name def)) ()\n ,(funcall make-reset-form cache-type)))\n ,@(loop for def in definitions\n for cache-type in cache-type-list\n for name-alias in name-alias-list\n for make-cache-querier in make-cache-querier-list\n collect `(,(def-name def) ,(def-args def)\n ,@(%extract-declarations (def-body def))\n (labels ((,name-alias ,(def-args def) ,@(def-body def)))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type (def-name def) (def-args def))))))\n (declare (ignorable ,@(loop for def in definitions\n for make-reset-name in make-reset-name-list\n collect `#',(funcall make-reset-name\n (def-name def)))))\n ,@labels-body))))))\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (term-char #\\Space))\n \"Reads ASCII inputs and returns two values: the string and the end\nposition. Note that the returned string will be reused if this form is executed\nmore than once.\n\nThis macro calls READ-BYTE to read characters though it calls READ-CHAR instead\non SLIME because SLIME's IO is not bivalent.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let* ((,buffer (load-time-value (make-string ,buffer-size :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n ,(if (member :swank *features*)\n `(read-char ,in nil #\\Newline) ; on SLIME\n `(code-char (read-byte ,in nil #.(char-code #\\Newline))))\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,term-char))\n (return (values ,buffer ,idx))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((h (read))\n (w (read))\n (cumuls (make-array (list (+ h 1) (+ w 1)) :element-type 'uint32 :initial-element 0)))\n (declare (uint8 h w))\n (dotimes (i h)\n (let ((line (buffered-read-line 185)))\n (dotimes (j w)\n (when (char= #\\# (aref line j))\n (setf (aref cumuls (+ i 1) (+ j 1)) 1)))))\n (dotimes (i (+ h 1))\n (dotimes (j w)\n (incf (aref cumuls i (+ j 1)) (aref cumuls i j))))\n (dotimes (j (+ w 1))\n (dotimes (i h)\n (incf (aref cumuls (+ i 1) j) (aref cumuls i j))))\n (with-caches ((:array ((+ h 1) (+ w 1) (+ h 1) 20)\n :element-type 'uint8\n :initial-element #xff)\n (:array ((+ h 1) (+ w 1) (+ w 1) 20)\n :element-type 'uint8\n :initial-element #xff))\n (labels\n ((f (y1 x1 y2 c)\n (declare (uint8 y1 x1 y2 c))\n (if (zerop c)\n (sb-int:named-let bisect ((ok x1) (ng (+ w 1)))\n (declare (uint8 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (floor (+ ok ng) 2))\n (sum (get-2dcumul cumuls y1 x1 y2 mid)))\n (if (or (= sum (* (- y2 y1) (- mid x1)))\n (= sum 0))\n (bisect mid ng)\n (bisect ok mid)))))\n (let ((res1 (f y1 (f y1 x1 y2 (- c 1)) y2 (- c 1)))\n (res2 (sb-int:named-let bisect ((ok x1) (ng (+ w 1)))\n (declare (uint8 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (floor (+ ok ng) 2))\n (val (g (g y1 x1 mid (- c 1)) x1 mid (- c 1))))\n (if (>= val y2)\n (bisect mid ng)\n (bisect ok mid)))))))\n (max res1 res2))))\n (g (y1 x1 x2 c)\n (declare (uint8 y1 x1 x2 c))\n (if (zerop c)\n (sb-int:named-let bisect ((ok y1) (ng (+ h 1)))\n (declare (uint8 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (floor (+ ok ng) 2))\n (sum (get-2dcumul cumuls y1 x1 mid x2)))\n (if (or (= sum (* (- mid y1) (- x2 x1)))\n (= sum 0))\n (bisect mid ng)\n (bisect ok mid)))))\n (let ((res1 (g (g y1 x1 x2 (- c 1)) x1 x2 (- c 1)))\n (res2 (sb-int:named-let bisect ((ok y1) (ng (+ h 1)))\n (declare (uint8 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (floor (+ ok ng) 2))\n (val (f y1 (f y1 x1 mid (- c 1)) mid (- c 1))))\n (if (>= val x2)\n (bisect mid ng)\n (bisect ok mid)))))))\n (max res1 res2)))))\n (dotimes (c 20)\n (let ((x (f 0 0 h c)))\n (when (= x w)\n (println c)\n (return-from main))))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1566530929, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03056.html", "problem_id": "p03056", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03056/input.txt", "sample_output_relpath": "derived/input_output/data/p03056/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03056/Lisp/s427295213.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s427295213", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline get-2dcumul))\n(defun get-2dcumul (cumul-table i0 j0 i1 j1)\n \"Returns the cumulative sum of the region given by the rectangle [i0, i1)*[j0,\nj1). CUMUL-TABLE must be appropriately initialized beforehand:\ni.e. CUMUL-TABLE[i][j] = sum of the region given by the regtangle [0, i)*[0,\nj).\"\n (+ (- (aref cumul-table i1 j1)\n (aref cumul-table i0 j1)\n (aref cumul-table i1 j0))\n (aref cumul-table i0 j0)))\n\n;;;\n;;; Memoization macro\n;;;\n\n;;\n;; Basic usage:\n;;\n;; (with-cache (:hash-table :test #'equal :key #'cons)\n;; (defun add (a b)\n;; (+ a b)))\n;; This function caches the returned values for already passed combinations of\n;; arguments. In this case ADD stores the key (CONS A B) and the return value to\n;; a hash-table when evaluating (ADD A B) for the first time. ADD returns the\n;; stored value when it is called with the same arguments (w.r.t. EQUAL) again.\n;;\n;; The storage for the cache is hash-table or array. Let's see an example for\n;; array:\n;; (with-cache (:array (10 20 30) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c) ... ))\n;; This form stores the value of FOO in the array created by (make-array (list\n;; 10 20 30) :initial-element -1 :element-type 'fixnum). Note that\n;; INITIAL-ELEMENT must always be given here as it is used as the flag for `not\n;; yet stored'. (Therefore INITIAL-ELEMENT should be a value FOO never takes.)\n;;\n;; If you want to ignore some arguments, you can put `*' in dimensions:\n;; (with-cache (:array (10 10 * 10) :initial-element -1)\n;; (defun foo (a b c d) ...)) ; then C is ignored when querying or storing cache\n;;\n;; Available definition forms in WITH-CACHE are DEFUN, LABELS, FLET, and\n;; SB-INT:NAMED-LET.\n;;\n;; You can trace the memoized function by :TRACE option:\n;; (with-cache (:array (10 10) :initial-element -1 :trace t)\n;; (defun foo (x y) ...))\n;; Then FOO is traced as with CL:TRACE.\n;;\n\n;; FIXME: *RECURSION-DEPTH* should be included within the macro.\n(declaim (type (integer 0 #.most-positive-fixnum) *recursion-depth*))\n(defparameter *recursion-depth* 0)\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun %enclose-with-tracing (fname args form)\n (let ((value (gensym)))\n `(progn\n (format t \"~&~A~A: (~A ~{~A~^ ~}) =>\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args))\n (let ((,value (let ((*recursion-depth* (1+ *recursion-depth*)))\n ,form)))\n (format t \"~&~A~A: (~A ~{~A~^ ~}) => ~A\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args)\n ,value)\n ,value))))\n\n (defun %extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car (if (listp form) form (list form)))))\n body))\n\n (defun %parse-cache-form (cache-specifier)\n (let ((cache-type (car cache-specifier))\n (cache-attribs (cdr cache-specifier)))\n (assert (member cache-type '(:hash-table :array)))\n (let* ((dims-with-* (when (eql cache-type :array) (first cache-attribs)))\n (dims (remove '* dims-with-*))\n (rank (length dims))\n (rest-attribs (ecase cache-type\n (:hash-table cache-attribs)\n (:array (cdr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (trace-p (prog1 (getf rest-attribs :trace) (remf rest-attribs :trace)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array (list ,@dims) ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym \"CACHE\"))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels\n ((make-cache-querier (cache-type name args)\n (let ((res (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dims-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value))))))))\n (if trace-p\n (%enclose-with-tracing name args res)\n res)))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name)))))\n (values cache cache-form cache-type name-alias\n #'make-reset-name\n #'make-reset-form\n #'make-cache-querier)))))))\n\n(defmacro with-caches (cache-specs def-form)\n \"DEF-FORM := definition form with LABELS or FLET.\n\n (with-caches (cache-spec1 cache-spec2)\n (labels ((f (x) ...) (g (y) ...))))\nis equivalent to the line up of\n (with-cache cache-spec1 (labels ((f (x) ...))))\nand\n (with-cache cache-spec2 (labels ((g (y) ...)))) \"\n (assert (member (car def-form) '(labels flet)))\n (let (cache-symbol-list cache-form-list cache-type-list name-alias-list make-reset-name-list make-reset-form-list make-cache-querier-list)\n (dolist (cache-spec (reverse cache-specs))\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form make-cache-querier)\n (%parse-cache-form cache-spec)\n (push cache-symbol cache-symbol-list)\n (push cache-form cache-form-list)\n (push cache-type cache-type-list)\n (push name-alias name-alias-list)\n (push make-reset-name make-reset-name-list)\n (push make-reset-form make-reset-form-list)\n (push make-cache-querier make-cache-querier-list)))\n (labels ((def-name (def) (first def))\n (def-args (def) (second def))\n (def-body (def) (cddr def)))\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n `(let ,(loop for cache-symbol in cache-symbol-list\n for cache-form in cache-form-list\n collect `(,cache-symbol ,cache-form))\n (,(car def-form)\n (,@(loop for def in definitions\n for cache-type in cache-type-list\n for make-reset-name in make-reset-name-list\n for make-reset-form in make-reset-form-list\n collect `(,(funcall make-reset-name (def-name def)) ()\n ,(funcall make-reset-form cache-type)))\n ,@(loop for def in definitions\n for cache-type in cache-type-list\n for name-alias in name-alias-list\n for make-cache-querier in make-cache-querier-list\n collect `(,(def-name def) ,(def-args def)\n ,@(%extract-declarations (def-body def))\n (labels ((,name-alias ,(def-args def) ,@(def-body def)))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type (def-name def) (def-args def))))))\n (declare (ignorable ,@(loop for def in definitions\n for make-reset-name in make-reset-name-list\n collect `#',(funcall make-reset-name\n (def-name def)))))\n ,@labels-body))))))\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (term-char #\\Space))\n \"Reads ASCII inputs and returns two values: the string and the end\nposition. Note that the returned string will be reused if this form is executed\nmore than once.\n\nThis macro calls READ-BYTE to read characters though it calls READ-CHAR instead\non SLIME because SLIME's IO is not bivalent.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let* ((,buffer (load-time-value (make-string ,buffer-size :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n ,(if (member :swank *features*)\n `(read-char ,in nil #\\Newline) ; on SLIME\n `(code-char (read-byte ,in nil #.(char-code #\\Newline))))\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,term-char))\n (return (values ,buffer ,idx))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((h (read))\n (w (read))\n (cumuls (make-array (list (+ h 1) (+ w 1)) :element-type 'uint32 :initial-element 0)))\n (declare (uint8 h w))\n (dotimes (i h)\n (let ((line (buffered-read-line 185)))\n (dotimes (j w)\n (when (char= #\\# (aref line j))\n (setf (aref cumuls (+ i 1) (+ j 1)) 1)))))\n (dotimes (i (+ h 1))\n (dotimes (j w)\n (incf (aref cumuls i (+ j 1)) (aref cumuls i j))))\n (dotimes (j (+ w 1))\n (dotimes (i h)\n (incf (aref cumuls (+ i 1) j) (aref cumuls i j))))\n (with-caches ((:array ((+ h 1) (+ w 1) (+ h 1) 20)\n :element-type 'uint8\n :initial-element #xff)\n (:array ((+ h 1) (+ w 1) (+ w 1) 20)\n :element-type 'uint8\n :initial-element #xff))\n (labels\n ((f (y1 x1 y2 c)\n (declare (uint8 y1 x1 y2 c))\n (if (zerop c)\n (sb-int:named-let bisect ((ok x1) (ng (+ w 1)))\n (declare (uint8 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (floor (+ ok ng) 2))\n (sum (get-2dcumul cumuls y1 x1 y2 mid)))\n (if (or (= sum (* (- y2 y1) (- mid x1)))\n (= sum 0))\n (bisect mid ng)\n (bisect ok mid)))))\n (let ((res1 (f y1 (f y1 x1 y2 (- c 1)) y2 (- c 1)))\n (res2 (sb-int:named-let bisect ((ok x1) (ng (+ w 1)))\n (declare (uint8 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (floor (+ ok ng) 2))\n (val (g (g y1 x1 mid (- c 1)) x1 mid (- c 1))))\n (if (>= val y2)\n (bisect mid ng)\n (bisect ok mid)))))))\n (max res1 res2))))\n (g (y1 x1 x2 c)\n (declare (uint8 y1 x1 x2 c))\n (if (zerop c)\n (sb-int:named-let bisect ((ok y1) (ng (+ h 1)))\n (declare (uint8 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (floor (+ ok ng) 2))\n (sum (get-2dcumul cumuls y1 x1 mid x2)))\n (if (or (= sum (* (- mid y1) (- x2 x1)))\n (= sum 0))\n (bisect mid ng)\n (bisect ok mid)))))\n (let ((res1 (g (g y1 x1 x2 (- c 1)) x1 x2 (- c 1)))\n (res2 (sb-int:named-let bisect ((ok y1) (ng (+ h 1)))\n (declare (uint8 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (floor (+ ok ng) 2))\n (val (f y1 (f y1 x1 mid (- c 1)) mid (- c 1))))\n (if (>= val x2)\n (bisect mid ng)\n (bisect ok mid)))))))\n (max res1 res2)))))\n (dotimes (c 20)\n (let ((x (f 0 0 h c)))\n (when (= x w)\n (println c)\n (return-from main))))))))\n\n#-swank (main)\n", "problem_context": "Score : 1000 points\n\nProblem Statement\n\nNote the unusual memory limit.\n\nFor a rectangular grid where each square is painted white or black, we define its complexity as follows:\n\nIf all the squares are black or all the squares are white, the complexity is 0.\n\nOtherwise, divide the grid into two subgrids by a line parallel to one of the sides of the grid, and let c_1 and c_2 be the complexities of the subgrids. There can be multiple ways to perform the division, and let m be the minimum value of \\max(c_1, c_2) in those divisions. The complexity of the grid is m+1.\n\nYou are given a grid with H horizontal rows and W vertical columns where each square is painted white or black.\nHW characters from A_{11} to A_{HW} represent the colors of the squares.\nA_{ij} is # if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is . if that square is white.\n\nFind the complexity of the given grid.\n\nConstraints\n\n1 \\leq H,W \\leq 185\n\nA_{ij} is # or ..\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nA_{11}A_{12}...A_{1W}\n:\nA_{H1}A_{H2}...A_{HW}\n\nOutput\n\nPrint the complexity of the given grid.\n\nSample Input 1\n\n3 3\n...\n.##\n.##\n\nSample Output 1\n\n2\n\nLet us divide the grid by the boundary line between the first and second columns.\nThe subgrid consisting of the first column has the complexity of 0, and the subgrid consisting of the second and third columns has the complexity of 1, so the whole grid has the complexity of at most 2.\n\nSample Input 2\n\n6 7\n.####.#\n#....#.\n#....#.\n#....#.\n.####.#\n#....##\n\nSample Output 2\n\n4", "sample_input": "3 3\n...\n.##\n.##\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03056", "source_text": "Score : 1000 points\n\nProblem Statement\n\nNote the unusual memory limit.\n\nFor a rectangular grid where each square is painted white or black, we define its complexity as follows:\n\nIf all the squares are black or all the squares are white, the complexity is 0.\n\nOtherwise, divide the grid into two subgrids by a line parallel to one of the sides of the grid, and let c_1 and c_2 be the complexities of the subgrids. There can be multiple ways to perform the division, and let m be the minimum value of \\max(c_1, c_2) in those divisions. The complexity of the grid is m+1.\n\nYou are given a grid with H horizontal rows and W vertical columns where each square is painted white or black.\nHW characters from A_{11} to A_{HW} represent the colors of the squares.\nA_{ij} is # if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is . if that square is white.\n\nFind the complexity of the given grid.\n\nConstraints\n\n1 \\leq H,W \\leq 185\n\nA_{ij} is # or ..\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nA_{11}A_{12}...A_{1W}\n:\nA_{H1}A_{H2}...A_{HW}\n\nOutput\n\nPrint the complexity of the given grid.\n\nSample Input 1\n\n3 3\n...\n.##\n.##\n\nSample Output 1\n\n2\n\nLet us divide the grid by the boundary line between the first and second columns.\nThe subgrid consisting of the first column has the complexity of 0, and the subgrid consisting of the second and third columns has the complexity of 1, so the whole grid has the complexity of at most 2.\n\nSample Input 2\n\n6 7\n.####.#\n#....#.\n#....#.\n#....#.\n.####.#\n#....##\n\nSample Output 2\n\n4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 15905, "cpu_time_ms": 5257, "memory_kb": 291432}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s076619206", "group_id": "codeNet:p03059", "input_text": "\n(defmacro aif(test then else)\n `(let ((it ,test))\n (if it ,then ,else)))\n\n(defun split (pattern str)\n (aif (search pattern str)\n (cons (subseq str 0 it) (split pattern (subseq str (+ it (length pattern)))))\n (list str)))\n\n(defun main ()\n (let* ((input (split \" \" (read-line)))\n (a (parse-integer (first input)))\n (b (parse-integer (second input)))\n (tt (parse-integer (third input))))\n (print (* (floor tt a) b))))\n(main)", "language": "Lisp", "metadata": {"date": 1558011591, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03059.html", "problem_id": "p03059", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03059/input.txt", "sample_output_relpath": "derived/input_output/data/p03059/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03059/Lisp/s076619206.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s076619206", "user_id": "u526818046"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "\n(defmacro aif(test then else)\n `(let ((it ,test))\n (if it ,then ,else)))\n\n(defun split (pattern str)\n (aif (search pattern str)\n (cons (subseq str 0 it) (split pattern (subseq str (+ it (length pattern)))))\n (list str)))\n\n(defun main ()\n (let* ((input (split \" \" (read-line)))\n (a (parse-integer (first input)))\n (b (parse-integer (second input)))\n (tt (parse-integer (third input))))\n (print (* (floor tt a) b))))\n(main)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nA biscuit making machine produces B biscuits at the following moments: A seconds, 2A seconds, 3A seconds and each subsequent multiple of A seconds after activation.\n\nFind the total number of biscuits produced within T + 0.5 seconds after activation.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A, B, T \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B T\n\nOutput\n\nPrint the total number of biscuits produced within T + 0.5 seconds after activation.\n\nSample Input 1\n\n3 5 7\n\nSample Output 1\n\n10\n\nFive biscuits will be produced three seconds after activation.\n\nAnother five biscuits will be produced six seconds after activation.\n\nThus, a total of ten biscuits will be produced within 7.5 seconds after activation.\n\nSample Input 2\n\n3 2 9\n\nSample Output 2\n\n6\n\nSample Input 3\n\n20 20 19\n\nSample Output 3\n\n0", "sample_input": "3 5 7\n"}, "reference_outputs": ["10\n"], "source_document_id": "p03059", "source_text": "Score : 100 points\n\nProblem Statement\n\nA biscuit making machine produces B biscuits at the following moments: A seconds, 2A seconds, 3A seconds and each subsequent multiple of A seconds after activation.\n\nFind the total number of biscuits produced within T + 0.5 seconds after activation.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A, B, T \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B T\n\nOutput\n\nPrint the total number of biscuits produced within T + 0.5 seconds after activation.\n\nSample Input 1\n\n3 5 7\n\nSample Output 1\n\n10\n\nFive biscuits will be produced three seconds after activation.\n\nAnother five biscuits will be produced six seconds after activation.\n\nThus, a total of ten biscuits will be produced within 7.5 seconds after activation.\n\nSample Input 2\n\n3 2 9\n\nSample Output 2\n\n6\n\nSample Input 3\n\n20 20 19\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 468, "cpu_time_ms": 145, "memory_kb": 13924}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s608675680", "group_id": "codeNet:p03059", "input_text": "(let ((a (read))\n (b (read))\n (c (read)))\n (princ (* (floor c a) b)))", "language": "Lisp", "metadata": {"date": 1556413350, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03059.html", "problem_id": "p03059", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03059/input.txt", "sample_output_relpath": "derived/input_output/data/p03059/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03059/Lisp/s608675680.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s608675680", "user_id": "u610490393"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (c (read)))\n (princ (* (floor c a) b)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nA biscuit making machine produces B biscuits at the following moments: A seconds, 2A seconds, 3A seconds and each subsequent multiple of A seconds after activation.\n\nFind the total number of biscuits produced within T + 0.5 seconds after activation.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A, B, T \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B T\n\nOutput\n\nPrint the total number of biscuits produced within T + 0.5 seconds after activation.\n\nSample Input 1\n\n3 5 7\n\nSample Output 1\n\n10\n\nFive biscuits will be produced three seconds after activation.\n\nAnother five biscuits will be produced six seconds after activation.\n\nThus, a total of ten biscuits will be produced within 7.5 seconds after activation.\n\nSample Input 2\n\n3 2 9\n\nSample Output 2\n\n6\n\nSample Input 3\n\n20 20 19\n\nSample Output 3\n\n0", "sample_input": "3 5 7\n"}, "reference_outputs": ["10\n"], "source_document_id": "p03059", "source_text": "Score : 100 points\n\nProblem Statement\n\nA biscuit making machine produces B biscuits at the following moments: A seconds, 2A seconds, 3A seconds and each subsequent multiple of A seconds after activation.\n\nFind the total number of biscuits produced within T + 0.5 seconds after activation.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A, B, T \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B T\n\nOutput\n\nPrint the total number of biscuits produced within T + 0.5 seconds after activation.\n\nSample Input 1\n\n3 5 7\n\nSample Output 1\n\n10\n\nFive biscuits will be produced three seconds after activation.\n\nAnother five biscuits will be produced six seconds after activation.\n\nThus, a total of ten biscuits will be produced within 7.5 seconds after activation.\n\nSample Input 2\n\n3 2 9\n\nSample Output 2\n\n6\n\nSample Input 3\n\n20 20 19\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 80, "cpu_time_ms": 205, "memory_kb": 12388}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s284214797", "group_id": "codeNet:p03060", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(setq *n* (read))\n(setq *v* (make-array *n* :initial-contents (mapcar #'parse-integer (split \" \" (read-line)))))\n(setq *c* (make-array *n* :initial-contents (mapcar #'parse-integer (split \" \" (read-line)))))\n\n(setq *gains* nil)\n\n(defun dfs (gain i)\n (let ((next-gain gain) (result nil))\n (if (>= i *n*)\n (setq *gains* (cons gain *gains*))\n (dotimes (n 2 result)\n ;(print (list \"next-gain \" next-gain (aref *v* i) (aref *c* i)))\n (when (= n 1) (setq next-gain (+ gain (- (aref *v* i) (aref *c* i)))))\n (setq result (dfs next-gain (1+ i)))))))\n\n (dfs 0 0)\n (print (apply #'max *gains*))", "language": "Lisp", "metadata": {"date": 1569382786, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03060.html", "problem_id": "p03060", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03060/input.txt", "sample_output_relpath": "derived/input_output/data/p03060/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03060/Lisp/s284214797.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s284214797", "user_id": "u358554431"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(setq *n* (read))\n(setq *v* (make-array *n* :initial-contents (mapcar #'parse-integer (split \" \" (read-line)))))\n(setq *c* (make-array *n* :initial-contents (mapcar #'parse-integer (split \" \" (read-line)))))\n\n(setq *gains* nil)\n\n(defun dfs (gain i)\n (let ((next-gain gain) (result nil))\n (if (>= i *n*)\n (setq *gains* (cons gain *gains*))\n (dotimes (n 2 result)\n ;(print (list \"next-gain \" next-gain (aref *v* i) (aref *c* i)))\n (when (= n 1) (setq next-gain (+ gain (- (aref *v* i) (aref *c* i)))))\n (setq result (dfs next-gain (1+ i)))))))\n\n (dfs 0 0)\n (print (apply #'max *gains*))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N gems. The value of the i-th gem is V_i.\n\nYou will choose some of these gems, possibly all or none, and get them.\n\nHowever, you need to pay a cost of C_i to get the i-th gem.\n\nLet X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.\n\nFind the maximum possible value of X-Y.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 20\n\n1 \\leq C_i, V_i \\leq 50\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nV_1 V_2 ... V_N\nC_1 C_2 ... C_N\n\nOutput\n\nPrint the maximum possible value of X-Y.\n\nSample Input 1\n\n3\n10 2 5\n6 3 4\n\nSample Output 1\n\n5\n\nIf we choose the first and third gems, X = 10 + 5 = 15 and Y = 6 + 4 = 10.\nWe have X-Y = 5 here, which is the maximum possible value.\n\nSample Input 2\n\n4\n13 21 6 19\n11 30 6 15\n\nSample Output 2\n\n6\n\nSample Input 3\n\n1\n1\n50\n\nSample Output 3\n\n0", "sample_input": "3\n10 2 5\n6 3 4\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03060", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N gems. The value of the i-th gem is V_i.\n\nYou will choose some of these gems, possibly all or none, and get them.\n\nHowever, you need to pay a cost of C_i to get the i-th gem.\n\nLet X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.\n\nFind the maximum possible value of X-Y.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 20\n\n1 \\leq C_i, V_i \\leq 50\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nV_1 V_2 ... V_N\nC_1 C_2 ... C_N\n\nOutput\n\nPrint the maximum possible value of X-Y.\n\nSample Input 1\n\n3\n10 2 5\n6 3 4\n\nSample Output 1\n\n5\n\nIf we choose the first and third gems, X = 10 + 5 = 15 and Y = 6 + 4 = 10.\nWe have X-Y = 5 here, which is the maximum possible value.\n\nSample Input 2\n\n4\n13 21 6 19\n11 30 6 15\n\nSample Output 2\n\n6\n\nSample Input 3\n\n1\n1\n50\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1290, "cpu_time_ms": 409, "memory_kb": 33852}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s179050370", "group_id": "codeNet:p03060", "input_text": "(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(setq *n* (read))\n(setq *v* (mapcar #'parse-integer (split \" \" (read-line))))\n(setq *c* (mapcar #'parse-integer (split \" \" (read-line))))\n(setq *f* 0)\n\n(dotimes (bit (ash 1 *n*))\n (let ((tmp 0))\n (dotimes (i *n*)\n (when\n (= 1 (logand 1 (ash bit (* -1 i))))\n (setq tmp (+ tmp (- (nth i *v*) (nth i *c*))))))\n (when (> tmp *f*)\n (setq *f* tmp))))\n\n(print *f*)", "language": "Lisp", "metadata": {"date": 1569374643, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03060.html", "problem_id": "p03060", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03060/input.txt", "sample_output_relpath": "derived/input_output/data/p03060/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03060/Lisp/s179050370.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s179050370", "user_id": "u358554431"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(setq *n* (read))\n(setq *v* (mapcar #'parse-integer (split \" \" (read-line))))\n(setq *c* (mapcar #'parse-integer (split \" \" (read-line))))\n(setq *f* 0)\n\n(dotimes (bit (ash 1 *n*))\n (let ((tmp 0))\n (dotimes (i *n*)\n (when\n (= 1 (logand 1 (ash bit (* -1 i))))\n (setq tmp (+ tmp (- (nth i *v*) (nth i *c*))))))\n (when (> tmp *f*)\n (setq *f* tmp))))\n\n(print *f*)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N gems. The value of the i-th gem is V_i.\n\nYou will choose some of these gems, possibly all or none, and get them.\n\nHowever, you need to pay a cost of C_i to get the i-th gem.\n\nLet X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.\n\nFind the maximum possible value of X-Y.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 20\n\n1 \\leq C_i, V_i \\leq 50\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nV_1 V_2 ... V_N\nC_1 C_2 ... C_N\n\nOutput\n\nPrint the maximum possible value of X-Y.\n\nSample Input 1\n\n3\n10 2 5\n6 3 4\n\nSample Output 1\n\n5\n\nIf we choose the first and third gems, X = 10 + 5 = 15 and Y = 6 + 4 = 10.\nWe have X-Y = 5 here, which is the maximum possible value.\n\nSample Input 2\n\n4\n13 21 6 19\n11 30 6 15\n\nSample Output 2\n\n6\n\nSample Input 3\n\n1\n1\n50\n\nSample Output 3\n\n0", "sample_input": "3\n10 2 5\n6 3 4\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03060", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N gems. The value of the i-th gem is V_i.\n\nYou will choose some of these gems, possibly all or none, and get them.\n\nHowever, you need to pay a cost of C_i to get the i-th gem.\n\nLet X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.\n\nFind the maximum possible value of X-Y.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 20\n\n1 \\leq C_i, V_i \\leq 50\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nV_1 V_2 ... V_N\nC_1 C_2 ... C_N\n\nOutput\n\nPrint the maximum possible value of X-Y.\n\nSample Input 1\n\n3\n10 2 5\n6 3 4\n\nSample Output 1\n\n5\n\nIf we choose the first and third gems, X = 10 + 5 = 15 and Y = 6 + 4 = 10.\nWe have X-Y = 5 here, which is the maximum possible value.\n\nSample Input 2\n\n4\n13 21 6 19\n11 30 6 15\n\nSample Output 2\n\n6\n\nSample Input 3\n\n1\n1\n50\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 660, "cpu_time_ms": 2105, "memory_kb": 59880}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s820803369", "group_id": "codeNet:p03060", "input_text": "(let ((n (read))\n (a (make-array 0 :element-type 'integer\n :adjustable t\n :fill-pointer 0))\n (ans 0)\n temp)\n (dotimes (i n)\n (vector-push-extend (read) a))\n (dotimes (i n)\n (setf temp (read))\n (if (< 0 (- (aref a i) temp)) (incf ans (- (aref a i) temp))))\n (princ ans))", "language": "Lisp", "metadata": {"date": 1566488473, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03060.html", "problem_id": "p03060", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03060/input.txt", "sample_output_relpath": "derived/input_output/data/p03060/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03060/Lisp/s820803369.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s820803369", "user_id": "u994767958"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(let ((n (read))\n (a (make-array 0 :element-type 'integer\n :adjustable t\n :fill-pointer 0))\n (ans 0)\n temp)\n (dotimes (i n)\n (vector-push-extend (read) a))\n (dotimes (i n)\n (setf temp (read))\n (if (< 0 (- (aref a i) temp)) (incf ans (- (aref a i) temp))))\n (princ ans))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N gems. The value of the i-th gem is V_i.\n\nYou will choose some of these gems, possibly all or none, and get them.\n\nHowever, you need to pay a cost of C_i to get the i-th gem.\n\nLet X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.\n\nFind the maximum possible value of X-Y.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 20\n\n1 \\leq C_i, V_i \\leq 50\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nV_1 V_2 ... V_N\nC_1 C_2 ... C_N\n\nOutput\n\nPrint the maximum possible value of X-Y.\n\nSample Input 1\n\n3\n10 2 5\n6 3 4\n\nSample Output 1\n\n5\n\nIf we choose the first and third gems, X = 10 + 5 = 15 and Y = 6 + 4 = 10.\nWe have X-Y = 5 here, which is the maximum possible value.\n\nSample Input 2\n\n4\n13 21 6 19\n11 30 6 15\n\nSample Output 2\n\n6\n\nSample Input 3\n\n1\n1\n50\n\nSample Output 3\n\n0", "sample_input": "3\n10 2 5\n6 3 4\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03060", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N gems. The value of the i-th gem is V_i.\n\nYou will choose some of these gems, possibly all or none, and get them.\n\nHowever, you need to pay a cost of C_i to get the i-th gem.\n\nLet X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.\n\nFind the maximum possible value of X-Y.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 20\n\n1 \\leq C_i, V_i \\leq 50\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nV_1 V_2 ... V_N\nC_1 C_2 ... C_N\n\nOutput\n\nPrint the maximum possible value of X-Y.\n\nSample Input 1\n\n3\n10 2 5\n6 3 4\n\nSample Output 1\n\n5\n\nIf we choose the first and third gems, X = 10 + 5 = 15 and Y = 6 + 4 = 10.\nWe have X-Y = 5 here, which is the maximum possible value.\n\nSample Input 2\n\n4\n13 21 6 19\n11 30 6 15\n\nSample Output 2\n\n6\n\nSample Input 3\n\n1\n1\n50\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 358, "cpu_time_ms": 13, "memory_kb": 3944}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s936078339", "group_id": "codeNet:p03067", "input_text": "(let ((a (read))\n (b (read))\n (c (read)))\n(princ(if (and (< (max a b) c) (> (min a b))) \"Yes\" \"No\")))", "language": "Lisp", "metadata": {"date": 1555815767, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03067.html", "problem_id": "p03067", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03067/input.txt", "sample_output_relpath": "derived/input_output/data/p03067/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03067/Lisp/s936078339.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s936078339", "user_id": "u994767958"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (c (read)))\n(princ(if (and (< (max a b) c) (> (min a b))) \"Yes\" \"No\")))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively.\nPrint Yes if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print No otherwise.\n\nConstraints\n\n0\\leq A,B,C\\leq 100\n\nA, B and C are distinct integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint Yes if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print No otherwise.\n\nSample Input 1\n\n3 8 5\n\nSample Output 1\n\nYes\n\nWe pass the coordinate 5 on the straight way from the house at coordinate 3 to the house at coordinate 8.\n\nSample Input 2\n\n7 3 1\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n10 2 4\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n31 41 59\n\nSample Output 4\n\nNo", "sample_input": "3 8 5\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03067", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively.\nPrint Yes if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print No otherwise.\n\nConstraints\n\n0\\leq A,B,C\\leq 100\n\nA, B and C are distinct integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint Yes if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print No otherwise.\n\nSample Input 1\n\n3 8 5\n\nSample Output 1\n\nYes\n\nWe pass the coordinate 5 on the straight way from the house at coordinate 3 to the house at coordinate 8.\n\nSample Input 2\n\n7 3 1\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n10 2 4\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n31 41 59\n\nSample Output 4\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 109, "cpu_time_ms": 110, "memory_kb": 10212}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s416094473", "group_id": "codeNet:p03068", "input_text": "(let ((n (read))\n (s (read-line))\n (k (read))\n (a \"\"))\n (setq a (char s (- k 1)))\n (loop for char across s do\n (if (char= char a)\n (format t \"~A\" a)\n (format t \"*\")\n )\n )\n (format t \"~%\")\n)", "language": "Lisp", "metadata": {"date": 1601472003, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03068.html", "problem_id": "p03068", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03068/input.txt", "sample_output_relpath": "derived/input_output/data/p03068/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03068/Lisp/s416094473.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s416094473", "user_id": "u136500538"}, "prompt_components": {"gold_output": "*rr*r\n", "input_to_evaluate": "(let ((n (read))\n (s (read-line))\n (k (read))\n (a \"\"))\n (setq a (char s (- k 1)))\n (loop for char across s do\n (if (char= char a)\n (format t \"~A\" a)\n (format t \"*\")\n )\n )\n (format t \"~%\")\n)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given a string S of length N consisting of lowercase English letters, and an integer K.\nPrint the string obtained by replacing every character in S that differs from the K-th character of S, with *.\n\nConstraints\n\n1 \\leq K \\leq N\\leq 10\n\nS is a string of length N consisting of lowercase English letters.\n\nN and K are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\nK\n\nOutput\n\nPrint the string obtained by replacing every character in S that differs from the K-th character of S, with *.\n\nSample Input 1\n\n5\nerror\n2\n\nSample Output 1\n\n*rr*r\n\nThe second character of S is r. When we replace every character in error that differs from r with *, we get the string *rr*r.\n\nSample Input 2\n\n6\neleven\n5\n\nSample Output 2\n\ne*e*e*\n\nSample Input 3\n\n9\neducation\n7\n\nSample Output 3\n\n******i**", "sample_input": "5\nerror\n2\n"}, "reference_outputs": ["*rr*r\n"], "source_document_id": "p03068", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given a string S of length N consisting of lowercase English letters, and an integer K.\nPrint the string obtained by replacing every character in S that differs from the K-th character of S, with *.\n\nConstraints\n\n1 \\leq K \\leq N\\leq 10\n\nS is a string of length N consisting of lowercase English letters.\n\nN and K are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\nK\n\nOutput\n\nPrint the string obtained by replacing every character in S that differs from the K-th character of S, with *.\n\nSample Input 1\n\n5\nerror\n2\n\nSample Output 1\n\n*rr*r\n\nThe second character of S is r. When we replace every character in error that differs from r with *, we get the string *rr*r.\n\nSample Input 2\n\n6\neleven\n5\n\nSample Output 2\n\ne*e*e*\n\nSample Input 3\n\n9\neducation\n7\n\nSample Output 3\n\n******i**", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 246, "cpu_time_ms": 21, "memory_kb": 24356}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s150112398", "group_id": "codeNet:p03069", "input_text": "(defun solve (n s)\n (let ((x (position #\\# s))\n (y (count #\\. s)))\n (if (null x)\n 0\n (- y x))))\n(format t \"~A~%\" (solve (read) (read-line)))", "language": "Lisp", "metadata": {"date": 1573679231, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03069.html", "problem_id": "p03069", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03069/input.txt", "sample_output_relpath": "derived/input_output/data/p03069/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03069/Lisp/s150112398.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s150112398", "user_id": "u672956630"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun solve (n s)\n (let ((x (position #\\# s))\n (y (count #\\. s)))\n (if (null x)\n 0\n (- y x))))\n(format t \"~A~%\" (solve (read) (read-line)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N stones arranged in a row. Every stone is painted white or black.\nA string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is ., and the stone is black if the character is #.\n\nTakahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone.\nFind the minimum number of stones that needs to be recolored.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\nS is a string of length N consisting of . and #.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the minimum number of stones that needs to be recolored.\n\nSample Input 1\n\n3\n#.#\n\nSample Output 1\n\n1\n\nIt is enough to change the color of the first stone to white.\n\nSample Input 2\n\n5\n#.##.\n\nSample Output 2\n\n2\n\nSample Input 3\n\n9\n.........\n\nSample Output 3\n\n0", "sample_input": "3\n#.#\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03069", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N stones arranged in a row. Every stone is painted white or black.\nA string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is ., and the stone is black if the character is #.\n\nTakahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone.\nFind the minimum number of stones that needs to be recolored.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\nS is a string of length N consisting of . and #.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the minimum number of stones that needs to be recolored.\n\nSample Input 1\n\n3\n#.#\n\nSample Output 1\n\n1\n\nIt is enough to change the color of the first stone to white.\n\nSample Input 2\n\n5\n#.##.\n\nSample Output 2\n\n2\n\nSample Input 3\n\n9\n.........\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 165, "cpu_time_ms": 125, "memory_kb": 13540}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s870405933", "group_id": "codeNet:p03069", "input_text": "(defparameter n (read))\n(defparameter s (coerce (read-line) 'list))\n\n(defun f (lst acc# acc)\n (cond ((or (endp lst)\n (endp (cdr lst)))\n acc)\n ((and (char= #\\. (car lst))\n (char= #\\# (cdr lst)))\n (f (cdr lst) acc# (cons (+ acc# (count #\\. (cdr lst))) acc)))\n ((char= #\\# (car lst))\n (f (cdr lst) (1+ acc#) acc))\n (t (f (cdr lst) acc# acc))))\n\n(format t \"~a\" (f s 0 '()))\n", "language": "Lisp", "metadata": {"date": 1555815280, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03069.html", "problem_id": "p03069", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03069/input.txt", "sample_output_relpath": "derived/input_output/data/p03069/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03069/Lisp/s870405933.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s870405933", "user_id": "u956039157"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defparameter n (read))\n(defparameter s (coerce (read-line) 'list))\n\n(defun f (lst acc# acc)\n (cond ((or (endp lst)\n (endp (cdr lst)))\n acc)\n ((and (char= #\\. (car lst))\n (char= #\\# (cdr lst)))\n (f (cdr lst) acc# (cons (+ acc# (count #\\. (cdr lst))) acc)))\n ((char= #\\# (car lst))\n (f (cdr lst) (1+ acc#) acc))\n (t (f (cdr lst) acc# acc))))\n\n(format t \"~a\" (f s 0 '()))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N stones arranged in a row. Every stone is painted white or black.\nA string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is ., and the stone is black if the character is #.\n\nTakahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone.\nFind the minimum number of stones that needs to be recolored.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\nS is a string of length N consisting of . and #.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the minimum number of stones that needs to be recolored.\n\nSample Input 1\n\n3\n#.#\n\nSample Output 1\n\n1\n\nIt is enough to change the color of the first stone to white.\n\nSample Input 2\n\n5\n#.##.\n\nSample Output 2\n\n2\n\nSample Input 3\n\n9\n.........\n\nSample Output 3\n\n0", "sample_input": "3\n#.#\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03069", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N stones arranged in a row. Every stone is painted white or black.\nA string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is ., and the stone is black if the character is #.\n\nTakahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone.\nFind the minimum number of stones that needs to be recolored.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\nS is a string of length N consisting of . and #.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the minimum number of stones that needs to be recolored.\n\nSample Input 1\n\n3\n#.#\n\nSample Output 1\n\n1\n\nIt is enough to change the color of the first stone to white.\n\nSample Input 2\n\n5\n#.##.\n\nSample Output 2\n\n2\n\nSample Input 3\n\n9\n.........\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 441, "cpu_time_ms": 2106, "memory_kb": 70120}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s785866371", "group_id": "codeNet:p03071", "input_text": "; ABC124-A\n(defun max2(a b)\n (if (> a b) a b)\n )\n\n(defun solve(a b)\n (setq r1 (max2 a b))\n (setq r2 (if (> a b) (max2 (- a 1) b) (max2 a (- b 1))))\n (+ r1 r2)\n )\n\n(let ((a (read)) (b (read)))\n (format t \"~d~%\" (solve a b))\n )\n", "language": "Lisp", "metadata": {"date": 1555242840, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03071.html", "problem_id": "p03071", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03071/input.txt", "sample_output_relpath": "derived/input_output/data/p03071/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03071/Lisp/s785866371.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s785866371", "user_id": "u021877437"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "; ABC124-A\n(defun max2(a b)\n (if (> a b) a b)\n )\n\n(defun solve(a b)\n (setq r1 (max2 a b))\n (setq r2 (if (> a b) (max2 (- a 1) b) (max2 a (- b 1))))\n (+ r1 r2)\n )\n\n(let ((a (read)) (b (read)))\n (format t \"~d~%\" (solve a b))\n )\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are two buttons, one of size A and one of size B.\n\nWhen you press a button of size X, you get X coins and the size of that button decreases by 1.\n\nYou will press a button twice. Here, you can press the same button twice, or press both buttons once.\n\nAt most how many coins can you get?\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq A, B \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the maximum number of coins you can get.\n\nSample Input 1\n\n5 3\n\nSample Output 1\n\n9\n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this is the maximum result.\n\nSample Input 2\n\n3 4\n\nSample Output 2\n\n7\n\nSample Input 3\n\n6 6\n\nSample Output 3\n\n12", "sample_input": "5 3\n"}, "reference_outputs": ["9\n"], "source_document_id": "p03071", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are two buttons, one of size A and one of size B.\n\nWhen you press a button of size X, you get X coins and the size of that button decreases by 1.\n\nYou will press a button twice. Here, you can press the same button twice, or press both buttons once.\n\nAt most how many coins can you get?\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq A, B \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the maximum number of coins you can get.\n\nSample Input 1\n\n5 3\n\nSample Output 1\n\n9\n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this is the maximum result.\n\nSample Input 2\n\n3 4\n\nSample Output 2\n\n7\n\nSample Input 3\n\n6 6\n\nSample Output 3\n\n12", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 234, "cpu_time_ms": 40, "memory_kb": 5736}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s580708329", "group_id": "codeNet:p03074", "input_text": "(defun window-sumlist (list windowsize)\n (labels ((mappedreduce (function sequence)\n (if (= 1 (length sequence))\n (list (elt sequence 0))\n (let* ((n (elt sequence 0)))\n (mapcar (lambda (x) (setf n (funcall function n x)))\n (subseq sequence 1))))))\n (let* ((lst-k (cons 0 (cons (car list) (mappedreduce #'+ list)))))\n (loop :for k :in (subseq lst-k windowsize)\n :for l :in lst-k\n :collect (- k l)))))\n\n\n(window-sumlist '(1 2 4 8 16) 3)\n\n(defun compressor (list)\n (let* ((ret nil))\n (map 'nil (lambda (x)\n (if (and ret (equal x (caar ret)))\n (incf (cdar ret))\n (push (cons x 1) ret)))\n list)\n ret))\n(let* ((n (read))\n (m (read))\n (lst (mapcar #'cdr (compressor (read-line)))))\n (princ (reduce #'max (window-sumlist lst (1+ (* 2 m))))))\n", "language": "Lisp", "metadata": {"date": 1590800480, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03074.html", "problem_id": "p03074", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03074/input.txt", "sample_output_relpath": "derived/input_output/data/p03074/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03074/Lisp/s580708329.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s580708329", "user_id": "u610490393"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun window-sumlist (list windowsize)\n (labels ((mappedreduce (function sequence)\n (if (= 1 (length sequence))\n (list (elt sequence 0))\n (let* ((n (elt sequence 0)))\n (mapcar (lambda (x) (setf n (funcall function n x)))\n (subseq sequence 1))))))\n (let* ((lst-k (cons 0 (cons (car list) (mappedreduce #'+ list)))))\n (loop :for k :in (subseq lst-k windowsize)\n :for l :in lst-k\n :collect (- k l)))))\n\n\n(window-sumlist '(1 2 4 8 16) 3)\n\n(defun compressor (list)\n (let* ((ret nil))\n (map 'nil (lambda (x)\n (if (and ret (equal x (caar ret)))\n (incf (cdar ret))\n (push (cons x 1) ret)))\n list)\n ret))\n(let* ((n (read))\n (m (read))\n (lst (mapcar #'cdr (compressor (read-line)))))\n (princ (reduce #'max (window-sumlist lst (1+ (* 2 m))))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nN people are arranged in a row from left to right.\n\nYou are given a string S of length N consisting of 0 and 1, and a positive integer K.\n\nThe i-th person from the left is standing on feet if the i-th character of S is 0, and standing on hands if that character is 1.\n\nYou will give the following direction at most K times (possibly zero):\n\nDirection: Choose integers l and r satisfying 1 \\leq l \\leq r \\leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands.\n\nFind the maximum possible number of consecutive people standing on hands after at most K directions.\n\nConstraints\n\nN is an integer satisfying 1 \\leq N \\leq 10^5.\n\nK is an integer satisfying 1 \\leq K \\leq 10^5.\n\nThe length of the string S is N.\n\nEach character of the string S is 0 or 1.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nS\n\nOutput\n\nPrint the maximum possible number of consecutive people standing on hands after at most K directions.\n\nSample Input 1\n\n5 1\n00010\n\nSample Output 1\n\n4\n\nWe can have four consecutive people standing on hands, which is the maximum result, by giving the following direction:\n\nGive the direction with l = 1, r = 3, which flips the first, second and third persons from the left.\n\nSample Input 2\n\n14 2\n11101010110011\n\nSample Output 2\n\n8\n\nSample Input 3\n\n1 1\n1\n\nSample Output 3\n\n1\n\nNo directions are necessary.", "sample_input": "5 1\n00010\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03074", "source_text": "Score : 400 points\n\nProblem Statement\n\nN people are arranged in a row from left to right.\n\nYou are given a string S of length N consisting of 0 and 1, and a positive integer K.\n\nThe i-th person from the left is standing on feet if the i-th character of S is 0, and standing on hands if that character is 1.\n\nYou will give the following direction at most K times (possibly zero):\n\nDirection: Choose integers l and r satisfying 1 \\leq l \\leq r \\leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands.\n\nFind the maximum possible number of consecutive people standing on hands after at most K directions.\n\nConstraints\n\nN is an integer satisfying 1 \\leq N \\leq 10^5.\n\nK is an integer satisfying 1 \\leq K \\leq 10^5.\n\nThe length of the string S is N.\n\nEach character of the string S is 0 or 1.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nS\n\nOutput\n\nPrint the maximum possible number of consecutive people standing on hands after at most K directions.\n\nSample Input 1\n\n5 1\n00010\n\nSample Output 1\n\n4\n\nWe can have four consecutive people standing on hands, which is the maximum result, by giving the following direction:\n\nGive the direction with l = 1, r = 3, which flips the first, second and third persons from the left.\n\nSample Input 2\n\n14 2\n11101010110011\n\nSample Output 2\n\n8\n\nSample Input 3\n\n1 1\n1\n\nSample Output 3\n\n1\n\nNo directions are necessary.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 934, "cpu_time_ms": 185, "memory_kb": 18784}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s158887464", "group_id": "codeNet:p03075", "input_text": "(setq a(read))(read)(read)(read)(princ(if(>(-(read)a)(read))\":(\"\"Yay!\"))", "language": "Lisp", "metadata": {"date": 1554589417, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03075.html", "problem_id": "p03075", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03075/input.txt", "sample_output_relpath": "derived/input_output/data/p03075/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03075/Lisp/s158887464.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s158887464", "user_id": "u657913472"}, "prompt_components": {"gold_output": "Yay!\n", "input_to_evaluate": "(setq a(read))(read)(read)(read)(princ(if(>(-(read)a)(read))\":(\"\"Yay!\"))", "problem_context": "Score: 100 points\n\nProblem Statement\n\nIn AtCoder city, there are five antennas standing in a straight line. They are called Antenna A, B, C, D and E from west to east, and their coordinates are a, b, c, d and e, respectively.\n\nTwo antennas can communicate directly if the distance between them is k or less, and they cannot if the distance is greater than k.\n\nDetermine if there exists a pair of antennas that cannot communicate directly.\n\nHere, assume that the distance between two antennas at coordinates p and q (p < q) is q - p.\n\nConstraints\n\na, b, c, d, e and k are integers between 0 and 123 (inclusive).\n\na < b < c < d < e\n\nInput\n\nInput is given from Standard Input in the following format:\n\na\nb\nc\nd\ne\nk\n\nOutput\n\nPrint :( if there exists a pair of antennas that cannot communicate directly, and print Yay! if there is no such pair.\n\nSample Input 1\n\n1\n2\n4\n8\n9\n15\n\nSample Output 1\n\nYay!\n\nIn this case, there is no pair of antennas that cannot communicate directly, because:\n\nthe distance between A and B is 2 - 1 = 1\n\nthe distance between A and C is 4 - 1 = 3\n\nthe distance between A and D is 8 - 1 = 7\n\nthe distance between A and E is 9 - 1 = 8\n\nthe distance between B and C is 4 - 2 = 2\n\nthe distance between B and D is 8 - 2 = 6\n\nthe distance between B and E is 9 - 2 = 7\n\nthe distance between C and D is 8 - 4 = 4\n\nthe distance between C and E is 9 - 4 = 5\n\nthe distance between D and E is 9 - 8 = 1\n\nand none of them is greater than 15. Thus, the correct output is Yay!.\n\nSample Input 2\n\n15\n18\n26\n35\n36\n18\n\nSample Output 2\n\n:(\n\nIn this case, the distance between antennas A and D is 35 - 15 = 20 and exceeds 18, so they cannot communicate directly.\nThus, the correct output is :(.", "sample_input": "1\n2\n4\n8\n9\n15\n"}, "reference_outputs": ["Yay!\n"], "source_document_id": "p03075", "source_text": "Score: 100 points\n\nProblem Statement\n\nIn AtCoder city, there are five antennas standing in a straight line. They are called Antenna A, B, C, D and E from west to east, and their coordinates are a, b, c, d and e, respectively.\n\nTwo antennas can communicate directly if the distance between them is k or less, and they cannot if the distance is greater than k.\n\nDetermine if there exists a pair of antennas that cannot communicate directly.\n\nHere, assume that the distance between two antennas at coordinates p and q (p < q) is q - p.\n\nConstraints\n\na, b, c, d, e and k are integers between 0 and 123 (inclusive).\n\na < b < c < d < e\n\nInput\n\nInput is given from Standard Input in the following format:\n\na\nb\nc\nd\ne\nk\n\nOutput\n\nPrint :( if there exists a pair of antennas that cannot communicate directly, and print Yay! if there is no such pair.\n\nSample Input 1\n\n1\n2\n4\n8\n9\n15\n\nSample Output 1\n\nYay!\n\nIn this case, there is no pair of antennas that cannot communicate directly, because:\n\nthe distance between A and B is 2 - 1 = 1\n\nthe distance between A and C is 4 - 1 = 3\n\nthe distance between A and D is 8 - 1 = 7\n\nthe distance between A and E is 9 - 1 = 8\n\nthe distance between B and C is 4 - 2 = 2\n\nthe distance between B and D is 8 - 2 = 6\n\nthe distance between B and E is 9 - 2 = 7\n\nthe distance between C and D is 8 - 4 = 4\n\nthe distance between C and E is 9 - 4 = 5\n\nthe distance between D and E is 9 - 8 = 1\n\nand none of them is greater than 15. Thus, the correct output is Yay!.\n\nSample Input 2\n\n15\n18\n26\n35\n36\n18\n\nSample Output 2\n\n:(\n\nIn this case, the distance between antennas A and D is 35 - 15 = 20 and exceeds 18, so they cannot communicate directly.\nThus, the correct output is :(.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 72, "cpu_time_ms": 298, "memory_kb": 8164}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s420080519", "group_id": "codeNet:p03076", "input_text": "(defparameter abcde\n (loop repeat 5\n collect (read)))\n\n(defun f (abcde)\n (+ (* 10 (1- (loop for i in abcde\n sum (ceiling i 10))))\n (reduce #'min\n (remove 0 (mapcar (lambda (i) (mod i 10))\n abcde)))))\n\n(princ (f abcde))\n", "language": "Lisp", "metadata": {"date": 1554578651, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03076.html", "problem_id": "p03076", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03076/input.txt", "sample_output_relpath": "derived/input_output/data/p03076/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03076/Lisp/s420080519.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s420080519", "user_id": "u956039157"}, "prompt_components": {"gold_output": "215\n", "input_to_evaluate": "(defparameter abcde\n (loop repeat 5\n collect (read)))\n\n(defun f (abcde)\n (+ (* 10 (1- (loop for i in abcde\n sum (ceiling i 10))))\n (reduce #'min\n (remove 0 (mapcar (lambda (i) (mod i 10))\n abcde)))))\n\n(princ (f abcde))\n", "problem_context": "Score: 200 points\n\nProblem Statement\n\nThe restaurant AtCoder serves the following five dishes:\n\nABC Don (rice bowl): takes A minutes to serve.\n\nARC Curry: takes B minutes to serve.\n\nAGC Pasta: takes C minutes to serve.\n\nAPC Ramen: takes D minutes to serve.\n\nATC Hanbagu (hamburger patty): takes E minutes to serve.\n\nHere, the time to serve a dish is the time between when an order is placed and when the dish is delivered.\n\nThis restaurant has the following rules on orders:\n\nAn order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...).\n\nOnly one dish can be ordered at a time.\n\nNo new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered.\n\nE869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered.\n\nHere, he can order the dishes in any order he likes, and he can place an order already at time 0.\n\nConstraints\n\nA, B, C, D and E are integers between 1 and 123 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA\nB\nC\nD\nE\n\nOutput\n\nPrint the earliest possible time for the last dish to be delivered, as an integer.\n\nSample Input 1\n\n29\n20\n7\n35\n120\n\nSample Output 1\n\n215\n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta, ATC Hanbagu, APC Ramen, the earliest possible time for each order is as follows:\n\nOrder ABC Don at time 0, which will be delivered at time 29.\n\nOrder ARC Curry at time 30, which will be delivered at time 50.\n\nOrder AGC Pasta at time 50, which will be delivered at time 57.\n\nOrder ATC Hanbagu at time 60, which will be delivered at time 180.\n\nOrder APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered earlier than this.\n\nSample Input 2\n\n101\n86\n119\n108\n57\n\nSample Output 2\n\n481\n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC Hanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as follows:\n\nOrder AGC Pasta at time 0, which will be delivered at time 119.\n\nOrder ARC Curry at time 120, which will be delivered at time 206.\n\nOrder ATC Hanbagu at time 210, which will be delivered at time 267.\n\nOrder APC Ramen at time 270, which will be delivered at time 378.\n\nOrder ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered earlier than this.\n\nSample Input 3\n\n123\n123\n123\n123\n123\n\nSample Output 3\n\n643\n\nThis is the largest valid case.", "sample_input": "29\n20\n7\n35\n120\n"}, "reference_outputs": ["215\n"], "source_document_id": "p03076", "source_text": "Score: 200 points\n\nProblem Statement\n\nThe restaurant AtCoder serves the following five dishes:\n\nABC Don (rice bowl): takes A minutes to serve.\n\nARC Curry: takes B minutes to serve.\n\nAGC Pasta: takes C minutes to serve.\n\nAPC Ramen: takes D minutes to serve.\n\nATC Hanbagu (hamburger patty): takes E minutes to serve.\n\nHere, the time to serve a dish is the time between when an order is placed and when the dish is delivered.\n\nThis restaurant has the following rules on orders:\n\nAn order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...).\n\nOnly one dish can be ordered at a time.\n\nNo new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered.\n\nE869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered.\n\nHere, he can order the dishes in any order he likes, and he can place an order already at time 0.\n\nConstraints\n\nA, B, C, D and E are integers between 1 and 123 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA\nB\nC\nD\nE\n\nOutput\n\nPrint the earliest possible time for the last dish to be delivered, as an integer.\n\nSample Input 1\n\n29\n20\n7\n35\n120\n\nSample Output 1\n\n215\n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta, ATC Hanbagu, APC Ramen, the earliest possible time for each order is as follows:\n\nOrder ABC Don at time 0, which will be delivered at time 29.\n\nOrder ARC Curry at time 30, which will be delivered at time 50.\n\nOrder AGC Pasta at time 50, which will be delivered at time 57.\n\nOrder ATC Hanbagu at time 60, which will be delivered at time 180.\n\nOrder APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered earlier than this.\n\nSample Input 2\n\n101\n86\n119\n108\n57\n\nSample Output 2\n\n481\n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC Hanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as follows:\n\nOrder AGC Pasta at time 0, which will be delivered at time 119.\n\nOrder ARC Curry at time 120, which will be delivered at time 206.\n\nOrder ATC Hanbagu at time 210, which will be delivered at time 267.\n\nOrder APC Ramen at time 270, which will be delivered at time 378.\n\nOrder ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered earlier than this.\n\nSample Input 3\n\n123\n123\n123\n123\n123\n\nSample Output 3\n\n643\n\nThis is the largest valid case.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 294, "cpu_time_ms": 184, "memory_kb": 15968}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s059298036", "group_id": "codeNet:p03079", "input_text": "(princ(if(= #1=(read)#1##1#)\"Yes\"\"No\"))", "language": "Lisp", "metadata": {"date": 1553984798, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03079.html", "problem_id": "p03079", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03079/input.txt", "sample_output_relpath": "derived/input_output/data/p03079/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03079/Lisp/s059298036.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s059298036", "user_id": "u657913472"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(princ(if(= #1=(read)#1##1#)\"Yes\"\"No\"))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given three integers A, B and C.\n\nDetermine if there exists an equilateral triangle whose sides have lengths A, B and C.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A,B,C \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf there exists an equilateral triangle whose sides have lengths A, B and C, print Yes; otherwise, print No.\n\nSample Input 1\n\n2 2 2\n\nSample Output 1\n\nYes\n\nThere exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\nSample Input 2\n\n3 4 5\n\nSample Output 2\n\nNo\n\nThere is no equilateral triangle whose sides have lengths 3, 4 and 5.", "sample_input": "2 2 2\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03079", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given three integers A, B and C.\n\nDetermine if there exists an equilateral triangle whose sides have lengths A, B and C.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A,B,C \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf there exists an equilateral triangle whose sides have lengths A, B and C, print Yes; otherwise, print No.\n\nSample Input 1\n\n2 2 2\n\nSample Output 1\n\nYes\n\nThere exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\nSample Input 2\n\n3 4 5\n\nSample Output 2\n\nNo\n\nThere is no equilateral triangle whose sides have lengths 3, 4 and 5.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 39, "cpu_time_ms": 19, "memory_kb": 3944}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s342128951", "group_id": "codeNet:p03080", "input_text": "(let ((n (read))\n (s (read-line)))\n (princ (if (< (count #\\B s) (count #\\R s)) \"Yes\" \"No\")))", "language": "Lisp", "metadata": {"date": 1554239018, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03080.html", "problem_id": "p03080", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03080/input.txt", "sample_output_relpath": "derived/input_output/data/p03080/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03080/Lisp/s342128951.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s342128951", "user_id": "u994767958"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((n (read))\n (s (read-line)))\n (princ (if (< (count #\\B s) (count #\\R s)) \"Yes\" \"No\")))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N people numbered 1 to N. Each person wears a red hat or a blue hat.\n\nYou are given a string s representing the colors of the people. Person i wears a red hat if s_i is R, and a blue hat if s_i is B.\n\nDetermine if there are more people wearing a red hat than people wearing a blue hat.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n|s| = N\n\ns_i is R or B.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\ns\n\nOutput\n\nIf there are more people wearing a red hat than there are people wearing a blue hat, print Yes; otherwise, print No.\n\nSample Input 1\n\n4\nRRBR\n\nSample Output 1\n\nYes\n\nThere are three people wearing a red hat, and one person wearing a blue hat.\n\nSince there are more people wearing a red hat than people wearing a blue hat, the answer is Yes.\n\nSample Input 2\n\n4\nBRBR\n\nSample Output 2\n\nNo\n\nThere are two people wearing a red hat, and two people wearing a blue hat.\n\nSince there are as many people wearing a red hat as people wearing a blue hat, the answer is No.", "sample_input": "4\nRRBR\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03080", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N people numbered 1 to N. Each person wears a red hat or a blue hat.\n\nYou are given a string s representing the colors of the people. Person i wears a red hat if s_i is R, and a blue hat if s_i is B.\n\nDetermine if there are more people wearing a red hat than people wearing a blue hat.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n|s| = N\n\ns_i is R or B.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\ns\n\nOutput\n\nIf there are more people wearing a red hat than there are people wearing a blue hat, print Yes; otherwise, print No.\n\nSample Input 1\n\n4\nRRBR\n\nSample Output 1\n\nYes\n\nThere are three people wearing a red hat, and one person wearing a blue hat.\n\nSince there are more people wearing a red hat than people wearing a blue hat, the answer is Yes.\n\nSample Input 2\n\n4\nBRBR\n\nSample Output 2\n\nNo\n\nThere are two people wearing a red hat, and two people wearing a blue hat.\n\nSince there are as many people wearing a red hat as people wearing a blue hat, the answer is No.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 101, "cpu_time_ms": 9, "memory_kb": 3176}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s587152408", "group_id": "codeNet:p03080", "input_text": "(let ((n (read))\n (lst (concatenate 'list (read-line))))\n (if (> (count #\\R lst :test #'char=) (count #\\B lst :test #'char=))\n (princ \"Yes\")\n (princ \"No\")))", "language": "Lisp", "metadata": {"date": 1553976378, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03080.html", "problem_id": "p03080", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03080/input.txt", "sample_output_relpath": "derived/input_output/data/p03080/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03080/Lisp/s587152408.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s587152408", "user_id": "u610490393"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((n (read))\n (lst (concatenate 'list (read-line))))\n (if (> (count #\\R lst :test #'char=) (count #\\B lst :test #'char=))\n (princ \"Yes\")\n (princ \"No\")))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N people numbered 1 to N. Each person wears a red hat or a blue hat.\n\nYou are given a string s representing the colors of the people. Person i wears a red hat if s_i is R, and a blue hat if s_i is B.\n\nDetermine if there are more people wearing a red hat than people wearing a blue hat.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n|s| = N\n\ns_i is R or B.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\ns\n\nOutput\n\nIf there are more people wearing a red hat than there are people wearing a blue hat, print Yes; otherwise, print No.\n\nSample Input 1\n\n4\nRRBR\n\nSample Output 1\n\nYes\n\nThere are three people wearing a red hat, and one person wearing a blue hat.\n\nSince there are more people wearing a red hat than people wearing a blue hat, the answer is Yes.\n\nSample Input 2\n\n4\nBRBR\n\nSample Output 2\n\nNo\n\nThere are two people wearing a red hat, and two people wearing a blue hat.\n\nSince there are as many people wearing a red hat as people wearing a blue hat, the answer is No.", "sample_input": "4\nRRBR\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03080", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N people numbered 1 to N. Each person wears a red hat or a blue hat.\n\nYou are given a string s representing the colors of the people. Person i wears a red hat if s_i is R, and a blue hat if s_i is B.\n\nDetermine if there are more people wearing a red hat than people wearing a blue hat.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n|s| = N\n\ns_i is R or B.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\ns\n\nOutput\n\nIf there are more people wearing a red hat than there are people wearing a blue hat, print Yes; otherwise, print No.\n\nSample Input 1\n\n4\nRRBR\n\nSample Output 1\n\nYes\n\nThere are three people wearing a red hat, and one person wearing a blue hat.\n\nSince there are more people wearing a red hat than people wearing a blue hat, the answer is Yes.\n\nSample Input 2\n\n4\nBRBR\n\nSample Output 2\n\nNo\n\nThere are two people wearing a red hat, and two people wearing a blue hat.\n\nSince there are as many people wearing a red hat as people wearing a blue hat, the answer is No.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 172, "cpu_time_ms": 105, "memory_kb": 10084}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s384037194", "group_id": "codeNet:p03081", "input_text": "(defparameter n (read))\n(defparameter q (read))\n(defparameter address (read-line))\n(defparameter magic-words\n (loop repeat q\n collect (list (character (read)) (character (read)))))\n\n(defparameter golem-vector\n (make-array n :initial-element 1))\n\n(defun char-positions (char string)\n (declare (optimize (speed 3) (debug 0) (safety 0)))\n (let ((n (length string)))\n (labels ((rec (index acc)\n (cond ((< index 0) acc)\n ((char= char (char string index))\n (rec (1- index) (cons index acc)))\n (t (rec (1- index) acc)))))\n (rec (1- n) nil))))\n\n(defun f (size golem-vector address magic-words)\n (loop for magic-word in magic-words\n do (destructuring-bind (ti di) magic-word\n (let ((positions (char-positions ti address)))\n (mapc (lambda (pos)\n (let ((cur-pos-golems (svref golem-vector pos))\n (r-pos (1- pos))\n (l-pos (1+ pos)))\n (cond ((and (char= di #\\R)\n (<= 0 r-pos (1- size)))\n (incf (svref golem-vector r-pos)\n cur-pos-golems))\n ((and (char= di #\\L)\n (<= 0 r-pos (1- size)))\n (incf (svref golem-vector l-pos)\n cur-pos-golems)))\n (setf (svref golem-vector pos) 0)))\n positions))))\n golem-vector)\n\n(defun vector-sum (vector)\n (let ((n (length vector)))\n (labels ((rec (i acc)\n (if (zerop i)\n acc\n (rec (1- i) (+ (svref vector (1- i)) acc)))))\n (rec n 0))))\n\n(princ (vector-sum (f n golem-vector address magic-words)))\n", "language": "Lisp", "metadata": {"date": 1553980975, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03081.html", "problem_id": "p03081", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03081/input.txt", "sample_output_relpath": "derived/input_output/data/p03081/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03081/Lisp/s384037194.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s384037194", "user_id": "u956039157"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defparameter n (read))\n(defparameter q (read))\n(defparameter address (read-line))\n(defparameter magic-words\n (loop repeat q\n collect (list (character (read)) (character (read)))))\n\n(defparameter golem-vector\n (make-array n :initial-element 1))\n\n(defun char-positions (char string)\n (declare (optimize (speed 3) (debug 0) (safety 0)))\n (let ((n (length string)))\n (labels ((rec (index acc)\n (cond ((< index 0) acc)\n ((char= char (char string index))\n (rec (1- index) (cons index acc)))\n (t (rec (1- index) acc)))))\n (rec (1- n) nil))))\n\n(defun f (size golem-vector address magic-words)\n (loop for magic-word in magic-words\n do (destructuring-bind (ti di) magic-word\n (let ((positions (char-positions ti address)))\n (mapc (lambda (pos)\n (let ((cur-pos-golems (svref golem-vector pos))\n (r-pos (1- pos))\n (l-pos (1+ pos)))\n (cond ((and (char= di #\\R)\n (<= 0 r-pos (1- size)))\n (incf (svref golem-vector r-pos)\n cur-pos-golems))\n ((and (char= di #\\L)\n (<= 0 r-pos (1- size)))\n (incf (svref golem-vector l-pos)\n cur-pos-golems)))\n (setf (svref golem-vector pos) 0)))\n positions))))\n golem-vector)\n\n(defun vector-sum (vector)\n (let ((n (length vector)))\n (labels ((rec (i acc)\n (if (zerop i)\n acc\n (rec (1- i) (+ (svref vector (1- i)) acc)))))\n (rec n 0))))\n\n(princ (vector-sum (f n golem-vector address magic-words)))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere are N squares numbered 1 to N from left to right.\nEach square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square.\n\nSnuke cast Q spells to move the golems.\n\nThe i-th spell consisted of two characters t_i and d_i, where d_i is L or R.\nWhen Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is L, and moved to the square adjacent to the right if d_i is R.\n\nHowever, when a golem tried to move left from Square 1 or move right from Square N, it disappeared.\n\nFind the number of golems remaining after Snuke cast the Q spells.\n\nConstraints\n\n1 \\leq N,Q \\leq 2 \\times 10^{5}\n\n|s| = N\n\ns_i and t_i are uppercase English letters.\n\nd_i is L or R.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\ns\nt_1 d_1\n\\vdots\nt_{Q} d_Q\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3 4\nABC\nA L\nB L\nB R\nA R\n\nSample Output 1\n\n2\n\nInitially, there is one golem on each square.\n\nIn the first spell, the golem on Square 1 tries to move left and disappears.\n\nIn the second spell, the golem on Square 2 moves left.\n\nIn the third spell, no golem moves.\n\nIn the fourth spell, the golem on Square 1 moves right.\n\nAfter the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\nSample Input 2\n\n8 3\nAABCBDBA\nA L\nB R\nA R\n\nSample Output 2\n\n5\n\nAfter the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n\nNote that a single spell may move multiple golems.\n\nSample Input 3\n\n10 15\nSNCZWRCEWB\nB R\nR R\nE R\nW R\nZ L\nS R\nQ L\nW L\nB R\nC L\nA L\nN L\nE R\nZ L\nS L\n\nSample Output 3\n\n3", "sample_input": "3 4\nABC\nA L\nB L\nB R\nA R\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03081", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere are N squares numbered 1 to N from left to right.\nEach square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square.\n\nSnuke cast Q spells to move the golems.\n\nThe i-th spell consisted of two characters t_i and d_i, where d_i is L or R.\nWhen Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is L, and moved to the square adjacent to the right if d_i is R.\n\nHowever, when a golem tried to move left from Square 1 or move right from Square N, it disappeared.\n\nFind the number of golems remaining after Snuke cast the Q spells.\n\nConstraints\n\n1 \\leq N,Q \\leq 2 \\times 10^{5}\n\n|s| = N\n\ns_i and t_i are uppercase English letters.\n\nd_i is L or R.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\ns\nt_1 d_1\n\\vdots\nt_{Q} d_Q\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3 4\nABC\nA L\nB L\nB R\nA R\n\nSample Output 1\n\n2\n\nInitially, there is one golem on each square.\n\nIn the first spell, the golem on Square 1 tries to move left and disappears.\n\nIn the second spell, the golem on Square 2 moves left.\n\nIn the third spell, no golem moves.\n\nIn the fourth spell, the golem on Square 1 moves right.\n\nAfter the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\nSample Input 2\n\n8 3\nAABCBDBA\nA L\nB R\nA R\n\nSample Output 2\n\n5\n\nAfter the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n\nNote that a single spell may move multiple golems.\n\nSample Input 3\n\n10 15\nSNCZWRCEWB\nB R\nR R\nE R\nW R\nZ L\nS R\nQ L\nW L\nB R\nC L\nA L\nN L\nE R\nZ L\nS L\n\nSample Output 3\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1886, "cpu_time_ms": 2106, "memory_kb": 82400}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s228948388", "group_id": "codeNet:p03085", "input_text": "(let ((b (read-char)))\n(if (string= b \"A\")\n(princ \"T\")\n)\n(if (string= b \"T\")\n(princ \"A\")\n)\n(if (string= b \"C\")\n(princ \"G\")\n)\n(if (string= b \"G\")\n(princ \"C\")\n)\n)", "language": "Lisp", "metadata": {"date": 1596880726, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03085.html", "problem_id": "p03085", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03085/input.txt", "sample_output_relpath": "derived/input_output/data/p03085/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03085/Lisp/s228948388.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s228948388", "user_id": "u136500538"}, "prompt_components": {"gold_output": "T\n", "input_to_evaluate": "(let ((b (read-char)))\n(if (string= b \"A\")\n(princ \"T\")\n)\n(if (string= b \"T\")\n(princ \"A\")\n)\n(if (string= b \"C\")\n(princ \"G\")\n)\n(if (string= b \"G\")\n(princ \"C\")\n)\n)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nOn the Planet AtCoder, there are four types of bases: A, C, G and T. A bonds with T, and C bonds with G.\n\nYou are given a letter b as input, which is A, C, G or T. Write a program that prints the letter representing the base that bonds with the base b.\n\nConstraints\n\nb is one of the letters A, C, G and T.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nb\n\nOutput\n\nPrint the letter representing the base that bonds with the base b.\n\nSample Input 1\n\nA\n\nSample Output 1\n\nT\n\nSample Input 2\n\nG\n\nSample Output 2\n\nC", "sample_input": "A\n"}, "reference_outputs": ["T\n"], "source_document_id": "p03085", "source_text": "Score : 100 points\n\nProblem Statement\n\nOn the Planet AtCoder, there are four types of bases: A, C, G and T. A bonds with T, and C bonds with G.\n\nYou are given a letter b as input, which is A, C, G or T. Write a program that prints the letter representing the base that bonds with the base b.\n\nConstraints\n\nb is one of the letters A, C, G and T.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nb\n\nOutput\n\nPrint the letter representing the base that bonds with the base b.\n\nSample Input 1\n\nA\n\nSample Output 1\n\nT\n\nSample Input 2\n\nG\n\nSample Output 2\n\nC", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 160, "cpu_time_ms": 13, "memory_kb": 24192}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s644885119", "group_id": "codeNet:p03085", "input_text": "(let ((s (read-line)))\n (case s\n (\"A\" (princ \"T\"))\n (\"T\" (princ \"A\"))\n (\"G\" (princ \"C\"))\n (\"C\" (princ \"G\"))))\n(fresh-line)\n", "language": "Lisp", "metadata": {"date": 1593870812, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03085.html", "problem_id": "p03085", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03085/input.txt", "sample_output_relpath": "derived/input_output/data/p03085/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03085/Lisp/s644885119.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s644885119", "user_id": "u425762225"}, "prompt_components": {"gold_output": "T\n", "input_to_evaluate": "(let ((s (read-line)))\n (case s\n (\"A\" (princ \"T\"))\n (\"T\" (princ \"A\"))\n (\"G\" (princ \"C\"))\n (\"C\" (princ \"G\"))))\n(fresh-line)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nOn the Planet AtCoder, there are four types of bases: A, C, G and T. A bonds with T, and C bonds with G.\n\nYou are given a letter b as input, which is A, C, G or T. Write a program that prints the letter representing the base that bonds with the base b.\n\nConstraints\n\nb is one of the letters A, C, G and T.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nb\n\nOutput\n\nPrint the letter representing the base that bonds with the base b.\n\nSample Input 1\n\nA\n\nSample Output 1\n\nT\n\nSample Input 2\n\nG\n\nSample Output 2\n\nC", "sample_input": "A\n"}, "reference_outputs": ["T\n"], "source_document_id": "p03085", "source_text": "Score : 100 points\n\nProblem Statement\n\nOn the Planet AtCoder, there are four types of bases: A, C, G and T. A bonds with T, and C bonds with G.\n\nYou are given a letter b as input, which is A, C, G or T. Write a program that prints the letter representing the base that bonds with the base b.\n\nConstraints\n\nb is one of the letters A, C, G and T.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nb\n\nOutput\n\nPrint the letter representing the base that bonds with the base b.\n\nSample Input 1\n\nA\n\nSample Output 1\n\nT\n\nSample Input 2\n\nG\n\nSample Output 2\n\nC", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 151, "cpu_time_ms": 15, "memory_kb": 23364}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s712775671", "group_id": "codeNet:p03085", "input_text": "(princ \n (if (equal \"A\" (setq b (read))) \"T\" \n\t(if (equal \"T\" b) \"A\" \n\t (if (equal \"C\" b) \"G\"\n\t\t(if (equal \"G\" b) \"C\"\n\t\t)))))", "language": "Lisp", "metadata": {"date": 1559268328, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03085.html", "problem_id": "p03085", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03085/input.txt", "sample_output_relpath": "derived/input_output/data/p03085/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03085/Lisp/s712775671.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s712775671", "user_id": "u192442087"}, "prompt_components": {"gold_output": "T\n", "input_to_evaluate": "(princ \n (if (equal \"A\" (setq b (read))) \"T\" \n\t(if (equal \"T\" b) \"A\" \n\t (if (equal \"C\" b) \"G\"\n\t\t(if (equal \"G\" b) \"C\"\n\t\t)))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nOn the Planet AtCoder, there are four types of bases: A, C, G and T. A bonds with T, and C bonds with G.\n\nYou are given a letter b as input, which is A, C, G or T. Write a program that prints the letter representing the base that bonds with the base b.\n\nConstraints\n\nb is one of the letters A, C, G and T.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nb\n\nOutput\n\nPrint the letter representing the base that bonds with the base b.\n\nSample Input 1\n\nA\n\nSample Output 1\n\nT\n\nSample Input 2\n\nG\n\nSample Output 2\n\nC", "sample_input": "A\n"}, "reference_outputs": ["T\n"], "source_document_id": "p03085", "source_text": "Score : 100 points\n\nProblem Statement\n\nOn the Planet AtCoder, there are four types of bases: A, C, G and T. A bonds with T, and C bonds with G.\n\nYou are given a letter b as input, which is A, C, G or T. Write a program that prints the letter representing the base that bonds with the base b.\n\nConstraints\n\nb is one of the letters A, C, G and T.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nb\n\nOutput\n\nPrint the letter representing the base that bonds with the base b.\n\nSample Input 1\n\nA\n\nSample Output 1\n\nT\n\nSample Input 2\n\nG\n\nSample Output 2\n\nC", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 125, "cpu_time_ms": 95, "memory_kb": 8164}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s217383004", "group_id": "codeNet:p03085", "input_text": "(format t \"~A\" (case (read) ('a \"T\") ('t \"A\") ('c \"G\") ('g \"C\")))", "language": "Lisp", "metadata": {"date": 1553458396, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03085.html", "problem_id": "p03085", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03085/input.txt", "sample_output_relpath": "derived/input_output/data/p03085/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03085/Lisp/s217383004.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s217383004", "user_id": "u007403111"}, "prompt_components": {"gold_output": "T\n", "input_to_evaluate": "(format t \"~A\" (case (read) ('a \"T\") ('t \"A\") ('c \"G\") ('g \"C\")))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nOn the Planet AtCoder, there are four types of bases: A, C, G and T. A bonds with T, and C bonds with G.\n\nYou are given a letter b as input, which is A, C, G or T. Write a program that prints the letter representing the base that bonds with the base b.\n\nConstraints\n\nb is one of the letters A, C, G and T.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nb\n\nOutput\n\nPrint the letter representing the base that bonds with the base b.\n\nSample Input 1\n\nA\n\nSample Output 1\n\nT\n\nSample Input 2\n\nG\n\nSample Output 2\n\nC", "sample_input": "A\n"}, "reference_outputs": ["T\n"], "source_document_id": "p03085", "source_text": "Score : 100 points\n\nProblem Statement\n\nOn the Planet AtCoder, there are four types of bases: A, C, G and T. A bonds with T, and C bonds with G.\n\nYou are given a letter b as input, which is A, C, G or T. Write a program that prints the letter representing the base that bonds with the base b.\n\nConstraints\n\nb is one of the letters A, C, G and T.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nb\n\nOutput\n\nPrint the letter representing the base that bonds with the base b.\n\nSample Input 1\n\nA\n\nSample Output 1\n\nT\n\nSample Input 2\n\nG\n\nSample Output 2\n\nC", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 65, "cpu_time_ms": 130, "memory_kb": 8036}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s133760489", "group_id": "codeNet:p03086", "input_text": "(let* ((lst (concatenate 'list (read-line)))\n (k '()))\n (loop :for a :from 0 :upto (1- (length lst) ) :do\n (loop :for b :from a :upto (- (1- (length lst) ) a)\n :do(let* ((n (nth b lst)))\n (cond ((char= n #\\A) t)\n ((char= n #\\T) t)\n ((char= n #\\C) t)\n ((char= n #\\G) t)\n (t (progn (push (- b a) k) (loop-finish)))))))\n (princ (reduce #'max k)))\n", "language": "Lisp", "metadata": {"date": 1553460172, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03086.html", "problem_id": "p03086", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03086/input.txt", "sample_output_relpath": "derived/input_output/data/p03086/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03086/Lisp/s133760489.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s133760489", "user_id": "u610490393"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let* ((lst (concatenate 'list (read-line)))\n (k '()))\n (loop :for a :from 0 :upto (1- (length lst) ) :do\n (loop :for b :from a :upto (- (1- (length lst) ) a)\n :do(let* ((n (nth b lst)))\n (cond ((char= n #\\A) t)\n ((char= n #\\T) t)\n ((char= n #\\C) t)\n ((char= n #\\G) t)\n (t (progn (push (- b a) k) (loop-finish)))))))\n (princ (reduce #'max k)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.\n\nHere, a ACGT string is a string that contains no characters other than A, C, G and T.\n\nNotes\n\nA substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.\n\nFor example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and (the empty string), but not AC.\n\nConstraints\n\nS is a string of length between 1 and 10 (inclusive).\n\nEach character in S is an uppercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the length of the longest ACGT string that is a substring of S.\n\nSample Input 1\n\nATCODER\n\nSample Output 1\n\n3\n\nAmong the ACGT strings that are substrings of ATCODER, the longest one is ATC.\n\nSample Input 2\n\nHATAGAYA\n\nSample Output 2\n\n5\n\nAmong the ACGT strings that are substrings of HATAGAYA, the longest one is ATAGA.\n\nSample Input 3\n\nSHINJUKU\n\nSample Output 3\n\n0\n\nAmong the ACGT strings that are substrings of SHINJUKU, the longest one is (the empty string).", "sample_input": "ATCODER\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03086", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.\n\nHere, a ACGT string is a string that contains no characters other than A, C, G and T.\n\nNotes\n\nA substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.\n\nFor example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and (the empty string), but not AC.\n\nConstraints\n\nS is a string of length between 1 and 10 (inclusive).\n\nEach character in S is an uppercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the length of the longest ACGT string that is a substring of S.\n\nSample Input 1\n\nATCODER\n\nSample Output 1\n\n3\n\nAmong the ACGT strings that are substrings of ATCODER, the longest one is ATC.\n\nSample Input 2\n\nHATAGAYA\n\nSample Output 2\n\n5\n\nAmong the ACGT strings that are substrings of HATAGAYA, the longest one is ATAGA.\n\nSample Input 3\n\nSHINJUKU\n\nSample Output 3\n\n0\n\nAmong the ACGT strings that are substrings of SHINJUKU, the longest one is (the empty string).", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 458, "cpu_time_ms": 480, "memory_kb": 12000}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s856702222", "group_id": "codeNet:p03087", "input_text": "(let* ((n (read))\n (m (read))\n (str (read-line))\n (lst (loop :repeat m :collect (cons (read) (read)))))\n (defun f (p q)\n (let* ((k (search \"AC\" p :start2 q)))\n (if k (f p (1+ k)) q)))\n (map nil (lambda (a)\n (print (floor (f (subseq str (1- (car a)) (cdr a)) 0) 2))) lst))", "language": "Lisp", "metadata": {"date": 1559316052, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03087.html", "problem_id": "p03087", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03087/input.txt", "sample_output_relpath": "derived/input_output/data/p03087/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03087/Lisp/s856702222.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s856702222", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2\n0\n3\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (str (read-line))\n (lst (loop :repeat m :collect (cons (read) (read)))))\n (defun f (p q)\n (let* ((k (search \"AC\" p :start2 q)))\n (if k (f p (1+ k)) q)))\n (map nil (lambda (a)\n (print (floor (f (subseq str (1- (car a)) (cdr a)) 0) 2))) lst))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given a string S of length N consisting of A, C, G and T. Answer the following Q queries:\n\nQuery i (1 \\leq i \\leq Q): You will be given integers l_i and r_i (1 \\leq l_i < r_i \\leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does AC occurs as a substring?\n\nNotes\n\nA substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.\n\nFor example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and (the empty string), but not AC.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq Q \\leq 10^5\n\nS is a string of length N.\n\nEach character in S is A, C, G or T.\n\n1 \\leq l_i < r_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nS\nl_1 r_1\n:\nl_Q r_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the answer to the i-th query.\n\nSample Input 1\n\n8 3\nACACTACG\n3 7\n2 3\n1 8\n\nSample Output 1\n\n2\n0\n3\n\nQuery 1: the substring of S starting at index 3 and ending at index 7 is ACTAC. In this string, AC occurs twice as a substring.\n\nQuery 2: the substring of S starting at index 2 and ending at index 3 is CA. In this string, AC occurs zero times as a substring.\n\nQuery 3: the substring of S starting at index 1 and ending at index 8 is ACACTACG. In this string, AC occurs three times as a substring.", "sample_input": "8 3\nACACTACG\n3 7\n2 3\n1 8\n"}, "reference_outputs": ["2\n0\n3\n"], "source_document_id": "p03087", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given a string S of length N consisting of A, C, G and T. Answer the following Q queries:\n\nQuery i (1 \\leq i \\leq Q): You will be given integers l_i and r_i (1 \\leq l_i < r_i \\leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does AC occurs as a substring?\n\nNotes\n\nA substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.\n\nFor example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and (the empty string), but not AC.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq Q \\leq 10^5\n\nS is a string of length N.\n\nEach character in S is A, C, G or T.\n\n1 \\leq l_i < r_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nS\nl_1 r_1\n:\nl_Q r_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the answer to the i-th query.\n\nSample Input 1\n\n8 3\nACACTACG\n3 7\n2 3\n1 8\n\nSample Output 1\n\n2\n0\n3\n\nQuery 1: the substring of S starting at index 3 and ending at index 7 is ACTAC. In this string, AC occurs twice as a substring.\n\nQuery 2: the substring of S starting at index 2 and ending at index 3 is CA. In this string, AC occurs zero times as a substring.\n\nQuery 3: the substring of S starting at index 1 and ending at index 8 is ACACTACG. In this string, AC occurs three times as a substring.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 311, "cpu_time_ms": 2105, "memory_kb": 70084}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s714024756", "group_id": "codeNet:p03087", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #.(char-code #\\Newline)))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,terminate-char))\n (return (values ,buffer ,idx))))))\n\n(defmacro split-ints-bind (vars string &body body)\n (let ((position (gensym))\n (s (gensym)))\n (labels ((expand (vars &optional init-pos)\n (if (null vars)\n body\n `((multiple-value-bind (,(car vars) ,position)\n (parse-integer ,s :start ,(or init-pos position)\n :junk-allowed t)\n ,@(when (null (cdr vars)) `((declare (ignore ,position))))\n ,@(expand (cdr vars)))))))\n `(let ((,s ,string))\n (declare (string ,s))\n ,@(expand vars 0)))))\n\n(declaim (inline read-line-into))\n(defun read-line-into (buffer-string &key (in *standard-input*) (terminate-char #\\Space))\n (declare (simple-base-string buffer-string))\n (loop for c of-type base-char =\n #-swank (code-char (read-byte in nil #.(char-code #\\Newline)))\n #+swank (read-char in nil #\\Newline)\n for idx from 0\n until (char= c #\\Newline)\n do (setf (schar buffer-string idx) c)\n finally (when (< idx (length buffer-string))\n (setf (schar buffer-string idx) terminate-char))\n (return (values buffer-string idx))))\n\n(defmacro dbg (&rest forms)\n #+swank\n `(progn\n ,@(mapcar (lambda (form) `(format *error-output* \"~A => ~A~%\" ',form ,form))\n forms))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (q (read))\n (buf (make-string n :element-type 'base-char))\n (cumul (make-array (1+ n) :element-type 'uint32 :initial-element 0))\n (out (make-string-output-stream :element-type 'base-char)))\n (declare (uint32 n q))\n (read-line-into buf)\n (dotimes (i (- n 1))\n (when (and (char= #\\A (schar buf i))\n (char= #\\C (schar buf (+ i 1))))\n (setf (aref cumul (+ i 2)) 1)))\n (loop for i from 1 to n\n do (incf (aref cumul i) (aref cumul (- i 1))))\n (dotimes (_ q (write-string (get-output-stream-string out)))\n (split-ints-bind (l r) (buffered-read-line 13)\n (println (- (aref cumul r) (aref cumul l)) out)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1553536668, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03087.html", "problem_id": "p03087", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03087/input.txt", "sample_output_relpath": "derived/input_output/data/p03087/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03087/Lisp/s714024756.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s714024756", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n0\n3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #.(char-code #\\Newline)))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,terminate-char))\n (return (values ,buffer ,idx))))))\n\n(defmacro split-ints-bind (vars string &body body)\n (let ((position (gensym))\n (s (gensym)))\n (labels ((expand (vars &optional init-pos)\n (if (null vars)\n body\n `((multiple-value-bind (,(car vars) ,position)\n (parse-integer ,s :start ,(or init-pos position)\n :junk-allowed t)\n ,@(when (null (cdr vars)) `((declare (ignore ,position))))\n ,@(expand (cdr vars)))))))\n `(let ((,s ,string))\n (declare (string ,s))\n ,@(expand vars 0)))))\n\n(declaim (inline read-line-into))\n(defun read-line-into (buffer-string &key (in *standard-input*) (terminate-char #\\Space))\n (declare (simple-base-string buffer-string))\n (loop for c of-type base-char =\n #-swank (code-char (read-byte in nil #.(char-code #\\Newline)))\n #+swank (read-char in nil #\\Newline)\n for idx from 0\n until (char= c #\\Newline)\n do (setf (schar buffer-string idx) c)\n finally (when (< idx (length buffer-string))\n (setf (schar buffer-string idx) terminate-char))\n (return (values buffer-string idx))))\n\n(defmacro dbg (&rest forms)\n #+swank\n `(progn\n ,@(mapcar (lambda (form) `(format *error-output* \"~A => ~A~%\" ',form ,form))\n forms))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (q (read))\n (buf (make-string n :element-type 'base-char))\n (cumul (make-array (1+ n) :element-type 'uint32 :initial-element 0))\n (out (make-string-output-stream :element-type 'base-char)))\n (declare (uint32 n q))\n (read-line-into buf)\n (dotimes (i (- n 1))\n (when (and (char= #\\A (schar buf i))\n (char= #\\C (schar buf (+ i 1))))\n (setf (aref cumul (+ i 2)) 1)))\n (loop for i from 1 to n\n do (incf (aref cumul i) (aref cumul (- i 1))))\n (dotimes (_ q (write-string (get-output-stream-string out)))\n (split-ints-bind (l r) (buffered-read-line 13)\n (println (- (aref cumul r) (aref cumul l)) out)))))\n\n#-swank(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given a string S of length N consisting of A, C, G and T. Answer the following Q queries:\n\nQuery i (1 \\leq i \\leq Q): You will be given integers l_i and r_i (1 \\leq l_i < r_i \\leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does AC occurs as a substring?\n\nNotes\n\nA substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.\n\nFor example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and (the empty string), but not AC.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq Q \\leq 10^5\n\nS is a string of length N.\n\nEach character in S is A, C, G or T.\n\n1 \\leq l_i < r_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nS\nl_1 r_1\n:\nl_Q r_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the answer to the i-th query.\n\nSample Input 1\n\n8 3\nACACTACG\n3 7\n2 3\n1 8\n\nSample Output 1\n\n2\n0\n3\n\nQuery 1: the substring of S starting at index 3 and ending at index 7 is ACTAC. In this string, AC occurs twice as a substring.\n\nQuery 2: the substring of S starting at index 2 and ending at index 3 is CA. In this string, AC occurs zero times as a substring.\n\nQuery 3: the substring of S starting at index 1 and ending at index 8 is ACACTACG. In this string, AC occurs three times as a substring.", "sample_input": "8 3\nACACTACG\n3 7\n2 3\n1 8\n"}, "reference_outputs": ["2\n0\n3\n"], "source_document_id": "p03087", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given a string S of length N consisting of A, C, G and T. Answer the following Q queries:\n\nQuery i (1 \\leq i \\leq Q): You will be given integers l_i and r_i (1 \\leq l_i < r_i \\leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does AC occurs as a substring?\n\nNotes\n\nA substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.\n\nFor example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and (the empty string), but not AC.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq Q \\leq 10^5\n\nS is a string of length N.\n\nEach character in S is A, C, G or T.\n\n1 \\leq l_i < r_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nS\nl_1 r_1\n:\nl_Q r_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the answer to the i-th query.\n\nSample Input 1\n\n8 3\nACACTACG\n3 7\n2 3\n1 8\n\nSample Output 1\n\n2\n0\n3\n\nQuery 1: the substring of S starting at index 3 and ending at index 7 is ACTAC. In this string, AC occurs twice as a substring.\n\nQuery 2: the substring of S starting at index 2 and ending at index 3 is CA. In this string, AC occurs zero times as a substring.\n\nQuery 3: the substring of S starting at index 1 and ending at index 8 is ACACTACG. In this string, AC occurs three times as a substring.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4008, "cpu_time_ms": 169, "memory_kb": 22240}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s191028595", "group_id": "codeNet:p03087", "input_text": "(defun calc (s left right)\n (let ((count 0)\n (current (- left 1)))\n (dotimes (n (+ 1 (- right left)))\n ;; (format t \"Current: ~A Left: ~A Right: ~A~%\" current left right)\n (when (>= (+ current 1) right)\n (return-from calc count))\n (when (equal (nth current s) #\\A)\n (when (equal (nth (+ current 1) s) #\\C)\n (incf count)\n (incf current)))\n (incf current))\n count))\n\n(defun main ()\n (let ((N (read))\n (Q (read))\n (S (concatenate 'list (read-line)))\n (result (list nil)))\n (declare (ignore N))\n (dotimes (n Q)\n (push (calc S (read) (read)) result))\n (setq result (cdr (reverse result)))\n (dolist (n result)\n (print n))))\n\n(main)", "language": "Lisp", "metadata": {"date": 1553510077, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03087.html", "problem_id": "p03087", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03087/input.txt", "sample_output_relpath": "derived/input_output/data/p03087/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03087/Lisp/s191028595.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s191028595", "user_id": "u631655863"}, "prompt_components": {"gold_output": "2\n0\n3\n", "input_to_evaluate": "(defun calc (s left right)\n (let ((count 0)\n (current (- left 1)))\n (dotimes (n (+ 1 (- right left)))\n ;; (format t \"Current: ~A Left: ~A Right: ~A~%\" current left right)\n (when (>= (+ current 1) right)\n (return-from calc count))\n (when (equal (nth current s) #\\A)\n (when (equal (nth (+ current 1) s) #\\C)\n (incf count)\n (incf current)))\n (incf current))\n count))\n\n(defun main ()\n (let ((N (read))\n (Q (read))\n (S (concatenate 'list (read-line)))\n (result (list nil)))\n (declare (ignore N))\n (dotimes (n Q)\n (push (calc S (read) (read)) result))\n (setq result (cdr (reverse result)))\n (dolist (n result)\n (print n))))\n\n(main)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given a string S of length N consisting of A, C, G and T. Answer the following Q queries:\n\nQuery i (1 \\leq i \\leq Q): You will be given integers l_i and r_i (1 \\leq l_i < r_i \\leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does AC occurs as a substring?\n\nNotes\n\nA substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.\n\nFor example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and (the empty string), but not AC.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq Q \\leq 10^5\n\nS is a string of length N.\n\nEach character in S is A, C, G or T.\n\n1 \\leq l_i < r_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nS\nl_1 r_1\n:\nl_Q r_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the answer to the i-th query.\n\nSample Input 1\n\n8 3\nACACTACG\n3 7\n2 3\n1 8\n\nSample Output 1\n\n2\n0\n3\n\nQuery 1: the substring of S starting at index 3 and ending at index 7 is ACTAC. In this string, AC occurs twice as a substring.\n\nQuery 2: the substring of S starting at index 2 and ending at index 3 is CA. In this string, AC occurs zero times as a substring.\n\nQuery 3: the substring of S starting at index 1 and ending at index 8 is ACACTACG. In this string, AC occurs three times as a substring.", "sample_input": "8 3\nACACTACG\n3 7\n2 3\n1 8\n"}, "reference_outputs": ["2\n0\n3\n"], "source_document_id": "p03087", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given a string S of length N consisting of A, C, G and T. Answer the following Q queries:\n\nQuery i (1 \\leq i \\leq Q): You will be given integers l_i and r_i (1 \\leq l_i < r_i \\leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does AC occurs as a substring?\n\nNotes\n\nA substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.\n\nFor example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and (the empty string), but not AC.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq Q \\leq 10^5\n\nS is a string of length N.\n\nEach character in S is A, C, G or T.\n\n1 \\leq l_i < r_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nS\nl_1 r_1\n:\nl_Q r_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the answer to the i-th query.\n\nSample Input 1\n\n8 3\nACACTACG\n3 7\n2 3\n1 8\n\nSample Output 1\n\n2\n0\n3\n\nQuery 1: the substring of S starting at index 3 and ending at index 7 is ACTAC. In this string, AC occurs twice as a substring.\n\nQuery 2: the substring of S starting at index 2 and ending at index 3 is CA. In this string, AC occurs zero times as a substring.\n\nQuery 3: the substring of S starting at index 1 and ending at index 8 is ACACTACG. In this string, AC occurs three times as a substring.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 741, "cpu_time_ms": 2104, "memory_kb": 8552}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s757359986", "group_id": "codeNet:p03089", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (let* ((n (read))\n (bs (make-array n :element-type 'uint7))\n (marked (make-array n :element-type 'boolean :initial-element nil))\n (cumul (make-array n :element-type 'uint7 :initial-element 0))\n res)\n (dotimes (i n) (setf (aref bs i) (- (read) 1)))\n (dotimes (time n)\n (loop for i from (- n 1) downto 0\n do (when (and (not (aref marked i))\n (= (aref bs i) (aref cumul i)))\n (push (aref bs i) res)\n (setf (aref marked i) t)\n (loop for j from (1+ i) below n\n do (incf (aref cumul j)))\n (return))\n finally (println -1)\n (return-from main)))\n (dolist (b (reverse res))\n (println (1+ b)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1553377225, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03089.html", "problem_id": "p03089", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03089/input.txt", "sample_output_relpath": "derived/input_output/data/p03089/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03089/Lisp/s757359986.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s757359986", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n1\n2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (let* ((n (read))\n (bs (make-array n :element-type 'uint7))\n (marked (make-array n :element-type 'boolean :initial-element nil))\n (cumul (make-array n :element-type 'uint7 :initial-element 0))\n res)\n (dotimes (i n) (setf (aref bs i) (- (read) 1)))\n (dotimes (time n)\n (loop for i from (- n 1) downto 0\n do (when (and (not (aref marked i))\n (= (aref bs i) (aref cumul i)))\n (push (aref bs i) res)\n (setf (aref marked i) t)\n (loop for j from (1+ i) below n\n do (incf (aref cumul j)))\n (return))\n finally (println -1)\n (return-from main)))\n (dolist (b (reverse res))\n (println (1+ b)))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nSnuke has an empty sequence a.\n\nHe will perform N operations on this sequence.\n\nIn the i-th operation, he chooses an integer j satisfying 1 \\leq j \\leq i, and insert j at position j in a (the beginning is position 1).\n\nYou are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n1 \\leq b_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nb_1 \\dots b_N\n\nOutput\n\nIf there is no sequence of N operations after which a would be equal to b, print -1.\nIf there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.\n\nSample Input 1\n\n3\n1 2 1\n\nSample Output 1\n\n1\n1\n2\n\nIn this sequence of operations, the sequence a changes as follows:\n\nAfter the first operation: (1)\n\nAfter the second operation: (1,1)\n\nAfter the third operation: (1,2,1)\n\nSample Input 2\n\n2\n2 2\n\nSample Output 2\n\n-1\n\n2 cannot be inserted at the beginning of the sequence, so this is impossible.\n\nSample Input 3\n\n9\n1 1 1 2 2 1 2 3 2\n\nSample Output 3\n\n1\n2\n2\n3\n1\n2\n2\n1\n1", "sample_input": "3\n1 2 1\n"}, "reference_outputs": ["1\n1\n2\n"], "source_document_id": "p03089", "source_text": "Score : 400 points\n\nProblem Statement\n\nSnuke has an empty sequence a.\n\nHe will perform N operations on this sequence.\n\nIn the i-th operation, he chooses an integer j satisfying 1 \\leq j \\leq i, and insert j at position j in a (the beginning is position 1).\n\nYou are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n1 \\leq b_i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nb_1 \\dots b_N\n\nOutput\n\nIf there is no sequence of N operations after which a would be equal to b, print -1.\nIf there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.\n\nSample Input 1\n\n3\n1 2 1\n\nSample Output 1\n\n1\n1\n2\n\nIn this sequence of operations, the sequence a changes as follows:\n\nAfter the first operation: (1)\n\nAfter the second operation: (1,1)\n\nAfter the third operation: (1,2,1)\n\nSample Input 2\n\n2\n2 2\n\nSample Output 2\n\n-1\n\n2 cannot be inserted at the beginning of the sequence, so this is impossible.\n\nSample Input 3\n\n9\n1 1 1 2 2 1 2 3 2\n\nSample Output 3\n\n1\n2\n2\n3\n1\n2\n2\n1\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1738, "cpu_time_ms": 463, "memory_kb": 21472}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s122671831", "group_id": "codeNet:p03091", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Queue with singly linked list\n;;;\n\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type list))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Removes and returns the element at the front of QUEUE. Returns NIL if QUEUE\nis empty.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline queue-peek))\n(defun queue-peek (queue)\n (car (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n;; 辺素なオイラー閉路を一点以上の点でくっつけるとオイラー閉路だから、オイラー閉路を1つ見つけて取り除いたときに、2つ以上のcomponentが残っていればOK。1つでもさらにオイラー閉路を取り除ければOK\n;; けっきょく最短の単純閉路(=最短のサーキット)をどこかの点で見つけて、取り除く、ではだめ?\n\n(defun find-cycle (graph e1 e2)\n (let* ((n (length graph))\n (dists (make-array n :element-type 'uint32 :initial-element #xffffffff))\n (paths (make-array n :element-type 'list :initial-element nil))\n (que (make-queue)))\n ;; #>graph\n (dbg e1 e2)\n (enqueue e1 que)\n (setf (aref dists e1) 0)\n (push e1 (aref paths e1))\n (loop until (queue-empty-p que)\n for v = (dequeue que)\n do (dolist (next (aref graph v))\n (when (and (= #xffffffff (aref dists next))\n (not (and (= e1 v) (= e2 next))))\n (enqueue next que)\n (setf (aref paths next)\n (cons next (aref paths v)))\n (setf (aref dists next)\n (+ (aref dists v) 1)))))\n (cons e1 (aref paths e2))))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (degs (make-array n :element-type 'uint31 :initial-element 0)))\n (labels ((no () (write-line \"No\") (return-from main)))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))\n (incf (aref degs a))\n (incf (aref degs b))))\n (unless (loop for x across degs\n always (evenp x))\n (no))\n (labels ((frob ()\n (let ((e1 (position nil graph :test-not #'eq)))\n #>e1\n (unless e1 (no))\n (let ((path (find-cycle graph e1 (car (aref graph e1))))\n (table (make-hash-table :test #'equal)))\n #>path\n (loop for (u v) on path\n while v\n do (setf (gethash (cons u v) table) t\n (gethash (cons v u) table) t))\n (dotimes (i n)\n (setf (aref graph i)\n (loop for j in (aref graph i)\n unless (gethash (cons i j) table)\n collect j)))\n #>graph\n (dotimes (i n)\n (dolist (j (aref graph i))\n (when (< i j)\n (format t \"~D ~D~%\" i j))))\n (unless (find nil graph :test-not #'eq)\n (no))))))\n (frob)\n (frob)\n (write-line \"Yes\")))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7 9\n1 2\n1 3\n2 3\n1 4\n1 5\n4 5\n1 6\n1 7\n6 7\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1 2\n2 3\n3 1\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"18 27\n17 7\n12 15\n18 17\n13 18\n13 6\n5 7\n7 1\n14 5\n15 11\n7 6\n1 9\n5 4\n18 16\n4 6\n7 2\n7 11\n6 3\n12 14\n5 2\n10 5\n7 8\n10 15\n3 15\n9 8\n7 15\n5 16\n18 15\n\"\n \"Yes\n\")))\n", "language": "Lisp", "metadata": {"date": 1589347017, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03091.html", "problem_id": "p03091", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03091/input.txt", "sample_output_relpath": "derived/input_output/data/p03091/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03091/Lisp/s122671831.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s122671831", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Queue with singly linked list\n;;;\n\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type list))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Removes and returns the element at the front of QUEUE. Returns NIL if QUEUE\nis empty.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline queue-peek))\n(defun queue-peek (queue)\n (car (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n;; 辺素なオイラー閉路を一点以上の点でくっつけるとオイラー閉路だから、オイラー閉路を1つ見つけて取り除いたときに、2つ以上のcomponentが残っていればOK。1つでもさらにオイラー閉路を取り除ければOK\n;; けっきょく最短の単純閉路(=最短のサーキット)をどこかの点で見つけて、取り除く、ではだめ?\n\n(defun find-cycle (graph e1 e2)\n (let* ((n (length graph))\n (dists (make-array n :element-type 'uint32 :initial-element #xffffffff))\n (paths (make-array n :element-type 'list :initial-element nil))\n (que (make-queue)))\n ;; #>graph\n (dbg e1 e2)\n (enqueue e1 que)\n (setf (aref dists e1) 0)\n (push e1 (aref paths e1))\n (loop until (queue-empty-p que)\n for v = (dequeue que)\n do (dolist (next (aref graph v))\n (when (and (= #xffffffff (aref dists next))\n (not (and (= e1 v) (= e2 next))))\n (enqueue next que)\n (setf (aref paths next)\n (cons next (aref paths v)))\n (setf (aref dists next)\n (+ (aref dists v) 1)))))\n (cons e1 (aref paths e2))))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (degs (make-array n :element-type 'uint31 :initial-element 0)))\n (labels ((no () (write-line \"No\") (return-from main)))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))\n (incf (aref degs a))\n (incf (aref degs b))))\n (unless (loop for x across degs\n always (evenp x))\n (no))\n (labels ((frob ()\n (let ((e1 (position nil graph :test-not #'eq)))\n #>e1\n (unless e1 (no))\n (let ((path (find-cycle graph e1 (car (aref graph e1))))\n (table (make-hash-table :test #'equal)))\n #>path\n (loop for (u v) on path\n while v\n do (setf (gethash (cons u v) table) t\n (gethash (cons v u) table) t))\n (dotimes (i n)\n (setf (aref graph i)\n (loop for j in (aref graph i)\n unless (gethash (cons i j) table)\n collect j)))\n #>graph\n (dotimes (i n)\n (dolist (j (aref graph i))\n (when (< i j)\n (format t \"~D ~D~%\" i j))))\n (unless (find nil graph :test-not #'eq)\n (no))))))\n (frob)\n (frob)\n (write-line \"Yes\")))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7 9\n1 2\n1 3\n2 3\n1 4\n1 5\n4 5\n1 6\n1 7\n6 7\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1 2\n2 3\n3 1\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"18 27\n17 7\n12 15\n18 17\n13 18\n13 6\n5 7\n7 1\n14 5\n15 11\n7 6\n1 9\n5 4\n18 16\n4 6\n7 2\n7 11\n6 3\n12 14\n5 2\n10 5\n7 8\n10 15\n3 15\n9 8\n7 15\n5 16\n18 15\n\"\n \"Yes\n\")))\n", "problem_context": "Score : 800 points\n\nProblem Statement\n\nYou are given a simple connected undirected graph consisting of N vertices and M edges.\nThe vertices are numbered 1 to N, and the edges are numbered 1 to M.\n\nEdge i connects Vertex a_i and b_i bidirectionally.\n\nDetermine if three circuits (see Notes) can be formed using each of the edges exactly once.\n\nNotes\n\nA circuit is a cycle allowing repetitions of vertices but not edges.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N,M \\leq 10^{5}\n\n1 \\leq a_i, b_i \\leq N\n\nThe given graph is simple and connected.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\n:\na_M b_M\n\nOutput\n\nIf three circuits can be formed using each of the edges exactly once, print Yes; if they cannot, print No.\n\nSample Input 1\n\n7 9\n1 2\n1 3\n2 3\n1 4\n1 5\n4 5\n1 6\n1 7\n6 7\n\nSample Output 1\n\nYes\n\nThree circuits can be formed using each of the edges exactly once, as follows:\n\nSample Input 2\n\n3 3\n1 2\n2 3\n3 1\n\nSample Output 2\n\nNo\n\nThree circuits are needed.\n\nSample Input 3\n\n18 27\n17 7\n12 15\n18 17\n13 18\n13 6\n5 7\n7 1\n14 5\n15 11\n7 6\n1 9\n5 4\n18 16\n4 6\n7 2\n7 11\n6 3\n12 14\n5 2\n10 5\n7 8\n10 15\n3 15\n9 8\n7 15\n5 16\n18 15\n\nSample Output 3\n\nYes", "sample_input": "7 9\n1 2\n1 3\n2 3\n1 4\n1 5\n4 5\n1 6\n1 7\n6 7\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03091", "source_text": "Score : 800 points\n\nProblem Statement\n\nYou are given a simple connected undirected graph consisting of N vertices and M edges.\nThe vertices are numbered 1 to N, and the edges are numbered 1 to M.\n\nEdge i connects Vertex a_i and b_i bidirectionally.\n\nDetermine if three circuits (see Notes) can be formed using each of the edges exactly once.\n\nNotes\n\nA circuit is a cycle allowing repetitions of vertices but not edges.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N,M \\leq 10^{5}\n\n1 \\leq a_i, b_i \\leq N\n\nThe given graph is simple and connected.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\n:\na_M b_M\n\nOutput\n\nIf three circuits can be formed using each of the edges exactly once, print Yes; if they cannot, print No.\n\nSample Input 1\n\n7 9\n1 2\n1 3\n2 3\n1 4\n1 5\n4 5\n1 6\n1 7\n6 7\n\nSample Output 1\n\nYes\n\nThree circuits can be formed using each of the edges exactly once, as follows:\n\nSample Input 2\n\n3 3\n1 2\n2 3\n3 1\n\nSample Output 2\n\nNo\n\nThree circuits are needed.\n\nSample Input 3\n\n18 27\n17 7\n12 15\n18 17\n13 18\n13 6\n5 7\n7 1\n14 5\n15 11\n7 6\n1 9\n5 4\n18 16\n4 6\n7 2\n7 11\n6 3\n12 14\n5 2\n10 5\n7 8\n10 15\n3 15\n9 8\n7 15\n5 16\n18 15\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9057, "cpu_time_ms": 800, "memory_kb": 70880}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s590561369", "group_id": "codeNet:p03092", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;;;\n;;; Max flow (Dinic's algorithm)\n;;;\n\n(defconstant +graph-inf-distance+ #xffffffff)\n\n(define-condition max-flow-overflow (error)\n ((graph :initarg :graph :reader max-flow-overflow-graph))\n (:report\n (lambda (condition stream)\n (format stream \"MOST-POSITIVE-FIXNUM or more units can flow on graph ~W.\"\n (max-flow-overflow-graph condition)))))\n\n(declaim (inline edge-to edge-capacity edge-reversed))\n(defun edge-to (edge)\n (the (integer 0 #.most-positive-fixnum) (car edge)))\n(defun edge-capacity (edge)\n (the (integer 0 #.most-positive-fixnum) (cadr edge)))\n(defun edge-reversed (edge)\n (the list (cddr edge)))\n\n(defun add-edge (graph from-idx to-idx capacity &key bidirectional)\n \"FROM-IDX, TO-IDX := index of vertex\nGRAPH := vector of lists of all the edges that goes from each vertex\n\nIf BIDIRECTIONAL is true, PUSH-EDGE adds the reversed edge of the same\ncapacity in addition.\"\n (declare (optimize (speed 3))\n ((simple-array list (*)) graph))\n (let* ((dep (list* to-idx capacity nil))\n (ret (list* from-idx\n (if bidirectional capacity 0)\n dep)))\n (setf (cddr dep) ret)\n (push dep (aref graph from-idx))\n (push ret (aref graph to-idx))))\n\n(defun %fill-dist-table (graph src dist-table queue)\n \"Does BFS and sets DIST-TABLE to the distance between SRC and each vertex of\nGRAPH, where an edge of zero capacity is regarded as disconnected.\"\n (declare (optimize (speed 3) (safety 0))\n ((integer 0 #.most-positive-fixnum) src)\n ((simple-array list (*)) graph)\n ((simple-array (unsigned-byte 32) (*)) dist-table queue))\n (let* ((q-front 0)\n (q-end 0))\n (declare ((integer 0 #.most-positive-fixnum) q-front q-end))\n (labels ((enqueue (obj)\n (setf (aref queue q-end) obj)\n (incf q-end))\n (dequeue ()\n (prog1 (aref queue q-front)\n (incf q-front))))\n (declare (inline enqueue dequeue))\n (fill dist-table +graph-inf-distance+)\n (setf (aref dist-table src) 0)\n (enqueue src)\n (loop until (= q-front q-end)\n for vertex = (dequeue)\n do (dolist (edge (aref graph vertex))\n (let ((neighbor (edge-to edge)))\n (when (and (> (edge-capacity edge) 0)\n (= +graph-inf-distance+ (aref dist-table neighbor)))\n (setf (aref dist-table neighbor)\n (+ 1 (aref dist-table vertex)))\n (enqueue neighbor)))))))\n dist-table)\n\n(declaim (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) %find-path))\n(defun %find-path (src dest tmp-graph dist-table)\n \"Finds an augmenting path, sends the maximum flow through it, and returns the\namount of the flow.\"\n (declare (optimize (speed 3) (safety 0))\n ((integer 0 #.most-positive-fixnum) src dest)\n ((simple-array list (*)) tmp-graph)\n ((simple-array (unsigned-byte 32) (*)) dist-table))\n (labels ((dfs (v flow)\n (declare ((integer 0 #.most-positive-fixnum) v flow))\n (when (= v dest)\n (return-from dfs flow))\n (loop\n (unless (aref tmp-graph v)\n (return 0))\n (let ((edge (car (aref tmp-graph v))))\n (when (and (> (edge-capacity edge) 0)\n (< (aref dist-table v) (aref dist-table (edge-to edge))))\n (let ((result (dfs (edge-to edge) (min flow (edge-capacity edge)))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (when (> result 0)\n (decf (the uint62 (cadr edge)) result)\n (incf (the uint62 (cadr (cddr edge))) result)\n (return result)))))\n (pop (aref tmp-graph v)))))\n (dfs src most-positive-fixnum)))\n\n(declaim (ftype (function * (values (mod #.most-positive-fixnum) &optional)) max-flow!))\n(defun max-flow! (graph src dest)\n \"Destructively sends the maximum flow from SRC to DEST and returns the amount\nof the flow. This function signals MAX-FLOW-OVERFLOW error when an infinite\nflow (to be precise, >= MOST-POSITIVE-FIXNUM) is possible.\"\n (declare #+sbcl (muffle-conditions style-warning)\n ((integer 0 #.most-positive-fixnum) src dest)\n ((simple-array list (*)) graph))\n (let* ((n (length graph))\n (dist-table (make-array n :element-type '(unsigned-byte 32)))\n (queue (make-array n :element-type '(unsigned-byte 32)))\n (tmp-graph (make-array n :element-type 'list))\n (result 0))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (%fill-dist-table graph src dist-table queue)\n (when (= (aref dist-table dest) +graph-inf-distance+)\n ;; SRC and DEST are not connected on the current residual network.\n (return result))\n (dotimes (i n)\n (setf (aref tmp-graph i) (aref graph i)))\n (loop for delta = (%find-path src dest tmp-graph dist-table)\n until (zerop delta)\n do (when (>= (+ result delta) most-positive-fixnum)\n (error 'max-flow-overflow :graph graph))\n (incf result delta)))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (a (read))\n (b (read))\n (ps (make-array n :element-type 'uint31 :initial-element 0))\n (graph (make-array (+ (* 2 n) 2) :element-type 'list :initial-element nil))\n (source (* 2 n))\n (sink (+ (* 2 n) 1)))\n (dotimes (i n)\n (setf (aref ps i) (- (read) 1)))\n (dotimes (i n)\n (add-edge graph source i a)\n (add-edge graph (+ i n) sink b))\n (dotimes (i n)\n (loop for j from (+ i 1) below n\n when (> (aref ps i) (aref ps j))\n do (add-edge graph i (+ j n) most-positive-fixnum)))\n (println (max-flow! graph source sink))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 20 30\n3 1 2\n\"\n \"20\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 20 30\n4 2 3 1\n\"\n \"50\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 10 10\n1\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 1000000000 1000000000\n4 3 2 1\n\"\n \"3000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9 40 50\n5 3 4 7 6 1 2 9 8\n\"\n \"220\n\")))\n", "language": "Lisp", "metadata": {"date": 1592506189, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03092.html", "problem_id": "p03092", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03092/input.txt", "sample_output_relpath": "derived/input_output/data/p03092/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03092/Lisp/s590561369.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s590561369", "user_id": "u352600849"}, "prompt_components": {"gold_output": "20\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;;;\n;;; Max flow (Dinic's algorithm)\n;;;\n\n(defconstant +graph-inf-distance+ #xffffffff)\n\n(define-condition max-flow-overflow (error)\n ((graph :initarg :graph :reader max-flow-overflow-graph))\n (:report\n (lambda (condition stream)\n (format stream \"MOST-POSITIVE-FIXNUM or more units can flow on graph ~W.\"\n (max-flow-overflow-graph condition)))))\n\n(declaim (inline edge-to edge-capacity edge-reversed))\n(defun edge-to (edge)\n (the (integer 0 #.most-positive-fixnum) (car edge)))\n(defun edge-capacity (edge)\n (the (integer 0 #.most-positive-fixnum) (cadr edge)))\n(defun edge-reversed (edge)\n (the list (cddr edge)))\n\n(defun add-edge (graph from-idx to-idx capacity &key bidirectional)\n \"FROM-IDX, TO-IDX := index of vertex\nGRAPH := vector of lists of all the edges that goes from each vertex\n\nIf BIDIRECTIONAL is true, PUSH-EDGE adds the reversed edge of the same\ncapacity in addition.\"\n (declare (optimize (speed 3))\n ((simple-array list (*)) graph))\n (let* ((dep (list* to-idx capacity nil))\n (ret (list* from-idx\n (if bidirectional capacity 0)\n dep)))\n (setf (cddr dep) ret)\n (push dep (aref graph from-idx))\n (push ret (aref graph to-idx))))\n\n(defun %fill-dist-table (graph src dist-table queue)\n \"Does BFS and sets DIST-TABLE to the distance between SRC and each vertex of\nGRAPH, where an edge of zero capacity is regarded as disconnected.\"\n (declare (optimize (speed 3) (safety 0))\n ((integer 0 #.most-positive-fixnum) src)\n ((simple-array list (*)) graph)\n ((simple-array (unsigned-byte 32) (*)) dist-table queue))\n (let* ((q-front 0)\n (q-end 0))\n (declare ((integer 0 #.most-positive-fixnum) q-front q-end))\n (labels ((enqueue (obj)\n (setf (aref queue q-end) obj)\n (incf q-end))\n (dequeue ()\n (prog1 (aref queue q-front)\n (incf q-front))))\n (declare (inline enqueue dequeue))\n (fill dist-table +graph-inf-distance+)\n (setf (aref dist-table src) 0)\n (enqueue src)\n (loop until (= q-front q-end)\n for vertex = (dequeue)\n do (dolist (edge (aref graph vertex))\n (let ((neighbor (edge-to edge)))\n (when (and (> (edge-capacity edge) 0)\n (= +graph-inf-distance+ (aref dist-table neighbor)))\n (setf (aref dist-table neighbor)\n (+ 1 (aref dist-table vertex)))\n (enqueue neighbor)))))))\n dist-table)\n\n(declaim (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) %find-path))\n(defun %find-path (src dest tmp-graph dist-table)\n \"Finds an augmenting path, sends the maximum flow through it, and returns the\namount of the flow.\"\n (declare (optimize (speed 3) (safety 0))\n ((integer 0 #.most-positive-fixnum) src dest)\n ((simple-array list (*)) tmp-graph)\n ((simple-array (unsigned-byte 32) (*)) dist-table))\n (labels ((dfs (v flow)\n (declare ((integer 0 #.most-positive-fixnum) v flow))\n (when (= v dest)\n (return-from dfs flow))\n (loop\n (unless (aref tmp-graph v)\n (return 0))\n (let ((edge (car (aref tmp-graph v))))\n (when (and (> (edge-capacity edge) 0)\n (< (aref dist-table v) (aref dist-table (edge-to edge))))\n (let ((result (dfs (edge-to edge) (min flow (edge-capacity edge)))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (when (> result 0)\n (decf (the uint62 (cadr edge)) result)\n (incf (the uint62 (cadr (cddr edge))) result)\n (return result)))))\n (pop (aref tmp-graph v)))))\n (dfs src most-positive-fixnum)))\n\n(declaim (ftype (function * (values (mod #.most-positive-fixnum) &optional)) max-flow!))\n(defun max-flow! (graph src dest)\n \"Destructively sends the maximum flow from SRC to DEST and returns the amount\nof the flow. This function signals MAX-FLOW-OVERFLOW error when an infinite\nflow (to be precise, >= MOST-POSITIVE-FIXNUM) is possible.\"\n (declare #+sbcl (muffle-conditions style-warning)\n ((integer 0 #.most-positive-fixnum) src dest)\n ((simple-array list (*)) graph))\n (let* ((n (length graph))\n (dist-table (make-array n :element-type '(unsigned-byte 32)))\n (queue (make-array n :element-type '(unsigned-byte 32)))\n (tmp-graph (make-array n :element-type 'list))\n (result 0))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (%fill-dist-table graph src dist-table queue)\n (when (= (aref dist-table dest) +graph-inf-distance+)\n ;; SRC and DEST are not connected on the current residual network.\n (return result))\n (dotimes (i n)\n (setf (aref tmp-graph i) (aref graph i)))\n (loop for delta = (%find-path src dest tmp-graph dist-table)\n until (zerop delta)\n do (when (>= (+ result delta) most-positive-fixnum)\n (error 'max-flow-overflow :graph graph))\n (incf result delta)))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (a (read))\n (b (read))\n (ps (make-array n :element-type 'uint31 :initial-element 0))\n (graph (make-array (+ (* 2 n) 2) :element-type 'list :initial-element nil))\n (source (* 2 n))\n (sink (+ (* 2 n) 1)))\n (dotimes (i n)\n (setf (aref ps i) (- (read) 1)))\n (dotimes (i n)\n (add-edge graph source i a)\n (add-edge graph (+ i n) sink b))\n (dotimes (i n)\n (loop for j from (+ i 1) below n\n when (> (aref ps i) (aref ps j))\n do (add-edge graph i (+ j n) most-positive-fixnum)))\n (println (max-flow! graph source sink))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 20 30\n3 1 2\n\"\n \"20\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 20 30\n4 2 3 1\n\"\n \"50\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 10 10\n1\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 1000000000 1000000000\n4 3 2 1\n\"\n \"3000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9 40 50\n5 3 4 7 6 1 2 9 8\n\"\n \"220\n\")))\n", "problem_context": "Score : 1000 points\n\nProblem Statement\n\nYou are given a permutation p = (p_1, \\ldots, p_N) of \\{ 1, \\ldots, N \\}.\nYou can perform the following two kinds of operations repeatedly in any order:\n\nPay a cost A. Choose integers l and r (1 \\leq l < r \\leq N), and shift (p_l, \\ldots, p_r) to the left by one. That is, replace p_l, p_{l + 1}, \\ldots, p_{r - 1}, p_r with p_{l + 1}, p_{l + 2}, \\ldots, p_r, p_l, respectively.\n\nPay a cost B. Choose integers l and r (1 \\leq l < r \\leq N), and shift (p_l, \\ldots, p_r) to the right by one. That is, replace p_l, p_{l + 1}, \\ldots, p_{r - 1}, p_r with p_r, p_l, \\ldots, p_{r - 2}, p_{r - 1}, respectively.\n\nFind the minimum total cost required to sort p in ascending order.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 5000\n\n1 \\leq A, B \\leq 10^9\n\n(p_1 \\ldots, p_N) is a permutation of \\{ 1, \\ldots, N \\}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\np_1 \\cdots p_N\n\nOutput\n\nPrint the minimum total cost required to sort p in ascending order.\n\nSample Input 1\n\n3 20 30\n3 1 2\n\nSample Output 1\n\n20\n\nShifting (p_1, p_2, p_3) to the left by one results in p = (1, 2, 3).\n\nSample Input 2\n\n4 20 30\n4 2 3 1\n\nSample Output 2\n\n50\n\nOne possible sequence of operations is as follows:\n\nShift (p_1, p_2, p_3, p_4) to the left by one. Now we have p = (2, 3, 1, 4).\n\nShift (p_1, p_2, p_3) to the right by one. Now we have p = (1, 2, 3, 4).\n\nHere, the total cost is 20 + 30 = 50.\n\nSample Input 3\n\n1 10 10\n1\n\nSample Output 3\n\n0\n\nSample Input 4\n\n4 1000000000 1000000000\n4 3 2 1\n\nSample Output 4\n\n3000000000\n\nSample Input 5\n\n9 40 50\n5 3 4 7 6 1 2 9 8\n\nSample Output 5\n\n220", "sample_input": "3 20 30\n3 1 2\n"}, "reference_outputs": ["20\n"], "source_document_id": "p03092", "source_text": "Score : 1000 points\n\nProblem Statement\n\nYou are given a permutation p = (p_1, \\ldots, p_N) of \\{ 1, \\ldots, N \\}.\nYou can perform the following two kinds of operations repeatedly in any order:\n\nPay a cost A. Choose integers l and r (1 \\leq l < r \\leq N), and shift (p_l, \\ldots, p_r) to the left by one. That is, replace p_l, p_{l + 1}, \\ldots, p_{r - 1}, p_r with p_{l + 1}, p_{l + 2}, \\ldots, p_r, p_l, respectively.\n\nPay a cost B. Choose integers l and r (1 \\leq l < r \\leq N), and shift (p_l, \\ldots, p_r) to the right by one. That is, replace p_l, p_{l + 1}, \\ldots, p_{r - 1}, p_r with p_r, p_l, \\ldots, p_{r - 2}, p_{r - 1}, respectively.\n\nFind the minimum total cost required to sort p in ascending order.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 5000\n\n1 \\leq A, B \\leq 10^9\n\n(p_1 \\ldots, p_N) is a permutation of \\{ 1, \\ldots, N \\}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\np_1 \\cdots p_N\n\nOutput\n\nPrint the minimum total cost required to sort p in ascending order.\n\nSample Input 1\n\n3 20 30\n3 1 2\n\nSample Output 1\n\n20\n\nShifting (p_1, p_2, p_3) to the left by one results in p = (1, 2, 3).\n\nSample Input 2\n\n4 20 30\n4 2 3 1\n\nSample Output 2\n\n50\n\nOne possible sequence of operations is as follows:\n\nShift (p_1, p_2, p_3, p_4) to the left by one. Now we have p = (2, 3, 1, 4).\n\nShift (p_1, p_2, p_3) to the right by one. Now we have p = (1, 2, 3, 4).\n\nHere, the total cost is 20 + 30 = 50.\n\nSample Input 3\n\n1 10 10\n1\n\nSample Output 3\n\n0\n\nSample Input 4\n\n4 1000000000 1000000000\n4 3 2 1\n\nSample Output 4\n\n3000000000\n\nSample Input 5\n\n9 40 50\n5 3 4 7 6 1 2 9 8\n\nSample Output 5\n\n220", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9697, "cpu_time_ms": 2237, "memory_kb": 921276}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s400484507", "group_id": "codeNet:p03092", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ most-positive-fixnum)\n(defun main ()\n (let* ((n (read))\n (a (read))\n (b (read))\n (ps (make-array n :element-type 'uint31 :initial-element 0))\n (invs (make-array n :element-type 'uint31 :initial-element 0))\n (dp (make-array (list (+ n 1) (+ n 1))\n :element-type 'uint62\n :initial-element +inf+)))\n (declare (uint31 n a b))\n (dotimes (i n)\n (setf (aref invs (- (read) 1)) i))\n (setf (aref dp 0 0) 0)\n (dotimes (x (+ n 1))\n (dotimes (y (+ n 1))\n (when (< y n)\n (minf (aref dp x (+ y 1))\n (aref dp x y)))\n (when (< x n)\n (cond ((< (aref invs x) y)\n (minf (aref dp (+ x 1) y)\n (+ (aref dp x y) a)))\n ((> (aref invs x) y)\n (minf (aref dp (+ x 1) y)\n (+ (aref dp x y) b)))\n (t\n (minf (aref dp (+ x 1) (+ y 1))\n (aref dp x y)))))))\n (println (aref dp n n))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 20 30\n3 1 2\n\"\n \"20\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 20 30\n4 2 3 1\n\"\n \"50\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 10 10\n1\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 1000000000 1000000000\n4 3 2 1\n\"\n \"3000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9 40 50\n5 3 4 7 6 1 2 9 8\n\"\n \"220\n\")))\n", "language": "Lisp", "metadata": {"date": 1589931796, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03092.html", "problem_id": "p03092", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03092/input.txt", "sample_output_relpath": "derived/input_output/data/p03092/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03092/Lisp/s400484507.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s400484507", "user_id": "u352600849"}, "prompt_components": {"gold_output": "20\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ most-positive-fixnum)\n(defun main ()\n (let* ((n (read))\n (a (read))\n (b (read))\n (ps (make-array n :element-type 'uint31 :initial-element 0))\n (invs (make-array n :element-type 'uint31 :initial-element 0))\n (dp (make-array (list (+ n 1) (+ n 1))\n :element-type 'uint62\n :initial-element +inf+)))\n (declare (uint31 n a b))\n (dotimes (i n)\n (setf (aref invs (- (read) 1)) i))\n (setf (aref dp 0 0) 0)\n (dotimes (x (+ n 1))\n (dotimes (y (+ n 1))\n (when (< y n)\n (minf (aref dp x (+ y 1))\n (aref dp x y)))\n (when (< x n)\n (cond ((< (aref invs x) y)\n (minf (aref dp (+ x 1) y)\n (+ (aref dp x y) a)))\n ((> (aref invs x) y)\n (minf (aref dp (+ x 1) y)\n (+ (aref dp x y) b)))\n (t\n (minf (aref dp (+ x 1) (+ y 1))\n (aref dp x y)))))))\n (println (aref dp n n))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 20 30\n3 1 2\n\"\n \"20\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 20 30\n4 2 3 1\n\"\n \"50\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 10 10\n1\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 1000000000 1000000000\n4 3 2 1\n\"\n \"3000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9 40 50\n5 3 4 7 6 1 2 9 8\n\"\n \"220\n\")))\n", "problem_context": "Score : 1000 points\n\nProblem Statement\n\nYou are given a permutation p = (p_1, \\ldots, p_N) of \\{ 1, \\ldots, N \\}.\nYou can perform the following two kinds of operations repeatedly in any order:\n\nPay a cost A. Choose integers l and r (1 \\leq l < r \\leq N), and shift (p_l, \\ldots, p_r) to the left by one. That is, replace p_l, p_{l + 1}, \\ldots, p_{r - 1}, p_r with p_{l + 1}, p_{l + 2}, \\ldots, p_r, p_l, respectively.\n\nPay a cost B. Choose integers l and r (1 \\leq l < r \\leq N), and shift (p_l, \\ldots, p_r) to the right by one. That is, replace p_l, p_{l + 1}, \\ldots, p_{r - 1}, p_r with p_r, p_l, \\ldots, p_{r - 2}, p_{r - 1}, respectively.\n\nFind the minimum total cost required to sort p in ascending order.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 5000\n\n1 \\leq A, B \\leq 10^9\n\n(p_1 \\ldots, p_N) is a permutation of \\{ 1, \\ldots, N \\}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\np_1 \\cdots p_N\n\nOutput\n\nPrint the minimum total cost required to sort p in ascending order.\n\nSample Input 1\n\n3 20 30\n3 1 2\n\nSample Output 1\n\n20\n\nShifting (p_1, p_2, p_3) to the left by one results in p = (1, 2, 3).\n\nSample Input 2\n\n4 20 30\n4 2 3 1\n\nSample Output 2\n\n50\n\nOne possible sequence of operations is as follows:\n\nShift (p_1, p_2, p_3, p_4) to the left by one. Now we have p = (2, 3, 1, 4).\n\nShift (p_1, p_2, p_3) to the right by one. Now we have p = (1, 2, 3, 4).\n\nHere, the total cost is 20 + 30 = 50.\n\nSample Input 3\n\n1 10 10\n1\n\nSample Output 3\n\n0\n\nSample Input 4\n\n4 1000000000 1000000000\n4 3 2 1\n\nSample Output 4\n\n3000000000\n\nSample Input 5\n\n9 40 50\n5 3 4 7 6 1 2 9 8\n\nSample Output 5\n\n220", "sample_input": "3 20 30\n3 1 2\n"}, "reference_outputs": ["20\n"], "source_document_id": "p03092", "source_text": "Score : 1000 points\n\nProblem Statement\n\nYou are given a permutation p = (p_1, \\ldots, p_N) of \\{ 1, \\ldots, N \\}.\nYou can perform the following two kinds of operations repeatedly in any order:\n\nPay a cost A. Choose integers l and r (1 \\leq l < r \\leq N), and shift (p_l, \\ldots, p_r) to the left by one. That is, replace p_l, p_{l + 1}, \\ldots, p_{r - 1}, p_r with p_{l + 1}, p_{l + 2}, \\ldots, p_r, p_l, respectively.\n\nPay a cost B. Choose integers l and r (1 \\leq l < r \\leq N), and shift (p_l, \\ldots, p_r) to the right by one. That is, replace p_l, p_{l + 1}, \\ldots, p_{r - 1}, p_r with p_r, p_l, \\ldots, p_{r - 2}, p_{r - 1}, respectively.\n\nFind the minimum total cost required to sort p in ascending order.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 5000\n\n1 \\leq A, B \\leq 10^9\n\n(p_1 \\ldots, p_N) is a permutation of \\{ 1, \\ldots, N \\}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\np_1 \\cdots p_N\n\nOutput\n\nPrint the minimum total cost required to sort p in ascending order.\n\nSample Input 1\n\n3 20 30\n3 1 2\n\nSample Output 1\n\n20\n\nShifting (p_1, p_2, p_3) to the left by one results in p = (1, 2, 3).\n\nSample Input 2\n\n4 20 30\n4 2 3 1\n\nSample Output 2\n\n50\n\nOne possible sequence of operations is as follows:\n\nShift (p_1, p_2, p_3, p_4) to the left by one. Now we have p = (2, 3, 1, 4).\n\nShift (p_1, p_2, p_3) to the right by one. Now we have p = (1, 2, 3, 4).\n\nHere, the total cost is 20 + 30 = 50.\n\nSample Input 3\n\n1 10 10\n1\n\nSample Output 3\n\n0\n\nSample Input 4\n\n4 1000000000 1000000000\n4 3 2 1\n\nSample Output 4\n\n3000000000\n\nSample Input 5\n\n9 40 50\n5 3 4 7 6 1 2 9 8\n\nSample Output 5\n\n220", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5049, "cpu_time_ms": 402, "memory_kb": 215780}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s802224507", "group_id": "codeNet:p03095", "input_text": "(defun string->duplicates-removed-list (string)\n (declare (optimize (speed 3) (safety 0) (debug 0)))\n (labels ((rec (n acc)\n (if (= n -1)\n acc\n (let ((c (char string n)))\n (if (member c acc)\n (rec (1- n) acc)\n (rec (1- n) (cons c acc)))))))\n (rec (1- (length string)) nil)))\n\n(defun f (str)\n (declare (optimize (speed 3) (safety 0) (debug 0)))\n (labels ((rec (lst acc)\n (if (null lst)\n acc\n (rec (cdr lst) (* (1+ (count (car lst) str)) acc)))))\n (1- (rec (string->duplicates-removed-list str) 1))))\n\n(defparameter *n* (read))\n(defparameter *s* (read))\n\n(print (mod (f *s*) (+ 1e9 7)))\n", "language": "Lisp", "metadata": {"date": 1552771510, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03095.html", "problem_id": "p03095", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03095/input.txt", "sample_output_relpath": "derived/input_output/data/p03095/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03095/Lisp/s802224507.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s802224507", "user_id": "u956039157"}, "prompt_components": {"gold_output": "15\n", "input_to_evaluate": "(defun string->duplicates-removed-list (string)\n (declare (optimize (speed 3) (safety 0) (debug 0)))\n (labels ((rec (n acc)\n (if (= n -1)\n acc\n (let ((c (char string n)))\n (if (member c acc)\n (rec (1- n) acc)\n (rec (1- n) (cons c acc)))))))\n (rec (1- (length string)) nil)))\n\n(defun f (str)\n (declare (optimize (speed 3) (safety 0) (debug 0)))\n (labels ((rec (lst acc)\n (if (null lst)\n acc\n (rec (cdr lst) (* (1+ (count (car lst) str)) acc)))))\n (1- (rec (string->duplicates-removed-list str) 1))))\n\n(defparameter *n* (read))\n(defparameter *s* (read))\n\n(print (mod (f *s*) (+ 1e9 7)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given a string S of length N.\nAmong its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings.\n\nHere, a subsequence of a string is a concatenation of one or more characters from the string without changing the order.\n\nConstraints\n\n1 \\leq N \\leq 100000\n\nS consists of lowercase English letters.\n\n|S|=N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the number of the subsequences such that all characters are different, modulo 10^9+7.\n\nSample Input 1\n\n4\nabcd\n\nSample Output 1\n\n15\n\nSince all characters in S itself are different, all its subsequences satisfy the condition.\n\nSample Input 2\n\n3\nbaa\n\nSample Output 2\n\n5\n\nThe answer is five: b, two occurrences of a, two occurrences of ba. Note that we do not count baa, since it contains two as.\n\nSample Input 3\n\n5\nabcab\n\nSample Output 3\n\n17", "sample_input": "4\nabcd\n"}, "reference_outputs": ["15\n"], "source_document_id": "p03095", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given a string S of length N.\nAmong its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings.\n\nHere, a subsequence of a string is a concatenation of one or more characters from the string without changing the order.\n\nConstraints\n\n1 \\leq N \\leq 100000\n\nS consists of lowercase English letters.\n\n|S|=N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the number of the subsequences such that all characters are different, modulo 10^9+7.\n\nSample Input 1\n\n4\nabcd\n\nSample Output 1\n\n15\n\nSince all characters in S itself are different, all its subsequences satisfy the condition.\n\nSample Input 2\n\n3\nbaa\n\nSample Output 2\n\n5\n\nThe answer is five: b, two occurrences of a, two occurrences of ba. Note that we do not count baa, since it contains two as.\n\nSample Input 3\n\n5\nabcab\n\nSample Output 3\n\n17", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 745, "cpu_time_ms": 177, "memory_kb": 16612}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s375823092", "group_id": "codeNet:p03102", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))\n (declare (string string)\n (function key)\n ((array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop with position = 0\n for idx from offset below (length dest-vector)\n do (setf (values (aref dest-vector idx) position)\n (parse-integer string :start position :junk-allowed t))\n (setf (aref dest-vector idx) (funcall key (aref dest-vector idx)))\n finally (return dest-vector)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (c (read))\n (bs (make-array m :element-type 'int32))\n (as (make-array m :element-type 'int32)))\n (split-ints-into-vector (read-line) bs)\n (println\n (loop repeat n\n do (split-ints-into-vector (read-line) as)\n count (> (+ c\n (loop for a across as\n for b across bs\n sum (* a b)))\n 0)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1552162556, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03102.html", "problem_id": "p03102", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03102/input.txt", "sample_output_relpath": "derived/input_output/data/p03102/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03102/Lisp/s375823092.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s375823092", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))\n (declare (string string)\n (function key)\n ((array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop with position = 0\n for idx from offset below (length dest-vector)\n do (setf (values (aref dest-vector idx) position)\n (parse-integer string :start position :junk-allowed t))\n (setf (aref dest-vector idx) (funcall key (aref dest-vector idx)))\n finally (return dest-vector)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (c (read))\n (bs (make-array m :element-type 'int32))\n (as (make-array m :element-type 'int32)))\n (split-ints-into-vector (read-line) bs)\n (println\n (loop repeat n\n do (split-ints-into-vector (read-line) as)\n count (> (+ c\n (loop for a across as\n for b across bs\n sum (* a b)))\n 0)))))\n\n#-swank(main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N pieces of source code. The characteristics of the i-th code is represented by M integers A_{i1}, A_{i2}, ..., A_{iM}.\n\nAdditionally, you are given integers B_1, B_2, ..., B_M and C.\n\nThe i-th code correctly solves this problem if and only if A_{i1} B_1 + A_{i2} B_2 + ... + A_{iM} B_M + C > 0.\n\nAmong the N codes, find the number of codes that correctly solve this problem.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N, M \\leq 20\n\n-100 \\leq A_{ij} \\leq 100\n\n-100 \\leq B_i \\leq 100\n\n-100 \\leq C \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M C\nB_1 B_2 ... B_M\nA_{11} A_{12} ... A_{1M}\nA_{21} A_{22} ... A_{2M}\n\\vdots\nA_{N1} A_{N2} ... A_{NM}\n\nOutput\n\nPrint the number of codes among the given N codes that correctly solve this problem.\n\nSample Input 1\n\n2 3 -10\n1 2 3\n3 2 1\n1 2 2\n\nSample Output 1\n\n1\n\nOnly the second code correctly solves this problem, as follows:\n\nSince 3 \\times 1 + 2 \\times 2 + 1 \\times 3 + (-10) = 0 \\leq 0, the first code does not solve this problem.\n\n1 \\times 1 + 2 \\times 2 + 2 \\times 3 + (-10) = 1 > 0, the second code solves this problem.\n\nSample Input 2\n\n5 2 -4\n-2 5\n100 41\n100 40\n-3 0\n-6 -2\n18 -13\n\nSample Output 2\n\n2\n\nSample Input 3\n\n3 3 0\n100 -100 0\n0 100 100\n100 100 100\n-100 100 100\n\nSample Output 3\n\n0\n\nAll of them are Wrong Answer. Except yours.", "sample_input": "2 3 -10\n1 2 3\n3 2 1\n1 2 2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03102", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N pieces of source code. The characteristics of the i-th code is represented by M integers A_{i1}, A_{i2}, ..., A_{iM}.\n\nAdditionally, you are given integers B_1, B_2, ..., B_M and C.\n\nThe i-th code correctly solves this problem if and only if A_{i1} B_1 + A_{i2} B_2 + ... + A_{iM} B_M + C > 0.\n\nAmong the N codes, find the number of codes that correctly solve this problem.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N, M \\leq 20\n\n-100 \\leq A_{ij} \\leq 100\n\n-100 \\leq B_i \\leq 100\n\n-100 \\leq C \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M C\nB_1 B_2 ... B_M\nA_{11} A_{12} ... A_{1M}\nA_{21} A_{22} ... A_{2M}\n\\vdots\nA_{N1} A_{N2} ... A_{NM}\n\nOutput\n\nPrint the number of codes among the given N codes that correctly solve this problem.\n\nSample Input 1\n\n2 3 -10\n1 2 3\n3 2 1\n1 2 2\n\nSample Output 1\n\n1\n\nOnly the second code correctly solves this problem, as follows:\n\nSince 3 \\times 1 + 2 \\times 2 + 1 \\times 3 + (-10) = 0 \\leq 0, the first code does not solve this problem.\n\n1 \\times 1 + 2 \\times 2 + 2 \\times 3 + (-10) = 1 > 0, the second code solves this problem.\n\nSample Input 2\n\n5 2 -4\n-2 5\n100 41\n100 40\n-3 0\n-6 -2\n18 -13\n\nSample Output 2\n\n2\n\nSample Input 3\n\n3 3 0\n100 -100 0\n0 100 100\n100 100 100\n-100 100 100\n\nSample Output 3\n\n0\n\nAll of them are Wrong Answer. Except yours.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2029, "cpu_time_ms": 240, "memory_kb": 21856}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s836680026", "group_id": "codeNet:p03103", "input_text": "(let* ((n (read))\n (m (read))\n (a (make-array (list n)))\n (money 0))\n (loop for i below n do\n (setf (aref a i) (list (read) (read)))\n )\n (setf a (sort a #'< :key #'car))\n (loop for i below n while (> m 0) do\n (progn\n (if (>= (second (aref a i)) m)\n (incf money (* (car (aref a i)) m))\n (incf money (* (car (aref a i)) (second (aref a i))))\n )\n (decf m (second (aref a i)))\n )\n )\n (princ money)\n)", "language": "Lisp", "metadata": {"date": 1595860425, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03103.html", "problem_id": "p03103", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03103/input.txt", "sample_output_relpath": "derived/input_output/data/p03103/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03103/Lisp/s836680026.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s836680026", "user_id": "u136500538"}, "prompt_components": {"gold_output": "12\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (a (make-array (list n)))\n (money 0))\n (loop for i below n do\n (setf (aref a i) (list (read) (read)))\n )\n (setf a (sort a #'< :key #'car))\n (loop for i below n while (> m 0) do\n (progn\n (if (>= (second (aref a i)) m)\n (incf money (* (car (aref a i)) m))\n (incf money (* (car (aref a i)) (second (aref a i))))\n )\n (decf m (second (aref a i)))\n )\n )\n (princ money)\n)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nHearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks.\n\nThere are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each.\n\nWhat is the minimum amount of money with which he can buy M cans of energy drinks?\n\nIt is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N, M \\leq 10^5\n\n1 \\leq A_i \\leq 10^9\n\n1 \\leq B_i \\leq 10^5\n\nB_1 + ... + B_N \\geq M\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\nA_2 B_2\n\\vdots\nA_N B_N\n\nOutput\n\nPrint the minimum amount of money with which Takahashi can buy M cans of energy drinks.\n\nSample Input 1\n\n2 5\n4 9\n2 4\n\nSample Output 1\n\n12\n\nWith 12 yen, we can buy one drink at the first store and four drinks at the second store, for the total of five drinks. However, we cannot buy 5 drinks with 11 yen or less.\n\nSample Input 2\n\n4 30\n6 18\n2 5\n3 10\n7 9\n\nSample Output 2\n\n130\n\nSample Input 3\n\n1 100000\n1000000000 100000\n\nSample Output 3\n\n100000000000000\n\nThe output may not fit into a 32-bit integer type.", "sample_input": "2 5\n4 9\n2 4\n"}, "reference_outputs": ["12\n"], "source_document_id": "p03103", "source_text": "Score : 300 points\n\nProblem Statement\n\nHearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks.\n\nThere are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each.\n\nWhat is the minimum amount of money with which he can buy M cans of energy drinks?\n\nIt is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N, M \\leq 10^5\n\n1 \\leq A_i \\leq 10^9\n\n1 \\leq B_i \\leq 10^5\n\nB_1 + ... + B_N \\geq M\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\nA_2 B_2\n\\vdots\nA_N B_N\n\nOutput\n\nPrint the minimum amount of money with which Takahashi can buy M cans of energy drinks.\n\nSample Input 1\n\n2 5\n4 9\n2 4\n\nSample Output 1\n\n12\n\nWith 12 yen, we can buy one drink at the first store and four drinks at the second store, for the total of five drinks. However, we cannot buy 5 drinks with 11 yen or less.\n\nSample Input 2\n\n4 30\n6 18\n2 5\n3 10\n7 9\n\nSample Output 2\n\n130\n\nSample Input 3\n\n1 100000\n1000000000 100000\n\nSample Output 3\n\n100000000000000\n\nThe output may not fit into a 32-bit integer type.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 506, "cpu_time_ms": 261, "memory_kb": 80804}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s149873543", "group_id": "codeNet:p03106", "input_text": "(setq a(read))(setq b(read))(setq k(read))\n(loop for i from 100 downto 1 do(if(=(mod a i)(mod b i)0)(decf k))(if(= k 0)(progn(princ i)(decf k))))", "language": "Lisp", "metadata": {"date": 1551647296, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03106.html", "problem_id": "p03106", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03106/input.txt", "sample_output_relpath": "derived/input_output/data/p03106/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03106/Lisp/s149873543.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s149873543", "user_id": "u657913472"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(setq a(read))(setq b(read))(setq k(read))\n(loop for i from 100 downto 1 do(if(=(mod a i)(mod b i)0)(decf k))(if(= k 0)(progn(princ i)(decf k))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given positive integers A and B.\n\nFind the K-th largest positive integer that divides both A and B.\n\nThe input guarantees that there exists such a number.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A, B \\leq 100\n\nThe K-th largest positive integer that divides both A and B exists.\n\nK \\geq 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B K\n\nOutput\n\nPrint the K-th largest positive integer that divides both A and B.\n\nSample Input 1\n\n8 12 2\n\nSample Output 1\n\n2\n\nThree positive integers divides both 8 and 12: 1, 2 and 4.\nAmong them, the second largest is 2.\n\nSample Input 2\n\n100 50 4\n\nSample Output 2\n\n5\n\nSample Input 3\n\n1 1 1\n\nSample Output 3\n\n1", "sample_input": "8 12 2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03106", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given positive integers A and B.\n\nFind the K-th largest positive integer that divides both A and B.\n\nThe input guarantees that there exists such a number.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A, B \\leq 100\n\nThe K-th largest positive integer that divides both A and B exists.\n\nK \\geq 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B K\n\nOutput\n\nPrint the K-th largest positive integer that divides both A and B.\n\nSample Input 1\n\n8 12 2\n\nSample Output 1\n\n2\n\nThree positive integers divides both 8 and 12: 1, 2 and 4.\nAmong them, the second largest is 2.\n\nSample Input 2\n\n100 50 4\n\nSample Output 2\n\n5\n\nSample Input 3\n\n1 1 1\n\nSample Output 3\n\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 145, "cpu_time_ms": 151, "memory_kb": 16104}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s713107655", "group_id": "codeNet:p03106", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (let* ((a (read))\n (b (read))\n (k (read))\n (gcd (gcd a b)))\n (loop with c = 1\n for num from gcd downto 1\n do (when (zerop (mod gcd num))\n (when (= k c)\n (println num)\n (return-from main))\n (incf c)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1551643788, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03106.html", "problem_id": "p03106", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03106/input.txt", "sample_output_relpath": "derived/input_output/data/p03106/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03106/Lisp/s713107655.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s713107655", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (let* ((a (read))\n (b (read))\n (k (read))\n (gcd (gcd a b)))\n (loop with c = 1\n for num from gcd downto 1\n do (when (zerop (mod gcd num))\n (when (= k c)\n (println num)\n (return-from main))\n (incf c)))))\n\n#-swank(main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given positive integers A and B.\n\nFind the K-th largest positive integer that divides both A and B.\n\nThe input guarantees that there exists such a number.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A, B \\leq 100\n\nThe K-th largest positive integer that divides both A and B exists.\n\nK \\geq 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B K\n\nOutput\n\nPrint the K-th largest positive integer that divides both A and B.\n\nSample Input 1\n\n8 12 2\n\nSample Output 1\n\n2\n\nThree positive integers divides both 8 and 12: 1, 2 and 4.\nAmong them, the second largest is 2.\n\nSample Input 2\n\n100 50 4\n\nSample Output 2\n\n5\n\nSample Input 3\n\n1 1 1\n\nSample Output 3\n\n1", "sample_input": "8 12 2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03106", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given positive integers A and B.\n\nFind the K-th largest positive integer that divides both A and B.\n\nThe input guarantees that there exists such a number.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A, B \\leq 100\n\nThe K-th largest positive integer that divides both A and B exists.\n\nK \\geq 1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B K\n\nOutput\n\nPrint the K-th largest positive integer that divides both A and B.\n\nSample Input 1\n\n8 12 2\n\nSample Output 1\n\n2\n\nThree positive integers divides both 8 and 12: 1, 2 and 4.\nAmong them, the second largest is 2.\n\nSample Input 2\n\n100 50 4\n\nSample Output 2\n\n5\n\nSample Input 3\n\n1 1 1\n\nSample Output 3\n\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1257, "cpu_time_ms": 149, "memory_kb": 16100}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s978355893", "group_id": "codeNet:p03111", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (let* ((n (read))\n (a (read))\n (b (read))\n (c (read))\n (ls (make-array n :element-type 'uint15))\n (min-cost most-positive-fixnum))\n (dotimes (i n) (setf (aref ls i) (read)))\n (loop for is from 0 below (expt 4 n)\n do (loop with set1 = 0\n with set2 = 0\n with set3 = 0\n with set1-size = 0\n with set2-size = 0\n with set3-size = 0\n for i from 0 below n\n for mask = 3 then (ash mask 2)\n do (let ((value (ash (logand mask is) (* -2 i))))\n (cond ((= value 1)\n (incf set1-size)\n (incf set1 (aref ls i)))\n ((= value 2)\n (incf set2-size)\n (incf set2 (aref ls i)))\n ((= value 3)\n (incf set3-size)\n (incf set3 (aref ls i)))\n ((zerop value) nil)\n (t (error \"Huh\"))))\n finally (unless (or (zerop set1-size)\n (zerop set2-size)\n (zerop set3-size))\n (let* ((merge-cost (* 10 (+ (- set1-size 1)\n (- set2-size 1)\n (- set3-size 1))))\n (cost (+ merge-cost\n (abs (- a set1))\n (abs (- b set2))\n (abs (- c set3)))))\n (when (< cost min-cost)\n (setf min-cost cost))))))\n (println min-cost)))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1551043330, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03111.html", "problem_id": "p03111", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03111/input.txt", "sample_output_relpath": "derived/input_output/data/p03111/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03111/Lisp/s978355893.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s978355893", "user_id": "u352600849"}, "prompt_components": {"gold_output": "23\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (let* ((n (read))\n (a (read))\n (b (read))\n (c (read))\n (ls (make-array n :element-type 'uint15))\n (min-cost most-positive-fixnum))\n (dotimes (i n) (setf (aref ls i) (read)))\n (loop for is from 0 below (expt 4 n)\n do (loop with set1 = 0\n with set2 = 0\n with set3 = 0\n with set1-size = 0\n with set2-size = 0\n with set3-size = 0\n for i from 0 below n\n for mask = 3 then (ash mask 2)\n do (let ((value (ash (logand mask is) (* -2 i))))\n (cond ((= value 1)\n (incf set1-size)\n (incf set1 (aref ls i)))\n ((= value 2)\n (incf set2-size)\n (incf set2 (aref ls i)))\n ((= value 3)\n (incf set3-size)\n (incf set3 (aref ls i)))\n ((zerop value) nil)\n (t (error \"Huh\"))))\n finally (unless (or (zerop set1-size)\n (zerop set2-size)\n (zerop set3-size))\n (let* ((merge-cost (* 10 (+ (- set1-size 1)\n (- set2-size 1)\n (- set3-size 1))))\n (cost (+ merge-cost\n (abs (- a set1))\n (abs (- b set2))\n (abs (- c set3)))))\n (when (< cost min-cost)\n (setf min-cost cost))))))\n (println min-cost)))\n\n#-swank(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.\n\nYour objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:\n\nExtension Magic: Consumes 1 MP (magic point). Choose one bamboo and increase its length by 1.\n\nShortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.\n\nComposition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)\n\nAt least how much MP is needed to achieve the objective?\n\nConstraints\n\n3 \\leq N \\leq 8\n\n1 \\leq C < B < A \\leq 1000\n\n1 \\leq l_i \\leq 1000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B C\nl_1\nl_2\n:\nl_N\n\nOutput\n\nPrint the minimum amount of MP needed to achieve the objective.\n\nSample Input 1\n\n5 100 90 80\n98\n40\n30\n21\n80\n\nSample Output 1\n\n23\n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98, 40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain bamboos of lengths 100, 90 by using the magics as follows at the total cost of 23 MP, which is optimal.\n\nUse Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n\nUse Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n\nUse Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n\nUse Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\nSample Input 2\n\n8 100 90 80\n100\n100\n90\n90\n90\n80\n80\n80\n\nSample Output 2\n\n0\n\nIf we already have all bamboos of the desired lengths, the amount of MP needed is 0. As seen here, we do not necessarily need to use all the bamboos.\n\nSample Input 3\n\n8 1000 800 100\n300\n333\n400\n444\n500\n555\n600\n666\n\nSample Output 3\n\n243", "sample_input": "5 100 90 80\n98\n40\n30\n21\n80\n"}, "reference_outputs": ["23\n"], "source_document_id": "p03111", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.\n\nYour objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:\n\nExtension Magic: Consumes 1 MP (magic point). Choose one bamboo and increase its length by 1.\n\nShortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.\n\nComposition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)\n\nAt least how much MP is needed to achieve the objective?\n\nConstraints\n\n3 \\leq N \\leq 8\n\n1 \\leq C < B < A \\leq 1000\n\n1 \\leq l_i \\leq 1000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B C\nl_1\nl_2\n:\nl_N\n\nOutput\n\nPrint the minimum amount of MP needed to achieve the objective.\n\nSample Input 1\n\n5 100 90 80\n98\n40\n30\n21\n80\n\nSample Output 1\n\n23\n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98, 40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain bamboos of lengths 100, 90 by using the magics as follows at the total cost of 23 MP, which is optimal.\n\nUse Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n\nUse Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n\nUse Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n\nUse Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\nSample Input 2\n\n8 100 90 80\n100\n100\n90\n90\n90\n80\n80\n80\n\nSample Output 2\n\n0\n\nIf we already have all bamboos of the desired lengths, the amount of MP needed is 0. As seen here, we do not necessarily need to use all the bamboos.\n\nSample Input 3\n\n8 1000 800 100\n300\n333\n400\n444\n500\n555\n600\n666\n\nSample Output 3\n\n243", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2899, "cpu_time_ms": 154, "memory_kb": 20064}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s792881889", "group_id": "codeNet:p03112", "input_text": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.cl-user::opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defpackage :cp/bisect\n (:use :cl)\n (:export #:bisect-left #:bisect-right))\n(in-package :cp/bisect)\n\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of lower_bound() of C++ or bisect_left() of Python: Returns the\nsmallest index (or input) i that fulfills TARGET[i] >= VALUE, where '>=' is the\ncomplement of ORDER. In other words, this function returns the leftmost index at\nwhich VALUE can be inserted with keeping the order. Therefore, TARGET must be\nmonotonically non-decreasing with respect to ORDER.\n\n- This function returns END if VALUE exceeds TARGET[END-1]. \n- The range [START, END) is half-open.\n- END must be explicitly specified if TARGET is function.\n- KEY is applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-left (ng ok)\n ;; TARGET[OK] >= VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (funcall order (funcall key (,accessor target mid)) value)\n (%bisect-left mid ok)\n (%bisect-left ng mid))))))\n (assert (<= start end))\n (%bisect-left (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.most-positive-fixnum)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of upper_bound() of C++ or bisect_right() of Python: Returns the\nsmallest index (or input) i that fulfills TARGET[i] > VALUE. In other words,\nthis function returns the rightmost index at which VALUE can be inserted with\nkeeping the order. Therefore, TARGET must be monotonically non-decreasing with\nrespect to ORDER.\n\n- This function returns END if VALUE >= TARGET[END-1].\n- The range [START, END) is half-open.\n- END must be explicitly specified if TARGET is function.\n- KEY is applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-right (ng ok)\n ;; TARGET[OK] > VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (funcall order value (funcall key (,accessor target mid)))\n (%bisect-right ng mid)\n (%bisect-right mid ok))))))\n (assert (<= start end))\n (%bisect-right (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.array-total-size-limit)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/bisect :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +pos-inf+ #.(expt 10 17))\n(defconstant +neg-inf+ #.(- (expt 10 17)))\n(defun main ()\n (declare #.cl-user::opt)\n (let* ((a (read))\n (b (read))\n (q (read))\n (ss (make-array (+ a 2) :element-type 'fixnum :initial-element 0))\n (ts (make-array (+ b 2) :element-type 'fixnum :initial-element 0)))\n (declare (uint31 a b q))\n (setf (aref ss 0) +neg-inf+\n (aref ss (+ a 1)) +pos-inf+\n (aref ts 0) +neg-inf+\n (aref ts (+ b 1)) +pos-inf+)\n (loop for i from 1 to a\n do (setf (aref ss i) (read-fixnum)))\n (loop for i from 1 to b\n do (setf (aref ts i) (read-fixnum)))\n (labels ((calc-dist (vec x)\n (if (< +neg-inf+ x +pos-inf+)\n (let* ((r (bisect-left vec x))\n (l (- r 1)))\n (min (abs (- (aref vec r) x))\n (abs (- (aref vec l) x))))\n +pos-inf+)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (_ q)\n (let* ((x (read-fixnum))\n (sr (bisect-left ss x))\n (sl (- sr 1))\n (tr (bisect-left ts x))\n (tl (- tr 1)))\n (println\n (min (+ (abs (- x (aref ss sr)))\n (calc-dist ts (aref ss sr)))\n (+ (abs (- x (aref ss sl)))\n (calc-dist ts (aref ss sl)))\n (+ (abs (- x (aref ts tr)))\n (calc-dist ss (aref ts tr)))\n (+ (abs (- x (aref ts tl)))\n (calc-dist ss (aref ts tl))))))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"350\n1400\n301\n399\n\"\n (run \"2 3 4\n100\n600\n400\n900\n1000\n150\n2000\n899\n799\n\" nil)))\n (it.bese.fiveam:is\n (equal \"10000000000\n10000000000\n14999999998\n\"\n (run \"1 1 3\n1\n10000000000\n2\n9999999999\n5000000000\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1599346836, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03112.html", "problem_id": "p03112", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03112/input.txt", "sample_output_relpath": "derived/input_output/data/p03112/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03112/Lisp/s792881889.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s792881889", "user_id": "u352600849"}, "prompt_components": {"gold_output": "350\n1400\n301\n399\n", "input_to_evaluate": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.cl-user::opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defpackage :cp/bisect\n (:use :cl)\n (:export #:bisect-left #:bisect-right))\n(in-package :cp/bisect)\n\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of lower_bound() of C++ or bisect_left() of Python: Returns the\nsmallest index (or input) i that fulfills TARGET[i] >= VALUE, where '>=' is the\ncomplement of ORDER. In other words, this function returns the leftmost index at\nwhich VALUE can be inserted with keeping the order. Therefore, TARGET must be\nmonotonically non-decreasing with respect to ORDER.\n\n- This function returns END if VALUE exceeds TARGET[END-1]. \n- The range [START, END) is half-open.\n- END must be explicitly specified if TARGET is function.\n- KEY is applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-left (ng ok)\n ;; TARGET[OK] >= VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (funcall order (funcall key (,accessor target mid)) value)\n (%bisect-left mid ok)\n (%bisect-left ng mid))))))\n (assert (<= start end))\n (%bisect-left (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.most-positive-fixnum)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (order #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nORDER := strict order\n\nAnalogue of upper_bound() of C++ or bisect_right() of Python: Returns the\nsmallest index (or input) i that fulfills TARGET[i] > VALUE. In other words,\nthis function returns the rightmost index at which VALUE can be inserted with\nkeeping the order. Therefore, TARGET must be monotonically non-decreasing with\nrespect to ORDER.\n\n- This function returns END if VALUE >= TARGET[END-1].\n- The range [START, END) is half-open.\n- END must be explicitly specified if TARGET is function.\n- KEY is applied to each element of TARGET before comparison.\"\n (declare (function key order)\n (integer start)\n ((or null integer) end))\n (macrolet\n ((frob (accessor &optional declaration)\n `(labels\n ((%bisect-right (ng ok)\n ;; TARGET[OK] > VALUE always holds (assuming\n ;; TARGET[END] = +infinity)\n ,@(when declaration (list declaration))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ng ok) -1)))\n (if (funcall order value (funcall key (,accessor target mid)))\n (%bisect-right ng mid)\n (%bisect-right mid ok))))))\n (assert (<= start end))\n (%bisect-right (- start 1) end))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (frob aref (declare ((integer -1 (#.array-total-size-limit)) ng ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob funcall)))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/bisect :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +pos-inf+ #.(expt 10 17))\n(defconstant +neg-inf+ #.(- (expt 10 17)))\n(defun main ()\n (declare #.cl-user::opt)\n (let* ((a (read))\n (b (read))\n (q (read))\n (ss (make-array (+ a 2) :element-type 'fixnum :initial-element 0))\n (ts (make-array (+ b 2) :element-type 'fixnum :initial-element 0)))\n (declare (uint31 a b q))\n (setf (aref ss 0) +neg-inf+\n (aref ss (+ a 1)) +pos-inf+\n (aref ts 0) +neg-inf+\n (aref ts (+ b 1)) +pos-inf+)\n (loop for i from 1 to a\n do (setf (aref ss i) (read-fixnum)))\n (loop for i from 1 to b\n do (setf (aref ts i) (read-fixnum)))\n (labels ((calc-dist (vec x)\n (if (< +neg-inf+ x +pos-inf+)\n (let* ((r (bisect-left vec x))\n (l (- r 1)))\n (min (abs (- (aref vec r) x))\n (abs (- (aref vec l) x))))\n +pos-inf+)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (_ q)\n (let* ((x (read-fixnum))\n (sr (bisect-left ss x))\n (sl (- sr 1))\n (tr (bisect-left ts x))\n (tl (- tr 1)))\n (println\n (min (+ (abs (- x (aref ss sr)))\n (calc-dist ts (aref ss sr)))\n (+ (abs (- x (aref ss sl)))\n (calc-dist ts (aref ss sl)))\n (+ (abs (- x (aref ts tr)))\n (calc-dist ss (aref ts tr)))\n (+ (abs (- x (aref ts tl)))\n (calc-dist ss (aref ts tl))))))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"350\n1400\n301\n399\n\"\n (run \"2 3 4\n100\n600\n400\n900\n1000\n150\n2000\n899\n799\n\" nil)))\n (it.bese.fiveam:is\n (equal \"10000000000\n10000000000\n14999999998\n\"\n (run \"1 1 3\n1\n10000000000\n2\n9999999999\n5000000000\n\" nil))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nAlong a road running in an east-west direction, there are A shrines and B temples.\nThe i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.\n\nAnswer the following Q queries:\n\nQuery i (1 \\leq i \\leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)\n\nConstraints\n\n1 \\leq A, B \\leq 10^5\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq s_1 < s_2 < ... < s_A \\leq 10^{10}\n\n1 \\leq t_1 < t_2 < ... < t_B \\leq 10^{10}\n\n1 \\leq x_i \\leq 10^{10}\n\ns_1, ..., s_A, t_1, ..., t_B, x_1, ..., x_Q are all different.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B Q\ns_1\n:\ns_A\nt_1\n:\nt_B\nx_1\n:\nx_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the answer to the i-th query.\n\nSample Input 1\n\n2 3 4\n100\n600\n400\n900\n1000\n150\n2000\n899\n799\n\nSample Output 1\n\n350\n1400\n301\n399\n\nThere are two shrines and three temples. The shrines are located at distances of 100, 600 meters from the west end of the road, and the temples are located at distances of 400, 900, 1000 meters from the west end of the road.\n\nQuery 1: If we start from a point at a distance of 150 meters from the west end of the road, the optimal move is first to walk 50 meters west to visit a shrine, then to walk 300 meters east to visit a temple.\n\nQuery 2: If we start from a point at a distance of 2000 meters from the west end of the road, the optimal move is first to walk 1000 meters west to visit a temple, then to walk 400 meters west to visit a shrine. We will pass by another temple on the way, but it is fine.\n\nQuery 3: If we start from a point at a distance of 899 meters from the west end of the road, the optimal move is first to walk 1 meter east to visit a temple, then to walk 300 meters west to visit a shrine.\n\nQuery 4: If we start from a point at a distance of 799 meters from the west end of the road, the optimal move is first to walk 199 meters west to visit a shrine, then to walk 200 meters west to visit a temple.\n\nSample Input 2\n\n1 1 3\n1\n10000000000\n2\n9999999999\n5000000000\n\nSample Output 2\n\n10000000000\n10000000000\n14999999998\n\nThe road is quite long, and we may need to travel a distance that does not fit into a 32-bit integer.", "sample_input": "2 3 4\n100\n600\n400\n900\n1000\n150\n2000\n899\n799\n"}, "reference_outputs": ["350\n1400\n301\n399\n"], "source_document_id": "p03112", "source_text": "Score : 400 points\n\nProblem Statement\n\nAlong a road running in an east-west direction, there are A shrines and B temples.\nThe i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.\n\nAnswer the following Q queries:\n\nQuery i (1 \\leq i \\leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)\n\nConstraints\n\n1 \\leq A, B \\leq 10^5\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq s_1 < s_2 < ... < s_A \\leq 10^{10}\n\n1 \\leq t_1 < t_2 < ... < t_B \\leq 10^{10}\n\n1 \\leq x_i \\leq 10^{10}\n\ns_1, ..., s_A, t_1, ..., t_B, x_1, ..., x_Q are all different.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B Q\ns_1\n:\ns_A\nt_1\n:\nt_B\nx_1\n:\nx_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the answer to the i-th query.\n\nSample Input 1\n\n2 3 4\n100\n600\n400\n900\n1000\n150\n2000\n899\n799\n\nSample Output 1\n\n350\n1400\n301\n399\n\nThere are two shrines and three temples. The shrines are located at distances of 100, 600 meters from the west end of the road, and the temples are located at distances of 400, 900, 1000 meters from the west end of the road.\n\nQuery 1: If we start from a point at a distance of 150 meters from the west end of the road, the optimal move is first to walk 50 meters west to visit a shrine, then to walk 300 meters east to visit a temple.\n\nQuery 2: If we start from a point at a distance of 2000 meters from the west end of the road, the optimal move is first to walk 1000 meters west to visit a temple, then to walk 400 meters west to visit a shrine. We will pass by another temple on the way, but it is fine.\n\nQuery 3: If we start from a point at a distance of 899 meters from the west end of the road, the optimal move is first to walk 1 meter east to visit a temple, then to walk 300 meters west to visit a shrine.\n\nQuery 4: If we start from a point at a distance of 799 meters from the west end of the road, the optimal move is first to walk 199 meters west to visit a shrine, then to walk 200 meters west to visit a temple.\n\nSample Input 2\n\n1 1 3\n1\n10000000000\n2\n9999999999\n5000000000\n\nSample Output 2\n\n10000000000\n10000000000\n14999999998\n\nThe road is quite long, and we may need to travel a distance that does not fit into a 32-bit integer.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10295, "cpu_time_ms": 142, "memory_kb": 29100}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s080331205", "group_id": "codeNet:p03131", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (let* ((k (read))\n (a (read))\n (b (read)))\n (if (or (>= a k) (>= a b))\n (println (+ 1 k))\n (if (evenp (+ k (- a) 1))\n (println (max (+ k 1)\n (+ a (floor (* (- b a) (+ k (- a) 1)) 2))))\n (println (max (+ k 1)\n (+ 1 a (floor (* (- b a) (- k a)) 2))))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1549767325, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03131.html", "problem_id": "p03131", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03131/input.txt", "sample_output_relpath": "derived/input_output/data/p03131/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03131/Lisp/s080331205.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s080331205", "user_id": "u352600849"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (let* ((k (read))\n (a (read))\n (b (read)))\n (if (or (>= a k) (>= a b))\n (println (+ 1 k))\n (if (evenp (+ k (- a) 1))\n (println (max (+ k 1)\n (+ a (floor (* (- b a) (+ k (- a) 1)) 2))))\n (println (max (+ k 1)\n (+ 1 a (floor (* (- b a) (- k a)) 2))))))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nSnuke has one biscuit and zero Japanese yen (the currency) in his pocket.\nHe will perform the following operations exactly K times in total, in the order he likes:\n\nHit his pocket, which magically increases the number of biscuits by one.\n\nExchange A biscuits to 1 yen.\n\nExchange 1 yen to B biscuits.\n\nFind the maximum possible number of biscuits in Snuke's pocket after K operations.\n\nConstraints\n\n1 \\leq K,A,B \\leq 10^9\n\nK,A and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK A B\n\nOutput\n\nPrint the maximum possible number of biscuits in Snuke's pocket after K operations.\n\nSample Input 1\n\n4 2 6\n\nSample Output 1\n\n7\n\nThe number of biscuits in Snuke's pocket after K operations is maximized as follows:\n\nHit his pocket. Now he has 2 biscuits and 0 yen.\n\nExchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n\nHit his pocket. Now he has 1 biscuits and 1 yen.\n\nExchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\nSample Input 2\n\n7 3 4\n\nSample Output 2\n\n8\n\nSample Input 3\n\n314159265 35897932 384626433\n\nSample Output 3\n\n48518828981938099", "sample_input": "4 2 6\n"}, "reference_outputs": ["7\n"], "source_document_id": "p03131", "source_text": "Score : 400 points\n\nProblem Statement\n\nSnuke has one biscuit and zero Japanese yen (the currency) in his pocket.\nHe will perform the following operations exactly K times in total, in the order he likes:\n\nHit his pocket, which magically increases the number of biscuits by one.\n\nExchange A biscuits to 1 yen.\n\nExchange 1 yen to B biscuits.\n\nFind the maximum possible number of biscuits in Snuke's pocket after K operations.\n\nConstraints\n\n1 \\leq K,A,B \\leq 10^9\n\nK,A and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK A B\n\nOutput\n\nPrint the maximum possible number of biscuits in Snuke's pocket after K operations.\n\nSample Input 1\n\n4 2 6\n\nSample Output 1\n\n7\n\nThe number of biscuits in Snuke's pocket after K operations is maximized as follows:\n\nHit his pocket. Now he has 2 biscuits and 0 yen.\n\nExchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n\nHit his pocket. Now he has 1 biscuits and 1 yen.\n\nExchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\nSample Input 2\n\n7 3 4\n\nSample Output 2\n\n8\n\nSample Input 3\n\n314159265 35897932 384626433\n\nSample Output 3\n\n48518828981938099", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1308, "cpu_time_ms": 169, "memory_kb": 18916}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s523039273", "group_id": "codeNet:p03140", "input_text": "(defun f (a b c)\n (cond ((char= a b c) 0)\n ((char= a b) 1)\n ((char= b c) 1)\n ((char= a c) 1)\n (t 2)))\n(let* ((n (read))\n (a (read-line))\n (b (read-line))\n (c (read-line)))\n (princ (loop :for k :from 0 :upto (1- n) :sum (f (aref a k) (aref b k) (aref c k)))))\n", "language": "Lisp", "metadata": {"date": 1568219118, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03140.html", "problem_id": "p03140", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03140/input.txt", "sample_output_relpath": "derived/input_output/data/p03140/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03140/Lisp/s523039273.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s523039273", "user_id": "u610490393"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun f (a b c)\n (cond ((char= a b c) 0)\n ((char= a b) 1)\n ((char= b c) 1)\n ((char= a c) 1)\n (t 2)))\n(let* ((n (read))\n (a (read-line))\n (b (read-line))\n (c (read-line)))\n (princ (loop :for k :from 0 :upto (1- n) :sum (f (aref a k) (aref b k) (aref c k)))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters.\n\nOur objective is to make all these three strings equal. For that, you can repeatedly perform the following operation:\n\nOperation: Choose one of the strings A, B and C, and specify an integer i between 1 and N (inclusive). Change the i-th character from the beginning of the chosen string to some other lowercase English letter.\n\nWhat is the minimum number of operations required to achieve the objective?\n\nConstraints\n\n1 \\leq N \\leq 100\n\nEach of the strings A, B and C is a string of length N.\n\nEach character in each of the strings A, B and C is a lowercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA\nB\nC\n\nOutput\n\nPrint the minimum number of operations required.\n\nSample Input 1\n\n4\nwest\neast\nwait\n\nSample Output 1\n\n3\n\nIn this sample, initially A = west、B = east、C = wait. We can achieve the objective in the minimum number of operations by performing three operations as follows:\n\nChange the second character in A to a. A is now wast.\n\nChange the first character in B to w. B is now wast.\n\nChange the third character in C to s. C is now wast.\n\nSample Input 2\n\n9\ndifferent\ndifferent\ndifferent\n\nSample Output 2\n\n0\n\nIf A, B and C are already equal in the beginning, the number of operations required is 0.\n\nSample Input 3\n\n7\nzenkoku\ntouitsu\nprogram\n\nSample Output 3\n\n13", "sample_input": "4\nwest\neast\nwait\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03140", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters.\n\nOur objective is to make all these three strings equal. For that, you can repeatedly perform the following operation:\n\nOperation: Choose one of the strings A, B and C, and specify an integer i between 1 and N (inclusive). Change the i-th character from the beginning of the chosen string to some other lowercase English letter.\n\nWhat is the minimum number of operations required to achieve the objective?\n\nConstraints\n\n1 \\leq N \\leq 100\n\nEach of the strings A, B and C is a string of length N.\n\nEach character in each of the strings A, B and C is a lowercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA\nB\nC\n\nOutput\n\nPrint the minimum number of operations required.\n\nSample Input 1\n\n4\nwest\neast\nwait\n\nSample Output 1\n\n3\n\nIn this sample, initially A = west、B = east、C = wait. We can achieve the objective in the minimum number of operations by performing three operations as follows:\n\nChange the second character in A to a. A is now wast.\n\nChange the first character in B to w. B is now wast.\n\nChange the third character in C to s. C is now wast.\n\nSample Input 2\n\n9\ndifferent\ndifferent\ndifferent\n\nSample Output 2\n\n0\n\nIf A, B and C are already equal in the beginning, the number of operations required is 0.\n\nSample Input 3\n\n7\nzenkoku\ntouitsu\nprogram\n\nSample Output 3\n\n13", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 307, "cpu_time_ms": 17, "memory_kb": 4456}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s671600793", "group_id": "codeNet:p03142", "input_text": "#-(or child-sbcl swank)\n(quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n '(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" #.(namestring *load-pathname*))\n :output t :error t :input t)))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n\n;; -*- coding:utf-8 -*-\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue!))\n(defun enqueue! (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue!))\n(defun dequeue! (queue)\n (pop (queue-list queue)))\n\n(defun empty-queue-p (queue)\n (null (queue-list queue)))\n\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #.(char-code #\\Newline)))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (setf (schar ,buffer ,idx) ,terminate-char)\n (return (values ,buffer ,idx))))))\n\n(defmacro split-ints-bind (vars string &body body)\n (let ((position (gensym))\n (s (gensym)))\n (labels ((expand (vars &optional init-pos)\n (if (null vars)\n body\n `((multiple-value-bind (,(car vars) ,position)\n (parse-integer ,s :start ,(or init-pos position)\n :junk-allowed t)\n ,@(when (null (cdr vars)) `((declare (ignore ,position))))\n ,@(expand (cdr vars)))))))\n `(let ((,s ,string))\n (declare (string ,s))\n ,@(expand vars 0)))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n(defun solve (graph root)\n (let* ((n (length graph))\n (cost-table (make-array n :element-type 'uint32 :initial-element 0))\n (parents-table (make-array n :element-type 'int32 :initial-element -1)))\n (setf (aref cost-table root) 0)\n (dotimes (i n)\n (nlet recurse ((graph graph))\n (unless (null graph)\n (let* ((pair (car graph))\n (a (car pair))\n (b (cdr pair)))\n (when (> (+ (aref cost-table a) 1) (aref cost-table b))\n (setf (aref cost-table b) (+ (aref cost-table a) 1))\n (setf (aref parents-table b) a))\n (recurse (cdr graph))))))\n parents-table))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (n-1+m (+ n -1 m))\n graph\n (rev-graph (make-array n :element-type 'list :initial-element nil))\n (out (make-string-output-stream :element-type 'base-char)))\n (dotimes (i (+ n -1 m))\n (split-ints-bind (a b) (buffered-read-line 20)\n (declare (uint32 a b))\n (push (cons (- a 1) (- b 1)) graph)\n (push (- a 1) (aref rev-graph (- b 1)))))\n (let* ((root (nlet find-root ((node 0))\n (if (null (aref rev-graph node))\n node\n (loop for next in (aref rev-graph node)\n for root = (find-root next)\n when root\n do (return root)))))\n (parents (solve graph root)))\n (declare ((simple-array int32 (*)) parents))\n (dotimes (i n (write-string (get-output-stream-string out)))\n (println (1+ (aref parents i)) out)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1548647963, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03142.html", "problem_id": "p03142", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03142/input.txt", "sample_output_relpath": "derived/input_output/data/p03142/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03142/Lisp/s671600793.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s671600793", "user_id": "u352600849"}, "prompt_components": {"gold_output": "0\n1\n2\n", "input_to_evaluate": "#-(or child-sbcl swank)\n(quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n '(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" #.(namestring *load-pathname*))\n :output t :error t :input t)))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n\n;; -*- coding:utf-8 -*-\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue!))\n(defun enqueue! (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue!))\n(defun dequeue! (queue)\n (pop (queue-list queue)))\n\n(defun empty-queue-p (queue)\n (null (queue-list queue)))\n\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #.(char-code #\\Newline)))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (setf (schar ,buffer ,idx) ,terminate-char)\n (return (values ,buffer ,idx))))))\n\n(defmacro split-ints-bind (vars string &body body)\n (let ((position (gensym))\n (s (gensym)))\n (labels ((expand (vars &optional init-pos)\n (if (null vars)\n body\n `((multiple-value-bind (,(car vars) ,position)\n (parse-integer ,s :start ,(or init-pos position)\n :junk-allowed t)\n ,@(when (null (cdr vars)) `((declare (ignore ,position))))\n ,@(expand (cdr vars)))))))\n `(let ((,s ,string))\n (declare (string ,s))\n ,@(expand vars 0)))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n(defun solve (graph root)\n (let* ((n (length graph))\n (cost-table (make-array n :element-type 'uint32 :initial-element 0))\n (parents-table (make-array n :element-type 'int32 :initial-element -1)))\n (setf (aref cost-table root) 0)\n (dotimes (i n)\n (nlet recurse ((graph graph))\n (unless (null graph)\n (let* ((pair (car graph))\n (a (car pair))\n (b (cdr pair)))\n (when (> (+ (aref cost-table a) 1) (aref cost-table b))\n (setf (aref cost-table b) (+ (aref cost-table a) 1))\n (setf (aref parents-table b) a))\n (recurse (cdr graph))))))\n parents-table))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (n-1+m (+ n -1 m))\n graph\n (rev-graph (make-array n :element-type 'list :initial-element nil))\n (out (make-string-output-stream :element-type 'base-char)))\n (dotimes (i (+ n -1 m))\n (split-ints-bind (a b) (buffered-read-line 20)\n (declare (uint32 a b))\n (push (cons (- a 1) (- b 1)) graph)\n (push (- a 1) (aref rev-graph (- b 1)))))\n (let* ((root (nlet find-root ((node 0))\n (if (null (aref rev-graph node))\n node\n (loop for next in (aref rev-graph node)\n for root = (find-root next)\n when root\n do (return root)))))\n (parents (solve graph root)))\n (declare ((simple-array int32 (*)) parents))\n (dotimes (i n (write-string (get-output-stream-string out)))\n (println (1+ (aref parents i)) out)))))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere is a rooted tree (see Notes) with N vertices numbered 1 to N.\nEach of the vertices, except the root, has a directed edge coming from its parent.\nNote that the root may not be Vertex 1.\n\nTakahashi has added M new directed edges to this graph.\nEach of these M edges, u \\rightarrow v, extends from some vertex u to its descendant v.\n\nYou are given the directed graph with N vertices and N-1+M edges after Takahashi added edges.\nMore specifically, you are given N-1+M pairs of integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}), which represent that the i-th edge extends from Vertex A_i to Vertex B_i.\n\nRestore the original rooted tree.\n\nNotes\n\nFor \"tree\" and other related terms in graph theory, see the article in Wikipedia, for example.\n\nConstraints\n\n3 \\leq N\n\n1 \\leq M\n\nN + M \\leq 10^5\n\n1 \\leq A_i, B_i \\leq N\n\nA_i \\neq B_i\n\nIf i \\neq j, (A_i, B_i) \\neq (A_j, B_j).\n\nThe graph in input can be obtained by adding M edges satisfying the condition in the problem statement to a rooted tree with N vertices.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\n:\nA_{N-1+M} B_{N-1+M}\n\nOutput\n\nPrint N lines.\nIn the i-th line, print 0 if Vertex i is the root of the original tree, and otherwise print the integer representing the parent of Vertex i in the original tree.\n\nNote that it can be shown that the original tree is uniquely determined.\n\nSample Input 1\n\n3 1\n1 2\n1 3\n2 3\n\nSample Output 1\n\n0\n1\n2\n\nThe graph in this input is shown below:\n\nIt can be seen that this graph is obtained by adding the edge 1 \\rightarrow 3 to the rooted tree 1 \\rightarrow 2 \\rightarrow 3.\n\nSample Input 2\n\n6 3\n2 1\n2 3\n4 1\n4 2\n6 1\n2 6\n4 6\n6 5\n\nSample Output 2\n\n6\n4\n2\n0\n6\n2", "sample_input": "3 1\n1 2\n1 3\n2 3\n"}, "reference_outputs": ["0\n1\n2\n"], "source_document_id": "p03142", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere is a rooted tree (see Notes) with N vertices numbered 1 to N.\nEach of the vertices, except the root, has a directed edge coming from its parent.\nNote that the root may not be Vertex 1.\n\nTakahashi has added M new directed edges to this graph.\nEach of these M edges, u \\rightarrow v, extends from some vertex u to its descendant v.\n\nYou are given the directed graph with N vertices and N-1+M edges after Takahashi added edges.\nMore specifically, you are given N-1+M pairs of integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}), which represent that the i-th edge extends from Vertex A_i to Vertex B_i.\n\nRestore the original rooted tree.\n\nNotes\n\nFor \"tree\" and other related terms in graph theory, see the article in Wikipedia, for example.\n\nConstraints\n\n3 \\leq N\n\n1 \\leq M\n\nN + M \\leq 10^5\n\n1 \\leq A_i, B_i \\leq N\n\nA_i \\neq B_i\n\nIf i \\neq j, (A_i, B_i) \\neq (A_j, B_j).\n\nThe graph in input can be obtained by adding M edges satisfying the condition in the problem statement to a rooted tree with N vertices.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\n:\nA_{N-1+M} B_{N-1+M}\n\nOutput\n\nPrint N lines.\nIn the i-th line, print 0 if Vertex i is the root of the original tree, and otherwise print the integer representing the parent of Vertex i in the original tree.\n\nNote that it can be shown that the original tree is uniquely determined.\n\nSample Input 1\n\n3 1\n1 2\n1 3\n2 3\n\nSample Output 1\n\n0\n1\n2\n\nThe graph in this input is shown below:\n\nIt can be seen that this graph is obtained by adding the edge 1 \\rightarrow 3 to the rooted tree 1 \\rightarrow 2 \\rightarrow 3.\n\nSample Input 2\n\n6 3\n2 1\n2 3\n4 1\n4 2\n6 1\n2 6\n4 6\n6 5\n\nSample Output 2\n\n6\n4\n2\n0\n6\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5622, "cpu_time_ms": 2116, "memory_kb": 32184}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s867800196", "group_id": "codeNet:p03143", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"256MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.cl-user::opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Sort multiple vectors\n;;;\n\n(defpackage :cp/parallel-sort\n (:use :cl)\n (:export #:parallel-sort!))\n(in-package :cp/parallel-sort)\n\n;; TODO: throw an error if there are two ore more identical vectors in the given\n;; vectors\n\n(declaim (inline %median3))\n(defun %median3 (x y z order)\n (if (funcall order x y)\n (if (funcall order y z)\n y\n (if (funcall order z x)\n x\n z))\n (if (funcall order z y)\n y\n (if (funcall order x z)\n x\n z))))\n\n(defun parallel-sort! (vector order &rest vectors)\n \"Destructively sorts VECTOR w.r.t. ORDER and applies the same permutation to\nall the vectors in VECTORS.\n\nNote: not randomized; shuffle the inputs if necessary\"\n (declare (vector vector))\n (labels\n ((recur (left right)\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3 (aref vector l)\n (aref vector (ash (+ l r) -1))\n (aref vector r)\n order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall order (aref vector l) pivot)\n do (incf l 1))\n (loop while (funcall order pivot (aref vector r))\n do (decf r 1))\n (when (>= l r)\n (return))\n (rotatef (aref vector l) (aref vector r))\n (dolist (v vectors)\n (rotatef (aref v l) (aref v r)))\n (incf l 1)\n (decf r 1))\n (recur left (- l 1))\n (recur (+ r 1) right)))))\n (recur 0 (- (length vector) 1))\n vector))\n\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (sb-ext:muffle-conditions warning))\n (sb-c:define-source-transform parallel-sort! (vector order &rest vectors)\n (let ((vec (gensym))\n (vecs (loop for _ in vectors collect (gensym))))\n `(let ((,vec ,vector)\n ,@(loop for v in vectors\n for sym in vecs\n collect `(,sym ,v)))\n (labels\n ((recur (left right)\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3 (aref ,vec l)\n (aref ,vec (ash (+ l r) -1))\n (aref ,vec r)\n ,order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall ,order (aref ,vec l) pivot)\n do (incf l 1))\n (loop while (funcall ,order pivot (aref ,vec r))\n do (decf r 1))\n (when (>= l r)\n (return))\n (rotatef (aref ,vec l) (aref ,vec r))\n ,@(loop for sym in vecs\n collect `(rotatef (aref ,sym l) (aref ,sym r)))\n (incf l 1)\n (decf r 1))\n (recur left (- l 1))\n (recur (+ r 1) right)))))\n (recur 0 (- (length ,vec) 1))\n ,vec))))))\n\n;;;\n;;; Disjoint set by Union-Find algorithm over arbitrary monoid\n;;;\n\n;; not tested\n\n(defpackage :cp/abstract-disjoint-set\n (:use :cl)\n (:export #:define-disjoint-set))\n(in-package :cp/abstract-disjoint-set)\n\n(defmacro define-disjoint-set (name &key (operation '#'+) (element-type 'fixnum) (union-by-size t) conc-name)\n (check-type name symbol)\n (let* ((conc-string (if conc-name\n (symbol-name conc-name)\n (format nil \"~A-\" (symbol-name name))))\n (constructor (intern (format nil \"MAKE-~A\" (symbol-name name))))\n (rooter (intern (format nil \"~AROOT\" conc-string)))\n (reffer (intern (format nil \"~AREF\" conc-string)))\n (uniter (intern (format nil \"~AUNITE!\" conc-string)))\n (connectivity-checker (intern (format nil \"~ACONNECTED-P\" conc-string)))\n (size-getter (intern (format nil \"~ASIZE\" conc-string)))\n (data-accessor (intern (format nil \"~ADATA\" conc-string)))\n (values-accessor (intern (format nil \"~AVALUES\" conc-string))))\n `(progn\n (defstruct (,name\n (:constructor ,constructor\n (size\n &optional\n (contents (make-array size :element-type ',element-type))\n &aux\n (values\n (prog1 contents\n (assert (= (length contents) size))))\n (data (make-array size :element-type 'fixnum :initial-element -1))))\n ,@(when conc-name `((:conc-name ,(intern conc-string)))))\n (data nil :type (simple-array fixnum (*)))\n (values nil :type (simple-array ,element-type (*))))\n \n (declaim (inline ,rooter)\n (ftype (function * (values (mod #.array-total-size-limit) &optional))\n ,rooter))\n (defun ,rooter (,name x)\n \"Returns the root of X.\"\n (declare ((mod #.array-total-size-limit) x))\n (let ((data (,data-accessor ,name)))\n (labels ((recur (x)\n (if (< (aref data x) 0)\n x\n (setf (aref data x) (recur (aref data x))))))\n (recur x))))\n \n (declaim (inline ,reffer))\n (defun ,reffer (,name x)\n (aref (,values-accessor ,name)\n (,rooter ,name x)))\n \n (declaim (inline (setf ,reffer)))\n (defun (setf ,reffer) (new-value ,name x)\n (setf (aref (,values-accessor ,name)\n (,rooter ,name x))\n new-value))\n \n (declaim (inline ,uniter))\n (defun ,uniter (,name x1 x2)\n \"Destructively unites X1 and X2 and returns true iff X1 and X2 become\nconnected for the first time. (If UNION-BY-SIZE is disabled, X1 becomes root.)\"\n (let ((root1 (,rooter ,name x1))\n (root2 (,rooter ,name x2)))\n (unless (= root1 root2)\n (let ((data (,data-accessor ,name))\n (values (,values-accessor ,name)))\n ;; ensure the size of root1 >= the size of root2\n ,@(when union-by-size\n '((when (> (aref data root1) (aref data root2))\n (rotatef root1 root2))))\n (incf (aref data root1) (aref data root2))\n (setf (aref values root1)\n (funcall ,operation (aref values root2) (aref values root1)))\n (setf (aref data root2) root1)))))\n\n (declaim (inline ,connectivity-checker))\n (defun ,connectivity-checker (,name x1 x2)\n \"Returns true iff X1 and X2 have the same root.\"\n (= (,rooter ,name x1) (,rooter ,name x2)))\n\n (declaim (inline ,size-getter))\n (defun ,size-getter (,name x)\n \"Returns the size of the connected component to which X belongs.\"\n (- (aref (,data-accessor ,name)\n (,rooter ,name x)))))))\n\n#+(or)\n(define-disjoint-set disjoint-set\n :operation #'max\n :element-type fixnum\n :conc-name ds-\n :union-by-size nil)\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/abstract-disjoint-set :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/parallel-sort :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(define-disjoint-set disjoint-set\n :operation #'+\n :element-type uint62\n :conc-name ds-)\n\n(defun main ()\n (declare #.cl-user::opt)\n (let* ((n (read))\n (m (read))\n (xs (make-array n :element-type 'uint62 :initial-element 0))\n (as (make-array m :element-type 'uint31 :initial-element 0))\n (bs (make-array m :element-type 'uint31 :initial-element 0))\n (ys (make-array m :element-type 'uint31 :initial-element 0))\n (graph (make-array n :element-type 'list :initial-element nil)))\n (dotimes (i n)\n (setf (aref xs i) (read-fixnum)))\n (dotimes (i m)\n (setf (aref as i) (- (read-fixnum) 1)\n (aref bs i) (- (read-fixnum) 1)\n (aref ys i) (read-fixnum)))\n (parallel-sort! ys #'< as bs)\n (dotimes (i m)\n (push i (aref graph (aref as i)))\n (push i (aref graph (aref bs i))))\n (let ((dset (make-disjoint-set n xs))\n (flags (make-array m :element-type 'bit :initial-element 0))\n (res (make-array m :element-type 'bit :initial-element 0)))\n (dotimes (i m)\n (let* ((a (aref as i))\n (b (aref bs i))\n (y (aref ys i)))\n (ds-unite! dset a b)\n (when (<= y (ds-ref dset a))\n (setf (aref flags i) 1))))\n (loop for i from (- m 1) downto 0\n for a = (aref as i)\n for max-y = (aref ys i)\n when (and (= 1 (aref flags i)) (= 0 (aref res i)))\n do (sb-int:named-let dfs ((v a))\n (dolist (eidx (aref graph v))\n (let* ((a (aref as eidx))\n (b (aref bs eidx))\n (y (aref ys eidx))\n (next-v (if (= a v) b a)))\n (when (and (= 0 (aref res eidx))\n (<= y max-y))\n (setf (aref res eidx) 1)\n (dfs next-v))))))\n (println (- m (count 1 res))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"2\n\"\n (run \"4 4\n2 3 5 7\n1 2 7\n1 3 9\n2 3 12\n3 4 18\n\" nil)))\n (it.bese.fiveam:is\n (equal \"4\n\"\n (run \"6 10\n4 4 1 1 1 7\n3 5 19\n2 5 20\n4 5 8\n1 6 16\n2 3 9\n3 6 16\n3 4 1\n2 6 20\n2 4 19\n1 2 9\n\" nil)))\n (it.bese.fiveam:is\n (equal \"8\n\"\n (run \"10 9\n81 16 73 7 2 61 86 38 90 28\n6 8 725\n3 10 12\n1 4 558\n4 9 615\n5 6 942\n8 9 918\n2 7 720\n4 7 292\n7 10 414\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1599118810, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03143.html", "problem_id": "p03143", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03143/input.txt", "sample_output_relpath": "derived/input_output/data/p03143/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03143/Lisp/s867800196.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s867800196", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"256MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/read-fixnum\n (:use :cl)\n (:export #:read-fixnum))\n(in-package :cp/read-fixnum)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.cl-user::opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Sort multiple vectors\n;;;\n\n(defpackage :cp/parallel-sort\n (:use :cl)\n (:export #:parallel-sort!))\n(in-package :cp/parallel-sort)\n\n;; TODO: throw an error if there are two ore more identical vectors in the given\n;; vectors\n\n(declaim (inline %median3))\n(defun %median3 (x y z order)\n (if (funcall order x y)\n (if (funcall order y z)\n y\n (if (funcall order z x)\n x\n z))\n (if (funcall order z y)\n y\n (if (funcall order x z)\n x\n z))))\n\n(defun parallel-sort! (vector order &rest vectors)\n \"Destructively sorts VECTOR w.r.t. ORDER and applies the same permutation to\nall the vectors in VECTORS.\n\nNote: not randomized; shuffle the inputs if necessary\"\n (declare (vector vector))\n (labels\n ((recur (left right)\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3 (aref vector l)\n (aref vector (ash (+ l r) -1))\n (aref vector r)\n order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall order (aref vector l) pivot)\n do (incf l 1))\n (loop while (funcall order pivot (aref vector r))\n do (decf r 1))\n (when (>= l r)\n (return))\n (rotatef (aref vector l) (aref vector r))\n (dolist (v vectors)\n (rotatef (aref v l) (aref v r)))\n (incf l 1)\n (decf r 1))\n (recur left (- l 1))\n (recur (+ r 1) right)))))\n (recur 0 (- (length vector) 1))\n vector))\n\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (sb-ext:muffle-conditions warning))\n (sb-c:define-source-transform parallel-sort! (vector order &rest vectors)\n (let ((vec (gensym))\n (vecs (loop for _ in vectors collect (gensym))))\n `(let ((,vec ,vector)\n ,@(loop for v in vectors\n for sym in vecs\n collect `(,sym ,v)))\n (labels\n ((recur (left right)\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3 (aref ,vec l)\n (aref ,vec (ash (+ l r) -1))\n (aref ,vec r)\n ,order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall ,order (aref ,vec l) pivot)\n do (incf l 1))\n (loop while (funcall ,order pivot (aref ,vec r))\n do (decf r 1))\n (when (>= l r)\n (return))\n (rotatef (aref ,vec l) (aref ,vec r))\n ,@(loop for sym in vecs\n collect `(rotatef (aref ,sym l) (aref ,sym r)))\n (incf l 1)\n (decf r 1))\n (recur left (- l 1))\n (recur (+ r 1) right)))))\n (recur 0 (- (length ,vec) 1))\n ,vec))))))\n\n;;;\n;;; Disjoint set by Union-Find algorithm over arbitrary monoid\n;;;\n\n;; not tested\n\n(defpackage :cp/abstract-disjoint-set\n (:use :cl)\n (:export #:define-disjoint-set))\n(in-package :cp/abstract-disjoint-set)\n\n(defmacro define-disjoint-set (name &key (operation '#'+) (element-type 'fixnum) (union-by-size t) conc-name)\n (check-type name symbol)\n (let* ((conc-string (if conc-name\n (symbol-name conc-name)\n (format nil \"~A-\" (symbol-name name))))\n (constructor (intern (format nil \"MAKE-~A\" (symbol-name name))))\n (rooter (intern (format nil \"~AROOT\" conc-string)))\n (reffer (intern (format nil \"~AREF\" conc-string)))\n (uniter (intern (format nil \"~AUNITE!\" conc-string)))\n (connectivity-checker (intern (format nil \"~ACONNECTED-P\" conc-string)))\n (size-getter (intern (format nil \"~ASIZE\" conc-string)))\n (data-accessor (intern (format nil \"~ADATA\" conc-string)))\n (values-accessor (intern (format nil \"~AVALUES\" conc-string))))\n `(progn\n (defstruct (,name\n (:constructor ,constructor\n (size\n &optional\n (contents (make-array size :element-type ',element-type))\n &aux\n (values\n (prog1 contents\n (assert (= (length contents) size))))\n (data (make-array size :element-type 'fixnum :initial-element -1))))\n ,@(when conc-name `((:conc-name ,(intern conc-string)))))\n (data nil :type (simple-array fixnum (*)))\n (values nil :type (simple-array ,element-type (*))))\n \n (declaim (inline ,rooter)\n (ftype (function * (values (mod #.array-total-size-limit) &optional))\n ,rooter))\n (defun ,rooter (,name x)\n \"Returns the root of X.\"\n (declare ((mod #.array-total-size-limit) x))\n (let ((data (,data-accessor ,name)))\n (labels ((recur (x)\n (if (< (aref data x) 0)\n x\n (setf (aref data x) (recur (aref data x))))))\n (recur x))))\n \n (declaim (inline ,reffer))\n (defun ,reffer (,name x)\n (aref (,values-accessor ,name)\n (,rooter ,name x)))\n \n (declaim (inline (setf ,reffer)))\n (defun (setf ,reffer) (new-value ,name x)\n (setf (aref (,values-accessor ,name)\n (,rooter ,name x))\n new-value))\n \n (declaim (inline ,uniter))\n (defun ,uniter (,name x1 x2)\n \"Destructively unites X1 and X2 and returns true iff X1 and X2 become\nconnected for the first time. (If UNION-BY-SIZE is disabled, X1 becomes root.)\"\n (let ((root1 (,rooter ,name x1))\n (root2 (,rooter ,name x2)))\n (unless (= root1 root2)\n (let ((data (,data-accessor ,name))\n (values (,values-accessor ,name)))\n ;; ensure the size of root1 >= the size of root2\n ,@(when union-by-size\n '((when (> (aref data root1) (aref data root2))\n (rotatef root1 root2))))\n (incf (aref data root1) (aref data root2))\n (setf (aref values root1)\n (funcall ,operation (aref values root2) (aref values root1)))\n (setf (aref data root2) root1)))))\n\n (declaim (inline ,connectivity-checker))\n (defun ,connectivity-checker (,name x1 x2)\n \"Returns true iff X1 and X2 have the same root.\"\n (= (,rooter ,name x1) (,rooter ,name x2)))\n\n (declaim (inline ,size-getter))\n (defun ,size-getter (,name x)\n \"Returns the size of the connected component to which X belongs.\"\n (- (aref (,data-accessor ,name)\n (,rooter ,name x)))))))\n\n#+(or)\n(define-disjoint-set disjoint-set\n :operation #'max\n :element-type fixnum\n :conc-name ds-\n :union-by-size nil)\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/abstract-disjoint-set :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/parallel-sort :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/read-fixnum :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(define-disjoint-set disjoint-set\n :operation #'+\n :element-type uint62\n :conc-name ds-)\n\n(defun main ()\n (declare #.cl-user::opt)\n (let* ((n (read))\n (m (read))\n (xs (make-array n :element-type 'uint62 :initial-element 0))\n (as (make-array m :element-type 'uint31 :initial-element 0))\n (bs (make-array m :element-type 'uint31 :initial-element 0))\n (ys (make-array m :element-type 'uint31 :initial-element 0))\n (graph (make-array n :element-type 'list :initial-element nil)))\n (dotimes (i n)\n (setf (aref xs i) (read-fixnum)))\n (dotimes (i m)\n (setf (aref as i) (- (read-fixnum) 1)\n (aref bs i) (- (read-fixnum) 1)\n (aref ys i) (read-fixnum)))\n (parallel-sort! ys #'< as bs)\n (dotimes (i m)\n (push i (aref graph (aref as i)))\n (push i (aref graph (aref bs i))))\n (let ((dset (make-disjoint-set n xs))\n (flags (make-array m :element-type 'bit :initial-element 0))\n (res (make-array m :element-type 'bit :initial-element 0)))\n (dotimes (i m)\n (let* ((a (aref as i))\n (b (aref bs i))\n (y (aref ys i)))\n (ds-unite! dset a b)\n (when (<= y (ds-ref dset a))\n (setf (aref flags i) 1))))\n (loop for i from (- m 1) downto 0\n for a = (aref as i)\n for max-y = (aref ys i)\n when (and (= 1 (aref flags i)) (= 0 (aref res i)))\n do (sb-int:named-let dfs ((v a))\n (dolist (eidx (aref graph v))\n (let* ((a (aref as eidx))\n (b (aref bs eidx))\n (y (aref ys eidx))\n (next-v (if (= a v) b a)))\n (when (and (= 0 (aref res eidx))\n (<= y max-y))\n (setf (aref res eidx) 1)\n (dfs next-v))))))\n (println (- m (count 1 res))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"2\n\"\n (run \"4 4\n2 3 5 7\n1 2 7\n1 3 9\n2 3 12\n3 4 18\n\" nil)))\n (it.bese.fiveam:is\n (equal \"4\n\"\n (run \"6 10\n4 4 1 1 1 7\n3 5 19\n2 5 20\n4 5 8\n1 6 16\n2 3 9\n3 6 16\n3 4 1\n2 6 20\n2 4 19\n1 2 9\n\" nil)))\n (it.bese.fiveam:is\n (equal \"8\n\"\n (run \"10 9\n81 16 73 7 2 61 86 38 90 28\n6 8 725\n3 10 12\n1 4 558\n4 9 615\n5 6 942\n8 9 918\n2 7 720\n4 7 292\n7 10 414\n\" nil))))\n", "problem_context": "Score : 800 points\n\nProblem Statement\n\nThere is a connected undirected graph with N vertices and M edges.\nThe vertices are numbered 1 to N, and the edges are numbered 1 to M.\nAlso, each of these vertices and edges has a specified weight.\nVertex i has a weight of X_i; Edge i has a weight of Y_i and connects Vertex A_i and B_i.\n\nWe would like to remove zero or more edges so that the following condition is satisfied:\n\nFor each edge that is not removed, the sum of the weights of the vertices in the connected component containing that edge, is greater than or equal to the weight of that edge.\n\nFind the minimum number of edges that need to be removed.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\nN-1 \\leq M \\leq 10^5\n\n1 \\leq X_i \\leq 10^9\n\n1 \\leq A_i < B_i \\leq N\n\n1 \\leq Y_i \\leq 10^9\n\n(A_i,B_i) \\neq (A_j,B_j) (i \\neq j)\n\nThe given graph is connected.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nX_1 X_2 ... X_N\nA_1 B_1 Y_1\nA_2 B_2 Y_2\n:\nA_M B_M Y_M\n\nOutput\n\nFind the minimum number of edges that need to be removed.\n\nSample Input 1\n\n4 4\n2 3 5 7\n1 2 7\n1 3 9\n2 3 12\n3 4 18\n\nSample Output 1\n\n2\n\nAssume that we removed Edge 3 and 4.\nIn this case, the connected component containing Edge 1 contains Vertex 1, 2 and 3, and the sum of the weights of these vertices is 2+3+5=10.\nThe weight of Edge 1 is 7, so the condition is satisfied for Edge 1.\nSimilarly, it can be seen that the condition is also satisfied for Edge 2.\nThus, a graph satisfying the condition can be obtained by removing two edges.\n\nThe condition cannot be satisfied by removing one or less edges, so the answer is 2.\n\nSample Input 2\n\n6 10\n4 4 1 1 1 7\n3 5 19\n2 5 20\n4 5 8\n1 6 16\n2 3 9\n3 6 16\n3 4 1\n2 6 20\n2 4 19\n1 2 9\n\nSample Output 2\n\n4\n\nSample Input 3\n\n10 9\n81 16 73 7 2 61 86 38 90 28\n6 8 725\n3 10 12\n1 4 558\n4 9 615\n5 6 942\n8 9 918\n2 7 720\n4 7 292\n7 10 414\n\nSample Output 3\n\n8", "sample_input": "4 4\n2 3 5 7\n1 2 7\n1 3 9\n2 3 12\n3 4 18\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03143", "source_text": "Score : 800 points\n\nProblem Statement\n\nThere is a connected undirected graph with N vertices and M edges.\nThe vertices are numbered 1 to N, and the edges are numbered 1 to M.\nAlso, each of these vertices and edges has a specified weight.\nVertex i has a weight of X_i; Edge i has a weight of Y_i and connects Vertex A_i and B_i.\n\nWe would like to remove zero or more edges so that the following condition is satisfied:\n\nFor each edge that is not removed, the sum of the weights of the vertices in the connected component containing that edge, is greater than or equal to the weight of that edge.\n\nFind the minimum number of edges that need to be removed.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\nN-1 \\leq M \\leq 10^5\n\n1 \\leq X_i \\leq 10^9\n\n1 \\leq A_i < B_i \\leq N\n\n1 \\leq Y_i \\leq 10^9\n\n(A_i,B_i) \\neq (A_j,B_j) (i \\neq j)\n\nThe given graph is connected.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nX_1 X_2 ... X_N\nA_1 B_1 Y_1\nA_2 B_2 Y_2\n:\nA_M B_M Y_M\n\nOutput\n\nFind the minimum number of edges that need to be removed.\n\nSample Input 1\n\n4 4\n2 3 5 7\n1 2 7\n1 3 9\n2 3 12\n3 4 18\n\nSample Output 1\n\n2\n\nAssume that we removed Edge 3 and 4.\nIn this case, the connected component containing Edge 1 contains Vertex 1, 2 and 3, and the sum of the weights of these vertices is 2+3+5=10.\nThe weight of Edge 1 is 7, so the condition is satisfied for Edge 1.\nSimilarly, it can be seen that the condition is also satisfied for Edge 2.\nThus, a graph satisfying the condition can be obtained by removing two edges.\n\nThe condition cannot be satisfied by removing one or less edges, so the answer is 2.\n\nSample Input 2\n\n6 10\n4 4 1 1 1 7\n3 5 19\n2 5 20\n4 5 8\n1 6 16\n2 3 9\n3 6 16\n3 4 1\n2 6 20\n2 4 19\n1 2 9\n\nSample Output 2\n\n4\n\nSample Input 3\n\n10 9\n81 16 73 7 2 61 86 38 90 28\n6 8 725\n3 10 12\n1 4 558\n4 9 615\n5 6 942\n8 9 918\n2 7 720\n4 7 292\n7 10 414\n\nSample Output 3\n\n8", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 15162, "cpu_time_ms": 105, "memory_kb": 46716}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s424973994", "group_id": "codeNet:p03145", "input_text": "(princ (/ (* (read) (read)) 2))", "language": "Lisp", "metadata": {"date": 1590717808, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03145.html", "problem_id": "p03145", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03145/input.txt", "sample_output_relpath": "derived/input_output/data/p03145/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03145/Lisp/s424973994.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s424973994", "user_id": "u425762225"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(princ (/ (* (read) (read)) 2))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere is a right triangle ABC with ∠ABC=90°.\n\nGiven the lengths of the three sides, |AB|,|BC| and |CA|, find the area of the right triangle ABC.\n\nIt is guaranteed that the area of the triangle ABC is an integer.\n\nConstraints\n\n1 \\leq |AB|,|BC|,|CA| \\leq 100\n\nAll values in input are integers.\n\nThe area of the triangle ABC is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\n|AB| |BC| |CA|\n\nOutput\n\nPrint the area of the triangle ABC.\n\nSample Input 1\n\n3 4 5\n\nSample Output 1\n\n6\n\nThis triangle has an area of 6.\n\nSample Input 2\n\n5 12 13\n\nSample Output 2\n\n30\n\nThis triangle has an area of 30.\n\nSample Input 3\n\n45 28 53\n\nSample Output 3\n\n630\n\nThis triangle has an area of 630.", "sample_input": "3 4 5\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03145", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere is a right triangle ABC with ∠ABC=90°.\n\nGiven the lengths of the three sides, |AB|,|BC| and |CA|, find the area of the right triangle ABC.\n\nIt is guaranteed that the area of the triangle ABC is an integer.\n\nConstraints\n\n1 \\leq |AB|,|BC|,|CA| \\leq 100\n\nAll values in input are integers.\n\nThe area of the triangle ABC is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\n|AB| |BC| |CA|\n\nOutput\n\nPrint the area of the triangle ABC.\n\nSample Input 1\n\n3 4 5\n\nSample Output 1\n\n6\n\nThis triangle has an area of 6.\n\nSample Input 2\n\n5 12 13\n\nSample Output 2\n\n30\n\nThis triangle has an area of 30.\n\nSample Input 3\n\n45 28 53\n\nSample Output 3\n\n630\n\nThis triangle has an area of 630.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 31, "cpu_time_ms": 18, "memory_kb": 3684}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s690113704", "group_id": "codeNet:p03145", "input_text": "(setq a (read) b (read) c (read))\n(princ (/ (* a b) 2))", "language": "Lisp", "metadata": {"date": 1561951136, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03145.html", "problem_id": "p03145", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03145/input.txt", "sample_output_relpath": "derived/input_output/data/p03145/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03145/Lisp/s690113704.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s690113704", "user_id": "u480300350"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(setq a (read) b (read) c (read))\n(princ (/ (* a b) 2))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere is a right triangle ABC with ∠ABC=90°.\n\nGiven the lengths of the three sides, |AB|,|BC| and |CA|, find the area of the right triangle ABC.\n\nIt is guaranteed that the area of the triangle ABC is an integer.\n\nConstraints\n\n1 \\leq |AB|,|BC|,|CA| \\leq 100\n\nAll values in input are integers.\n\nThe area of the triangle ABC is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\n|AB| |BC| |CA|\n\nOutput\n\nPrint the area of the triangle ABC.\n\nSample Input 1\n\n3 4 5\n\nSample Output 1\n\n6\n\nThis triangle has an area of 6.\n\nSample Input 2\n\n5 12 13\n\nSample Output 2\n\n30\n\nThis triangle has an area of 30.\n\nSample Input 3\n\n45 28 53\n\nSample Output 3\n\n630\n\nThis triangle has an area of 630.", "sample_input": "3 4 5\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03145", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere is a right triangle ABC with ∠ABC=90°.\n\nGiven the lengths of the three sides, |AB|,|BC| and |CA|, find the area of the right triangle ABC.\n\nIt is guaranteed that the area of the triangle ABC is an integer.\n\nConstraints\n\n1 \\leq |AB|,|BC|,|CA| \\leq 100\n\nAll values in input are integers.\n\nThe area of the triangle ABC is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\n|AB| |BC| |CA|\n\nOutput\n\nPrint the area of the triangle ABC.\n\nSample Input 1\n\n3 4 5\n\nSample Output 1\n\n6\n\nThis triangle has an area of 6.\n\nSample Input 2\n\n5 12 13\n\nSample Output 2\n\n30\n\nThis triangle has an area of 30.\n\nSample Input 3\n\n45 28 53\n\nSample Output 3\n\n630\n\nThis triangle has an area of 630.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 55, "cpu_time_ms": 80, "memory_kb": 8416}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s444616922", "group_id": "codeNet:p03145", "input_text": "(let ((a (read))\n (b (read))\n (c (read))\n s)\n (setf s (/ (+ a b c) 2))\n (princ (rational (sqrt (* s (- s a) (- s b) (- s c))))))", "language": "Lisp", "metadata": {"date": 1550173880, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03145.html", "problem_id": "p03145", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03145/input.txt", "sample_output_relpath": "derived/input_output/data/p03145/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03145/Lisp/s444616922.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s444616922", "user_id": "u994767958"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (c (read))\n s)\n (setf s (/ (+ a b c) 2))\n (princ (rational (sqrt (* s (- s a) (- s b) (- s c))))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere is a right triangle ABC with ∠ABC=90°.\n\nGiven the lengths of the three sides, |AB|,|BC| and |CA|, find the area of the right triangle ABC.\n\nIt is guaranteed that the area of the triangle ABC is an integer.\n\nConstraints\n\n1 \\leq |AB|,|BC|,|CA| \\leq 100\n\nAll values in input are integers.\n\nThe area of the triangle ABC is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\n|AB| |BC| |CA|\n\nOutput\n\nPrint the area of the triangle ABC.\n\nSample Input 1\n\n3 4 5\n\nSample Output 1\n\n6\n\nThis triangle has an area of 6.\n\nSample Input 2\n\n5 12 13\n\nSample Output 2\n\n30\n\nThis triangle has an area of 30.\n\nSample Input 3\n\n45 28 53\n\nSample Output 3\n\n630\n\nThis triangle has an area of 630.", "sample_input": "3 4 5\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03145", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere is a right triangle ABC with ∠ABC=90°.\n\nGiven the lengths of the three sides, |AB|,|BC| and |CA|, find the area of the right triangle ABC.\n\nIt is guaranteed that the area of the triangle ABC is an integer.\n\nConstraints\n\n1 \\leq |AB|,|BC|,|CA| \\leq 100\n\nAll values in input are integers.\n\nThe area of the triangle ABC is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\n|AB| |BC| |CA|\n\nOutput\n\nPrint the area of the triangle ABC.\n\nSample Input 1\n\n3 4 5\n\nSample Output 1\n\n6\n\nThis triangle has an area of 6.\n\nSample Input 2\n\n5 12 13\n\nSample Output 2\n\n30\n\nThis triangle has an area of 30.\n\nSample Input 3\n\n45 28 53\n\nSample Output 3\n\n630\n\nThis triangle has an area of 630.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 151, "cpu_time_ms": 10, "memory_kb": 3304}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s990239548", "group_id": "codeNet:p03145", "input_text": "(princ (/ (* (read) (read)) 2))", "language": "Lisp", "metadata": {"date": 1548096636, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03145.html", "problem_id": "p03145", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03145/input.txt", "sample_output_relpath": "derived/input_output/data/p03145/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03145/Lisp/s990239548.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s990239548", "user_id": "u610490393"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(princ (/ (* (read) (read)) 2))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere is a right triangle ABC with ∠ABC=90°.\n\nGiven the lengths of the three sides, |AB|,|BC| and |CA|, find the area of the right triangle ABC.\n\nIt is guaranteed that the area of the triangle ABC is an integer.\n\nConstraints\n\n1 \\leq |AB|,|BC|,|CA| \\leq 100\n\nAll values in input are integers.\n\nThe area of the triangle ABC is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\n|AB| |BC| |CA|\n\nOutput\n\nPrint the area of the triangle ABC.\n\nSample Input 1\n\n3 4 5\n\nSample Output 1\n\n6\n\nThis triangle has an area of 6.\n\nSample Input 2\n\n5 12 13\n\nSample Output 2\n\n30\n\nThis triangle has an area of 30.\n\nSample Input 3\n\n45 28 53\n\nSample Output 3\n\n630\n\nThis triangle has an area of 630.", "sample_input": "3 4 5\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03145", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere is a right triangle ABC with ∠ABC=90°.\n\nGiven the lengths of the three sides, |AB|,|BC| and |CA|, find the area of the right triangle ABC.\n\nIt is guaranteed that the area of the triangle ABC is an integer.\n\nConstraints\n\n1 \\leq |AB|,|BC|,|CA| \\leq 100\n\nAll values in input are integers.\n\nThe area of the triangle ABC is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\n|AB| |BC| |CA|\n\nOutput\n\nPrint the area of the triangle ABC.\n\nSample Input 1\n\n3 4 5\n\nSample Output 1\n\n6\n\nThis triangle has an area of 6.\n\nSample Input 2\n\n5 12 13\n\nSample Output 2\n\n30\n\nThis triangle has an area of 30.\n\nSample Input 3\n\n45 28 53\n\nSample Output 3\n\n630\n\nThis triangle has an area of 630.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 31, "cpu_time_ms": 6, "memory_kb": 2792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s371640485", "group_id": "codeNet:p03146", "input_text": "(princ(do((s(read)(if(=(mod s 2)0)(/ s 2)(1+(* s 3))))(i 2(1+ i)))((> 2 s)i)))", "language": "Lisp", "metadata": {"date": 1548041525, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03146.html", "problem_id": "p03146", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03146/input.txt", "sample_output_relpath": "derived/input_output/data/p03146/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03146/Lisp/s371640485.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s371640485", "user_id": "u657913472"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(princ(do((s(read)(if(=(mod s 2)0)(/ s 2)(1+(* s 3))))(i 2(1+ i)))((> 2 s)i)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nA sequence a=\\{a_1,a_2,a_3,......\\} is determined as follows:\n\nThe first term s is given as input.\n\nLet f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.\n\na_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.\n\nFind the minimum integer m that satisfies the following condition:\n\nThere exists an integer n such that a_m = a_n (m > n).\n\nConstraints\n\n1 \\leq s \\leq 100\n\nAll values in input are integers.\n\nIt is guaranteed that all elements in a and the minimum m that satisfies the condition are at most 1000000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the minimum integer m that satisfies the condition.\n\nSample Input 1\n\n8\n\nSample Output 1\n\n5\n\na=\\{8,4,2,1,4,2,1,4,2,1,......\\}. As a_5=a_2, the answer is 5.\n\nSample Input 2\n\n7\n\nSample Output 2\n\n18\n\na=\\{7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1,4,2,1,......\\}.\n\nSample Input 3\n\n54\n\nSample Output 3\n\n114", "sample_input": "8\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03146", "source_text": "Score : 200 points\n\nProblem Statement\n\nA sequence a=\\{a_1,a_2,a_3,......\\} is determined as follows:\n\nThe first term s is given as input.\n\nLet f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.\n\na_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.\n\nFind the minimum integer m that satisfies the following condition:\n\nThere exists an integer n such that a_m = a_n (m > n).\n\nConstraints\n\n1 \\leq s \\leq 100\n\nAll values in input are integers.\n\nIt is guaranteed that all elements in a and the minimum m that satisfies the condition are at most 1000000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the minimum integer m that satisfies the condition.\n\nSample Input 1\n\n8\n\nSample Output 1\n\n5\n\na=\\{8,4,2,1,4,2,1,4,2,1,......\\}. As a_5=a_2, the answer is 5.\n\nSample Input 2\n\n7\n\nSample Output 2\n\n18\n\na=\\{7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1,4,2,1,......\\}.\n\nSample Input 3\n\n54\n\nSample Output 3\n\n114", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 78, "cpu_time_ms": 260, "memory_kb": 12516}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s489115245", "group_id": "codeNet:p03155", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(defun main ()\n (let* ((n (read))\n (h (read))\n (w (read)))\n (println (* (+ n (- h) 1) (+ n (- w) 1)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1547328625, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03155.html", "problem_id": "p03155", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03155/input.txt", "sample_output_relpath": "derived/input_output/data/p03155/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03155/Lisp/s489115245.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s489115245", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(defun main ()\n (let* ((n (read))\n (h (read))\n (w (read)))\n (println (* (+ n (- h) 1) (+ n (- w) 1)))))\n\n#-swank(main)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIt has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board.\n\nThe bulletin board is in the form of a grid with N rows and N columns, and the notice will occupy a rectangular region with H rows and W columns.\n\nHow many ways are there to choose where to put the notice so that it completely covers exactly HW squares?\n\nConstraints\n\n1 \\leq H, W \\leq N \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nH\nW\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3\n2\n3\n\nSample Output 1\n\n2\n\nThere are two ways to put the notice, as follows:\n\n### ...\n### ###\n... ###\n\nHere, # represents a square covered by the notice, and . represents a square not covered.\n\nSample Input 2\n\n100\n1\n1\n\nSample Output 2\n\n10000\n\nSample Input 3\n\n5\n4\n2\n\nSample Output 3\n\n8", "sample_input": "3\n2\n3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03155", "source_text": "Score : 100 points\n\nProblem Statement\n\nIt has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board.\n\nThe bulletin board is in the form of a grid with N rows and N columns, and the notice will occupy a rectangular region with H rows and W columns.\n\nHow many ways are there to choose where to put the notice so that it completely covers exactly HW squares?\n\nConstraints\n\n1 \\leq H, W \\leq N \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nH\nW\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3\n2\n3\n\nSample Output 1\n\n2\n\nThere are two ways to put the notice, as follows:\n\n### ...\n### ###\n... ###\n\nHere, # represents a square covered by the notice, and . represents a square not covered.\n\nSample Input 2\n\n100\n1\n1\n\nSample Output 2\n\n10000\n\nSample Input 3\n\n5\n4\n2\n\nSample Output 3\n\n8", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1025, "cpu_time_ms": 145, "memory_kb": 15592}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s284253055", "group_id": "codeNet:p03162", "input_text": "(defun solve (n points)\n (let ((happiness (make-array (list n 3) :element-type 'fixnum))\n (first-day (pop points)))\n (setf (aref happiness 0 0) (nth 0 first-day))\n (setf (aref happiness 0 1) (nth 1 first-day))\n (setf (aref happiness 0 2) (nth 2 first-day))\n (loop for i from 1\n for (a b c) in points\n do\n (setf (aref happiness i 0)\n (+ (max (aref happiness (1- i) 1)\n (aref happiness (1- i) 2))\n a))\n (setf (aref happiness i 1)\n (+ (max (aref happiness (1- i) 0)\n (aref happiness (1- i) 2))\n b))\n (setf (aref happiness i 2)\n (+ (max (aref happiness (1- i) 0)\n (aref happiness (1- i) 1))\n c)))\n (max (aref happiness (1- n) 0)\n (aref happiness (1- n) 1)\n (aref happiness (1- n) 2))))\n\n#-swank\n(let* ((n (read))\n (points (loop repeat n collect (list (read) (read) (read)))))\n (format t \"~A~%\" (solve n points)))\n", "language": "Lisp", "metadata": {"date": 1580225341, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03162.html", "problem_id": "p03162", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03162/input.txt", "sample_output_relpath": "derived/input_output/data/p03162/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03162/Lisp/s284253055.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s284253055", "user_id": "u202886318"}, "prompt_components": {"gold_output": "210\n", "input_to_evaluate": "(defun solve (n points)\n (let ((happiness (make-array (list n 3) :element-type 'fixnum))\n (first-day (pop points)))\n (setf (aref happiness 0 0) (nth 0 first-day))\n (setf (aref happiness 0 1) (nth 1 first-day))\n (setf (aref happiness 0 2) (nth 2 first-day))\n (loop for i from 1\n for (a b c) in points\n do\n (setf (aref happiness i 0)\n (+ (max (aref happiness (1- i) 1)\n (aref happiness (1- i) 2))\n a))\n (setf (aref happiness i 1)\n (+ (max (aref happiness (1- i) 0)\n (aref happiness (1- i) 2))\n b))\n (setf (aref happiness i 2)\n (+ (max (aref happiness (1- i) 0)\n (aref happiness (1- i) 1))\n c)))\n (max (aref happiness (1- n) 0)\n (aref happiness (1- n) 1)\n (aref happiness (1- n) 2))))\n\n#-swank\n(let* ((n (read))\n (points (loop repeat n collect (list (read) (read) (read)))))\n (format t \"~A~%\" (solve n points)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTaro's summer vacation starts tomorrow, and he has decided to make plans for it now.\n\nThe vacation consists of N days.\nFor each i (1 \\leq i \\leq N), Taro will choose one of the following activities and do it on the i-th day:\n\nA: Swim in the sea. Gain a_i points of happiness.\n\nB: Catch bugs in the mountains. Gain b_i points of happiness.\n\nC: Do homework at home. Gain c_i points of happiness.\n\nAs Taro gets bored easily, he cannot do the same activities for two or more consecutive days.\n\nFind the maximum possible total points of happiness that Taro gains.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq a_i, b_i, c_i \\leq 10^4\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 b_1 c_1\na_2 b_2 c_2\n:\na_N b_N c_N\n\nOutput\n\nPrint the maximum possible total points of happiness that Taro gains.\n\nSample Input 1\n\n3\n10 40 70\n20 50 80\n30 60 90\n\nSample Output 1\n\n210\n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210 points of happiness.\n\nSample Input 2\n\n1\n100 10 1\n\nSample Output 2\n\n100\n\nSample Input 3\n\n7\n6 7 8\n8 8 3\n2 5 2\n7 8 6\n4 6 8\n2 3 4\n7 5 1\n\nSample Output 3\n\n46\n\nTaro should do activities in the order C, A, B, A, C, B, A.", "sample_input": "3\n10 40 70\n20 50 80\n30 60 90\n"}, "reference_outputs": ["210\n"], "source_document_id": "p03162", "source_text": "Score : 100 points\n\nProblem Statement\n\nTaro's summer vacation starts tomorrow, and he has decided to make plans for it now.\n\nThe vacation consists of N days.\nFor each i (1 \\leq i \\leq N), Taro will choose one of the following activities and do it on the i-th day:\n\nA: Swim in the sea. Gain a_i points of happiness.\n\nB: Catch bugs in the mountains. Gain b_i points of happiness.\n\nC: Do homework at home. Gain c_i points of happiness.\n\nAs Taro gets bored easily, he cannot do the same activities for two or more consecutive days.\n\nFind the maximum possible total points of happiness that Taro gains.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq a_i, b_i, c_i \\leq 10^4\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 b_1 c_1\na_2 b_2 c_2\n:\na_N b_N c_N\n\nOutput\n\nPrint the maximum possible total points of happiness that Taro gains.\n\nSample Input 1\n\n3\n10 40 70\n20 50 80\n30 60 90\n\nSample Output 1\n\n210\n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210 points of happiness.\n\nSample Input 2\n\n1\n100 10 1\n\nSample Output 2\n\n100\n\nSample Input 3\n\n7\n6 7 8\n8 8 3\n2 5 2\n7 8 6\n4 6 8\n2 3 4\n7 5 1\n\nSample Output 3\n\n46\n\nTaro should do activities in the order C, A, B, A, C, B, A.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1068, "cpu_time_ms": 599, "memory_kb": 66024}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s941455423", "group_id": "codeNet:p03164", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ most-positive-fixnum)\n(defconstant +max+ 100001)\n\n(defun main ()\n (let* ((n (read-fixnum))\n (limit (read-fixnum))\n (dp (make-array (list (+ n 1) (+ +max+ 1)) :element-type 'uint62 :initial-element +inf+)))\n (setf (aref dp 0 0) 0)\n (loop for x from 1 to n\n for w = (read-fixnum)\n for v = (read-fixnum)\n do (dotimes (y (+ +max+ 1))\n (setf (aref dp x y)\n (if (>= y v)\n (min (+ w (aref dp (- x 1) (- y v)))\n (aref dp (- x 1) y))\n (aref dp (- x 1) y)))))\n (loop for y from +max+ downto 0\n when (<= (aref dp n y) limit)\n do (println y)\n (return))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 8\n3 30\n4 50\n5 60\n\"\n \"90\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 1000000000\n1000000000 10\n\"\n \"10\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 15\n6 5\n5 6\n6 4\n6 6\n3 5\n7 2\n\"\n \"17\n\")))\n", "language": "Lisp", "metadata": {"date": 1593260991, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03164.html", "problem_id": "p03164", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03164/input.txt", "sample_output_relpath": "derived/input_output/data/p03164/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03164/Lisp/s941455423.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s941455423", "user_id": "u352600849"}, "prompt_components": {"gold_output": "90\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ most-positive-fixnum)\n(defconstant +max+ 100001)\n\n(defun main ()\n (let* ((n (read-fixnum))\n (limit (read-fixnum))\n (dp (make-array (list (+ n 1) (+ +max+ 1)) :element-type 'uint62 :initial-element +inf+)))\n (setf (aref dp 0 0) 0)\n (loop for x from 1 to n\n for w = (read-fixnum)\n for v = (read-fixnum)\n do (dotimes (y (+ +max+ 1))\n (setf (aref dp x y)\n (if (>= y v)\n (min (+ w (aref dp (- x 1) (- y v)))\n (aref dp (- x 1) y))\n (aref dp (- x 1) y)))))\n (loop for y from +max+ downto 0\n when (<= (aref dp n y) limit)\n do (println y)\n (return))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 8\n3 30\n4 50\n5 60\n\"\n \"90\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 1000000000\n1000000000 10\n\"\n \"10\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 15\n6 5\n5 6\n6 4\n6 6\n3 5\n7 2\n\"\n \"17\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are N items, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N), Item i has a weight of w_i and a value of v_i.\n\nTaro has decided to choose some of the N items and carry them home in a knapsack.\nThe capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W.\n\nFind the maximum possible sum of the values of items that Taro takes home.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n1 \\leq W \\leq 10^9\n\n1 \\leq w_i \\leq W\n\n1 \\leq v_i \\leq 10^3\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN W\nw_1 v_1\nw_2 v_2\n:\nw_N v_N\n\nOutput\n\nPrint the maximum possible sum of the values of items that Taro takes home.\n\nSample Input 1\n\n3 8\n3 30\n4 50\n5 60\n\nSample Output 1\n\n90\n\nItems 1 and 3 should be taken.\nThen, the sum of the weights is 3 + 5 = 8, and the sum of the values is 30 + 60 = 90.\n\nSample Input 2\n\n1 1000000000\n1000000000 10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n6 15\n6 5\n5 6\n6 4\n6 6\n3 5\n7 2\n\nSample Output 3\n\n17\n\nItems 2, 4 and 5 should be taken.\nThen, the sum of the weights is 5 + 6 + 3 = 14, and the sum of the values is 6 + 6 + 5 = 17.", "sample_input": "3 8\n3 30\n4 50\n5 60\n"}, "reference_outputs": ["90\n"], "source_document_id": "p03164", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are N items, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N), Item i has a weight of w_i and a value of v_i.\n\nTaro has decided to choose some of the N items and carry them home in a knapsack.\nThe capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W.\n\nFind the maximum possible sum of the values of items that Taro takes home.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n1 \\leq W \\leq 10^9\n\n1 \\leq w_i \\leq W\n\n1 \\leq v_i \\leq 10^3\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN W\nw_1 v_1\nw_2 v_2\n:\nw_N v_N\n\nOutput\n\nPrint the maximum possible sum of the values of items that Taro takes home.\n\nSample Input 1\n\n3 8\n3 30\n4 50\n5 60\n\nSample Output 1\n\n90\n\nItems 1 and 3 should be taken.\nThen, the sum of the weights is 3 + 5 = 8, and the sum of the values is 30 + 60 = 90.\n\nSample Input 2\n\n1 1000000000\n1000000000 10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n6 15\n6 5\n5 6\n6 4\n6 6\n3 5\n7 2\n\nSample Output 3\n\n17\n\nItems 2, 4 and 5 should be taken.\nThen, the sum of the weights is 5 + 6 + 3 = 14, and the sum of the values is 6 + 6 + 5 = 17.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4346, "cpu_time_ms": 24, "memory_kb": 26832}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s573922544", "group_id": "codeNet:p03169", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read-fixnum))\n (dp (make-array (list (+ n 1) (+ n 1) (+ n 1))\n :element-type 'double-float\n :initial-element 0d0))\n (init-x 0)\n (init-y 0)\n (init-z 0))\n (declare (uint8 n))\n (dotimes (i n)\n (ecase (read)\n (3 (incf init-x))\n (2 (incf init-y))\n (1 (incf init-z))))\n (labels ((%get (x y z)\n (if (and (<= 0 x n)\n (<= 0 y n)\n (<= 0 z n))\n (aref dp x y z)\n 0d0)))\n (dotimes (x (+ n 1))\n (dotimes (y (+ n 1))\n (dotimes (z (+ n 1))\n (unless (= x y z 0)\n (let ((num (+ n\n (* x (%get (- x 1) (+ y 1) z))\n (* y (%get x (- y 1) (+ z 1)))\n (* z (%get x y (- z 1)))))\n (denom (+ x y z)))\n (setf (aref dp x y z) (/ num denom)))))))\n (println (aref dp init-x init-y init-z)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 1 1\n\"\n \"5.5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n3\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 2\n\"\n \"4.5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n1 3 2 3 3 2 3 2 1 3\n\"\n \"54.48064457488221\n\")))\n", "language": "Lisp", "metadata": {"date": 1593285639, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03169.html", "problem_id": "p03169", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03169/input.txt", "sample_output_relpath": "derived/input_output/data/p03169/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03169/Lisp/s573922544.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s573922544", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5.5\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read-fixnum))\n (dp (make-array (list (+ n 1) (+ n 1) (+ n 1))\n :element-type 'double-float\n :initial-element 0d0))\n (init-x 0)\n (init-y 0)\n (init-z 0))\n (declare (uint8 n))\n (dotimes (i n)\n (ecase (read)\n (3 (incf init-x))\n (2 (incf init-y))\n (1 (incf init-z))))\n (labels ((%get (x y z)\n (if (and (<= 0 x n)\n (<= 0 y n)\n (<= 0 z n))\n (aref dp x y z)\n 0d0)))\n (dotimes (x (+ n 1))\n (dotimes (y (+ n 1))\n (dotimes (z (+ n 1))\n (unless (= x y z 0)\n (let ((num (+ n\n (* x (%get (- x 1) (+ y 1) z))\n (* y (%get x (- y 1) (+ z 1)))\n (* z (%get x y (- z 1)))))\n (denom (+ x y z)))\n (setf (aref dp x y z) (/ num denom)))))))\n (println (aref dp init-x init-y init-z)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 1 1\n\"\n \"5.5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n3\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 2\n\"\n \"4.5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n1 3 2 3 3 2 3 2 1 3\n\"\n \"54.48064457488221\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are N dishes, numbered 1, 2, \\ldots, N.\nInitially, for each i (1 \\leq i \\leq N), Dish i has a_i (1 \\leq a_i \\leq 3) pieces of sushi on it.\n\nTaro will perform the following operation repeatedly until all the pieces of sushi are eaten:\n\nRoll a die that shows the numbers 1, 2, \\ldots, N with equal probabilities, and let i be the outcome. If there are some pieces of sushi on Dish i, eat one of them; if there is none, do nothing.\n\nFind the expected number of times the operation is performed before all the pieces of sushi are eaten.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 300\n\n1 \\leq a_i \\leq 3\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 \\ldots a_N\n\nOutput\n\nPrint the expected number of times the operation is performed before all the pieces of sushi are eaten.\nThe output is considered correct when the relative difference is not greater than 10^{-9}.\n\nSample Input 1\n\n3\n1 1 1\n\nSample Output 1\n\n5.5\n\nThe expected number of operations before the first piece of sushi is eaten, is 1.\nAfter that, the expected number of operations before the second sushi is eaten, is 1.5.\nAfter that, the expected number of operations before the third sushi is eaten, is 3.\nThus, the expected total number of operations is 1 + 1.5 + 3 = 5.5.\n\nSample Input 2\n\n1\n3\n\nSample Output 2\n\n3\n\nOutputs such as 3.00, 3.000000003 and 2.999999997 will also be accepted.\n\nSample Input 3\n\n2\n1 2\n\nSample Output 3\n\n4.5\n\nSample Input 4\n\n10\n1 3 2 3 3 2 3 2 1 3\n\nSample Output 4\n\n54.48064457488221", "sample_input": "3\n1 1 1\n"}, "reference_outputs": ["5.5\n"], "source_document_id": "p03169", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are N dishes, numbered 1, 2, \\ldots, N.\nInitially, for each i (1 \\leq i \\leq N), Dish i has a_i (1 \\leq a_i \\leq 3) pieces of sushi on it.\n\nTaro will perform the following operation repeatedly until all the pieces of sushi are eaten:\n\nRoll a die that shows the numbers 1, 2, \\ldots, N with equal probabilities, and let i be the outcome. If there are some pieces of sushi on Dish i, eat one of them; if there is none, do nothing.\n\nFind the expected number of times the operation is performed before all the pieces of sushi are eaten.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 300\n\n1 \\leq a_i \\leq 3\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 \\ldots a_N\n\nOutput\n\nPrint the expected number of times the operation is performed before all the pieces of sushi are eaten.\nThe output is considered correct when the relative difference is not greater than 10^{-9}.\n\nSample Input 1\n\n3\n1 1 1\n\nSample Output 1\n\n5.5\n\nThe expected number of operations before the first piece of sushi is eaten, is 1.\nAfter that, the expected number of operations before the second sushi is eaten, is 1.5.\nAfter that, the expected number of operations before the third sushi is eaten, is 3.\nThus, the expected total number of operations is 1 + 1.5 + 3 = 5.5.\n\nSample Input 2\n\n1\n3\n\nSample Output 2\n\n3\n\nOutputs such as 3.00, 3.000000003 and 2.999999997 will also be accepted.\n\nSample Input 3\n\n2\n1 2\n\nSample Output 3\n\n4.5\n\nSample Input 4\n\n10\n1 3 2 3 3 2 3 2 1 3\n\nSample Output 4\n\n54.48064457488221", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4705, "cpu_time_ms": 30, "memory_kb": 26740}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s658977664", "group_id": "codeNet:p03171", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Memoization macro\n;;;\n\n;;\n;; Basic usage:\n;;\n;; (with-cache (:hash-table :test #'equal :key #'cons)\n;; (defun add (a b)\n;; (+ a b)))\n;; This function caches the returned values for already passed combinations of\n;; arguments. In this case ADD stores the key (CONS A B) and the returned value\n;; to a hash-table when (ADD A B) is evaluated for the first time. ADD returns\n;; the stored value when it is called with the same arguments (w.r.t. EQUAL)\n;; again.\n;;\n;; The storage for cache can be hash-table or array. Let's see an example for\n;; array:\n;; (with-cache (:array (10 20 30) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c) ... ))\n;; This form stores the value of FOO in an array created by (make-array (list 10\n;; 20 30) :initial-element -1 :element-type 'fixnum). Note that INITIAL-ELEMENT\n;; must always be given here as it is used as the flag expressing `not yet\n;; stored'. (Therefore INITIAL-ELEMENT should be a value FOO never takes.)\n;;\n;; If you want to ignore some arguments, you can put `*' in dimensions:\n;; (with-cache (:array (10 10 * 10) :initial-element -1)\n;; (defun foo (a b c d) ...)) ; then C is ignored when querying or storing cache\n;;\n;; Available definition forms in WITH-CACHE are DEFUN, LABELS, FLET, and\n;; SB-INT:NAMED-LET.\n;;\n;; You can trace the memoized function by :TRACE option:\n;; (with-cache (:array (10 10) :initial-element -1 :trace t)\n;; (defun foo (x y) ...))\n;; Then FOO is traced as with CL:TRACE.\n;;\n\n;; TODO & NOTE: Currently a memoized function is not enclosed with a block of\n;; the function name.\n\n;; FIXME: *RECURSION-DEPTH* should be included within the macro.\n(declaim (type (integer 0 #.most-positive-fixnum) *recursion-depth*))\n(defparameter *recursion-depth* 0)\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun %enclose-with-trace (fname args form)\n (let ((value (gensym)))\n `(progn\n (format t \"~&~A~A: (~A ~{~A~^ ~}) =>\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args))\n (let ((,value (let ((*recursion-depth* (1+ *recursion-depth*)))\n ,form)))\n (format t \"~&~A~A: (~A ~{~A~^ ~}) => ~A\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args)\n ,value)\n ,value))))\n\n (defun %extract-declarations (body)\n (remove-if-not (lambda (form) (and (consp form) (eql 'declare (car form))))\n body))\n\n (defun %parse-cache-form (cache-specifier)\n (let ((cache-type (car cache-specifier))\n (cache-attribs (cdr cache-specifier)))\n (assert (member cache-type '(:hash-table :array)))\n (let* ((dims-with-* (when (eql cache-type :array) (first cache-attribs)))\n (dims (remove '* dims-with-*))\n (rank (length dims))\n (rest-attribs (ecase cache-type\n (:hash-table cache-attribs)\n (:array (cdr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (trace-p (prog1 (getf rest-attribs :trace) (remf rest-attribs :trace)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array (list ,@dims) ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym \"CACHE\"))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels\n ((make-cache-querier (cache-type name args)\n (let ((res (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key '#'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (assert (= (length args) (length dims-with-*)))\n (let ((memoized-args (loop for dimension in dims-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value))))))))\n (if trace-p\n (%enclose-with-trace name args res)\n res)))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n ;; TODO: portable fill\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name)))))\n (values cache cache-form cache-type name-alias\n #'make-reset-name\n #'make-reset-form\n #'make-cache-querier)))))))\n\n(defmacro with-cache ((cache-type &rest cache-attribs) def-form)\n \"CACHE-TYPE := :HASH-TABLE | :ARRAY.\nDEF-FORM := definition form with DEFUN, LABELS, FLET, or SB-INT:NAMED-LET.\"\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form\n make-cache-querier)\n (%parse-cache-form (cons cache-type cache-attribs))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (defun ,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (defun ,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form)\n ((,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args)))\n ,@(cdr definitions))\n (declare (ignorable #',(funcall make-reset-name name)))\n ,@labels-body)))))\n ((nlet #+sbcl sb-int:named-let)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form) ,name ,bindings\n ,@(%extract-declarations body)\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))))))\n\n(defmacro with-caches (cache-specs def-form)\n \"DEF-FORM := definition form by LABELS or FLET.\n\n (with-caches (cache-spec1 cache-spec2)\n (labels ((f (x) ...) (g (y) ...))))\nis equivalent to the line up of\n (with-cache cache-spec1 (labels ((f (x) ...))))\nand\n (with-cache cache-spec2 (labels ((g (y) ...))))\n\nThis macro will be useful to do mutual recursion between memoized local\nfunctions.\"\n (assert (member (car def-form) '(labels flet)))\n (let (cache-symbol-list cache-form-list cache-type-list name-alias-list make-reset-name-list make-reset-form-list make-cache-querier-list)\n (dolist (cache-spec (reverse cache-specs))\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form make-cache-querier)\n (%parse-cache-form cache-spec)\n (push cache-symbol cache-symbol-list)\n (push cache-form cache-form-list)\n (push cache-type cache-type-list)\n (push name-alias name-alias-list)\n (push make-reset-name make-reset-name-list)\n (push make-reset-form make-reset-form-list)\n (push make-cache-querier make-cache-querier-list)))\n (labels ((def-name (def) (first def))\n (def-args (def) (second def))\n (def-body (def) (cddr def)))\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n `(let ,(loop for cache-symbol in cache-symbol-list\n for cache-form in cache-form-list\n collect `(,cache-symbol ,cache-form))\n (,(car def-form)\n (,@(loop for def in definitions\n for cache-type in cache-type-list\n for make-reset-name in make-reset-name-list\n for make-reset-form in make-reset-form-list\n collect `(,(funcall make-reset-name (def-name def)) ()\n ,(funcall make-reset-form cache-type)))\n ,@(loop for def in definitions\n for cache-type in cache-type-list\n for name-alias in name-alias-list\n for make-cache-querier in make-cache-querier-list\n collect `(,(def-name def) ,(def-args def)\n ,@(%extract-declarations (def-body def))\n (labels ((,name-alias ,(def-args def) ,@(def-body def)))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type (def-name def) (def-args def))))))\n (declare (ignorable ,@(loop for def in definitions\n for make-reset-name in make-reset-name-list\n collect `#',(funcall make-reset-name\n (def-name def)))))\n ,@labels-body))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n))\n (dotimes (i n)\n (setf (aref as i) (read)))\n (println\n (with-cache (:array ((+ n 1) (+ n 1)) :element-type 'fixnum :initial-element -1)\n (sb-int:named-let dp ((x 0) (y 0))\n (declare (uint31 x y))\n (if (= (+ x y) n)\n 0\n (max (- (aref as x) (dp (+ x 1) y))\n (- (aref as (- n y 1)) (dp x (+ y 1))))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n10 80 90 30\n\"\n \"10\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n10 100 10\n\"\n \"-80\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n10\n\"\n \"10\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\n\"\n \"4999999995\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n4 2 9 7 1 5\n\"\n \"2\n\")))\n", "language": "Lisp", "metadata": {"date": 1593286375, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03171.html", "problem_id": "p03171", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03171/input.txt", "sample_output_relpath": "derived/input_output/data/p03171/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03171/Lisp/s658977664.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s658977664", "user_id": "u352600849"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Memoization macro\n;;;\n\n;;\n;; Basic usage:\n;;\n;; (with-cache (:hash-table :test #'equal :key #'cons)\n;; (defun add (a b)\n;; (+ a b)))\n;; This function caches the returned values for already passed combinations of\n;; arguments. In this case ADD stores the key (CONS A B) and the returned value\n;; to a hash-table when (ADD A B) is evaluated for the first time. ADD returns\n;; the stored value when it is called with the same arguments (w.r.t. EQUAL)\n;; again.\n;;\n;; The storage for cache can be hash-table or array. Let's see an example for\n;; array:\n;; (with-cache (:array (10 20 30) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c) ... ))\n;; This form stores the value of FOO in an array created by (make-array (list 10\n;; 20 30) :initial-element -1 :element-type 'fixnum). Note that INITIAL-ELEMENT\n;; must always be given here as it is used as the flag expressing `not yet\n;; stored'. (Therefore INITIAL-ELEMENT should be a value FOO never takes.)\n;;\n;; If you want to ignore some arguments, you can put `*' in dimensions:\n;; (with-cache (:array (10 10 * 10) :initial-element -1)\n;; (defun foo (a b c d) ...)) ; then C is ignored when querying or storing cache\n;;\n;; Available definition forms in WITH-CACHE are DEFUN, LABELS, FLET, and\n;; SB-INT:NAMED-LET.\n;;\n;; You can trace the memoized function by :TRACE option:\n;; (with-cache (:array (10 10) :initial-element -1 :trace t)\n;; (defun foo (x y) ...))\n;; Then FOO is traced as with CL:TRACE.\n;;\n\n;; TODO & NOTE: Currently a memoized function is not enclosed with a block of\n;; the function name.\n\n;; FIXME: *RECURSION-DEPTH* should be included within the macro.\n(declaim (type (integer 0 #.most-positive-fixnum) *recursion-depth*))\n(defparameter *recursion-depth* 0)\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun %enclose-with-trace (fname args form)\n (let ((value (gensym)))\n `(progn\n (format t \"~&~A~A: (~A ~{~A~^ ~}) =>\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args))\n (let ((,value (let ((*recursion-depth* (1+ *recursion-depth*)))\n ,form)))\n (format t \"~&~A~A: (~A ~{~A~^ ~}) => ~A\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args)\n ,value)\n ,value))))\n\n (defun %extract-declarations (body)\n (remove-if-not (lambda (form) (and (consp form) (eql 'declare (car form))))\n body))\n\n (defun %parse-cache-form (cache-specifier)\n (let ((cache-type (car cache-specifier))\n (cache-attribs (cdr cache-specifier)))\n (assert (member cache-type '(:hash-table :array)))\n (let* ((dims-with-* (when (eql cache-type :array) (first cache-attribs)))\n (dims (remove '* dims-with-*))\n (rank (length dims))\n (rest-attribs (ecase cache-type\n (:hash-table cache-attribs)\n (:array (cdr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (trace-p (prog1 (getf rest-attribs :trace) (remf rest-attribs :trace)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array (list ,@dims) ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym \"CACHE\"))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels\n ((make-cache-querier (cache-type name args)\n (let ((res (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key '#'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (assert (= (length args) (length dims-with-*)))\n (let ((memoized-args (loop for dimension in dims-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value))))))))\n (if trace-p\n (%enclose-with-trace name args res)\n res)))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n ;; TODO: portable fill\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name)))))\n (values cache cache-form cache-type name-alias\n #'make-reset-name\n #'make-reset-form\n #'make-cache-querier)))))))\n\n(defmacro with-cache ((cache-type &rest cache-attribs) def-form)\n \"CACHE-TYPE := :HASH-TABLE | :ARRAY.\nDEF-FORM := definition form with DEFUN, LABELS, FLET, or SB-INT:NAMED-LET.\"\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form\n make-cache-querier)\n (%parse-cache-form (cons cache-type cache-attribs))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (defun ,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (defun ,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form)\n ((,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args)))\n ,@(cdr definitions))\n (declare (ignorable #',(funcall make-reset-name name)))\n ,@labels-body)))))\n ((nlet #+sbcl sb-int:named-let)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form) ,name ,bindings\n ,@(%extract-declarations body)\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))))))\n\n(defmacro with-caches (cache-specs def-form)\n \"DEF-FORM := definition form by LABELS or FLET.\n\n (with-caches (cache-spec1 cache-spec2)\n (labels ((f (x) ...) (g (y) ...))))\nis equivalent to the line up of\n (with-cache cache-spec1 (labels ((f (x) ...))))\nand\n (with-cache cache-spec2 (labels ((g (y) ...))))\n\nThis macro will be useful to do mutual recursion between memoized local\nfunctions.\"\n (assert (member (car def-form) '(labels flet)))\n (let (cache-symbol-list cache-form-list cache-type-list name-alias-list make-reset-name-list make-reset-form-list make-cache-querier-list)\n (dolist (cache-spec (reverse cache-specs))\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form make-cache-querier)\n (%parse-cache-form cache-spec)\n (push cache-symbol cache-symbol-list)\n (push cache-form cache-form-list)\n (push cache-type cache-type-list)\n (push name-alias name-alias-list)\n (push make-reset-name make-reset-name-list)\n (push make-reset-form make-reset-form-list)\n (push make-cache-querier make-cache-querier-list)))\n (labels ((def-name (def) (first def))\n (def-args (def) (second def))\n (def-body (def) (cddr def)))\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n `(let ,(loop for cache-symbol in cache-symbol-list\n for cache-form in cache-form-list\n collect `(,cache-symbol ,cache-form))\n (,(car def-form)\n (,@(loop for def in definitions\n for cache-type in cache-type-list\n for make-reset-name in make-reset-name-list\n for make-reset-form in make-reset-form-list\n collect `(,(funcall make-reset-name (def-name def)) ()\n ,(funcall make-reset-form cache-type)))\n ,@(loop for def in definitions\n for cache-type in cache-type-list\n for name-alias in name-alias-list\n for make-cache-querier in make-cache-querier-list\n collect `(,(def-name def) ,(def-args def)\n ,@(%extract-declarations (def-body def))\n (labels ((,name-alias ,(def-args def) ,@(def-body def)))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type (def-name def) (def-args def))))))\n (declare (ignorable ,@(loop for def in definitions\n for make-reset-name in make-reset-name-list\n collect `#',(funcall make-reset-name\n (def-name def)))))\n ,@labels-body))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n))\n (dotimes (i n)\n (setf (aref as i) (read)))\n (println\n (with-cache (:array ((+ n 1) (+ n 1)) :element-type 'fixnum :initial-element -1)\n (sb-int:named-let dp ((x 0) (y 0))\n (declare (uint31 x y))\n (if (= (+ x y) n)\n 0\n (max (- (aref as x) (dp (+ x 1) y))\n (- (aref as (- n y 1)) (dp x (+ y 1))))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n10 80 90 30\n\"\n \"10\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n10 100 10\n\"\n \"-80\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n10\n\"\n \"10\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\n\"\n \"4999999995\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n4 2 9 7 1 5\n\"\n \"2\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTaro and Jiro will play the following game against each other.\n\nInitially, they are given a sequence a = (a_1, a_2, \\ldots, a_N).\nUntil a becomes empty, the two players perform the following operation alternately, starting from Taro:\n\nRemove the element at the beginning or the end of a. The player earns x points, where x is the removed element.\n\nLet X and Y be Taro's and Jiro's total score at the end of the game, respectively.\nTaro tries to maximize X - Y, while Jiro tries to minimize X - Y.\n\nAssuming that the two players play optimally, find the resulting value of X - Y.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 3000\n\n1 \\leq a_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 \\ldots a_N\n\nOutput\n\nPrint the resulting value of X - Y, assuming that the two players play optimally.\n\nSample Input 1\n\n4\n10 80 90 30\n\nSample Output 1\n\n10\n\nThe game proceeds as follows when the two players play optimally (the element being removed is written bold):\n\nTaro: (10, 80, 90, 30) → (10, 80, 90)\n\nJiro: (10, 80, 90) → (10, 80)\n\nTaro: (10, 80) → (10)\n\nJiro: (10) → ()\n\nHere, X = 30 + 80 = 110 and Y = 90 + 10 = 100.\n\nSample Input 2\n\n3\n10 100 10\n\nSample Output 2\n\n-80\n\nThe game proceeds, for example, as follows when the two players play optimally:\n\nTaro: (10, 100, 10) → (100, 10)\n\nJiro: (100, 10) → (10)\n\nTaro: (10) → ()\n\nHere, X = 10 + 10 = 20 and Y = 100.\n\nSample Input 3\n\n1\n10\n\nSample Output 3\n\n10\n\nSample Input 4\n\n10\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\n\nSample Output 4\n\n4999999995\n\nThe answer may not fit into a 32-bit integer type.\n\nSample Input 5\n\n6\n4 2 9 7 1 5\n\nSample Output 5\n\n2\n\nThe game proceeds, for example, as follows when the two players play optimally:\n\nTaro: (4, 2, 9, 7, 1, 5) → (4, 2, 9, 7, 1)\n\nJiro: (4, 2, 9, 7, 1) → (2, 9, 7, 1)\n\nTaro: (2, 9, 7, 1) → (2, 9, 7)\n\nJiro: (2, 9, 7) → (2, 9)\n\nTaro: (2, 9) → (2)\n\nJiro: (2) → ()\n\nHere, X = 5 + 1 + 9 = 15 and Y = 4 + 7 + 2 = 13.", "sample_input": "4\n10 80 90 30\n"}, "reference_outputs": ["10\n"], "source_document_id": "p03171", "source_text": "Score : 100 points\n\nProblem Statement\n\nTaro and Jiro will play the following game against each other.\n\nInitially, they are given a sequence a = (a_1, a_2, \\ldots, a_N).\nUntil a becomes empty, the two players perform the following operation alternately, starting from Taro:\n\nRemove the element at the beginning or the end of a. The player earns x points, where x is the removed element.\n\nLet X and Y be Taro's and Jiro's total score at the end of the game, respectively.\nTaro tries to maximize X - Y, while Jiro tries to minimize X - Y.\n\nAssuming that the two players play optimally, find the resulting value of X - Y.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 3000\n\n1 \\leq a_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 \\ldots a_N\n\nOutput\n\nPrint the resulting value of X - Y, assuming that the two players play optimally.\n\nSample Input 1\n\n4\n10 80 90 30\n\nSample Output 1\n\n10\n\nThe game proceeds as follows when the two players play optimally (the element being removed is written bold):\n\nTaro: (10, 80, 90, 30) → (10, 80, 90)\n\nJiro: (10, 80, 90) → (10, 80)\n\nTaro: (10, 80) → (10)\n\nJiro: (10) → ()\n\nHere, X = 30 + 80 = 110 and Y = 90 + 10 = 100.\n\nSample Input 2\n\n3\n10 100 10\n\nSample Output 2\n\n-80\n\nThe game proceeds, for example, as follows when the two players play optimally:\n\nTaro: (10, 100, 10) → (100, 10)\n\nJiro: (100, 10) → (10)\n\nTaro: (10) → ()\n\nHere, X = 10 + 10 = 20 and Y = 100.\n\nSample Input 3\n\n1\n10\n\nSample Output 3\n\n10\n\nSample Input 4\n\n10\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\n\nSample Output 4\n\n4999999995\n\nThe answer may not fit into a 32-bit integer type.\n\nSample Input 5\n\n6\n4 2 9 7 1 5\n\nSample Output 5\n\n2\n\nThe game proceeds, for example, as follows when the two players play optimally:\n\nTaro: (4, 2, 9, 7, 1, 5) → (4, 2, 9, 7, 1)\n\nJiro: (4, 2, 9, 7, 1) → (2, 9, 7, 1)\n\nTaro: (2, 9, 7, 1) → (2, 9, 7)\n\nJiro: (2, 9, 7) → (2, 9)\n\nTaro: (2, 9) → (2)\n\nJiro: (2) → ()\n\nHere, X = 5 + 1 + 9 = 15 and Y = 4 + 7 + 2 = 13.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 16325, "cpu_time_ms": 129, "memory_kb": 97360}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s684510998", "group_id": "codeNet:p03172", "input_text": "#-(or child-sbcl swank)\n(quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n '(\"--control-stack-size\" \"32MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" #.(namestring *load-pathname*))\n :output t :error t :input t)))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ',dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dimensions-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref cache ,@memoized-args)\n (,name-alias ,@args))\n ,value)))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name))))\n (extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car form))) body)))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n;; (test with-memoizing\n;; (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (labels ((add (x y) (+ x y))\n;; \t\t (my-print (x) (print x)))\n;; \t (add 1 2))))))\n\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0))\n (declare (string string)\n ((simple-array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop for idx from offset below (length dest-vector)\n for pos1 = 0 then (1+ pos2)\n for pos2 = (position #\\space string :start pos1 :test #'char=)\n do (setf (aref dest-vector idx)\n (parse-integer string :start pos1 :end pos2))\n finally (return dest-vector)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(defconstant +magic+ (+ 7 (expt 10 9)))\n(defun solve (as k)\n (declare #.OPT\n ((simple-array uint32 (*)) as))\n (let ((n (length as)))\n (with-memoizing (:array (100 100001) :element-type 'uint32 :initial-element #xffffffff)\n (nlet recurse ((x (- n 1)) (y k))\n (cond ((zerop x)\n (if (<= y (aref as 0))\n 1\n 0))\n ((zerop y) 1)\n (t (mod (the fixnum (+ (recurse (- x 1) y)\n (recurse x (- y 1))\n (if (< (aref as x) y)\n (- (recurse (- x 1) (- y (aref as x) 1)))\n 0)))\n +magic+)))))))\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'uint32)))\n (split-ints-into-vector (read-line) as)\n (println (solve as k))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1547687811, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03172.html", "problem_id": "p03172", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03172/input.txt", "sample_output_relpath": "derived/input_output/data/p03172/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03172/Lisp/s684510998.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s684510998", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "#-(or child-sbcl swank)\n(quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n '(\"--control-stack-size\" \"32MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" #.(namestring *load-pathname*))\n :output t :error t :input t)))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ',dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dimensions-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref cache ,@memoized-args)\n (,name-alias ,@args))\n ,value)))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name))))\n (extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car form))) body)))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n;; (test with-memoizing\n;; (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (labels ((add (x y) (+ x y))\n;; \t\t (my-print (x) (print x)))\n;; \t (add 1 2))))))\n\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0))\n (declare (string string)\n ((simple-array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop for idx from offset below (length dest-vector)\n for pos1 = 0 then (1+ pos2)\n for pos2 = (position #\\space string :start pos1 :test #'char=)\n do (setf (aref dest-vector idx)\n (parse-integer string :start pos1 :end pos2))\n finally (return dest-vector)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(defconstant +magic+ (+ 7 (expt 10 9)))\n(defun solve (as k)\n (declare #.OPT\n ((simple-array uint32 (*)) as))\n (let ((n (length as)))\n (with-memoizing (:array (100 100001) :element-type 'uint32 :initial-element #xffffffff)\n (nlet recurse ((x (- n 1)) (y k))\n (cond ((zerop x)\n (if (<= y (aref as 0))\n 1\n 0))\n ((zerop y) 1)\n (t (mod (the fixnum (+ (recurse (- x 1) y)\n (recurse x (- y 1))\n (if (< (aref as x) y)\n (- (recurse (- x 1) (- y (aref as x) 1)))\n 0)))\n +magic+)))))))\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'uint32)))\n (split-ints-into-vector (read-line) as)\n (println (solve as k))))\n\n#-swank(main)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are N children, numbered 1, 2, \\ldots, N.\n\nThey have decided to share K candies among themselves.\nHere, for each i (1 \\leq i \\leq N), Child i must receive between 0 and a_i candies (inclusive).\nAlso, no candies should be left over.\n\nFind the number of ways for them to share candies, modulo 10^9 + 7.\nHere, two ways are said to be different when there exists a child who receives a different number of candies.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n0 \\leq K \\leq 10^5\n\n0 \\leq a_i \\leq K\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\na_1 a_2 \\ldots a_N\n\nOutput\n\nPrint the number of ways for the children to share candies, modulo 10^9 + 7.\n\nSample Input 1\n\n3 4\n1 2 3\n\nSample Output 1\n\n5\n\nThere are five ways for the children to share candies, as follows:\n\n(0, 1, 3)\n\n(0, 2, 2)\n\n(1, 0, 3)\n\n(1, 1, 2)\n\n(1, 2, 1)\n\nHere, in each sequence, the i-th element represents the number of candies that Child i receives.\n\nSample Input 2\n\n1 10\n9\n\nSample Output 2\n\n0\n\nThere may be no ways for the children to share candies.\n\nSample Input 3\n\n2 0\n0 0\n\nSample Output 3\n\n1\n\nThere is one way for the children to share candies, as follows:\n\n(0, 0)\n\nSample Input 4\n\n4 100000\n100000 100000 100000 100000\n\nSample Output 4\n\n665683269\n\nBe sure to print the answer modulo 10^9 + 7.", "sample_input": "3 4\n1 2 3\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03172", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are N children, numbered 1, 2, \\ldots, N.\n\nThey have decided to share K candies among themselves.\nHere, for each i (1 \\leq i \\leq N), Child i must receive between 0 and a_i candies (inclusive).\nAlso, no candies should be left over.\n\nFind the number of ways for them to share candies, modulo 10^9 + 7.\nHere, two ways are said to be different when there exists a child who receives a different number of candies.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n0 \\leq K \\leq 10^5\n\n0 \\leq a_i \\leq K\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\na_1 a_2 \\ldots a_N\n\nOutput\n\nPrint the number of ways for the children to share candies, modulo 10^9 + 7.\n\nSample Input 1\n\n3 4\n1 2 3\n\nSample Output 1\n\n5\n\nThere are five ways for the children to share candies, as follows:\n\n(0, 1, 3)\n\n(0, 2, 2)\n\n(1, 0, 3)\n\n(1, 1, 2)\n\n(1, 2, 1)\n\nHere, in each sequence, the i-th element represents the number of candies that Child i receives.\n\nSample Input 2\n\n1 10\n9\n\nSample Output 2\n\n0\n\nThere may be no ways for the children to share candies.\n\nSample Input 3\n\n2 0\n0 0\n\nSample Output 3\n\n1\n\nThere is one way for the children to share candies, as follows:\n\n(0, 0)\n\nSample Input 4\n\n4 100000\n100000 100000 100000 100000\n\nSample Output 4\n\n665683269\n\nBe sure to print the answer modulo 10^9 + 7.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9071, "cpu_time_ms": 388, "memory_kb": 72244}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s397017535", "group_id": "codeNet:p03172", "input_text": "#-(or child-sbcl swank)\n(quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n '(\"--control-stack-size\" \"32MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" #.(namestring *load-pathname*))\n :output t :error t :input t)))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ',dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dimensions-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref cache ,@memoized-args)\n (,name-alias ,@args))\n ,value)))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name))))\n (extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car form))) body)))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n;; (test with-memoizing\n;; (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (labels ((add (x y) (+ x y))\n;; \t\t (my-print (x) (print x)))\n;; \t (add 1 2))))))\n\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0))\n (declare (string string)\n ((simple-array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop for idx from offset below (length dest-vector)\n for pos1 = 0 then (1+ pos2)\n for pos2 = (position #\\space string :start pos1 :test #'char=)\n do (setf (aref dest-vector idx)\n (parse-integer string :start pos1 :end pos2))\n finally (return dest-vector)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(defconstant +magic+ (+ 7 (expt 10 9)))\n(defun solve (as k)\n (declare #.OPT\n ((simple-array uint32 (*)) as))\n (let ((n (length as)))\n (with-memoizing (:array (100 100001) :element-type 'uint32 :initial-element #xffffffff)\n (nlet recurse ((x (- n 1)) (y k))\n (cond ((zerop x)\n (if (<= y (aref as 0))\n 1\n 0))\n ((zerop y) 1)\n (t (mod (+ (recurse (- x 1) y)\n (recurse x (- y 1))\n (if (< (aref as x) y)\n (- (recurse (- x 1) (- y (aref as x) 1)))\n 0))\n +magic+)))))))\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'uint32)))\n (split-ints-into-vector (read-line) as)\n (println (solve as k))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1547674134, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03172.html", "problem_id": "p03172", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03172/input.txt", "sample_output_relpath": "derived/input_output/data/p03172/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03172/Lisp/s397017535.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s397017535", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "#-(or child-sbcl swank)\n(quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n '(\"--control-stack-size\" \"32MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" #.(namestring *load-pathname*))\n :output t :error t :input t)))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ',dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dimensions-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref cache ,@memoized-args)\n (,name-alias ,@args))\n ,value)))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name))))\n (extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car form))) body)))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n;; (test with-memoizing\n;; (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (labels ((add (x y) (+ x y))\n;; \t\t (my-print (x) (print x)))\n;; \t (add 1 2))))))\n\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0))\n (declare (string string)\n ((simple-array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop for idx from offset below (length dest-vector)\n for pos1 = 0 then (1+ pos2)\n for pos2 = (position #\\space string :start pos1 :test #'char=)\n do (setf (aref dest-vector idx)\n (parse-integer string :start pos1 :end pos2))\n finally (return dest-vector)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(defconstant +magic+ (+ 7 (expt 10 9)))\n(defun solve (as k)\n (declare #.OPT\n ((simple-array uint32 (*)) as))\n (let ((n (length as)))\n (with-memoizing (:array (100 100001) :element-type 'uint32 :initial-element #xffffffff)\n (nlet recurse ((x (- n 1)) (y k))\n (cond ((zerop x)\n (if (<= y (aref as 0))\n 1\n 0))\n ((zerop y) 1)\n (t (mod (+ (recurse (- x 1) y)\n (recurse x (- y 1))\n (if (< (aref as x) y)\n (- (recurse (- x 1) (- y (aref as x) 1)))\n 0))\n +magic+)))))))\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'uint32)))\n (split-ints-into-vector (read-line) as)\n (println (solve as k))))\n\n#-swank(main)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are N children, numbered 1, 2, \\ldots, N.\n\nThey have decided to share K candies among themselves.\nHere, for each i (1 \\leq i \\leq N), Child i must receive between 0 and a_i candies (inclusive).\nAlso, no candies should be left over.\n\nFind the number of ways for them to share candies, modulo 10^9 + 7.\nHere, two ways are said to be different when there exists a child who receives a different number of candies.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n0 \\leq K \\leq 10^5\n\n0 \\leq a_i \\leq K\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\na_1 a_2 \\ldots a_N\n\nOutput\n\nPrint the number of ways for the children to share candies, modulo 10^9 + 7.\n\nSample Input 1\n\n3 4\n1 2 3\n\nSample Output 1\n\n5\n\nThere are five ways for the children to share candies, as follows:\n\n(0, 1, 3)\n\n(0, 2, 2)\n\n(1, 0, 3)\n\n(1, 1, 2)\n\n(1, 2, 1)\n\nHere, in each sequence, the i-th element represents the number of candies that Child i receives.\n\nSample Input 2\n\n1 10\n9\n\nSample Output 2\n\n0\n\nThere may be no ways for the children to share candies.\n\nSample Input 3\n\n2 0\n0 0\n\nSample Output 3\n\n1\n\nThere is one way for the children to share candies, as follows:\n\n(0, 0)\n\nSample Input 4\n\n4 100000\n100000 100000 100000 100000\n\nSample Output 4\n\n665683269\n\nBe sure to print the answer modulo 10^9 + 7.", "sample_input": "3 4\n1 2 3\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03172", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are N children, numbered 1, 2, \\ldots, N.\n\nThey have decided to share K candies among themselves.\nHere, for each i (1 \\leq i \\leq N), Child i must receive between 0 and a_i candies (inclusive).\nAlso, no candies should be left over.\n\nFind the number of ways for them to share candies, modulo 10^9 + 7.\nHere, two ways are said to be different when there exists a child who receives a different number of candies.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n0 \\leq K \\leq 10^5\n\n0 \\leq a_i \\leq K\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\na_1 a_2 \\ldots a_N\n\nOutput\n\nPrint the number of ways for the children to share candies, modulo 10^9 + 7.\n\nSample Input 1\n\n3 4\n1 2 3\n\nSample Output 1\n\n5\n\nThere are five ways for the children to share candies, as follows:\n\n(0, 1, 3)\n\n(0, 2, 2)\n\n(1, 0, 3)\n\n(1, 1, 2)\n\n(1, 2, 1)\n\nHere, in each sequence, the i-th element represents the number of candies that Child i receives.\n\nSample Input 2\n\n1 10\n9\n\nSample Output 2\n\n0\n\nThere may be no ways for the children to share candies.\n\nSample Input 3\n\n2 0\n0 0\n\nSample Output 3\n\n1\n\nThere is one way for the children to share candies, as follows:\n\n(0, 0)\n\nSample Input 4\n\n4 100000\n100000 100000 100000 100000\n\nSample Output 4\n\n665683269\n\nBe sure to print the answer modulo 10^9 + 7.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9030, "cpu_time_ms": 384, "memory_kb": 72248}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s608755034", "group_id": "codeNet:p03174", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ',dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dimensions-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value)))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name))))\n (extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car form))) body)))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n;; (test with-memoizing\n;; (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (labels ((add (x y) (+ x y))\n;; \t\t (my-print (x) (print x)))\n;; \t (add 1 2))))))\n\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(declaim (inline split-integers-into-array))\n(defun split-integers-into-array (string dest-array row &key (offset 0))\n (declare (string string)\n ((simple-array * (* *)) dest-array)\n ((integer 0 #.most-positive-fixnum) row offset))\n (loop for idx from offset below (array-dimension dest-array 1)\n for pos1 = 0 then (1+ pos2)\n for pos2 = (position #\\space string :start pos1 :test #'char=)\n do (setf (aref dest-array row idx)\n (parse-integer string :start pos1 :end pos2))\n finally (return dest-array)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n(defconstant +magic+ (+ 7 (expt 10 9)))\n\n;; f(S, k) := the number of matchings that match each element of S (in A) to one\n;; of the first k elements (0, 1, ..., k-1) in B.\n(defun solve (mat n)\n (declare #.OPT\n ((integer 0 21) n))\n (with-memoizing (:array (#.(expt 2 21) * 22)\n :element-type 'uint32\n :initial-element #xffffffff)\n (nlet recurse ((s (- (expt 2 n) 1)) (s-size n) (k n))\n (declare ((integer 0 21) s-size))\n (cond ((zerop s) 1)\n ((> s-size k) 0)\n (t (mod (+ (recurse s s-size (- k 1))\n (loop with res of-type uint32 = 0\n for pos from 0 below n\n for mask of-type uint32 = 1 then (ash mask 1)\n when (and (/= 0 (logand mask s))\n (= 1 (sbit mat pos (- k 1))))\n do (setf res\n (mod (+ res (recurse (logxor mask s) (- s-size 1) (- k 1)))\n +magic+))\n finally (return res)))\n +magic+))))))\n(defun main ()\n (let* ((n (read))\n (mat (make-array (list n n) :element-type 'bit)))\n (dotimes (i n)\n (split-integers-into-array (read-line) mat i))\n (println (solve mat n))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1547766670, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03174.html", "problem_id": "p03174", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03174/input.txt", "sample_output_relpath": "derived/input_output/data/p03174/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03174/Lisp/s608755034.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s608755034", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ',dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dimensions-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value)))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name))))\n (extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car form))) body)))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n;; (test with-memoizing\n;; (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (labels ((add (x y) (+ x y))\n;; \t\t (my-print (x) (print x)))\n;; \t (add 1 2))))))\n\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(declaim (inline split-integers-into-array))\n(defun split-integers-into-array (string dest-array row &key (offset 0))\n (declare (string string)\n ((simple-array * (* *)) dest-array)\n ((integer 0 #.most-positive-fixnum) row offset))\n (loop for idx from offset below (array-dimension dest-array 1)\n for pos1 = 0 then (1+ pos2)\n for pos2 = (position #\\space string :start pos1 :test #'char=)\n do (setf (aref dest-array row idx)\n (parse-integer string :start pos1 :end pos2))\n finally (return dest-array)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n(defconstant +magic+ (+ 7 (expt 10 9)))\n\n;; f(S, k) := the number of matchings that match each element of S (in A) to one\n;; of the first k elements (0, 1, ..., k-1) in B.\n(defun solve (mat n)\n (declare #.OPT\n ((integer 0 21) n))\n (with-memoizing (:array (#.(expt 2 21) * 22)\n :element-type 'uint32\n :initial-element #xffffffff)\n (nlet recurse ((s (- (expt 2 n) 1)) (s-size n) (k n))\n (declare ((integer 0 21) s-size))\n (cond ((zerop s) 1)\n ((> s-size k) 0)\n (t (mod (+ (recurse s s-size (- k 1))\n (loop with res of-type uint32 = 0\n for pos from 0 below n\n for mask of-type uint32 = 1 then (ash mask 1)\n when (and (/= 0 (logand mask s))\n (= 1 (sbit mat pos (- k 1))))\n do (setf res\n (mod (+ res (recurse (logxor mask s) (- s-size 1) (- k 1)))\n +magic+))\n finally (return res)))\n +magic+))))))\n(defun main ()\n (let* ((n (read))\n (mat (make-array (list n n) :element-type 'bit)))\n (dotimes (i n)\n (split-integers-into-array (read-line) mat i))\n (println (solve mat n))))\n\n#-swank(main)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are N men and N women, both numbered 1, 2, \\ldots, N.\n\nFor each i, j (1 \\leq i, j \\leq N), the compatibility of Man i and Woman j is given as an integer a_{i, j}.\nIf a_{i, j} = 1, Man i and Woman j are compatible; if a_{i, j} = 0, they are not.\n\nTaro is trying to make N pairs, each consisting of a man and a woman who are compatible.\nHere, each man and each woman must belong to exactly one pair.\n\nFind the number of ways in which Taro can make N pairs, modulo 10^9 + 7.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 21\n\na_{i, j} is 0 or 1.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_{1, 1} \\ldots a_{1, N}\n:\na_{N, 1} \\ldots a_{N, N}\n\nOutput\n\nPrint the number of ways in which Taro can make N pairs, modulo 10^9 + 7.\n\nSample Input 1\n\n3\n0 1 1\n1 0 1\n1 1 1\n\nSample Output 1\n\n3\n\nThere are three ways to make pairs, as follows ((i, j) denotes a pair of Man i and Woman j):\n\n(1, 2), (2, 1), (3, 3)\n\n(1, 2), (2, 3), (3, 1)\n\n(1, 3), (2, 1), (3, 2)\n\nSample Input 2\n\n4\n0 1 0 0\n0 0 0 1\n1 0 0 0\n0 0 1 0\n\nSample Output 2\n\n1\n\nThere is one way to make pairs, as follows:\n\n(1, 2), (2, 4), (3, 1), (4, 3)\n\nSample Input 3\n\n1\n0\n\nSample Output 3\n\n0\n\nSample Input 4\n\n21\n0 0 0 0 0 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1\n1 1 1 0 0 1 0 0 0 1 0 0 0 0 1 1 1 0 1 1 0\n0 0 1 1 1 1 0 1 1 0 0 1 0 0 1 1 0 0 0 1 1\n0 1 1 0 1 1 0 1 0 1 0 0 1 0 0 0 0 0 1 1 0\n1 1 0 0 1 0 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0\n0 1 1 0 1 1 1 0 1 1 1 0 0 0 1 1 1 1 0 0 1\n0 1 0 0 0 1 0 1 0 0 0 1 1 1 0 0 1 1 0 1 0\n0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 1 1 1 1 1 1\n0 0 1 0 0 1 0 0 1 0 1 1 0 0 1 0 1 0 1 1 1\n0 0 0 0 1 1 0 0 1 1 1 0 0 0 0 1 1 0 0 0 1\n0 1 1 0 1 1 0 0 1 1 0 0 0 1 1 1 1 0 1 1 0\n0 0 1 0 0 1 1 1 1 0 1 1 0 1 1 1 0 0 0 0 1\n0 1 1 0 0 1 1 1 1 0 0 0 1 0 1 1 0 1 0 1 1\n1 1 1 1 1 0 0 0 0 1 0 0 1 1 0 1 1 1 0 0 1\n0 0 0 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1\n1 0 1 1 0 1 0 1 0 0 1 0 0 1 1 0 1 0 1 1 0\n0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1\n0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 0 0 1 1 0 1\n0 0 0 0 1 1 1 0 1 0 1 1 1 0 1 1 0 0 1 1 0\n1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 1 1 1 0 1 0\n1 0 0 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 0 0 0\n\nSample Output 4\n\n102515160\n\nBe sure to print the number modulo 10^9 + 7.", "sample_input": "3\n0 1 1\n1 0 1\n1 1 1\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03174", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are N men and N women, both numbered 1, 2, \\ldots, N.\n\nFor each i, j (1 \\leq i, j \\leq N), the compatibility of Man i and Woman j is given as an integer a_{i, j}.\nIf a_{i, j} = 1, Man i and Woman j are compatible; if a_{i, j} = 0, they are not.\n\nTaro is trying to make N pairs, each consisting of a man and a woman who are compatible.\nHere, each man and each woman must belong to exactly one pair.\n\nFind the number of ways in which Taro can make N pairs, modulo 10^9 + 7.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 21\n\na_{i, j} is 0 or 1.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_{1, 1} \\ldots a_{1, N}\n:\na_{N, 1} \\ldots a_{N, N}\n\nOutput\n\nPrint the number of ways in which Taro can make N pairs, modulo 10^9 + 7.\n\nSample Input 1\n\n3\n0 1 1\n1 0 1\n1 1 1\n\nSample Output 1\n\n3\n\nThere are three ways to make pairs, as follows ((i, j) denotes a pair of Man i and Woman j):\n\n(1, 2), (2, 1), (3, 3)\n\n(1, 2), (2, 3), (3, 1)\n\n(1, 3), (2, 1), (3, 2)\n\nSample Input 2\n\n4\n0 1 0 0\n0 0 0 1\n1 0 0 0\n0 0 1 0\n\nSample Output 2\n\n1\n\nThere is one way to make pairs, as follows:\n\n(1, 2), (2, 4), (3, 1), (4, 3)\n\nSample Input 3\n\n1\n0\n\nSample Output 3\n\n0\n\nSample Input 4\n\n21\n0 0 0 0 0 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1\n1 1 1 0 0 1 0 0 0 1 0 0 0 0 1 1 1 0 1 1 0\n0 0 1 1 1 1 0 1 1 0 0 1 0 0 1 1 0 0 0 1 1\n0 1 1 0 1 1 0 1 0 1 0 0 1 0 0 0 0 0 1 1 0\n1 1 0 0 1 0 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0\n0 1 1 0 1 1 1 0 1 1 1 0 0 0 1 1 1 1 0 0 1\n0 1 0 0 0 1 0 1 0 0 0 1 1 1 0 0 1 1 0 1 0\n0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 1 1 1 1 1 1\n0 0 1 0 0 1 0 0 1 0 1 1 0 0 1 0 1 0 1 1 1\n0 0 0 0 1 1 0 0 1 1 1 0 0 0 0 1 1 0 0 0 1\n0 1 1 0 1 1 0 0 1 1 0 0 0 1 1 1 1 0 1 1 0\n0 0 1 0 0 1 1 1 1 0 1 1 0 1 1 1 0 0 0 0 1\n0 1 1 0 0 1 1 1 1 0 0 0 1 0 1 1 0 1 0 1 1\n1 1 1 1 1 0 0 0 0 1 0 0 1 1 0 1 1 1 0 0 1\n0 0 0 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1\n1 0 1 1 0 1 0 1 0 0 1 0 0 1 1 0 1 0 1 1 0\n0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1\n0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 0 0 1 1 0 1\n0 0 0 0 1 1 1 0 1 0 1 1 1 0 1 1 0 0 1 1 0\n1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 1 1 1 0 1 0\n1 0 0 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 0 0 0\n\nSample Output 4\n\n102515160\n\nBe sure to print the number modulo 10^9 + 7.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9168, "cpu_time_ms": 931, "memory_kb": 218084}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s976147889", "group_id": "codeNet:p03174", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ',dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dimensions-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value)))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name))))\n (extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car form))) body)))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n;; (test with-memoizing\n;; (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (labels ((add (x y) (+ x y))\n;; \t\t (my-print (x) (print x)))\n;; \t (add 1 2))))))\n\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(declaim (inline split-integers-into-array))\n(defun split-integers-into-array (string dest-array row &key (offset 0))\n (declare (string string)\n ((simple-array * (* *)) dest-array)\n ((integer 0 #.most-positive-fixnum) row offset))\n (loop for idx from offset below (array-dimension dest-array 1)\n for pos1 = 0 then (1+ pos2)\n for pos2 = (position #\\space string :start pos1 :test #'char=)\n do (setf (aref dest-array row idx)\n (parse-integer string :start pos1 :end pos2))\n finally (return dest-array)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n(defconstant +magic+ (+ 7 (expt 10 9)))\n\n;; f(S, k) := the number of matchings that match each element of S (in A) to one\n;; of the first k elements (0, 1, ..., k-1) in B.\n(defun solve (mat n)\n (declare #.OPT\n ((integer 0 21) n))\n (with-memoizing (:array (#.(expt 2 21) * 22)\n :element-type 'uint32\n :initial-element #xffffffff)\n (nlet recurse ((s (- (expt 2 n) 1)) (s-size n) (k n))\n (declare ((integer 0 21) s-size))\n (cond ((zerop s) 1)\n ((> s-size k) 0)\n (t (mod (+ (recurse s s-size (- k 1))\n (loop with res of-type uint32 = 0\n for pos from 0 below n\n for mask of-type uint32 = 1 then (ash mask 1)\n when (and (not (zerop (logand mask s)))\n (= 1 (sbit mat pos (- k 1))))\n do (setf res\n (mod (+ res (recurse (logxor mask s) (- s-size 1) (- k 1)))\n +magic+))\n finally (return res)))\n +magic+))))))\n(defun main ()\n (let* ((n (read))\n (mat (make-array (list n n) :element-type 'bit)))\n (dotimes (i n)\n (split-integers-into-array (read-line) mat i))\n (println (solve mat n))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1547726997, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03174.html", "problem_id": "p03174", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03174/input.txt", "sample_output_relpath": "derived/input_output/data/p03174/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03174/Lisp/s976147889.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s976147889", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ',dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dimensions-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value)))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name))))\n (extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car form))) body)))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n;; (test with-memoizing\n;; (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (labels ((add (x y) (+ x y))\n;; \t\t (my-print (x) (print x)))\n;; \t (add 1 2))))))\n\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(declaim (inline split-integers-into-array))\n(defun split-integers-into-array (string dest-array row &key (offset 0))\n (declare (string string)\n ((simple-array * (* *)) dest-array)\n ((integer 0 #.most-positive-fixnum) row offset))\n (loop for idx from offset below (array-dimension dest-array 1)\n for pos1 = 0 then (1+ pos2)\n for pos2 = (position #\\space string :start pos1 :test #'char=)\n do (setf (aref dest-array row idx)\n (parse-integer string :start pos1 :end pos2))\n finally (return dest-array)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n(defconstant +magic+ (+ 7 (expt 10 9)))\n\n;; f(S, k) := the number of matchings that match each element of S (in A) to one\n;; of the first k elements (0, 1, ..., k-1) in B.\n(defun solve (mat n)\n (declare #.OPT\n ((integer 0 21) n))\n (with-memoizing (:array (#.(expt 2 21) * 22)\n :element-type 'uint32\n :initial-element #xffffffff)\n (nlet recurse ((s (- (expt 2 n) 1)) (s-size n) (k n))\n (declare ((integer 0 21) s-size))\n (cond ((zerop s) 1)\n ((> s-size k) 0)\n (t (mod (+ (recurse s s-size (- k 1))\n (loop with res of-type uint32 = 0\n for pos from 0 below n\n for mask of-type uint32 = 1 then (ash mask 1)\n when (and (not (zerop (logand mask s)))\n (= 1 (sbit mat pos (- k 1))))\n do (setf res\n (mod (+ res (recurse (logxor mask s) (- s-size 1) (- k 1)))\n +magic+))\n finally (return res)))\n +magic+))))))\n(defun main ()\n (let* ((n (read))\n (mat (make-array (list n n) :element-type 'bit)))\n (dotimes (i n)\n (split-integers-into-array (read-line) mat i))\n (println (solve mat n))))\n\n#-swank(main)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are N men and N women, both numbered 1, 2, \\ldots, N.\n\nFor each i, j (1 \\leq i, j \\leq N), the compatibility of Man i and Woman j is given as an integer a_{i, j}.\nIf a_{i, j} = 1, Man i and Woman j are compatible; if a_{i, j} = 0, they are not.\n\nTaro is trying to make N pairs, each consisting of a man and a woman who are compatible.\nHere, each man and each woman must belong to exactly one pair.\n\nFind the number of ways in which Taro can make N pairs, modulo 10^9 + 7.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 21\n\na_{i, j} is 0 or 1.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_{1, 1} \\ldots a_{1, N}\n:\na_{N, 1} \\ldots a_{N, N}\n\nOutput\n\nPrint the number of ways in which Taro can make N pairs, modulo 10^9 + 7.\n\nSample Input 1\n\n3\n0 1 1\n1 0 1\n1 1 1\n\nSample Output 1\n\n3\n\nThere are three ways to make pairs, as follows ((i, j) denotes a pair of Man i and Woman j):\n\n(1, 2), (2, 1), (3, 3)\n\n(1, 2), (2, 3), (3, 1)\n\n(1, 3), (2, 1), (3, 2)\n\nSample Input 2\n\n4\n0 1 0 0\n0 0 0 1\n1 0 0 0\n0 0 1 0\n\nSample Output 2\n\n1\n\nThere is one way to make pairs, as follows:\n\n(1, 2), (2, 4), (3, 1), (4, 3)\n\nSample Input 3\n\n1\n0\n\nSample Output 3\n\n0\n\nSample Input 4\n\n21\n0 0 0 0 0 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1\n1 1 1 0 0 1 0 0 0 1 0 0 0 0 1 1 1 0 1 1 0\n0 0 1 1 1 1 0 1 1 0 0 1 0 0 1 1 0 0 0 1 1\n0 1 1 0 1 1 0 1 0 1 0 0 1 0 0 0 0 0 1 1 0\n1 1 0 0 1 0 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0\n0 1 1 0 1 1 1 0 1 1 1 0 0 0 1 1 1 1 0 0 1\n0 1 0 0 0 1 0 1 0 0 0 1 1 1 0 0 1 1 0 1 0\n0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 1 1 1 1 1 1\n0 0 1 0 0 1 0 0 1 0 1 1 0 0 1 0 1 0 1 1 1\n0 0 0 0 1 1 0 0 1 1 1 0 0 0 0 1 1 0 0 0 1\n0 1 1 0 1 1 0 0 1 1 0 0 0 1 1 1 1 0 1 1 0\n0 0 1 0 0 1 1 1 1 0 1 1 0 1 1 1 0 0 0 0 1\n0 1 1 0 0 1 1 1 1 0 0 0 1 0 1 1 0 1 0 1 1\n1 1 1 1 1 0 0 0 0 1 0 0 1 1 0 1 1 1 0 0 1\n0 0 0 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1\n1 0 1 1 0 1 0 1 0 0 1 0 0 1 1 0 1 0 1 1 0\n0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1\n0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 0 0 1 1 0 1\n0 0 0 0 1 1 1 0 1 0 1 1 1 0 1 1 0 0 1 1 0\n1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 1 1 1 0 1 0\n1 0 0 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 0 0 0\n\nSample Output 4\n\n102515160\n\nBe sure to print the number modulo 10^9 + 7.", "sample_input": "3\n0 1 1\n1 0 1\n1 1 1\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03174", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are N men and N women, both numbered 1, 2, \\ldots, N.\n\nFor each i, j (1 \\leq i, j \\leq N), the compatibility of Man i and Woman j is given as an integer a_{i, j}.\nIf a_{i, j} = 1, Man i and Woman j are compatible; if a_{i, j} = 0, they are not.\n\nTaro is trying to make N pairs, each consisting of a man and a woman who are compatible.\nHere, each man and each woman must belong to exactly one pair.\n\nFind the number of ways in which Taro can make N pairs, modulo 10^9 + 7.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 21\n\na_{i, j} is 0 or 1.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_{1, 1} \\ldots a_{1, N}\n:\na_{N, 1} \\ldots a_{N, N}\n\nOutput\n\nPrint the number of ways in which Taro can make N pairs, modulo 10^9 + 7.\n\nSample Input 1\n\n3\n0 1 1\n1 0 1\n1 1 1\n\nSample Output 1\n\n3\n\nThere are three ways to make pairs, as follows ((i, j) denotes a pair of Man i and Woman j):\n\n(1, 2), (2, 1), (3, 3)\n\n(1, 2), (2, 3), (3, 1)\n\n(1, 3), (2, 1), (3, 2)\n\nSample Input 2\n\n4\n0 1 0 0\n0 0 0 1\n1 0 0 0\n0 0 1 0\n\nSample Output 2\n\n1\n\nThere is one way to make pairs, as follows:\n\n(1, 2), (2, 4), (3, 1), (4, 3)\n\nSample Input 3\n\n1\n0\n\nSample Output 3\n\n0\n\nSample Input 4\n\n21\n0 0 0 0 0 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1\n1 1 1 0 0 1 0 0 0 1 0 0 0 0 1 1 1 0 1 1 0\n0 0 1 1 1 1 0 1 1 0 0 1 0 0 1 1 0 0 0 1 1\n0 1 1 0 1 1 0 1 0 1 0 0 1 0 0 0 0 0 1 1 0\n1 1 0 0 1 0 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0\n0 1 1 0 1 1 1 0 1 1 1 0 0 0 1 1 1 1 0 0 1\n0 1 0 0 0 1 0 1 0 0 0 1 1 1 0 0 1 1 0 1 0\n0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 1 1 1 1 1 1\n0 0 1 0 0 1 0 0 1 0 1 1 0 0 1 0 1 0 1 1 1\n0 0 0 0 1 1 0 0 1 1 1 0 0 0 0 1 1 0 0 0 1\n0 1 1 0 1 1 0 0 1 1 0 0 0 1 1 1 1 0 1 1 0\n0 0 1 0 0 1 1 1 1 0 1 1 0 1 1 1 0 0 0 0 1\n0 1 1 0 0 1 1 1 1 0 0 0 1 0 1 1 0 1 0 1 1\n1 1 1 1 1 0 0 0 0 1 0 0 1 1 0 1 1 1 0 0 1\n0 0 0 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1\n1 0 1 1 0 1 0 1 0 0 1 0 0 1 1 0 1 0 1 1 0\n0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1\n0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 0 0 1 1 0 1\n0 0 0 0 1 1 1 0 1 0 1 1 1 0 1 1 0 0 1 1 0\n1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 1 1 1 0 1 0\n1 0 0 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 0 0 0\n\nSample Output 4\n\n102515160\n\nBe sure to print the number modulo 10^9 + 7.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9175, "cpu_time_ms": 759, "memory_kb": 205416}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s513011320", "group_id": "codeNet:p03175", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ',dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dimensions-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value)))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name))))\n (extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car form))) body)))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n;; (test with-memoizing\n;; (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (labels ((add (x y) (+ x y))\n;; \t\t (my-print (x) (print x)))\n;; \t (add 1 2))))))\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #.(char-code #\\Newline)))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (setf (schar ,buffer ,idx) ,terminate-char)\n (return (values ,buffer ,idx))))))\n\n(defmacro split-ints-and-bind (vars string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str (gensym \"STR\")))\n (labels ((expand (vars &optional (init-pos1 t))\n\t (if (null vars)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str :start ,pos1 :test #'char=))\n\t\t\t (,(car vars) (parse-integer ,str :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr vars) nil))))))\n `(let ((,str ,string))\n (declare (string ,str))\n\t ,@(expand vars)))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n;; f(i, c) := the number of colorings that assigns color c to vertex i.\n;; f(i, 1) = Πf(j, 0) (j is child of i)\n;; f(i, 0) = Π(f(j, 0)+f(j, 1)) ditto\n\n(defun solve (tree)\n (declare #.OPT\n ((simple-array list (*)) tree))\n (with-memoizing (:array (100000 2 *) :element-type 'uint32 :initial-element #xffffffff)\n (labels ((dp (i c parent)\n (if (zerop c)\n (loop with res of-type uint32 = 1\n for child of-type uint32 in (aref tree i)\n unless (= child parent)\n do (setf res (mod (* res (+ (dp child 0 i)\n (dp child 1 i)))\n +mod+))\n finally (return res))\n (loop with res of-type uint32 = 1\n for child of-type uint32 in (aref tree i)\n unless (= child parent)\n do (setf res (mod (* res (+ (dp child 0 i)))\n +mod+))\n finally (return res)))))\n (mod (+ (dp 0 0 -1) (dp 0 1 -1)) +mod+))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (tree (make-array n :element-type 'list :initial-element nil)))\n (dotimes (i (- n 1))\n (split-ints-and-bind (a b) (buffered-read-line 20)\n (declare (uint32 a b))\n (push (- b 1) (aref tree (- a 1)))\n (push (- a 1) (aref tree (- b 1)))))\n (println (solve tree))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1547899863, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03175.html", "problem_id": "p03175", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03175/input.txt", "sample_output_relpath": "derived/input_output/data/p03175/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03175/Lisp/s513011320.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s513011320", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ',dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dimensions-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value)))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name))))\n (extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car form))) body)))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n;; (test with-memoizing\n;; (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (labels ((add (x y) (+ x y))\n;; \t\t (my-print (x) (print x)))\n;; \t (add 1 2))))))\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #.(char-code #\\Newline)))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (setf (schar ,buffer ,idx) ,terminate-char)\n (return (values ,buffer ,idx))))))\n\n(defmacro split-ints-and-bind (vars string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str (gensym \"STR\")))\n (labels ((expand (vars &optional (init-pos1 t))\n\t (if (null vars)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str :start ,pos1 :test #'char=))\n\t\t\t (,(car vars) (parse-integer ,str :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr vars) nil))))))\n `(let ((,str ,string))\n (declare (string ,str))\n\t ,@(expand vars)))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n;; f(i, c) := the number of colorings that assigns color c to vertex i.\n;; f(i, 1) = Πf(j, 0) (j is child of i)\n;; f(i, 0) = Π(f(j, 0)+f(j, 1)) ditto\n\n(defun solve (tree)\n (declare #.OPT\n ((simple-array list (*)) tree))\n (with-memoizing (:array (100000 2 *) :element-type 'uint32 :initial-element #xffffffff)\n (labels ((dp (i c parent)\n (if (zerop c)\n (loop with res of-type uint32 = 1\n for child of-type uint32 in (aref tree i)\n unless (= child parent)\n do (setf res (mod (* res (+ (dp child 0 i)\n (dp child 1 i)))\n +mod+))\n finally (return res))\n (loop with res of-type uint32 = 1\n for child of-type uint32 in (aref tree i)\n unless (= child parent)\n do (setf res (mod (* res (+ (dp child 0 i)))\n +mod+))\n finally (return res)))))\n (mod (+ (dp 0 0 -1) (dp 0 1 -1)) +mod+))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (tree (make-array n :element-type 'list :initial-element nil)))\n (dotimes (i (- n 1))\n (split-ints-and-bind (a b) (buffered-read-line 20)\n (declare (uint32 a b))\n (push (- b 1) (aref tree (- a 1)))\n (push (- a 1) (aref tree (- b 1)))))\n (println (solve tree))))\n\n#-swank(main)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere is a tree with N vertices, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N - 1), the i-th edge connects Vertex x_i and y_i.\n\nTaro has decided to paint each vertex in white or black.\nHere, it is not allowed to paint two adjacent vertices both in black.\n\nFind the number of ways in which the vertices can be painted, modulo 10^9 + 7.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq x_i, y_i \\leq N\n\nThe given graph is a tree.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\nx_2 y_2\n:\nx_{N - 1} y_{N - 1}\n\nOutput\n\nPrint the number of ways in which the vertices can be painted, modulo 10^9 + 7.\n\nSample Input 1\n\n3\n1 2\n2 3\n\nSample Output 1\n\n5\n\nThere are five ways to paint the vertices, as follows:\n\nSample Input 2\n\n4\n1 2\n1 3\n1 4\n\nSample Output 2\n\n9\n\nThere are nine ways to paint the vertices, as follows:\n\nSample Input 3\n\n1\n\nSample Output 3\n\n2\n\nSample Input 4\n\n10\n8 5\n10 8\n6 5\n1 5\n4 8\n2 10\n3 6\n9 2\n1 7\n\nSample Output 4\n\n157", "sample_input": "3\n1 2\n2 3\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03175", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere is a tree with N vertices, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N - 1), the i-th edge connects Vertex x_i and y_i.\n\nTaro has decided to paint each vertex in white or black.\nHere, it is not allowed to paint two adjacent vertices both in black.\n\nFind the number of ways in which the vertices can be painted, modulo 10^9 + 7.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq x_i, y_i \\leq N\n\nThe given graph is a tree.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\nx_2 y_2\n:\nx_{N - 1} y_{N - 1}\n\nOutput\n\nPrint the number of ways in which the vertices can be painted, modulo 10^9 + 7.\n\nSample Input 1\n\n3\n1 2\n2 3\n\nSample Output 1\n\n5\n\nThere are five ways to paint the vertices, as follows:\n\nSample Input 2\n\n4\n1 2\n1 3\n1 4\n\nSample Output 2\n\n9\n\nThere are nine ways to paint the vertices, as follows:\n\nSample Input 3\n\n1\n\nSample Output 3\n\n2\n\nSample Input 4\n\n10\n8 5\n10 8\n6 5\n1 5\n4 8\n2 10\n3 6\n9 2\n1 7\n\nSample Output 4\n\n157", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9943, "cpu_time_ms": 382, "memory_kb": 49632}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s119563777", "group_id": "codeNet:p03178", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun main ()\n (declare #.OPT)\n (let* ((k (read-line))\n (n (length k))\n (d (read))\n (dp (make-array '(100001 101 2) :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n d))\n (setf (aref dp 0 0 1) 1)\n (dotimes (x n)\n (let ((c (digit-char-p (aref k x))))\n (declare ((integer 0 9) c))\n (dotimes (sum1 d)\n (loop for digit from 0 to 9\n for sum2 = (mod (+ sum1 digit) d)\n do (incfmod (aref dp (+ x 1) sum2 0)\n (aref dp x sum1 0))\n (cond ((< digit c)\n (incfmod (aref dp (+ x 1) sum2 0)\n (aref dp x sum1 1)))\n ((= digit c)\n (incfmod (aref dp (+ x 1) sum2 1)\n (aref dp x sum1 1))))))))\n (println (mod+ (aref dp n 0 0) (aref dp n 0 1) -1))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"30\n4\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1000000009\n1\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"98765432109876543210\n58\n\"\n \"635270834\n\")))\n", "language": "Lisp", "metadata": {"date": 1593299778, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03178.html", "problem_id": "p03178", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03178/input.txt", "sample_output_relpath": "derived/input_output/data/p03178/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03178/Lisp/s119563777.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s119563777", "user_id": "u352600849"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun main ()\n (declare #.OPT)\n (let* ((k (read-line))\n (n (length k))\n (d (read))\n (dp (make-array '(100001 101 2) :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n d))\n (setf (aref dp 0 0 1) 1)\n (dotimes (x n)\n (let ((c (digit-char-p (aref k x))))\n (declare ((integer 0 9) c))\n (dotimes (sum1 d)\n (loop for digit from 0 to 9\n for sum2 = (mod (+ sum1 digit) d)\n do (incfmod (aref dp (+ x 1) sum2 0)\n (aref dp x sum1 0))\n (cond ((< digit c)\n (incfmod (aref dp (+ x 1) sum2 0)\n (aref dp x sum1 1)))\n ((= digit c)\n (incfmod (aref dp (+ x 1) sum2 1)\n (aref dp x sum1 1))))))))\n (println (mod+ (aref dp n 0 0) (aref dp n 0 1) -1))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"30\n4\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1000000009\n1\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"98765432109876543210\n58\n\"\n \"635270834\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nFind the number of integers between 1 and K (inclusive) satisfying the following condition, modulo 10^9 + 7:\n\nThe sum of the digits in base ten is a multiple of D.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq K < 10^{10000}\n\n1 \\leq D \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\nD\n\nOutput\n\nPrint the number of integers satisfying the condition, modulo 10^9 + 7.\n\nSample Input 1\n\n30\n4\n\nSample Output 1\n\n6\n\nThose six integers are: 4, 8, 13, 17, 22 and 26.\n\nSample Input 2\n\n1000000009\n1\n\nSample Output 2\n\n2\n\nBe sure to print the number modulo 10^9 + 7.\n\nSample Input 3\n\n98765432109876543210\n58\n\nSample Output 3\n\n635270834", "sample_input": "30\n4\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03178", "source_text": "Score : 100 points\n\nProblem Statement\n\nFind the number of integers between 1 and K (inclusive) satisfying the following condition, modulo 10^9 + 7:\n\nThe sum of the digits in base ten is a multiple of D.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq K < 10^{10000}\n\n1 \\leq D \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\nD\n\nOutput\n\nPrint the number of integers satisfying the condition, modulo 10^9 + 7.\n\nSample Input 1\n\n30\n4\n\nSample Output 1\n\n6\n\nThose six integers are: 4, 8, 13, 17, 22 and 26.\n\nSample Input 2\n\n1000000009\n1\n\nSample Output 2\n\n2\n\nBe sure to print the number modulo 10^9 + 7.\n\nSample Input 3\n\n98765432109876543210\n58\n\nSample Output 3\n\n635270834", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5656, "cpu_time_ms": 172, "memory_kb": 32960}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s401333996", "group_id": "codeNet:p03178", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun main ()\n (let* ((k (read-line))\n (n (length k))\n (d (read))\n (dp (make-array (list (+ n 1) d 2) :element-type 'uint31 :initial-element 0)))\n (setf (aref dp 0 0 1) 1)\n (dotimes (x n)\n (let ((c (digit-char-p (aref k x))))\n (declare ((integer 0 9) c))\n (dotimes (sum1 d)\n (loop for digit from 0 to 9\n for sum2 = (mod (+ sum1 digit) d)\n do (incfmod (aref dp (+ x 1) sum2 0)\n (aref dp x sum1 0))\n (cond ((< digit c)\n (incfmod (aref dp (+ x 1) sum2 0)\n (aref dp x sum1 1)))\n ((= digit c)\n (incfmod (aref dp (+ x 1) sum2 1)\n (aref dp x sum1 1))))))))\n (println (mod+ (aref dp n 0 0) (aref dp n 0 1) -1))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"30\n4\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1000000009\n1\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"98765432109876543210\n58\n\"\n \"635270834\n\")))\n", "language": "Lisp", "metadata": {"date": 1593290070, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03178.html", "problem_id": "p03178", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03178/input.txt", "sample_output_relpath": "derived/input_output/data/p03178/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03178/Lisp/s401333996.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s401333996", "user_id": "u352600849"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun main ()\n (let* ((k (read-line))\n (n (length k))\n (d (read))\n (dp (make-array (list (+ n 1) d 2) :element-type 'uint31 :initial-element 0)))\n (setf (aref dp 0 0 1) 1)\n (dotimes (x n)\n (let ((c (digit-char-p (aref k x))))\n (declare ((integer 0 9) c))\n (dotimes (sum1 d)\n (loop for digit from 0 to 9\n for sum2 = (mod (+ sum1 digit) d)\n do (incfmod (aref dp (+ x 1) sum2 0)\n (aref dp x sum1 0))\n (cond ((< digit c)\n (incfmod (aref dp (+ x 1) sum2 0)\n (aref dp x sum1 1)))\n ((= digit c)\n (incfmod (aref dp (+ x 1) sum2 1)\n (aref dp x sum1 1))))))))\n (println (mod+ (aref dp n 0 0) (aref dp n 0 1) -1))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"30\n4\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1000000009\n1\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"98765432109876543210\n58\n\"\n \"635270834\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nFind the number of integers between 1 and K (inclusive) satisfying the following condition, modulo 10^9 + 7:\n\nThe sum of the digits in base ten is a multiple of D.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq K < 10^{10000}\n\n1 \\leq D \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\nD\n\nOutput\n\nPrint the number of integers satisfying the condition, modulo 10^9 + 7.\n\nSample Input 1\n\n30\n4\n\nSample Output 1\n\n6\n\nThose six integers are: 4, 8, 13, 17, 22 and 26.\n\nSample Input 2\n\n1000000009\n1\n\nSample Output 2\n\n2\n\nBe sure to print the number modulo 10^9 + 7.\n\nSample Input 3\n\n98765432109876543210\n58\n\nSample Output 3\n\n635270834", "sample_input": "30\n4\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03178", "source_text": "Score : 100 points\n\nProblem Statement\n\nFind the number of integers between 1 and K (inclusive) satisfying the following condition, modulo 10^9 + 7:\n\nThe sum of the digits in base ten is a multiple of D.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq K < 10^{10000}\n\n1 \\leq D \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\nD\n\nOutput\n\nPrint the number of integers satisfying the condition, modulo 10^9 + 7.\n\nSample Input 1\n\n30\n4\n\nSample Output 1\n\n6\n\nThose six integers are: 4, 8, 13, 17, 22 and 26.\n\nSample Input 2\n\n1000000009\n1\n\nSample Output 2\n\n2\n\nBe sure to print the number modulo 10^9 + 7.\n\nSample Input 3\n\n98765432109876543210\n58\n\nSample Output 3\n\n635270834", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5614, "cpu_time_ms": 362, "memory_kb": 32700}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s857393267", "group_id": "codeNet:p03179", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y)\n (let ((res (+ x y)))\n (if (>= res ,divisor)\n (- res ,divisor)\n res))))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (s (read-line))\n (dp (make-array (list n (+ n 1)) :element-type 'uint31 :initial-element 0)))\n (declare (simple-string s)\n (uint31 n))\n (dotimes (y n)\n (setf (aref dp 0 y) 1))\n (loop for x from 0 below (- n 1)\n do (if (char= #\\< (aref s x))\n (loop for y below (- n x)\n do (incfmod (aref dp (+ x 1) y)\n (aref dp x y))\n (incfmod (aref dp (+ x 1) (- n x))\n (the uint31 (- +mod+ (aref dp x y)))))\n (loop for y below (- n x)\n do (incfmod (aref dp (+ x 1) 0)\n (aref dp x y))\n (incfmod (aref dp (+ x 1) y)\n (the uint31 (- +mod+ (aref dp x y))))))\n (dotimes (y n)\n (incfmod (aref dp (+ x 1) (+ y 1))\n (aref dp (+ x 1) y))))\n (println (aref dp (- n 1) 0))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n<><\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n<<<<\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"20\n>>>><>>><>><>>><<>>\n\"\n \"217136290\n\")))\n", "language": "Lisp", "metadata": {"date": 1571972030, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03179.html", "problem_id": "p03179", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03179/input.txt", "sample_output_relpath": "derived/input_output/data/p03179/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03179/Lisp/s857393267.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s857393267", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y)\n (let ((res (+ x y)))\n (if (>= res ,divisor)\n (- res ,divisor)\n res))))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (s (read-line))\n (dp (make-array (list n (+ n 1)) :element-type 'uint31 :initial-element 0)))\n (declare (simple-string s)\n (uint31 n))\n (dotimes (y n)\n (setf (aref dp 0 y) 1))\n (loop for x from 0 below (- n 1)\n do (if (char= #\\< (aref s x))\n (loop for y below (- n x)\n do (incfmod (aref dp (+ x 1) y)\n (aref dp x y))\n (incfmod (aref dp (+ x 1) (- n x))\n (the uint31 (- +mod+ (aref dp x y)))))\n (loop for y below (- n x)\n do (incfmod (aref dp (+ x 1) 0)\n (aref dp x y))\n (incfmod (aref dp (+ x 1) y)\n (the uint31 (- +mod+ (aref dp x y))))))\n (dotimes (y n)\n (incfmod (aref dp (+ x 1) (+ y 1))\n (aref dp (+ x 1) y))))\n (println (aref dp (- n 1) 0))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n<><\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n<<<<\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"20\n>>>><>>><>><>>><<>>\n\"\n \"217136290\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nLet N be a positive integer.\nYou are given a string s of length N - 1, consisting of < and >.\n\nFind the number of permutations (p_1, p_2, \\ldots, p_N) of (1, 2, \\ldots, N) that satisfy the following condition, modulo 10^9 + 7:\n\nFor each i (1 \\leq i \\leq N - 1), p_i < p_{i + 1} if the i-th character in s is <, and p_i > p_{i + 1} if the i-th character in s is >.\n\nConstraints\n\nN is an integer.\n\n2 \\leq N \\leq 3000\n\ns is a string of length N - 1.\n\ns consists of < and >.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\ns\n\nOutput\n\nPrint the number of permutations that satisfy the condition, modulo 10^9 + 7.\n\nSample Input 1\n\n4\n<><\n\nSample Output 1\n\n5\n\nThere are five permutations that satisfy the condition, as follows:\n\n(1, 3, 2, 4)\n\n(1, 4, 2, 3)\n\n(2, 3, 1, 4)\n\n(2, 4, 1, 3)\n\n(3, 4, 1, 2)\n\nSample Input 2\n\n5\n<<<<\n\nSample Output 2\n\n1\n\nThere is one permutation that satisfies the condition, as follows:\n\n(1, 2, 3, 4, 5)\n\nSample Input 3\n\n20\n>>>><>>><>><>>><<>>\n\nSample Output 3\n\n217136290\n\nBe sure to print the number modulo 10^9 + 7.", "sample_input": "4\n<><\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03179", "source_text": "Score : 100 points\n\nProblem Statement\n\nLet N be a positive integer.\nYou are given a string s of length N - 1, consisting of < and >.\n\nFind the number of permutations (p_1, p_2, \\ldots, p_N) of (1, 2, \\ldots, N) that satisfy the following condition, modulo 10^9 + 7:\n\nFor each i (1 \\leq i \\leq N - 1), p_i < p_{i + 1} if the i-th character in s is <, and p_i > p_{i + 1} if the i-th character in s is >.\n\nConstraints\n\nN is an integer.\n\n2 \\leq N \\leq 3000\n\ns is a string of length N - 1.\n\ns consists of < and >.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\ns\n\nOutput\n\nPrint the number of permutations that satisfy the condition, modulo 10^9 + 7.\n\nSample Input 1\n\n4\n<><\n\nSample Output 1\n\n5\n\nThere are five permutations that satisfy the condition, as follows:\n\n(1, 3, 2, 4)\n\n(1, 4, 2, 3)\n\n(2, 3, 1, 4)\n\n(2, 4, 1, 3)\n\n(3, 4, 1, 2)\n\nSample Input 2\n\n5\n<<<<\n\nSample Output 2\n\n1\n\nThere is one permutation that satisfies the condition, as follows:\n\n(1, 2, 3, 4, 5)\n\nSample Input 3\n\n20\n>>>><>>><>><>>><<>>\n\nSample Output 3\n\n217136290\n\nBe sure to print the number modulo 10^9 + 7.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5613, "cpu_time_ms": 177, "memory_kb": 51688}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s437326356", "group_id": "codeNet:p03181", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with dynamic modulus\n;;;\n\n(declaim ((unsigned-byte 32) *modulus*))\n(defvar *modulus*)\n\n(defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) *modulus*)) args))\n\n(defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) *modulus*)) args))\n\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) *modulus*)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) *modulus*)) args)))))\n\n(define-modify-macro incfmod (delta &optional (divisor '*modulus*))\n (lambda (x y divisor) (mod (+ x y) divisor)))\n\n(define-modify-macro decfmod (delta &optional (divisor '*modulus*))\n (lambda (x y divisor) (mod (- x y) divisor)))\n\n(define-modify-macro mulfmod (delta &optional (divisor '*modulus*))\n (lambda (x y divisor) (mod (* x y) divisor)))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (dp (make-array n :element-type 'uint31 :initial-element 0))\n (res (make-array n :element-type 'uint31 :initial-element 0))\n (*modulus* m))\n (declare (uint31 n m))\n (dotimes (i (- n 1))\n (let ((x (- (read-fixnum) 1))\n (y (- (read-fixnum) 1)))\n (push x (aref graph y))\n (push y (aref graph x))))\n (sb-int:named-let dfs ((v 0) (parent -1))\n (let ((value 1))\n (declare (uint31 value))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (dfs child v)\n (mulfmod value (+ 1 (aref dp child)))))\n (setf (aref dp v) value)))\n #>dp\n (sb-int:named-let dfs ((v 0) (parent -1))\n (setf (aref res v) (aref dp v))\n (let* ((old-value (aref dp v))\n (children (aref graph v))\n (len (length children))\n (cumuls1 (make-array (+ len 1) :element-type 'uint31 :initial-element 1))\n (cumuls2 (make-array (+ len 1) :element-type 'uint31 :initial-element 1)))\n (loop for i below len\n for child in children\n do (mulfmod (aref cumuls1 (+ i 1))\n (mod* (+ 1 (aref dp child)) (aref cumuls1 i))))\n (loop for i from (- len 1) downto 0\n for child in (reverse children)\n do (mulfmod (aref cumuls2 i)\n (mod* (+ 1 (aref dp child)) (aref cumuls2 (+ i 1)))))\n (loop for i below len\n for child in children\n for new-value = (mod* (aref cumuls1 i) (aref cumuls2 (+ i 1)))\n for old-child-value = (aref dp child)\n for new-child-value = (mod* (+ 1 new-value) old-child-value)\n unless (= child parent)\n do (setf (aref dp v) new-value\n (aref dp child) new-child-value)\n (dfs child v)\n (setf (aref dp v) old-value\n (aref dp child) old-child-value))))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (map () #'println res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 100\n1 2\n2 3\n\"\n \"3\n4\n3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 100\n1 2\n1 3\n1 4\n\"\n \"8\n5\n5\n5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 100\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 2\n8 5\n10 8\n6 5\n1 5\n4 8\n2 10\n3 6\n9 2\n1 7\n\"\n \"0\n0\n1\n1\n1\n0\n1\n0\n1\n1\n\")))\n", "language": "Lisp", "metadata": {"date": 1593292894, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03181.html", "problem_id": "p03181", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03181/input.txt", "sample_output_relpath": "derived/input_output/data/p03181/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03181/Lisp/s437326356.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s437326356", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n4\n3\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with dynamic modulus\n;;;\n\n(declaim ((unsigned-byte 32) *modulus*))\n(defvar *modulus*)\n\n(defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) *modulus*)) args))\n\n(defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) *modulus*)) args))\n\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) *modulus*)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) *modulus*)) args)))))\n\n(define-modify-macro incfmod (delta &optional (divisor '*modulus*))\n (lambda (x y divisor) (mod (+ x y) divisor)))\n\n(define-modify-macro decfmod (delta &optional (divisor '*modulus*))\n (lambda (x y divisor) (mod (- x y) divisor)))\n\n(define-modify-macro mulfmod (delta &optional (divisor '*modulus*))\n (lambda (x y divisor) (mod (* x y) divisor)))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (dp (make-array n :element-type 'uint31 :initial-element 0))\n (res (make-array n :element-type 'uint31 :initial-element 0))\n (*modulus* m))\n (declare (uint31 n m))\n (dotimes (i (- n 1))\n (let ((x (- (read-fixnum) 1))\n (y (- (read-fixnum) 1)))\n (push x (aref graph y))\n (push y (aref graph x))))\n (sb-int:named-let dfs ((v 0) (parent -1))\n (let ((value 1))\n (declare (uint31 value))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (dfs child v)\n (mulfmod value (+ 1 (aref dp child)))))\n (setf (aref dp v) value)))\n #>dp\n (sb-int:named-let dfs ((v 0) (parent -1))\n (setf (aref res v) (aref dp v))\n (let* ((old-value (aref dp v))\n (children (aref graph v))\n (len (length children))\n (cumuls1 (make-array (+ len 1) :element-type 'uint31 :initial-element 1))\n (cumuls2 (make-array (+ len 1) :element-type 'uint31 :initial-element 1)))\n (loop for i below len\n for child in children\n do (mulfmod (aref cumuls1 (+ i 1))\n (mod* (+ 1 (aref dp child)) (aref cumuls1 i))))\n (loop for i from (- len 1) downto 0\n for child in (reverse children)\n do (mulfmod (aref cumuls2 i)\n (mod* (+ 1 (aref dp child)) (aref cumuls2 (+ i 1)))))\n (loop for i below len\n for child in children\n for new-value = (mod* (aref cumuls1 i) (aref cumuls2 (+ i 1)))\n for old-child-value = (aref dp child)\n for new-child-value = (mod* (+ 1 new-value) old-child-value)\n unless (= child parent)\n do (setf (aref dp v) new-value\n (aref dp child) new-child-value)\n (dfs child v)\n (setf (aref dp v) old-value\n (aref dp child) old-child-value))))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (map () #'println res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 100\n1 2\n2 3\n\"\n \"3\n4\n3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 100\n1 2\n1 3\n1 4\n\"\n \"8\n5\n5\n5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 100\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 2\n8 5\n10 8\n6 5\n1 5\n4 8\n2 10\n3 6\n9 2\n1 7\n\"\n \"0\n0\n1\n1\n1\n0\n1\n0\n1\n1\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere is a tree with N vertices, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N - 1), the i-th edge connects Vertex x_i and y_i.\n\nTaro has decided to paint each vertex in white or black, so that any black vertex can be reached from any other black vertex by passing through only black vertices.\n\nYou are given a positive integer M.\nFor each v (1 \\leq v \\leq N), answer the following question:\n\nAssuming that Vertex v has to be black, find the number of ways in which the vertices can be painted, modulo M.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n2 \\leq M \\leq 10^9\n\n1 \\leq x_i, y_i \\leq N\n\nThe given graph is a tree.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nx_1 y_1\nx_2 y_2\n:\nx_{N - 1} y_{N - 1}\n\nOutput\n\nPrint N lines.\nThe v-th (1 \\leq v \\leq N) line should contain the answer to the following question:\n\nAssuming that Vertex v has to be black, find the number of ways in which the vertices can be painted, modulo M.\n\nSample Input 1\n\n3 100\n1 2\n2 3\n\nSample Output 1\n\n3\n4\n3\n\nThere are seven ways to paint the vertices, as shown in the figure below.\nAmong them, there are three ways such that Vertex 1 is black, four ways such that Vertex 2 is black and three ways such that Vertex 3 is black.\n\nSample Input 2\n\n4 100\n1 2\n1 3\n1 4\n\nSample Output 2\n\n8\n5\n5\n5\n\nSample Input 3\n\n1 100\n\nSample Output 3\n\n1\n\nSample Input 4\n\n10 2\n8 5\n10 8\n6 5\n1 5\n4 8\n2 10\n3 6\n9 2\n1 7\n\nSample Output 4\n\n0\n0\n1\n1\n1\n0\n1\n0\n1\n1\n\nBe sure to print the answers modulo M.", "sample_input": "3 100\n1 2\n2 3\n"}, "reference_outputs": ["3\n4\n3\n"], "source_document_id": "p03181", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere is a tree with N vertices, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N - 1), the i-th edge connects Vertex x_i and y_i.\n\nTaro has decided to paint each vertex in white or black, so that any black vertex can be reached from any other black vertex by passing through only black vertices.\n\nYou are given a positive integer M.\nFor each v (1 \\leq v \\leq N), answer the following question:\n\nAssuming that Vertex v has to be black, find the number of ways in which the vertices can be painted, modulo M.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n2 \\leq M \\leq 10^9\n\n1 \\leq x_i, y_i \\leq N\n\nThe given graph is a tree.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nx_1 y_1\nx_2 y_2\n:\nx_{N - 1} y_{N - 1}\n\nOutput\n\nPrint N lines.\nThe v-th (1 \\leq v \\leq N) line should contain the answer to the following question:\n\nAssuming that Vertex v has to be black, find the number of ways in which the vertices can be painted, modulo M.\n\nSample Input 1\n\n3 100\n1 2\n2 3\n\nSample Output 1\n\n3\n4\n3\n\nThere are seven ways to paint the vertices, as shown in the figure below.\nAmong them, there are three ways such that Vertex 1 is black, four ways such that Vertex 2 is black and three ways such that Vertex 3 is black.\n\nSample Input 2\n\n4 100\n1 2\n1 3\n1 4\n\nSample Output 2\n\n8\n5\n5\n5\n\nSample Input 3\n\n1 100\n\nSample Output 3\n\n1\n\nSample Input 4\n\n10 2\n8 5\n10 8\n6 5\n1 5\n4 8\n2 10\n3 6\n9 2\n1 7\n\nSample Output 4\n\n0\n0\n1\n1\n1\n0\n1\n0\n1\n1\n\nBe sure to print the answers modulo M.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8588, "cpu_time_ms": 150, "memory_kb": 52804}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s668229228", "group_id": "codeNet:p03183", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ 10001)\n(defconstant +nan+ -1)\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (dp (make-array (list (+ n 1) 10002) :element-type 'fixnum :initial-element +nan+))\n (towers (make-array n :element-type 'list)))\n (declare (uint31 n))\n (dotimes (i n)\n (setf (aref towers i) (list (read) (read) (read))))\n (setq towers (sort towers #'> :key (lambda (node) (+ (first node) (second node)))))\n (setf (aref dp 0 +inf+) 0)\n (dotimes (x n)\n (destructuring-bind (w s v) (aref towers x)\n (declare (uint31 w s v))\n (loop for y from 0 to 10000\n unless (= (aref dp x y) +nan+)\n do (maxf (aref dp (+ x 1) y) (aref dp x y))\n (let ((next-y (min s (- y w))))\n (when (>= next-y 0)\n (maxf (aref dp (+ x 1) next-y)\n (+ v (aref dp x y))))))\n (maxf (aref dp (+ x 1) +inf+)\n (aref dp x +inf+))\n (maxf (aref dp (+ x 1) s)\n (+ v (aref dp x +inf+)))))\n (println (loop for y from 0 below 10002\n maximize (aref dp n y)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n2 2 20\n2 1 30\n3 1 40\n\"\n \"50\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 2 10\n3 1 10\n2 4 10\n1 6 10\n\"\n \"40\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n1 10000 1000000000\n1 10000 1000000000\n1 10000 1000000000\n1 10000 1000000000\n1 10000 1000000000\n\"\n \"5000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n9 5 7\n6 2 7\n5 7 3\n7 8 8\n1 9 6\n3 3 3\n4 1 7\n4 5 5\n\"\n \"22\n\")))\n", "language": "Lisp", "metadata": {"date": 1593294877, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03183.html", "problem_id": "p03183", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03183/input.txt", "sample_output_relpath": "derived/input_output/data/p03183/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03183/Lisp/s668229228.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s668229228", "user_id": "u352600849"}, "prompt_components": {"gold_output": "50\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ 10001)\n(defconstant +nan+ -1)\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (dp (make-array (list (+ n 1) 10002) :element-type 'fixnum :initial-element +nan+))\n (towers (make-array n :element-type 'list)))\n (declare (uint31 n))\n (dotimes (i n)\n (setf (aref towers i) (list (read) (read) (read))))\n (setq towers (sort towers #'> :key (lambda (node) (+ (first node) (second node)))))\n (setf (aref dp 0 +inf+) 0)\n (dotimes (x n)\n (destructuring-bind (w s v) (aref towers x)\n (declare (uint31 w s v))\n (loop for y from 0 to 10000\n unless (= (aref dp x y) +nan+)\n do (maxf (aref dp (+ x 1) y) (aref dp x y))\n (let ((next-y (min s (- y w))))\n (when (>= next-y 0)\n (maxf (aref dp (+ x 1) next-y)\n (+ v (aref dp x y))))))\n (maxf (aref dp (+ x 1) +inf+)\n (aref dp x +inf+))\n (maxf (aref dp (+ x 1) s)\n (+ v (aref dp x +inf+)))))\n (println (loop for y from 0 below 10002\n maximize (aref dp n y)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n2 2 20\n2 1 30\n3 1 40\n\"\n \"50\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 2 10\n3 1 10\n2 4 10\n1 6 10\n\"\n \"40\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n1 10000 1000000000\n1 10000 1000000000\n1 10000 1000000000\n1 10000 1000000000\n1 10000 1000000000\n\"\n \"5000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n9 5 7\n6 2 7\n5 7 3\n7 8 8\n1 9 6\n3 3 3\n4 1 7\n4 5 5\n\"\n \"22\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are N blocks, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N), Block i has a weight of w_i, a solidness of s_i and a value of v_i.\n\nTaro has decided to build a tower by choosing some of the N blocks and stacking them vertically in some order.\nHere, the tower must satisfy the following condition:\n\nFor each Block i contained in the tower, the sum of the weights of the blocks stacked above it is not greater than s_i.\n\nFind the maximum possible sum of the values of the blocks contained in the tower.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^3\n\n1 \\leq w_i, s_i \\leq 10^4\n\n1 \\leq v_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nw_1 s_1 v_1\nw_2 s_2 v_2\n:\nw_N s_N v_N\n\nOutput\n\nPrint the maximum possible sum of the values of the blocks contained in the tower.\n\nSample Input 1\n\n3\n2 2 20\n2 1 30\n3 1 40\n\nSample Output 1\n\n50\n\nIf Blocks 2, 1 are stacked in this order from top to bottom, this tower will satisfy the condition, with the total value of 30 + 20 = 50.\n\nSample Input 2\n\n4\n1 2 10\n3 1 10\n2 4 10\n1 6 10\n\nSample Output 2\n\n40\n\nBlocks 1, 2, 3, 4 should be stacked in this order from top to bottom.\n\nSample Input 3\n\n5\n1 10000 1000000000\n1 10000 1000000000\n1 10000 1000000000\n1 10000 1000000000\n1 10000 1000000000\n\nSample Output 3\n\n5000000000\n\nThe answer may not fit into a 32-bit integer type.\n\nSample Input 4\n\n8\n9 5 7\n6 2 7\n5 7 3\n7 8 8\n1 9 6\n3 3 3\n4 1 7\n4 5 5\n\nSample Output 4\n\n22\n\nWe should, for example, stack Blocks 5, 6, 8, 4 in this order from top to bottom.", "sample_input": "3\n2 2 20\n2 1 30\n3 1 40\n"}, "reference_outputs": ["50\n"], "source_document_id": "p03183", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are N blocks, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N), Block i has a weight of w_i, a solidness of s_i and a value of v_i.\n\nTaro has decided to build a tower by choosing some of the N blocks and stacking them vertically in some order.\nHere, the tower must satisfy the following condition:\n\nFor each Block i contained in the tower, the sum of the weights of the blocks stacked above it is not greater than s_i.\n\nFind the maximum possible sum of the values of the blocks contained in the tower.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^3\n\n1 \\leq w_i, s_i \\leq 10^4\n\n1 \\leq v_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nw_1 s_1 v_1\nw_2 s_2 v_2\n:\nw_N s_N v_N\n\nOutput\n\nPrint the maximum possible sum of the values of the blocks contained in the tower.\n\nSample Input 1\n\n3\n2 2 20\n2 1 30\n3 1 40\n\nSample Output 1\n\n50\n\nIf Blocks 2, 1 are stacked in this order from top to bottom, this tower will satisfy the condition, with the total value of 30 + 20 = 50.\n\nSample Input 2\n\n4\n1 2 10\n3 1 10\n2 4 10\n1 6 10\n\nSample Output 2\n\n40\n\nBlocks 1, 2, 3, 4 should be stacked in this order from top to bottom.\n\nSample Input 3\n\n5\n1 10000 1000000000\n1 10000 1000000000\n1 10000 1000000000\n1 10000 1000000000\n1 10000 1000000000\n\nSample Output 3\n\n5000000000\n\nThe answer may not fit into a 32-bit integer type.\n\nSample Input 4\n\n8\n9 5 7\n6 2 7\n5 7 3\n7 8 8\n1 9 6\n3 3 3\n4 1 7\n4 5 5\n\nSample Output 4\n\n22\n\nWe should, for example, stack Blocks 5, 6, 8, 4 in this order from top to bottom.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5146, "cpu_time_ms": 136, "memory_kb": 104824}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s696842661", "group_id": "codeNet:p03185", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Convex Hull Trick for monotone query (unfinished)\n;;;\n\n(deftype cht-element-type () 'fixnum)\n\n(define-condition cht-empty-error (simple-error)\n ((cht :initarg :cht :accessor cht-empty-error-cht))\n (:report (lambda (condition stream)\n (format stream\n \"Attempted to get a value on an empty CHT ~W\"\n (cht-empty-error-cht condition)))))\n\n(define-condition cht-full-error (simple-error)\n ((cht :initarg :cht :accessor cht-full-error-cht))\n (:report (lambda (condition stream)\n (format stream\n \"Attempted to push a value on a full CHT ~W\"\n (cht-full-error-cht condition)))))\n\n(defstruct (convex-hull-trick\n (:constructor make-cht\n (max-length\n &optional (minimum t)\n &aux\n (slopes (make-array max-length :element-type 'cht-element-type))\n (intercepts (make-array max-length :element-type 'cht-element-type))))\n (:conc-name %cht-)\n (:copier nil))\n (slopes nil :type (simple-array cht-element-type (*)))\n (intercepts nil :type (simple-array cht-element-type (*)))\n (minimum t :type boolean)\n (start 0 :type (integer 0 #.most-positive-fixnum))\n (length 0 :type (integer 0 #.most-positive-fixnum))\n (max-length 0 :type (integer 0 #.most-positive-fixnum)))\n\n;; four operations on deque\n(declaim (inline %cht-pop-back))\n(defun %cht-pop-back (cht)\n (decf (%cht-length cht)))\n\n(declaim (inline %cht-pop-front))\n(defun %cht-pop-front (cht)\n (decf (%cht-length cht))\n (incf (%cht-start cht))\n (when (= (%cht-start cht) (%cht-max-length cht))\n (setf (%cht-start cht) 0)))\n\n(declaim (inline %cht-push-back))\n(defun %cht-push-back (cht slope intercept)\n (let ((pos (+ (%cht-start cht) (%cht-length cht))))\n (declare ((integer 0 #.most-positive-fixnum) pos))\n (when (>= pos (%cht-max-length cht))\n (decf pos (%cht-max-length cht)))\n (setf (aref (%cht-slopes cht) pos) slope\n (aref (%cht-intercepts cht) pos) intercept)\n (incf (%cht-length cht))))\n\n(declaim (inline %cht-push-front))\n(defun %cht-push-front (cht slope intercept)\n (let ((new-start (- (%cht-start cht) 1)))\n (when (= -1 new-start)\n (incf new-start (%cht-max-length cht)))\n (setf (aref (%cht-slopes cht) new-start) slope\n (aref (%cht-intercepts cht) new-start) intercept)\n (setf (%cht-start cht) new-start)\n (incf (%cht-length cht))))\n\n(declaim (inline %removable-p))\n(defun %removable-p (slope1 intercept1 slope2 intercept2 slope3 intercept3)\n \"Returns true iff the **second** line is removable.\"\n (>= (the cht-element-type (* (- intercept3 intercept2)\n (- slope2 slope1)))\n (the cht-element-type (* (- intercept2 intercept1)\n (- slope3 slope2)))))\n\n;; NOTE: The slopes of lines newly added to CHT must be largest or smallest\n;; ever.\n(defun cht-push (cht slope intercept)\n \"Adds a new line to CHT.\"\n (declare (optimize (speed 3))\n (cht-element-type slope intercept))\n (when (= (%cht-length cht) (%cht-max-length cht))\n (error 'cht-full-error :cht cht))\n (unless (%cht-minimum cht)\n (setq slope (- slope)\n intercept (- intercept)))\n (let ((slopes (%cht-slopes cht))\n (intercepts (%cht-intercepts cht)))\n (labels ((ref (i)\n (let ((pos (+ (%cht-start cht) i)))\n (declare ((integer 0 #.most-positive-fixnum) pos))\n (when (>= pos (%cht-max-length cht))\n (decf pos (%cht-max-length cht)))\n (values (aref slopes pos) (aref intercepts pos)))))\n (cond ((zerop (%cht-length cht))\n (%cht-push-front cht slope intercept))\n ((>= slope (aref slopes (%cht-start cht)))\n ;; push the line to the front if SLOPE is larger than that of the head.\n (loop for start = (%cht-start cht)\n while (and (>= (%cht-length cht) 2)\n (let ((slope+1 (aref slopes start))\n (intercept+1 (aref intercepts start)))\n (multiple-value-bind (slope+2 intercept+2) (ref 1)\n (declare (cht-element-type slope+1 intercept+1 slope+2 intercept+2))\n (%removable-p slope intercept\n slope+1 intercept+1\n slope+2 intercept+2))))\n do (%cht-pop-front cht)\n finally (%cht-push-front cht slope intercept)))\n (t\n ;; push the line to the end if SLOPE is smaller than that of the tail.\n ;; TODO: assert it.\n (loop for offset = (%cht-length cht)\n while (and (>= offset 2)\n (multiple-value-bind (slope-2 intercept-2) (ref (- offset 2))\n (multiple-value-bind (slope-1 intercept-1) (ref (- offset 1))\n (declare (cht-element-type slope-2 intercept-2 slope-1 intercept-1))\n (%removable-p slope-2 intercept-2\n slope-1 intercept-1\n slope intercept))))\n do (%cht-pop-back cht)\n finally (%cht-push-back cht slope intercept))))\n cht)))\n\n(declaim (inline cht-get))\n(defun cht-get (cht x)\n \"Returns the minimum (maximum) value at X.\"\n (when (zerop (%cht-length cht))\n (error 'cht-empty-error :cht cht))\n (let ((ng -1)\n (ok (- (%cht-length cht) 1))\n (slopes (%cht-slopes cht))\n (intercepts (%cht-intercepts cht)))\n (declare ((integer -1 (#.array-total-size-limit)) ng ok))\n (labels ((calc (i)\n (let ((pos (+ (%cht-start cht) i)))\n (declare ((integer 0 #.most-positive-fixnum) pos))\n (when (>= pos (%cht-max-length cht))\n (decf pos (%cht-max-length cht)))\n (+ (* x (aref slopes pos))\n (aref intercepts pos)))))\n (loop\n (when (<= (- ok ng) 1)\n (return\n (if (%cht-minimum cht)\n (calc ok)\n (- (calc ok)))))\n (let ((mid (ash (+ ng ok) -1)))\n (if (< (calc mid) (calc (+ mid 1)))\n (setq ok mid)\n (setq ng mid)))))))\n\n(declaim (inline cht-increasing-get))\n(defun cht-increasing-get (cht x)\n (when (zerop (%cht-length cht))\n (error 'cht-empty-error :cht cht))\n (let ((slopes (%cht-slopes cht))\n (intercepts (%cht-intercepts cht)))\n (labels ((calc (slope intercept)\n (declare (cht-element-type slope intercept))\n (+ (* x slope) intercept)))\n (loop while (and (>= (%cht-length cht) 2)\n (let* ((pos (%cht-start cht))\n (slope0 (aref slopes pos))\n (intercept0 (aref intercepts pos)))\n (incf pos)\n (when (= pos (%cht-max-length cht))\n (setq pos 0))\n (let ((slope1 (aref slopes pos))\n (intercept1 (aref intercepts pos)))\n (>= (calc slope0 intercept0)\n (calc slope1 intercept1)))))\n do (%cht-pop-front cht))\n (let ((start (%cht-start cht)))\n (if (%cht-minimum cht)\n (calc (aref slopes start) (aref intercepts start))\n (- (calc (aref slopes start) (aref intercepts start))))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (c (read))\n (hs (make-array n :element-type 'uint31))\n (dp (make-array n :element-type 'uint62 :initial-element most-positive-fixnum))\n (cht (make-cht n)))\n (declare (uint62 n c))\n (dotimes (i n)\n (setf (aref hs i) (read-fixnum)))\n (setf (aref dp 0) 0)\n (loop for x from 1 below n\n do (cht-push cht\n (* -2 (aref hs (- x 1)))\n (+ (expt (aref hs (- x 1)) 2)\n (aref dp (- x 1))))\n (let ((chtmin (cht-increasing-get cht (aref hs x))))\n (declare (fixnum chtmin))\n (setf (aref dp x)\n (+ chtmin\n c\n (expt (aref hs x) 2)))))\n (println (aref dp (- n 1)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 6\n1 2 3 4 5\n\"\n \"20\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 1000000000000\n500000 1000000\n\"\n \"1250000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8 5\n1 3 4 5 10 11 12 13\n\"\n \"62\n\")))\n", "language": "Lisp", "metadata": {"date": 1572749451, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03185.html", "problem_id": "p03185", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03185/input.txt", "sample_output_relpath": "derived/input_output/data/p03185/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03185/Lisp/s696842661.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s696842661", "user_id": "u352600849"}, "prompt_components": {"gold_output": "20\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Convex Hull Trick for monotone query (unfinished)\n;;;\n\n(deftype cht-element-type () 'fixnum)\n\n(define-condition cht-empty-error (simple-error)\n ((cht :initarg :cht :accessor cht-empty-error-cht))\n (:report (lambda (condition stream)\n (format stream\n \"Attempted to get a value on an empty CHT ~W\"\n (cht-empty-error-cht condition)))))\n\n(define-condition cht-full-error (simple-error)\n ((cht :initarg :cht :accessor cht-full-error-cht))\n (:report (lambda (condition stream)\n (format stream\n \"Attempted to push a value on a full CHT ~W\"\n (cht-full-error-cht condition)))))\n\n(defstruct (convex-hull-trick\n (:constructor make-cht\n (max-length\n &optional (minimum t)\n &aux\n (slopes (make-array max-length :element-type 'cht-element-type))\n (intercepts (make-array max-length :element-type 'cht-element-type))))\n (:conc-name %cht-)\n (:copier nil))\n (slopes nil :type (simple-array cht-element-type (*)))\n (intercepts nil :type (simple-array cht-element-type (*)))\n (minimum t :type boolean)\n (start 0 :type (integer 0 #.most-positive-fixnum))\n (length 0 :type (integer 0 #.most-positive-fixnum))\n (max-length 0 :type (integer 0 #.most-positive-fixnum)))\n\n;; four operations on deque\n(declaim (inline %cht-pop-back))\n(defun %cht-pop-back (cht)\n (decf (%cht-length cht)))\n\n(declaim (inline %cht-pop-front))\n(defun %cht-pop-front (cht)\n (decf (%cht-length cht))\n (incf (%cht-start cht))\n (when (= (%cht-start cht) (%cht-max-length cht))\n (setf (%cht-start cht) 0)))\n\n(declaim (inline %cht-push-back))\n(defun %cht-push-back (cht slope intercept)\n (let ((pos (+ (%cht-start cht) (%cht-length cht))))\n (declare ((integer 0 #.most-positive-fixnum) pos))\n (when (>= pos (%cht-max-length cht))\n (decf pos (%cht-max-length cht)))\n (setf (aref (%cht-slopes cht) pos) slope\n (aref (%cht-intercepts cht) pos) intercept)\n (incf (%cht-length cht))))\n\n(declaim (inline %cht-push-front))\n(defun %cht-push-front (cht slope intercept)\n (let ((new-start (- (%cht-start cht) 1)))\n (when (= -1 new-start)\n (incf new-start (%cht-max-length cht)))\n (setf (aref (%cht-slopes cht) new-start) slope\n (aref (%cht-intercepts cht) new-start) intercept)\n (setf (%cht-start cht) new-start)\n (incf (%cht-length cht))))\n\n(declaim (inline %removable-p))\n(defun %removable-p (slope1 intercept1 slope2 intercept2 slope3 intercept3)\n \"Returns true iff the **second** line is removable.\"\n (>= (the cht-element-type (* (- intercept3 intercept2)\n (- slope2 slope1)))\n (the cht-element-type (* (- intercept2 intercept1)\n (- slope3 slope2)))))\n\n;; NOTE: The slopes of lines newly added to CHT must be largest or smallest\n;; ever.\n(defun cht-push (cht slope intercept)\n \"Adds a new line to CHT.\"\n (declare (optimize (speed 3))\n (cht-element-type slope intercept))\n (when (= (%cht-length cht) (%cht-max-length cht))\n (error 'cht-full-error :cht cht))\n (unless (%cht-minimum cht)\n (setq slope (- slope)\n intercept (- intercept)))\n (let ((slopes (%cht-slopes cht))\n (intercepts (%cht-intercepts cht)))\n (labels ((ref (i)\n (let ((pos (+ (%cht-start cht) i)))\n (declare ((integer 0 #.most-positive-fixnum) pos))\n (when (>= pos (%cht-max-length cht))\n (decf pos (%cht-max-length cht)))\n (values (aref slopes pos) (aref intercepts pos)))))\n (cond ((zerop (%cht-length cht))\n (%cht-push-front cht slope intercept))\n ((>= slope (aref slopes (%cht-start cht)))\n ;; push the line to the front if SLOPE is larger than that of the head.\n (loop for start = (%cht-start cht)\n while (and (>= (%cht-length cht) 2)\n (let ((slope+1 (aref slopes start))\n (intercept+1 (aref intercepts start)))\n (multiple-value-bind (slope+2 intercept+2) (ref 1)\n (declare (cht-element-type slope+1 intercept+1 slope+2 intercept+2))\n (%removable-p slope intercept\n slope+1 intercept+1\n slope+2 intercept+2))))\n do (%cht-pop-front cht)\n finally (%cht-push-front cht slope intercept)))\n (t\n ;; push the line to the end if SLOPE is smaller than that of the tail.\n ;; TODO: assert it.\n (loop for offset = (%cht-length cht)\n while (and (>= offset 2)\n (multiple-value-bind (slope-2 intercept-2) (ref (- offset 2))\n (multiple-value-bind (slope-1 intercept-1) (ref (- offset 1))\n (declare (cht-element-type slope-2 intercept-2 slope-1 intercept-1))\n (%removable-p slope-2 intercept-2\n slope-1 intercept-1\n slope intercept))))\n do (%cht-pop-back cht)\n finally (%cht-push-back cht slope intercept))))\n cht)))\n\n(declaim (inline cht-get))\n(defun cht-get (cht x)\n \"Returns the minimum (maximum) value at X.\"\n (when (zerop (%cht-length cht))\n (error 'cht-empty-error :cht cht))\n (let ((ng -1)\n (ok (- (%cht-length cht) 1))\n (slopes (%cht-slopes cht))\n (intercepts (%cht-intercepts cht)))\n (declare ((integer -1 (#.array-total-size-limit)) ng ok))\n (labels ((calc (i)\n (let ((pos (+ (%cht-start cht) i)))\n (declare ((integer 0 #.most-positive-fixnum) pos))\n (when (>= pos (%cht-max-length cht))\n (decf pos (%cht-max-length cht)))\n (+ (* x (aref slopes pos))\n (aref intercepts pos)))))\n (loop\n (when (<= (- ok ng) 1)\n (return\n (if (%cht-minimum cht)\n (calc ok)\n (- (calc ok)))))\n (let ((mid (ash (+ ng ok) -1)))\n (if (< (calc mid) (calc (+ mid 1)))\n (setq ok mid)\n (setq ng mid)))))))\n\n(declaim (inline cht-increasing-get))\n(defun cht-increasing-get (cht x)\n (when (zerop (%cht-length cht))\n (error 'cht-empty-error :cht cht))\n (let ((slopes (%cht-slopes cht))\n (intercepts (%cht-intercepts cht)))\n (labels ((calc (slope intercept)\n (declare (cht-element-type slope intercept))\n (+ (* x slope) intercept)))\n (loop while (and (>= (%cht-length cht) 2)\n (let* ((pos (%cht-start cht))\n (slope0 (aref slopes pos))\n (intercept0 (aref intercepts pos)))\n (incf pos)\n (when (= pos (%cht-max-length cht))\n (setq pos 0))\n (let ((slope1 (aref slopes pos))\n (intercept1 (aref intercepts pos)))\n (>= (calc slope0 intercept0)\n (calc slope1 intercept1)))))\n do (%cht-pop-front cht))\n (let ((start (%cht-start cht)))\n (if (%cht-minimum cht)\n (calc (aref slopes start) (aref intercepts start))\n (- (calc (aref slopes start) (aref intercepts start))))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (c (read))\n (hs (make-array n :element-type 'uint31))\n (dp (make-array n :element-type 'uint62 :initial-element most-positive-fixnum))\n (cht (make-cht n)))\n (declare (uint62 n c))\n (dotimes (i n)\n (setf (aref hs i) (read-fixnum)))\n (setf (aref dp 0) 0)\n (loop for x from 1 below n\n do (cht-push cht\n (* -2 (aref hs (- x 1)))\n (+ (expt (aref hs (- x 1)) 2)\n (aref dp (- x 1))))\n (let ((chtmin (cht-increasing-get cht (aref hs x))))\n (declare (fixnum chtmin))\n (setf (aref dp x)\n (+ chtmin\n c\n (expt (aref hs x) 2)))))\n (println (aref dp (- n 1)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 6\n1 2 3 4 5\n\"\n \"20\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 1000000000000\n500000 1000000\n\"\n \"1250000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8 5\n1 3 4 5 10 11 12 13\n\"\n \"62\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are N stones, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N), the height of Stone i is h_i.\nHere, h_1 < h_2 < \\cdots < h_N holds.\n\nThere is a frog who is initially on Stone 1.\nHe will repeat the following action some number of times to reach Stone N:\n\nIf the frog is currently on Stone i, jump to one of the following: Stone i + 1, i + 2, \\ldots, N. Here, a cost of (h_j - h_i)^2 + C is incurred, where j is the stone to land on.\n\nFind the minimum possible total cost incurred before the frog reaches Stone N.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq C \\leq 10^{12}\n\n1 \\leq h_1 < h_2 < \\cdots < h_N \\leq 10^6\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN C\nh_1 h_2 \\ldots h_N\n\nOutput\n\nPrint the minimum possible total cost incurred.\n\nSample Input 1\n\n5 6\n1 2 3 4 5\n\nSample Output 1\n\n20\n\nIf we follow the path 1 → 3 → 5, the total cost incurred would be ((3 - 1)^2 + 6) + ((5 - 3)^2 + 6) = 20.\n\nSample Input 2\n\n2 1000000000000\n500000 1000000\n\nSample Output 2\n\n1250000000000\n\nThe answer may not fit into a 32-bit integer type.\n\nSample Input 3\n\n8 5\n1 3 4 5 10 11 12 13\n\nSample Output 3\n\n62\n\nIf we follow the path 1 → 2 → 4 → 5 → 8, the total cost incurred would be ((3 - 1)^2 + 5) + ((5 - 3)^2 + 5) + ((10 - 5)^2 + 5) + ((13 - 10)^2 + 5) = 62.", "sample_input": "5 6\n1 2 3 4 5\n"}, "reference_outputs": ["20\n"], "source_document_id": "p03185", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are N stones, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N), the height of Stone i is h_i.\nHere, h_1 < h_2 < \\cdots < h_N holds.\n\nThere is a frog who is initially on Stone 1.\nHe will repeat the following action some number of times to reach Stone N:\n\nIf the frog is currently on Stone i, jump to one of the following: Stone i + 1, i + 2, \\ldots, N. Here, a cost of (h_j - h_i)^2 + C is incurred, where j is the stone to land on.\n\nFind the minimum possible total cost incurred before the frog reaches Stone N.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq C \\leq 10^{12}\n\n1 \\leq h_1 < h_2 < \\cdots < h_N \\leq 10^6\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN C\nh_1 h_2 \\ldots h_N\n\nOutput\n\nPrint the minimum possible total cost incurred.\n\nSample Input 1\n\n5 6\n1 2 3 4 5\n\nSample Output 1\n\n20\n\nIf we follow the path 1 → 3 → 5, the total cost incurred would be ((3 - 1)^2 + 6) + ((5 - 3)^2 + 6) = 20.\n\nSample Input 2\n\n2 1000000000000\n500000 1000000\n\nSample Output 2\n\n1250000000000\n\nThe answer may not fit into a 32-bit integer type.\n\nSample Input 3\n\n8 5\n1 3 4 5 10 11 12 13\n\nSample Output 3\n\n62\n\nIf we follow the path 1 → 2 → 4 → 5 → 8, the total cost incurred would be ((3 - 1)^2 + 5) + ((5 - 3)^2 + 5) + ((10 - 5)^2 + 5) + ((13 - 10)^2 + 5) = 62.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 13232, "cpu_time_ms": 359, "memory_kb": 42592}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s693946612", "group_id": "codeNet:p03186", "input_text": "(let ((a (read)) (b (read)) (c (read)))\n (format t \"~D~%\" (+ b (min c (+ a c 1))))\n)", "language": "Lisp", "metadata": {"date": 1558448531, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03186.html", "problem_id": "p03186", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03186/input.txt", "sample_output_relpath": "derived/input_output/data/p03186/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03186/Lisp/s693946612.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s693946612", "user_id": "u966695411"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(let ((a (read)) (b (read)) (c (read)))\n (format t \"~D~%\" (+ b (min c (+ a c 1))))\n)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison.\n\nEating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death.\nAs he wants to live, he cannot eat one in such a situation.\nEating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches.\n\nFind the maximum number of tasty cookies that Takahashi can eat.\n\nConstraints\n\n0 \\leq A,B,C \\leq 10^9\n\nA,B and C are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the maximum number of tasty cookies that Takahashi can eat.\n\nSample Input 1\n\n3 1 4\n\nSample Output 1\n\n5\n\nWe can eat all tasty cookies, in the following order:\n\nA tasty cookie containing poison\n\nAn untasty cookie containing antidotes\n\nA tasty cookie containing poison\n\nA tasty cookie containing antidotes\n\nA tasty cookie containing poison\n\nAn untasty cookie containing antidotes\n\nA tasty cookie containing poison\n\nSample Input 2\n\n5 2 9\n\nSample Output 2\n\n10\n\nSample Input 3\n\n8 8 1\n\nSample Output 3\n\n9", "sample_input": "3 1 4\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03186", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison.\n\nEating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death.\nAs he wants to live, he cannot eat one in such a situation.\nEating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches.\n\nFind the maximum number of tasty cookies that Takahashi can eat.\n\nConstraints\n\n0 \\leq A,B,C \\leq 10^9\n\nA,B and C are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the maximum number of tasty cookies that Takahashi can eat.\n\nSample Input 1\n\n3 1 4\n\nSample Output 1\n\n5\n\nWe can eat all tasty cookies, in the following order:\n\nA tasty cookie containing poison\n\nAn untasty cookie containing antidotes\n\nA tasty cookie containing poison\n\nA tasty cookie containing antidotes\n\nA tasty cookie containing poison\n\nAn untasty cookie containing antidotes\n\nA tasty cookie containing poison\n\nSample Input 2\n\n5 2 9\n\nSample Output 2\n\n10\n\nSample Input 3\n\n8 8 1\n\nSample Output 3\n\n9", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 87, "cpu_time_ms": 13, "memory_kb": 3816}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s204398767", "group_id": "codeNet:p03186", "input_text": "(locally\n (declare (optimize (speed 3) (safety 0) (compilation-speed 3) (debug 0)))\n (defun poison (a b c)\n (declare (fixnum a b c))\n (write (if (> (+ a b 1) c) (+ b c) (+ a b b 1))))\n (poison (read) (read) (read)))", "language": "Lisp", "metadata": {"date": 1546148728, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03186.html", "problem_id": "p03186", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03186/input.txt", "sample_output_relpath": "derived/input_output/data/p03186/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03186/Lisp/s204398767.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s204398767", "user_id": "u048894831"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(locally\n (declare (optimize (speed 3) (safety 0) (compilation-speed 3) (debug 0)))\n (defun poison (a b c)\n (declare (fixnum a b c))\n (write (if (> (+ a b 1) c) (+ b c) (+ a b b 1))))\n (poison (read) (read) (read)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison.\n\nEating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death.\nAs he wants to live, he cannot eat one in such a situation.\nEating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches.\n\nFind the maximum number of tasty cookies that Takahashi can eat.\n\nConstraints\n\n0 \\leq A,B,C \\leq 10^9\n\nA,B and C are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the maximum number of tasty cookies that Takahashi can eat.\n\nSample Input 1\n\n3 1 4\n\nSample Output 1\n\n5\n\nWe can eat all tasty cookies, in the following order:\n\nA tasty cookie containing poison\n\nAn untasty cookie containing antidotes\n\nA tasty cookie containing poison\n\nA tasty cookie containing antidotes\n\nA tasty cookie containing poison\n\nAn untasty cookie containing antidotes\n\nA tasty cookie containing poison\n\nSample Input 2\n\n5 2 9\n\nSample Output 2\n\n10\n\nSample Input 3\n\n8 8 1\n\nSample Output 3\n\n9", "sample_input": "3 1 4\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03186", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison.\n\nEating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death.\nAs he wants to live, he cannot eat one in such a situation.\nEating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches.\n\nFind the maximum number of tasty cookies that Takahashi can eat.\n\nConstraints\n\n0 \\leq A,B,C \\leq 10^9\n\nA,B and C are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the maximum number of tasty cookies that Takahashi can eat.\n\nSample Input 1\n\n3 1 4\n\nSample Output 1\n\n5\n\nWe can eat all tasty cookies, in the following order:\n\nA tasty cookie containing poison\n\nAn untasty cookie containing antidotes\n\nA tasty cookie containing poison\n\nA tasty cookie containing antidotes\n\nA tasty cookie containing poison\n\nAn untasty cookie containing antidotes\n\nA tasty cookie containing poison\n\nSample Input 2\n\n5 2 9\n\nSample Output 2\n\n10\n\nSample Input 3\n\n8 8 1\n\nSample Output 3\n\n9", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 219, "cpu_time_ms": 11, "memory_kb": 3432}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s634228129", "group_id": "codeNet:p03186", "input_text": "(let ((a (read)) (b (read)) (c (read)) (n 0))\n (declare (optimize (speed 3) (safety 0)))\n (declare (fixnum a b c n))\n (setq n (- (+ a b 1) c))\n (format t \"~a\" \n (if (> n 0) (+ b c) (+ b c n)))\n )\n", "language": "Lisp", "metadata": {"date": 1546138212, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03186.html", "problem_id": "p03186", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03186/input.txt", "sample_output_relpath": "derived/input_output/data/p03186/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03186/Lisp/s634228129.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s634228129", "user_id": "u048894831"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(let ((a (read)) (b (read)) (c (read)) (n 0))\n (declare (optimize (speed 3) (safety 0)))\n (declare (fixnum a b c n))\n (setq n (- (+ a b 1) c))\n (format t \"~a\" \n (if (> n 0) (+ b c) (+ b c n)))\n )\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison.\n\nEating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death.\nAs he wants to live, he cannot eat one in such a situation.\nEating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches.\n\nFind the maximum number of tasty cookies that Takahashi can eat.\n\nConstraints\n\n0 \\leq A,B,C \\leq 10^9\n\nA,B and C are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the maximum number of tasty cookies that Takahashi can eat.\n\nSample Input 1\n\n3 1 4\n\nSample Output 1\n\n5\n\nWe can eat all tasty cookies, in the following order:\n\nA tasty cookie containing poison\n\nAn untasty cookie containing antidotes\n\nA tasty cookie containing poison\n\nA tasty cookie containing antidotes\n\nA tasty cookie containing poison\n\nAn untasty cookie containing antidotes\n\nA tasty cookie containing poison\n\nSample Input 2\n\n5 2 9\n\nSample Output 2\n\n10\n\nSample Input 3\n\n8 8 1\n\nSample Output 3\n\n9", "sample_input": "3 1 4\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03186", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison.\n\nEating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death.\nAs he wants to live, he cannot eat one in such a situation.\nEating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches.\n\nFind the maximum number of tasty cookies that Takahashi can eat.\n\nConstraints\n\n0 \\leq A,B,C \\leq 10^9\n\nA,B and C are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the maximum number of tasty cookies that Takahashi can eat.\n\nSample Input 1\n\n3 1 4\n\nSample Output 1\n\n5\n\nWe can eat all tasty cookies, in the following order:\n\nA tasty cookie containing poison\n\nAn untasty cookie containing antidotes\n\nA tasty cookie containing poison\n\nA tasty cookie containing antidotes\n\nA tasty cookie containing poison\n\nAn untasty cookie containing antidotes\n\nA tasty cookie containing poison\n\nSample Input 2\n\n5 2 9\n\nSample Output 2\n\n10\n\nSample Input 3\n\n8 8 1\n\nSample Output 3\n\n9", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 223, "cpu_time_ms": 321, "memory_kb": 11872}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s787666019", "group_id": "codeNet:p03192", "input_text": "(count #\\2 (read-line))", "language": "Lisp", "metadata": {"date": 1547010355, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03192.html", "problem_id": "p03192", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03192/input.txt", "sample_output_relpath": "derived/input_output/data/p03192/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03192/Lisp/s787666019.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s787666019", "user_id": "u652695471"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(count #\\2 (read-line))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given an integer N that has exactly four digits in base ten.\nHow many times does 2 occur in the base-ten representation of N?\n\nConstraints\n\n1000 \\leq N \\leq 9999\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n1222\n\nSample Output 1\n\n3\n\n2 occurs three times in 1222. By the way, this contest is held on December 22 (JST).\n\nSample Input 2\n\n3456\n\nSample Output 2\n\n0\n\nSample Input 3\n\n9592\n\nSample Output 3\n\n1", "sample_input": "1222\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03192", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given an integer N that has exactly four digits in base ten.\nHow many times does 2 occur in the base-ten representation of N?\n\nConstraints\n\n1000 \\leq N \\leq 9999\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n1222\n\nSample Output 1\n\n3\n\n2 occurs three times in 1222. By the way, this contest is held on December 22 (JST).\n\nSample Input 2\n\n3456\n\nSample Output 2\n\n0\n\nSample Input 3\n\n9592\n\nSample Output 3\n\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 23, "cpu_time_ms": 20, "memory_kb": 3812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s743257929", "group_id": "codeNet:p03194", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 1))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload :cl-debug-print))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * simple-bit-vector) make-prime-table))\n(defun make-prime-table (size)\n \"Erzeugt die Primzahlentabelle 0 zu SIZE-1.\"\n (declare (optimize (speed 3) (safety 1)))\n (let ((dict (make-array size :element-type 'bit :initial-element 1)))\n (setf (aref dict 0) 0 (aref dict 1) 0)\n (loop for even-num from 4 below size by 2\n do (setf (aref dict even-num) 0))\n (loop for p from 3 to (ceiling (sqrt size)) by 2\n when (= 1 (aref dict p))\n do (loop for composite from (+ p p) below size by p\n until (>= composite size)\n do (setf (aref dict composite) 0)))\n dict))\n\n(defun decompose-to-pow-table (num prime-table)\n (declare (optimize (speed 3) (safety 1))\n ((unsigned-byte 63) num) ; Beachte!\n ((simple-array bit (*)) prime-table))\n (let ((factor-table (make-array (length prime-table)\n :element-type '(unsigned-byte 7)\n :initial-element 0)))\n (when (= 1 (aref prime-table 2))\n (setf (aref factor-table 2)\n (loop while (evenp num)\n count t\n do (setf num (ash num -1)))))\n (loop for prime from 3 to (min num (- (length prime-table) 1)) by 2\n when (= 1 (aref prime-table prime))\n do (setf (aref factor-table prime)\n (loop with quot and rem\n do (setf (values quot rem) (floor num prime))\n while (zerop rem)\n count t\n do (setf num quot)))\n finally (return factor-table))))\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(prog1 (princ ,obj ,stream) (terpri ,stream)))\n\n;; Hauptteil\n\n;; Sei gcd(a1, ..., aN) = 2^f(2)*3^f(3)*....\n;; Da P = a1* ... *aN, gilt gcd(a1, ..., aN)^N | P und somit\n;; 2^(f(2)*N)*3^(f(3)*N)*... | P\n;; Wir müssen nur so ein f finden, so dass jedes f(k) maximal ist.\n;; Nun sei 2^g(2)*3^g(3)*.... die Primfaktorzerlegung von P.\n;; Dann muss f Folgendes erfüllen:\n;; f(2)* N <= g(2)\n;; f(3)* N <= g(3)...\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (p (read))\n (size 100001)\n (prime-dict (make-prime-table size))\n (factor-table (decompose-to-pow-table p prime-dict)))\n (declare (fixnum n p)\n ((simple-array (unsigned-byte 7) (*)) factor-table))\n (if (= n 1)\n (println p)\n (loop for prime from 2 below size\n with product of-type integer = 1\n when (>= (aref factor-table prime) 1)\n do (setf product\n (* product (expt prime (floor (aref factor-table prime) n))))\n finally (println product)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1545586366, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03194.html", "problem_id": "p03194", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03194/input.txt", "sample_output_relpath": "derived/input_output/data/p03194/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03194/Lisp/s743257929.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s743257929", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 1))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload :cl-debug-print))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * simple-bit-vector) make-prime-table))\n(defun make-prime-table (size)\n \"Erzeugt die Primzahlentabelle 0 zu SIZE-1.\"\n (declare (optimize (speed 3) (safety 1)))\n (let ((dict (make-array size :element-type 'bit :initial-element 1)))\n (setf (aref dict 0) 0 (aref dict 1) 0)\n (loop for even-num from 4 below size by 2\n do (setf (aref dict even-num) 0))\n (loop for p from 3 to (ceiling (sqrt size)) by 2\n when (= 1 (aref dict p))\n do (loop for composite from (+ p p) below size by p\n until (>= composite size)\n do (setf (aref dict composite) 0)))\n dict))\n\n(defun decompose-to-pow-table (num prime-table)\n (declare (optimize (speed 3) (safety 1))\n ((unsigned-byte 63) num) ; Beachte!\n ((simple-array bit (*)) prime-table))\n (let ((factor-table (make-array (length prime-table)\n :element-type '(unsigned-byte 7)\n :initial-element 0)))\n (when (= 1 (aref prime-table 2))\n (setf (aref factor-table 2)\n (loop while (evenp num)\n count t\n do (setf num (ash num -1)))))\n (loop for prime from 3 to (min num (- (length prime-table) 1)) by 2\n when (= 1 (aref prime-table prime))\n do (setf (aref factor-table prime)\n (loop with quot and rem\n do (setf (values quot rem) (floor num prime))\n while (zerop rem)\n count t\n do (setf num quot)))\n finally (return factor-table))))\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(prog1 (princ ,obj ,stream) (terpri ,stream)))\n\n;; Hauptteil\n\n;; Sei gcd(a1, ..., aN) = 2^f(2)*3^f(3)*....\n;; Da P = a1* ... *aN, gilt gcd(a1, ..., aN)^N | P und somit\n;; 2^(f(2)*N)*3^(f(3)*N)*... | P\n;; Wir müssen nur so ein f finden, so dass jedes f(k) maximal ist.\n;; Nun sei 2^g(2)*3^g(3)*.... die Primfaktorzerlegung von P.\n;; Dann muss f Folgendes erfüllen:\n;; f(2)* N <= g(2)\n;; f(3)* N <= g(3)...\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (p (read))\n (size 100001)\n (prime-dict (make-prime-table size))\n (factor-table (decompose-to-pow-table p prime-dict)))\n (declare (fixnum n p)\n ((simple-array (unsigned-byte 7) (*)) factor-table))\n (if (= n 1)\n (println p)\n (loop for prime from 2 below size\n with product of-type integer = 1\n when (>= (aref factor-table prime) 1)\n do (setf product\n (* product (expt prime (floor (aref factor-table prime) n))))\n finally (println product)))))\n\n#-swank(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N integers a_1, a_2, ..., a_N not less than 1.\nThe values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \\times a_2 \\times ... \\times a_N = P.\n\nFind the maximum possible greatest common divisor of a_1, a_2, ..., a_N.\n\nConstraints\n\n1 \\leq N \\leq 10^{12}\n\n1 \\leq P \\leq 10^{12}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN P\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3 24\n\nSample Output 1\n\n2\n\nThe greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and a_3=2.\n\nSample Input 2\n\n5 1\n\nSample Output 2\n\n1\n\nAs a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4 = a_5 = 1.\n\nSample Input 3\n\n1 111\n\nSample Output 3\n\n111\n\nSample Input 4\n\n4 972439611840\n\nSample Output 4\n\n206", "sample_input": "3 24\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03194", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N integers a_1, a_2, ..., a_N not less than 1.\nThe values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \\times a_2 \\times ... \\times a_N = P.\n\nFind the maximum possible greatest common divisor of a_1, a_2, ..., a_N.\n\nConstraints\n\n1 \\leq N \\leq 10^{12}\n\n1 \\leq P \\leq 10^{12}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN P\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n3 24\n\nSample Output 1\n\n2\n\nThe greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and a_3=2.\n\nSample Input 2\n\n5 1\n\nSample Output 2\n\n1\n\nAs a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4 = a_5 = 1.\n\nSample Input 3\n\n1 111\n\nSample Output 3\n\n111\n\nSample Input 4\n\n4 972439611840\n\nSample Output 4\n\n206", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3077, "cpu_time_ms": 98, "memory_kb": 14948}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s511116000", "group_id": "codeNet:p03197", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read)))\n (dotimes (_ n (write-line \"second\"))\n (when (oddp (read))\n (write-line \"first\")\n (return-from main)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1556058961, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03197.html", "problem_id": "p03197", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03197/input.txt", "sample_output_relpath": "derived/input_output/data/p03197/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03197/Lisp/s511116000.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s511116000", "user_id": "u352600849"}, "prompt_components": {"gold_output": "first\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read)))\n (dotimes (_ n (write-line \"second\"))\n (when (oddp (read))\n (write-line \"first\")\n (return-from main)))))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere is an apple tree that bears apples of N colors. The N colors of these apples are numbered 1 to N, and there are a_i apples of Color i.\n\nYou and Lunlun the dachshund alternately perform the following operation (starting from you):\n\nChoose one or more apples from the tree and eat them. Here, the apples chosen at the same time must all have different colors.\n\nThe one who eats the last apple from the tree will be declared winner. If both you and Lunlun play optimally, which will win?\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq a_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1\na_2\n:\na_N\n\nOutput\n\nIf you will win, print first; if Lunlun will win, print second.\n\nSample Input 1\n\n2\n1\n2\n\nSample Output 1\n\nfirst\n\nLet Color 1 be red, and Color 2 be blue. In this case, the tree bears one red apple and two blue apples.\n\nYou should eat the red apple in your first turn. Lunlun is then forced to eat one of the blue apples, and you can win by eating the other in your next turn.\n\nNote that you are also allowed to eat two apples in your first turn, one red and one blue (not a winning move, though).\n\nSample Input 2\n\n3\n100000\n30000\n20000\n\nSample Output 2\n\nsecond", "sample_input": "2\n1\n2\n"}, "reference_outputs": ["first\n"], "source_document_id": "p03197", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere is an apple tree that bears apples of N colors. The N colors of these apples are numbered 1 to N, and there are a_i apples of Color i.\n\nYou and Lunlun the dachshund alternately perform the following operation (starting from you):\n\nChoose one or more apples from the tree and eat them. Here, the apples chosen at the same time must all have different colors.\n\nThe one who eats the last apple from the tree will be declared winner. If both you and Lunlun play optimally, which will win?\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq a_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1\na_2\n:\na_N\n\nOutput\n\nIf you will win, print first; if Lunlun will win, print second.\n\nSample Input 1\n\n2\n1\n2\n\nSample Output 1\n\nfirst\n\nLet Color 1 be red, and Color 2 be blue. In this case, the tree bears one red apple and two blue apples.\n\nYou should eat the red apple in your first turn. Lunlun is then forced to eat one of the blue apples, and you can win by eating the other in your next turn.\n\nNote that you are also allowed to eat two apples in your first turn, one red and one blue (not a winning move, though).\n\nSample Input 2\n\n3\n100000\n30000\n20000\n\nSample Output 2\n\nsecond", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1372, "cpu_time_ms": 327, "memory_kb": 57828}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s390166731", "group_id": "codeNet:p03207", "input_text": "(let* ((a (read))\n (lst (loop :repeat a :collect (read))))\n (sort lst #'>)\n (princ (+ (floor (car lst) 2) (reduce #'+ (cdr lst)))))", "language": "Lisp", "metadata": {"date": 1544809543, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03207.html", "problem_id": "p03207", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03207/input.txt", "sample_output_relpath": "derived/input_output/data/p03207/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03207/Lisp/s390166731.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s390166731", "user_id": "u610490393"}, "prompt_components": {"gold_output": "15950\n", "input_to_evaluate": "(let* ((a (read))\n (lst (loop :repeat a :collect (read))))\n (sort lst #'>)\n (princ (+ (floor (car lst) 2) (reduce #'+ (cdr lst)))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nIn some other world, today is the day before Christmas Eve.\n\nMr. Takaha is buying N items at a department store. The regular price of the i-th item (1 \\leq i \\leq N) is p_i yen (the currency of Japan).\n\nHe has a discount coupon, and can buy one item with the highest price for half the regular price. The remaining N-1 items cost their regular prices. What is the total amount he will pay?\n\nConstraints\n\n2 \\leq N \\leq 10\n\n100 \\leq p_i \\leq 10000\n\np_i is an even number.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\np_1\np_2\n:\np_N\n\nOutput\n\nPrint the total amount Mr. Takaha will pay.\n\nSample Input 1\n\n3\n4980\n7980\n6980\n\nSample Output 1\n\n15950\n\nThe 7980-yen item gets the discount and the total is 4980 + 7980 / 2 + 6980 = 15950 yen.\n\nNote that outputs such as 15950.0 will be judged as Wrong Answer.\n\nSample Input 2\n\n4\n4320\n4320\n4320\n4320\n\nSample Output 2\n\n15120\n\nOnly one of the four items gets the discount and the total is 4320 / 2 + 4320 + 4320 + 4320 = 15120 yen.", "sample_input": "3\n4980\n7980\n6980\n"}, "reference_outputs": ["15950\n"], "source_document_id": "p03207", "source_text": "Score : 200 points\n\nProblem Statement\n\nIn some other world, today is the day before Christmas Eve.\n\nMr. Takaha is buying N items at a department store. The regular price of the i-th item (1 \\leq i \\leq N) is p_i yen (the currency of Japan).\n\nHe has a discount coupon, and can buy one item with the highest price for half the regular price. The remaining N-1 items cost their regular prices. What is the total amount he will pay?\n\nConstraints\n\n2 \\leq N \\leq 10\n\n100 \\leq p_i \\leq 10000\n\np_i is an even number.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\np_1\np_2\n:\np_N\n\nOutput\n\nPrint the total amount Mr. Takaha will pay.\n\nSample Input 1\n\n3\n4980\n7980\n6980\n\nSample Output 1\n\n15950\n\nThe 7980-yen item gets the discount and the total is 4980 + 7980 / 2 + 6980 = 15950 yen.\n\nNote that outputs such as 15950.0 will be judged as Wrong Answer.\n\nSample Input 2\n\n4\n4320\n4320\n4320\n4320\n\nSample Output 2\n\n15120\n\nOnly one of the four items gets the discount and the total is 4320 / 2 + 4320 + 4320 + 4320 = 15120 yen.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 139, "cpu_time_ms": 57, "memory_kb": 6500}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s778641743", "group_id": "codeNet:p03208", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 1))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload :cl-debug-print))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n\n(declaim (inline read-line-into))\n(defun read-line-into (buf-str &optional (in *standard-input*) (terminate-char #\\Newline))\n (declare (simple-base-string buf-str))\n (loop for ch of-type base-char =\n #-swank (code-char (read-byte in nil #\\Newline))\n #+swank (read-char in nil #\\Newline)\n for idx = 0 then (1+ idx)\n until (char= ch #\\Newline)\n do (setf (aref buf-str idx) ch)\n finally (setf (aref buf-str idx) terminate-char)\n (return buf-str)))\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(deftype uint nil `(integer 0 ,(expt 10 9)))\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (table (make-array (list n) :element-type 'uint))\n (buf (make-string 11 :element-type 'standard-char :initial-element #\\Newline)))\n (declare (uint k)\n ((simple-array uint (*)) table))\n (dotimes (idx n)\n (setf (aref table idx)\n (parse-integer (read-line-into buf *standard-input* #\\Newline) :junk-allowed t)))\n (stable-sort table #'<)\n (println\n (loop for begin-idx from 0\n for end-idx from (- (min k (length table)) 1) below (length table)\n minimize (- (aref table end-idx) (aref table begin-idx))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1545938246, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03208.html", "problem_id": "p03208", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03208/input.txt", "sample_output_relpath": "derived/input_output/data/p03208/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03208/Lisp/s778641743.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s778641743", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 1))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload :cl-debug-print))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n\n(declaim (inline read-line-into))\n(defun read-line-into (buf-str &optional (in *standard-input*) (terminate-char #\\Newline))\n (declare (simple-base-string buf-str))\n (loop for ch of-type base-char =\n #-swank (code-char (read-byte in nil #\\Newline))\n #+swank (read-char in nil #\\Newline)\n for idx = 0 then (1+ idx)\n until (char= ch #\\Newline)\n do (setf (aref buf-str idx) ch)\n finally (setf (aref buf-str idx) terminate-char)\n (return buf-str)))\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(deftype uint nil `(integer 0 ,(expt 10 9)))\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (table (make-array (list n) :element-type 'uint))\n (buf (make-string 11 :element-type 'standard-char :initial-element #\\Newline)))\n (declare (uint k)\n ((simple-array uint (*)) table))\n (dotimes (idx n)\n (setf (aref table idx)\n (parse-integer (read-line-into buf *standard-input* #\\Newline) :junk-allowed t)))\n (stable-sort table #'<)\n (println\n (loop for begin-idx from 0\n for end-idx from (- (min k (length table)) 1) below (length table)\n minimize (- (aref table end-idx) (aref table begin-idx))))))\n\n#-swank(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nIn some other world, today is Christmas Eve.\n\nThere are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \\leq i \\leq N) is h_i meters.\n\nHe decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.\n\nMore specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?\n\nConstraints\n\n2 \\leq K < N \\leq 10^5\n\n1 \\leq h_i \\leq 10^9\n\nh_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nh_1\nh_2\n:\nh_N\n\nOutput\n\nPrint the minimum possible value of h_{max} - h_{min}.\n\nSample Input 1\n\n5 3\n10\n15\n11\n14\n12\n\nSample Output 1\n\n2\n\nIf we decorate the first, third and fifth trees, h_{max} = 12, h_{min} = 10 so h_{max} - h_{min} = 2. This is optimal.\n\nSample Input 2\n\n5 3\n5\n7\n5\n7\n7\n\nSample Output 2\n\n0\n\nIf we decorate the second, fourth and fifth trees, h_{max} = 7, h_{min} = 7 so h_{max} - h_{min} = 0. This is optimal.\n\nThere are not too many trees in these sample inputs, but note that there can be at most one hundred thousand trees (we just can't put a sample with a hundred thousand lines here).", "sample_input": "5 3\n10\n15\n11\n14\n12\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03208", "source_text": "Score : 300 points\n\nProblem Statement\n\nIn some other world, today is Christmas Eve.\n\nThere are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \\leq i \\leq N) is h_i meters.\n\nHe decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.\n\nMore specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?\n\nConstraints\n\n2 \\leq K < N \\leq 10^5\n\n1 \\leq h_i \\leq 10^9\n\nh_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nh_1\nh_2\n:\nh_N\n\nOutput\n\nPrint the minimum possible value of h_{max} - h_{min}.\n\nSample Input 1\n\n5 3\n10\n15\n11\n14\n12\n\nSample Output 1\n\n2\n\nIf we decorate the first, third and fifth trees, h_{max} = 12, h_{min} = 10 so h_{max} - h_{min} = 2. This is optimal.\n\nSample Input 2\n\n5 3\n5\n7\n5\n7\n7\n\nSample Output 2\n\n0\n\nIf we decorate the second, fourth and fifth trees, h_{max} = 7, h_{min} = 7 so h_{max} - h_{min} = 0. This is optimal.\n\nThere are not too many trees in these sample inputs, but note that there can be at most one hundred thousand trees (we just can't put a sample with a hundred thousand lines here).", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1723, "cpu_time_ms": 206, "memory_kb": 20704}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s983882139", "group_id": "codeNet:p03210", "input_text": "(defun to_be_celebrate(n)\n (or (= n 3) (= n 5) (= n 7)))\n\n(print (if (to_be_celebrate (read)) 'YES 'NO))\n", "language": "Lisp", "metadata": {"date": 1546716430, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03210.html", "problem_id": "p03210", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03210/input.txt", "sample_output_relpath": "derived/input_output/data/p03210/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03210/Lisp/s983882139.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s983882139", "user_id": "u953240666"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(defun to_be_celebrate(n)\n (or (= n 3) (= n 5) (= n 7)))\n\n(print (if (to_be_celebrate (read)) 'YES 'NO))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nShichi-Go-San (literally \"Seven-Five-Three\") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.\n\nTakahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?\n\nConstraints\n\n1 ≤ X ≤ 9\n\nX is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nIf Takahashi's growth will be celebrated, print YES; if it will not, print NO.\n\nSample Input 1\n\n5\n\nSample Output 1\n\nYES\n\nThe growth of a five-year-old child will be celebrated.\n\nSample Input 2\n\n6\n\nSample Output 2\n\nNO\n\nSee you next year.", "sample_input": "5\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03210", "source_text": "Score : 100 points\n\nProblem Statement\n\nShichi-Go-San (literally \"Seven-Five-Three\") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.\n\nTakahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?\n\nConstraints\n\n1 ≤ X ≤ 9\n\nX is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nIf Takahashi's growth will be celebrated, print YES; if it will not, print NO.\n\nSample Input 1\n\n5\n\nSample Output 1\n\nYES\n\nThe growth of a five-year-old child will be celebrated.\n\nSample Input 2\n\n6\n\nSample Output 2\n\nNO\n\nSee you next year.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 106, "cpu_time_ms": 21, "memory_kb": 3684}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s633614206", "group_id": "codeNet:p03210", "input_text": "(let ((x (parse-integer (read-line))))\n (if (or (= x 3)\n (= x 5)\n (= x 7))\n (format t \"YES\")\n (format t \"NO\")))", "language": "Lisp", "metadata": {"date": 1544825804, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03210.html", "problem_id": "p03210", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03210/input.txt", "sample_output_relpath": "derived/input_output/data/p03210/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03210/Lisp/s633614206.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s633614206", "user_id": "u434088994"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(let ((x (parse-integer (read-line))))\n (if (or (= x 3)\n (= x 5)\n (= x 7))\n (format t \"YES\")\n (format t \"NO\")))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nShichi-Go-San (literally \"Seven-Five-Three\") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.\n\nTakahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?\n\nConstraints\n\n1 ≤ X ≤ 9\n\nX is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nIf Takahashi's growth will be celebrated, print YES; if it will not, print NO.\n\nSample Input 1\n\n5\n\nSample Output 1\n\nYES\n\nThe growth of a five-year-old child will be celebrated.\n\nSample Input 2\n\n6\n\nSample Output 2\n\nNO\n\nSee you next year.", "sample_input": "5\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03210", "source_text": "Score : 100 points\n\nProblem Statement\n\nShichi-Go-San (literally \"Seven-Five-Three\") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.\n\nTakahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?\n\nConstraints\n\n1 ≤ X ≤ 9\n\nX is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nIf Takahashi's growth will be celebrated, print YES; if it will not, print NO.\n\nSample Input 1\n\n5\n\nSample Output 1\n\nYES\n\nThe growth of a five-year-old child will be celebrated.\n\nSample Input 2\n\n6\n\nSample Output 2\n\nNO\n\nSee you next year.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 140, "cpu_time_ms": 100, "memory_kb": 10084}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s143131343", "group_id": "codeNet:p03212", "input_text": "#+swank (declaim (optimize (speed 0) (safety 3) (debug 3)))\n#-swank (declaim (optimize (speed 3) (safety 0) (debug 0)))\n\n(defconstant +mod+ 1000000007)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (terpri stream))))\n\n\n(defmethod fast-sort ((sequence list) &key (test #'<))\n (declare (inline sort)\n (inline sb-impl::stable-sort-list))\n (sort sequence (lambda (x y)\n (funcall test x y))))\n\n\n(defmethod fast-sort ((sequence array) &key (test #'<))\n (declare (inline sort))\n (sort sequence (lambda (x y)\n (funcall test x y))))\n\n(defmacro read-numbers-to-list (size)\n `(progn\n (when (not (integerp ,size))\n (error \"Size must be integer.\"))\n (when (< ,size 0)\n (error \"Size must be plus or zero.\"))\n (loop repeat ,size collect (read))))\n\n\n\n(defmacro read-numbers-to-array (size)\n `(progn\n (when (not (integerp ,size))\n (error \"Size must be integer.\"))\n (when (< ,size 0)\n (error \"Size must be plus or zero.\"))\n (make-array ,size :initial-contents (read-numbers-to-list ,size))))\n\n(defmacro read-numbers-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size))))\n (dotimes (,r ,row-size)\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (read))))\n ,board)))\n\n\n(defmethod make-cumlative-sum ((sequence list))\n (labels ((inner (sequence &optional (acc '(0)))\n (if (null sequence)\n (reverse acc)\n (inner (rest sequence) (cons (+ (first sequence)\n (first acc))\n acc)))))\n (inner sequence)))\n\n\n(defmethod make-cumlative-sum ((sequence array))\n (declare (type (simple-array fixnum) sequence))\n (the array\n (let* ((n (length sequence))\n (acc (make-array (1+ n) :element-type 'integer :initial-element 0)))\n (loop for i below n do\n (setf (aref acc (1+ i)) (+ (aref sequence i)\n (aref acc i)))\n finally\n (return acc)))))\n\n\n\n\n(defun princ-for-each-line (list)\n (format t \"~{~a~&~}~&\" list))\n\n(defun unwrap (list)\n (format nil \"~{~a ~}~&\" list))\n\n\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n\n\n\n;;; Write code here\n\n(defun int->lst (k &optional (acc nil))\n (if (zerop k)\n acc\n (int->lst\n (truncate k 10)\n (cons (rem k 10) acc))))\n\n(defun lst->int (xs &optional (acc 0))\n (If (null xs)\n acc\n (let ((tmp (pop xs)))\n (lst->int xs (+ (* acc 10) tmp)))))\n\n(defun judge (k)\n (every\n (lambda (x) (plusp (count x (int->lst k))))\n '(3 5 7)))\n\n(defun solve (n)\n (labels ((inner (k)\n (if (> k n)\n 0\n (+\n (if (judge k) 1 0)\n (reduce #'+\n (mapcar (lambda (c)\n (inner (+ (* k 10)\n c)))\n '(3 5 7)))))))\n (inner 0)))\n\n\n(defun main ()\n (let ((n (read)))\n (format t \"~a~%\" (solve n))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1599141167, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03212.html", "problem_id": "p03212", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03212/input.txt", "sample_output_relpath": "derived/input_output/data/p03212/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03212/Lisp/s143131343.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s143131343", "user_id": "u425762225"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "#+swank (declaim (optimize (speed 0) (safety 3) (debug 3)))\n#-swank (declaim (optimize (speed 3) (safety 0) (debug 0)))\n\n(defconstant +mod+ 1000000007)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (terpri stream))))\n\n\n(defmethod fast-sort ((sequence list) &key (test #'<))\n (declare (inline sort)\n (inline sb-impl::stable-sort-list))\n (sort sequence (lambda (x y)\n (funcall test x y))))\n\n\n(defmethod fast-sort ((sequence array) &key (test #'<))\n (declare (inline sort))\n (sort sequence (lambda (x y)\n (funcall test x y))))\n\n(defmacro read-numbers-to-list (size)\n `(progn\n (when (not (integerp ,size))\n (error \"Size must be integer.\"))\n (when (< ,size 0)\n (error \"Size must be plus or zero.\"))\n (loop repeat ,size collect (read))))\n\n\n\n(defmacro read-numbers-to-array (size)\n `(progn\n (when (not (integerp ,size))\n (error \"Size must be integer.\"))\n (when (< ,size 0)\n (error \"Size must be plus or zero.\"))\n (make-array ,size :initial-contents (read-numbers-to-list ,size))))\n\n(defmacro read-numbers-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size))))\n (dotimes (,r ,row-size)\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (read))))\n ,board)))\n\n\n(defmethod make-cumlative-sum ((sequence list))\n (labels ((inner (sequence &optional (acc '(0)))\n (if (null sequence)\n (reverse acc)\n (inner (rest sequence) (cons (+ (first sequence)\n (first acc))\n acc)))))\n (inner sequence)))\n\n\n(defmethod make-cumlative-sum ((sequence array))\n (declare (type (simple-array fixnum) sequence))\n (the array\n (let* ((n (length sequence))\n (acc (make-array (1+ n) :element-type 'integer :initial-element 0)))\n (loop for i below n do\n (setf (aref acc (1+ i)) (+ (aref sequence i)\n (aref acc i)))\n finally\n (return acc)))))\n\n\n\n\n(defun princ-for-each-line (list)\n (format t \"~{~a~&~}~&\" list))\n\n(defun unwrap (list)\n (format nil \"~{~a ~}~&\" list))\n\n\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n\n\n\n;;; Write code here\n\n(defun int->lst (k &optional (acc nil))\n (if (zerop k)\n acc\n (int->lst\n (truncate k 10)\n (cons (rem k 10) acc))))\n\n(defun lst->int (xs &optional (acc 0))\n (If (null xs)\n acc\n (let ((tmp (pop xs)))\n (lst->int xs (+ (* acc 10) tmp)))))\n\n(defun judge (k)\n (every\n (lambda (x) (plusp (count x (int->lst k))))\n '(3 5 7)))\n\n(defun solve (n)\n (labels ((inner (k)\n (if (> k n)\n 0\n (+\n (if (judge k) 1 0)\n (reduce #'+\n (mapcar (lambda (c)\n (inner (+ (* k 10)\n c)))\n '(3 5 7)))))))\n (inner 0)))\n\n\n(defun main ()\n (let ((n (read)))\n (format t \"~a~%\" (solve n))))\n\n(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally \"Seven-Five-Three numbers\") are there?\n\nHere, a Shichi-Go-San number is a positive integer that satisfies the following condition:\n\nWhen the number is written in base ten, each of the digits 7, 5 and 3 appears at least once, and the other digits never appear.\n\nConstraints\n\n1 \\leq N < 10^9\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the number of the Shichi-Go-San numbers between 1 and N (inclusive).\n\nSample Input 1\n\n575\n\nSample Output 1\n\n4\n\nThere are four Shichi-Go-San numbers not greater than 575: 357, 375, 537 and 573.\n\nSample Input 2\n\n3600\n\nSample Output 2\n\n13\n\nThere are 13 Shichi-Go-San numbers not greater than 3600: the above four numbers, 735, 753, 3357, 3375, 3537, 3557, 3573, 3575 and 3577.\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\n26484", "sample_input": "575\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03212", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally \"Seven-Five-Three numbers\") are there?\n\nHere, a Shichi-Go-San number is a positive integer that satisfies the following condition:\n\nWhen the number is written in base ten, each of the digits 7, 5 and 3 appears at least once, and the other digits never appear.\n\nConstraints\n\n1 \\leq N < 10^9\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the number of the Shichi-Go-San numbers between 1 and N (inclusive).\n\nSample Input 1\n\n575\n\nSample Output 1\n\n4\n\nThere are four Shichi-Go-San numbers not greater than 575: 357, 375, 537 and 573.\n\nSample Input 2\n\n3600\n\nSample Output 2\n\n13\n\nThere are 13 Shichi-Go-San numbers not greater than 3600: the above four numbers, 735, 753, 3357, 3375, 3537, 3557, 3573, 3575 and 3577.\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\n26484", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3571, "cpu_time_ms": 63, "memory_kb": 37984}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s128290785", "group_id": "codeNet:p03219", "input_text": "(princ (+ (read)\n (floor (read) 2)))", "language": "Lisp", "metadata": {"date": 1599179727, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03219.html", "problem_id": "p03219", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03219/input.txt", "sample_output_relpath": "derived/input_output/data/p03219/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03219/Lisp/s128290785.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s128290785", "user_id": "u425762225"}, "prompt_components": {"gold_output": "110\n", "input_to_evaluate": "(princ (+ (read)\n (floor (read) 2)))", "problem_context": "Score: 100 points\n\nProblem Statement\n\nThere is a train going from Station A to Station B that costs X yen (the currency of Japan).\n\nAlso, there is a bus going from Station B to Station C that costs Y yen.\n\nJoisino got a special ticket. With this ticket, she can take the bus for half the fare if she travels from Station A to Station B by train and then travels from Station B to Station C by bus.\n\nHow much does it cost to travel from Station A to Station C if she uses this ticket?\n\nConstraints\n\n1 \\leq X,Y \\leq 100\n\nY is an even number.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nIf it costs x yen to travel from Station A to Station C, print x.\n\nSample Input 1\n\n81 58\n\nSample Output 1\n\n110\n\nThe train fare is 81 yen.\n\nThe train fare is 58 ⁄ 2=29 yen with the 50% discount.\n\nThus, it costs 110 yen to travel from Station A to Station C.\n\nSample Input 2\n\n4 54\n\nSample Output 2\n\n31", "sample_input": "81 58\n"}, "reference_outputs": ["110\n"], "source_document_id": "p03219", "source_text": "Score: 100 points\n\nProblem Statement\n\nThere is a train going from Station A to Station B that costs X yen (the currency of Japan).\n\nAlso, there is a bus going from Station B to Station C that costs Y yen.\n\nJoisino got a special ticket. With this ticket, she can take the bus for half the fare if she travels from Station A to Station B by train and then travels from Station B to Station C by bus.\n\nHow much does it cost to travel from Station A to Station C if she uses this ticket?\n\nConstraints\n\n1 \\leq X,Y \\leq 100\n\nY is an even number.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nIf it costs x yen to travel from Station A to Station C, print x.\n\nSample Input 1\n\n81 58\n\nSample Output 1\n\n110\n\nThe train fare is 81 yen.\n\nThe train fare is 58 ⁄ 2=29 yen with the 50% discount.\n\nThus, it costs 110 yen to travel from Station A to Station C.\n\nSample Input 2\n\n4 54\n\nSample Output 2\n\n31", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 45, "cpu_time_ms": 20, "memory_kb": 24076}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s303070572", "group_id": "codeNet:p03219", "input_text": "(defun fee (x y)\n (+ x (/ y 2))\n )\n(format t \"~A~%\" (fee (read) (read)))", "language": "Lisp", "metadata": {"date": 1561241162, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03219.html", "problem_id": "p03219", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03219/input.txt", "sample_output_relpath": "derived/input_output/data/p03219/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03219/Lisp/s303070572.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s303070572", "user_id": "u606976120"}, "prompt_components": {"gold_output": "110\n", "input_to_evaluate": "(defun fee (x y)\n (+ x (/ y 2))\n )\n(format t \"~A~%\" (fee (read) (read)))", "problem_context": "Score: 100 points\n\nProblem Statement\n\nThere is a train going from Station A to Station B that costs X yen (the currency of Japan).\n\nAlso, there is a bus going from Station B to Station C that costs Y yen.\n\nJoisino got a special ticket. With this ticket, she can take the bus for half the fare if she travels from Station A to Station B by train and then travels from Station B to Station C by bus.\n\nHow much does it cost to travel from Station A to Station C if she uses this ticket?\n\nConstraints\n\n1 \\leq X,Y \\leq 100\n\nY is an even number.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nIf it costs x yen to travel from Station A to Station C, print x.\n\nSample Input 1\n\n81 58\n\nSample Output 1\n\n110\n\nThe train fare is 81 yen.\n\nThe train fare is 58 ⁄ 2=29 yen with the 50% discount.\n\nThus, it costs 110 yen to travel from Station A to Station C.\n\nSample Input 2\n\n4 54\n\nSample Output 2\n\n31", "sample_input": "81 58\n"}, "reference_outputs": ["110\n"], "source_document_id": "p03219", "source_text": "Score: 100 points\n\nProblem Statement\n\nThere is a train going from Station A to Station B that costs X yen (the currency of Japan).\n\nAlso, there is a bus going from Station B to Station C that costs Y yen.\n\nJoisino got a special ticket. With this ticket, she can take the bus for half the fare if she travels from Station A to Station B by train and then travels from Station B to Station C by bus.\n\nHow much does it cost to travel from Station A to Station C if she uses this ticket?\n\nConstraints\n\n1 \\leq X,Y \\leq 100\n\nY is an even number.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nIf it costs x yen to travel from Station A to Station C, print x.\n\nSample Input 1\n\n81 58\n\nSample Output 1\n\n110\n\nThe train fare is 81 yen.\n\nThe train fare is 58 ⁄ 2=29 yen with the 50% discount.\n\nThus, it costs 110 yen to travel from Station A to Station C.\n\nSample Input 2\n\n4 54\n\nSample Output 2\n\n31", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 74, "cpu_time_ms": 91, "memory_kb": 10084}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s851161996", "group_id": "codeNet:p03219", "input_text": "(defun f (X Y)\n (format t \"~a\" (+ X (/ Y 2))))\n\n(f (read) (read))\n", "language": "Lisp", "metadata": {"date": 1544724750, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03219.html", "problem_id": "p03219", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03219/input.txt", "sample_output_relpath": "derived/input_output/data/p03219/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03219/Lisp/s851161996.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s851161996", "user_id": "u477651929"}, "prompt_components": {"gold_output": "110\n", "input_to_evaluate": "(defun f (X Y)\n (format t \"~a\" (+ X (/ Y 2))))\n\n(f (read) (read))\n", "problem_context": "Score: 100 points\n\nProblem Statement\n\nThere is a train going from Station A to Station B that costs X yen (the currency of Japan).\n\nAlso, there is a bus going from Station B to Station C that costs Y yen.\n\nJoisino got a special ticket. With this ticket, she can take the bus for half the fare if she travels from Station A to Station B by train and then travels from Station B to Station C by bus.\n\nHow much does it cost to travel from Station A to Station C if she uses this ticket?\n\nConstraints\n\n1 \\leq X,Y \\leq 100\n\nY is an even number.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nIf it costs x yen to travel from Station A to Station C, print x.\n\nSample Input 1\n\n81 58\n\nSample Output 1\n\n110\n\nThe train fare is 81 yen.\n\nThe train fare is 58 ⁄ 2=29 yen with the 50% discount.\n\nThus, it costs 110 yen to travel from Station A to Station C.\n\nSample Input 2\n\n4 54\n\nSample Output 2\n\n31", "sample_input": "81 58\n"}, "reference_outputs": ["110\n"], "source_document_id": "p03219", "source_text": "Score: 100 points\n\nProblem Statement\n\nThere is a train going from Station A to Station B that costs X yen (the currency of Japan).\n\nAlso, there is a bus going from Station B to Station C that costs Y yen.\n\nJoisino got a special ticket. With this ticket, she can take the bus for half the fare if she travels from Station A to Station B by train and then travels from Station B to Station C by bus.\n\nHow much does it cost to travel from Station A to Station C if she uses this ticket?\n\nConstraints\n\n1 \\leq X,Y \\leq 100\n\nY is an even number.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nIf it costs x yen to travel from Station A to Station C, print x.\n\nSample Input 1\n\n81 58\n\nSample Output 1\n\n110\n\nThe train fare is 81 yen.\n\nThe train fare is 58 ⁄ 2=29 yen with the 50% discount.\n\nThus, it costs 110 yen to travel from Station A to Station C.\n\nSample Input 2\n\n4 54\n\nSample Output 2\n\n31", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 67, "cpu_time_ms": 118, "memory_kb": 11492}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s556978848", "group_id": "codeNet:p03221", "input_text": "(let* ((n (read))\n (m (read))\n (stk (loop :repeat n :collect 1))\n (lst (loop :repeat m :collect (cons (read) (read))))\n (lst-st (copy-list lst)))\n (sort lst-st #'< :key #'cdr)\n (setf lst-st (mapcar (lambda (x) (list (car x) (1- (incf (elt stk (1- (car x))))) (cdr x))) lst-st))\n (loop :for k :in lst\n :for a := (find (cdr k) lst-st :key #'third :test #'=)\n :do (format t \"~6,'0d~6,'0d~%\" (first a) (second a))))", "language": "Lisp", "metadata": {"date": 1590820925, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03221.html", "problem_id": "p03221", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03221/input.txt", "sample_output_relpath": "derived/input_output/data/p03221/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03221/Lisp/s556978848.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s556978848", "user_id": "u610490393"}, "prompt_components": {"gold_output": "000001000002\n000002000001\n000001000001\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (stk (loop :repeat n :collect 1))\n (lst (loop :repeat m :collect (cons (read) (read))))\n (lst-st (copy-list lst)))\n (sort lst-st #'< :key #'cdr)\n (setf lst-st (mapcar (lambda (x) (list (car x) (1- (incf (elt stk (1- (car x))))) (cdr x))) lst-st))\n (loop :for k :in lst\n :for a := (find (cdr k) lst-st :key #'third :test #'=)\n :do (format t \"~6,'0d~6,'0d~%\" (first a) (second a))))", "problem_context": "Score: 300 points\n\nProblem Statement\n\nIn Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.\n\nCity i is established in year Y_i and belongs to Prefecture P_i.\n\nYou can assume that there are no multiple cities that are established in the same year.\n\nIt is decided to allocate a 12-digit ID number to each city.\n\nIf City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.\n\nHere, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.\n\nFind the ID numbers for all the cities.\n\nNote that there can be a prefecture with no cities.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq P_i \\leq N\n\n1 \\leq Y_i \\leq 10^9\n\nY_i are all different.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nP_1 Y_1\n:\nP_M Y_M\n\nOutput\n\nPrint the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...).\n\nSample Input 1\n\n2 3\n1 32\n2 63\n1 12\n\nSample Output 1\n\n000001000002\n000002000001\n000001000001\n\nAs City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.\n\nAs City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.\n\nAs City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.\n\nSample Input 2\n\n2 3\n2 55\n2 77\n2 99\n\nSample Output 2\n\n000002000001\n000002000002\n000002000003", "sample_input": "2 3\n1 32\n2 63\n1 12\n"}, "reference_outputs": ["000001000002\n000002000001\n000001000001\n"], "source_document_id": "p03221", "source_text": "Score: 300 points\n\nProblem Statement\n\nIn Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.\n\nCity i is established in year Y_i and belongs to Prefecture P_i.\n\nYou can assume that there are no multiple cities that are established in the same year.\n\nIt is decided to allocate a 12-digit ID number to each city.\n\nIf City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.\n\nHere, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.\n\nFind the ID numbers for all the cities.\n\nNote that there can be a prefecture with no cities.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq P_i \\leq N\n\n1 \\leq Y_i \\leq 10^9\n\nY_i are all different.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nP_1 Y_1\n:\nP_M Y_M\n\nOutput\n\nPrint the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...).\n\nSample Input 1\n\n2 3\n1 32\n2 63\n1 12\n\nSample Output 1\n\n000001000002\n000002000001\n000001000001\n\nAs City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.\n\nAs City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.\n\nAs City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.\n\nSample Input 2\n\n2 3\n2 55\n2 77\n2 99\n\nSample Output 2\n\n000002000001\n000002000002\n000002000003", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 452, "cpu_time_ms": 2105, "memory_kb": 61924}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s093130086", "group_id": "codeNet:p03221", "input_text": "(defvar *N* (read))\n(defvar *M* (read))\n\n(defun adjustment-digit (n)\n (let* ((tmp-str (write-to-string n))\n (size (length tmp-str)))\n (when (< size 6)\n (let ((tmp (list (coerce tmp-str 'character))))\n (dotimes (x (- 6 size))\n (push #\\0 tmp))\n (return-from adjustment-digit (concatenate 'string tmp))))\n tmp-str))\n\n(defun shape-ans (n lst)\n (let ((tmp-lst (list nil)))\n (dolist (x lst)\n (when (= n (car x))\n (push (cdr x) tmp-lst)))\n (setq tmp-lst (sort (cdr (reverse tmp-lst)) #'<))\n (let ((count 0)\n (tmp-alist (list nil))\n (r-lst (list nil))\n (flag nil))\n (dolist (x tmp-lst)\n (push (cons x (incf count)) tmp-alist))\n (setq tmp-alist (cdr (reverse tmp-alist)))\n (dolist (x lst)\n (dolist (y tmp-alist)\n (when (eql (cdr x) (car y))\n (push (cons 0 (concatenate 'string (adjustment-digit n) (adjustment-digit (cdr y)))) r-lst)\n (setq flag t)))\n (unless flag\n (push x r-lst))\n (setq flag nil))\n (cdr (reverse r-lst)))))\n\n(defun calc (lst &optional (n 1))\n (if (= n *N*)\n (shape-ans n lst)\n (calc (shape-ans n lst) (1+ n))))\n\n(defun main ()\n (let ((lst (list nil)))\n (dotimes (x *M*)\n (push (cons (read) (read)) lst))\n (setq lst (cdr (reverse lst)))\n (let ((result (calc lst)))\n (dolist (v result)\n (when (= 0 (car v))\n (format t \"~A~%\" (cdr v)))))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1541793053, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03221.html", "problem_id": "p03221", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03221/input.txt", "sample_output_relpath": "derived/input_output/data/p03221/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03221/Lisp/s093130086.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s093130086", "user_id": "u631655863"}, "prompt_components": {"gold_output": "000001000002\n000002000001\n000001000001\n", "input_to_evaluate": "(defvar *N* (read))\n(defvar *M* (read))\n\n(defun adjustment-digit (n)\n (let* ((tmp-str (write-to-string n))\n (size (length tmp-str)))\n (when (< size 6)\n (let ((tmp (list (coerce tmp-str 'character))))\n (dotimes (x (- 6 size))\n (push #\\0 tmp))\n (return-from adjustment-digit (concatenate 'string tmp))))\n tmp-str))\n\n(defun shape-ans (n lst)\n (let ((tmp-lst (list nil)))\n (dolist (x lst)\n (when (= n (car x))\n (push (cdr x) tmp-lst)))\n (setq tmp-lst (sort (cdr (reverse tmp-lst)) #'<))\n (let ((count 0)\n (tmp-alist (list nil))\n (r-lst (list nil))\n (flag nil))\n (dolist (x tmp-lst)\n (push (cons x (incf count)) tmp-alist))\n (setq tmp-alist (cdr (reverse tmp-alist)))\n (dolist (x lst)\n (dolist (y tmp-alist)\n (when (eql (cdr x) (car y))\n (push (cons 0 (concatenate 'string (adjustment-digit n) (adjustment-digit (cdr y)))) r-lst)\n (setq flag t)))\n (unless flag\n (push x r-lst))\n (setq flag nil))\n (cdr (reverse r-lst)))))\n\n(defun calc (lst &optional (n 1))\n (if (= n *N*)\n (shape-ans n lst)\n (calc (shape-ans n lst) (1+ n))))\n\n(defun main ()\n (let ((lst (list nil)))\n (dotimes (x *M*)\n (push (cons (read) (read)) lst))\n (setq lst (cdr (reverse lst)))\n (let ((result (calc lst)))\n (dolist (v result)\n (when (= 0 (car v))\n (format t \"~A~%\" (cdr v)))))))\n\n(main)\n", "problem_context": "Score: 300 points\n\nProblem Statement\n\nIn Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.\n\nCity i is established in year Y_i and belongs to Prefecture P_i.\n\nYou can assume that there are no multiple cities that are established in the same year.\n\nIt is decided to allocate a 12-digit ID number to each city.\n\nIf City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.\n\nHere, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.\n\nFind the ID numbers for all the cities.\n\nNote that there can be a prefecture with no cities.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq P_i \\leq N\n\n1 \\leq Y_i \\leq 10^9\n\nY_i are all different.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nP_1 Y_1\n:\nP_M Y_M\n\nOutput\n\nPrint the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...).\n\nSample Input 1\n\n2 3\n1 32\n2 63\n1 12\n\nSample Output 1\n\n000001000002\n000002000001\n000001000001\n\nAs City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.\n\nAs City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.\n\nAs City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.\n\nSample Input 2\n\n2 3\n2 55\n2 77\n2 99\n\nSample Output 2\n\n000002000001\n000002000002\n000002000003", "sample_input": "2 3\n1 32\n2 63\n1 12\n"}, "reference_outputs": ["000001000002\n000002000001\n000001000001\n"], "source_document_id": "p03221", "source_text": "Score: 300 points\n\nProblem Statement\n\nIn Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.\n\nCity i is established in year Y_i and belongs to Prefecture P_i.\n\nYou can assume that there are no multiple cities that are established in the same year.\n\nIt is decided to allocate a 12-digit ID number to each city.\n\nIf City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.\n\nHere, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.\n\nFind the ID numbers for all the cities.\n\nNote that there can be a prefecture with no cities.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq P_i \\leq N\n\n1 \\leq Y_i \\leq 10^9\n\nY_i are all different.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nP_1 Y_1\n:\nP_M Y_M\n\nOutput\n\nPrint the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...).\n\nSample Input 1\n\n2 3\n1 32\n2 63\n1 12\n\nSample Output 1\n\n000001000002\n000002000001\n000001000001\n\nAs City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.\n\nAs City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.\n\nAs City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.\n\nSample Input 2\n\n2 3\n2 55\n2 77\n2 99\n\nSample Output 2\n\n000002000001\n000002000002\n000002000003", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1481, "cpu_time_ms": 2106, "memory_kb": 86400}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s123213874", "group_id": "codeNet:p03221", "input_text": "(defvar *N* (read))\n(defvar *M* (read))\n\n(defun shape-ans (n lst)\n (let ((tmp-lst (list nil)))\n (dolist (x lst)\n (when (= n (car x))\n (push (cdr x) tmp-lst)))\n (setq tmp-lst (sort (cdr (reverse tmp-lst)) #'<))\n (let* ((count 0)\n (tmp-alist (loop for x in tmp-lst\n for y from 1 to (1+ (length tmp-lst))\n collect (cons x y)))\n (r-lst (list nil))\n (flag nil))\n (dolist (x lst)\n (dolist (y tmp-alist)\n (when (eql (cdr x) (car y))\n (push (cons 0 (concatenate 'string (format nil \"~6,'0D\" n) (format nil \"~6,'0D\" (cdr y)))) r-lst)\n (setq flag t)))\n (unless flag\n (push x r-lst))\n (setq flag nil))\n (cdr (reverse r-lst)))))\n\n(defun main ()\n (let ((lst (loop for x from 0 to *N*\n collect (cons (read) (read)))))\n (dotimes (x *N*)\n (setq lst (shape-ans (1+ x) lst)))\n (dolist (result lst)\n (when (= 0 (car result))\n (format t \"~A~%\" (cdr result))))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1541788694, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03221.html", "problem_id": "p03221", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03221/input.txt", "sample_output_relpath": "derived/input_output/data/p03221/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03221/Lisp/s123213874.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s123213874", "user_id": "u631655863"}, "prompt_components": {"gold_output": "000001000002\n000002000001\n000001000001\n", "input_to_evaluate": "(defvar *N* (read))\n(defvar *M* (read))\n\n(defun shape-ans (n lst)\n (let ((tmp-lst (list nil)))\n (dolist (x lst)\n (when (= n (car x))\n (push (cdr x) tmp-lst)))\n (setq tmp-lst (sort (cdr (reverse tmp-lst)) #'<))\n (let* ((count 0)\n (tmp-alist (loop for x in tmp-lst\n for y from 1 to (1+ (length tmp-lst))\n collect (cons x y)))\n (r-lst (list nil))\n (flag nil))\n (dolist (x lst)\n (dolist (y tmp-alist)\n (when (eql (cdr x) (car y))\n (push (cons 0 (concatenate 'string (format nil \"~6,'0D\" n) (format nil \"~6,'0D\" (cdr y)))) r-lst)\n (setq flag t)))\n (unless flag\n (push x r-lst))\n (setq flag nil))\n (cdr (reverse r-lst)))))\n\n(defun main ()\n (let ((lst (loop for x from 0 to *N*\n collect (cons (read) (read)))))\n (dotimes (x *N*)\n (setq lst (shape-ans (1+ x) lst)))\n (dolist (result lst)\n (when (= 0 (car result))\n (format t \"~A~%\" (cdr result))))))\n\n(main)\n", "problem_context": "Score: 300 points\n\nProblem Statement\n\nIn Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.\n\nCity i is established in year Y_i and belongs to Prefecture P_i.\n\nYou can assume that there are no multiple cities that are established in the same year.\n\nIt is decided to allocate a 12-digit ID number to each city.\n\nIf City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.\n\nHere, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.\n\nFind the ID numbers for all the cities.\n\nNote that there can be a prefecture with no cities.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq P_i \\leq N\n\n1 \\leq Y_i \\leq 10^9\n\nY_i are all different.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nP_1 Y_1\n:\nP_M Y_M\n\nOutput\n\nPrint the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...).\n\nSample Input 1\n\n2 3\n1 32\n2 63\n1 12\n\nSample Output 1\n\n000001000002\n000002000001\n000001000001\n\nAs City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.\n\nAs City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.\n\nAs City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.\n\nSample Input 2\n\n2 3\n2 55\n2 77\n2 99\n\nSample Output 2\n\n000002000001\n000002000002\n000002000003", "sample_input": "2 3\n1 32\n2 63\n1 12\n"}, "reference_outputs": ["000001000002\n000002000001\n000001000001\n"], "source_document_id": "p03221", "source_text": "Score: 300 points\n\nProblem Statement\n\nIn Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.\n\nCity i is established in year Y_i and belongs to Prefecture P_i.\n\nYou can assume that there are no multiple cities that are established in the same year.\n\nIt is decided to allocate a 12-digit ID number to each city.\n\nIf City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.\n\nHere, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.\n\nFind the ID numbers for all the cities.\n\nNote that there can be a prefecture with no cities.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq P_i \\leq N\n\n1 \\leq Y_i \\leq 10^9\n\nY_i are all different.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nP_1 Y_1\n:\nP_M Y_M\n\nOutput\n\nPrint the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...).\n\nSample Input 1\n\n2 3\n1 32\n2 63\n1 12\n\nSample Output 1\n\n000001000002\n000002000001\n000001000001\n\nAs City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.\n\nAs City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.\n\nAs City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.\n\nSample Input 2\n\n2 3\n2 55\n2 77\n2 99\n\nSample Output 2\n\n000002000001\n000002000002\n000002000003", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1077, "cpu_time_ms": 2106, "memory_kb": 98680}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s351190489", "group_id": "codeNet:p03221", "input_text": "(defvar *N* (read))\n(defvar *M* (read))\n\n(defun shape-ans (n lst)\n (let ((tmp-lst (list nil)))\n (dolist (x lst)\n (when (= n (car x))\n (push (cdr x) tmp-lst)))\n (setq tmp-lst (sort (cdr (reverse tmp-lst)) #'<))\n (let ((count 0)\n (tmp-alist (list nil))\n (r-lst (list nil))\n (flag nil))\n (dolist (x tmp-lst)\n (push (cons x (incf count)) tmp-alist))\n (setq tmp-alist (cdr (reverse tmp-alist)))\n (dolist (x lst)\n (dolist (y tmp-alist)\n (when (eql (cdr x) (car y))\n (push (cons 0 (concatenate 'string (format nil \"~6,'0D\" n) (format nil \"~6,'0D\" (cdr y)))) r-lst)\n (setq flag t)))\n (unless flag\n (push x r-lst))\n (setq flag nil))\n (cdr (reverse r-lst)))))\n\n(defun main ()\n (let ((lst (list nil)))\n (dotimes (x *M*)\n (let ((a (read))\n (b (read)))\n (push (cons a b lst))))\n (setq lst (cdr (reverse lst)))\n (dotimes (x *N*)\n (setq lst (shape-ans (1+ x) lst)))\n (dolist (result lst)\n (when (= 0 (car result))\n (princ (cdr result))))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1541773982, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03221.html", "problem_id": "p03221", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03221/input.txt", "sample_output_relpath": "derived/input_output/data/p03221/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03221/Lisp/s351190489.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s351190489", "user_id": "u631655863"}, "prompt_components": {"gold_output": "000001000002\n000002000001\n000001000001\n", "input_to_evaluate": "(defvar *N* (read))\n(defvar *M* (read))\n\n(defun shape-ans (n lst)\n (let ((tmp-lst (list nil)))\n (dolist (x lst)\n (when (= n (car x))\n (push (cdr x) tmp-lst)))\n (setq tmp-lst (sort (cdr (reverse tmp-lst)) #'<))\n (let ((count 0)\n (tmp-alist (list nil))\n (r-lst (list nil))\n (flag nil))\n (dolist (x tmp-lst)\n (push (cons x (incf count)) tmp-alist))\n (setq tmp-alist (cdr (reverse tmp-alist)))\n (dolist (x lst)\n (dolist (y tmp-alist)\n (when (eql (cdr x) (car y))\n (push (cons 0 (concatenate 'string (format nil \"~6,'0D\" n) (format nil \"~6,'0D\" (cdr y)))) r-lst)\n (setq flag t)))\n (unless flag\n (push x r-lst))\n (setq flag nil))\n (cdr (reverse r-lst)))))\n\n(defun main ()\n (let ((lst (list nil)))\n (dotimes (x *M*)\n (let ((a (read))\n (b (read)))\n (push (cons a b lst))))\n (setq lst (cdr (reverse lst)))\n (dotimes (x *N*)\n (setq lst (shape-ans (1+ x) lst)))\n (dolist (result lst)\n (when (= 0 (car result))\n (princ (cdr result))))))\n\n(main)\n", "problem_context": "Score: 300 points\n\nProblem Statement\n\nIn Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.\n\nCity i is established in year Y_i and belongs to Prefecture P_i.\n\nYou can assume that there are no multiple cities that are established in the same year.\n\nIt is decided to allocate a 12-digit ID number to each city.\n\nIf City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.\n\nHere, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.\n\nFind the ID numbers for all the cities.\n\nNote that there can be a prefecture with no cities.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq P_i \\leq N\n\n1 \\leq Y_i \\leq 10^9\n\nY_i are all different.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nP_1 Y_1\n:\nP_M Y_M\n\nOutput\n\nPrint the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...).\n\nSample Input 1\n\n2 3\n1 32\n2 63\n1 12\n\nSample Output 1\n\n000001000002\n000002000001\n000001000001\n\nAs City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.\n\nAs City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.\n\nAs City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.\n\nSample Input 2\n\n2 3\n2 55\n2 77\n2 99\n\nSample Output 2\n\n000002000001\n000002000002\n000002000003", "sample_input": "2 3\n1 32\n2 63\n1 12\n"}, "reference_outputs": ["000001000002\n000002000001\n000001000001\n"], "source_document_id": "p03221", "source_text": "Score: 300 points\n\nProblem Statement\n\nIn Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.\n\nCity i is established in year Y_i and belongs to Prefecture P_i.\n\nYou can assume that there are no multiple cities that are established in the same year.\n\nIt is decided to allocate a 12-digit ID number to each city.\n\nIf City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.\n\nHere, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.\n\nFind the ID numbers for all the cities.\n\nNote that there can be a prefecture with no cities.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq P_i \\leq N\n\n1 \\leq Y_i \\leq 10^9\n\nY_i are all different.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nP_1 Y_1\n:\nP_M Y_M\n\nOutput\n\nPrint the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...).\n\nSample Input 1\n\n2 3\n1 32\n2 63\n1 12\n\nSample Output 1\n\n000001000002\n000002000001\n000001000001\n\nAs City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.\n\nAs City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.\n\nAs City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.\n\nSample Input 2\n\n2 3\n2 55\n2 77\n2 99\n\nSample Output 2\n\n000002000001\n000002000002\n000002000003", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1131, "cpu_time_ms": 507, "memory_kb": 32996}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s439333380", "group_id": "codeNet:p03227", "input_text": "(let ((s (read-line)))\n (princ (if (equal (length s) 2)\n\t\t s\n\t\t (reverse s))))\n", "language": "Lisp", "metadata": {"date": 1576945380, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03227.html", "problem_id": "p03227", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03227/input.txt", "sample_output_relpath": "derived/input_output/data/p03227/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03227/Lisp/s439333380.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s439333380", "user_id": "u493610446"}, "prompt_components": {"gold_output": "cba\n", "input_to_evaluate": "(let ((s (read-line)))\n (princ (if (equal (length s) 2)\n\t\t s\n\t\t (reverse s))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.\n\nConstraints\n\nThe length of S is 2 or 3.\n\nS consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf the length of S is 2, print S as is; if the length is 3, print S after reversing it.\n\nSample Input 1\n\nabc\n\nSample Output 1\n\ncba\n\nAs the length of S is 3, we print it after reversing it.\n\nSample Input 2\n\nac\n\nSample Output 2\n\nac\n\nAs the length of S is 2, we print it as is.", "sample_input": "abc\n"}, "reference_outputs": ["cba\n"], "source_document_id": "p03227", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.\n\nConstraints\n\nThe length of S is 2 or 3.\n\nS consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf the length of S is 2, print S as is; if the length is 3, print S after reversing it.\n\nSample Input 1\n\nabc\n\nSample Output 1\n\ncba\n\nAs the length of S is 3, we print it after reversing it.\n\nSample Input 2\n\nac\n\nSample Output 2\n\nac\n\nAs the length of S is 2, we print it as is.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 84, "cpu_time_ms": 14, "memory_kb": 3684}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s089598549", "group_id": "codeNet:p03231", "input_text": ";; Two Abbreviations\n\n(defun f1 (n m s1 s2)\n (let ((k (gcd n m))\n )\n (labels ((inner (p q)\n (if (or (<= n p) (<= m q))\n t\n (if (eq (nth p s1)\n (nth q s2))\n (inner (+ (+ 1 p) (/ n k))\n (+ (+ 1 q) (/ m k)))\n nil))))\n (inner (/ n k) (/ m k))) \n ))\n\n(defun main ()\n (let ((n (read)) (m (read)))\n (if (f1 n m\n (loop for k from 1 upto n collect (read-char))\n (loop for k from 1 upto m collect (read-char)))\n (princ (lcm n m))\n (princ -1))))\n(main)", "language": "Lisp", "metadata": {"date": 1539484930, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03231.html", "problem_id": "p03231", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03231/input.txt", "sample_output_relpath": "derived/input_output/data/p03231/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03231/Lisp/s089598549.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s089598549", "user_id": "u396817842"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": ";; Two Abbreviations\n\n(defun f1 (n m s1 s2)\n (let ((k (gcd n m))\n )\n (labels ((inner (p q)\n (if (or (<= n p) (<= m q))\n t\n (if (eq (nth p s1)\n (nth q s2))\n (inner (+ (+ 1 p) (/ n k))\n (+ (+ 1 q) (/ m k)))\n nil))))\n (inner (/ n k) (/ m k))) \n ))\n\n(defun main ()\n (let ((n (read)) (m (read)))\n (if (f1 n m\n (loop for k from 1 upto n collect (read-char))\n (loop for k from 1 upto m collect (read-char)))\n (princ (lcm n m))\n (princ -1))))\n(main)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given a string S of length N and another string T of length M.\nThese strings consist of lowercase English letters.\n\nA string X is called a good string when the following conditions are all met:\n\nLet L be the length of X. L is divisible by both N and M.\n\nConcatenating the 1-st, (\\frac{L}{N}+1)-th, (2 \\times \\frac{L}{N}+1)-th, ..., ((N-1)\\times\\frac{L}{N}+1)-th characters of X, without changing the order, results in S.\n\nConcatenating the 1-st, (\\frac{L}{M}+1)-th, (2 \\times \\frac{L}{M}+1)-th, ..., ((M-1)\\times\\frac{L}{M}+1)-th characters of X, without changing the order, results in T.\n\nDetermine if there exists a good string. If it exists, find the length of the shortest such string.\n\nConstraints\n\n1 \\leq N,M \\leq 10^5\n\nS and T consist of lowercase English letters.\n\n|S|=N\n\n|T|=M\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nS\nT\n\nOutput\n\nIf a good string does not exist, print -1; if it exists, print the length of the shortest such string.\n\nSample Input 1\n\n3 2\nacp\nae\n\nSample Output 1\n\n6\n\nFor example, the string accept is a good string.\nThere is no good string shorter than this, so the answer is 6.\n\nSample Input 2\n\n6 3\nabcdef\nabc\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n15 9\ndnsusrayukuaiia\ndujrunuma\n\nSample Output 3\n\n45", "sample_input": "3 2\nacp\nae\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03231", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given a string S of length N and another string T of length M.\nThese strings consist of lowercase English letters.\n\nA string X is called a good string when the following conditions are all met:\n\nLet L be the length of X. L is divisible by both N and M.\n\nConcatenating the 1-st, (\\frac{L}{N}+1)-th, (2 \\times \\frac{L}{N}+1)-th, ..., ((N-1)\\times\\frac{L}{N}+1)-th characters of X, without changing the order, results in S.\n\nConcatenating the 1-st, (\\frac{L}{M}+1)-th, (2 \\times \\frac{L}{M}+1)-th, ..., ((M-1)\\times\\frac{L}{M}+1)-th characters of X, without changing the order, results in T.\n\nDetermine if there exists a good string. If it exists, find the length of the shortest such string.\n\nConstraints\n\n1 \\leq N,M \\leq 10^5\n\nS and T consist of lowercase English letters.\n\n|S|=N\n\n|T|=M\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nS\nT\n\nOutput\n\nIf a good string does not exist, print -1; if it exists, print the length of the shortest such string.\n\nSample Input 1\n\n3 2\nacp\nae\n\nSample Output 1\n\n6\n\nFor example, the string accept is a good string.\nThere is no good string shorter than this, so the answer is 6.\n\nSample Input 2\n\n6 3\nabcdef\nabc\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n15 9\ndnsusrayukuaiia\ndujrunuma\n\nSample Output 3\n\n45", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 652, "cpu_time_ms": 128, "memory_kb": 12904}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s020034967", "group_id": "codeNet:p03232", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\n\n;; TODO: non-global handling\n\n(defconstant +binom-size+ 110000)\n(defconstant +binom-mod+ #.(+ (expt 10 9) 7))\n\n(declaim ((simple-array (unsigned-byte 32) (*)) *fact* *fact-inv* *inv*))\n(defparameter *fact* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of factorials\")\n(defparameter *fact-inv* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of inverses of factorials\")\n(defparameter *inv* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of inverses of non-negative integers\")\n\n(defun initialize-binom ()\n (declare (optimize (speed 3) (safety 0)))\n (setf (aref *fact* 0) 1\n (aref *fact* 1) 1\n (aref *fact-inv* 0) 1\n (aref *fact-inv* 1) 1\n (aref *inv* 1) 1)\n (loop for i from 2 below +binom-size+\n do (setf (aref *fact* i) (mod (* i (aref *fact* (- i 1))) +binom-mod+)\n (aref *inv* i) (- +binom-mod+\n (mod (* (aref *inv* (rem +binom-mod+ i))\n (floor +binom-mod+ i))\n +binom-mod+))\n (aref *fact-inv* i) (mod (* (aref *inv* i)\n (aref *fact-inv* (- i 1)))\n +binom-mod+))))\n\n(initialize-binom)\n\n(declaim (inline binom))\n(defun binom (n k)\n \"Returns nCk.\"\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (mod (* (aref *fact* n)\n (mod (* (aref *fact-inv* k) (aref *fact-inv* (- n k))) +binom-mod+))\n +binom-mod+)))\n\n(declaim (inline perm))\n(defun perm (n k)\n \"Returns nPk.\"\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (mod (* (aref *fact* n) (aref *fact-inv* (- n k))) +binom-mod+)))\n\n;; TODO: compiler macro or source-transform\n(declaim (inline multinomial))\n(defun multinomial (&rest ks)\n \"Returns the multinomial coefficient K!/k_1!k_2!...k_n! for K = k_1 + k_2 +\n... + k_n. K must be equal to or smaller than\nMOST-POSITIVE-FIXNUM. (multinomial) returns 1.\"\n (let ((sum 0)\n (result 1))\n (declare ((integer 0 #.most-positive-fixnum) result sum))\n (dolist (k ks)\n (incf sum k)\n (setq result\n (mod (* result (aref *fact-inv* k)) +binom-mod+)))\n (mod (* result (aref *fact* sum)) +binom-mod+)))\n\n(declaim (inline catalan))\n(defun catalan (n)\n \"Returns the N-th Catalan number.\"\n (declare ((integer 0 #.most-positive-fixnum) n))\n (mod (* (aref *fact* (* 2 n))\n (mod (* (aref *fact-inv* (+ n 1))\n (aref *fact-inv* n))\n +binom-mod+))\n +binom-mod+))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n (res 0)\n (factor 0)\n (l 1)\n (r n))\n (declare (uint31 n res factor l r))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i n)\n (if (zerop i)\n (loop for i from 1 to n\n do (incfmod factor (aref *inv* i)))\n (progn\n (decfmod factor (aref *inv* r))\n (decf r)\n (incf l)\n (incfmod factor (aref *inv* l))))\n (incfmod res (mod* (aref *fact* n)\n (aref as i)\n factor)))\n (println res)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 2\n\"\n \"9\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 1 1 1\n\"\n \"212\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n1 2 4 8 16 32 64 128 256 512\n\"\n \"880971923\n\")))\n", "language": "Lisp", "metadata": {"date": 1580357427, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03232.html", "problem_id": "p03232", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03232/input.txt", "sample_output_relpath": "derived/input_output/data/p03232/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03232/Lisp/s020034967.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s020034967", "user_id": "u352600849"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\n\n;; TODO: non-global handling\n\n(defconstant +binom-size+ 110000)\n(defconstant +binom-mod+ #.(+ (expt 10 9) 7))\n\n(declaim ((simple-array (unsigned-byte 32) (*)) *fact* *fact-inv* *inv*))\n(defparameter *fact* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of factorials\")\n(defparameter *fact-inv* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of inverses of factorials\")\n(defparameter *inv* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of inverses of non-negative integers\")\n\n(defun initialize-binom ()\n (declare (optimize (speed 3) (safety 0)))\n (setf (aref *fact* 0) 1\n (aref *fact* 1) 1\n (aref *fact-inv* 0) 1\n (aref *fact-inv* 1) 1\n (aref *inv* 1) 1)\n (loop for i from 2 below +binom-size+\n do (setf (aref *fact* i) (mod (* i (aref *fact* (- i 1))) +binom-mod+)\n (aref *inv* i) (- +binom-mod+\n (mod (* (aref *inv* (rem +binom-mod+ i))\n (floor +binom-mod+ i))\n +binom-mod+))\n (aref *fact-inv* i) (mod (* (aref *inv* i)\n (aref *fact-inv* (- i 1)))\n +binom-mod+))))\n\n(initialize-binom)\n\n(declaim (inline binom))\n(defun binom (n k)\n \"Returns nCk.\"\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (mod (* (aref *fact* n)\n (mod (* (aref *fact-inv* k) (aref *fact-inv* (- n k))) +binom-mod+))\n +binom-mod+)))\n\n(declaim (inline perm))\n(defun perm (n k)\n \"Returns nPk.\"\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (mod (* (aref *fact* n) (aref *fact-inv* (- n k))) +binom-mod+)))\n\n;; TODO: compiler macro or source-transform\n(declaim (inline multinomial))\n(defun multinomial (&rest ks)\n \"Returns the multinomial coefficient K!/k_1!k_2!...k_n! for K = k_1 + k_2 +\n... + k_n. K must be equal to or smaller than\nMOST-POSITIVE-FIXNUM. (multinomial) returns 1.\"\n (let ((sum 0)\n (result 1))\n (declare ((integer 0 #.most-positive-fixnum) result sum))\n (dolist (k ks)\n (incf sum k)\n (setq result\n (mod (* result (aref *fact-inv* k)) +binom-mod+)))\n (mod (* result (aref *fact* sum)) +binom-mod+)))\n\n(declaim (inline catalan))\n(defun catalan (n)\n \"Returns the N-th Catalan number.\"\n (declare ((integer 0 #.most-positive-fixnum) n))\n (mod (* (aref *fact* (* 2 n))\n (mod (* (aref *fact-inv* (+ n 1))\n (aref *fact-inv* n))\n +binom-mod+))\n +binom-mod+))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n (res 0)\n (factor 0)\n (l 1)\n (r n))\n (declare (uint31 n res factor l r))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i n)\n (if (zerop i)\n (loop for i from 1 to n\n do (incfmod factor (aref *inv* i)))\n (progn\n (decfmod factor (aref *inv* r))\n (decf r)\n (incf l)\n (incfmod factor (aref *inv* l))))\n (incfmod res (mod* (aref *fact* n)\n (aref as i)\n factor)))\n (println res)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 2\n\"\n \"9\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 1 1 1\n\"\n \"212\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n1 2 4 8 16 32 64 128 256 512\n\"\n \"880971923\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere are N blocks arranged in a row, numbered 1 to N from left to right.\nEach block has a weight, and the weight of Block i is A_i.\nSnuke will perform the following operation on these blocks N times:\n\nChoose one block that is still not removed, and remove it.\nThe cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself).\nHere, two blocks x and y ( x \\leq y ) are connected when, for all z ( x \\leq z \\leq y ), Block z is still not removed.\n\nThere are N! possible orders in which Snuke removes the blocks.\nFor all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs.\nAs the answer can be extremely large, compute the sum modulo 10^9+7.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nFor all of the N! orders, find the total cost of the N operations, and print the sum of those N! total costs, modulo 10^9+7.\n\nSample Input 1\n\n2\n1 2\n\nSample Output 1\n\n9\n\nFirst, we will consider the order \"Block 1 -> Block 2\".\nIn the first operation, the cost of the operation is 1+2=3, as Block 1 and 2 are connected.\nIn the second operation, the cost of the operation is 2, as only Block 2 remains.\nThus, the total cost of the two operations for this order is 3+2=5.\n\nThen, we will consider the order \"Block 2 -> Block 1\".\nIn the first operation, the cost of the operation is 1+2=3, as Block 1 and 2 are connected.\nIn the second operation, the cost of the operation is 1, as only Block 1 remains.\nThus, the total cost of the two operations for this order is 3+1=4.\n\nTherefore, the answer is 5+4=9.\n\nSample Input 2\n\n4\n1 1 1 1\n\nSample Output 2\n\n212\n\nSample Input 3\n\n10\n1 2 4 8 16 32 64 128 256 512\n\nSample Output 3\n\n880971923", "sample_input": "2\n1 2\n"}, "reference_outputs": ["9\n"], "source_document_id": "p03232", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere are N blocks arranged in a row, numbered 1 to N from left to right.\nEach block has a weight, and the weight of Block i is A_i.\nSnuke will perform the following operation on these blocks N times:\n\nChoose one block that is still not removed, and remove it.\nThe cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself).\nHere, two blocks x and y ( x \\leq y ) are connected when, for all z ( x \\leq z \\leq y ), Block z is still not removed.\n\nThere are N! possible orders in which Snuke removes the blocks.\nFor all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs.\nAs the answer can be extremely large, compute the sum modulo 10^9+7.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nFor all of the N! orders, find the total cost of the N operations, and print the sum of those N! total costs, modulo 10^9+7.\n\nSample Input 1\n\n2\n1 2\n\nSample Output 1\n\n9\n\nFirst, we will consider the order \"Block 1 -> Block 2\".\nIn the first operation, the cost of the operation is 1+2=3, as Block 1 and 2 are connected.\nIn the second operation, the cost of the operation is 2, as only Block 2 remains.\nThus, the total cost of the two operations for this order is 3+2=5.\n\nThen, we will consider the order \"Block 2 -> Block 1\".\nIn the first operation, the cost of the operation is 1+2=3, as Block 1 and 2 are connected.\nIn the second operation, the cost of the operation is 1, as only Block 1 remains.\nThus, the total cost of the two operations for this order is 3+1=4.\n\nTherefore, the answer is 5+4=9.\n\nSample Input 2\n\n4\n1 1 1 1\n\nSample Output 2\n\n212\n\nSample Input 3\n\n10\n1 2 4 8 16 32 64 128 256 512\n\nSample Output 3\n\n880971923", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9171, "cpu_time_ms": 295, "memory_kb": 37344}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s741774390", "group_id": "codeNet:p03239", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"256MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun range-0-n (n &optional (step 1))\n (loop for i from 0 below n by step collect i))\n\n(defun range-1-n (n &optional (step 1))\n (loop for i from 1 below n by step collect i))\n\n(defun range-a-b (a b &optional (step 1))\n (loop for i from a below b by step collect i))\n\n(defun map-0-n (function n &optional (step 1))\n (mapcar function (range-0-n n step)))\n\n(defun map-1-n (function n &optional (step 1))\n (mapcar function (range-1-n n step)))\n\n(defun map-a-b (function a b &optional (step 1))\n (mapcar function (range-a-b a b step)))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (and result (is-empty char))\n do (return (concatenate 'string (nreverse result)))\n when (null (is-empty char))\n do (push char result))))\n\n(defun merge-sort (lst &optional (compare #'<))\n (let ((turn 0))\n (labels ((merge-list (a b a-length b-length)\n (cond ((zerop a-length) b)\n ((zerop b-length) a)\n ((funcall compare (car b) (car a))\n (incf turn a-length)\n (cons (car b)\n (merge-list a (cdr b) a-length (1- b-length))))\n (t\n (cons (car a)\n (merge-list (cdr a) b (1- a-length) b-length)))))\n (f (lst length)\n (if (= length 1)\n lst\n (let ((mid (ash length -1)))\n (merge-list (f (subseq lst 0 mid) mid)\n (f (subseq lst mid) (- length mid))\n mid\n (- length mid))))))\n (values (f lst (length lst)) turn))))\n\n(defun group (lst &optional (test #'eql) (key nil))\n (let ((table (make-hash-table :test test)))\n (mapc (lambda (x)\n (push x (gethash (if key (funcall key x) x) table)))\n lst)\n (loop for value being each hash-value in table\n collect value)))\n\n(defun nearby (&rest args)\n (let ((current (subseq args 0 (ash (length args) -1)))\n (validator (subseq args (ash (length args) -1)))\n (res nil))\n (labels ((check ()\n (every (lambda (x y) (and (<= 0 x) (< x y)))\n current validator))\n (f (lst)\n (unless lst (return-from f))\n (let ((x (car lst)))\n (setf (car lst) (1+ x))\n (when (check) (push (copy-list current) res))\n (setf (car lst) (1- x))\n (when (check) (push (copy-list current) res))\n (setf (car lst) x))\n (f (cdr lst))))\n (f current)\n res)))\n\n(defun main (limit line)\n (let ((validated (remove-if (lambda (x) (> (cdr x) limit)) line)))\n (if validated\n (reduce #'min validated :key #'car)\n \"TLE\")))\n\n(let ((n (read))\n (limit (read)))\n (princ (main limit (collect-times n (cons (read) (read))))))\n", "language": "Lisp", "metadata": {"date": 1589776005, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03239.html", "problem_id": "p03239", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03239/input.txt", "sample_output_relpath": "derived/input_output/data/p03239/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03239/Lisp/s741774390.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s741774390", "user_id": "u493610446"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"256MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun range-0-n (n &optional (step 1))\n (loop for i from 0 below n by step collect i))\n\n(defun range-1-n (n &optional (step 1))\n (loop for i from 1 below n by step collect i))\n\n(defun range-a-b (a b &optional (step 1))\n (loop for i from a below b by step collect i))\n\n(defun map-0-n (function n &optional (step 1))\n (mapcar function (range-0-n n step)))\n\n(defun map-1-n (function n &optional (step 1))\n (mapcar function (range-1-n n step)))\n\n(defun map-a-b (function a b &optional (step 1))\n (mapcar function (range-a-b a b step)))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (and result (is-empty char))\n do (return (concatenate 'string (nreverse result)))\n when (null (is-empty char))\n do (push char result))))\n\n(defun merge-sort (lst &optional (compare #'<))\n (let ((turn 0))\n (labels ((merge-list (a b a-length b-length)\n (cond ((zerop a-length) b)\n ((zerop b-length) a)\n ((funcall compare (car b) (car a))\n (incf turn a-length)\n (cons (car b)\n (merge-list a (cdr b) a-length (1- b-length))))\n (t\n (cons (car a)\n (merge-list (cdr a) b (1- a-length) b-length)))))\n (f (lst length)\n (if (= length 1)\n lst\n (let ((mid (ash length -1)))\n (merge-list (f (subseq lst 0 mid) mid)\n (f (subseq lst mid) (- length mid))\n mid\n (- length mid))))))\n (values (f lst (length lst)) turn))))\n\n(defun group (lst &optional (test #'eql) (key nil))\n (let ((table (make-hash-table :test test)))\n (mapc (lambda (x)\n (push x (gethash (if key (funcall key x) x) table)))\n lst)\n (loop for value being each hash-value in table\n collect value)))\n\n(defun nearby (&rest args)\n (let ((current (subseq args 0 (ash (length args) -1)))\n (validator (subseq args (ash (length args) -1)))\n (res nil))\n (labels ((check ()\n (every (lambda (x y) (and (<= 0 x) (< x y)))\n current validator))\n (f (lst)\n (unless lst (return-from f))\n (let ((x (car lst)))\n (setf (car lst) (1+ x))\n (when (check) (push (copy-list current) res))\n (setf (car lst) (1- x))\n (when (check) (push (copy-list current) res))\n (setf (car lst) x))\n (f (cdr lst))))\n (f current)\n res)))\n\n(defun main (limit line)\n (let ((validated (remove-if (lambda (x) (> (cdr x) limit)) line)))\n (if validated\n (reduce #'min validated :key #'car)\n \"TLE\")))\n\n(let ((n (read))\n (limit (read)))\n (princ (main limit (collect-times n (cons (read) (read))))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWhen Mr. X is away from home, he has decided to use his smartwatch to search the best route to go back home, to participate in ABC.\n\nYou, the smartwatch, has found N routes to his home.\n\nIf Mr. X uses the i-th of these routes, he will get home in time t_i at cost c_i.\n\nFind the smallest cost of a route that takes not longer than time T.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n1 \\leq T \\leq 1000\n\n1 \\leq c_i \\leq 1000\n\n1 \\leq t_i \\leq 1000\n\nThe pairs (c_i, t_i) are distinct.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN T\nc_1 t_1\nc_2 t_2\n:\nc_N t_N\n\nOutput\n\nPrint the smallest cost of a route that takes not longer than time T.\n\nIf there is no route that takes not longer than time T, print TLE instead.\n\nSample Input 1\n\n3 70\n7 60\n1 80\n4 50\n\nSample Output 1\n\n4\n\nThe first route gets him home at cost 7.\n\nThe second route takes longer than time T = 70.\n\nThe third route gets him home at cost 4.\n\nThus, the cost 4 of the third route is the minimum.\n\nSample Input 2\n\n4 3\n1 1000\n2 4\n3 1000\n4 500\n\nSample Output 2\n\nTLE\n\nThere is no route that takes not longer than time T = 3.\n\nSample Input 3\n\n5 9\n25 8\n5 9\n4 10\n1000 1000\n6 1\n\nSample Output 3\n\n5", "sample_input": "3 70\n7 60\n1 80\n4 50\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03239", "source_text": "Score : 200 points\n\nProblem Statement\n\nWhen Mr. X is away from home, he has decided to use his smartwatch to search the best route to go back home, to participate in ABC.\n\nYou, the smartwatch, has found N routes to his home.\n\nIf Mr. X uses the i-th of these routes, he will get home in time t_i at cost c_i.\n\nFind the smallest cost of a route that takes not longer than time T.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n1 \\leq T \\leq 1000\n\n1 \\leq c_i \\leq 1000\n\n1 \\leq t_i \\leq 1000\n\nThe pairs (c_i, t_i) are distinct.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN T\nc_1 t_1\nc_2 t_2\n:\nc_N t_N\n\nOutput\n\nPrint the smallest cost of a route that takes not longer than time T.\n\nIf there is no route that takes not longer than time T, print TLE instead.\n\nSample Input 1\n\n3 70\n7 60\n1 80\n4 50\n\nSample Output 1\n\n4\n\nThe first route gets him home at cost 7.\n\nThe second route takes longer than time T = 70.\n\nThe third route gets him home at cost 4.\n\nThus, the cost 4 of the third route is the minimum.\n\nSample Input 2\n\n4 3\n1 1000\n2 4\n3 1000\n4 500\n\nSample Output 2\n\nTLE\n\nThere is no route that takes not longer than time T = 3.\n\nSample Input 3\n\n5 9\n25 8\n5 9\n4 10\n1000 1000\n6 1\n\nSample Output 3\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5779, "cpu_time_ms": 266, "memory_kb": 30520}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s956983945", "group_id": "codeNet:p03239", "input_text": "(defun solve (n ans tmax)\n (cond\n ((< n 1)\n (if (> ans 1000) 'tle ans))\n (t\n (let ((cost (read)) (time (read)))\n\t (if (and\n\t (<= time tmax)\n\t (< cost ans))\n\t (solve (- n 1) cost tmax)\n\t (solve (- n 1) ans tmax))))))\n(print (solve (read) 1000000000 (read)))", "language": "Lisp", "metadata": {"date": 1573585370, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03239.html", "problem_id": "p03239", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03239/input.txt", "sample_output_relpath": "derived/input_output/data/p03239/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03239/Lisp/s956983945.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s956983945", "user_id": "u691380397"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun solve (n ans tmax)\n (cond\n ((< n 1)\n (if (> ans 1000) 'tle ans))\n (t\n (let ((cost (read)) (time (read)))\n\t (if (and\n\t (<= time tmax)\n\t (< cost ans))\n\t (solve (- n 1) cost tmax)\n\t (solve (- n 1) ans tmax))))))\n(print (solve (read) 1000000000 (read)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWhen Mr. X is away from home, he has decided to use his smartwatch to search the best route to go back home, to participate in ABC.\n\nYou, the smartwatch, has found N routes to his home.\n\nIf Mr. X uses the i-th of these routes, he will get home in time t_i at cost c_i.\n\nFind the smallest cost of a route that takes not longer than time T.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n1 \\leq T \\leq 1000\n\n1 \\leq c_i \\leq 1000\n\n1 \\leq t_i \\leq 1000\n\nThe pairs (c_i, t_i) are distinct.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN T\nc_1 t_1\nc_2 t_2\n:\nc_N t_N\n\nOutput\n\nPrint the smallest cost of a route that takes not longer than time T.\n\nIf there is no route that takes not longer than time T, print TLE instead.\n\nSample Input 1\n\n3 70\n7 60\n1 80\n4 50\n\nSample Output 1\n\n4\n\nThe first route gets him home at cost 7.\n\nThe second route takes longer than time T = 70.\n\nThe third route gets him home at cost 4.\n\nThus, the cost 4 of the third route is the minimum.\n\nSample Input 2\n\n4 3\n1 1000\n2 4\n3 1000\n4 500\n\nSample Output 2\n\nTLE\n\nThere is no route that takes not longer than time T = 3.\n\nSample Input 3\n\n5 9\n25 8\n5 9\n4 10\n1000 1000\n6 1\n\nSample Output 3\n\n5", "sample_input": "3 70\n7 60\n1 80\n4 50\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03239", "source_text": "Score : 200 points\n\nProblem Statement\n\nWhen Mr. X is away from home, he has decided to use his smartwatch to search the best route to go back home, to participate in ABC.\n\nYou, the smartwatch, has found N routes to his home.\n\nIf Mr. X uses the i-th of these routes, he will get home in time t_i at cost c_i.\n\nFind the smallest cost of a route that takes not longer than time T.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n1 \\leq T \\leq 1000\n\n1 \\leq c_i \\leq 1000\n\n1 \\leq t_i \\leq 1000\n\nThe pairs (c_i, t_i) are distinct.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN T\nc_1 t_1\nc_2 t_2\n:\nc_N t_N\n\nOutput\n\nPrint the smallest cost of a route that takes not longer than time T.\n\nIf there is no route that takes not longer than time T, print TLE instead.\n\nSample Input 1\n\n3 70\n7 60\n1 80\n4 50\n\nSample Output 1\n\n4\n\nThe first route gets him home at cost 7.\n\nThe second route takes longer than time T = 70.\n\nThe third route gets him home at cost 4.\n\nThus, the cost 4 of the third route is the minimum.\n\nSample Input 2\n\n4 3\n1 1000\n2 4\n3 1000\n4 500\n\nSample Output 2\n\nTLE\n\nThere is no route that takes not longer than time T = 3.\n\nSample Input 3\n\n5 9\n25 8\n5 9\n4 10\n1000 1000\n6 1\n\nSample Output 3\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 289, "cpu_time_ms": 123, "memory_kb": 11492}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s261165250", "group_id": "codeNet:p03239", "input_text": "(defun main ()\n (let ((N (read))\n (Time (read))\n (lst (list nil)))\n (dotimes (x N)\n (let ((a (read))\n (b (read)))\n (when (<= b Time)\n (push a lst))))\n (setq lst (sort (cdr (reverse lst)) #'<))\n (let ((ans (nth 0 lst)))\n (if (null ans)\n (princ \"TLE\")\n (princ ans)))))\n\n(main)", "language": "Lisp", "metadata": {"date": 1538921198, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03239.html", "problem_id": "p03239", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03239/input.txt", "sample_output_relpath": "derived/input_output/data/p03239/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03239/Lisp/s261165250.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s261165250", "user_id": "u631655863"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun main ()\n (let ((N (read))\n (Time (read))\n (lst (list nil)))\n (dotimes (x N)\n (let ((a (read))\n (b (read)))\n (when (<= b Time)\n (push a lst))))\n (setq lst (sort (cdr (reverse lst)) #'<))\n (let ((ans (nth 0 lst)))\n (if (null ans)\n (princ \"TLE\")\n (princ ans)))))\n\n(main)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWhen Mr. X is away from home, he has decided to use his smartwatch to search the best route to go back home, to participate in ABC.\n\nYou, the smartwatch, has found N routes to his home.\n\nIf Mr. X uses the i-th of these routes, he will get home in time t_i at cost c_i.\n\nFind the smallest cost of a route that takes not longer than time T.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n1 \\leq T \\leq 1000\n\n1 \\leq c_i \\leq 1000\n\n1 \\leq t_i \\leq 1000\n\nThe pairs (c_i, t_i) are distinct.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN T\nc_1 t_1\nc_2 t_2\n:\nc_N t_N\n\nOutput\n\nPrint the smallest cost of a route that takes not longer than time T.\n\nIf there is no route that takes not longer than time T, print TLE instead.\n\nSample Input 1\n\n3 70\n7 60\n1 80\n4 50\n\nSample Output 1\n\n4\n\nThe first route gets him home at cost 7.\n\nThe second route takes longer than time T = 70.\n\nThe third route gets him home at cost 4.\n\nThus, the cost 4 of the third route is the minimum.\n\nSample Input 2\n\n4 3\n1 1000\n2 4\n3 1000\n4 500\n\nSample Output 2\n\nTLE\n\nThere is no route that takes not longer than time T = 3.\n\nSample Input 3\n\n5 9\n25 8\n5 9\n4 10\n1000 1000\n6 1\n\nSample Output 3\n\n5", "sample_input": "3 70\n7 60\n1 80\n4 50\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03239", "source_text": "Score : 200 points\n\nProblem Statement\n\nWhen Mr. X is away from home, he has decided to use his smartwatch to search the best route to go back home, to participate in ABC.\n\nYou, the smartwatch, has found N routes to his home.\n\nIf Mr. X uses the i-th of these routes, he will get home in time t_i at cost c_i.\n\nFind the smallest cost of a route that takes not longer than time T.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n1 \\leq T \\leq 1000\n\n1 \\leq c_i \\leq 1000\n\n1 \\leq t_i \\leq 1000\n\nThe pairs (c_i, t_i) are distinct.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN T\nc_1 t_1\nc_2 t_2\n:\nc_N t_N\n\nOutput\n\nPrint the smallest cost of a route that takes not longer than time T.\n\nIf there is no route that takes not longer than time T, print TLE instead.\n\nSample Input 1\n\n3 70\n7 60\n1 80\n4 50\n\nSample Output 1\n\n4\n\nThe first route gets him home at cost 7.\n\nThe second route takes longer than time T = 70.\n\nThe third route gets him home at cost 4.\n\nThus, the cost 4 of the third route is the minimum.\n\nSample Input 2\n\n4 3\n1 1000\n2 4\n3 1000\n4 500\n\nSample Output 2\n\nTLE\n\nThere is no route that takes not longer than time T = 3.\n\nSample Input 3\n\n5 9\n25 8\n5 9\n4 10\n1000 1000\n6 1\n\nSample Output 3\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 353, "cpu_time_ms": 127, "memory_kb": 12132}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s479579482", "group_id": "codeNet:p03239", "input_text": "(defparameter *n* (read))\n(defparameter *t* (read))\n(defparameter *c-t* (loop repeat *n*\n collect (cons (read) (read))))\n\n(defun f (c-t tt)\n (let ((alst (mapcar #'car \n (remove-if-not (lambda (pair) (>= tt (cdr pair)))\n c-t))))\n (if alst\n (reduce #'min alst)\n \"TLE\")))\n\n(princ (f *c-t* *t*))", "language": "Lisp", "metadata": {"date": 1538875461, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03239.html", "problem_id": "p03239", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03239/input.txt", "sample_output_relpath": "derived/input_output/data/p03239/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03239/Lisp/s479579482.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s479579482", "user_id": "u956039157"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defparameter *n* (read))\n(defparameter *t* (read))\n(defparameter *c-t* (loop repeat *n*\n collect (cons (read) (read))))\n\n(defun f (c-t tt)\n (let ((alst (mapcar #'car \n (remove-if-not (lambda (pair) (>= tt (cdr pair)))\n c-t))))\n (if alst\n (reduce #'min alst)\n \"TLE\")))\n\n(princ (f *c-t* *t*))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWhen Mr. X is away from home, he has decided to use his smartwatch to search the best route to go back home, to participate in ABC.\n\nYou, the smartwatch, has found N routes to his home.\n\nIf Mr. X uses the i-th of these routes, he will get home in time t_i at cost c_i.\n\nFind the smallest cost of a route that takes not longer than time T.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n1 \\leq T \\leq 1000\n\n1 \\leq c_i \\leq 1000\n\n1 \\leq t_i \\leq 1000\n\nThe pairs (c_i, t_i) are distinct.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN T\nc_1 t_1\nc_2 t_2\n:\nc_N t_N\n\nOutput\n\nPrint the smallest cost of a route that takes not longer than time T.\n\nIf there is no route that takes not longer than time T, print TLE instead.\n\nSample Input 1\n\n3 70\n7 60\n1 80\n4 50\n\nSample Output 1\n\n4\n\nThe first route gets him home at cost 7.\n\nThe second route takes longer than time T = 70.\n\nThe third route gets him home at cost 4.\n\nThus, the cost 4 of the third route is the minimum.\n\nSample Input 2\n\n4 3\n1 1000\n2 4\n3 1000\n4 500\n\nSample Output 2\n\nTLE\n\nThere is no route that takes not longer than time T = 3.\n\nSample Input 3\n\n5 9\n25 8\n5 9\n4 10\n1000 1000\n6 1\n\nSample Output 3\n\n5", "sample_input": "3 70\n7 60\n1 80\n4 50\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03239", "source_text": "Score : 200 points\n\nProblem Statement\n\nWhen Mr. X is away from home, he has decided to use his smartwatch to search the best route to go back home, to participate in ABC.\n\nYou, the smartwatch, has found N routes to his home.\n\nIf Mr. X uses the i-th of these routes, he will get home in time t_i at cost c_i.\n\nFind the smallest cost of a route that takes not longer than time T.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n1 \\leq T \\leq 1000\n\n1 \\leq c_i \\leq 1000\n\n1 \\leq t_i \\leq 1000\n\nThe pairs (c_i, t_i) are distinct.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN T\nc_1 t_1\nc_2 t_2\n:\nc_N t_N\n\nOutput\n\nPrint the smallest cost of a route that takes not longer than time T.\n\nIf there is no route that takes not longer than time T, print TLE instead.\n\nSample Input 1\n\n3 70\n7 60\n1 80\n4 50\n\nSample Output 1\n\n4\n\nThe first route gets him home at cost 7.\n\nThe second route takes longer than time T = 70.\n\nThe third route gets him home at cost 4.\n\nThus, the cost 4 of the third route is the minimum.\n\nSample Input 2\n\n4 3\n1 1000\n2 4\n3 1000\n4 500\n\nSample Output 2\n\nTLE\n\nThere is no route that takes not longer than time T = 3.\n\nSample Input 3\n\n5 9\n25 8\n5 9\n4 10\n1000 1000\n6 1\n\nSample Output 3\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 391, "cpu_time_ms": 138, "memory_kb": 13796}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s125674929", "group_id": "codeNet:p03242", "input_text": "(defun f (x)\n (cond\n ((equal x #\\1) (prin1 9))\n ((equal x #\\9) (prin1 1))\n (t (prin1 x))))\n\n(loop for i across (read-line)\n collect (f i))", "language": "Lisp", "metadata": {"date": 1573534106, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03242.html", "problem_id": "p03242", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03242/input.txt", "sample_output_relpath": "derived/input_output/data/p03242/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03242/Lisp/s125674929.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s125674929", "user_id": "u691380397"}, "prompt_components": {"gold_output": "991\n", "input_to_evaluate": "(defun f (x)\n (cond\n ((equal x #\\1) (prin1 9))\n ((equal x #\\9) (prin1 1))\n (t (prin1 x))))\n\n(loop for i across (read-line)\n collect (f i))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nCat Snuke is learning to write characters.\nToday, he practiced writing digits 1 and 9, but he did it the other way around.\n\nYou are given a three-digit integer n written by Snuke.\nPrint the integer obtained by replacing each digit 1 with 9 and each digit 9 with 1 in n.\n\nConstraints\n\n111 \\leq n \\leq 999\n\nn is an integer consisting of digits 1 and 9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\n\nOutput\n\nPrint the integer obtained by replacing each occurrence of 1 with 9 and each occurrence of 9 with 1 in n.\n\nSample Input 1\n\n119\n\nSample Output 1\n\n991\n\nReplace the 9 in the ones place with 1, the 1 in the tens place with 9 and the 1 in the hundreds place with 9. The answer is 991.\n\nSample Input 2\n\n999\n\nSample Output 2\n\n111", "sample_input": "119\n"}, "reference_outputs": ["991\n"], "source_document_id": "p03242", "source_text": "Score : 100 points\n\nProblem Statement\n\nCat Snuke is learning to write characters.\nToday, he practiced writing digits 1 and 9, but he did it the other way around.\n\nYou are given a three-digit integer n written by Snuke.\nPrint the integer obtained by replacing each digit 1 with 9 and each digit 9 with 1 in n.\n\nConstraints\n\n111 \\leq n \\leq 999\n\nn is an integer consisting of digits 1 and 9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\n\nOutput\n\nPrint the integer obtained by replacing each occurrence of 1 with 9 and each occurrence of 9 with 1 in n.\n\nSample Input 1\n\n119\n\nSample Output 1\n\n991\n\nReplace the 9 in the ones place with 1, the 1 in the tens place with 9 and the 1 in the hundreds place with 9. The answer is 991.\n\nSample Input 2\n\n999\n\nSample Output 2\n\n111", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 152, "cpu_time_ms": 133, "memory_kb": 12772}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s689658970", "group_id": "codeNet:p03242", "input_text": "(princ(- 1110(read)))", "language": "Lisp", "metadata": {"date": 1538281813, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03242.html", "problem_id": "p03242", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03242/input.txt", "sample_output_relpath": "derived/input_output/data/p03242/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03242/Lisp/s689658970.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s689658970", "user_id": "u657913472"}, "prompt_components": {"gold_output": "991\n", "input_to_evaluate": "(princ(- 1110(read)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nCat Snuke is learning to write characters.\nToday, he practiced writing digits 1 and 9, but he did it the other way around.\n\nYou are given a three-digit integer n written by Snuke.\nPrint the integer obtained by replacing each digit 1 with 9 and each digit 9 with 1 in n.\n\nConstraints\n\n111 \\leq n \\leq 999\n\nn is an integer consisting of digits 1 and 9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\n\nOutput\n\nPrint the integer obtained by replacing each occurrence of 1 with 9 and each occurrence of 9 with 1 in n.\n\nSample Input 1\n\n119\n\nSample Output 1\n\n991\n\nReplace the 9 in the ones place with 1, the 1 in the tens place with 9 and the 1 in the hundreds place with 9. The answer is 991.\n\nSample Input 2\n\n999\n\nSample Output 2\n\n111", "sample_input": "119\n"}, "reference_outputs": ["991\n"], "source_document_id": "p03242", "source_text": "Score : 100 points\n\nProblem Statement\n\nCat Snuke is learning to write characters.\nToday, he practiced writing digits 1 and 9, but he did it the other way around.\n\nYou are given a three-digit integer n written by Snuke.\nPrint the integer obtained by replacing each digit 1 with 9 and each digit 9 with 1 in n.\n\nConstraints\n\n111 \\leq n \\leq 999\n\nn is an integer consisting of digits 1 and 9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\n\nOutput\n\nPrint the integer obtained by replacing each occurrence of 1 with 9 and each occurrence of 9 with 1 in n.\n\nSample Input 1\n\n119\n\nSample Output 1\n\n991\n\nReplace the 9 in the ones place with 1, the 1 in the tens place with 9 and the 1 in the hundreds place with 9. The answer is 991.\n\nSample Input 2\n\n999\n\nSample Output 2\n\n111", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 21, "cpu_time_ms": 20, "memory_kb": 3812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s201179540", "group_id": "codeNet:p03242", "input_text": "(let ((s (read-line)))\n (loop for i across s do\n (format t \"~A\" (if (equal i #\\9) 1 9)))\n (format t \"~%\"))", "language": "Lisp", "metadata": {"date": 1538276635, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03242.html", "problem_id": "p03242", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03242/input.txt", "sample_output_relpath": "derived/input_output/data/p03242/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03242/Lisp/s201179540.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s201179540", "user_id": "u994767958"}, "prompt_components": {"gold_output": "991\n", "input_to_evaluate": "(let ((s (read-line)))\n (loop for i across s do\n (format t \"~A\" (if (equal i #\\9) 1 9)))\n (format t \"~%\"))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nCat Snuke is learning to write characters.\nToday, he practiced writing digits 1 and 9, but he did it the other way around.\n\nYou are given a three-digit integer n written by Snuke.\nPrint the integer obtained by replacing each digit 1 with 9 and each digit 9 with 1 in n.\n\nConstraints\n\n111 \\leq n \\leq 999\n\nn is an integer consisting of digits 1 and 9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\n\nOutput\n\nPrint the integer obtained by replacing each occurrence of 1 with 9 and each occurrence of 9 with 1 in n.\n\nSample Input 1\n\n119\n\nSample Output 1\n\n991\n\nReplace the 9 in the ones place with 1, the 1 in the tens place with 9 and the 1 in the hundreds place with 9. The answer is 991.\n\nSample Input 2\n\n999\n\nSample Output 2\n\n111", "sample_input": "119\n"}, "reference_outputs": ["991\n"], "source_document_id": "p03242", "source_text": "Score : 100 points\n\nProblem Statement\n\nCat Snuke is learning to write characters.\nToday, he practiced writing digits 1 and 9, but he did it the other way around.\n\nYou are given a three-digit integer n written by Snuke.\nPrint the integer obtained by replacing each digit 1 with 9 and each digit 9 with 1 in n.\n\nConstraints\n\n111 \\leq n \\leq 999\n\nn is an integer consisting of digits 1 and 9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\n\nOutput\n\nPrint the integer obtained by replacing each occurrence of 1 with 9 and each occurrence of 9 with 1 in n.\n\nSample Input 1\n\n119\n\nSample Output 1\n\n991\n\nReplace the 9 in the ones place with 1, the 1 in the tens place with 9 and the 1 in the hundreds place with 9. The answer is 991.\n\nSample Input 2\n\n999\n\nSample Output 2\n\n111", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 111, "cpu_time_ms": 133, "memory_kb": 12516}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s759440893", "group_id": "codeNet:p03243", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"256MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun range-0-n (n &optional (step 1))\n (loop for i from 0 below n by step collect i))\n\n(defun range-1-n (n &optional (step 1))\n (loop for i from 1 below n by step collect i))\n\n(defun range-a-b (a b &optional (step 1))\n (loop for i from a below b by step collect i))\n\n(defun map-0-n (function n &optional (step 1))\n (mapcar function (range-0-n n step)))\n\n(defun map-1-n (function n &optional (step 1))\n (mapcar function (range-1-n n step)))\n\n(defun map-a-b (function a b &optional (step 1))\n (mapcar function (range-a-b a b step)))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (and result (is-empty char))\n do (return (concatenate 'string (nreverse result)))\n when (null (is-empty char))\n do (push char result))))\n\n(defun merge-sort (lst &optional (compare #'<))\n (let ((turn 0))\n (labels ((merge-list (a b a-length b-length)\n (cond ((zerop a-length) b)\n ((zerop b-length) a)\n ((funcall compare (car b) (car a))\n (incf turn a-length)\n (cons (car b)\n (merge-list a (cdr b) a-length (1- b-length))))\n (t\n (cons (car a)\n (merge-list (cdr a) b (1- a-length) b-length)))))\n (f (lst length)\n (if (= length 1)\n lst\n (let ((mid (ash length -1)))\n (merge-list (f (subseq lst 0 mid) mid)\n (f (subseq lst mid) (- length mid))\n mid\n (- length mid))))))\n (values (f lst (length lst)) turn))))\n\n(defun group (lst &optional (test #'eql) (key nil))\n (let ((table (make-hash-table :test test)))\n (mapc (lambda (x)\n (push x (gethash (if key (funcall key x) x) table)))\n lst)\n (loop for value being each hash-value in table\n collect value)))\n\n(defun nearby (&rest args)\n (let ((current (subseq args 0 (ash (length args) -1)))\n (validator (subseq args (ash (length args) -1)))\n (res nil))\n (labels ((check ()\n (every (lambda (x y) (and (<= 0 x) (< x y)))\n current validator))\n (f (lst)\n (unless lst (return-from f))\n (let ((x (car lst)))\n (setf (car lst) (1+ x))\n (when (check) (push (copy-list current) res))\n (setf (car lst) (1- x))\n (when (check) (push (copy-list current) res))\n (setf (car lst) x))\n (f (cdr lst))))\n (f current)\n res)))\n\n(defun main (n &optional (x 111))\n (if (<= n x)\n x\n (main n (+ x 111))))\n\n(princ (main (read)))\n", "language": "Lisp", "metadata": {"date": 1589776178, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03243.html", "problem_id": "p03243", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03243/input.txt", "sample_output_relpath": "derived/input_output/data/p03243/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03243/Lisp/s759440893.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s759440893", "user_id": "u493610446"}, "prompt_components": {"gold_output": "111\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"256MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun range-0-n (n &optional (step 1))\n (loop for i from 0 below n by step collect i))\n\n(defun range-1-n (n &optional (step 1))\n (loop for i from 1 below n by step collect i))\n\n(defun range-a-b (a b &optional (step 1))\n (loop for i from a below b by step collect i))\n\n(defun map-0-n (function n &optional (step 1))\n (mapcar function (range-0-n n step)))\n\n(defun map-1-n (function n &optional (step 1))\n (mapcar function (range-1-n n step)))\n\n(defun map-a-b (function a b &optional (step 1))\n (mapcar function (range-a-b a b step)))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (and result (is-empty char))\n do (return (concatenate 'string (nreverse result)))\n when (null (is-empty char))\n do (push char result))))\n\n(defun merge-sort (lst &optional (compare #'<))\n (let ((turn 0))\n (labels ((merge-list (a b a-length b-length)\n (cond ((zerop a-length) b)\n ((zerop b-length) a)\n ((funcall compare (car b) (car a))\n (incf turn a-length)\n (cons (car b)\n (merge-list a (cdr b) a-length (1- b-length))))\n (t\n (cons (car a)\n (merge-list (cdr a) b (1- a-length) b-length)))))\n (f (lst length)\n (if (= length 1)\n lst\n (let ((mid (ash length -1)))\n (merge-list (f (subseq lst 0 mid) mid)\n (f (subseq lst mid) (- length mid))\n mid\n (- length mid))))))\n (values (f lst (length lst)) turn))))\n\n(defun group (lst &optional (test #'eql) (key nil))\n (let ((table (make-hash-table :test test)))\n (mapc (lambda (x)\n (push x (gethash (if key (funcall key x) x) table)))\n lst)\n (loop for value being each hash-value in table\n collect value)))\n\n(defun nearby (&rest args)\n (let ((current (subseq args 0 (ash (length args) -1)))\n (validator (subseq args (ash (length args) -1)))\n (res nil))\n (labels ((check ()\n (every (lambda (x y) (and (<= 0 x) (< x y)))\n current validator))\n (f (lst)\n (unless lst (return-from f))\n (let ((x (car lst)))\n (setf (car lst) (1+ x))\n (when (check) (push (copy-list current) res))\n (setf (car lst) (1- x))\n (when (check) (push (copy-list current) res))\n (setf (car lst) x))\n (f (cdr lst))))\n (f current)\n res)))\n\n(defun main (n &optional (x 111))\n (if (<= n x)\n x\n (main n (+ x 111))))\n\n(princ (main (read)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nKurohashi has never participated in AtCoder Beginner Contest (ABC).\n\nThe next ABC to be held is ABC N (the N-th ABC ever held).\nKurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same.\n\nWhat is the earliest ABC where Kurohashi can make his debut?\n\nConstraints\n\n100 \\leq N \\leq 999\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf the earliest ABC where Kurohashi can make his debut is ABC n, print n.\n\nSample Input 1\n\n111\n\nSample Output 1\n\n111\n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\nSample Input 2\n\n112\n\nSample Output 2\n\n222\n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer participate in ABC 111.\nAmong the ABCs where Kurohashi can make his debut, the earliest one is ABC 222.\n\nSample Input 3\n\n750\n\nSample Output 3\n\n777", "sample_input": "111\n"}, "reference_outputs": ["111\n"], "source_document_id": "p03243", "source_text": "Score : 200 points\n\nProblem Statement\n\nKurohashi has never participated in AtCoder Beginner Contest (ABC).\n\nThe next ABC to be held is ABC N (the N-th ABC ever held).\nKurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same.\n\nWhat is the earliest ABC where Kurohashi can make his debut?\n\nConstraints\n\n100 \\leq N \\leq 999\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf the earliest ABC where Kurohashi can make his debut is ABC n, print n.\n\nSample Input 1\n\n111\n\nSample Output 1\n\n111\n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\nSample Input 2\n\n112\n\nSample Output 2\n\n222\n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer participate in ABC 111.\nAmong the ABCs where Kurohashi can make his debut, the earliest one is ABC 222.\n\nSample Input 3\n\n750\n\nSample Output 3\n\n777", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5610, "cpu_time_ms": 231, "memory_kb": 30516}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s892547990", "group_id": "codeNet:p03243", "input_text": "(princ(*(ceiling(read)111)111))", "language": "Lisp", "metadata": {"date": 1538276353, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03243.html", "problem_id": "p03243", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03243/input.txt", "sample_output_relpath": "derived/input_output/data/p03243/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03243/Lisp/s892547990.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s892547990", "user_id": "u657913472"}, "prompt_components": {"gold_output": "111\n", "input_to_evaluate": "(princ(*(ceiling(read)111)111))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nKurohashi has never participated in AtCoder Beginner Contest (ABC).\n\nThe next ABC to be held is ABC N (the N-th ABC ever held).\nKurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same.\n\nWhat is the earliest ABC where Kurohashi can make his debut?\n\nConstraints\n\n100 \\leq N \\leq 999\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf the earliest ABC where Kurohashi can make his debut is ABC n, print n.\n\nSample Input 1\n\n111\n\nSample Output 1\n\n111\n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\nSample Input 2\n\n112\n\nSample Output 2\n\n222\n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer participate in ABC 111.\nAmong the ABCs where Kurohashi can make his debut, the earliest one is ABC 222.\n\nSample Input 3\n\n750\n\nSample Output 3\n\n777", "sample_input": "111\n"}, "reference_outputs": ["111\n"], "source_document_id": "p03243", "source_text": "Score : 200 points\n\nProblem Statement\n\nKurohashi has never participated in AtCoder Beginner Contest (ABC).\n\nThe next ABC to be held is ABC N (the N-th ABC ever held).\nKurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same.\n\nWhat is the earliest ABC where Kurohashi can make his debut?\n\nConstraints\n\n100 \\leq N \\leq 999\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf the earliest ABC where Kurohashi can make his debut is ABC n, print n.\n\nSample Input 1\n\n111\n\nSample Output 1\n\n111\n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\nSample Input 2\n\n112\n\nSample Output 2\n\n222\n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer participate in ABC 111.\nAmong the ABCs where Kurohashi can make his debut, the earliest one is ABC 222.\n\nSample Input 3\n\n750\n\nSample Output 3\n\n777", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 31, "cpu_time_ms": 20, "memory_kb": 3808}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s407688703", "group_id": "codeNet:p03243", "input_text": "(defun a (n m)\n (if (< n (+ (* 100 m) (* 10 m) m))\n (+ (* 100 m) (* 10 m) m) (a n (1+ m))))\n(princ (a (read) 1))\n", "language": "Lisp", "metadata": {"date": 1538270965, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03243.html", "problem_id": "p03243", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03243/input.txt", "sample_output_relpath": "derived/input_output/data/p03243/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03243/Lisp/s407688703.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s407688703", "user_id": "u610490393"}, "prompt_components": {"gold_output": "111\n", "input_to_evaluate": "(defun a (n m)\n (if (< n (+ (* 100 m) (* 10 m) m))\n (+ (* 100 m) (* 10 m) m) (a n (1+ m))))\n(princ (a (read) 1))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nKurohashi has never participated in AtCoder Beginner Contest (ABC).\n\nThe next ABC to be held is ABC N (the N-th ABC ever held).\nKurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same.\n\nWhat is the earliest ABC where Kurohashi can make his debut?\n\nConstraints\n\n100 \\leq N \\leq 999\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf the earliest ABC where Kurohashi can make his debut is ABC n, print n.\n\nSample Input 1\n\n111\n\nSample Output 1\n\n111\n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\nSample Input 2\n\n112\n\nSample Output 2\n\n222\n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer participate in ABC 111.\nAmong the ABCs where Kurohashi can make his debut, the earliest one is ABC 222.\n\nSample Input 3\n\n750\n\nSample Output 3\n\n777", "sample_input": "111\n"}, "reference_outputs": ["111\n"], "source_document_id": "p03243", "source_text": "Score : 200 points\n\nProblem Statement\n\nKurohashi has never participated in AtCoder Beginner Contest (ABC).\n\nThe next ABC to be held is ABC N (the N-th ABC ever held).\nKurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same.\n\nWhat is the earliest ABC where Kurohashi can make his debut?\n\nConstraints\n\n100 \\leq N \\leq 999\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf the earliest ABC where Kurohashi can make his debut is ABC n, print n.\n\nSample Input 1\n\n111\n\nSample Output 1\n\n111\n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\nSample Input 2\n\n112\n\nSample Output 2\n\n222\n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer participate in ABC 111.\nAmong the ABCs where Kurohashi can make his debut, the earliest one is ABC 222.\n\nSample Input 3\n\n750\n\nSample Output 3\n\n777", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 119, "cpu_time_ms": 27, "memory_kb": 4712}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s039196168", "group_id": "codeNet:p03252", "input_text": "(defparameter *s* (coerce (read-line) 'list))\n(defparameter *t* (coerce (read-line) 'list))\n\n(defparameter *alphabet* (coerce \"abcdefghijklmnopqrstuvwxyz\" 'list))\n\n(defun f (str)\n (mapcar (lambda (x) (count x str)) *alphabet*))\n\n(defun g (str1 str2)\n (if (equal (sort (remove 0 (f str1)) #'<)\n (sort (remove 0 (f str2)) #'<))\n \"Yes\"\n \"No\"))\n\n(princ (g *s* *t*))", "language": "Lisp", "metadata": {"date": 1537947852, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03252.html", "problem_id": "p03252", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03252/input.txt", "sample_output_relpath": "derived/input_output/data/p03252/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03252/Lisp/s039196168.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s039196168", "user_id": "u956039157"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defparameter *s* (coerce (read-line) 'list))\n(defparameter *t* (coerce (read-line) 'list))\n\n(defparameter *alphabet* (coerce \"abcdefghijklmnopqrstuvwxyz\" 'list))\n\n(defun f (str)\n (mapcar (lambda (x) (count x str)) *alphabet*))\n\n(defun g (str1 str2)\n (if (equal (sort (remove 0 (f str1)) #'<)\n (sort (remove 0 (f str2)) #'<))\n \"Yes\"\n \"No\"))\n\n(princ (g *s* *t*))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given strings S and T consisting of lowercase English letters.\n\nYou can perform the following operation on S any number of times:\n\nOperation: Choose two distinct lowercase English letters c_1 and c_2, then replace every occurrence of c_1 with c_2, and every occurrence of c_2 with c_1.\n\nDetermine if S and T can be made equal by performing the operation zero or more times.\n\nConstraints\n\n1 \\leq |S| \\leq 2 \\times 10^5\n\n|S| = |T|\n\nS and T consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nIf S and T can be made equal, print Yes; otherwise, print No.\n\nSample Input 1\n\nazzel\napple\n\nSample Output 1\n\nYes\n\nazzel can be changed to apple, as follows:\n\nChoose e as c_1 and l as c_2. azzel becomes azzle.\n\nChoose z as c_1 and p as c_2. azzle becomes apple.\n\nSample Input 2\n\nchokudai\nredcoder\n\nSample Output 2\n\nNo\n\nNo sequences of operation can change chokudai to redcoder.\n\nSample Input 3\n\nabcdefghijklmnopqrstuvwxyz\nibyhqfrekavclxjstdwgpzmonu\n\nSample Output 3\n\nYes", "sample_input": "azzel\napple\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03252", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given strings S and T consisting of lowercase English letters.\n\nYou can perform the following operation on S any number of times:\n\nOperation: Choose two distinct lowercase English letters c_1 and c_2, then replace every occurrence of c_1 with c_2, and every occurrence of c_2 with c_1.\n\nDetermine if S and T can be made equal by performing the operation zero or more times.\n\nConstraints\n\n1 \\leq |S| \\leq 2 \\times 10^5\n\n|S| = |T|\n\nS and T consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nIf S and T can be made equal, print Yes; otherwise, print No.\n\nSample Input 1\n\nazzel\napple\n\nSample Output 1\n\nYes\n\nazzel can be changed to apple, as follows:\n\nChoose e as c_1 and l as c_2. azzel becomes azzle.\n\nChoose z as c_1 and p as c_2. azzle becomes apple.\n\nSample Input 2\n\nchokudai\nredcoder\n\nSample Output 2\n\nNo\n\nNo sequences of operation can change chokudai to redcoder.\n\nSample Input 3\n\nabcdefghijklmnopqrstuvwxyz\nibyhqfrekavclxjstdwgpzmonu\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 385, "cpu_time_ms": 195, "memory_kb": 16612}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s580333777", "group_id": "codeNet:p03253", "input_text": ";; -*- coding: utf-8 -*-\n#-(or child-sbcl swank)\n(quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n '(\"--control-stack-size\" \"32MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" #.(namestring *load-pathname*))\n :output t :error t :input t)))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(declaim (ftype (function * (values simple-bit-vector &optional)) make-prime-table))\n(defun make-prime-table (size)\n \"Erzeugt die Primzahlentabelle 0 zu SIZE-1.\"\n (declare (optimize (speed 3) (safety 1)))\n (let ((dict (make-array size :element-type 'bit :initial-element 1)))\n (setf (sbit dict 0) 0 (sbit dict 1) 0)\n (loop for even-num from 4 below size by 2\n do (setf (sbit dict even-num) 0))\n (loop for p from 3 to (ceiling (sqrt size)) by 2\n when (= 1 (sbit dict p))\n do (loop for composite from (+ p p) below size by p\n until (>= composite size)\n do (setf (sbit dict composite) 0)))\n dict))\n\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array '(10 10 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions (when (eql cache-type :array) (second cache-attribs)))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ,dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@args)\n (,name-alias ,@args))\n ,value))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name)))))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n(defconstant +magic+ #.(+ 7 (expt 10 9)))\n(defun decompose (m)\n (declare #.OPT\n (uint32 m))\n (let* ((factor-sup (ceiling (sqrt m)))\n (prime-table (make-prime-table (1+ factor-sup))))\n (loop for i from 2 below (length prime-table)\n when (= 1 (sbit prime-table i))\n collect (nlet recurse ((count 0))\n (declare (uint32 count))\n (multiple-value-bind (quot rem) (floor m i)\n (if (zerop rem)\n (progn (setf m quot)\n (recurse (1+ count)))\n count)))\n into factors\n finally (return\n (let ((factors (delete 0 (the list factors))))\n (if (= 1 m)\n factors\n (append factors (list 1))))))))\n\n(with-memoizing (:array '(100001 32) :element-type 'fixnum :initial-element -1)\n (defun multiset-coefficient (n k)\n (declare #.OPT\n ((integer 1 #.most-positive-fixnum) n)\n ((integer 0 #.most-positive-fixnum) k))\n (cond ((zerop k) 1)\n ((= n 1) 1)\n (t (mod (the uint63 (+ (multiset-coefficient (- n 1) k)\n (multiset-coefficient n (- k 1))))\n +magic+)))))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (factors (decompose m)))\n (if (= m 1)\n (println 1)\n (println\n (reduce (lambda (x y) (mod (* x y) +magic+))\n factors\n :key (lambda (k) (multiset-coefficient n k)))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1546581912, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03253.html", "problem_id": "p03253", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03253/input.txt", "sample_output_relpath": "derived/input_output/data/p03253/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03253/Lisp/s580333777.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s580333777", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n#-(or child-sbcl swank)\n(quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n '(\"--control-stack-size\" \"32MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" #.(namestring *load-pathname*))\n :output t :error t :input t)))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(declaim (ftype (function * (values simple-bit-vector &optional)) make-prime-table))\n(defun make-prime-table (size)\n \"Erzeugt die Primzahlentabelle 0 zu SIZE-1.\"\n (declare (optimize (speed 3) (safety 1)))\n (let ((dict (make-array size :element-type 'bit :initial-element 1)))\n (setf (sbit dict 0) 0 (sbit dict 1) 0)\n (loop for even-num from 4 below size by 2\n do (setf (sbit dict even-num) 0))\n (loop for p from 3 to (ceiling (sqrt size)) by 2\n when (= 1 (sbit dict p))\n do (loop for composite from (+ p p) below size by p\n until (>= composite size)\n do (setf (sbit dict composite) 0)))\n dict))\n\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array '(10 10 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions (when (eql cache-type :array) (second cache-attribs)))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ,dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@args)\n (,name-alias ,@args))\n ,value))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name)))))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n(defconstant +magic+ #.(+ 7 (expt 10 9)))\n(defun decompose (m)\n (declare #.OPT\n (uint32 m))\n (let* ((factor-sup (ceiling (sqrt m)))\n (prime-table (make-prime-table (1+ factor-sup))))\n (loop for i from 2 below (length prime-table)\n when (= 1 (sbit prime-table i))\n collect (nlet recurse ((count 0))\n (declare (uint32 count))\n (multiple-value-bind (quot rem) (floor m i)\n (if (zerop rem)\n (progn (setf m quot)\n (recurse (1+ count)))\n count)))\n into factors\n finally (return\n (let ((factors (delete 0 (the list factors))))\n (if (= 1 m)\n factors\n (append factors (list 1))))))))\n\n(with-memoizing (:array '(100001 32) :element-type 'fixnum :initial-element -1)\n (defun multiset-coefficient (n k)\n (declare #.OPT\n ((integer 1 #.most-positive-fixnum) n)\n ((integer 0 #.most-positive-fixnum) k))\n (cond ((zerop k) 1)\n ((= n 1) 1)\n (t (mod (the uint63 (+ (multiset-coefficient (- n 1) k)\n (multiset-coefficient n (- k 1))))\n +magic+)))))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (factors (decompose m)))\n (if (= m 1)\n (println 1)\n (println\n (reduce (lambda (x y) (mod (* x y) +magic+))\n factors\n :key (lambda (k) (multiset-coefficient n k)))))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYou are given positive integers N and M.\n\nHow many sequences a of length N consisting of positive integers satisfy a_1 \\times a_2 \\times ... \\times a_N = M? Find the count modulo 10^9+7.\n\nHere, two sequences a' and a'' are considered different when there exists some i such that a_i' \\neq a_i''.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nPrint the number of the sequences consisting of positive integers that satisfy the condition, modulo 10^9 + 7.\n\nSample Input 1\n\n2 6\n\nSample Output 1\n\n4\n\nFour sequences satisfy the condition: \\{a_1, a_2\\} = \\{1, 6\\}, \\{2, 3\\}, \\{3, 2\\} and \\{6, 1\\}.\n\nSample Input 2\n\n3 12\n\nSample Output 2\n\n18\n\nSample Input 3\n\n100000 1000000000\n\nSample Output 3\n\n957870001", "sample_input": "2 6\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03253", "source_text": "Score : 400 points\n\nProblem Statement\n\nYou are given positive integers N and M.\n\nHow many sequences a of length N consisting of positive integers satisfy a_1 \\times a_2 \\times ... \\times a_N = M? Find the count modulo 10^9+7.\n\nHere, two sequences a' and a'' are considered different when there exists some i such that a_i' \\neq a_i''.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nPrint the number of the sequences consisting of positive integers that satisfy the condition, modulo 10^9 + 7.\n\nSample Input 1\n\n2 6\n\nSample Output 1\n\n4\n\nFour sequences satisfy the condition: \\{a_1, a_2\\} = \\{1, 6\\}, \\{2, 3\\}, \\{3, 2\\} and \\{6, 1\\}.\n\nSample Input 2\n\n3 12\n\nSample Output 2\n\n18\n\nSample Input 3\n\n100000 1000000000\n\nSample Output 3\n\n957870001", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8467, "cpu_time_ms": 164, "memory_kb": 56380}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s777427674", "group_id": "codeNet:p03253", "input_text": ";; -*- coding: utf-8 -*-\n#-(or child-sbcl swank)\n(quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n '(\"--control-stack-size\" \"32MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" #.(namestring *load-pathname*))\n :output t :error t :input t)))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(declaim (ftype (function * (values simple-bit-vector &optional)) make-prime-table))\n(defun make-prime-table (size)\n \"Erzeugt die Primzahlentabelle 0 zu SIZE-1.\"\n (declare (optimize (speed 3) (safety 1)))\n (let ((dict (make-array size :element-type 'bit :initial-element 1)))\n (setf (sbit dict 0) 0 (sbit dict 1) 0)\n (loop for even-num from 4 below size by 2\n do (setf (sbit dict even-num) 0))\n (loop for p from 3 to (ceiling (sqrt size)) by 2\n when (= 1 (sbit dict p))\n do (loop for composite from (+ p p) below size by p\n until (>= composite size)\n do (setf (sbit dict composite) 0)))\n dict))\n\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array '(10 10 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions (when (eql cache-type :array) (second cache-attribs)))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ,dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@args)\n (,name-alias ,@args))\n ,value))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name)))))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n(defconstant +magic+ #.(+ 7 (expt 10 9)))\n(defun decompose (m prime-table)\n (declare #.OPT\n (simple-bit-vector prime-table)\n (uint32 m))\n (loop for i from 2 below (length prime-table)\n when (= 1 (sbit prime-table i))\n collect (nlet recurse ((count 0))\n (declare (uint32 count))\n (multiple-value-bind (quot rem) (floor m i)\n (if (zerop rem)\n (progn (setf m quot)\n (recurse (1+ count)))\n count)))\n into factors\n finally (let ((factors (delete 0 (the list factors))))\n (return (or factors (list 1))))))\n\n(with-memoizing (:array '(100001 32) :element-type 'fixnum :initial-element -1)\n (defun multiset-coefficient (n k)\n (declare #.OPT\n ((integer 1 #.most-positive-fixnum) n)\n ((integer 0 #.most-positive-fixnum) k))\n (cond ((zerop k) 1)\n ((= n 1) 1)\n (t (mod (the uint63 (+ (multiset-coefficient (- n 1) k)\n (multiset-coefficient n (- k 1))))\n +magic+)))))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (max-prime (ceiling (sqrt m)))\n (prime-table (make-prime-table (1+ max-prime)))\n (factors (decompose m prime-table)))\n (println\n (reduce (lambda (x y) (mod (* x y) +magic+))\n factors\n :key (lambda (k) (multiset-coefficient n k))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1546580271, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03253.html", "problem_id": "p03253", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03253/input.txt", "sample_output_relpath": "derived/input_output/data/p03253/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03253/Lisp/s777427674.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s777427674", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n#-(or child-sbcl swank)\n(quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n '(\"--control-stack-size\" \"32MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" #.(namestring *load-pathname*))\n :output t :error t :input t)))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(declaim (ftype (function * (values simple-bit-vector &optional)) make-prime-table))\n(defun make-prime-table (size)\n \"Erzeugt die Primzahlentabelle 0 zu SIZE-1.\"\n (declare (optimize (speed 3) (safety 1)))\n (let ((dict (make-array size :element-type 'bit :initial-element 1)))\n (setf (sbit dict 0) 0 (sbit dict 1) 0)\n (loop for even-num from 4 below size by 2\n do (setf (sbit dict even-num) 0))\n (loop for p from 3 to (ceiling (sqrt size)) by 2\n when (= 1 (sbit dict p))\n do (loop for composite from (+ p p) below size by p\n until (>= composite size)\n do (setf (sbit dict composite) 0)))\n dict))\n\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array '(10 10 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions (when (eql cache-type :array) (second cache-attribs)))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ,dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@args)\n (,name-alias ,@args))\n ,value))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name)))))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n(defconstant +magic+ #.(+ 7 (expt 10 9)))\n(defun decompose (m prime-table)\n (declare #.OPT\n (simple-bit-vector prime-table)\n (uint32 m))\n (loop for i from 2 below (length prime-table)\n when (= 1 (sbit prime-table i))\n collect (nlet recurse ((count 0))\n (declare (uint32 count))\n (multiple-value-bind (quot rem) (floor m i)\n (if (zerop rem)\n (progn (setf m quot)\n (recurse (1+ count)))\n count)))\n into factors\n finally (let ((factors (delete 0 (the list factors))))\n (return (or factors (list 1))))))\n\n(with-memoizing (:array '(100001 32) :element-type 'fixnum :initial-element -1)\n (defun multiset-coefficient (n k)\n (declare #.OPT\n ((integer 1 #.most-positive-fixnum) n)\n ((integer 0 #.most-positive-fixnum) k))\n (cond ((zerop k) 1)\n ((= n 1) 1)\n (t (mod (the uint63 (+ (multiset-coefficient (- n 1) k)\n (multiset-coefficient n (- k 1))))\n +magic+)))))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (max-prime (ceiling (sqrt m)))\n (prime-table (make-prime-table (1+ max-prime)))\n (factors (decompose m prime-table)))\n (println\n (reduce (lambda (x y) (mod (* x y) +magic+))\n factors\n :key (lambda (k) (multiset-coefficient n k))))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYou are given positive integers N and M.\n\nHow many sequences a of length N consisting of positive integers satisfy a_1 \\times a_2 \\times ... \\times a_N = M? Find the count modulo 10^9+7.\n\nHere, two sequences a' and a'' are considered different when there exists some i such that a_i' \\neq a_i''.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nPrint the number of the sequences consisting of positive integers that satisfy the condition, modulo 10^9 + 7.\n\nSample Input 1\n\n2 6\n\nSample Output 1\n\n4\n\nFour sequences satisfy the condition: \\{a_1, a_2\\} = \\{1, 6\\}, \\{2, 3\\}, \\{3, 2\\} and \\{6, 1\\}.\n\nSample Input 2\n\n3 12\n\nSample Output 2\n\n18\n\nSample Input 3\n\n100000 1000000000\n\nSample Output 3\n\n957870001", "sample_input": "2 6\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03253", "source_text": "Score : 400 points\n\nProblem Statement\n\nYou are given positive integers N and M.\n\nHow many sequences a of length N consisting of positive integers satisfy a_1 \\times a_2 \\times ... \\times a_N = M? Find the count modulo 10^9+7.\n\nHere, two sequences a' and a'' are considered different when there exists some i such that a_i' \\neq a_i''.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nPrint the number of the sequences consisting of positive integers that satisfy the condition, modulo 10^9 + 7.\n\nSample Input 1\n\n2 6\n\nSample Output 1\n\n4\n\nFour sequences satisfy the condition: \\{a_1, a_2\\} = \\{1, 6\\}, \\{2, 3\\}, \\{3, 2\\} and \\{6, 1\\}.\n\nSample Input 2\n\n3 12\n\nSample Output 2\n\n18\n\nSample Input 3\n\n100000 1000000000\n\nSample Output 3\n\n957870001", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8354, "cpu_time_ms": 328, "memory_kb": 63036}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s167897666", "group_id": "codeNet:p03254", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun main (n sum kids)\n (let ((sums (coerce (comulative #'+ (sort kids #'<)) 'vector)))\n (- (binary-search (lambda (x) (> (aref sums x) sum)) -1 n)\n (if (< (apply #'+ kids) sum) 1 0))))\n\n(let ((n (read))\n (x (read)))\n (princ (main n x (read-times n))))\n", "language": "Lisp", "metadata": {"date": 1589138873, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03254.html", "problem_id": "p03254", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03254/input.txt", "sample_output_relpath": "derived/input_output/data/p03254/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03254/Lisp/s167897666.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s167897666", "user_id": "u493610446"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun main (n sum kids)\n (let ((sums (coerce (comulative #'+ (sort kids #'<)) 'vector)))\n (- (binary-search (lambda (x) (> (aref sums x) sum)) -1 n)\n (if (< (apply #'+ kids) sum) 1 0))))\n\n(let ((n (read))\n (x (read)))\n (princ (main n x (read-times n))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N children, numbered 1, 2, ..., N.\n\nSnuke has decided to distribute x sweets among them.\nHe needs to give out all the x sweets, but some of the children may get zero sweets.\n\nFor each i (1 \\leq i \\leq N), Child i will be happy if he/she gets exactly a_i sweets.\nSnuke is trying to maximize the number of happy children by optimally distributing the sweets.\nFind the maximum possible number of happy children.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 100\n\n1 \\leq x \\leq 10^9\n\n1 \\leq a_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN x\na_1 a_2 ... a_N\n\nOutput\n\nPrint the maximum possible number of happy children.\n\nSample Input 1\n\n3 70\n20 30 10\n\nSample Output 1\n\n2\n\nOne optimal way to distribute sweets is (20, 30, 20).\n\nSample Input 2\n\n3 10\n20 30 10\n\nSample Output 2\n\n1\n\nThe optimal way to distribute sweets is (0, 0, 10).\n\nSample Input 3\n\n4 1111\n1 10 100 1000\n\nSample Output 3\n\n4\n\nThe optimal way to distribute sweets is (1, 10, 100, 1000).\n\nSample Input 4\n\n2 10\n20 20\n\nSample Output 4\n\n0\n\nNo children will be happy, no matter how the sweets are distributed.", "sample_input": "3 70\n20 30 10\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03254", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N children, numbered 1, 2, ..., N.\n\nSnuke has decided to distribute x sweets among them.\nHe needs to give out all the x sweets, but some of the children may get zero sweets.\n\nFor each i (1 \\leq i \\leq N), Child i will be happy if he/she gets exactly a_i sweets.\nSnuke is trying to maximize the number of happy children by optimally distributing the sweets.\nFind the maximum possible number of happy children.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 100\n\n1 \\leq x \\leq 10^9\n\n1 \\leq a_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN x\na_1 a_2 ... a_N\n\nOutput\n\nPrint the maximum possible number of happy children.\n\nSample Input 1\n\n3 70\n20 30 10\n\nSample Output 1\n\n2\n\nOne optimal way to distribute sweets is (20, 30, 20).\n\nSample Input 2\n\n3 10\n20 30 10\n\nSample Output 2\n\n1\n\nThe optimal way to distribute sweets is (0, 0, 10).\n\nSample Input 3\n\n4 1111\n1 10 100 1000\n\nSample Output 3\n\n4\n\nThe optimal way to distribute sweets is (1, 10, 100, 1000).\n\nSample Input 4\n\n2 10\n20 20\n\nSample Output 4\n\n0\n\nNo children will be happy, no matter how the sweets are distributed.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2305, "cpu_time_ms": 71, "memory_kb": 13236}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s370902936", "group_id": "codeNet:p03254", "input_text": "(let* ((n (read))\n (m (read))\n (lst (sort (loop :repeat n :collect (read)) #'<))\n (ans 0))\n (setf ans (count t (mapcar (lambda (k) (setf m (- m k)) (<= 0 m)) lst)))\n (if (= m 0)\n (princ ans)\n (princ (1- ans))))", "language": "Lisp", "metadata": {"date": 1560781275, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03254.html", "problem_id": "p03254", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03254/input.txt", "sample_output_relpath": "derived/input_output/data/p03254/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03254/Lisp/s370902936.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s370902936", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (lst (sort (loop :repeat n :collect (read)) #'<))\n (ans 0))\n (setf ans (count t (mapcar (lambda (k) (setf m (- m k)) (<= 0 m)) lst)))\n (if (= m 0)\n (princ ans)\n (princ (1- ans))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N children, numbered 1, 2, ..., N.\n\nSnuke has decided to distribute x sweets among them.\nHe needs to give out all the x sweets, but some of the children may get zero sweets.\n\nFor each i (1 \\leq i \\leq N), Child i will be happy if he/she gets exactly a_i sweets.\nSnuke is trying to maximize the number of happy children by optimally distributing the sweets.\nFind the maximum possible number of happy children.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 100\n\n1 \\leq x \\leq 10^9\n\n1 \\leq a_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN x\na_1 a_2 ... a_N\n\nOutput\n\nPrint the maximum possible number of happy children.\n\nSample Input 1\n\n3 70\n20 30 10\n\nSample Output 1\n\n2\n\nOne optimal way to distribute sweets is (20, 30, 20).\n\nSample Input 2\n\n3 10\n20 30 10\n\nSample Output 2\n\n1\n\nThe optimal way to distribute sweets is (0, 0, 10).\n\nSample Input 3\n\n4 1111\n1 10 100 1000\n\nSample Output 3\n\n4\n\nThe optimal way to distribute sweets is (1, 10, 100, 1000).\n\nSample Input 4\n\n2 10\n20 20\n\nSample Output 4\n\n0\n\nNo children will be happy, no matter how the sweets are distributed.", "sample_input": "3 70\n20 30 10\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03254", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N children, numbered 1, 2, ..., N.\n\nSnuke has decided to distribute x sweets among them.\nHe needs to give out all the x sweets, but some of the children may get zero sweets.\n\nFor each i (1 \\leq i \\leq N), Child i will be happy if he/she gets exactly a_i sweets.\nSnuke is trying to maximize the number of happy children by optimally distributing the sweets.\nFind the maximum possible number of happy children.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 100\n\n1 \\leq x \\leq 10^9\n\n1 \\leq a_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN x\na_1 a_2 ... a_N\n\nOutput\n\nPrint the maximum possible number of happy children.\n\nSample Input 1\n\n3 70\n20 30 10\n\nSample Output 1\n\n2\n\nOne optimal way to distribute sweets is (20, 30, 20).\n\nSample Input 2\n\n3 10\n20 30 10\n\nSample Output 2\n\n1\n\nThe optimal way to distribute sweets is (0, 0, 10).\n\nSample Input 3\n\n4 1111\n1 10 100 1000\n\nSample Output 3\n\n4\n\nThe optimal way to distribute sweets is (1, 10, 100, 1000).\n\nSample Input 4\n\n2 10\n20 20\n\nSample Output 4\n\n0\n\nNo children will be happy, no matter how the sweets are distributed.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 240, "cpu_time_ms": 141, "memory_kb": 13544}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s190653297", "group_id": "codeNet:p03254", "input_text": "(defparameter n (read))\n(defparameter x (read))\n(defparameter a (loop repeat n\n collect (read)))\n\n(defun f (x a c)\n (let ((head (car a))\n (tail (cdr a)))\n (if (< x head)\n c\n (f (- x head) tail (1+ c)))))\n\n(defun g (x a c)\n (if (null a)\n (1- c)\n (g (- x (car a)) (cdr a) (1+ c))))\n\n(princ\n (if (< x (apply #'+ a))\n (f x (sort a #'<) 0)\n (g x (sort a #'>) 0)))", "language": "Lisp", "metadata": {"date": 1537068690, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03254.html", "problem_id": "p03254", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03254/input.txt", "sample_output_relpath": "derived/input_output/data/p03254/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03254/Lisp/s190653297.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s190653297", "user_id": "u956039157"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defparameter n (read))\n(defparameter x (read))\n(defparameter a (loop repeat n\n collect (read)))\n\n(defun f (x a c)\n (let ((head (car a))\n (tail (cdr a)))\n (if (< x head)\n c\n (f (- x head) tail (1+ c)))))\n\n(defun g (x a c)\n (if (null a)\n (1- c)\n (g (- x (car a)) (cdr a) (1+ c))))\n\n(princ\n (if (< x (apply #'+ a))\n (f x (sort a #'<) 0)\n (g x (sort a #'>) 0)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N children, numbered 1, 2, ..., N.\n\nSnuke has decided to distribute x sweets among them.\nHe needs to give out all the x sweets, but some of the children may get zero sweets.\n\nFor each i (1 \\leq i \\leq N), Child i will be happy if he/she gets exactly a_i sweets.\nSnuke is trying to maximize the number of happy children by optimally distributing the sweets.\nFind the maximum possible number of happy children.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 100\n\n1 \\leq x \\leq 10^9\n\n1 \\leq a_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN x\na_1 a_2 ... a_N\n\nOutput\n\nPrint the maximum possible number of happy children.\n\nSample Input 1\n\n3 70\n20 30 10\n\nSample Output 1\n\n2\n\nOne optimal way to distribute sweets is (20, 30, 20).\n\nSample Input 2\n\n3 10\n20 30 10\n\nSample Output 2\n\n1\n\nThe optimal way to distribute sweets is (0, 0, 10).\n\nSample Input 3\n\n4 1111\n1 10 100 1000\n\nSample Output 3\n\n4\n\nThe optimal way to distribute sweets is (1, 10, 100, 1000).\n\nSample Input 4\n\n2 10\n20 20\n\nSample Output 4\n\n0\n\nNo children will be happy, no matter how the sweets are distributed.", "sample_input": "3 70\n20 30 10\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03254", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N children, numbered 1, 2, ..., N.\n\nSnuke has decided to distribute x sweets among them.\nHe needs to give out all the x sweets, but some of the children may get zero sweets.\n\nFor each i (1 \\leq i \\leq N), Child i will be happy if he/she gets exactly a_i sweets.\nSnuke is trying to maximize the number of happy children by optimally distributing the sweets.\nFind the maximum possible number of happy children.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 100\n\n1 \\leq x \\leq 10^9\n\n1 \\leq a_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN x\na_1 a_2 ... a_N\n\nOutput\n\nPrint the maximum possible number of happy children.\n\nSample Input 1\n\n3 70\n20 30 10\n\nSample Output 1\n\n2\n\nOne optimal way to distribute sweets is (20, 30, 20).\n\nSample Input 2\n\n3 10\n20 30 10\n\nSample Output 2\n\n1\n\nThe optimal way to distribute sweets is (0, 0, 10).\n\nSample Input 3\n\n4 1111\n1 10 100 1000\n\nSample Output 3\n\n4\n\nThe optimal way to distribute sweets is (1, 10, 100, 1000).\n\nSample Input 4\n\n2 10\n20 20\n\nSample Output 4\n\n0\n\nNo children will be happy, no matter how the sweets are distributed.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 426, "cpu_time_ms": 146, "memory_kb": 13664}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s444649591", "group_id": "codeNet:p03254", "input_text": "(defparameter n (read))\n(defparameter x (read))\n(defparameter a (loop repeat n\n collect (read)))\n(defun f (x a c)\n (cond ((null a) (1- c))\n ((< x (car a)) c)\n (t (f (- x (car a)) (cdr a) (1+ c)))))\n(f x (sort a #'<) 0)", "language": "Lisp", "metadata": {"date": 1537061540, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03254.html", "problem_id": "p03254", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03254/input.txt", "sample_output_relpath": "derived/input_output/data/p03254/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03254/Lisp/s444649591.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s444649591", "user_id": "u956039157"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defparameter n (read))\n(defparameter x (read))\n(defparameter a (loop repeat n\n collect (read)))\n(defun f (x a c)\n (cond ((null a) (1- c))\n ((< x (car a)) c)\n (t (f (- x (car a)) (cdr a) (1+ c)))))\n(f x (sort a #'<) 0)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N children, numbered 1, 2, ..., N.\n\nSnuke has decided to distribute x sweets among them.\nHe needs to give out all the x sweets, but some of the children may get zero sweets.\n\nFor each i (1 \\leq i \\leq N), Child i will be happy if he/she gets exactly a_i sweets.\nSnuke is trying to maximize the number of happy children by optimally distributing the sweets.\nFind the maximum possible number of happy children.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 100\n\n1 \\leq x \\leq 10^9\n\n1 \\leq a_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN x\na_1 a_2 ... a_N\n\nOutput\n\nPrint the maximum possible number of happy children.\n\nSample Input 1\n\n3 70\n20 30 10\n\nSample Output 1\n\n2\n\nOne optimal way to distribute sweets is (20, 30, 20).\n\nSample Input 2\n\n3 10\n20 30 10\n\nSample Output 2\n\n1\n\nThe optimal way to distribute sweets is (0, 0, 10).\n\nSample Input 3\n\n4 1111\n1 10 100 1000\n\nSample Output 3\n\n4\n\nThe optimal way to distribute sweets is (1, 10, 100, 1000).\n\nSample Input 4\n\n2 10\n20 20\n\nSample Output 4\n\n0\n\nNo children will be happy, no matter how the sweets are distributed.", "sample_input": "3 70\n20 30 10\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03254", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N children, numbered 1, 2, ..., N.\n\nSnuke has decided to distribute x sweets among them.\nHe needs to give out all the x sweets, but some of the children may get zero sweets.\n\nFor each i (1 \\leq i \\leq N), Child i will be happy if he/she gets exactly a_i sweets.\nSnuke is trying to maximize the number of happy children by optimally distributing the sweets.\nFind the maximum possible number of happy children.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 100\n\n1 \\leq x \\leq 10^9\n\n1 \\leq a_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN x\na_1 a_2 ... a_N\n\nOutput\n\nPrint the maximum possible number of happy children.\n\nSample Input 1\n\n3 70\n20 30 10\n\nSample Output 1\n\n2\n\nOne optimal way to distribute sweets is (20, 30, 20).\n\nSample Input 2\n\n3 10\n20 30 10\n\nSample Output 2\n\n1\n\nThe optimal way to distribute sweets is (0, 0, 10).\n\nSample Input 3\n\n4 1111\n1 10 100 1000\n\nSample Output 3\n\n4\n\nThe optimal way to distribute sweets is (1, 10, 100, 1000).\n\nSample Input 4\n\n2 10\n20 20\n\nSample Output 4\n\n0\n\nNo children will be happy, no matter how the sweets are distributed.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 254, "cpu_time_ms": 376, "memory_kb": 13536}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s899828519", "group_id": "codeNet:p03263", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0))\n (declare (string string)\n ((simple-array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop for idx from offset below (length dest-vector)\n for pos1 = 0 then (1+ pos2)\n for pos2 = (position #\\space string :start pos1 :test #'char=)\n do (setf (aref dest-vector idx)\n (parse-integer string :start pos1 :end pos2))\n finally (return dest-vector)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(defmacro with-collecting (&body body)\n (let ((list (gensym))\n (head (gensym))\n (length (gensym)))\n `(let* ((,list (list :dummy-element))\n (,head ,list)\n (,length 0))\n (labels ((collect (x)\n (setf (cdr ,list) (list x))\n (setf ,list (cdr ,list))\n (incf ,length)))\n ,@body\n (values (cdr ,head) ,length)))))\n\n(defun main ()\n (let* ((h (read))\n (w (read))\n (matrix (make-array (list h w) :element-type 'uint4))\n (row (make-array w :element-type 'uint4)))\n (dotimes (i h)\n (split-ints-into-vector (read-line) row)\n (dotimes (j w)\n (setf (aref matrix i j) (aref row j))))\n (multiple-value-bind (operations n)\n (with-collecting\n (dotimes (i h)\n (cond ((zerop i)\n (loop for j from 0 below (- w 1)\n when (oddp (aref matrix i j))\n do (decf (aref matrix i j))\n (incf (aref matrix i (+ j 1)))\n (collect (list i j i (+ j 1)))))\n ((oddp i)\n (when (oddp (aref matrix (- i 1) (- w 1)))\n (decf (aref matrix (- i 1) (- w 1)))\n (incf (aref matrix i (- w 1)))\n (collect (list (- i 1) (- w 1) i (- w 1))))\n (loop for j from (- w 1) above 0\n when (oddp (aref matrix i j))\n do (decf (aref matrix i j))\n (incf (aref matrix i (- j 1)))\n (collect (list i j i (- j 1)))))\n ((evenp i)\n (when (oddp (aref matrix (- i 1) 0))\n (decf (aref matrix (- i 1) 0))\n (incf (aref matrix i 0))\n (collect (list (- i 1) 0 i 0)))\n (loop for j from 0 below (- w 1)\n when (oddp (aref matrix i j))\n do (decf (aref matrix i j))\n (incf (aref matrix i (+ j 1)))\n (collect (list i j i (+ j 1))))))))\n (println n)\n (dolist (op operations)\n (destructuring-bind (i1 j1 i2 j2) op\n (format t \"~A ~A ~A ~A~%\" (+ i1 1) (+ j1 1) (+ i2 1) (+ j2 1)))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1547184957, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03263.html", "problem_id": "p03263", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03263/input.txt", "sample_output_relpath": "derived/input_output/data/p03263/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03263/Lisp/s899828519.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s899828519", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n2 2 2 3\n1 1 1 2\n1 3 1 2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0))\n (declare (string string)\n ((simple-array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop for idx from offset below (length dest-vector)\n for pos1 = 0 then (1+ pos2)\n for pos2 = (position #\\space string :start pos1 :test #'char=)\n do (setf (aref dest-vector idx)\n (parse-integer string :start pos1 :end pos2))\n finally (return dest-vector)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(defmacro with-collecting (&body body)\n (let ((list (gensym))\n (head (gensym))\n (length (gensym)))\n `(let* ((,list (list :dummy-element))\n (,head ,list)\n (,length 0))\n (labels ((collect (x)\n (setf (cdr ,list) (list x))\n (setf ,list (cdr ,list))\n (incf ,length)))\n ,@body\n (values (cdr ,head) ,length)))))\n\n(defun main ()\n (let* ((h (read))\n (w (read))\n (matrix (make-array (list h w) :element-type 'uint4))\n (row (make-array w :element-type 'uint4)))\n (dotimes (i h)\n (split-ints-into-vector (read-line) row)\n (dotimes (j w)\n (setf (aref matrix i j) (aref row j))))\n (multiple-value-bind (operations n)\n (with-collecting\n (dotimes (i h)\n (cond ((zerop i)\n (loop for j from 0 below (- w 1)\n when (oddp (aref matrix i j))\n do (decf (aref matrix i j))\n (incf (aref matrix i (+ j 1)))\n (collect (list i j i (+ j 1)))))\n ((oddp i)\n (when (oddp (aref matrix (- i 1) (- w 1)))\n (decf (aref matrix (- i 1) (- w 1)))\n (incf (aref matrix i (- w 1)))\n (collect (list (- i 1) (- w 1) i (- w 1))))\n (loop for j from (- w 1) above 0\n when (oddp (aref matrix i j))\n do (decf (aref matrix i j))\n (incf (aref matrix i (- j 1)))\n (collect (list i j i (- j 1)))))\n ((evenp i)\n (when (oddp (aref matrix (- i 1) 0))\n (decf (aref matrix (- i 1) 0))\n (incf (aref matrix i 0))\n (collect (list (- i 1) 0 i 0)))\n (loop for j from 0 below (- w 1)\n when (oddp (aref matrix i j))\n do (decf (aref matrix i j))\n (incf (aref matrix i (+ j 1)))\n (collect (list i j i (+ j 1))))))))\n (println n)\n (dolist (op operations)\n (destructuring-bind (i1 j1 i2 j2) op\n (format t \"~A ~A ~A ~A~%\" (+ i1 1) (+ j1 1) (+ i2 1) (+ j2 1)))))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j).\n\nIn Cell (i, j), a_{ij} coins are placed.\n\nYou can perform the following operation any number of times:\n\nOperation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell.\n\nMaximize the number of cells containing an even number of coins.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq H, W \\leq 500\n\n0 \\leq a_{ij} \\leq 9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\na_{11} a_{12} ... a_{1W}\na_{21} a_{22} ... a_{2W}\n:\na_{H1} a_{H2} ... a_{HW}\n\nOutput\n\nPrint a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format:\n\nN\ny_1 x_1 y_1' x_1'\ny_2 x_2 y_2' x_2'\n:\ny_N x_N y_N' x_N'\n\nThat is, in the first line, print an integer N between 0 and H \\times W (inclusive), representing the number of operations.\n\nIn the (i+1)-th line (1 \\leq i \\leq N), print four integers y_i, x_i, y_i' and x_i' (1 \\leq y_i, y_i' \\leq H and 1 \\leq x_i, x_i' \\leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i').\n\nNote that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in Wrong Answer.\n\nSample Input 1\n\n2 3\n1 2 3\n0 1 1\n\nSample Output 1\n\n3\n2 2 2 3\n1 1 1 2\n1 3 1 2\n\nEvery cell contains an even number of coins after the following sequence of operations:\n\nMove the coin in Cell (2, 2) to Cell (2, 3).\n\nMove the coin in Cell (1, 1) to Cell (1, 2).\n\nMove one of the coins in Cell (1, 3) to Cell (1, 2).\n\nSample Input 2\n\n3 2\n1 0\n2 1\n1 0\n\nSample Output 2\n\n3\n1 1 1 2\n1 2 2 2\n3 1 3 2\n\nSample Input 3\n\n1 5\n9 9 9 9 9\n\nSample Output 3\n\n2\n1 1 1 2\n1 3 1 4", "sample_input": "2 3\n1 2 3\n0 1 1\n"}, "reference_outputs": ["3\n2 2 2 3\n1 1 1 2\n1 3 1 2\n"], "source_document_id": "p03263", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j).\n\nIn Cell (i, j), a_{ij} coins are placed.\n\nYou can perform the following operation any number of times:\n\nOperation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell.\n\nMaximize the number of cells containing an even number of coins.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq H, W \\leq 500\n\n0 \\leq a_{ij} \\leq 9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\na_{11} a_{12} ... a_{1W}\na_{21} a_{22} ... a_{2W}\n:\na_{H1} a_{H2} ... a_{HW}\n\nOutput\n\nPrint a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format:\n\nN\ny_1 x_1 y_1' x_1'\ny_2 x_2 y_2' x_2'\n:\ny_N x_N y_N' x_N'\n\nThat is, in the first line, print an integer N between 0 and H \\times W (inclusive), representing the number of operations.\n\nIn the (i+1)-th line (1 \\leq i \\leq N), print four integers y_i, x_i, y_i' and x_i' (1 \\leq y_i, y_i' \\leq H and 1 \\leq x_i, x_i' \\leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i').\n\nNote that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in Wrong Answer.\n\nSample Input 1\n\n2 3\n1 2 3\n0 1 1\n\nSample Output 1\n\n3\n2 2 2 3\n1 1 1 2\n1 3 1 2\n\nEvery cell contains an even number of coins after the following sequence of operations:\n\nMove the coin in Cell (2, 2) to Cell (2, 3).\n\nMove the coin in Cell (1, 1) to Cell (1, 2).\n\nMove one of the coins in Cell (1, 3) to Cell (1, 2).\n\nSample Input 2\n\n3 2\n1 0\n2 1\n1 0\n\nSample Output 2\n\n3\n1 1 1 2\n1 2 2 2\n3 1 3 2\n\nSample Input 3\n\n1 5\n9 9 9 9 9\n\nSample Output 3\n\n2\n1 1 1 2\n1 3 1 4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3802, "cpu_time_ms": 767, "memory_kb": 41192}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s258183312", "group_id": "codeNet:p03264", "input_text": "(defun calcOdd (n)\n (* (/ (- n 1) 2) (+ 1 (/ (- n 1) 2)))\n )\n(defun pair (n)\n (if (evenp n)\n (expt (/ n 2) 2)\n (calcOdd n)\n )\n )\n(princ (pair (read)))", "language": "Lisp", "metadata": {"date": 1569409104, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03264.html", "problem_id": "p03264", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03264/input.txt", "sample_output_relpath": "derived/input_output/data/p03264/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03264/Lisp/s258183312.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s258183312", "user_id": "u606976120"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun calcOdd (n)\n (* (/ (- n 1) 2) (+ 1 (/ (- n 1) 2)))\n )\n(defun pair (n)\n (if (evenp n)\n (expt (/ n 2) 2)\n (calcOdd n)\n )\n )\n(princ (pair (read)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nFind the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive). The order does not matter.\n\nConstraints\n\n2\\leq K\\leq 100\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive).\n\nSample Input 1\n\n3\n\nSample Output 1\n\n2\n\nTwo pairs can be chosen: (2,1) and (2,3).\n\nSample Input 2\n\n6\n\nSample Output 2\n\n9\n\nSample Input 3\n\n11\n\nSample Output 3\n\n30\n\nSample Input 4\n\n50\n\nSample Output 4\n\n625", "sample_input": "3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03264", "source_text": "Score : 100 points\n\nProblem Statement\n\nFind the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive). The order does not matter.\n\nConstraints\n\n2\\leq K\\leq 100\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive).\n\nSample Input 1\n\n3\n\nSample Output 1\n\n2\n\nTwo pairs can be chosen: (2,1) and (2,3).\n\nSample Input 2\n\n6\n\nSample Output 2\n\n9\n\nSample Input 3\n\n11\n\nSample Output 3\n\n30\n\nSample Input 4\n\n50\n\nSample Output 4\n\n625", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 170, "cpu_time_ms": 12, "memory_kb": 3560}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s395312255", "group_id": "codeNet:p03264", "input_text": "(defparameter k (read))\n(defvar q)\n(defvar res)\n\n(multiple-value-bind (q res) (floor k 2)\n (if (= res 0)\n (princ (expt q 2))\n (princ (* q (incf q)))))", "language": "Lisp", "metadata": {"date": 1561759839, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03264.html", "problem_id": "p03264", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03264/input.txt", "sample_output_relpath": "derived/input_output/data/p03264/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03264/Lisp/s395312255.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s395312255", "user_id": "u480300350"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defparameter k (read))\n(defvar q)\n(defvar res)\n\n(multiple-value-bind (q res) (floor k 2)\n (if (= res 0)\n (princ (expt q 2))\n (princ (* q (incf q)))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nFind the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive). The order does not matter.\n\nConstraints\n\n2\\leq K\\leq 100\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive).\n\nSample Input 1\n\n3\n\nSample Output 1\n\n2\n\nTwo pairs can be chosen: (2,1) and (2,3).\n\nSample Input 2\n\n6\n\nSample Output 2\n\n9\n\nSample Input 3\n\n11\n\nSample Output 3\n\n30\n\nSample Input 4\n\n50\n\nSample Output 4\n\n625", "sample_input": "3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03264", "source_text": "Score : 100 points\n\nProblem Statement\n\nFind the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive). The order does not matter.\n\nConstraints\n\n2\\leq K\\leq 100\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive).\n\nSample Input 1\n\n3\n\nSample Output 1\n\n2\n\nTwo pairs can be chosen: (2,1) and (2,3).\n\nSample Input 2\n\n6\n\nSample Output 2\n\n9\n\nSample Input 3\n\n11\n\nSample Output 3\n\n30\n\nSample Input 4\n\n50\n\nSample Output 4\n\n625", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 157, "cpu_time_ms": 138, "memory_kb": 13284}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s931858427", "group_id": "codeNet:p03264", "input_text": "(defun a (x)\n (if (= 1 (mod x 2)) \n (floor (* (1- x) (1+ x)) 4) \n (floor (* x x) 4)))\n\n(a (parse-integer (read)))", "language": "Lisp", "metadata": {"date": 1536528137, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03264.html", "problem_id": "p03264", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03264/input.txt", "sample_output_relpath": "derived/input_output/data/p03264/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03264/Lisp/s931858427.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s931858427", "user_id": "u026537738"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun a (x)\n (if (= 1 (mod x 2)) \n (floor (* (1- x) (1+ x)) 4) \n (floor (* x x) 4)))\n\n(a (parse-integer (read)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nFind the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive). The order does not matter.\n\nConstraints\n\n2\\leq K\\leq 100\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive).\n\nSample Input 1\n\n3\n\nSample Output 1\n\n2\n\nTwo pairs can be chosen: (2,1) and (2,3).\n\nSample Input 2\n\n6\n\nSample Output 2\n\n9\n\nSample Input 3\n\n11\n\nSample Output 3\n\n30\n\nSample Input 4\n\n50\n\nSample Output 4\n\n625", "sample_input": "3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03264", "source_text": "Score : 100 points\n\nProblem Statement\n\nFind the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive). The order does not matter.\n\nConstraints\n\n2\\leq K\\leq 100\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive).\n\nSample Input 1\n\n3\n\nSample Output 1\n\n2\n\nTwo pairs can be chosen: (2,1) and (2,3).\n\nSample Input 2\n\n6\n\nSample Output 2\n\n9\n\nSample Input 3\n\n11\n\nSample Output 3\n\n30\n\nSample Input 4\n\n50\n\nSample Output 4\n\n625", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 124, "cpu_time_ms": 153, "memory_kb": 16996}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s182613577", "group_id": "codeNet:p03264", "input_text": "(princ(floor(expt(read)2)4))", "language": "Lisp", "metadata": {"date": 1535870405, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03264.html", "problem_id": "p03264", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03264/input.txt", "sample_output_relpath": "derived/input_output/data/p03264/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03264/Lisp/s182613577.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s182613577", "user_id": "u657913472"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(princ(floor(expt(read)2)4))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nFind the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive). The order does not matter.\n\nConstraints\n\n2\\leq K\\leq 100\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive).\n\nSample Input 1\n\n3\n\nSample Output 1\n\n2\n\nTwo pairs can be chosen: (2,1) and (2,3).\n\nSample Input 2\n\n6\n\nSample Output 2\n\n9\n\nSample Input 3\n\n11\n\nSample Output 3\n\n30\n\nSample Input 4\n\n50\n\nSample Output 4\n\n625", "sample_input": "3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03264", "source_text": "Score : 100 points\n\nProblem Statement\n\nFind the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive). The order does not matter.\n\nConstraints\n\n2\\leq K\\leq 100\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive).\n\nSample Input 1\n\n3\n\nSample Output 1\n\n2\n\nTwo pairs can be chosen: (2,1) and (2,3).\n\nSample Input 2\n\n6\n\nSample Output 2\n\n9\n\nSample Input 3\n\n11\n\nSample Output 3\n\n30\n\nSample Input 4\n\n50\n\nSample Output 4\n\n625", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 28, "cpu_time_ms": 20, "memory_kb": 3808}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s065703347", "group_id": "codeNet:p03265", "input_text": "(defvar *ans*)\n\n(defun solve (x1 y1 x2 y2)\n (let (x3 y3 x4 y4)\n (setq x3 (- x2 (- y2 y1)))\n (setq y3 (+ y2 (- x2 x1)))\n (setq x4 (- x1 (- y2 y1)))\n (setq y4 (+ y1 (- x2 x1)))\n (list x3 y3 x4 y4)))\n\n(defun main ()\n (let ((x1 (read))\n (y1 (read))\n (x2 (read))\n (y2 (read)))\n (setf *ans* (solve x1 y1 x2 y2))\n (fresh-line)\n (dotimes (i 4)\n (princ (nth i *ans*))\n (princ #\\space))\n (princ #\\newline)\n (fresh-line)))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1594439399, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03265.html", "problem_id": "p03265", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03265/input.txt", "sample_output_relpath": "derived/input_output/data/p03265/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03265/Lisp/s065703347.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s065703347", "user_id": "u425762225"}, "prompt_components": {"gold_output": "-1 1 -1 0\n", "input_to_evaluate": "(defvar *ans*)\n\n(defun solve (x1 y1 x2 y2)\n (let (x3 y3 x4 y4)\n (setq x3 (- x2 (- y2 y1)))\n (setq y3 (+ y2 (- x2 x1)))\n (setq x4 (- x1 (- y2 y1)))\n (setq y4 (+ y1 (- x2 x1)))\n (list x3 y3 x4 y4)))\n\n(defun main ()\n (let ((x1 (read))\n (y1 (read))\n (x2 (read))\n (y2 (read)))\n (setf *ans* (solve x1 y1 x2 y2))\n (fresh-line)\n (dotimes (i 4)\n (princ (nth i *ans*))\n (princ #\\space))\n (princ #\\newline)\n (fresh-line)))\n\n(main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere is a square in the xy-plane. The coordinates of its four vertices are (x_1,y_1),(x_2,y_2),(x_3,y_3) and (x_4,y_4) in counter-clockwise order.\n(Assume that the positive x-axis points right, and the positive y-axis points up.)\n\nTakahashi remembers (x_1,y_1) and (x_2,y_2), but he has forgot (x_3,y_3) and (x_4,y_4).\n\nGiven x_1,x_2,y_1,y_2, restore x_3,y_3,x_4,y_4. It can be shown that x_3,y_3,x_4 and y_4 uniquely exist and have integer values.\n\nConstraints\n\n|x_1|,|y_1|,|x_2|,|y_2| \\leq 100\n\n(x_1,y_1) ≠ (x_2,y_2)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx_1 y_1 x_2 y_2\n\nOutput\n\nPrint x_3,y_3,x_4 and y_4 as integers, in this order.\n\nSample Input 1\n\n0 0 0 1\n\nSample Output 1\n\n-1 1 -1 0\n\n(0,0),(0,1),(-1,1),(-1,0) is the four vertices of a square in counter-clockwise order.\nNote that (x_3,y_3)=(1,1),(x_4,y_4)=(1,0) is not accepted, as the vertices are in clockwise order.\n\nSample Input 2\n\n2 3 6 6\n\nSample Output 2\n\n3 10 -1 7\n\nSample Input 3\n\n31 -41 -59 26\n\nSample Output 3\n\n-126 -64 -36 -131", "sample_input": "0 0 0 1\n"}, "reference_outputs": ["-1 1 -1 0\n"], "source_document_id": "p03265", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere is a square in the xy-plane. The coordinates of its four vertices are (x_1,y_1),(x_2,y_2),(x_3,y_3) and (x_4,y_4) in counter-clockwise order.\n(Assume that the positive x-axis points right, and the positive y-axis points up.)\n\nTakahashi remembers (x_1,y_1) and (x_2,y_2), but he has forgot (x_3,y_3) and (x_4,y_4).\n\nGiven x_1,x_2,y_1,y_2, restore x_3,y_3,x_4,y_4. It can be shown that x_3,y_3,x_4 and y_4 uniquely exist and have integer values.\n\nConstraints\n\n|x_1|,|y_1|,|x_2|,|y_2| \\leq 100\n\n(x_1,y_1) ≠ (x_2,y_2)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx_1 y_1 x_2 y_2\n\nOutput\n\nPrint x_3,y_3,x_4 and y_4 as integers, in this order.\n\nSample Input 1\n\n0 0 0 1\n\nSample Output 1\n\n-1 1 -1 0\n\n(0,0),(0,1),(-1,1),(-1,0) is the four vertices of a square in counter-clockwise order.\nNote that (x_3,y_3)=(1,1),(x_4,y_4)=(1,0) is not accepted, as the vertices are in clockwise order.\n\nSample Input 2\n\n2 3 6 6\n\nSample Output 2\n\n3 10 -1 7\n\nSample Input 3\n\n31 -41 -59 26\n\nSample Output 3\n\n-126 -64 -36 -131", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 483, "cpu_time_ms": 18, "memory_kb": 24360}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s735718772", "group_id": "codeNet:p03265", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n ,then\n ,else))\n\n(defun read2 ()\n (cons (read) (read)))\n\n(defun add (a b)\n (cons (+ (car a) (car b)) (+ (cdr a) (cdr b))))\n\n(defun sub (a b)\n (cons (- (car a) (car b)) (- (cdr a) (cdr b))))\n\n(defun rot (x)\n (cons (- 0 (cdr x)) (car x)))\n\n(defun tolist (x)\n (list (car x) (cdr x)))\n\n(defun main (v1 v2)\n (let ((adder (rot (sub v2 v1))))\n (append (tolist (add v2 adder)) (tolist (add v1 adder)))))\n\n(format t \"~{~a~^ ~}\" (main (read2) (read2)))\n\n(main (read2) (read2))\n", "language": "Lisp", "metadata": {"date": 1587153163, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03265.html", "problem_id": "p03265", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03265/input.txt", "sample_output_relpath": "derived/input_output/data/p03265/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03265/Lisp/s735718772.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s735718772", "user_id": "u493610446"}, "prompt_components": {"gold_output": "-1 1 -1 0\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n ,then\n ,else))\n\n(defun read2 ()\n (cons (read) (read)))\n\n(defun add (a b)\n (cons (+ (car a) (car b)) (+ (cdr a) (cdr b))))\n\n(defun sub (a b)\n (cons (- (car a) (car b)) (- (cdr a) (cdr b))))\n\n(defun rot (x)\n (cons (- 0 (cdr x)) (car x)))\n\n(defun tolist (x)\n (list (car x) (cdr x)))\n\n(defun main (v1 v2)\n (let ((adder (rot (sub v2 v1))))\n (append (tolist (add v2 adder)) (tolist (add v1 adder)))))\n\n(format t \"~{~a~^ ~}\" (main (read2) (read2)))\n\n(main (read2) (read2))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere is a square in the xy-plane. The coordinates of its four vertices are (x_1,y_1),(x_2,y_2),(x_3,y_3) and (x_4,y_4) in counter-clockwise order.\n(Assume that the positive x-axis points right, and the positive y-axis points up.)\n\nTakahashi remembers (x_1,y_1) and (x_2,y_2), but he has forgot (x_3,y_3) and (x_4,y_4).\n\nGiven x_1,x_2,y_1,y_2, restore x_3,y_3,x_4,y_4. It can be shown that x_3,y_3,x_4 and y_4 uniquely exist and have integer values.\n\nConstraints\n\n|x_1|,|y_1|,|x_2|,|y_2| \\leq 100\n\n(x_1,y_1) ≠ (x_2,y_2)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx_1 y_1 x_2 y_2\n\nOutput\n\nPrint x_3,y_3,x_4 and y_4 as integers, in this order.\n\nSample Input 1\n\n0 0 0 1\n\nSample Output 1\n\n-1 1 -1 0\n\n(0,0),(0,1),(-1,1),(-1,0) is the four vertices of a square in counter-clockwise order.\nNote that (x_3,y_3)=(1,1),(x_4,y_4)=(1,0) is not accepted, as the vertices are in clockwise order.\n\nSample Input 2\n\n2 3 6 6\n\nSample Output 2\n\n3 10 -1 7\n\nSample Input 3\n\n31 -41 -59 26\n\nSample Output 3\n\n-126 -64 -36 -131", "sample_input": "0 0 0 1\n"}, "reference_outputs": ["-1 1 -1 0\n"], "source_document_id": "p03265", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere is a square in the xy-plane. The coordinates of its four vertices are (x_1,y_1),(x_2,y_2),(x_3,y_3) and (x_4,y_4) in counter-clockwise order.\n(Assume that the positive x-axis points right, and the positive y-axis points up.)\n\nTakahashi remembers (x_1,y_1) and (x_2,y_2), but he has forgot (x_3,y_3) and (x_4,y_4).\n\nGiven x_1,x_2,y_1,y_2, restore x_3,y_3,x_4,y_4. It can be shown that x_3,y_3,x_4 and y_4 uniquely exist and have integer values.\n\nConstraints\n\n|x_1|,|y_1|,|x_2|,|y_2| \\leq 100\n\n(x_1,y_1) ≠ (x_2,y_2)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx_1 y_1 x_2 y_2\n\nOutput\n\nPrint x_3,y_3,x_4 and y_4 as integers, in this order.\n\nSample Input 1\n\n0 0 0 1\n\nSample Output 1\n\n-1 1 -1 0\n\n(0,0),(0,1),(-1,1),(-1,0) is the four vertices of a square in counter-clockwise order.\nNote that (x_3,y_3)=(1,1),(x_4,y_4)=(1,0) is not accepted, as the vertices are in clockwise order.\n\nSample Input 2\n\n2 3 6 6\n\nSample Output 2\n\n3 10 -1 7\n\nSample Input 3\n\n31 -41 -59 26\n\nSample Output 3\n\n-126 -64 -36 -131", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1582, "cpu_time_ms": 148, "memory_kb": 18744}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s811190422", "group_id": "codeNet:p03265", "input_text": "(defun b (x1 y1 x2 y2)\n (let ((x3 x2)\n\t(x4 x1)\n\t(y3 (+ y2 (- x2 x1)))\n\t(y4 (+ y1 (- x2 x1))))\n (list x3 y3 x3 x4)))\n\n(defun split (line)\n (let ((result ()) (str \"\"))\n (dolist (i (loop for i across line collect i))\n (if (eql i #\\space)\n\t (progn\n\t (setf result (append result (list (parse-integer str))))\n\t (setf str \"\"))\n\t (setf str (concatenate 'string str (string i)))))\n (setf result (append result (list (parse-integer str))))\n result))\n\n(format t \"~{~a ~}\" (eval `(b ,@(split (read-line)))))", "language": "Lisp", "metadata": {"date": 1536533663, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03265.html", "problem_id": "p03265", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03265/input.txt", "sample_output_relpath": "derived/input_output/data/p03265/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03265/Lisp/s811190422.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s811190422", "user_id": "u026537738"}, "prompt_components": {"gold_output": "-1 1 -1 0\n", "input_to_evaluate": "(defun b (x1 y1 x2 y2)\n (let ((x3 x2)\n\t(x4 x1)\n\t(y3 (+ y2 (- x2 x1)))\n\t(y4 (+ y1 (- x2 x1))))\n (list x3 y3 x3 x4)))\n\n(defun split (line)\n (let ((result ()) (str \"\"))\n (dolist (i (loop for i across line collect i))\n (if (eql i #\\space)\n\t (progn\n\t (setf result (append result (list (parse-integer str))))\n\t (setf str \"\"))\n\t (setf str (concatenate 'string str (string i)))))\n (setf result (append result (list (parse-integer str))))\n result))\n\n(format t \"~{~a ~}\" (eval `(b ,@(split (read-line)))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere is a square in the xy-plane. The coordinates of its four vertices are (x_1,y_1),(x_2,y_2),(x_3,y_3) and (x_4,y_4) in counter-clockwise order.\n(Assume that the positive x-axis points right, and the positive y-axis points up.)\n\nTakahashi remembers (x_1,y_1) and (x_2,y_2), but he has forgot (x_3,y_3) and (x_4,y_4).\n\nGiven x_1,x_2,y_1,y_2, restore x_3,y_3,x_4,y_4. It can be shown that x_3,y_3,x_4 and y_4 uniquely exist and have integer values.\n\nConstraints\n\n|x_1|,|y_1|,|x_2|,|y_2| \\leq 100\n\n(x_1,y_1) ≠ (x_2,y_2)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx_1 y_1 x_2 y_2\n\nOutput\n\nPrint x_3,y_3,x_4 and y_4 as integers, in this order.\n\nSample Input 1\n\n0 0 0 1\n\nSample Output 1\n\n-1 1 -1 0\n\n(0,0),(0,1),(-1,1),(-1,0) is the four vertices of a square in counter-clockwise order.\nNote that (x_3,y_3)=(1,1),(x_4,y_4)=(1,0) is not accepted, as the vertices are in clockwise order.\n\nSample Input 2\n\n2 3 6 6\n\nSample Output 2\n\n3 10 -1 7\n\nSample Input 3\n\n31 -41 -59 26\n\nSample Output 3\n\n-126 -64 -36 -131", "sample_input": "0 0 0 1\n"}, "reference_outputs": ["-1 1 -1 0\n"], "source_document_id": "p03265", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere is a square in the xy-plane. The coordinates of its four vertices are (x_1,y_1),(x_2,y_2),(x_3,y_3) and (x_4,y_4) in counter-clockwise order.\n(Assume that the positive x-axis points right, and the positive y-axis points up.)\n\nTakahashi remembers (x_1,y_1) and (x_2,y_2), but he has forgot (x_3,y_3) and (x_4,y_4).\n\nGiven x_1,x_2,y_1,y_2, restore x_3,y_3,x_4,y_4. It can be shown that x_3,y_3,x_4 and y_4 uniquely exist and have integer values.\n\nConstraints\n\n|x_1|,|y_1|,|x_2|,|y_2| \\leq 100\n\n(x_1,y_1) ≠ (x_2,y_2)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx_1 y_1 x_2 y_2\n\nOutput\n\nPrint x_3,y_3,x_4 and y_4 as integers, in this order.\n\nSample Input 1\n\n0 0 0 1\n\nSample Output 1\n\n-1 1 -1 0\n\n(0,0),(0,1),(-1,1),(-1,0) is the four vertices of a square in counter-clockwise order.\nNote that (x_3,y_3)=(1,1),(x_4,y_4)=(1,0) is not accepted, as the vertices are in clockwise order.\n\nSample Input 2\n\n2 3 6 6\n\nSample Output 2\n\n3 10 -1 7\n\nSample Input 3\n\n31 -41 -59 26\n\nSample Output 3\n\n-126 -64 -36 -131", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 522, "cpu_time_ms": 138, "memory_kb": 13408}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s328318002", "group_id": "codeNet:p03266", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (k (read)))\n (println\n (if (oddp k)\n (expt (floor n k) 3)\n (+ (expt (floor (+ n (floor k 2)) k) 3)\n (expt (floor n k) 3))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1561072117, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03266.html", "problem_id": "p03266", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03266/input.txt", "sample_output_relpath": "derived/input_output/data/p03266/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03266/Lisp/s328318002.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s328318002", "user_id": "u352600849"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (k (read)))\n (println\n (if (oddp k)\n (expt (floor n k) 3)\n (+ (expt (floor (+ n (floor k 2)) k) 3)\n (expt (floor n k) 3))))))\n\n#-swank(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.\nThe order of a,b,c does matter, and some of them can be the same.\n\nConstraints\n\n1 \\leq N,K \\leq 2\\times 10^5\n\nN and K are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.\n\nSample Input 1\n\n3 2\n\nSample Output 1\n\n9\n\n(1,1,1),(1,1,3),(1,3,1),(1,3,3),(2,2,2),(3,1,1),(3,1,3),(3,3,1) and (3,3,3) satisfy the condition.\n\nSample Input 2\n\n5 3\n\nSample Output 2\n\n1\n\nSample Input 3\n\n31415 9265\n\nSample Output 3\n\n27\n\nSample Input 4\n\n35897 932\n\nSample Output 4\n\n114191", "sample_input": "3 2\n"}, "reference_outputs": ["9\n"], "source_document_id": "p03266", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.\nThe order of a,b,c does matter, and some of them can be the same.\n\nConstraints\n\n1 \\leq N,K \\leq 2\\times 10^5\n\nN and K are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.\n\nSample Input 1\n\n3 2\n\nSample Output 1\n\n9\n\n(1,1,1),(1,1,3),(1,3,1),(1,3,3),(2,2,2),(3,1,1),(3,1,3),(3,3,1) and (3,3,3) satisfy the condition.\n\nSample Input 2\n\n5 3\n\nSample Output 2\n\n1\n\nSample Input 3\n\n31415 9265\n\nSample Output 3\n\n27\n\nSample Input 4\n\n35897 932\n\nSample Output 4\n\n114191", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1526, "cpu_time_ms": 200, "memory_kb": 21220}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s559194915", "group_id": "codeNet:p03272", "input_text": "(defun a (n i)\n (- (+ n 1) i)\n )\n(princ (a (read)))", "language": "Lisp", "metadata": {"date": 1569464783, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03272.html", "problem_id": "p03272", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03272/input.txt", "sample_output_relpath": "derived/input_output/data/p03272/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03272/Lisp/s559194915.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s559194915", "user_id": "u606976120"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun a (n i)\n (- (+ n 1) i)\n )\n(princ (a (read)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere is an N-car train.\n\nYou are given an integer i. Find the value of j such that the following statement is true: \"the i-th car from the front of the train is the j-th car from the back.\"\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN i\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n4 2\n\nSample Output 1\n\n3\n\nThe second car from the front of a 4-car train is the third car from the back.\n\nSample Input 2\n\n1 1\n\nSample Output 2\n\n1\n\nSample Input 3\n\n15 11\n\nSample Output 3\n\n5", "sample_input": "4 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03272", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere is an N-car train.\n\nYou are given an integer i. Find the value of j such that the following statement is true: \"the i-th car from the front of the train is the j-th car from the back.\"\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN i\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n4 2\n\nSample Output 1\n\n3\n\nThe second car from the front of a 4-car train is the third car from the back.\n\nSample Input 2\n\n1 1\n\nSample Output 2\n\n1\n\nSample Input 3\n\n15 11\n\nSample Output 3\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 53, "cpu_time_ms": 149, "memory_kb": 11876}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s850988598", "group_id": "codeNet:p03272", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(deftype int32 () '(signed-byte 32))\n(deftype int64 () '(signed-byte 64))\n\n\n;;macros\n(defmacro println (n)\n `(format t \"~a~%\" ,n))\n(defmacro vint-out (vec)\n `(progn\n (rep i (length ,vec)\n (princ (vref ,vec i))\n (princ \" \"))\n (fresh-line)))\n\n\n;;vector\n(defmacro vec (type &optional (num 100) (val 0))\n (let* ((g (gensym)))\n `(let* ((,g ,num))\n (make-array ,g :element-type ',type :initial-element ,val\n :adjustable nil :fill-pointer ,g))))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vint (&optional (num 0) (val 0))\n `(vec int32 ,num ,val))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vref (vector pos &optional value)\n (let ((g (gensym)))\n `(let ((,g ,value))\n (if ,g\n (setf (aref ,vector ,pos) ,g)\n (aref ,vector ,pos)))))\n\n(defmacro chvar (sym comp predicate)\n (let ((g (gensym)))\n `(let ((,g ,comp))\n (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))\n (setf ,sym ,g)))))\n\n(defmacro chmax (sym comp &optional (predicate #'>))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro chmin (sym comp &optional (predicate #'<))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro defchangef (name op default-val)\n `(defmacro ,name (var &optional (val ,default-val))\n `(setq ,var (,',op ,val ,var))))\n\n;;本体\n(defun main()\n (let ((n (read))(i (read)))\n (println (- (1+ n) i))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1559248291, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03272.html", "problem_id": "p03272", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03272/input.txt", "sample_output_relpath": "derived/input_output/data/p03272/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03272/Lisp/s850988598.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s850988598", "user_id": "u432998668"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(deftype int32 () '(signed-byte 32))\n(deftype int64 () '(signed-byte 64))\n\n\n;;macros\n(defmacro println (n)\n `(format t \"~a~%\" ,n))\n(defmacro vint-out (vec)\n `(progn\n (rep i (length ,vec)\n (princ (vref ,vec i))\n (princ \" \"))\n (fresh-line)))\n\n\n;;vector\n(defmacro vec (type &optional (num 100) (val 0))\n (let* ((g (gensym)))\n `(let* ((,g ,num))\n (make-array ,g :element-type ',type :initial-element ,val\n :adjustable nil :fill-pointer ,g))))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vint (&optional (num 0) (val 0))\n `(vec int32 ,num ,val))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vref (vector pos &optional value)\n (let ((g (gensym)))\n `(let ((,g ,value))\n (if ,g\n (setf (aref ,vector ,pos) ,g)\n (aref ,vector ,pos)))))\n\n(defmacro chvar (sym comp predicate)\n (let ((g (gensym)))\n `(let ((,g ,comp))\n (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))\n (setf ,sym ,g)))))\n\n(defmacro chmax (sym comp &optional (predicate #'>))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro chmin (sym comp &optional (predicate #'<))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro defchangef (name op default-val)\n `(defmacro ,name (var &optional (val ,default-val))\n `(setq ,var (,',op ,val ,var))))\n\n;;本体\n(defun main()\n (let ((n (read))(i (read)))\n (println (- (1+ n) i))))\n\n#-swank(main)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere is an N-car train.\n\nYou are given an integer i. Find the value of j such that the following statement is true: \"the i-th car from the front of the train is the j-th car from the back.\"\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN i\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n4 2\n\nSample Output 1\n\n3\n\nThe second car from the front of a 4-car train is the third car from the back.\n\nSample Input 2\n\n1 1\n\nSample Output 2\n\n1\n\nSample Input 3\n\n15 11\n\nSample Output 3\n\n5", "sample_input": "4 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03272", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere is an N-car train.\n\nYou are given an integer i. Find the value of j such that the following statement is true: \"the i-th car from the front of the train is the j-th car from the back.\"\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq i \\leq N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN i\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n4 2\n\nSample Output 1\n\n3\n\nThe second car from the front of a 4-car train is the third car from the back.\n\nSample Input 2\n\n1 1\n\nSample Output 2\n\n1\n\nSample Input 3\n\n15 11\n\nSample Output 3\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1915, "cpu_time_ms": 42, "memory_kb": 9060}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s723147591", "group_id": "codeNet:p03274", "input_text": ";;; body\n\n(defun solve (n k x)\n (flet ((calc-dist (i-left i-right)\n (min (+ (abs i-left) (abs (- i-right i-left)))\n (+ (abs i-right) (abs (- i-right i-left))))))\n (if (= n 1)\n (abs (aref x 0))\n (reduce #'min \n (loop for i below (1+ (- n k)) collect\n (calc-dist (aref x i)\n (aref x (1- (+ i k)))))))))\n\n(defun main ()\n (let ((n (read))\n (k (read)))\n (let ((x (make-array n\n :initial-contents (loop repeat n collect (read)))))\n (princ (solve n k x))\n (fresh-line))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1599828366, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03274.html", "problem_id": "p03274", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03274/input.txt", "sample_output_relpath": "derived/input_output/data/p03274/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03274/Lisp/s723147591.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s723147591", "user_id": "u425762225"}, "prompt_components": {"gold_output": "40\n", "input_to_evaluate": ";;; body\n\n(defun solve (n k x)\n (flet ((calc-dist (i-left i-right)\n (min (+ (abs i-left) (abs (- i-right i-left)))\n (+ (abs i-right) (abs (- i-right i-left))))))\n (if (= n 1)\n (abs (aref x 0))\n (reduce #'min \n (loop for i below (1+ (- n k)) collect\n (calc-dist (aref x i)\n (aref x (1- (+ i k)))))))))\n\n(defun main ()\n (let ((n (read))\n (k (read)))\n (let ((x (make-array n\n :initial-contents (loop repeat n collect (read)))))\n (princ (solve n k x))\n (fresh-line))))\n\n#-swank (main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N candles placed on a number line.\nThe i-th candle from the left is placed on coordinate x_i.\nHere, x_1 < x_2 < ... < x_N holds.\n\nInitially, no candles are burning.\nSnuke decides to light K of the N candles.\n\nNow, he is at coordinate 0.\nHe can move left and right along the line with speed 1.\nHe can also light a candle when he is at the same position as the candle, in negligible time.\n\nFind the minimum time required to light K candles.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq K \\leq N\n\nx_i is an integer.\n\n|x_i| \\leq 10^8\n\nx_1 < x_2 < ... < x_N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nx_1 x_2 ... x_N\n\nOutput\n\nPrint the minimum time required to light K candles.\n\nSample Input 1\n\n5 3\n-30 -10 10 20 50\n\nSample Output 1\n\n40\n\nHe should move and light candles as follows:\n\nMove from coordinate 0 to -10.\n\nLight the second candle from the left.\n\nMove from coordinate -10 to 10.\n\nLight the third candle from the left.\n\nMove from coordinate 10 to 20.\n\nLight the fourth candle from the left.\n\nSample Input 2\n\n3 2\n10 20 30\n\nSample Output 2\n\n20\n\nSample Input 3\n\n1 1\n0\n\nSample Output 3\n\n0\n\nThere may be a candle placed at coordinate 0.\n\nSample Input 4\n\n8 5\n-9 -7 -4 -3 1 2 3 4\n\nSample Output 4\n\n10", "sample_input": "5 3\n-30 -10 10 20 50\n"}, "reference_outputs": ["40\n"], "source_document_id": "p03274", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N candles placed on a number line.\nThe i-th candle from the left is placed on coordinate x_i.\nHere, x_1 < x_2 < ... < x_N holds.\n\nInitially, no candles are burning.\nSnuke decides to light K of the N candles.\n\nNow, he is at coordinate 0.\nHe can move left and right along the line with speed 1.\nHe can also light a candle when he is at the same position as the candle, in negligible time.\n\nFind the minimum time required to light K candles.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq K \\leq N\n\nx_i is an integer.\n\n|x_i| \\leq 10^8\n\nx_1 < x_2 < ... < x_N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nx_1 x_2 ... x_N\n\nOutput\n\nPrint the minimum time required to light K candles.\n\nSample Input 1\n\n5 3\n-30 -10 10 20 50\n\nSample Output 1\n\n40\n\nHe should move and light candles as follows:\n\nMove from coordinate 0 to -10.\n\nLight the second candle from the left.\n\nMove from coordinate -10 to 10.\n\nLight the third candle from the left.\n\nMove from coordinate 10 to 20.\n\nLight the fourth candle from the left.\n\nSample Input 2\n\n3 2\n10 20 30\n\nSample Output 2\n\n20\n\nSample Input 3\n\n1 1\n0\n\nSample Output 3\n\n0\n\nThere may be a candle placed at coordinate 0.\n\nSample Input 4\n\n8 5\n-9 -7 -4 -3 1 2 3 4\n\nSample Output 4\n\n10", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 635, "cpu_time_ms": 144, "memory_kb": 78420}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s908158252", "group_id": "codeNet:p03275", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; ARRAY-ELEMENT-TYPE is not constant-folded on SBCL version earlier than\n;;; 1.5.0. See\n;;; https://github.com/sbcl/sbcl/commit/9f0d12e7ab961828931d01c0b2a76a5885ad35d2\n;;;\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:deftransform array-element-type ((array))\n (let ((type (sb-c::lvar-type array)))\n (flet ((element-type (type)\n (and (sb-c::array-type-p type)\n (sb-int:neq (sb-kernel::array-type-specialized-element-type type) sb-kernel:*wild-type*)\n (sb-kernel:type-specifier (sb-kernel::array-type-specialized-element-type type)))))\n (cond ((let ((type (element-type type)))\n (and type\n `',type)))\n ((sb-kernel:union-type-p type)\n (let (result)\n (loop for type in (sb-kernel:union-type-types type)\n for et = (element-type type)\n unless (and et\n (if result\n (equal result et)\n (setf result et)))\n do (sb-c::give-up-ir1-transform))\n `',result))\n ((sb-kernel:intersection-type-p type)\n (loop for type in (sb-kernel:intersection-type-types type)\n for et = (element-type type)\n when et\n return `',et\n finally (sb-c::give-up-ir1-transform)))\n (t\n (sb-c::give-up-ir1-transform)))))))\n\n;;;\n;;; Calculate inversion number by merge sort\n;;;\n\n(declaim (inline %merge-count))\n(defun %merge-count (l mid r source-vec dest-vec predicate)\n (declare ((integer 0 #.array-total-size-limit) l mid r)\n (function predicate))\n (loop with count of-type (integer 0 #.most-positive-fixnum) = 0\n with i = l\n with j = mid\n for idx from l\n when (= i mid)\n do (loop for j from j below r\n for idx from idx\n do (setf (aref dest-vec idx)\n (aref source-vec j))\n finally (return-from %merge-count count))\n when (= j r)\n do (loop for i from i below mid\n for idx from idx\n do (setf (aref dest-vec idx)\n (aref source-vec i))\n finally (return-from %merge-count count))\n do (if (funcall predicate\n (aref source-vec j)\n (aref source-vec i))\n (setf (aref dest-vec idx) (aref source-vec j)\n j (1+ j)\n count (+ count (- mid i)))\n (setf (aref dest-vec idx) (aref source-vec i)\n i (1+ i)))))\n\n(defmacro with-fixnum+ (form)\n (let ((fixnum+ '(integer 0 #.most-positive-fixnum)))\n `(the ,fixnum+\n ,(reduce (lambda (f1 f2)`(,(car form)\n (the ,fixnum+ ,f1)\n (the ,fixnum+ ,f2)))\n\t (cdr form)))))\n\n(declaim (inline %calc-by-insertion-sort!))\n(defun %calc-by-insertion-sort! (vec predicate l r)\n (declare (function predicate)\n ((integer 0 #.array-total-size-limit) l r))\n (loop with inv-count of-type (integer 0 #.most-positive-fixnum) = 0\n for end from (+ l 1) below r\n do (loop for i from end above l\n while (funcall predicate (aref vec i) (aref vec (- i 1)))\n do (rotatef (aref vec (- i 1)) (aref vec i))\n (incf inv-count))\n finally (return inv-count)))\n\n(declaim (inline calc-inversion-number!))\n(defun calc-inversion-number! (vector predicate &key (start 0) end)\n \"Calculates the inversion number of VECTOR w.r.t. the strict order\nPREDICATE. This function sorts VECTOR as a side effect.\"\n (declare (vector vector)\n (function predicate))\n (let ((end (or end (length vector))))\n (declare ((integer 0 #.array-total-size-limit) start end))\n (assert (<= start end))\n (let ((buffer (make-array (length vector) :element-type (array-element-type vector))))\n (labels\n ((recurse (l r merge-to-vec1-p)\n (declare (optimize (safety 0))\n ((integer 0 #.array-total-size-limit) l r))\n (cond ;; It is faster to use insertion sort. I don't adopt it\n ;; by default, however, because that makes it hard to\n ;; change the code to fit some special settings.\n ((and (<= (- r l) 24) merge-to-vec1-p)\n (%calc-by-insertion-sort! vector predicate l r))\n (t\n (let ((mid (floor (+ l r) 2)))\n (with-fixnum+\n (+ (recurse l mid (not merge-to-vec1-p))\n (recurse mid r (not merge-to-vec1-p))\n (if merge-to-vec1-p\n (%merge-count l mid r buffer vector predicate)\n (%merge-count l mid r vector buffer predicate)))))))))\n (recurse start end t)))))\n\n;; Scheme-style named let\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun feasible-p (as x)\n (declare #.OPT\n ((simple-array uint32 (*)) as)\n (uint32 x))\n (let* ((n (length as))\n (cumul (make-array (+ n 1) :element-type 'int32 :initial-element 0)))\n (dotimes (i n)\n (setf (aref cumul (+ i 1))\n (+ (aref cumul i) (if (>= (aref as i) x) 1 -1))))\n (let ((non-inversion-number (- (ash (* n (+ n 1)) -1)\n (calc-inversion-number! cumul #'<)))\n (threshold (ceiling (* n (+ n 1)) 4)))\n (>= non-inversion-number threshold))))\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint32)))\n (dotimes (i n) (setf (aref as i) (read-fixnum)))\n (nlet bisect ((ok 1) (ng 1000000001))\n (if (<= (- ng ok) 1)\n (println ok)\n (let ((mid (ash (+ ok ng) -1)))\n (if (feasible-p as mid)\n (bisect mid ng)\n (bisect ok mid)))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1560994235, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03275.html", "problem_id": "p03275", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03275/input.txt", "sample_output_relpath": "derived/input_output/data/p03275/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03275/Lisp/s908158252.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s908158252", "user_id": "u352600849"}, "prompt_components": {"gold_output": "30\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; ARRAY-ELEMENT-TYPE is not constant-folded on SBCL version earlier than\n;;; 1.5.0. See\n;;; https://github.com/sbcl/sbcl/commit/9f0d12e7ab961828931d01c0b2a76a5885ad35d2\n;;;\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:deftransform array-element-type ((array))\n (let ((type (sb-c::lvar-type array)))\n (flet ((element-type (type)\n (and (sb-c::array-type-p type)\n (sb-int:neq (sb-kernel::array-type-specialized-element-type type) sb-kernel:*wild-type*)\n (sb-kernel:type-specifier (sb-kernel::array-type-specialized-element-type type)))))\n (cond ((let ((type (element-type type)))\n (and type\n `',type)))\n ((sb-kernel:union-type-p type)\n (let (result)\n (loop for type in (sb-kernel:union-type-types type)\n for et = (element-type type)\n unless (and et\n (if result\n (equal result et)\n (setf result et)))\n do (sb-c::give-up-ir1-transform))\n `',result))\n ((sb-kernel:intersection-type-p type)\n (loop for type in (sb-kernel:intersection-type-types type)\n for et = (element-type type)\n when et\n return `',et\n finally (sb-c::give-up-ir1-transform)))\n (t\n (sb-c::give-up-ir1-transform)))))))\n\n;;;\n;;; Calculate inversion number by merge sort\n;;;\n\n(declaim (inline %merge-count))\n(defun %merge-count (l mid r source-vec dest-vec predicate)\n (declare ((integer 0 #.array-total-size-limit) l mid r)\n (function predicate))\n (loop with count of-type (integer 0 #.most-positive-fixnum) = 0\n with i = l\n with j = mid\n for idx from l\n when (= i mid)\n do (loop for j from j below r\n for idx from idx\n do (setf (aref dest-vec idx)\n (aref source-vec j))\n finally (return-from %merge-count count))\n when (= j r)\n do (loop for i from i below mid\n for idx from idx\n do (setf (aref dest-vec idx)\n (aref source-vec i))\n finally (return-from %merge-count count))\n do (if (funcall predicate\n (aref source-vec j)\n (aref source-vec i))\n (setf (aref dest-vec idx) (aref source-vec j)\n j (1+ j)\n count (+ count (- mid i)))\n (setf (aref dest-vec idx) (aref source-vec i)\n i (1+ i)))))\n\n(defmacro with-fixnum+ (form)\n (let ((fixnum+ '(integer 0 #.most-positive-fixnum)))\n `(the ,fixnum+\n ,(reduce (lambda (f1 f2)`(,(car form)\n (the ,fixnum+ ,f1)\n (the ,fixnum+ ,f2)))\n\t (cdr form)))))\n\n(declaim (inline %calc-by-insertion-sort!))\n(defun %calc-by-insertion-sort! (vec predicate l r)\n (declare (function predicate)\n ((integer 0 #.array-total-size-limit) l r))\n (loop with inv-count of-type (integer 0 #.most-positive-fixnum) = 0\n for end from (+ l 1) below r\n do (loop for i from end above l\n while (funcall predicate (aref vec i) (aref vec (- i 1)))\n do (rotatef (aref vec (- i 1)) (aref vec i))\n (incf inv-count))\n finally (return inv-count)))\n\n(declaim (inline calc-inversion-number!))\n(defun calc-inversion-number! (vector predicate &key (start 0) end)\n \"Calculates the inversion number of VECTOR w.r.t. the strict order\nPREDICATE. This function sorts VECTOR as a side effect.\"\n (declare (vector vector)\n (function predicate))\n (let ((end (or end (length vector))))\n (declare ((integer 0 #.array-total-size-limit) start end))\n (assert (<= start end))\n (let ((buffer (make-array (length vector) :element-type (array-element-type vector))))\n (labels\n ((recurse (l r merge-to-vec1-p)\n (declare (optimize (safety 0))\n ((integer 0 #.array-total-size-limit) l r))\n (cond ;; It is faster to use insertion sort. I don't adopt it\n ;; by default, however, because that makes it hard to\n ;; change the code to fit some special settings.\n ((and (<= (- r l) 24) merge-to-vec1-p)\n (%calc-by-insertion-sort! vector predicate l r))\n (t\n (let ((mid (floor (+ l r) 2)))\n (with-fixnum+\n (+ (recurse l mid (not merge-to-vec1-p))\n (recurse mid r (not merge-to-vec1-p))\n (if merge-to-vec1-p\n (%merge-count l mid r buffer vector predicate)\n (%merge-count l mid r vector buffer predicate)))))))))\n (recurse start end t)))))\n\n;; Scheme-style named let\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun feasible-p (as x)\n (declare #.OPT\n ((simple-array uint32 (*)) as)\n (uint32 x))\n (let* ((n (length as))\n (cumul (make-array (+ n 1) :element-type 'int32 :initial-element 0)))\n (dotimes (i n)\n (setf (aref cumul (+ i 1))\n (+ (aref cumul i) (if (>= (aref as i) x) 1 -1))))\n (let ((non-inversion-number (- (ash (* n (+ n 1)) -1)\n (calc-inversion-number! cumul #'<)))\n (threshold (ceiling (* n (+ n 1)) 4)))\n (>= non-inversion-number threshold))))\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint32)))\n (dotimes (i n) (setf (aref as i) (read-fixnum)))\n (nlet bisect ((ok 1) (ng 1000000001))\n (if (<= (- ng ok) 1)\n (println ok)\n (let ((mid (ash (+ ok ng) -1)))\n (if (feasible-p as mid)\n (bisect mid ng)\n (bisect ok mid)))))))\n\n#-swank(main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nWe will define the median of a sequence b of length M, as follows:\n\nLet b' be the sequence obtained by sorting b in non-decreasing order. Then, the value of the (M / 2 + 1)-th element of b' is the median of b. Here, / is integer division, rounding down.\n\nFor example, the median of (10, 30, 20) is 20; the median of (10, 30, 20, 40) is 30; the median of (10, 10, 10, 20, 30) is 10.\n\nSnuke comes up with the following problem.\n\nYou are given a sequence a of length N.\nFor each pair (l, r) (1 \\leq l \\leq r \\leq N), let m_{l, r} be the median of the contiguous subsequence (a_l, a_{l + 1}, ..., a_r) of a.\nWe will list m_{l, r} for all pairs (l, r) to create a new sequence m.\nFind the median of m.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\na_i is an integer.\n\n1 \\leq a_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the median of m.\n\nSample Input 1\n\n3\n10 30 20\n\nSample Output 1\n\n30\n\nThe median of each contiguous subsequence of a is as follows:\n\nThe median of (10) is 10.\n\nThe median of (30) is 30.\n\nThe median of (20) is 20.\n\nThe median of (10, 30) is 30.\n\nThe median of (30, 20) is 30.\n\nThe median of (10, 30, 20) is 20.\n\nThus, m = (10, 30, 20, 30, 30, 20) and the median of m is 30.\n\nSample Input 2\n\n1\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n10\n5 9 5 9 8 9 3 5 4 3\n\nSample Output 3\n\n8", "sample_input": "3\n10 30 20\n"}, "reference_outputs": ["30\n"], "source_document_id": "p03275", "source_text": "Score : 700 points\n\nProblem Statement\n\nWe will define the median of a sequence b of length M, as follows:\n\nLet b' be the sequence obtained by sorting b in non-decreasing order. Then, the value of the (M / 2 + 1)-th element of b' is the median of b. Here, / is integer division, rounding down.\n\nFor example, the median of (10, 30, 20) is 20; the median of (10, 30, 20, 40) is 30; the median of (10, 10, 10, 20, 30) is 10.\n\nSnuke comes up with the following problem.\n\nYou are given a sequence a of length N.\nFor each pair (l, r) (1 \\leq l \\leq r \\leq N), let m_{l, r} be the median of the contiguous subsequence (a_l, a_{l + 1}, ..., a_r) of a.\nWe will list m_{l, r} for all pairs (l, r) to create a new sequence m.\nFind the median of m.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\na_i is an integer.\n\n1 \\leq a_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the median of m.\n\nSample Input 1\n\n3\n10 30 20\n\nSample Output 1\n\n30\n\nThe median of each contiguous subsequence of a is as follows:\n\nThe median of (10) is 10.\n\nThe median of (30) is 30.\n\nThe median of (20) is 20.\n\nThe median of (10, 30) is 30.\n\nThe median of (30, 20) is 30.\n\nThe median of (10, 30, 20) is 20.\n\nThus, m = (10, 30, 20, 30, 30, 20) and the median of m is 30.\n\nSample Input 2\n\n1\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n10\n5 9 5 9 8 9 3 5 4 3\n\nSample Output 3\n\n8", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8759, "cpu_time_ms": 304, "memory_kb": 53736}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s928913395", "group_id": "codeNet:p03275", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; 1-dimensional binary indexed tree\n;;;\n\n;; TODO: multidimensional BIT\n\n(defmacro define-bitree (name &key (operator '#'+) (identity 0) sum-type (order '#'>))\n \"OPERATOR := binary operator (on a commutative monoid)\nIDENTITY := object (identity element of the monoid)\nORDER := nil | strict comparison operator on the monoid\nSUM-TYPE := nil | type specifier\n\nDefines no structure; BIT is just a vector. This macro defines the three\nfunction: -UPDATE!, -SUM and COERCE-TO-!. If ORDER is\nspecified, this macro defines the bisection function -BISECT-LEFT in\naddition. (Note that the -BISECT-LEFT function works only when the sequence of\nprefix sums (VECTOR[0], VECTOR[0]+VECTOR[1], ...) is monotonous.)\n\nSUM-TYPE is used only for the type declaration: each sum\nVECTOR[i]+VECTOR[i+1]...+VECTOR[i+k] is declared to be this type. (The\nelement-type of vector itself doesn't need to be SUM-TYPE.)\"\n (let* ((name (string name))\n (fname-update (intern (format nil \"~A-UPDATE!\" name)))\n (fname-sum (intern (format nil \"~A-SUM\" name)))\n (fname-coerce (intern (format nil \"COERCE-TO-~A!\" name)))\n (fname-bisect-left (intern (format nil \"~A-BISECT-LEFT\" name)))\n (fname-bisect-right (intern (format nil \"~A-BISECT-RIGHT\" name))))\n `(progn\n (declaim (inline ,fname-update))\n (defun ,fname-update (bitree index delta)\n \"Destructively increments the vector: vector[INDEX] = vector[INDEX] +\nDELTA\"\n (let ((len (length bitree)))\n (do ((i index (logior i (+ i 1))))\n ((>= i len) bitree)\n (declare ((integer 0 #.most-positive-fixnum) i))\n (setf (aref bitree i)\n (funcall ,operator (aref bitree i) delta)))))\n\n (declaim (inline ,fname-sum))\n (defun ,fname-sum (bitree end)\n \"Returns the sum of the prefix: vector[0] + ... + vector[END-1].\"\n (declare ((integer 0 #.most-positive-fixnum) end))\n (let ((res ,identity))\n ,@(when sum-type `((declare (type ,sum-type res))))\n (do ((i (- end 1) (- (logand i (+ i 1)) 1)))\n ((< i 0) res)\n (declare ((integer -1 #.most-positive-fixnum) i))\n (setf res (funcall ,operator res (aref bitree i))))))\n\n (declaim (inline ,fname-coerce))\n (defun ,fname-coerce (vector)\n \"Destructively constructs BIT from VECTOR.\"\n (loop with len = (length vector)\n for i below len\n for dest-i = (logior i (+ i 1))\n when (< dest-i len)\n do (setf (aref vector dest-i)\n (funcall ,operator (aref vector dest-i) (aref vector i)))\n finally (return vector)))\n\n ,@(when order\n `((declaim (inline ,fname-bisect-left))\n (defun ,fname-bisect-left (bitree value)\n \"Returns the smallest index that fulfills VECTOR[0]+ ... +\nVECTOR[index] >= VALUE. Returns the length of VECTOR if VECTOR[0]+\n... +VECTOR[length-1] < VALUE.\"\n (declare (vector bitree))\n (if (not (funcall ,order value ,identity))\n 0\n (let ((len (length bitree))\n (index+1 0)\n (cumul ,identity))\n (declare ((integer 0 #.most-positive-fixnum) index+1)\n ,@(when sum-type\n `((type ,sum-type cumul))))\n (do ((delta (ash 1 (- (integer-length len) 1))\n (ash delta -1)))\n ((zerop delta) index+1)\n (declare ((integer 0 #.most-positive-fixnum) delta))\n (let ((next-index (+ index+1 delta -1)))\n (when (< next-index len)\n (let ((next-cumul (funcall ,operator cumul (aref bitree next-index))))\n ,@(when sum-type\n `((declare (type ,sum-type next-cumul))))\n (when (funcall ,order value next-cumul)\n (setf cumul next-cumul)\n (incf index+1 delta)))))))))\n (declaim (inline ,fname-bisect-right))\n (defun ,fname-bisect-right (bitree value)\n \"Returns the smallest index that fulfills VECTOR[0]+ ... +\nVECTOR[index] > VALUE. Returns the length of VECTOR if VECTOR[0]+\n... +VECTOR[length-1] <= VALUE.\"\n (declare (vector bitree))\n (if (funcall ,order ,identity value)\n 0\n (let ((len (length bitree))\n (index+1 0)\n (cumul ,identity))\n (declare ((integer 0 #.most-positive-fixnum) index+1)\n ,@(when sum-type\n `((type ,sum-type cumul))))\n (do ((delta (ash 1 (- (integer-length len) 1))\n (ash delta -1)))\n ((zerop delta) index+1)\n (declare ((integer 0 #.most-positive-fixnum) delta))\n (let ((next-index (+ index+1 delta -1)))\n (when (< next-index len)\n (let ((next-cumul (funcall ,operator cumul (aref bitree next-index))))\n ,@(when sum-type\n `((declare (type ,sum-type next-cumul))))\n (unless (funcall ,order next-cumul value)\n (setf cumul next-cumul)\n (incf index+1 delta))))))))))))))\n\n(define-bitree bitree\n :operator #'+\n :identity 0\n :sum-type fixnum)\n\n;; Scheme-style named let\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun feasible-p (as x)\n (declare ((simple-array uint32 (*)) as)\n (uint32 x))\n (let* ((n (length as))\n (cumul (make-array (+ n 1) :element-type 'int32 :initial-element 0))\n (dp (make-array 200001 :element-type 'uint32 :initial-element 0))\n (res 0)\n (threshold (ceiling (* n (+ n 1)) 4)))\n (declare (fixnum res threshold))\n (dotimes (i n)\n (setf (aref cumul (+ i 1))\n (+ (aref cumul i) (if (>= (aref as i) x) 1 -1))))\n (loop for r from 0 to n\n for sr = (aref cumul r)\n do (incf res (bitree-sum dp (+ 100001 sr)))\n (bitree-update! dp (+ 100000 sr) 1))\n (>= res threshold)))\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint32)))\n (dotimes (i n) (setf (aref as i) (read-fixnum)))\n (nlet bisect ((ok 1) (ng 1000000001))\n (if (<= (- ng ok) 1)\n (println ok)\n (let ((mid (ash (+ ok ng) -1)))\n (if (feasible-p as mid)\n (bisect mid ng)\n (bisect ok mid)))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1560992786, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03275.html", "problem_id": "p03275", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03275/input.txt", "sample_output_relpath": "derived/input_output/data/p03275/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03275/Lisp/s928913395.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s928913395", "user_id": "u352600849"}, "prompt_components": {"gold_output": "30\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; 1-dimensional binary indexed tree\n;;;\n\n;; TODO: multidimensional BIT\n\n(defmacro define-bitree (name &key (operator '#'+) (identity 0) sum-type (order '#'>))\n \"OPERATOR := binary operator (on a commutative monoid)\nIDENTITY := object (identity element of the monoid)\nORDER := nil | strict comparison operator on the monoid\nSUM-TYPE := nil | type specifier\n\nDefines no structure; BIT is just a vector. This macro defines the three\nfunction: -UPDATE!, -SUM and COERCE-TO-!. If ORDER is\nspecified, this macro defines the bisection function -BISECT-LEFT in\naddition. (Note that the -BISECT-LEFT function works only when the sequence of\nprefix sums (VECTOR[0], VECTOR[0]+VECTOR[1], ...) is monotonous.)\n\nSUM-TYPE is used only for the type declaration: each sum\nVECTOR[i]+VECTOR[i+1]...+VECTOR[i+k] is declared to be this type. (The\nelement-type of vector itself doesn't need to be SUM-TYPE.)\"\n (let* ((name (string name))\n (fname-update (intern (format nil \"~A-UPDATE!\" name)))\n (fname-sum (intern (format nil \"~A-SUM\" name)))\n (fname-coerce (intern (format nil \"COERCE-TO-~A!\" name)))\n (fname-bisect-left (intern (format nil \"~A-BISECT-LEFT\" name)))\n (fname-bisect-right (intern (format nil \"~A-BISECT-RIGHT\" name))))\n `(progn\n (declaim (inline ,fname-update))\n (defun ,fname-update (bitree index delta)\n \"Destructively increments the vector: vector[INDEX] = vector[INDEX] +\nDELTA\"\n (let ((len (length bitree)))\n (do ((i index (logior i (+ i 1))))\n ((>= i len) bitree)\n (declare ((integer 0 #.most-positive-fixnum) i))\n (setf (aref bitree i)\n (funcall ,operator (aref bitree i) delta)))))\n\n (declaim (inline ,fname-sum))\n (defun ,fname-sum (bitree end)\n \"Returns the sum of the prefix: vector[0] + ... + vector[END-1].\"\n (declare ((integer 0 #.most-positive-fixnum) end))\n (let ((res ,identity))\n ,@(when sum-type `((declare (type ,sum-type res))))\n (do ((i (- end 1) (- (logand i (+ i 1)) 1)))\n ((< i 0) res)\n (declare ((integer -1 #.most-positive-fixnum) i))\n (setf res (funcall ,operator res (aref bitree i))))))\n\n (declaim (inline ,fname-coerce))\n (defun ,fname-coerce (vector)\n \"Destructively constructs BIT from VECTOR.\"\n (loop with len = (length vector)\n for i below len\n for dest-i = (logior i (+ i 1))\n when (< dest-i len)\n do (setf (aref vector dest-i)\n (funcall ,operator (aref vector dest-i) (aref vector i)))\n finally (return vector)))\n\n ,@(when order\n `((declaim (inline ,fname-bisect-left))\n (defun ,fname-bisect-left (bitree value)\n \"Returns the smallest index that fulfills VECTOR[0]+ ... +\nVECTOR[index] >= VALUE. Returns the length of VECTOR if VECTOR[0]+\n... +VECTOR[length-1] < VALUE.\"\n (declare (vector bitree))\n (if (not (funcall ,order value ,identity))\n 0\n (let ((len (length bitree))\n (index+1 0)\n (cumul ,identity))\n (declare ((integer 0 #.most-positive-fixnum) index+1)\n ,@(when sum-type\n `((type ,sum-type cumul))))\n (do ((delta (ash 1 (- (integer-length len) 1))\n (ash delta -1)))\n ((zerop delta) index+1)\n (declare ((integer 0 #.most-positive-fixnum) delta))\n (let ((next-index (+ index+1 delta -1)))\n (when (< next-index len)\n (let ((next-cumul (funcall ,operator cumul (aref bitree next-index))))\n ,@(when sum-type\n `((declare (type ,sum-type next-cumul))))\n (when (funcall ,order value next-cumul)\n (setf cumul next-cumul)\n (incf index+1 delta)))))))))\n (declaim (inline ,fname-bisect-right))\n (defun ,fname-bisect-right (bitree value)\n \"Returns the smallest index that fulfills VECTOR[0]+ ... +\nVECTOR[index] > VALUE. Returns the length of VECTOR if VECTOR[0]+\n... +VECTOR[length-1] <= VALUE.\"\n (declare (vector bitree))\n (if (funcall ,order ,identity value)\n 0\n (let ((len (length bitree))\n (index+1 0)\n (cumul ,identity))\n (declare ((integer 0 #.most-positive-fixnum) index+1)\n ,@(when sum-type\n `((type ,sum-type cumul))))\n (do ((delta (ash 1 (- (integer-length len) 1))\n (ash delta -1)))\n ((zerop delta) index+1)\n (declare ((integer 0 #.most-positive-fixnum) delta))\n (let ((next-index (+ index+1 delta -1)))\n (when (< next-index len)\n (let ((next-cumul (funcall ,operator cumul (aref bitree next-index))))\n ,@(when sum-type\n `((declare (type ,sum-type next-cumul))))\n (unless (funcall ,order next-cumul value)\n (setf cumul next-cumul)\n (incf index+1 delta))))))))))))))\n\n(define-bitree bitree\n :operator #'+\n :identity 0\n :sum-type fixnum)\n\n;; Scheme-style named let\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun feasible-p (as x)\n (declare ((simple-array uint32 (*)) as)\n (uint32 x))\n (let* ((n (length as))\n (cumul (make-array (+ n 1) :element-type 'int32 :initial-element 0))\n (dp (make-array 200001 :element-type 'uint32 :initial-element 0))\n (res 0)\n (threshold (ceiling (* n (+ n 1)) 4)))\n (declare (fixnum res threshold))\n (dotimes (i n)\n (setf (aref cumul (+ i 1))\n (+ (aref cumul i) (if (>= (aref as i) x) 1 -1))))\n (loop for r from 0 to n\n for sr = (aref cumul r)\n do (incf res (bitree-sum dp (+ 100001 sr)))\n (bitree-update! dp (+ 100000 sr) 1))\n (>= res threshold)))\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint32)))\n (dotimes (i n) (setf (aref as i) (read-fixnum)))\n (nlet bisect ((ok 1) (ng 1000000001))\n (if (<= (- ng ok) 1)\n (println ok)\n (let ((mid (ash (+ ok ng) -1)))\n (if (feasible-p as mid)\n (bisect mid ng)\n (bisect ok mid)))))))\n\n#-swank(main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nWe will define the median of a sequence b of length M, as follows:\n\nLet b' be the sequence obtained by sorting b in non-decreasing order. Then, the value of the (M / 2 + 1)-th element of b' is the median of b. Here, / is integer division, rounding down.\n\nFor example, the median of (10, 30, 20) is 20; the median of (10, 30, 20, 40) is 30; the median of (10, 10, 10, 20, 30) is 10.\n\nSnuke comes up with the following problem.\n\nYou are given a sequence a of length N.\nFor each pair (l, r) (1 \\leq l \\leq r \\leq N), let m_{l, r} be the median of the contiguous subsequence (a_l, a_{l + 1}, ..., a_r) of a.\nWe will list m_{l, r} for all pairs (l, r) to create a new sequence m.\nFind the median of m.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\na_i is an integer.\n\n1 \\leq a_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the median of m.\n\nSample Input 1\n\n3\n10 30 20\n\nSample Output 1\n\n30\n\nThe median of each contiguous subsequence of a is as follows:\n\nThe median of (10) is 10.\n\nThe median of (30) is 30.\n\nThe median of (20) is 20.\n\nThe median of (10, 30) is 30.\n\nThe median of (30, 20) is 30.\n\nThe median of (10, 30, 20) is 20.\n\nThus, m = (10, 30, 20, 30, 30, 20) and the median of m is 30.\n\nSample Input 2\n\n1\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n10\n5 9 5 9 8 9 3 5 4 3\n\nSample Output 3\n\n8", "sample_input": "3\n10 30 20\n"}, "reference_outputs": ["30\n"], "source_document_id": "p03275", "source_text": "Score : 700 points\n\nProblem Statement\n\nWe will define the median of a sequence b of length M, as follows:\n\nLet b' be the sequence obtained by sorting b in non-decreasing order. Then, the value of the (M / 2 + 1)-th element of b' is the median of b. Here, / is integer division, rounding down.\n\nFor example, the median of (10, 30, 20) is 20; the median of (10, 30, 20, 40) is 30; the median of (10, 10, 10, 20, 30) is 10.\n\nSnuke comes up with the following problem.\n\nYou are given a sequence a of length N.\nFor each pair (l, r) (1 \\leq l \\leq r \\leq N), let m_{l, r} be the median of the contiguous subsequence (a_l, a_{l + 1}, ..., a_r) of a.\nWe will list m_{l, r} for all pairs (l, r) to create a new sequence m.\nFind the median of m.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\na_i is an integer.\n\n1 \\leq a_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the median of m.\n\nSample Input 1\n\n3\n10 30 20\n\nSample Output 1\n\n30\n\nThe median of each contiguous subsequence of a is as follows:\n\nThe median of (10) is 10.\n\nThe median of (30) is 30.\n\nThe median of (20) is 20.\n\nThe median of (10, 30) is 30.\n\nThe median of (30, 20) is 30.\n\nThe median of (10, 30, 20) is 20.\n\nThus, m = (10, 30, 20, 30, 30, 20) and the median of m is 30.\n\nSample Input 2\n\n1\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n10\n5 9 5 9 8 9 3 5 4 3\n\nSample Output 3\n\n8", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9484, "cpu_time_ms": 301, "memory_kb": 62052}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s325325950", "group_id": "codeNet:p03275", "input_text": "(defvar *N* (read))\n\n(defvar *array* (make-array *N*))\n(defun set-array ()\n (dotimes (i *N*)\n (let ((x (read)))\n (setf (aref *array* i) x))))\n\n(defun get-median (l)\n (let* ((size (length l))\n (check (round (/ (float size) 2))))\n (cond ((evenp size)\n (nth check l))\n ((= size 1)\n (nth 0 l))\n (t\n (nth (- check 1) l)))))\n\n(defun main ()\n (set-array)\n (let ((result (reverse (coerce *array* 'list)))\n (array-size (- *N* 1)))\n (dotimes (n *N*)\n (let ((right (+ n 1)))\n (if (/= n array-size)\n (progn\n (let* ((tmp (list (aref *array* n) (aref *array* right)))\n (sorted (sort tmp #'<)))\n (push (cadr sorted) result)))\n (push (get-median (sort (coerce *array* 'list) #'<)) result))))\n (setq result (sort (reverse result) #'<))\n (format t \"~A~%\" (get-median result))))\n\n\n(main)", "language": "Lisp", "metadata": {"date": 1535313219, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03275.html", "problem_id": "p03275", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03275/input.txt", "sample_output_relpath": "derived/input_output/data/p03275/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03275/Lisp/s325325950.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s325325950", "user_id": "u631655863"}, "prompt_components": {"gold_output": "30\n", "input_to_evaluate": "(defvar *N* (read))\n\n(defvar *array* (make-array *N*))\n(defun set-array ()\n (dotimes (i *N*)\n (let ((x (read)))\n (setf (aref *array* i) x))))\n\n(defun get-median (l)\n (let* ((size (length l))\n (check (round (/ (float size) 2))))\n (cond ((evenp size)\n (nth check l))\n ((= size 1)\n (nth 0 l))\n (t\n (nth (- check 1) l)))))\n\n(defun main ()\n (set-array)\n (let ((result (reverse (coerce *array* 'list)))\n (array-size (- *N* 1)))\n (dotimes (n *N*)\n (let ((right (+ n 1)))\n (if (/= n array-size)\n (progn\n (let* ((tmp (list (aref *array* n) (aref *array* right)))\n (sorted (sort tmp #'<)))\n (push (cadr sorted) result)))\n (push (get-median (sort (coerce *array* 'list) #'<)) result))))\n (setq result (sort (reverse result) #'<))\n (format t \"~A~%\" (get-median result))))\n\n\n(main)", "problem_context": "Score : 700 points\n\nProblem Statement\n\nWe will define the median of a sequence b of length M, as follows:\n\nLet b' be the sequence obtained by sorting b in non-decreasing order. Then, the value of the (M / 2 + 1)-th element of b' is the median of b. Here, / is integer division, rounding down.\n\nFor example, the median of (10, 30, 20) is 20; the median of (10, 30, 20, 40) is 30; the median of (10, 10, 10, 20, 30) is 10.\n\nSnuke comes up with the following problem.\n\nYou are given a sequence a of length N.\nFor each pair (l, r) (1 \\leq l \\leq r \\leq N), let m_{l, r} be the median of the contiguous subsequence (a_l, a_{l + 1}, ..., a_r) of a.\nWe will list m_{l, r} for all pairs (l, r) to create a new sequence m.\nFind the median of m.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\na_i is an integer.\n\n1 \\leq a_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the median of m.\n\nSample Input 1\n\n3\n10 30 20\n\nSample Output 1\n\n30\n\nThe median of each contiguous subsequence of a is as follows:\n\nThe median of (10) is 10.\n\nThe median of (30) is 30.\n\nThe median of (20) is 20.\n\nThe median of (10, 30) is 30.\n\nThe median of (30, 20) is 30.\n\nThe median of (10, 30, 20) is 20.\n\nThus, m = (10, 30, 20, 30, 30, 20) and the median of m is 30.\n\nSample Input 2\n\n1\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n10\n5 9 5 9 8 9 3 5 4 3\n\nSample Output 3\n\n8", "sample_input": "3\n10 30 20\n"}, "reference_outputs": ["30\n"], "source_document_id": "p03275", "source_text": "Score : 700 points\n\nProblem Statement\n\nWe will define the median of a sequence b of length M, as follows:\n\nLet b' be the sequence obtained by sorting b in non-decreasing order. Then, the value of the (M / 2 + 1)-th element of b' is the median of b. Here, / is integer division, rounding down.\n\nFor example, the median of (10, 30, 20) is 20; the median of (10, 30, 20, 40) is 30; the median of (10, 10, 10, 20, 30) is 10.\n\nSnuke comes up with the following problem.\n\nYou are given a sequence a of length N.\nFor each pair (l, r) (1 \\leq l \\leq r \\leq N), let m_{l, r} be the median of the contiguous subsequence (a_l, a_{l + 1}, ..., a_r) of a.\nWe will list m_{l, r} for all pairs (l, r) to create a new sequence m.\nFind the median of m.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\na_i is an integer.\n\n1 \\leq a_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the median of m.\n\nSample Input 1\n\n3\n10 30 20\n\nSample Output 1\n\n30\n\nThe median of each contiguous subsequence of a is as follows:\n\nThe median of (10) is 10.\n\nThe median of (30) is 30.\n\nThe median of (20) is 20.\n\nThe median of (10, 30) is 30.\n\nThe median of (30, 20) is 30.\n\nThe median of (10, 30, 20) is 20.\n\nThus, m = (10, 30, 20, 30, 30, 20) and the median of m is 30.\n\nSample Input 2\n\n1\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n10\n5 9 5 9 8 9 3 5 4 3\n\nSample Output 3\n\n8", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 938, "cpu_time_ms": 388, "memory_kb": 59752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s625105988", "group_id": "codeNet:p03275", "input_text": "(defvar *N* (read))\n\n(defun split-string (s d)\n (let ((l (concatenate 'list s))\n (r (list nil))\n (tmp (list nil)))\n (dolist (n l)\n (if (eql n d)\n (progn\n (push (parse-integer (concatenate 'string (cdr (reverse tmp)))) r)\n (setq tmp (list nil)))\n (push n tmp)))\n (let ((check (parse-integer (concatenate 'string (cdr (reverse tmp))) :junk-allowed t)))\n (unless (null check)\n (push check r)))\n (cdr (reverse r))))\n\n(defun main ()\n (let ((tmp (read-line)))\n (let* ((l (split-string tmp #\\Space))\n (check (round (/ (float (length l)) 2))))\n (if (= check 0)\n (format t \"~a~%\" (nth check l))\n (if (/= (mod check 2) 0)\n (format t \"~a~%\" (nth (- check 1) l))\n (progn\n (let ((x (/ (+ (nth (- check 1) l) (nth check l)) 2)))\n (format t \"~a~%\" x))))))))\n\n(main)", "language": "Lisp", "metadata": {"date": 1535250287, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03275.html", "problem_id": "p03275", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03275/input.txt", "sample_output_relpath": "derived/input_output/data/p03275/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03275/Lisp/s625105988.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s625105988", "user_id": "u631655863"}, "prompt_components": {"gold_output": "30\n", "input_to_evaluate": "(defvar *N* (read))\n\n(defun split-string (s d)\n (let ((l (concatenate 'list s))\n (r (list nil))\n (tmp (list nil)))\n (dolist (n l)\n (if (eql n d)\n (progn\n (push (parse-integer (concatenate 'string (cdr (reverse tmp)))) r)\n (setq tmp (list nil)))\n (push n tmp)))\n (let ((check (parse-integer (concatenate 'string (cdr (reverse tmp))) :junk-allowed t)))\n (unless (null check)\n (push check r)))\n (cdr (reverse r))))\n\n(defun main ()\n (let ((tmp (read-line)))\n (let* ((l (split-string tmp #\\Space))\n (check (round (/ (float (length l)) 2))))\n (if (= check 0)\n (format t \"~a~%\" (nth check l))\n (if (/= (mod check 2) 0)\n (format t \"~a~%\" (nth (- check 1) l))\n (progn\n (let ((x (/ (+ (nth (- check 1) l) (nth check l)) 2)))\n (format t \"~a~%\" x))))))))\n\n(main)", "problem_context": "Score : 700 points\n\nProblem Statement\n\nWe will define the median of a sequence b of length M, as follows:\n\nLet b' be the sequence obtained by sorting b in non-decreasing order. Then, the value of the (M / 2 + 1)-th element of b' is the median of b. Here, / is integer division, rounding down.\n\nFor example, the median of (10, 30, 20) is 20; the median of (10, 30, 20, 40) is 30; the median of (10, 10, 10, 20, 30) is 10.\n\nSnuke comes up with the following problem.\n\nYou are given a sequence a of length N.\nFor each pair (l, r) (1 \\leq l \\leq r \\leq N), let m_{l, r} be the median of the contiguous subsequence (a_l, a_{l + 1}, ..., a_r) of a.\nWe will list m_{l, r} for all pairs (l, r) to create a new sequence m.\nFind the median of m.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\na_i is an integer.\n\n1 \\leq a_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the median of m.\n\nSample Input 1\n\n3\n10 30 20\n\nSample Output 1\n\n30\n\nThe median of each contiguous subsequence of a is as follows:\n\nThe median of (10) is 10.\n\nThe median of (30) is 30.\n\nThe median of (20) is 20.\n\nThe median of (10, 30) is 30.\n\nThe median of (30, 20) is 30.\n\nThe median of (10, 30, 20) is 20.\n\nThus, m = (10, 30, 20, 30, 30, 20) and the median of m is 30.\n\nSample Input 2\n\n1\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n10\n5 9 5 9 8 9 3 5 4 3\n\nSample Output 3\n\n8", "sample_input": "3\n10 30 20\n"}, "reference_outputs": ["30\n"], "source_document_id": "p03275", "source_text": "Score : 700 points\n\nProblem Statement\n\nWe will define the median of a sequence b of length M, as follows:\n\nLet b' be the sequence obtained by sorting b in non-decreasing order. Then, the value of the (M / 2 + 1)-th element of b' is the median of b. Here, / is integer division, rounding down.\n\nFor example, the median of (10, 30, 20) is 20; the median of (10, 30, 20, 40) is 30; the median of (10, 10, 10, 20, 30) is 10.\n\nSnuke comes up with the following problem.\n\nYou are given a sequence a of length N.\nFor each pair (l, r) (1 \\leq l \\leq r \\leq N), let m_{l, r} be the median of the contiguous subsequence (a_l, a_{l + 1}, ..., a_r) of a.\nWe will list m_{l, r} for all pairs (l, r) to create a new sequence m.\nFind the median of m.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\na_i is an integer.\n\n1 \\leq a_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the median of m.\n\nSample Input 1\n\n3\n10 30 20\n\nSample Output 1\n\n30\n\nThe median of each contiguous subsequence of a is as follows:\n\nThe median of (10) is 10.\n\nThe median of (30) is 30.\n\nThe median of (20) is 20.\n\nThe median of (10, 30) is 30.\n\nThe median of (30, 20) is 30.\n\nThe median of (10, 30, 20) is 20.\n\nThus, m = (10, 30, 20, 30, 30, 20) and the median of m is 30.\n\nSample Input 2\n\n1\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n10\n5 9 5 9 8 9 3 5 4 3\n\nSample Output 3\n\n8", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 926, "cpu_time_ms": 382, "memory_kb": 66016}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s150279564", "group_id": "codeNet:p03281", "input_text": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/divisor\n (:use :cl)\n (:export #:enum-divisors #:enum-ascending-divisors #:make-divisors-table))\n(in-package :cp/divisor)\n\n(declaim (ftype (function * (values (vector (integer 0 #.most-positive-fixnum)) &optional))\n enum-divisors))\n(defun enum-divisors (x)\n \"Enumerates all the divisors of X in O(sqrt(X)) time. Note that the resultant\nvector is NOT sorted.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) x))\n (let* ((sqrt (isqrt x))\n (result (make-array (isqrt sqrt) ; FIXME: currently set the initial size to x^1/4\n :element-type '(integer 0 #.most-positive-fixnum)\n :fill-pointer 0)))\n (loop for i from 1 to sqrt\n do (multiple-value-bind (quot rem) (floor x i)\n (when (zerop rem)\n (vector-push-extend i result)\n (unless (= i quot)\n (vector-push-extend quot result)))))\n result))\n\n;; Below is a variant that returns a sorted list.\n(defun enum-ascending-divisors (n)\n \"Returns the ascending list of all the divisors of N.\"\n (declare (optimize (speed 3))\n ((integer 1 #.most-positive-fixnum) n))\n (if (= n 1)\n (list 1)\n (let* ((sqrt (isqrt n))\n (result (list 1)))\n (labels ((%enum (i first-half second-half)\n (declare ((integer 1 #.most-positive-fixnum) i))\n (cond ((or (< i sqrt)\n (and (= i sqrt) (/= (* sqrt sqrt) n)))\n (multiple-value-bind (quot rem) (floor n i)\n (if (zerop rem)\n (progn\n (setf (cdr first-half) (list i))\n (setf second-half (cons quot second-half))\n (%enum (1+ i) (cdr first-half) second-half))\n (%enum (1+ i) first-half second-half))))\n ((= i sqrt) ; N is a square number here\n (setf (cdr first-half) (cons i second-half)))\n (t ; (> i sqrt)\n (setf (cdr first-half) second-half)))))\n (%enum 2 result (list n))\n result))))\n\n(declaim (ftype (function * (values (simple-array list (*)) &optional))\n make-divisors-table))\n(defun make-divisors-table (sup)\n \"Returns a vector of length SUP whose each cell, vector[X], is the ascending\nlist of every divisor of X. Note that vector[0] = NIL.\"\n (declare ((integer 0 #.most-positive-fixnum) sup)\n #+sbcl (sb-ext:muffle-conditions style-warning))\n (let ((result (make-array sup :element-type 'list))\n (tails (make-array sup :element-type 'list))) ; stores the last cons cell\n (declare (optimize (speed 3) (safety 0)))\n (loop for i from 1 below sup\n for cell = (list 1)\n do (setf (aref result i) cell\n (aref tails i) cell))\n (when (>= sup 1)\n (setf (aref result 0) nil))\n (loop for divisor from 2 below sup\n do (loop for number from divisor below sup by divisor\n do (setf (cdr (aref tails number)) (list divisor)\n (aref tails number) (cdr (aref tails number)))))\n result))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/divisor :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (table (make-divisors-table (+ n 1))))\n (println (loop for i from 1 to n by 2\n count (= (length (aref table i)) 8)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (5am:is\n (equal \"1\n\"\n (run \"105\n\" nil)))\n (5am:is\n (equal \"0\n\"\n (run \"7\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1600761265, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03281.html", "problem_id": "p03281", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03281/input.txt", "sample_output_relpath": "derived/input_output/data/p03281/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03281/Lisp/s150279564.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s150279564", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/divisor\n (:use :cl)\n (:export #:enum-divisors #:enum-ascending-divisors #:make-divisors-table))\n(in-package :cp/divisor)\n\n(declaim (ftype (function * (values (vector (integer 0 #.most-positive-fixnum)) &optional))\n enum-divisors))\n(defun enum-divisors (x)\n \"Enumerates all the divisors of X in O(sqrt(X)) time. Note that the resultant\nvector is NOT sorted.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) x))\n (let* ((sqrt (isqrt x))\n (result (make-array (isqrt sqrt) ; FIXME: currently set the initial size to x^1/4\n :element-type '(integer 0 #.most-positive-fixnum)\n :fill-pointer 0)))\n (loop for i from 1 to sqrt\n do (multiple-value-bind (quot rem) (floor x i)\n (when (zerop rem)\n (vector-push-extend i result)\n (unless (= i quot)\n (vector-push-extend quot result)))))\n result))\n\n;; Below is a variant that returns a sorted list.\n(defun enum-ascending-divisors (n)\n \"Returns the ascending list of all the divisors of N.\"\n (declare (optimize (speed 3))\n ((integer 1 #.most-positive-fixnum) n))\n (if (= n 1)\n (list 1)\n (let* ((sqrt (isqrt n))\n (result (list 1)))\n (labels ((%enum (i first-half second-half)\n (declare ((integer 1 #.most-positive-fixnum) i))\n (cond ((or (< i sqrt)\n (and (= i sqrt) (/= (* sqrt sqrt) n)))\n (multiple-value-bind (quot rem) (floor n i)\n (if (zerop rem)\n (progn\n (setf (cdr first-half) (list i))\n (setf second-half (cons quot second-half))\n (%enum (1+ i) (cdr first-half) second-half))\n (%enum (1+ i) first-half second-half))))\n ((= i sqrt) ; N is a square number here\n (setf (cdr first-half) (cons i second-half)))\n (t ; (> i sqrt)\n (setf (cdr first-half) second-half)))))\n (%enum 2 result (list n))\n result))))\n\n(declaim (ftype (function * (values (simple-array list (*)) &optional))\n make-divisors-table))\n(defun make-divisors-table (sup)\n \"Returns a vector of length SUP whose each cell, vector[X], is the ascending\nlist of every divisor of X. Note that vector[0] = NIL.\"\n (declare ((integer 0 #.most-positive-fixnum) sup)\n #+sbcl (sb-ext:muffle-conditions style-warning))\n (let ((result (make-array sup :element-type 'list))\n (tails (make-array sup :element-type 'list))) ; stores the last cons cell\n (declare (optimize (speed 3) (safety 0)))\n (loop for i from 1 below sup\n for cell = (list 1)\n do (setf (aref result i) cell\n (aref tails i) cell))\n (when (>= sup 1)\n (setf (aref result 0) nil))\n (loop for divisor from 2 below sup\n do (loop for number from divisor below sup by divisor\n do (setf (cdr (aref tails number)) (list divisor)\n (aref tails number) (cdr (aref tails number)))))\n result))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/divisor :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (table (make-divisors-table (+ n 1))))\n (println (loop for i from 1 to n by 2\n count (= (length (aref table i)) 8)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (5am:is\n (equal \"1\n\"\n (run \"105\n\" nil)))\n (5am:is\n (equal \"0\n\"\n (run \"7\n\" nil))))\n", "problem_context": "Score: 200 points\n\nProblem Statement\n\nThe number 105 is quite special - it is odd but still it has eight divisors.\nNow, your task is this: how many odd numbers with exactly eight positive divisors are there between 1 and N (inclusive)?\n\nConstraints\n\nN is an integer between 1 and 200 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the count.\n\nSample Input 1\n\n105\n\nSample Output 1\n\n1\n\nAmong the numbers between 1 and 105, the only number that is odd and has exactly eight divisors is 105.\n\nSample Input 2\n\n7\n\nSample Output 2\n\n0\n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there is no number that satisfies the condition.", "sample_input": "105\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03281", "source_text": "Score: 200 points\n\nProblem Statement\n\nThe number 105 is quite special - it is odd but still it has eight divisors.\nNow, your task is this: how many odd numbers with exactly eight positive divisors are there between 1 and N (inclusive)?\n\nConstraints\n\nN is an integer between 1 and 200 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the count.\n\nSample Input 1\n\n105\n\nSample Output 1\n\n1\n\nAmong the numbers between 1 and 105, the only number that is odd and has exactly eight divisors is 105.\n\nSample Input 2\n\n7\n\nSample Output 2\n\n0\n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there is no number that satisfies the condition.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6885, "cpu_time_ms": 16, "memory_kb": 24948}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s932435566", "group_id": "codeNet:p03281", "input_text": "(defun main ()\n (count 8 (mapcar #'kn (loop :for a :from 1 :upto (read) :by 2 collect a))))\n(defun kn (n)\n (loop :for k :from 1 :upto n count(= (mod n k) 0)))\n(format t \"~A\" (main))\n", "language": "Lisp", "metadata": {"date": 1535644340, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03281.html", "problem_id": "p03281", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03281/input.txt", "sample_output_relpath": "derived/input_output/data/p03281/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03281/Lisp/s932435566.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s932435566", "user_id": "u610490393"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun main ()\n (count 8 (mapcar #'kn (loop :for a :from 1 :upto (read) :by 2 collect a))))\n(defun kn (n)\n (loop :for k :from 1 :upto n count(= (mod n k) 0)))\n(format t \"~A\" (main))\n", "problem_context": "Score: 200 points\n\nProblem Statement\n\nThe number 105 is quite special - it is odd but still it has eight divisors.\nNow, your task is this: how many odd numbers with exactly eight positive divisors are there between 1 and N (inclusive)?\n\nConstraints\n\nN is an integer between 1 and 200 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the count.\n\nSample Input 1\n\n105\n\nSample Output 1\n\n1\n\nAmong the numbers between 1 and 105, the only number that is odd and has exactly eight divisors is 105.\n\nSample Input 2\n\n7\n\nSample Output 2\n\n0\n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there is no number that satisfies the condition.", "sample_input": "105\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03281", "source_text": "Score: 200 points\n\nProblem Statement\n\nThe number 105 is quite special - it is odd but still it has eight divisors.\nNow, your task is this: how many odd numbers with exactly eight positive divisors are there between 1 and N (inclusive)?\n\nConstraints\n\nN is an integer between 1 and 200 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the count.\n\nSample Input 1\n\n105\n\nSample Output 1\n\n1\n\nAmong the numbers between 1 and 105, the only number that is odd and has exactly eight divisors is 105.\n\nSample Input 2\n\n7\n\nSample Output 2\n\n0\n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there is no number that satisfies the condition.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 184, "cpu_time_ms": 78, "memory_kb": 9320}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s071445393", "group_id": "codeNet:p03281", "input_text": "(format t \"~A\" (count 8 (mapcar #'kn (loop :for a :from 1 :upto (read) collect a))))\n(defun kn (n)\n (loop :for k :from 2 :upto n count(= (mod n k) 0)))", "language": "Lisp", "metadata": {"date": 1535643079, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03281.html", "problem_id": "p03281", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03281/input.txt", "sample_output_relpath": "derived/input_output/data/p03281/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03281/Lisp/s071445393.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s071445393", "user_id": "u610490393"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(format t \"~A\" (count 8 (mapcar #'kn (loop :for a :from 1 :upto (read) collect a))))\n(defun kn (n)\n (loop :for k :from 2 :upto n count(= (mod n k) 0)))", "problem_context": "Score: 200 points\n\nProblem Statement\n\nThe number 105 is quite special - it is odd but still it has eight divisors.\nNow, your task is this: how many odd numbers with exactly eight positive divisors are there between 1 and N (inclusive)?\n\nConstraints\n\nN is an integer between 1 and 200 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the count.\n\nSample Input 1\n\n105\n\nSample Output 1\n\n1\n\nAmong the numbers between 1 and 105, the only number that is odd and has exactly eight divisors is 105.\n\nSample Input 2\n\n7\n\nSample Output 2\n\n0\n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there is no number that satisfies the condition.", "sample_input": "105\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03281", "source_text": "Score: 200 points\n\nProblem Statement\n\nThe number 105 is quite special - it is odd but still it has eight divisors.\nNow, your task is this: how many odd numbers with exactly eight positive divisors are there between 1 and N (inclusive)?\n\nConstraints\n\nN is an integer between 1 and 200 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the count.\n\nSample Input 1\n\n105\n\nSample Output 1\n\n1\n\nAmong the numbers between 1 and 105, the only number that is odd and has exactly eight divisors is 105.\n\nSample Input 2\n\n7\n\nSample Output 2\n\n0\n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there is no number that satisfies the condition.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 152, "cpu_time_ms": 67, "memory_kb": 8032}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s103082037", "group_id": "codeNet:p03282", "input_text": "(defun solve (s k &optional (cnt 0))\n (cond\n ((= cnt k) 1)\n ((not (equal (first s) #\\1)) (first s))\n (t (solve (rest s)\n k\n (1+ cnt)))))\n\n(defun main ()\n (let ((s (concatenate 'list (read-line)))\n (k (read)))\n (princ (solve s k))\n (fresh-line)))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1594063879, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03282.html", "problem_id": "p03282", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03282/input.txt", "sample_output_relpath": "derived/input_output/data/p03282/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03282/Lisp/s103082037.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s103082037", "user_id": "u425762225"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun solve (s k &optional (cnt 0))\n (cond\n ((= cnt k) 1)\n ((not (equal (first s) #\\1)) (first s))\n (t (solve (rest s)\n k\n (1+ cnt)))))\n\n(defun main ()\n (let ((s (concatenate 'list (read-line)))\n (k (read)))\n (princ (solve s k))\n (fresh-line)))\n\n(main)\n", "problem_context": "Score: 300 points\n\nProblem Statement\n\nMr. Infinity has a string S consisting of digits from 1 to 9. Each time the date changes, this string changes as follows:\n\nEach occurrence of 2 in S is replaced with 22. Similarly, each 3 becomes 333, 4 becomes 4444, 5 becomes 55555, 6 becomes 666666, 7 becomes 7777777, 8 becomes 88888888 and 9 becomes 999999999. 1 remains as 1.\n\nFor example, if S is 1324, it becomes 1333224444 the next day, and it becomes 133333333322224444444444444444 the day after next.\nYou are interested in what the string looks like after 5 \\times 10^{15} days. What is the K-th character from the left in the string after 5 \\times 10^{15} days?\n\nConstraints\n\nS is a string of length between 1 and 100 (inclusive).\n\nK is an integer between 1 and 10^{18} (inclusive).\n\nThe length of the string after 5 \\times 10^{15} days is at least K.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nK\n\nOutput\n\nPrint the K-th character from the left in Mr. Infinity's string after 5 \\times 10^{15} days.\n\nSample Input 1\n\n1214\n4\n\nSample Output 1\n\n2\n\nThe string S changes as follows:\n\nNow: 1214\n\nAfter one day: 12214444\n\nAfter two days: 1222214444444444444444\n\nAfter three days: 12222222214444444444444444444444444444444444444444444444444444444444444444\n\nThe first five characters in the string after 5 \\times 10^{15} days is 12222. As K=4, we should print the fourth character, 2.\n\nSample Input 2\n\n3\n157\n\nSample Output 2\n\n3\n\nThe initial string is 3. The string after 5 \\times 10^{15} days consists only of 3.\n\nSample Input 3\n\n299792458\n9460730472580800\n\nSample Output 3\n\n2", "sample_input": "1214\n4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03282", "source_text": "Score: 300 points\n\nProblem Statement\n\nMr. Infinity has a string S consisting of digits from 1 to 9. Each time the date changes, this string changes as follows:\n\nEach occurrence of 2 in S is replaced with 22. Similarly, each 3 becomes 333, 4 becomes 4444, 5 becomes 55555, 6 becomes 666666, 7 becomes 7777777, 8 becomes 88888888 and 9 becomes 999999999. 1 remains as 1.\n\nFor example, if S is 1324, it becomes 1333224444 the next day, and it becomes 133333333322224444444444444444 the day after next.\nYou are interested in what the string looks like after 5 \\times 10^{15} days. What is the K-th character from the left in the string after 5 \\times 10^{15} days?\n\nConstraints\n\nS is a string of length between 1 and 100 (inclusive).\n\nK is an integer between 1 and 10^{18} (inclusive).\n\nThe length of the string after 5 \\times 10^{15} days is at least K.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nK\n\nOutput\n\nPrint the K-th character from the left in Mr. Infinity's string after 5 \\times 10^{15} days.\n\nSample Input 1\n\n1214\n4\n\nSample Output 1\n\n2\n\nThe string S changes as follows:\n\nNow: 1214\n\nAfter one day: 12214444\n\nAfter two days: 1222214444444444444444\n\nAfter three days: 12222222214444444444444444444444444444444444444444444444444444444444444444\n\nThe first five characters in the string after 5 \\times 10^{15} days is 12222. As K=4, we should print the fourth character, 2.\n\nSample Input 2\n\n3\n157\n\nSample Output 2\n\n3\n\nThe initial string is 3. The string after 5 \\times 10^{15} days consists only of 3.\n\nSample Input 3\n\n299792458\n9460730472580800\n\nSample Output 3\n\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 304, "cpu_time_ms": 18, "memory_kb": 24588}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s245321998", "group_id": "codeNet:p03282", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(deftype int32 () '(signed-byte 32))\n(deftype int64 () '(signed-byte 64))\n\n\n;;macros\n(defmacro println (n)\n `(format t \"~a~%\" ,n))\n(defmacro vint-out (vec)\n `(progn\n (rep i (length ,vec)\n (princ (vref ,vec i))\n (princ \" \"))\n (fresh-line)))\n\n\n;;vector\n(defmacro vec (type &optional (num 100) (val 0))\n (let* ((g (gensym)))\n `(let* ((,g ,num))\n (make-array ,g :element-type ',type :initial-element ,val\n :adjustable nil :fill-pointer ,g))))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vint (&optional (num 0) (val 0))\n `(vec int32 ,num ,val))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vref (vector pos &optional value)\n (let ((g (gensym)))\n `(let ((,g ,value))\n (if ,g\n (setf (aref ,vector ,pos) ,g)\n (aref ,vector ,pos)))))\n\n(defmacro chvar (sym comp predicate)\n (let ((g (gensym)))\n `(let ((,g ,comp))\n (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))\n (setf ,sym ,g)))))\n\n(defmacro chmax (sym comp &optional (predicate #'>))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro chmin (sym comp &optional (predicate #'<))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro defchangef (name op default-val)\n `(defmacro ,name (var &optional (val ,default-val))\n `(setq ,var (,',op ,val ,var))))\n\n;;本体\n(defun read1 (str)\n (cond\n ((char= (aref str 0) #\\1) (1+ (read1 (subseq str 1))))\n (t 0)))\n\n(defmacro aif (test then &optional else)\n `(let ((it ,test))\n (if it ,then ,else)))\n\n\n(defun main()\n (let* ((s (read-line)) (k (read)) (one (read1 s)))\n (println\n (cond\n ((<= k one) 1)\n (t (aref s one))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1559250192, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03282.html", "problem_id": "p03282", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03282/input.txt", "sample_output_relpath": "derived/input_output/data/p03282/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03282/Lisp/s245321998.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s245321998", "user_id": "u432998668"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(deftype int32 () '(signed-byte 32))\n(deftype int64 () '(signed-byte 64))\n\n\n;;macros\n(defmacro println (n)\n `(format t \"~a~%\" ,n))\n(defmacro vint-out (vec)\n `(progn\n (rep i (length ,vec)\n (princ (vref ,vec i))\n (princ \" \"))\n (fresh-line)))\n\n\n;;vector\n(defmacro vec (type &optional (num 100) (val 0))\n (let* ((g (gensym)))\n `(let* ((,g ,num))\n (make-array ,g :element-type ',type :initial-element ,val\n :adjustable nil :fill-pointer ,g))))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vint (&optional (num 0) (val 0))\n `(vec int32 ,num ,val))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vref (vector pos &optional value)\n (let ((g (gensym)))\n `(let ((,g ,value))\n (if ,g\n (setf (aref ,vector ,pos) ,g)\n (aref ,vector ,pos)))))\n\n(defmacro chvar (sym comp predicate)\n (let ((g (gensym)))\n `(let ((,g ,comp))\n (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))\n (setf ,sym ,g)))))\n\n(defmacro chmax (sym comp &optional (predicate #'>))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro chmin (sym comp &optional (predicate #'<))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro defchangef (name op default-val)\n `(defmacro ,name (var &optional (val ,default-val))\n `(setq ,var (,',op ,val ,var))))\n\n;;本体\n(defun read1 (str)\n (cond\n ((char= (aref str 0) #\\1) (1+ (read1 (subseq str 1))))\n (t 0)))\n\n(defmacro aif (test then &optional else)\n `(let ((it ,test))\n (if it ,then ,else)))\n\n\n(defun main()\n (let* ((s (read-line)) (k (read)) (one (read1 s)))\n (println\n (cond\n ((<= k one) 1)\n (t (aref s one))))))\n\n#-swank(main)\n", "problem_context": "Score: 300 points\n\nProblem Statement\n\nMr. Infinity has a string S consisting of digits from 1 to 9. Each time the date changes, this string changes as follows:\n\nEach occurrence of 2 in S is replaced with 22. Similarly, each 3 becomes 333, 4 becomes 4444, 5 becomes 55555, 6 becomes 666666, 7 becomes 7777777, 8 becomes 88888888 and 9 becomes 999999999. 1 remains as 1.\n\nFor example, if S is 1324, it becomes 1333224444 the next day, and it becomes 133333333322224444444444444444 the day after next.\nYou are interested in what the string looks like after 5 \\times 10^{15} days. What is the K-th character from the left in the string after 5 \\times 10^{15} days?\n\nConstraints\n\nS is a string of length between 1 and 100 (inclusive).\n\nK is an integer between 1 and 10^{18} (inclusive).\n\nThe length of the string after 5 \\times 10^{15} days is at least K.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nK\n\nOutput\n\nPrint the K-th character from the left in Mr. Infinity's string after 5 \\times 10^{15} days.\n\nSample Input 1\n\n1214\n4\n\nSample Output 1\n\n2\n\nThe string S changes as follows:\n\nNow: 1214\n\nAfter one day: 12214444\n\nAfter two days: 1222214444444444444444\n\nAfter three days: 12222222214444444444444444444444444444444444444444444444444444444444444444\n\nThe first five characters in the string after 5 \\times 10^{15} days is 12222. As K=4, we should print the fourth character, 2.\n\nSample Input 2\n\n3\n157\n\nSample Output 2\n\n3\n\nThe initial string is 3. The string after 5 \\times 10^{15} days consists only of 3.\n\nSample Input 3\n\n299792458\n9460730472580800\n\nSample Output 3\n\n2", "sample_input": "1214\n4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03282", "source_text": "Score: 300 points\n\nProblem Statement\n\nMr. Infinity has a string S consisting of digits from 1 to 9. Each time the date changes, this string changes as follows:\n\nEach occurrence of 2 in S is replaced with 22. Similarly, each 3 becomes 333, 4 becomes 4444, 5 becomes 55555, 6 becomes 666666, 7 becomes 7777777, 8 becomes 88888888 and 9 becomes 999999999. 1 remains as 1.\n\nFor example, if S is 1324, it becomes 1333224444 the next day, and it becomes 133333333322224444444444444444 the day after next.\nYou are interested in what the string looks like after 5 \\times 10^{15} days. What is the K-th character from the left in the string after 5 \\times 10^{15} days?\n\nConstraints\n\nS is a string of length between 1 and 100 (inclusive).\n\nK is an integer between 1 and 10^{18} (inclusive).\n\nThe length of the string after 5 \\times 10^{15} days is at least K.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nK\n\nOutput\n\nPrint the K-th character from the left in Mr. Infinity's string after 5 \\times 10^{15} days.\n\nSample Input 1\n\n1214\n4\n\nSample Output 1\n\n2\n\nThe string S changes as follows:\n\nNow: 1214\n\nAfter one day: 12214444\n\nAfter two days: 1222214444444444444444\n\nAfter three days: 12222222214444444444444444444444444444444444444444444444444444444444444444\n\nThe first five characters in the string after 5 \\times 10^{15} days is 12222. As K=4, we should print the fourth character, 2.\n\nSample Input 2\n\n3\n157\n\nSample Output 2\n\n3\n\nThe initial string is 3. The string after 5 \\times 10^{15} days consists only of 3.\n\nSample Input 3\n\n299792458\n9460730472580800\n\nSample Output 3\n\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2173, "cpu_time_ms": 183, "memory_kb": 21860}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s981496568", "group_id": "codeNet:p03282", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(defun main ()\n (let* ((str (read-line))\n (k (read)))\n (println\n (loop for c across str\n for digit = (- (char-code c) 48)\n unless (= digit 1)\n do (return digit)\n finally (return 1)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1546545910, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03282.html", "problem_id": "p03282", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03282/input.txt", "sample_output_relpath": "derived/input_output/data/p03282/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03282/Lisp/s981496568.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s981496568", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(defun main ()\n (let* ((str (read-line))\n (k (read)))\n (println\n (loop for c across str\n for digit = (- (char-code c) 48)\n unless (= digit 1)\n do (return digit)\n finally (return 1)))))\n\n#-swank(main)\n", "problem_context": "Score: 300 points\n\nProblem Statement\n\nMr. Infinity has a string S consisting of digits from 1 to 9. Each time the date changes, this string changes as follows:\n\nEach occurrence of 2 in S is replaced with 22. Similarly, each 3 becomes 333, 4 becomes 4444, 5 becomes 55555, 6 becomes 666666, 7 becomes 7777777, 8 becomes 88888888 and 9 becomes 999999999. 1 remains as 1.\n\nFor example, if S is 1324, it becomes 1333224444 the next day, and it becomes 133333333322224444444444444444 the day after next.\nYou are interested in what the string looks like after 5 \\times 10^{15} days. What is the K-th character from the left in the string after 5 \\times 10^{15} days?\n\nConstraints\n\nS is a string of length between 1 and 100 (inclusive).\n\nK is an integer between 1 and 10^{18} (inclusive).\n\nThe length of the string after 5 \\times 10^{15} days is at least K.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nK\n\nOutput\n\nPrint the K-th character from the left in Mr. Infinity's string after 5 \\times 10^{15} days.\n\nSample Input 1\n\n1214\n4\n\nSample Output 1\n\n2\n\nThe string S changes as follows:\n\nNow: 1214\n\nAfter one day: 12214444\n\nAfter two days: 1222214444444444444444\n\nAfter three days: 12222222214444444444444444444444444444444444444444444444444444444444444444\n\nThe first five characters in the string after 5 \\times 10^{15} days is 12222. As K=4, we should print the fourth character, 2.\n\nSample Input 2\n\n3\n157\n\nSample Output 2\n\n3\n\nThe initial string is 3. The string after 5 \\times 10^{15} days consists only of 3.\n\nSample Input 3\n\n299792458\n9460730472580800\n\nSample Output 3\n\n2", "sample_input": "1214\n4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03282", "source_text": "Score: 300 points\n\nProblem Statement\n\nMr. Infinity has a string S consisting of digits from 1 to 9. Each time the date changes, this string changes as follows:\n\nEach occurrence of 2 in S is replaced with 22. Similarly, each 3 becomes 333, 4 becomes 4444, 5 becomes 55555, 6 becomes 666666, 7 becomes 7777777, 8 becomes 88888888 and 9 becomes 999999999. 1 remains as 1.\n\nFor example, if S is 1324, it becomes 1333224444 the next day, and it becomes 133333333322224444444444444444 the day after next.\nYou are interested in what the string looks like after 5 \\times 10^{15} days. What is the K-th character from the left in the string after 5 \\times 10^{15} days?\n\nConstraints\n\nS is a string of length between 1 and 100 (inclusive).\n\nK is an integer between 1 and 10^{18} (inclusive).\n\nThe length of the string after 5 \\times 10^{15} days is at least K.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nK\n\nOutput\n\nPrint the K-th character from the left in Mr. Infinity's string after 5 \\times 10^{15} days.\n\nSample Input 1\n\n1214\n4\n\nSample Output 1\n\n2\n\nThe string S changes as follows:\n\nNow: 1214\n\nAfter one day: 12214444\n\nAfter two days: 1222214444444444444444\n\nAfter three days: 12222222214444444444444444444444444444444444444444444444444444444444444444\n\nThe first five characters in the string after 5 \\times 10^{15} days is 12222. As K=4, we should print the fourth character, 2.\n\nSample Input 2\n\n3\n157\n\nSample Output 2\n\n3\n\nThe initial string is 3. The string after 5 \\times 10^{15} days consists only of 3.\n\nSample Input 3\n\n299792458\n9460730472580800\n\nSample Output 3\n\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1165, "cpu_time_ms": 89, "memory_kb": 10468}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s213148088", "group_id": "codeNet:p03283", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string may be changed by repetitive use.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #\\Newline))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (setf (schar ,buffer ,idx) ,terminate-char)\n (return (values ,buffer ,idx))))))\n\n\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ',dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dimensions-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value)))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name))))\n (extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car form))) body)))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n;; (test with-memoizing\n;; (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (labels ((add (x y) (+ x y))\n;; \t\t (my-print (x) (print x)))\n;; \t (add 1 2))))))\n\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(defmacro split-ints-and-bind (vars string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str (gensym \"STR\")))\n (labels ((expand (vars &optional (init-pos1 t))\n\t (if (null vars)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str :start ,pos1 :test #'char=))\n\t\t\t (,(car vars) (parse-integer ,str :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr vars) nil))))))\n `(let ((,str ,string))\n (declare (string ,str))\n\t ,@(expand vars)))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (test #'<) (key #'identity))\n \"TARGET := vector | function\nTEST := strict order\n\nReturns the smallest index (or input) i that fulfills TARGET[i] >= VALUE, where\n'>=' is the complement of TEST and TARGET is monotonically\nnon-decreasing (w.r.t. TEST). Returns END if VALUE exceeds TARGET[END-1]. Note\nthat the range [START, END) is half-open. END must be specified If TARGET is\nfunction\"\n (declare (function key test))\n (macrolet ((body (accessor &optional (declaration `(declare)))\n `(if (funcall test (funcall key (,accessor target (- end 1))) value)\n end\n (labels ((%bisect-left (l r)\n ,declaration\n (let ((mid (floor (+ l r) 2)))\n (if (= mid l)\n (if (funcall test (funcall key (,accessor target l)) value)\n r\n l)\n (if (funcall test (funcall key (,accessor target mid)) value)\n (%bisect-left mid r)\n (%bisect-left l mid))))))\n (%bisect-left start (- end 1))))))\n (etypecase target\n (vector\n (when (null end)\n (setf end (length target)))\n (assert (<= start end))\n (if (= start end)\n end\n (body aref (declare ((integer 0 #.most-positive-fixnum) l r)))))\n (function\n (assert end)\n (assert (<= start end))\n (if (= start end)\n end\n (body funcall))))))\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (test #'<) (key #'identity))\n \"TARGET := vector | function\nTEST := strict order\n\nReturns the smallest index (or input) i that fulfills TARGET[i] > VALUE, where\nTARGET is monotonically non-decreasing (w.r.t. TEST). Returns END if VALUE\nexceeds TARGET[END-1]. Note that the range [START, END) is half-open. END must\nbe specified if TARGET is function.\"\n (declare (function key test))\n (macrolet ((body (accessor &optional (declaration `(declare)))\n `(if (funcall test value (funcall key (,accessor target (- end 1))))\n (labels ((%bisect-right (l r)\n ,declaration\n (let ((mid (floor (+ l r) 2)))\n (if (= mid l)\n (if (funcall test value (funcall key (,accessor target l)))\n l\n r)\n (if (funcall test value (funcall key (,accessor target mid)))\n (%bisect-right l mid)\n (%bisect-right mid r))))))\n \n (%bisect-right start (- end 1)))\n end)))\n (etypecase target\n (vector\n (when (null end)\n (setf end (length target)))\n (assert (<= start end))\n (if (= start end)\n end\n (body aref (declare ((integer 0 #.most-positive-fixnum) l r)))))\n (function\n (assert end)\n (assert (<= start end))\n (if (= start end)\n end\n (body funcall))))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (q (read))\n (lr-table (make-array m :element-type '(cons uint32 uint32)))\n (src-table (make-array (1+ n) :element-type 'uint32 :initial-element (length lr-table))))\n (declare ((simple-array (cons uint32 uint32) (*)) lr-table)\n (uint32 n m q))\n (dotimes (i m)\n (split-ints-and-bind (l r) (buffered-read-line)\n (declare (uint32 l r))\n (setf (aref lr-table i) (cons (- l 1) (- r 1)))))\n (setf lr-table (sort lr-table (lambda (pair1 pair2)\n (declare ((cons uint32 uint32) pair1 pair2))\n (or (< (car pair1) (car pair2))\n (and (= (car pair1) (car pair2))\n (< (cdr pair1) (cdr pair2)))))))\n (nlet recurse ((base 0) (l 0))\n (when (< l n)\n (setf (aref src-table l) base)\n (loop for i from base below (length lr-table)\n while (= (car (aref lr-table i)) l)\n finally (return (recurse i (1+ l))))))\n (with-memoizing (:array (501 501) :element-type 'uint32 :initial-element #.(- (expt 2 32) 1))\n (labels ((%dp (x y)\n (list x y)\n (if (= x y)\n (- (bisect-right lr-table y\n :start (aref src-table x)\n :end (aref src-table (1+ x))\n :key #'cdr)\n (bisect-left lr-table y\n :start (aref src-table x)\n :end (aref src-table (1+ x))\n :key #'cdr))\n (+ (%dp (1+ x) y)\n (- (bisect-right lr-table y\n :start (aref src-table x)\n :end (aref src-table (1+ x))\n :key #'cdr)\n (aref src-table x))))))\n (dotimes (i q)\n (split-ints-and-bind (p q) (buffered-read-line)\n (declare (uint32 p q))\n (println (%dp (- p 1) (- q 1)))))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1547176195, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03283.html", "problem_id": "p03283", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03283/input.txt", "sample_output_relpath": "derived/input_output/data/p03283/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03283/Lisp/s213148088.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s213148088", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string may be changed by repetitive use.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #\\Newline))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (setf (schar ,buffer ,idx) ,terminate-char)\n (return (values ,buffer ,idx))))))\n\n\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ',dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dimensions-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value)))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name))))\n (extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car form))) body)))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n;; (test with-memoizing\n;; (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (labels ((add (x y) (+ x y))\n;; \t\t (my-print (x) (print x)))\n;; \t (add 1 2))))))\n\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(defmacro split-ints-and-bind (vars string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str (gensym \"STR\")))\n (labels ((expand (vars &optional (init-pos1 t))\n\t (if (null vars)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str :start ,pos1 :test #'char=))\n\t\t\t (,(car vars) (parse-integer ,str :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr vars) nil))))))\n `(let ((,str ,string))\n (declare (string ,str))\n\t ,@(expand vars)))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (test #'<) (key #'identity))\n \"TARGET := vector | function\nTEST := strict order\n\nReturns the smallest index (or input) i that fulfills TARGET[i] >= VALUE, where\n'>=' is the complement of TEST and TARGET is monotonically\nnon-decreasing (w.r.t. TEST). Returns END if VALUE exceeds TARGET[END-1]. Note\nthat the range [START, END) is half-open. END must be specified If TARGET is\nfunction\"\n (declare (function key test))\n (macrolet ((body (accessor &optional (declaration `(declare)))\n `(if (funcall test (funcall key (,accessor target (- end 1))) value)\n end\n (labels ((%bisect-left (l r)\n ,declaration\n (let ((mid (floor (+ l r) 2)))\n (if (= mid l)\n (if (funcall test (funcall key (,accessor target l)) value)\n r\n l)\n (if (funcall test (funcall key (,accessor target mid)) value)\n (%bisect-left mid r)\n (%bisect-left l mid))))))\n (%bisect-left start (- end 1))))))\n (etypecase target\n (vector\n (when (null end)\n (setf end (length target)))\n (assert (<= start end))\n (if (= start end)\n end\n (body aref (declare ((integer 0 #.most-positive-fixnum) l r)))))\n (function\n (assert end)\n (assert (<= start end))\n (if (= start end)\n end\n (body funcall))))))\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (test #'<) (key #'identity))\n \"TARGET := vector | function\nTEST := strict order\n\nReturns the smallest index (or input) i that fulfills TARGET[i] > VALUE, where\nTARGET is monotonically non-decreasing (w.r.t. TEST). Returns END if VALUE\nexceeds TARGET[END-1]. Note that the range [START, END) is half-open. END must\nbe specified if TARGET is function.\"\n (declare (function key test))\n (macrolet ((body (accessor &optional (declaration `(declare)))\n `(if (funcall test value (funcall key (,accessor target (- end 1))))\n (labels ((%bisect-right (l r)\n ,declaration\n (let ((mid (floor (+ l r) 2)))\n (if (= mid l)\n (if (funcall test value (funcall key (,accessor target l)))\n l\n r)\n (if (funcall test value (funcall key (,accessor target mid)))\n (%bisect-right l mid)\n (%bisect-right mid r))))))\n \n (%bisect-right start (- end 1)))\n end)))\n (etypecase target\n (vector\n (when (null end)\n (setf end (length target)))\n (assert (<= start end))\n (if (= start end)\n end\n (body aref (declare ((integer 0 #.most-positive-fixnum) l r)))))\n (function\n (assert end)\n (assert (<= start end))\n (if (= start end)\n end\n (body funcall))))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (q (read))\n (lr-table (make-array m :element-type '(cons uint32 uint32)))\n (src-table (make-array (1+ n) :element-type 'uint32 :initial-element (length lr-table))))\n (declare ((simple-array (cons uint32 uint32) (*)) lr-table)\n (uint32 n m q))\n (dotimes (i m)\n (split-ints-and-bind (l r) (buffered-read-line)\n (declare (uint32 l r))\n (setf (aref lr-table i) (cons (- l 1) (- r 1)))))\n (setf lr-table (sort lr-table (lambda (pair1 pair2)\n (declare ((cons uint32 uint32) pair1 pair2))\n (or (< (car pair1) (car pair2))\n (and (= (car pair1) (car pair2))\n (< (cdr pair1) (cdr pair2)))))))\n (nlet recurse ((base 0) (l 0))\n (when (< l n)\n (setf (aref src-table l) base)\n (loop for i from base below (length lr-table)\n while (= (car (aref lr-table i)) l)\n finally (return (recurse i (1+ l))))))\n (with-memoizing (:array (501 501) :element-type 'uint32 :initial-element #.(- (expt 2 32) 1))\n (labels ((%dp (x y)\n (list x y)\n (if (= x y)\n (- (bisect-right lr-table y\n :start (aref src-table x)\n :end (aref src-table (1+ x))\n :key #'cdr)\n (bisect-left lr-table y\n :start (aref src-table x)\n :end (aref src-table (1+ x))\n :key #'cdr))\n (+ (%dp (1+ x) y)\n (- (bisect-right lr-table y\n :start (aref src-table x)\n :end (aref src-table (1+ x))\n :key #'cdr)\n (aref src-table x))))))\n (dotimes (i q)\n (split-ints-and-bind (p q) (buffered-read-line)\n (declare (uint32 p q))\n (println (%dp (- p 1) (- q 1)))))))))\n\n#-swank(main)\n", "problem_context": "Score: 400 points\n\nProblem Statement\n\nIn Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1, 2, 3, ..., N from west to east.\nA company called AtCoder Express possesses M trains, and the train i runs from City L_i to City R_i (it is possible that L_i = R_i).\nTakahashi the king is interested in the following Q matters:\n\nThe number of the trains that runs strictly within the section from City p_i to City q_i, that is, the number of trains j such that p_i \\leq L_j and R_j \\leq q_i.\n\nAlthough he is genius, this is too much data to process by himself. Find the answer for each of these Q queries to help him.\n\nConstraints\n\nN is an integer between 1 and 500 (inclusive).\n\nM is an integer between 1 and 200 \\ 000 (inclusive).\n\nQ is an integer between 1 and 100 \\ 000 (inclusive).\n\n1 \\leq L_i \\leq R_i \\leq N (1 \\leq i \\leq M)\n\n1 \\leq p_i \\leq q_i \\leq N (1 \\leq i \\leq Q)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M Q\nL_1 R_1\nL_2 R_2\n:\nL_M R_M\np_1 q_1\np_2 q_2\n:\np_Q q_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the number of the trains that runs strictly within the section from City p_i to City q_i.\n\nSample Input 1\n\n2 3 1\n1 1\n1 2\n2 2\n1 2\n\nSample Output 1\n\n3\n\nAs all the trains runs within the section from City 1 to City 2, the answer to the only query is 3.\n\nSample Input 2\n\n10 3 2\n1 5\n2 8\n7 10\n1 7\n3 10\n\nSample Output 2\n\n1\n1\n\nThe first query is on the section from City 1 to 7. There is only one train that runs strictly within that section: Train 1.\nThe second query is on the section from City 3 to 10. There is only one train that runs strictly within that section: Train 3.\n\nSample Input 3\n\n10 10 10\n1 6\n2 9\n4 5\n4 7\n4 7\n5 8\n6 6\n6 7\n7 9\n10 10\n1 8\n1 9\n1 10\n2 8\n2 9\n2 10\n3 8\n3 9\n3 10\n1 10\n\nSample Output 3\n\n7\n9\n10\n6\n8\n9\n6\n7\n8\n10", "sample_input": "2 3 1\n1 1\n1 2\n2 2\n1 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03283", "source_text": "Score: 400 points\n\nProblem Statement\n\nIn Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1, 2, 3, ..., N from west to east.\nA company called AtCoder Express possesses M trains, and the train i runs from City L_i to City R_i (it is possible that L_i = R_i).\nTakahashi the king is interested in the following Q matters:\n\nThe number of the trains that runs strictly within the section from City p_i to City q_i, that is, the number of trains j such that p_i \\leq L_j and R_j \\leq q_i.\n\nAlthough he is genius, this is too much data to process by himself. Find the answer for each of these Q queries to help him.\n\nConstraints\n\nN is an integer between 1 and 500 (inclusive).\n\nM is an integer between 1 and 200 \\ 000 (inclusive).\n\nQ is an integer between 1 and 100 \\ 000 (inclusive).\n\n1 \\leq L_i \\leq R_i \\leq N (1 \\leq i \\leq M)\n\n1 \\leq p_i \\leq q_i \\leq N (1 \\leq i \\leq Q)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M Q\nL_1 R_1\nL_2 R_2\n:\nL_M R_M\np_1 q_1\np_2 q_2\n:\np_Q q_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the number of the trains that runs strictly within the section from City p_i to City q_i.\n\nSample Input 1\n\n2 3 1\n1 1\n1 2\n2 2\n1 2\n\nSample Output 1\n\n3\n\nAs all the trains runs within the section from City 1 to City 2, the answer to the only query is 3.\n\nSample Input 2\n\n10 3 2\n1 5\n2 8\n7 10\n1 7\n3 10\n\nSample Output 2\n\n1\n1\n\nThe first query is on the section from City 1 to 7. There is only one train that runs strictly within that section: Train 1.\nThe second query is on the section from City 3 to 10. There is only one train that runs strictly within that section: Train 3.\n\nSample Input 3\n\n10 10 10\n1 6\n2 9\n4 5\n4 7\n4 7\n5 8\n6 6\n6 7\n7 9\n10 10\n1 8\n1 9\n1 10\n2 8\n2 9\n2 10\n3 8\n3 9\n3 10\n1 10\n\nSample Output 3\n\n7\n9\n10\n6\n8\n9\n6\n7\n8\n10", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 14334, "cpu_time_ms": 705, "memory_kb": 48352}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s086764294", "group_id": "codeNet:p03283", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ',dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dimensions-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value)))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name))))\n (extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car form))) body)))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n;; (test with-memoizing\n;; (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (labels ((add (x y) (+ x y))\n;; \t\t (my-print (x) (print x)))\n;; \t (add 1 2))))))\n\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(defmacro split-ints-and-bind (vars string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str (gensym \"STR\")))\n (labels ((expand (vars &optional (init-pos1 t))\n\t (if (null vars)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str :start ,pos1 :test #'char=))\n\t\t\t (,(car vars) (parse-integer ,str :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr vars) nil))))))\n `(let ((,str ,string))\n (declare (string ,str))\n\t ,@(expand vars)))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (test #'<) (key #'identity))\n \"TARGET := vector | function\nTEST := strict order\n\nReturns the smallest index (or input) i that fulfills TARGET[i] >= VALUE, where\n'>=' is the complement of TEST and TARGET is monotonically\nnon-decreasing (w.r.t. TEST). Returns END if VALUE exceeds TARGET[END-1]. Note\nthat the range [START, END) is half-open. END must be specified If TARGET is\nfunction\"\n (declare (function key test))\n (macrolet ((body (accessor)\n `(if (funcall test (funcall key (,accessor target (- end 1))) value)\n end\n (labels ((%bisect-left (l r)\n ;; (declare ((integer 0 #.most-positive-fixnum) l r))\n (let ((mid (floor (+ l r) 2)))\n (if (= mid l)\n (if (funcall test (funcall key (,accessor target l)) value)\n r\n l)\n (if (funcall test (funcall key (,accessor target mid)) value)\n (%bisect-left mid r)\n (%bisect-left l mid))))))\n (%bisect-left start (- end 1))))))\n (etypecase target\n (vector\n (when (null end)\n (setf end (length target)))\n (assert (<= start end))\n (if (= start end)\n end\n (body aref)))\n (function\n (assert end)\n (assert (<= start end))\n (if (= start end)\n end\n (body funcall))))))\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (test #'<) (key #'identity))\n \"TARGET := vector | function\nTEST := strict order\n\nReturns the smallest index (or input) i that fulfills TARGET[i] > VALUE, where\nTARGET is monotonically non-decreasing (w.r.t. TEST). Returns END if VALUE\nexceeds TARGET[END-1]. Note that the range [START, END) is half-open. END must\nbe specified if TARGET is function.\"\n (declare (function key test))\n (macrolet ((body (accessor)\n `(if (funcall test value (funcall key (,accessor target (- end 1))))\n (labels ((%bisect-right (l r)\n ;; (declare ((integer 0 #.most-positive-fixnum) l r))\n (let ((mid (floor (+ l r) 2)))\n (if (= mid l)\n (if (funcall test value (funcall key (,accessor target l)))\n l\n r)\n (if (funcall test value (funcall key (,accessor target mid)))\n (%bisect-right l mid)\n (%bisect-right mid r))))))\n \n (%bisect-right start (- end 1)))\n end)))\n (etypecase target\n (vector\n (when (null end)\n (setf end (length target)))\n (assert (<= start end))\n (if (= start end)\n end\n (body aref)))\n (function\n (assert end)\n (assert (<= start end))\n (if (= start end)\n end\n (body funcall))))))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (q (read))\n (lr-table (make-array m :element-type 'list))\n (src-table (make-array (1+ n) :element-type 'uint32 :initial-element (length lr-table))))\n (dotimes (i m)\n (split-ints-and-bind (l r) (read-line)\n (setf (aref lr-table i) (cons (- l 1) (- r 1)))))\n (setf lr-table (sort lr-table (lambda (pair1 pair2)\n (or (< (car pair1) (car pair2))\n (and (= (car pair1) (car pair2))\n (< (cdr pair1) (cdr pair2)))))))\n (nlet recurse ((base 0) (l 0))\n (when (< l n)\n (setf (aref src-table l) base)\n (loop for i from base below (length lr-table)\n while (= (car (aref lr-table i)) l)\n finally (return (recurse i (1+ l))))))\n (with-memoizing (:array (501 501) :element-type 'uint32 :initial-element #.(- (expt 2 32) 1))\n (labels ((%dp (x y)\n (list x y)\n (if (= x y)\n (- (bisect-right lr-table y\n :start (aref src-table x)\n :end (aref src-table (1+ x))\n :key #'cdr)\n (bisect-left lr-table y\n :start (aref src-table x)\n :end (aref src-table (1+ x))\n :key #'cdr))\n (+ (%dp (1+ x) y)\n (- (bisect-right lr-table y\n :start (aref src-table x)\n :end (aref src-table (1+ x))\n :key #'cdr)\n (aref src-table x))))))\n (dotimes (i q)\n (split-ints-and-bind (p q) (read-line)\n (println (%dp (- p 1) (- q 1)))))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1547175437, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03283.html", "problem_id": "p03283", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03283/input.txt", "sample_output_relpath": "derived/input_output/data/p03283/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03283/Lisp/s086764294.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s086764294", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ',dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dimensions-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value)))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name))))\n (extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car form))) body)))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n;; (test with-memoizing\n;; (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (labels ((add (x y) (+ x y))\n;; \t\t (my-print (x) (print x)))\n;; \t (add 1 2))))))\n\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(defmacro split-ints-and-bind (vars string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str (gensym \"STR\")))\n (labels ((expand (vars &optional (init-pos1 t))\n\t (if (null vars)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str :start ,pos1 :test #'char=))\n\t\t\t (,(car vars) (parse-integer ,str :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr vars) nil))))))\n `(let ((,str ,string))\n (declare (string ,str))\n\t ,@(expand vars)))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (test #'<) (key #'identity))\n \"TARGET := vector | function\nTEST := strict order\n\nReturns the smallest index (or input) i that fulfills TARGET[i] >= VALUE, where\n'>=' is the complement of TEST and TARGET is monotonically\nnon-decreasing (w.r.t. TEST). Returns END if VALUE exceeds TARGET[END-1]. Note\nthat the range [START, END) is half-open. END must be specified If TARGET is\nfunction\"\n (declare (function key test))\n (macrolet ((body (accessor)\n `(if (funcall test (funcall key (,accessor target (- end 1))) value)\n end\n (labels ((%bisect-left (l r)\n ;; (declare ((integer 0 #.most-positive-fixnum) l r))\n (let ((mid (floor (+ l r) 2)))\n (if (= mid l)\n (if (funcall test (funcall key (,accessor target l)) value)\n r\n l)\n (if (funcall test (funcall key (,accessor target mid)) value)\n (%bisect-left mid r)\n (%bisect-left l mid))))))\n (%bisect-left start (- end 1))))))\n (etypecase target\n (vector\n (when (null end)\n (setf end (length target)))\n (assert (<= start end))\n (if (= start end)\n end\n (body aref)))\n (function\n (assert end)\n (assert (<= start end))\n (if (= start end)\n end\n (body funcall))))))\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (test #'<) (key #'identity))\n \"TARGET := vector | function\nTEST := strict order\n\nReturns the smallest index (or input) i that fulfills TARGET[i] > VALUE, where\nTARGET is monotonically non-decreasing (w.r.t. TEST). Returns END if VALUE\nexceeds TARGET[END-1]. Note that the range [START, END) is half-open. END must\nbe specified if TARGET is function.\"\n (declare (function key test))\n (macrolet ((body (accessor)\n `(if (funcall test value (funcall key (,accessor target (- end 1))))\n (labels ((%bisect-right (l r)\n ;; (declare ((integer 0 #.most-positive-fixnum) l r))\n (let ((mid (floor (+ l r) 2)))\n (if (= mid l)\n (if (funcall test value (funcall key (,accessor target l)))\n l\n r)\n (if (funcall test value (funcall key (,accessor target mid)))\n (%bisect-right l mid)\n (%bisect-right mid r))))))\n \n (%bisect-right start (- end 1)))\n end)))\n (etypecase target\n (vector\n (when (null end)\n (setf end (length target)))\n (assert (<= start end))\n (if (= start end)\n end\n (body aref)))\n (function\n (assert end)\n (assert (<= start end))\n (if (= start end)\n end\n (body funcall))))))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (q (read))\n (lr-table (make-array m :element-type 'list))\n (src-table (make-array (1+ n) :element-type 'uint32 :initial-element (length lr-table))))\n (dotimes (i m)\n (split-ints-and-bind (l r) (read-line)\n (setf (aref lr-table i) (cons (- l 1) (- r 1)))))\n (setf lr-table (sort lr-table (lambda (pair1 pair2)\n (or (< (car pair1) (car pair2))\n (and (= (car pair1) (car pair2))\n (< (cdr pair1) (cdr pair2)))))))\n (nlet recurse ((base 0) (l 0))\n (when (< l n)\n (setf (aref src-table l) base)\n (loop for i from base below (length lr-table)\n while (= (car (aref lr-table i)) l)\n finally (return (recurse i (1+ l))))))\n (with-memoizing (:array (501 501) :element-type 'uint32 :initial-element #.(- (expt 2 32) 1))\n (labels ((%dp (x y)\n (list x y)\n (if (= x y)\n (- (bisect-right lr-table y\n :start (aref src-table x)\n :end (aref src-table (1+ x))\n :key #'cdr)\n (bisect-left lr-table y\n :start (aref src-table x)\n :end (aref src-table (1+ x))\n :key #'cdr))\n (+ (%dp (1+ x) y)\n (- (bisect-right lr-table y\n :start (aref src-table x)\n :end (aref src-table (1+ x))\n :key #'cdr)\n (aref src-table x))))))\n (dotimes (i q)\n (split-ints-and-bind (p q) (read-line)\n (println (%dp (- p 1) (- q 1)))))))))\n\n#-swank(main)\n", "problem_context": "Score: 400 points\n\nProblem Statement\n\nIn Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1, 2, 3, ..., N from west to east.\nA company called AtCoder Express possesses M trains, and the train i runs from City L_i to City R_i (it is possible that L_i = R_i).\nTakahashi the king is interested in the following Q matters:\n\nThe number of the trains that runs strictly within the section from City p_i to City q_i, that is, the number of trains j such that p_i \\leq L_j and R_j \\leq q_i.\n\nAlthough he is genius, this is too much data to process by himself. Find the answer for each of these Q queries to help him.\n\nConstraints\n\nN is an integer between 1 and 500 (inclusive).\n\nM is an integer between 1 and 200 \\ 000 (inclusive).\n\nQ is an integer between 1 and 100 \\ 000 (inclusive).\n\n1 \\leq L_i \\leq R_i \\leq N (1 \\leq i \\leq M)\n\n1 \\leq p_i \\leq q_i \\leq N (1 \\leq i \\leq Q)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M Q\nL_1 R_1\nL_2 R_2\n:\nL_M R_M\np_1 q_1\np_2 q_2\n:\np_Q q_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the number of the trains that runs strictly within the section from City p_i to City q_i.\n\nSample Input 1\n\n2 3 1\n1 1\n1 2\n2 2\n1 2\n\nSample Output 1\n\n3\n\nAs all the trains runs within the section from City 1 to City 2, the answer to the only query is 3.\n\nSample Input 2\n\n10 3 2\n1 5\n2 8\n7 10\n1 7\n3 10\n\nSample Output 2\n\n1\n1\n\nThe first query is on the section from City 1 to 7. There is only one train that runs strictly within that section: Train 1.\nThe second query is on the section from City 3 to 10. There is only one train that runs strictly within that section: Train 3.\n\nSample Input 3\n\n10 10 10\n1 6\n2 9\n4 5\n4 7\n4 7\n5 8\n6 6\n6 7\n7 9\n10 10\n1 8\n1 9\n1 10\n2 8\n2 9\n2 10\n3 8\n3 9\n3 10\n1 10\n\nSample Output 3\n\n7\n9\n10\n6\n8\n9\n6\n7\n8\n10", "sample_input": "2 3 1\n1 1\n1 2\n2 2\n1 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03283", "source_text": "Score: 400 points\n\nProblem Statement\n\nIn Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1, 2, 3, ..., N from west to east.\nA company called AtCoder Express possesses M trains, and the train i runs from City L_i to City R_i (it is possible that L_i = R_i).\nTakahashi the king is interested in the following Q matters:\n\nThe number of the trains that runs strictly within the section from City p_i to City q_i, that is, the number of trains j such that p_i \\leq L_j and R_j \\leq q_i.\n\nAlthough he is genius, this is too much data to process by himself. Find the answer for each of these Q queries to help him.\n\nConstraints\n\nN is an integer between 1 and 500 (inclusive).\n\nM is an integer between 1 and 200 \\ 000 (inclusive).\n\nQ is an integer between 1 and 100 \\ 000 (inclusive).\n\n1 \\leq L_i \\leq R_i \\leq N (1 \\leq i \\leq M)\n\n1 \\leq p_i \\leq q_i \\leq N (1 \\leq i \\leq Q)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M Q\nL_1 R_1\nL_2 R_2\n:\nL_M R_M\np_1 q_1\np_2 q_2\n:\np_Q q_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain the number of the trains that runs strictly within the section from City p_i to City q_i.\n\nSample Input 1\n\n2 3 1\n1 1\n1 2\n2 2\n1 2\n\nSample Output 1\n\n3\n\nAs all the trains runs within the section from City 1 to City 2, the answer to the only query is 3.\n\nSample Input 2\n\n10 3 2\n1 5\n2 8\n7 10\n1 7\n3 10\n\nSample Output 2\n\n1\n1\n\nThe first query is on the section from City 1 to 7. There is only one train that runs strictly within that section: Train 1.\nThe second query is on the section from City 3 to 10. There is only one train that runs strictly within that section: Train 3.\n\nSample Input 3\n\n10 10 10\n1 6\n2 9\n4 5\n4 7\n4 7\n5 8\n6 6\n6 7\n7 9\n10 10\n1 8\n1 9\n1 10\n2 8\n2 9\n2 10\n3 8\n3 9\n3 10\n1 10\n\nSample Output 3\n\n7\n9\n10\n6\n8\n9\n6\n7\n8\n10", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 13088, "cpu_time_ms": 1051, "memory_kb": 70752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s628692733", "group_id": "codeNet:p03284", "input_text": "(format t \"~A~%\" (if (= (mod (read)(read)) 0) 0 1))", "language": "Lisp", "metadata": {"date": 1561176510, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03284.html", "problem_id": "p03284", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03284/input.txt", "sample_output_relpath": "derived/input_output/data/p03284/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03284/Lisp/s628692733.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s628692733", "user_id": "u794246018"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(format t \"~A~%\" (if (= (mod (read)(read)) 0) 0 1))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi has decided to distribute N AtCoder Crackers to K users of as evenly as possible.\nWhen all the crackers are distributed, find the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.\n\nConstraints\n\n1 \\leq N,K \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.\n\nSample Input 1\n\n7 3\n\nSample Output 1\n\n1\n\nWhen the users receive two, two and three crackers, respectively, the (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user, is 1.\n\nSample Input 2\n\n100 10\n\nSample Output 2\n\n0\n\nThe crackers can be distributed evenly.\n\nSample Input 3\n\n1 1\n\nSample Output 3\n\n0", "sample_input": "7 3\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03284", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi has decided to distribute N AtCoder Crackers to K users of as evenly as possible.\nWhen all the crackers are distributed, find the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.\n\nConstraints\n\n1 \\leq N,K \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.\n\nSample Input 1\n\n7 3\n\nSample Output 1\n\n1\n\nWhen the users receive two, two and three crackers, respectively, the (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user, is 1.\n\nSample Input 2\n\n100 10\n\nSample Output 2\n\n0\n\nThe crackers can be distributed evenly.\n\nSample Input 3\n\n1 1\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 52, "cpu_time_ms": 21, "memory_kb": 3816}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s164140839", "group_id": "codeNet:p03285", "input_text": "(let ((a (read)))\n (if (or (= 4 (mod a 7)) (= 0 (mod a 7)))\n (princ \"Yes\")\n (princ \"No\"))", "language": "Lisp", "metadata": {"date": 1539294887, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03285.html", "problem_id": "p03285", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03285/input.txt", "sample_output_relpath": "derived/input_output/data/p03285/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03285/Lisp/s164140839.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s164140839", "user_id": "u610490393"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((a (read)))\n (if (or (= 4 (mod a 7)) (= 0 (mod a 7)))\n (princ \"Yes\")\n (princ \"No\"))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nLa Confiserie d'ABC sells cakes at 4 dollars each and doughnuts at 7 dollars each.\nDetermine if there is a way to buy some of them for exactly N dollars. You can buy two or more doughnuts and two or more cakes, and you can also choose to buy zero doughnuts or zero cakes.\n\nConstraints\n\nN is an integer between 1 and 100, inclusive.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf there is a way to buy some cakes and some doughnuts for exactly N dollars, print Yes; otherwise, print No.\n\nSample Input 1\n\n11\n\nSample Output 1\n\nYes\n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\nSample Input 2\n\n40\n\nSample Output 2\n\nYes\n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\nSample Input 3\n\n3\n\nSample Output 3\n\nNo\n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than 3 dollars, so there is no such way.", "sample_input": "11\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03285", "source_text": "Score : 200 points\n\nProblem Statement\n\nLa Confiserie d'ABC sells cakes at 4 dollars each and doughnuts at 7 dollars each.\nDetermine if there is a way to buy some of them for exactly N dollars. You can buy two or more doughnuts and two or more cakes, and you can also choose to buy zero doughnuts or zero cakes.\n\nConstraints\n\nN is an integer between 1 and 100, inclusive.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf there is a way to buy some cakes and some doughnuts for exactly N dollars, print Yes; otherwise, print No.\n\nSample Input 1\n\n11\n\nSample Output 1\n\nYes\n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\nSample Input 2\n\n40\n\nSample Output 2\n\nYes\n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\nSample Input 3\n\n3\n\nSample Output 3\n\nNo\n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than 3 dollars, so there is no such way.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 109, "cpu_time_ms": 88, "memory_kb": 8936}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s528393655", "group_id": "codeNet:p03286", "input_text": "(defvar *n* (read))\n\n(defvar *digits*\n (loop for n = *n* then (- (floor n 2))\n while (/= n 0)\n collect (mod n 2)))\n\n(setf *digits* (nreverse *digits*))\n\n\n(format t \"~{~a~}~%\" (if (zerop *n*)\n '(0)\n *digits*))\n", "language": "Lisp", "metadata": {"date": 1534038193, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03286.html", "problem_id": "p03286", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03286/input.txt", "sample_output_relpath": "derived/input_output/data/p03286/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03286/Lisp/s528393655.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s528393655", "user_id": "u390181802"}, "prompt_components": {"gold_output": "1011\n", "input_to_evaluate": "(defvar *n* (read))\n\n(defvar *digits*\n (loop for n = *n* then (- (floor n 2))\n while (/= n 0)\n collect (mod n 2)))\n\n(setf *digits* (nreverse *digits*))\n\n\n(format t \"~{~a~}~%\" (if (zerop *n*)\n '(0)\n *digits*))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nGiven an integer N, find the base -2 representation of N.\n\nHere, S is the base -2 representation of N when the following are all satisfied:\n\nS is a string consisting of 0 and 1.\n\nUnless S = 0, the initial character of S is 1.\n\nLet S = S_k S_{k-1} ... S_0, then S_0 \\times (-2)^0 + S_1 \\times (-2)^1 + ... + S_k \\times (-2)^k = N.\n\nIt can be proved that, for any integer M, the base -2 representation of M is uniquely determined.\n\nConstraints\n\nEvery value in input is integer.\n\n-10^9 \\leq N \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the base -2 representation of N.\n\nSample Input 1\n\n-9\n\nSample Output 1\n\n1011\n\nAs (-2)^0 + (-2)^1 + (-2)^3 = 1 + (-2) + (-8) = -9, 1011 is the base -2 representation of -9.\n\nSample Input 2\n\n123456789\n\nSample Output 2\n\n11000101011001101110100010101\n\nSample Input 3\n\n0\n\nSample Output 3\n\n0", "sample_input": "-9\n"}, "reference_outputs": ["1011\n"], "source_document_id": "p03286", "source_text": "Score : 300 points\n\nProblem Statement\n\nGiven an integer N, find the base -2 representation of N.\n\nHere, S is the base -2 representation of N when the following are all satisfied:\n\nS is a string consisting of 0 and 1.\n\nUnless S = 0, the initial character of S is 1.\n\nLet S = S_k S_{k-1} ... S_0, then S_0 \\times (-2)^0 + S_1 \\times (-2)^1 + ... + S_k \\times (-2)^k = N.\n\nIt can be proved that, for any integer M, the base -2 representation of M is uniquely determined.\n\nConstraints\n\nEvery value in input is integer.\n\n-10^9 \\leq N \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the base -2 representation of N.\n\nSample Input 1\n\n-9\n\nSample Output 1\n\n1011\n\nAs (-2)^0 + (-2)^1 + (-2)^3 = 1 + (-2) + (-8) = -9, 1011 is the base -2 representation of -9.\n\nSample Input 2\n\n123456789\n\nSample Output 2\n\n11000101011001101110100010101\n\nSample Input 3\n\n0\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 268, "cpu_time_ms": 108, "memory_kb": 12904}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s037227766", "group_id": "codeNet:p03288", "input_text": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n;; BEGIN_USE_PACKAGE\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((r (read)))\n (println (cond ((< r 1200) 'abc)\n ((< r 2800) 'arc)\n (t 'agc)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (5am:is\n (equal \"ABC\n\"\n (run \"1199\n\" nil)))\n (5am:is\n (equal \"ARC\n\"\n (run \"1200\n\" nil)))\n (5am:is\n (equal \"AGC\n\"\n (run \"4208\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1600763281, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03288.html", "problem_id": "p03288", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03288/input.txt", "sample_output_relpath": "derived/input_output/data/p03288/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03288/Lisp/s037227766.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s037227766", "user_id": "u352600849"}, "prompt_components": {"gold_output": "ABC\n", "input_to_evaluate": "(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (set-dispatch-macro-character #\\# #\\> #'cl-debug-print:debug-print-reader)\n\n(macrolet ((def-int (b)\n `(progn (deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))\n (deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))))\n (defs (&rest bits) `(progn ,@(mapcar (lambda (b) `(def-int ,b)) bits))))\n (defs 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n;; BEGIN_USE_PACKAGE\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((r (read)))\n (println (cond ((< r 1200) 'abc)\n ((< r 2800) 'arc)\n (t 'agc)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n#-swank\n(eval-when (:compile-toplevel)\n (when (and (boundp 'sb-c::*compiler-warning-count*)\n (> sb-c::*compiler-warning-count* 0))\n (sb-ext:quit :unix-status 1)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (5am:is\n (equal \"ABC\n\"\n (run \"1199\n\" nil)))\n (5am:is\n (equal \"ARC\n\"\n (run \"1200\n\" nil)))\n (5am:is\n (equal \"AGC\n\"\n (run \"4208\n\" nil))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nA programming competition site AtCode regularly holds programming contests.\n\nThe next contest on AtCode is called ABC, which is rated for contestants with ratings less than 1200.\n\nThe contest after the ABC is called ARC, which is rated for contestants with ratings less than 2800.\n\nThe contest after the ARC is called AGC, which is rated for all contestants.\n\nTakahashi's rating on AtCode is R. What is the next contest rated for him?\n\nConstraints\n\n0 ≤ R ≤ 4208\n\nR is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR\n\nOutput\n\nPrint the name of the next contest rated for Takahashi (ABC, ARC or AGC).\n\nSample Input 1\n\n1199\n\nSample Output 1\n\nABC\n\n1199 is less than 1200, so ABC will be rated.\n\nSample Input 2\n\n1200\n\nSample Output 2\n\nARC\n\n1200 is not less than 1200 and ABC will be unrated, but it is less than 2800 and ARC will be rated.\n\nSample Input 3\n\n4208\n\nSample Output 3\n\nAGC", "sample_input": "1199\n"}, "reference_outputs": ["ABC\n"], "source_document_id": "p03288", "source_text": "Score : 100 points\n\nProblem Statement\n\nA programming competition site AtCode regularly holds programming contests.\n\nThe next contest on AtCode is called ABC, which is rated for contestants with ratings less than 1200.\n\nThe contest after the ABC is called ARC, which is rated for contestants with ratings less than 2800.\n\nThe contest after the ARC is called AGC, which is rated for all contestants.\n\nTakahashi's rating on AtCode is R. What is the next contest rated for him?\n\nConstraints\n\n0 ≤ R ≤ 4208\n\nR is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR\n\nOutput\n\nPrint the name of the next contest rated for Takahashi (ABC, ARC or AGC).\n\nSample Input 1\n\n1199\n\nSample Output 1\n\nABC\n\n1199 is less than 1200, so ABC will be rated.\n\nSample Input 2\n\n1200\n\nSample Output 2\n\nARC\n\n1200 is not less than 1200 and ABC will be unrated, but it is less than 2800 and ARC will be rated.\n\nSample Input 3\n\n4208\n\nSample Output 3\n\nAGC", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3492, "cpu_time_ms": 15, "memory_kb": 23888}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s003309851", "group_id": "codeNet:p03288", "input_text": "(defvar R)\n(setf R (read))\n\n(cond\n ((< R 1200) (princ \"ABC\"))\n ((< R 2800) (princ \"ARC\"))\n (t (princ \"AGC\")) )", "language": "Lisp", "metadata": {"date": 1585311356, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03288.html", "problem_id": "p03288", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03288/input.txt", "sample_output_relpath": "derived/input_output/data/p03288/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03288/Lisp/s003309851.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s003309851", "user_id": "u334552723"}, "prompt_components": {"gold_output": "ABC\n", "input_to_evaluate": "(defvar R)\n(setf R (read))\n\n(cond\n ((< R 1200) (princ \"ABC\"))\n ((< R 2800) (princ \"ARC\"))\n (t (princ \"AGC\")) )", "problem_context": "Score : 100 points\n\nProblem Statement\n\nA programming competition site AtCode regularly holds programming contests.\n\nThe next contest on AtCode is called ABC, which is rated for contestants with ratings less than 1200.\n\nThe contest after the ABC is called ARC, which is rated for contestants with ratings less than 2800.\n\nThe contest after the ARC is called AGC, which is rated for all contestants.\n\nTakahashi's rating on AtCode is R. What is the next contest rated for him?\n\nConstraints\n\n0 ≤ R ≤ 4208\n\nR is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR\n\nOutput\n\nPrint the name of the next contest rated for Takahashi (ABC, ARC or AGC).\n\nSample Input 1\n\n1199\n\nSample Output 1\n\nABC\n\n1199 is less than 1200, so ABC will be rated.\n\nSample Input 2\n\n1200\n\nSample Output 2\n\nARC\n\n1200 is not less than 1200 and ABC will be unrated, but it is less than 2800 and ARC will be rated.\n\nSample Input 3\n\n4208\n\nSample Output 3\n\nAGC", "sample_input": "1199\n"}, "reference_outputs": ["ABC\n"], "source_document_id": "p03288", "source_text": "Score : 100 points\n\nProblem Statement\n\nA programming competition site AtCode regularly holds programming contests.\n\nThe next contest on AtCode is called ABC, which is rated for contestants with ratings less than 1200.\n\nThe contest after the ABC is called ARC, which is rated for contestants with ratings less than 2800.\n\nThe contest after the ARC is called AGC, which is rated for all contestants.\n\nTakahashi's rating on AtCode is R. What is the next contest rated for him?\n\nConstraints\n\n0 ≤ R ≤ 4208\n\nR is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR\n\nOutput\n\nPrint the name of the next contest rated for Takahashi (ABC, ARC or AGC).\n\nSample Input 1\n\n1199\n\nSample Output 1\n\nABC\n\n1199 is less than 1200, so ABC will be rated.\n\nSample Input 2\n\n1200\n\nSample Output 2\n\nARC\n\n1200 is not less than 1200 and ABC will be unrated, but it is less than 2800 and ARC will be rated.\n\nSample Input 3\n\n4208\n\nSample Output 3\n\nAGC", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 110, "cpu_time_ms": 19, "memory_kb": 3560}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s080842700", "group_id": "codeNet:p03288", "input_text": "(defun ans (r)\n (cond\n ((< r 1200) \"ABC\")\n ((< r 2800) \"ARC\")\n (t \"AGC\")))\n\n(format t \"~a~%\" (ans (read)))", "language": "Lisp", "metadata": {"date": 1569013769, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03288.html", "problem_id": "p03288", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03288/input.txt", "sample_output_relpath": "derived/input_output/data/p03288/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03288/Lisp/s080842700.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s080842700", "user_id": "u358554431"}, "prompt_components": {"gold_output": "ABC\n", "input_to_evaluate": "(defun ans (r)\n (cond\n ((< r 1200) \"ABC\")\n ((< r 2800) \"ARC\")\n (t \"AGC\")))\n\n(format t \"~a~%\" (ans (read)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nA programming competition site AtCode regularly holds programming contests.\n\nThe next contest on AtCode is called ABC, which is rated for contestants with ratings less than 1200.\n\nThe contest after the ABC is called ARC, which is rated for contestants with ratings less than 2800.\n\nThe contest after the ARC is called AGC, which is rated for all contestants.\n\nTakahashi's rating on AtCode is R. What is the next contest rated for him?\n\nConstraints\n\n0 ≤ R ≤ 4208\n\nR is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR\n\nOutput\n\nPrint the name of the next contest rated for Takahashi (ABC, ARC or AGC).\n\nSample Input 1\n\n1199\n\nSample Output 1\n\nABC\n\n1199 is less than 1200, so ABC will be rated.\n\nSample Input 2\n\n1200\n\nSample Output 2\n\nARC\n\n1200 is not less than 1200 and ABC will be unrated, but it is less than 2800 and ARC will be rated.\n\nSample Input 3\n\n4208\n\nSample Output 3\n\nAGC", "sample_input": "1199\n"}, "reference_outputs": ["ABC\n"], "source_document_id": "p03288", "source_text": "Score : 100 points\n\nProblem Statement\n\nA programming competition site AtCode regularly holds programming contests.\n\nThe next contest on AtCode is called ABC, which is rated for contestants with ratings less than 1200.\n\nThe contest after the ABC is called ARC, which is rated for contestants with ratings less than 2800.\n\nThe contest after the ARC is called AGC, which is rated for all contestants.\n\nTakahashi's rating on AtCode is R. What is the next contest rated for him?\n\nConstraints\n\n0 ≤ R ≤ 4208\n\nR is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR\n\nOutput\n\nPrint the name of the next contest rated for Takahashi (ABC, ARC or AGC).\n\nSample Input 1\n\n1199\n\nSample Output 1\n\nABC\n\n1199 is less than 1200, so ABC will be rated.\n\nSample Input 2\n\n1200\n\nSample Output 2\n\nARC\n\n1200 is not less than 1200 and ABC will be unrated, but it is less than 2800 and ARC will be rated.\n\nSample Input 3\n\n4208\n\nSample Output 3\n\nAGC", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 116, "cpu_time_ms": 8, "memory_kb": 3176}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s174465455", "group_id": "codeNet:p03288", "input_text": "(let ((r (read)))\n (cond ((< r 1200) (princ \"ABC\"))\n ((< r 2800) (princ \"ARC\"))\n (t (princ \"AGC\"))))", "language": "Lisp", "metadata": {"date": 1533517609, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03288.html", "problem_id": "p03288", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03288/input.txt", "sample_output_relpath": "derived/input_output/data/p03288/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03288/Lisp/s174465455.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s174465455", "user_id": "u956039157"}, "prompt_components": {"gold_output": "ABC\n", "input_to_evaluate": "(let ((r (read)))\n (cond ((< r 1200) (princ \"ABC\"))\n ((< r 2800) (princ \"ARC\"))\n (t (princ \"AGC\"))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nA programming competition site AtCode regularly holds programming contests.\n\nThe next contest on AtCode is called ABC, which is rated for contestants with ratings less than 1200.\n\nThe contest after the ABC is called ARC, which is rated for contestants with ratings less than 2800.\n\nThe contest after the ARC is called AGC, which is rated for all contestants.\n\nTakahashi's rating on AtCode is R. What is the next contest rated for him?\n\nConstraints\n\n0 ≤ R ≤ 4208\n\nR is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR\n\nOutput\n\nPrint the name of the next contest rated for Takahashi (ABC, ARC or AGC).\n\nSample Input 1\n\n1199\n\nSample Output 1\n\nABC\n\n1199 is less than 1200, so ABC will be rated.\n\nSample Input 2\n\n1200\n\nSample Output 2\n\nARC\n\n1200 is not less than 1200 and ABC will be unrated, but it is less than 2800 and ARC will be rated.\n\nSample Input 3\n\n4208\n\nSample Output 3\n\nAGC", "sample_input": "1199\n"}, "reference_outputs": ["ABC\n"], "source_document_id": "p03288", "source_text": "Score : 100 points\n\nProblem Statement\n\nA programming competition site AtCode regularly holds programming contests.\n\nThe next contest on AtCode is called ABC, which is rated for contestants with ratings less than 1200.\n\nThe contest after the ABC is called ARC, which is rated for contestants with ratings less than 2800.\n\nThe contest after the ARC is called AGC, which is rated for all contestants.\n\nTakahashi's rating on AtCode is R. What is the next contest rated for him?\n\nConstraints\n\n0 ≤ R ≤ 4208\n\nR is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR\n\nOutput\n\nPrint the name of the next contest rated for Takahashi (ABC, ARC or AGC).\n\nSample Input 1\n\n1199\n\nSample Output 1\n\nABC\n\n1199 is less than 1200, so ABC will be rated.\n\nSample Input 2\n\n1200\n\nSample Output 2\n\nARC\n\n1200 is not less than 1200 and ABC will be unrated, but it is less than 2800 and ARC will be rated.\n\nSample Input 3\n\n4208\n\nSample Output 3\n\nAGC", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 115, "cpu_time_ms": 288, "memory_kb": 8936}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s407078507", "group_id": "codeNet:p03289", "input_text": "(let*((s(concatenate 'list(read-line)))(c 0)(a(car s)))\n (dolist(i(cdr s))(if(char< i #\\a)(incf c(if(char= i #\\C)1 2))))\n (princ(if(or(/= c 1)(char/= a #\\A)(char<(nth 1 s)#\\a)(char<(car(last s))#\\a))\"WA\"\"AC\")))\n", "language": "Lisp", "metadata": {"date": 1534231191, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03289.html", "problem_id": "p03289", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03289/input.txt", "sample_output_relpath": "derived/input_output/data/p03289/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03289/Lisp/s407078507.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s407078507", "user_id": "u657913472"}, "prompt_components": {"gold_output": "AC\n", "input_to_evaluate": "(let*((s(concatenate 'list(read-line)))(c 0)(a(car s)))\n (dolist(i(cdr s))(if(char< i #\\a)(incf c(if(char= i #\\C)1 2))))\n (princ(if(or(/= c 1)(char/= a #\\A)(char<(nth 1 s)#\\a)(char<(car(last s))#\\a))\"WA\"\"AC\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given a string S. Each character of S is uppercase or lowercase English letter.\nDetermine if S satisfies all of the following conditions:\n\nThe initial character of S is an uppercase A.\n\nThere is exactly one occurrence of C between the third character from the beginning and the second to last character (inclusive).\n\nAll letters except the A and C mentioned above are lowercase.\n\nConstraints\n\n4 ≤ |S| ≤ 10 (|S| is the length of the string S.)\n\nEach character of S is uppercase or lowercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S satisfies all of the conditions in the problem statement, print AC; otherwise, print WA.\n\nSample Input 1\n\nAtCoder\n\nSample Output 1\n\nAC\n\nThe first letter is A, the third letter is C and the remaining letters are all lowercase, so all the conditions are satisfied.\n\nSample Input 2\n\nACoder\n\nSample Output 2\n\nWA\n\nThe second letter should not be C.\n\nSample Input 3\n\nAcycliC\n\nSample Output 3\n\nWA\n\nThe last letter should not be C, either.\n\nSample Input 4\n\nAtCoCo\n\nSample Output 4\n\nWA\n\nThere should not be two or more occurrences of C.\n\nSample Input 5\n\nAtcoder\n\nSample Output 5\n\nWA\n\nThe number of C should not be zero, either.", "sample_input": "AtCoder\n"}, "reference_outputs": ["AC\n"], "source_document_id": "p03289", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given a string S. Each character of S is uppercase or lowercase English letter.\nDetermine if S satisfies all of the following conditions:\n\nThe initial character of S is an uppercase A.\n\nThere is exactly one occurrence of C between the third character from the beginning and the second to last character (inclusive).\n\nAll letters except the A and C mentioned above are lowercase.\n\nConstraints\n\n4 ≤ |S| ≤ 10 (|S| is the length of the string S.)\n\nEach character of S is uppercase or lowercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S satisfies all of the conditions in the problem statement, print AC; otherwise, print WA.\n\nSample Input 1\n\nAtCoder\n\nSample Output 1\n\nAC\n\nThe first letter is A, the third letter is C and the remaining letters are all lowercase, so all the conditions are satisfied.\n\nSample Input 2\n\nACoder\n\nSample Output 2\n\nWA\n\nThe second letter should not be C.\n\nSample Input 3\n\nAcycliC\n\nSample Output 3\n\nWA\n\nThe last letter should not be C, either.\n\nSample Input 4\n\nAtCoCo\n\nSample Output 4\n\nWA\n\nThere should not be two or more occurrences of C.\n\nSample Input 5\n\nAtcoder\n\nSample Output 5\n\nWA\n\nThe number of C should not be zero, either.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 213, "cpu_time_ms": 109, "memory_kb": 11236}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s954190117", "group_id": "codeNet:p03289", "input_text": "(let ((s (read-line)))\n (princ (if (and (char= (char s 0) #\\A)\n (= (count #\\C s :start 2 :end (1- (length s)) :test #'char=) 1)\n (string= (remove-if #'lower-case-p (remove #\\C (subseq s 1) :test #'char= :count 1)) \"\"))\n \"AC\"\n \"WA\")))", "language": "Lisp", "metadata": {"date": 1533688820, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03289.html", "problem_id": "p03289", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03289/input.txt", "sample_output_relpath": "derived/input_output/data/p03289/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03289/Lisp/s954190117.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s954190117", "user_id": "u913204306"}, "prompt_components": {"gold_output": "AC\n", "input_to_evaluate": "(let ((s (read-line)))\n (princ (if (and (char= (char s 0) #\\A)\n (= (count #\\C s :start 2 :end (1- (length s)) :test #'char=) 1)\n (string= (remove-if #'lower-case-p (remove #\\C (subseq s 1) :test #'char= :count 1)) \"\"))\n \"AC\"\n \"WA\")))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given a string S. Each character of S is uppercase or lowercase English letter.\nDetermine if S satisfies all of the following conditions:\n\nThe initial character of S is an uppercase A.\n\nThere is exactly one occurrence of C between the third character from the beginning and the second to last character (inclusive).\n\nAll letters except the A and C mentioned above are lowercase.\n\nConstraints\n\n4 ≤ |S| ≤ 10 (|S| is the length of the string S.)\n\nEach character of S is uppercase or lowercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S satisfies all of the conditions in the problem statement, print AC; otherwise, print WA.\n\nSample Input 1\n\nAtCoder\n\nSample Output 1\n\nAC\n\nThe first letter is A, the third letter is C and the remaining letters are all lowercase, so all the conditions are satisfied.\n\nSample Input 2\n\nACoder\n\nSample Output 2\n\nWA\n\nThe second letter should not be C.\n\nSample Input 3\n\nAcycliC\n\nSample Output 3\n\nWA\n\nThe last letter should not be C, either.\n\nSample Input 4\n\nAtCoCo\n\nSample Output 4\n\nWA\n\nThere should not be two or more occurrences of C.\n\nSample Input 5\n\nAtcoder\n\nSample Output 5\n\nWA\n\nThe number of C should not be zero, either.", "sample_input": "AtCoder\n"}, "reference_outputs": ["AC\n"], "source_document_id": "p03289", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given a string S. Each character of S is uppercase or lowercase English letter.\nDetermine if S satisfies all of the following conditions:\n\nThe initial character of S is an uppercase A.\n\nThere is exactly one occurrence of C between the third character from the beginning and the second to last character (inclusive).\n\nAll letters except the A and C mentioned above are lowercase.\n\nConstraints\n\n4 ≤ |S| ≤ 10 (|S| is the length of the string S.)\n\nEach character of S is uppercase or lowercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S satisfies all of the conditions in the problem statement, print AC; otherwise, print WA.\n\nSample Input 1\n\nAtCoder\n\nSample Output 1\n\nAC\n\nThe first letter is A, the third letter is C and the remaining letters are all lowercase, so all the conditions are satisfied.\n\nSample Input 2\n\nACoder\n\nSample Output 2\n\nWA\n\nThe second letter should not be C.\n\nSample Input 3\n\nAcycliC\n\nSample Output 3\n\nWA\n\nThe last letter should not be C, either.\n\nSample Input 4\n\nAtCoCo\n\nSample Output 4\n\nWA\n\nThere should not be two or more occurrences of C.\n\nSample Input 5\n\nAtcoder\n\nSample Output 5\n\nWA\n\nThe number of C should not be zero, either.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 292, "cpu_time_ms": 165, "memory_kb": 12136}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s931844612", "group_id": "codeNet:p03289", "input_text": "(defun upcase-less-string-p (str)\n (labels ((capital-p (chr)\n (equal (char-upcase chr) chr)))\n (if (characterp str)\n (if (capital-p str)\n nil\n t)\n (if (capital-p (char str 0))\n nil\n (upcase-less-string-p (subseq str 1))))))\n\n(let ((s (coerce (read-line) 'list)))\n (if (and (equal (car s) #\\A)\n (equal (count #\\C s) 1)\n (< 1 (position #\\C s))\n (< (position #\\C s) (1- (length s)))\n (eval (cons 'and\n (mapcar #'upcase-less-string-p\n (append (subseq s 1 (position #\\C s))\n (subseq s (1+ (position #\\C s))))))))\n (princ \"AC\")\n (princ \"WA\")))", "language": "Lisp", "metadata": {"date": 1533522055, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03289.html", "problem_id": "p03289", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03289/input.txt", "sample_output_relpath": "derived/input_output/data/p03289/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03289/Lisp/s931844612.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s931844612", "user_id": "u956039157"}, "prompt_components": {"gold_output": "AC\n", "input_to_evaluate": "(defun upcase-less-string-p (str)\n (labels ((capital-p (chr)\n (equal (char-upcase chr) chr)))\n (if (characterp str)\n (if (capital-p str)\n nil\n t)\n (if (capital-p (char str 0))\n nil\n (upcase-less-string-p (subseq str 1))))))\n\n(let ((s (coerce (read-line) 'list)))\n (if (and (equal (car s) #\\A)\n (equal (count #\\C s) 1)\n (< 1 (position #\\C s))\n (< (position #\\C s) (1- (length s)))\n (eval (cons 'and\n (mapcar #'upcase-less-string-p\n (append (subseq s 1 (position #\\C s))\n (subseq s (1+ (position #\\C s))))))))\n (princ \"AC\")\n (princ \"WA\")))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given a string S. Each character of S is uppercase or lowercase English letter.\nDetermine if S satisfies all of the following conditions:\n\nThe initial character of S is an uppercase A.\n\nThere is exactly one occurrence of C between the third character from the beginning and the second to last character (inclusive).\n\nAll letters except the A and C mentioned above are lowercase.\n\nConstraints\n\n4 ≤ |S| ≤ 10 (|S| is the length of the string S.)\n\nEach character of S is uppercase or lowercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S satisfies all of the conditions in the problem statement, print AC; otherwise, print WA.\n\nSample Input 1\n\nAtCoder\n\nSample Output 1\n\nAC\n\nThe first letter is A, the third letter is C and the remaining letters are all lowercase, so all the conditions are satisfied.\n\nSample Input 2\n\nACoder\n\nSample Output 2\n\nWA\n\nThe second letter should not be C.\n\nSample Input 3\n\nAcycliC\n\nSample Output 3\n\nWA\n\nThe last letter should not be C, either.\n\nSample Input 4\n\nAtCoCo\n\nSample Output 4\n\nWA\n\nThere should not be two or more occurrences of C.\n\nSample Input 5\n\nAtcoder\n\nSample Output 5\n\nWA\n\nThe number of C should not be zero, either.", "sample_input": "AtCoder\n"}, "reference_outputs": ["AC\n"], "source_document_id": "p03289", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given a string S. Each character of S is uppercase or lowercase English letter.\nDetermine if S satisfies all of the following conditions:\n\nThe initial character of S is an uppercase A.\n\nThere is exactly one occurrence of C between the third character from the beginning and the second to last character (inclusive).\n\nAll letters except the A and C mentioned above are lowercase.\n\nConstraints\n\n4 ≤ |S| ≤ 10 (|S| is the length of the string S.)\n\nEach character of S is uppercase or lowercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S satisfies all of the conditions in the problem statement, print AC; otherwise, print WA.\n\nSample Input 1\n\nAtCoder\n\nSample Output 1\n\nAC\n\nThe first letter is A, the third letter is C and the remaining letters are all lowercase, so all the conditions are satisfied.\n\nSample Input 2\n\nACoder\n\nSample Output 2\n\nWA\n\nThe second letter should not be C.\n\nSample Input 3\n\nAcycliC\n\nSample Output 3\n\nWA\n\nThe last letter should not be C, either.\n\nSample Input 4\n\nAtCoCo\n\nSample Output 4\n\nWA\n\nThere should not be two or more occurrences of C.\n\nSample Input 5\n\nAtcoder\n\nSample Output 5\n\nWA\n\nThe number of C should not be zero, either.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 752, "cpu_time_ms": 830, "memory_kb": 15720}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s265082166", "group_id": "codeNet:p03290", "input_text": "(defvar +inf+ most-positive-fixnum)\n\n(defun most-difficult-problem-index (d bits)\n (loop for i from (1- d) downto 0\n if (not (logbitp i bits))\n do (return i)))\n\n(defun bits-problem-counts (d bits problems)\n (loop for i from 0 to d\n if (logbitp i bits)\n sum (car (nth i problems))))\n\n(defun solve (d g problems)\n (loop for bits from 0 below (expt 2 d)\n for points = (loop for i from 0 below d\n if (logbitp i bits)\n sum (destructuring-bind (count . bonus)\n (nth i problems)\n (+ bonus (* count (1+ i) 100))))\n minimize\n (cond\n ((<= g points)\n (bits-problem-counts d bits problems))\n ((most-difficult-problem-index d bits)\n (let ((j (most-difficult-problem-index d bits)))\n (let ((extra-counts (ceiling (- g points)\n (* 100 (1+ j)))))\n (if (<= extra-counts (car (nth j problems)))\n (+ (bits-problem-counts d bits problems)\n extra-counts)\n +inf+))))\n (t +inf+))))\n\n#-swank\n(let* ((d (read))\n (g (read))\n (problems (loop repeat d\n collect (cons (read) (read)))))\n (format t \"~A~%\" (solve d g problems)))\n", "language": "Lisp", "metadata": {"date": 1579921257, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03290.html", "problem_id": "p03290", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03290/input.txt", "sample_output_relpath": "derived/input_output/data/p03290/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03290/Lisp/s265082166.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s265082166", "user_id": "u202886318"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defvar +inf+ most-positive-fixnum)\n\n(defun most-difficult-problem-index (d bits)\n (loop for i from (1- d) downto 0\n if (not (logbitp i bits))\n do (return i)))\n\n(defun bits-problem-counts (d bits problems)\n (loop for i from 0 to d\n if (logbitp i bits)\n sum (car (nth i problems))))\n\n(defun solve (d g problems)\n (loop for bits from 0 below (expt 2 d)\n for points = (loop for i from 0 below d\n if (logbitp i bits)\n sum (destructuring-bind (count . bonus)\n (nth i problems)\n (+ bonus (* count (1+ i) 100))))\n minimize\n (cond\n ((<= g points)\n (bits-problem-counts d bits problems))\n ((most-difficult-problem-index d bits)\n (let ((j (most-difficult-problem-index d bits)))\n (let ((extra-counts (ceiling (- g points)\n (* 100 (1+ j)))))\n (if (<= extra-counts (car (nth j problems)))\n (+ (bits-problem-counts d bits problems)\n extra-counts)\n +inf+))))\n (t +inf+))))\n\n#-swank\n(let* ((d (read))\n (g (read))\n (problems (loop repeat d\n collect (cons (read) (read)))))\n (format t \"~A~%\" (solve d g problems)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nA programming competition site AtCode provides algorithmic problems.\nEach problem is allocated a score based on its difficulty.\nCurrently, for each integer i between 1 and D (inclusive), there are p_i problems with a score of 100i points.\nThese p_1 + … + p_D problems are all of the problems available on AtCode.\n\nA user of AtCode has a value called total score.\nThe total score of a user is the sum of the following two elements:\n\nBase score: the sum of the scores of all problems solved by the user.\n\nPerfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).\n\nTakahashi, who is the new user of AtCode, has not solved any problem.\nHis objective is to have a total score of G or more points.\nAt least how many problems does he need to solve for this objective?\n\nConstraints\n\n1 ≤ D ≤ 10\n\n1 ≤ p_i ≤ 100\n\n100 ≤ c_i ≤ 10^6\n\n100 ≤ G\n\nAll values in input are integers.\n\nc_i and G are all multiples of 100.\n\nIt is possible to have a total score of G or more points.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nD G\np_1 c_1\n:\np_D c_D\n\nOutput\n\nPrint the minimum number of problems that needs to be solved in order to have a total score of G or more points. Note that this objective is always achievable (see Constraints).\n\nSample Input 1\n\n2 700\n3 500\n5 800\n\nSample Output 1\n\n3\n\nIn this case, there are three problems each with 100 points and five problems each with 200 points. The perfect bonus for solving all the 100-point problems is 500 points, and the perfect bonus for solving all the 200-point problems is 800 points. Takahashi's objective is to have a total score of 700 points or more.\n\nOne way to achieve this objective is to solve four 200-point problems and earn a base score of 800 points. However, if we solve three 100-point problems, we can earn the perfect bonus of 500 points in addition to the base score of 300 points, for a total score of 800 points, and we can achieve the objective with fewer problems.\n\nSample Input 2\n\n2 2000\n3 500\n5 800\n\nSample Output 2\n\n7\n\nThis case is similar to Sample Input 1, but the Takahashi's objective this time is 2000 points or more. In this case, we inevitably need to solve all five 200-point problems, and by solving two 100-point problems additionally we have the total score of 2000 points.\n\nSample Input 3\n\n2 400\n3 500\n5 800\n\nSample Output 3\n\n2\n\nThis case is again similar to Sample Input 1, but the Takahashi's objective this time is 400 points or more. In this case, we only need to solve two 200-point problems to achieve the objective.\n\nSample Input 4\n\n5 25000\n20 1000\n40 1000\n50 1000\n30 1000\n1 1000\n\nSample Output 4\n\n66\n\nThere is only one 500-point problem, but the perfect bonus can be earned even in such a case.", "sample_input": "2 700\n3 500\n5 800\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03290", "source_text": "Score : 300 points\n\nProblem Statement\n\nA programming competition site AtCode provides algorithmic problems.\nEach problem is allocated a score based on its difficulty.\nCurrently, for each integer i between 1 and D (inclusive), there are p_i problems with a score of 100i points.\nThese p_1 + … + p_D problems are all of the problems available on AtCode.\n\nA user of AtCode has a value called total score.\nThe total score of a user is the sum of the following two elements:\n\nBase score: the sum of the scores of all problems solved by the user.\n\nPerfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).\n\nTakahashi, who is the new user of AtCode, has not solved any problem.\nHis objective is to have a total score of G or more points.\nAt least how many problems does he need to solve for this objective?\n\nConstraints\n\n1 ≤ D ≤ 10\n\n1 ≤ p_i ≤ 100\n\n100 ≤ c_i ≤ 10^6\n\n100 ≤ G\n\nAll values in input are integers.\n\nc_i and G are all multiples of 100.\n\nIt is possible to have a total score of G or more points.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nD G\np_1 c_1\n:\np_D c_D\n\nOutput\n\nPrint the minimum number of problems that needs to be solved in order to have a total score of G or more points. Note that this objective is always achievable (see Constraints).\n\nSample Input 1\n\n2 700\n3 500\n5 800\n\nSample Output 1\n\n3\n\nIn this case, there are three problems each with 100 points and five problems each with 200 points. The perfect bonus for solving all the 100-point problems is 500 points, and the perfect bonus for solving all the 200-point problems is 800 points. Takahashi's objective is to have a total score of 700 points or more.\n\nOne way to achieve this objective is to solve four 200-point problems and earn a base score of 800 points. However, if we solve three 100-point problems, we can earn the perfect bonus of 500 points in addition to the base score of 300 points, for a total score of 800 points, and we can achieve the objective with fewer problems.\n\nSample Input 2\n\n2 2000\n3 500\n5 800\n\nSample Output 2\n\n7\n\nThis case is similar to Sample Input 1, but the Takahashi's objective this time is 2000 points or more. In this case, we inevitably need to solve all five 200-point problems, and by solving two 100-point problems additionally we have the total score of 2000 points.\n\nSample Input 3\n\n2 400\n3 500\n5 800\n\nSample Output 3\n\n2\n\nThis case is again similar to Sample Input 1, but the Takahashi's objective this time is 400 points or more. In this case, we only need to solve two 200-point problems to achieve the objective.\n\nSample Input 4\n\n5 25000\n20 1000\n40 1000\n50 1000\n30 1000\n1 1000\n\nSample Output 4\n\n66\n\nThere is only one 500-point problem, but the perfect bonus can be earned even in such a case.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1374, "cpu_time_ms": 158, "memory_kb": 18788}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s502239985", "group_id": "codeNet:p03290", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(defmacro split-ints-and-bind (vars string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str (gensym \"STR\")))\n (labels ((expand (vars &optional (init-pos1 t))\n\t (if (null vars)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str :start ,pos1 :test #'char=))\n\t\t\t (,(car vars) (parse-integer ,str :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr vars) nil))))))\n `(let ((,str ,string))\n (declare (string ,str))\n\t ,@(expand vars)))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(defun main ()\n (let* ((d (read))\n (required-score (floor (read) 100))\n (ps (make-array d :element-type 'uint32))\n (max-scores (make-array d :element-type 'uint32)))\n (dotimes (i d)\n (split-ints-and-bind (p c) (read-line)\n (setf (aref ps i) p\n (aref max-scores i) (+ (floor c 100) (* p (+ i 1))))))\n (let ((min-num most-positive-fixnum))\n (dotimes (bits (expt 2 d))\n (let ((num 0)\n (score 0))\n (dotimes (i d)\n (when (= 1 (ldb (byte 1 i) bits))\n (incf score (aref max-scores i))\n (incf num (aref ps i))))\n (if (>= score required-score)\n (setf min-num (min num min-num))\n (let ((idx -1)\n (delta most-positive-fixnum))\n (dotimes (i d)\n (let ((tmp-delta (ceiling (max 0 (- required-score score)) (+ i 1))))\n (when (and (zerop (ldb (byte 1 i) bits))\n (< tmp-delta (aref ps i))\n (< tmp-delta delta))\n (setf idx i\n delta tmp-delta))))\n (incf num delta)\n (when (and (/= idx -1)\n (< num min-num))\n (setf min-num num))))))\n (println min-num))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1547591150, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03290.html", "problem_id": "p03290", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03290/input.txt", "sample_output_relpath": "derived/input_output/data/p03290/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03290/Lisp/s502239985.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s502239985", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n(defmacro split-ints-and-bind (vars string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str (gensym \"STR\")))\n (labels ((expand (vars &optional (init-pos1 t))\n\t (if (null vars)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str :start ,pos1 :test #'char=))\n\t\t\t (,(car vars) (parse-integer ,str :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr vars) nil))))))\n `(let ((,str ,string))\n (declare (string ,str))\n\t ,@(expand vars)))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(defun main ()\n (let* ((d (read))\n (required-score (floor (read) 100))\n (ps (make-array d :element-type 'uint32))\n (max-scores (make-array d :element-type 'uint32)))\n (dotimes (i d)\n (split-ints-and-bind (p c) (read-line)\n (setf (aref ps i) p\n (aref max-scores i) (+ (floor c 100) (* p (+ i 1))))))\n (let ((min-num most-positive-fixnum))\n (dotimes (bits (expt 2 d))\n (let ((num 0)\n (score 0))\n (dotimes (i d)\n (when (= 1 (ldb (byte 1 i) bits))\n (incf score (aref max-scores i))\n (incf num (aref ps i))))\n (if (>= score required-score)\n (setf min-num (min num min-num))\n (let ((idx -1)\n (delta most-positive-fixnum))\n (dotimes (i d)\n (let ((tmp-delta (ceiling (max 0 (- required-score score)) (+ i 1))))\n (when (and (zerop (ldb (byte 1 i) bits))\n (< tmp-delta (aref ps i))\n (< tmp-delta delta))\n (setf idx i\n delta tmp-delta))))\n (incf num delta)\n (when (and (/= idx -1)\n (< num min-num))\n (setf min-num num))))))\n (println min-num))))\n\n#-swank(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nA programming competition site AtCode provides algorithmic problems.\nEach problem is allocated a score based on its difficulty.\nCurrently, for each integer i between 1 and D (inclusive), there are p_i problems with a score of 100i points.\nThese p_1 + … + p_D problems are all of the problems available on AtCode.\n\nA user of AtCode has a value called total score.\nThe total score of a user is the sum of the following two elements:\n\nBase score: the sum of the scores of all problems solved by the user.\n\nPerfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).\n\nTakahashi, who is the new user of AtCode, has not solved any problem.\nHis objective is to have a total score of G or more points.\nAt least how many problems does he need to solve for this objective?\n\nConstraints\n\n1 ≤ D ≤ 10\n\n1 ≤ p_i ≤ 100\n\n100 ≤ c_i ≤ 10^6\n\n100 ≤ G\n\nAll values in input are integers.\n\nc_i and G are all multiples of 100.\n\nIt is possible to have a total score of G or more points.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nD G\np_1 c_1\n:\np_D c_D\n\nOutput\n\nPrint the minimum number of problems that needs to be solved in order to have a total score of G or more points. Note that this objective is always achievable (see Constraints).\n\nSample Input 1\n\n2 700\n3 500\n5 800\n\nSample Output 1\n\n3\n\nIn this case, there are three problems each with 100 points and five problems each with 200 points. The perfect bonus for solving all the 100-point problems is 500 points, and the perfect bonus for solving all the 200-point problems is 800 points. Takahashi's objective is to have a total score of 700 points or more.\n\nOne way to achieve this objective is to solve four 200-point problems and earn a base score of 800 points. However, if we solve three 100-point problems, we can earn the perfect bonus of 500 points in addition to the base score of 300 points, for a total score of 800 points, and we can achieve the objective with fewer problems.\n\nSample Input 2\n\n2 2000\n3 500\n5 800\n\nSample Output 2\n\n7\n\nThis case is similar to Sample Input 1, but the Takahashi's objective this time is 2000 points or more. In this case, we inevitably need to solve all five 200-point problems, and by solving two 100-point problems additionally we have the total score of 2000 points.\n\nSample Input 3\n\n2 400\n3 500\n5 800\n\nSample Output 3\n\n2\n\nThis case is again similar to Sample Input 1, but the Takahashi's objective this time is 400 points or more. In this case, we only need to solve two 200-point problems to achieve the objective.\n\nSample Input 4\n\n5 25000\n20 1000\n40 1000\n50 1000\n30 1000\n1 1000\n\nSample Output 4\n\n66\n\nThere is only one 500-point problem, but the perfect bonus can be earned even in such a case.", "sample_input": "2 700\n3 500\n5 800\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03290", "source_text": "Score : 300 points\n\nProblem Statement\n\nA programming competition site AtCode provides algorithmic problems.\nEach problem is allocated a score based on its difficulty.\nCurrently, for each integer i between 1 and D (inclusive), there are p_i problems with a score of 100i points.\nThese p_1 + … + p_D problems are all of the problems available on AtCode.\n\nA user of AtCode has a value called total score.\nThe total score of a user is the sum of the following two elements:\n\nBase score: the sum of the scores of all problems solved by the user.\n\nPerfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).\n\nTakahashi, who is the new user of AtCode, has not solved any problem.\nHis objective is to have a total score of G or more points.\nAt least how many problems does he need to solve for this objective?\n\nConstraints\n\n1 ≤ D ≤ 10\n\n1 ≤ p_i ≤ 100\n\n100 ≤ c_i ≤ 10^6\n\n100 ≤ G\n\nAll values in input are integers.\n\nc_i and G are all multiples of 100.\n\nIt is possible to have a total score of G or more points.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nD G\np_1 c_1\n:\np_D c_D\n\nOutput\n\nPrint the minimum number of problems that needs to be solved in order to have a total score of G or more points. Note that this objective is always achievable (see Constraints).\n\nSample Input 1\n\n2 700\n3 500\n5 800\n\nSample Output 1\n\n3\n\nIn this case, there are three problems each with 100 points and five problems each with 200 points. The perfect bonus for solving all the 100-point problems is 500 points, and the perfect bonus for solving all the 200-point problems is 800 points. Takahashi's objective is to have a total score of 700 points or more.\n\nOne way to achieve this objective is to solve four 200-point problems and earn a base score of 800 points. However, if we solve three 100-point problems, we can earn the perfect bonus of 500 points in addition to the base score of 300 points, for a total score of 800 points, and we can achieve the objective with fewer problems.\n\nSample Input 2\n\n2 2000\n3 500\n5 800\n\nSample Output 2\n\n7\n\nThis case is similar to Sample Input 1, but the Takahashi's objective this time is 2000 points or more. In this case, we inevitably need to solve all five 200-point problems, and by solving two 100-point problems additionally we have the total score of 2000 points.\n\nSample Input 3\n\n2 400\n3 500\n5 800\n\nSample Output 3\n\n2\n\nThis case is again similar to Sample Input 1, but the Takahashi's objective this time is 400 points or more. In this case, we only need to solve two 200-point problems to achieve the objective.\n\nSample Input 4\n\n5 25000\n20 1000\n40 1000\n50 1000\n30 1000\n1 1000\n\nSample Output 4\n\n66\n\nThere is only one 500-point problem, but the perfect bonus can be earned even in such a case.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3019, "cpu_time_ms": 234, "memory_kb": 26596}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s933975725", "group_id": "codeNet:p03290", "input_text": ";; -*- coding:utf-8 -*-\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 1))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))))\n\n(defmacro print-line (obj &optional (stream '*standard-output*))\n `(prog1 (princ ,obj ,stream) (terpri ,stream)))\n\n\n;; Hauptteil\n\n(defmacro split-and-bind (arg-lst string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str-evaled (gensym \"STR\")))\n (labels ((expand (arg-lst &optional (init-pos1 t))\n\t (if (null arg-lst)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str-evaled :start ,pos1 :test #'char=))\n\t\t\t (,(car arg-lst) (parse-integer ,str-evaled :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr arg-lst) nil))))))\n `(let ((,str-evaled ,string))\n\t ,@(expand arg-lst)))))\n\n(deftype uint nil `(integer 0 ,(expt 10 9)))\n(defstruct problem\n i p c)\n(defun get-complete-score (prob)\n (+ (* 100 (problem-i prob) (problem-p prob))\n (problem-c prob)))\n\n(defun main ()\n (let* ((d (read))\n (g (read))\n (problem-lst\n (sort (loop for i from 1 to d\n collect (split-and-bind (p c) (read-line)\n (make-problem :i i :p p :c c)))\n #'>=\n :key #'(lambda (prob)\n (with-slots (i p c) prob\n (/ (+ (* 100 i p) c)\n (float p)))))))\n (print-line (solve problem-lst g 0))))\n\n(defun solve (lst max-score num)\n (if (null lst)\n num\n (let ((comp (get-complete-score (car lst))))\n (if (> comp max-score)\n (solve-latter lst max-score num)\n (solve (cdr lst)\n (- max-score comp)\n (+ num (problem-p (car lst))))))))\n\n(defun solve-latter (lst rem-score num)\n (+ num\n (min (loop for prob in lst\n minimize (with-slots (i p c) prob\n (let ((p-needed (ceiling rem-score (* 100 i))))\n (if (> p-needed p)\n most-positive-fixnum\n p-needed))))\n (loop for prob in lst\n minimize (if (> (get-complete-score prob) rem-score)\n (problem-p prob)\n most-positive-fixnum)))))\n#-swank(main)\n\n\n;; Für Test\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank\n(defun test ()\n (with-input-from-string (*standard-input* (delete #\\return (get-clipbrd)))\n (main)))\n\n\n;; Für Benchmark\n#+swank(defparameter *this-path* *load-pathname*)\n#+swank(defparameter *this-dir-path* (uiop:pathname-directory-pathname *this-path*))\n#+swank(defparameter *dat-path* (merge-pathnames \"test.dat\" *this-dir-path*))\n\n#+swank\n(defun gendat ()\n (with-open-file (out *dat-path*\n\t\t :direction :output :if-exists :supersede)\n ))\n\n#+swank\n(defun bench ()\n (let ((*standard-output* (make-broadcast-stream)))\n (with-open-file (*standard-input* *dat-path*)\n (time (main)))))\n", "language": "Lisp", "metadata": {"date": 1534033660, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03290.html", "problem_id": "p03290", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03290/input.txt", "sample_output_relpath": "derived/input_output/data/p03290/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03290/Lisp/s933975725.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s933975725", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; -*- coding:utf-8 -*-\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 1))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))))\n\n(defmacro print-line (obj &optional (stream '*standard-output*))\n `(prog1 (princ ,obj ,stream) (terpri ,stream)))\n\n\n;; Hauptteil\n\n(defmacro split-and-bind (arg-lst string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str-evaled (gensym \"STR\")))\n (labels ((expand (arg-lst &optional (init-pos1 t))\n\t (if (null arg-lst)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str-evaled :start ,pos1 :test #'char=))\n\t\t\t (,(car arg-lst) (parse-integer ,str-evaled :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr arg-lst) nil))))))\n `(let ((,str-evaled ,string))\n\t ,@(expand arg-lst)))))\n\n(deftype uint nil `(integer 0 ,(expt 10 9)))\n(defstruct problem\n i p c)\n(defun get-complete-score (prob)\n (+ (* 100 (problem-i prob) (problem-p prob))\n (problem-c prob)))\n\n(defun main ()\n (let* ((d (read))\n (g (read))\n (problem-lst\n (sort (loop for i from 1 to d\n collect (split-and-bind (p c) (read-line)\n (make-problem :i i :p p :c c)))\n #'>=\n :key #'(lambda (prob)\n (with-slots (i p c) prob\n (/ (+ (* 100 i p) c)\n (float p)))))))\n (print-line (solve problem-lst g 0))))\n\n(defun solve (lst max-score num)\n (if (null lst)\n num\n (let ((comp (get-complete-score (car lst))))\n (if (> comp max-score)\n (solve-latter lst max-score num)\n (solve (cdr lst)\n (- max-score comp)\n (+ num (problem-p (car lst))))))))\n\n(defun solve-latter (lst rem-score num)\n (+ num\n (min (loop for prob in lst\n minimize (with-slots (i p c) prob\n (let ((p-needed (ceiling rem-score (* 100 i))))\n (if (> p-needed p)\n most-positive-fixnum\n p-needed))))\n (loop for prob in lst\n minimize (if (> (get-complete-score prob) rem-score)\n (problem-p prob)\n most-positive-fixnum)))))\n#-swank(main)\n\n\n;; Für Test\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank\n(defun test ()\n (with-input-from-string (*standard-input* (delete #\\return (get-clipbrd)))\n (main)))\n\n\n;; Für Benchmark\n#+swank(defparameter *this-path* *load-pathname*)\n#+swank(defparameter *this-dir-path* (uiop:pathname-directory-pathname *this-path*))\n#+swank(defparameter *dat-path* (merge-pathnames \"test.dat\" *this-dir-path*))\n\n#+swank\n(defun gendat ()\n (with-open-file (out *dat-path*\n\t\t :direction :output :if-exists :supersede)\n ))\n\n#+swank\n(defun bench ()\n (let ((*standard-output* (make-broadcast-stream)))\n (with-open-file (*standard-input* *dat-path*)\n (time (main)))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nA programming competition site AtCode provides algorithmic problems.\nEach problem is allocated a score based on its difficulty.\nCurrently, for each integer i between 1 and D (inclusive), there are p_i problems with a score of 100i points.\nThese p_1 + … + p_D problems are all of the problems available on AtCode.\n\nA user of AtCode has a value called total score.\nThe total score of a user is the sum of the following two elements:\n\nBase score: the sum of the scores of all problems solved by the user.\n\nPerfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).\n\nTakahashi, who is the new user of AtCode, has not solved any problem.\nHis objective is to have a total score of G or more points.\nAt least how many problems does he need to solve for this objective?\n\nConstraints\n\n1 ≤ D ≤ 10\n\n1 ≤ p_i ≤ 100\n\n100 ≤ c_i ≤ 10^6\n\n100 ≤ G\n\nAll values in input are integers.\n\nc_i and G are all multiples of 100.\n\nIt is possible to have a total score of G or more points.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nD G\np_1 c_1\n:\np_D c_D\n\nOutput\n\nPrint the minimum number of problems that needs to be solved in order to have a total score of G or more points. Note that this objective is always achievable (see Constraints).\n\nSample Input 1\n\n2 700\n3 500\n5 800\n\nSample Output 1\n\n3\n\nIn this case, there are three problems each with 100 points and five problems each with 200 points. The perfect bonus for solving all the 100-point problems is 500 points, and the perfect bonus for solving all the 200-point problems is 800 points. Takahashi's objective is to have a total score of 700 points or more.\n\nOne way to achieve this objective is to solve four 200-point problems and earn a base score of 800 points. However, if we solve three 100-point problems, we can earn the perfect bonus of 500 points in addition to the base score of 300 points, for a total score of 800 points, and we can achieve the objective with fewer problems.\n\nSample Input 2\n\n2 2000\n3 500\n5 800\n\nSample Output 2\n\n7\n\nThis case is similar to Sample Input 1, but the Takahashi's objective this time is 2000 points or more. In this case, we inevitably need to solve all five 200-point problems, and by solving two 100-point problems additionally we have the total score of 2000 points.\n\nSample Input 3\n\n2 400\n3 500\n5 800\n\nSample Output 3\n\n2\n\nThis case is again similar to Sample Input 1, but the Takahashi's objective this time is 400 points or more. In this case, we only need to solve two 200-point problems to achieve the objective.\n\nSample Input 4\n\n5 25000\n20 1000\n40 1000\n50 1000\n30 1000\n1 1000\n\nSample Output 4\n\n66\n\nThere is only one 500-point problem, but the perfect bonus can be earned even in such a case.", "sample_input": "2 700\n3 500\n5 800\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03290", "source_text": "Score : 300 points\n\nProblem Statement\n\nA programming competition site AtCode provides algorithmic problems.\nEach problem is allocated a score based on its difficulty.\nCurrently, for each integer i between 1 and D (inclusive), there are p_i problems with a score of 100i points.\nThese p_1 + … + p_D problems are all of the problems available on AtCode.\n\nA user of AtCode has a value called total score.\nThe total score of a user is the sum of the following two elements:\n\nBase score: the sum of the scores of all problems solved by the user.\n\nPerfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).\n\nTakahashi, who is the new user of AtCode, has not solved any problem.\nHis objective is to have a total score of G or more points.\nAt least how many problems does he need to solve for this objective?\n\nConstraints\n\n1 ≤ D ≤ 10\n\n1 ≤ p_i ≤ 100\n\n100 ≤ c_i ≤ 10^6\n\n100 ≤ G\n\nAll values in input are integers.\n\nc_i and G are all multiples of 100.\n\nIt is possible to have a total score of G or more points.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nD G\np_1 c_1\n:\np_D c_D\n\nOutput\n\nPrint the minimum number of problems that needs to be solved in order to have a total score of G or more points. Note that this objective is always achievable (see Constraints).\n\nSample Input 1\n\n2 700\n3 500\n5 800\n\nSample Output 1\n\n3\n\nIn this case, there are three problems each with 100 points and five problems each with 200 points. The perfect bonus for solving all the 100-point problems is 500 points, and the perfect bonus for solving all the 200-point problems is 800 points. Takahashi's objective is to have a total score of 700 points or more.\n\nOne way to achieve this objective is to solve four 200-point problems and earn a base score of 800 points. However, if we solve three 100-point problems, we can earn the perfect bonus of 500 points in addition to the base score of 300 points, for a total score of 800 points, and we can achieve the objective with fewer problems.\n\nSample Input 2\n\n2 2000\n3 500\n5 800\n\nSample Output 2\n\n7\n\nThis case is similar to Sample Input 1, but the Takahashi's objective this time is 2000 points or more. In this case, we inevitably need to solve all five 200-point problems, and by solving two 100-point problems additionally we have the total score of 2000 points.\n\nSample Input 3\n\n2 400\n3 500\n5 800\n\nSample Output 3\n\n2\n\nThis case is again similar to Sample Input 1, but the Takahashi's objective this time is 400 points or more. In this case, we only need to solve two 200-point problems to achieve the objective.\n\nSample Input 4\n\n5 25000\n20 1000\n40 1000\n50 1000\n30 1000\n1 1000\n\nSample Output 4\n\n66\n\nThere is only one 500-point problem, but the perfect bonus can be earned even in such a case.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3198, "cpu_time_ms": 225, "memory_kb": 23524}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s846932828", "group_id": "codeNet:p03290", "input_text": ";; -*- coding:utf-8 -*-\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 1))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))))\n\n(defmacro print-line (obj &optional (stream '*standard-output*))\n `(prog1 (princ ,obj ,stream) (terpri ,stream)))\n\n\n;; Hauptteil\n\n(defmacro split-and-bind (arg-lst string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str-evaled (gensym \"STR\")))\n (labels ((expand (arg-lst &optional (init-pos1 t))\n\t (if (null arg-lst)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str-evaled :start ,pos1 :test #'char=))\n\t\t\t (,(car arg-lst) (parse-integer ,str-evaled :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr arg-lst) nil))))))\n `(let ((,str-evaled ,string))\n\t ,@(expand arg-lst)))))\n\n(deftype uint nil `(integer 0 ,(expt 10 9)))\n(defstruct problem\n i p c)\n(defun get-complete-score (prob)\n (+ (* 100 (problem-i prob) (problem-p prob))\n (problem-c prob)))\n\n(defun main ()\n (let* ((d (read))\n (g (read))\n (problem-lst\n (sort (loop for i from 1 to d\n collect (split-and-bind (p c) (read-line)\n (make-problem :i i :p p :c c)))\n #'>=\n :key #'(lambda (prob)\n (with-slots (i p c) prob\n (/ (+ (* 100 i p) c)\n (float p)))))))\n (print-line (solve problem-lst g 0))))\n\n(defun solve (lst max-score num)\n (if (null lst)\n (error \"bug\")\n (let ((comp (get-complete-score (car lst))))\n (if (> comp max-score)\n (solve-latter lst max-score num)\n (solve (cdr lst)\n (- max-score comp)\n (+ num (problem-p (car lst))))))))\n\n(defun solve-latter (lst rem-score num)\n (+ num\n (min (loop for prob in lst\n minimize (with-slots (i p c) prob\n (let ((p-needed (floor rem-score (* 100 i))))\n (if (> p-needed p)\n most-positive-fixnum\n p-needed))))\n (loop for prob in lst\n minimize (if (> (get-complete-score prob) rem-score)\n (problem-p prob)\n most-positive-fixnum)))))\n#-swank(main)\n\n\n;; Für Test\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank\n(defun test ()\n (with-input-from-string (*standard-input* (delete #\\return (get-clipbrd)))\n (main)))\n\n\n;; Für Benchmark\n#+swank(defparameter *this-path* *load-pathname*)\n#+swank(defparameter *this-dir-path* (uiop:pathname-directory-pathname *this-path*))\n#+swank(defparameter *dat-path* (merge-pathnames \"test.dat\" *this-dir-path*))\n\n#+swank\n(defun gendat ()\n (with-open-file (out *dat-path*\n\t\t :direction :output :if-exists :supersede)\n ))\n\n#+swank\n(defun bench ()\n (let ((*standard-output* (make-broadcast-stream)))\n (with-open-file (*standard-input* *dat-path*)\n (time (main)))))\n", "language": "Lisp", "metadata": {"date": 1534033454, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03290.html", "problem_id": "p03290", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03290/input.txt", "sample_output_relpath": "derived/input_output/data/p03290/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03290/Lisp/s846932828.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s846932828", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; -*- coding:utf-8 -*-\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 1))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))))\n\n(defmacro print-line (obj &optional (stream '*standard-output*))\n `(prog1 (princ ,obj ,stream) (terpri ,stream)))\n\n\n;; Hauptteil\n\n(defmacro split-and-bind (arg-lst string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str-evaled (gensym \"STR\")))\n (labels ((expand (arg-lst &optional (init-pos1 t))\n\t (if (null arg-lst)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str-evaled :start ,pos1 :test #'char=))\n\t\t\t (,(car arg-lst) (parse-integer ,str-evaled :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr arg-lst) nil))))))\n `(let ((,str-evaled ,string))\n\t ,@(expand arg-lst)))))\n\n(deftype uint nil `(integer 0 ,(expt 10 9)))\n(defstruct problem\n i p c)\n(defun get-complete-score (prob)\n (+ (* 100 (problem-i prob) (problem-p prob))\n (problem-c prob)))\n\n(defun main ()\n (let* ((d (read))\n (g (read))\n (problem-lst\n (sort (loop for i from 1 to d\n collect (split-and-bind (p c) (read-line)\n (make-problem :i i :p p :c c)))\n #'>=\n :key #'(lambda (prob)\n (with-slots (i p c) prob\n (/ (+ (* 100 i p) c)\n (float p)))))))\n (print-line (solve problem-lst g 0))))\n\n(defun solve (lst max-score num)\n (if (null lst)\n (error \"bug\")\n (let ((comp (get-complete-score (car lst))))\n (if (> comp max-score)\n (solve-latter lst max-score num)\n (solve (cdr lst)\n (- max-score comp)\n (+ num (problem-p (car lst))))))))\n\n(defun solve-latter (lst rem-score num)\n (+ num\n (min (loop for prob in lst\n minimize (with-slots (i p c) prob\n (let ((p-needed (floor rem-score (* 100 i))))\n (if (> p-needed p)\n most-positive-fixnum\n p-needed))))\n (loop for prob in lst\n minimize (if (> (get-complete-score prob) rem-score)\n (problem-p prob)\n most-positive-fixnum)))))\n#-swank(main)\n\n\n;; Für Test\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank\n(defun test ()\n (with-input-from-string (*standard-input* (delete #\\return (get-clipbrd)))\n (main)))\n\n\n;; Für Benchmark\n#+swank(defparameter *this-path* *load-pathname*)\n#+swank(defparameter *this-dir-path* (uiop:pathname-directory-pathname *this-path*))\n#+swank(defparameter *dat-path* (merge-pathnames \"test.dat\" *this-dir-path*))\n\n#+swank\n(defun gendat ()\n (with-open-file (out *dat-path*\n\t\t :direction :output :if-exists :supersede)\n ))\n\n#+swank\n(defun bench ()\n (let ((*standard-output* (make-broadcast-stream)))\n (with-open-file (*standard-input* *dat-path*)\n (time (main)))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nA programming competition site AtCode provides algorithmic problems.\nEach problem is allocated a score based on its difficulty.\nCurrently, for each integer i between 1 and D (inclusive), there are p_i problems with a score of 100i points.\nThese p_1 + … + p_D problems are all of the problems available on AtCode.\n\nA user of AtCode has a value called total score.\nThe total score of a user is the sum of the following two elements:\n\nBase score: the sum of the scores of all problems solved by the user.\n\nPerfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).\n\nTakahashi, who is the new user of AtCode, has not solved any problem.\nHis objective is to have a total score of G or more points.\nAt least how many problems does he need to solve for this objective?\n\nConstraints\n\n1 ≤ D ≤ 10\n\n1 ≤ p_i ≤ 100\n\n100 ≤ c_i ≤ 10^6\n\n100 ≤ G\n\nAll values in input are integers.\n\nc_i and G are all multiples of 100.\n\nIt is possible to have a total score of G or more points.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nD G\np_1 c_1\n:\np_D c_D\n\nOutput\n\nPrint the minimum number of problems that needs to be solved in order to have a total score of G or more points. Note that this objective is always achievable (see Constraints).\n\nSample Input 1\n\n2 700\n3 500\n5 800\n\nSample Output 1\n\n3\n\nIn this case, there are three problems each with 100 points and five problems each with 200 points. The perfect bonus for solving all the 100-point problems is 500 points, and the perfect bonus for solving all the 200-point problems is 800 points. Takahashi's objective is to have a total score of 700 points or more.\n\nOne way to achieve this objective is to solve four 200-point problems and earn a base score of 800 points. However, if we solve three 100-point problems, we can earn the perfect bonus of 500 points in addition to the base score of 300 points, for a total score of 800 points, and we can achieve the objective with fewer problems.\n\nSample Input 2\n\n2 2000\n3 500\n5 800\n\nSample Output 2\n\n7\n\nThis case is similar to Sample Input 1, but the Takahashi's objective this time is 2000 points or more. In this case, we inevitably need to solve all five 200-point problems, and by solving two 100-point problems additionally we have the total score of 2000 points.\n\nSample Input 3\n\n2 400\n3 500\n5 800\n\nSample Output 3\n\n2\n\nThis case is again similar to Sample Input 1, but the Takahashi's objective this time is 400 points or more. In this case, we only need to solve two 200-point problems to achieve the objective.\n\nSample Input 4\n\n5 25000\n20 1000\n40 1000\n50 1000\n30 1000\n1 1000\n\nSample Output 4\n\n66\n\nThere is only one 500-point problem, but the perfect bonus can be earned even in such a case.", "sample_input": "2 700\n3 500\n5 800\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03290", "source_text": "Score : 300 points\n\nProblem Statement\n\nA programming competition site AtCode provides algorithmic problems.\nEach problem is allocated a score based on its difficulty.\nCurrently, for each integer i between 1 and D (inclusive), there are p_i problems with a score of 100i points.\nThese p_1 + … + p_D problems are all of the problems available on AtCode.\n\nA user of AtCode has a value called total score.\nThe total score of a user is the sum of the following two elements:\n\nBase score: the sum of the scores of all problems solved by the user.\n\nPerfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).\n\nTakahashi, who is the new user of AtCode, has not solved any problem.\nHis objective is to have a total score of G or more points.\nAt least how many problems does he need to solve for this objective?\n\nConstraints\n\n1 ≤ D ≤ 10\n\n1 ≤ p_i ≤ 100\n\n100 ≤ c_i ≤ 10^6\n\n100 ≤ G\n\nAll values in input are integers.\n\nc_i and G are all multiples of 100.\n\nIt is possible to have a total score of G or more points.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nD G\np_1 c_1\n:\np_D c_D\n\nOutput\n\nPrint the minimum number of problems that needs to be solved in order to have a total score of G or more points. Note that this objective is always achievable (see Constraints).\n\nSample Input 1\n\n2 700\n3 500\n5 800\n\nSample Output 1\n\n3\n\nIn this case, there are three problems each with 100 points and five problems each with 200 points. The perfect bonus for solving all the 100-point problems is 500 points, and the perfect bonus for solving all the 200-point problems is 800 points. Takahashi's objective is to have a total score of 700 points or more.\n\nOne way to achieve this objective is to solve four 200-point problems and earn a base score of 800 points. However, if we solve three 100-point problems, we can earn the perfect bonus of 500 points in addition to the base score of 300 points, for a total score of 800 points, and we can achieve the objective with fewer problems.\n\nSample Input 2\n\n2 2000\n3 500\n5 800\n\nSample Output 2\n\n7\n\nThis case is similar to Sample Input 1, but the Takahashi's objective this time is 2000 points or more. In this case, we inevitably need to solve all five 200-point problems, and by solving two 100-point problems additionally we have the total score of 2000 points.\n\nSample Input 3\n\n2 400\n3 500\n5 800\n\nSample Output 3\n\n2\n\nThis case is again similar to Sample Input 1, but the Takahashi's objective this time is 400 points or more. In this case, we only need to solve two 200-point problems to achieve the objective.\n\nSample Input 4\n\n5 25000\n20 1000\n40 1000\n50 1000\n30 1000\n1 1000\n\nSample Output 4\n\n66\n\nThere is only one 500-point problem, but the perfect bonus can be earned even in such a case.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3206, "cpu_time_ms": 208, "memory_kb": 23652}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s899096423", "group_id": "codeNet:p03291", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ',dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dimensions-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref cache ,@memoized-args)\n (,name-alias ,@args))\n ,value)))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name))))\n (extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car form))) body)))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n;; (test with-memoizing\n;; (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (labels ((add (x y) (+ x y))\n;; \t\t (my-print (x) (print x)))\n;; \t (add 1 2))))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n(defun solve (s)\n (declare #.OPT)\n (with-memoizing (:array (100001 4) :element-type 'uint32 :initial-element #xffffffff)\n (nlet dp ((x (length s)) (y 3))\n (if (zerop x)\n (if (zerop y)\n 1\n 0)\n (mod\n (cond ((= y 3) (case (schar s (- x 1))\n (#\\C (+ (dp (- x 1) 3) (dp (- x 1) 2)))\n (#\\? (+ (* 3 (dp (- x 1) 3)) (dp (- x 1) 2)))\n (otherwise (dp (- x 1) 3))))\n ((= y 2) (case (schar s (- x 1))\n (#\\B (+ (dp (- x 1) 2) (dp (- x 1) 1)))\n (#\\? (+ (* 3 (dp (- x 1) 2)) (dp (- x 1) 1)))\n (otherwise (dp (- x 1) 2))))\n ((= y 1) (case (schar s (- x 1))\n (#\\A (+ (dp (- x 1) 1) (dp (- x 1) 0)))\n (#\\? (+ (* 3 (dp (- x 1) 1)) (dp (- x 1) 0)))\n (otherwise (dp (- x 1) 1))))\n (t (case (schar s (- x 1))\n (#\\? (* 3 (dp (- x 1) 0)))\n (otherwise (dp ( - x 1) 0)))))\n +mod+)))))\n\n(defun main ()\n (let* ((s (coerce (read-line) 'simple-base-string)))\n (println (solve s))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1548322786, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03291.html", "problem_id": "p03291", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03291/input.txt", "sample_output_relpath": "derived/input_output/data/p03291/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03291/Lisp/s899096423.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s899096423", "user_id": "u352600849"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro nlet (name args &body body)\n (labels ((ensure-list (x) (if (listp x) x (list x))))\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args))))))\n\n;; (with-memoizing (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-memoizing (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)\n;; (defun ...))\n(defmacro with-memoizing (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array ',dimensions ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((make-cache-check-form (cache-type args)\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dimensions-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref cache ,@memoized-args)\n (,name-alias ,@args))\n ,value)))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name))))\n (extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car form))) body)))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args))))))\n ((nlet)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((cache ,cache-form))\n (nlet ,name ,bindings\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,@(extract-declarations body)\n ,(make-cache-check-form cache-type args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n;; (test with-memoizing\n;; (finishes (macroexpand `(with-memoizing (:hash-table :test #'equal)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (defun add (x y) (+ x y)))))\n;; (finishes (macroexpand `(with-memoizing (:array '(10 10)\n;; :element-type 'fixnum\n;; :initial-element -1)\n;; (labels ((add (x y) (+ x y))\n;; \t\t (my-print (x) (print x)))\n;; \t (add 1 2))))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n(defun solve (s)\n (declare #.OPT)\n (with-memoizing (:array (100001 4) :element-type 'uint32 :initial-element #xffffffff)\n (nlet dp ((x (length s)) (y 3))\n (if (zerop x)\n (if (zerop y)\n 1\n 0)\n (mod\n (cond ((= y 3) (case (schar s (- x 1))\n (#\\C (+ (dp (- x 1) 3) (dp (- x 1) 2)))\n (#\\? (+ (* 3 (dp (- x 1) 3)) (dp (- x 1) 2)))\n (otherwise (dp (- x 1) 3))))\n ((= y 2) (case (schar s (- x 1))\n (#\\B (+ (dp (- x 1) 2) (dp (- x 1) 1)))\n (#\\? (+ (* 3 (dp (- x 1) 2)) (dp (- x 1) 1)))\n (otherwise (dp (- x 1) 2))))\n ((= y 1) (case (schar s (- x 1))\n (#\\A (+ (dp (- x 1) 1) (dp (- x 1) 0)))\n (#\\? (+ (* 3 (dp (- x 1) 1)) (dp (- x 1) 0)))\n (otherwise (dp (- x 1) 1))))\n (t (case (schar s (- x 1))\n (#\\? (* 3 (dp (- x 1) 0)))\n (otherwise (dp ( - x 1) 0)))))\n +mod+)))))\n\n(defun main ()\n (let* ((s (coerce (read-line) 'simple-base-string)))\n (println (solve s))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThe ABC number of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:\n\n1 ≤ i < j < k ≤ |T| (|T| is the length of T.)\n\nT_i = A (T_i is the i-th character of T from the beginning.)\n\nT_j = B\n\nT_k = C\n\nFor example, when T = ABCBC, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.\n\nYou are given a string S. Each character of S is A, B, C or ?.\n\nLet Q be the number of occurrences of ? in S. We can make 3^Q strings by replacing each occurrence of ? in S with A, B or C. Find the sum of the ABC numbers of all these strings.\n\nThis sum can be extremely large, so print the sum modulo 10^9 + 7.\n\nConstraints\n\n3 ≤ |S| ≤ 10^5\n\nEach character of S is A, B, C or ?.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the sum of the ABC numbers of all the 3^Q strings, modulo 10^9 + 7.\n\nSample Input 1\n\nA??C\n\nSample Output 1\n\n8\n\nIn this case, Q = 2, and we can make 3^Q = 9 strings by by replacing each occurrence of ? with A, B or C. The ABC number of each of these strings is as follows:\n\nAAAC: 0\n\nAABC: 2\n\nAACC: 0\n\nABAC: 1\n\nABBC: 2\n\nABCC: 2\n\nACAC: 0\n\nACBC: 1\n\nACCC: 0\n\nThe sum of these is 0 + 2 + 0 + 1 + 2 + 2 + 0 + 1 + 0 = 8, so we print 8 modulo 10^9 + 7, that is, 8.\n\nSample Input 2\n\nABCBC\n\nSample Output 2\n\n3\n\nWhen Q = 0, we print the ABC number of S itself, modulo 10^9 + 7. This string is the same as the one given as an example in the problem statement, and its ABC number is 3.\n\nSample Input 3\n\n????C?????B??????A???????\n\nSample Output 3\n\n979596887\n\nIn this case, the sum of the ABC numbers of all the 3^Q strings is 2291979612924, and we should print this number modulo 10^9 + 7, that is, 979596887.", "sample_input": "A??C\n"}, "reference_outputs": ["8\n"], "source_document_id": "p03291", "source_text": "Score : 400 points\n\nProblem Statement\n\nThe ABC number of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:\n\n1 ≤ i < j < k ≤ |T| (|T| is the length of T.)\n\nT_i = A (T_i is the i-th character of T from the beginning.)\n\nT_j = B\n\nT_k = C\n\nFor example, when T = ABCBC, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.\n\nYou are given a string S. Each character of S is A, B, C or ?.\n\nLet Q be the number of occurrences of ? in S. We can make 3^Q strings by replacing each occurrence of ? in S with A, B or C. Find the sum of the ABC numbers of all these strings.\n\nThis sum can be extremely large, so print the sum modulo 10^9 + 7.\n\nConstraints\n\n3 ≤ |S| ≤ 10^5\n\nEach character of S is A, B, C or ?.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the sum of the ABC numbers of all the 3^Q strings, modulo 10^9 + 7.\n\nSample Input 1\n\nA??C\n\nSample Output 1\n\n8\n\nIn this case, Q = 2, and we can make 3^Q = 9 strings by by replacing each occurrence of ? with A, B or C. The ABC number of each of these strings is as follows:\n\nAAAC: 0\n\nAABC: 2\n\nAACC: 0\n\nABAC: 1\n\nABBC: 2\n\nABCC: 2\n\nACAC: 0\n\nACBC: 1\n\nACCC: 0\n\nThe sum of these is 0 + 2 + 0 + 1 + 2 + 2 + 0 + 1 + 0 = 8, so we print 8 modulo 10^9 + 7, that is, 8.\n\nSample Input 2\n\nABCBC\n\nSample Output 2\n\n3\n\nWhen Q = 0, we print the ABC number of S itself, modulo 10^9 + 7. This string is the same as the one given as an example in the problem statement, and its ABC number is 3.\n\nSample Input 3\n\n????C?????B??????A???????\n\nSample Output 3\n\n979596887\n\nIn this case, the sum of the ABC numbers of all the 3^Q strings is 2291979612924, and we should print this number modulo 10^9 + 7, that is, 979596887.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8486, "cpu_time_ms": 165, "memory_kb": 48872}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s638964252", "group_id": "codeNet:p03292", "input_text": "(let ((a1 (read))\n (a2 (read))\n (a3 (read)))\n (princ (min (+ (abs (- a1 a2)) (abs (- a2 a3)))\n (+ (abs (- a2 a3)) (abs (- a3 a1)))\n (+ (abs (- a3 a1)) (abs (- a1 a2)))\n (+ (abs (- a3 a2)) (abs (- a2 a1)))\n (+ (abs (- a2 a1)) (abs (- a1 a3)))\n (+ (abs (- a1 a3)) (abs (- a3 a2))))))", "language": "Lisp", "metadata": {"date": 1532221768, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03292.html", "problem_id": "p03292", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03292/input.txt", "sample_output_relpath": "derived/input_output/data/p03292/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03292/Lisp/s638964252.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s638964252", "user_id": "u956039157"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(let ((a1 (read))\n (a2 (read))\n (a3 (read)))\n (princ (min (+ (abs (- a1 a2)) (abs (- a2 a3)))\n (+ (abs (- a2 a3)) (abs (- a3 a1)))\n (+ (abs (- a3 a1)) (abs (- a1 a2)))\n (+ (abs (- a3 a2)) (abs (- a2 a1)))\n (+ (abs (- a2 a1)) (abs (- a1 a3)))\n (+ (abs (- a1 a3)) (abs (- a3 a2))))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou have three tasks, all of which need to be completed.\n\nFirst, you can complete any one task at cost 0.\n\nThen, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.\n\nHere, |x| denotes the absolute value of x.\n\nFind the minimum total cost required to complete all the task.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A_1, A_2, A_3 \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA_1 A_2 A_3\n\nOutput\n\nPrint the minimum total cost required to complete all the task.\n\nSample Input 1\n\n1 6 3\n\nSample Output 1\n\n5\n\nWhen the tasks are completed in the following order, the total cost will be 5, which is the minimum:\n\nComplete the first task at cost 0.\n\nComplete the third task at cost 2.\n\nComplete the second task at cost 3.\n\nSample Input 2\n\n11 5 5\n\nSample Output 2\n\n6\n\nSample Input 3\n\n100 100 100\n\nSample Output 3\n\n0", "sample_input": "1 6 3\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03292", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou have three tasks, all of which need to be completed.\n\nFirst, you can complete any one task at cost 0.\n\nThen, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.\n\nHere, |x| denotes the absolute value of x.\n\nFind the minimum total cost required to complete all the task.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A_1, A_2, A_3 \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA_1 A_2 A_3\n\nOutput\n\nPrint the minimum total cost required to complete all the task.\n\nSample Input 1\n\n1 6 3\n\nSample Output 1\n\n5\n\nWhen the tasks are completed in the following order, the total cost will be 5, which is the minimum:\n\nComplete the first task at cost 0.\n\nComplete the third task at cost 2.\n\nComplete the second task at cost 3.\n\nSample Input 2\n\n11 5 5\n\nSample Output 2\n\n6\n\nSample Input 3\n\n100 100 100\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 357, "cpu_time_ms": 386, "memory_kb": 14056}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s454131047", "group_id": "codeNet:p03293", "input_text": "(defparameter *string* (concatenate 'list (read-line)))\n(defparameter *answer* (concatenate 'list (read-line)))\n(defparameter *length* (length *string*))\n(format t \"~A\" (if (loop :for k :from 0 :upto *length* initially (setf (cdr (last *string*)) *string*) thereis(equal (subseq *string* k (+ k *length*)) *answer*))\n \"Yes\"\n \"No\"))", "language": "Lisp", "metadata": {"date": 1560446479, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03293.html", "problem_id": "p03293", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03293/input.txt", "sample_output_relpath": "derived/input_output/data/p03293/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03293/Lisp/s454131047.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s454131047", "user_id": "u610490393"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defparameter *string* (concatenate 'list (read-line)))\n(defparameter *answer* (concatenate 'list (read-line)))\n(defparameter *length* (length *string*))\n(format t \"~A\" (if (loop :for k :from 0 :upto *length* initially (setf (cdr (last *string*)) *string*) thereis(equal (subseq *string* k (+ k *length*)) *answer*))\n \"Yes\"\n \"No\"))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given string S and T consisting of lowercase English letters.\n\nDetermine if S equals T after rotation.\n\nThat is, determine if S equals T after the following operation is performed some number of times:\n\nOperation: Let S = S_1 S_2 ... S_{|S|}. Change S to S_{|S|} S_1 S_2 ... S_{|S|-1}.\n\nHere, |X| denotes the length of the string X.\n\nConstraints\n\n2 \\leq |S| \\leq 100\n\n|S| = |T|\n\nS and T consist of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nIf S equals T after rotation, print Yes; if it does not, print No.\n\nSample Input 1\n\nkyoto\ntokyo\n\nSample Output 1\n\nYes\n\nIn the first operation, kyoto becomes okyot.\n\nIn the second operation, okyot becomes tokyo.\n\nSample Input 2\n\nabc\narc\n\nSample Output 2\n\nNo\n\nabc does not equal arc after any number of operations.\n\nSample Input 3\n\naaaaaaaaaaaaaaab\naaaaaaaaaaaaaaab\n\nSample Output 3\n\nYes", "sample_input": "kyoto\ntokyo\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03293", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given string S and T consisting of lowercase English letters.\n\nDetermine if S equals T after rotation.\n\nThat is, determine if S equals T after the following operation is performed some number of times:\n\nOperation: Let S = S_1 S_2 ... S_{|S|}. Change S to S_{|S|} S_1 S_2 ... S_{|S|-1}.\n\nHere, |X| denotes the length of the string X.\n\nConstraints\n\n2 \\leq |S| \\leq 100\n\n|S| = |T|\n\nS and T consist of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\n\nOutput\n\nIf S equals T after rotation, print Yes; if it does not, print No.\n\nSample Input 1\n\nkyoto\ntokyo\n\nSample Output 1\n\nYes\n\nIn the first operation, kyoto becomes okyot.\n\nIn the second operation, okyot becomes tokyo.\n\nSample Input 2\n\nabc\narc\n\nSample Output 2\n\nNo\n\nabc does not equal arc after any number of operations.\n\nSample Input 3\n\naaaaaaaaaaaaaaab\naaaaaaaaaaaaaaab\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 367, "cpu_time_ms": 11, "memory_kb": 3684}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s061560199", "group_id": "codeNet:p03294", "input_text": "(princ(loop repeat(read)sum(-(read)1)))", "language": "Lisp", "metadata": {"date": 1550065612, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03294.html", "problem_id": "p03294", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03294/input.txt", "sample_output_relpath": "derived/input_output/data/p03294/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03294/Lisp/s061560199.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s061560199", "user_id": "u352600849"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(princ(loop repeat(read)sum(-(read)1)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given N positive integers a_1, a_2, ..., a_N.\n\nFor a non-negative integer m, let f(m) = (m\\ mod\\ a_1) + (m\\ mod\\ a_2) + ... + (m\\ mod\\ a_N).\n\nHere, X\\ mod\\ Y denotes the remainder of the division of X by Y.\n\nFind the maximum value of f.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 3000\n\n2 \\leq a_i \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the maximum value of f.\n\nSample Input 1\n\n3\n3 4 6\n\nSample Output 1\n\n10\n\nf(11) = (11\\ mod\\ 3) + (11\\ mod\\ 4) + (11\\ mod\\ 6) = 10 is the maximum value of f.\n\nSample Input 2\n\n5\n7 46 11 20 11\n\nSample Output 2\n\n90\n\nSample Input 3\n\n7\n994 518 941 851 647 2 581\n\nSample Output 3\n\n4527", "sample_input": "3\n3 4 6\n"}, "reference_outputs": ["10\n"], "source_document_id": "p03294", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given N positive integers a_1, a_2, ..., a_N.\n\nFor a non-negative integer m, let f(m) = (m\\ mod\\ a_1) + (m\\ mod\\ a_2) + ... + (m\\ mod\\ a_N).\n\nHere, X\\ mod\\ Y denotes the remainder of the division of X by Y.\n\nFind the maximum value of f.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 3000\n\n2 \\leq a_i \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the maximum value of f.\n\nSample Input 1\n\n3\n3 4 6\n\nSample Output 1\n\n10\n\nf(11) = (11\\ mod\\ 3) + (11\\ mod\\ 4) + (11\\ mod\\ 6) = 10 is the maximum value of f.\n\nSample Input 2\n\n5\n7 46 11 20 11\n\nSample Output 2\n\n90\n\nSample Input 3\n\n7\n994 518 941 851 647 2 581\n\nSample Output 3\n\n4527", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 39, "cpu_time_ms": 109, "memory_kb": 12644}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s801409791", "group_id": "codeNet:p03302", "input_text": "(let ((a (read))\n (b (read)))\n (format t \"~a~%\" (cond ((= 15 (+ a b)) #\\+)\n ((= 15 (* a b)) #\\*)\n (t #\\x))))", "language": "Lisp", "metadata": {"date": 1531084958, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03302.html", "problem_id": "p03302", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03302/input.txt", "sample_output_relpath": "derived/input_output/data/p03302/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03302/Lisp/s801409791.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s801409791", "user_id": "u994767958"}, "prompt_components": {"gold_output": "+\n", "input_to_evaluate": "(let ((a (read))\n (b (read)))\n (format t \"~a~%\" (cond ((= 15 (+ a b)) #\\+)\n ((= 15 (* a b)) #\\*)\n (t #\\x))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given two integers a and b.\nDetermine if a+b=15 or a\\times b=15 or neither holds.\n\nNote that a+b=15 and a\\times b=15 do not hold at the same time.\n\nConstraints\n\n1 \\leq a,b \\leq 15\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf a+b=15, print +;\nif a\\times b=15, print *;\nif neither holds, print x.\n\nSample Input 1\n\n4 11\n\nSample Output 1\n\n+\n\n4+11=15.\n\nSample Input 2\n\n3 5\n\nSample Output 2\n\n*\n\n3\\times 5=15.\n\nSample Input 3\n\n1 1\n\nSample Output 3\n\nx\n\n1+1=2 and 1\\times 1=1, neither of which is 15.", "sample_input": "4 11\n"}, "reference_outputs": ["+\n"], "source_document_id": "p03302", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given two integers a and b.\nDetermine if a+b=15 or a\\times b=15 or neither holds.\n\nNote that a+b=15 and a\\times b=15 do not hold at the same time.\n\nConstraints\n\n1 \\leq a,b \\leq 15\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf a+b=15, print +;\nif a\\times b=15, print *;\nif neither holds, print x.\n\nSample Input 1\n\n4 11\n\nSample Output 1\n\n+\n\n4+11=15.\n\nSample Input 2\n\n3 5\n\nSample Output 2\n\n*\n\n3\\times 5=15.\n\nSample Input 3\n\n1 1\n\nSample Output 3\n\nx\n\n1+1=2 and 1\\times 1=1, neither of which is 15.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 162, "cpu_time_ms": 112, "memory_kb": 11744}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s082884699", "group_id": "codeNet:p03305", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #\\Newline))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (setf (schar ,buffer ,idx) ,terminate-char)\n (return (values ,buffer ,idx))))))\n\n(defmacro split-ints-and-bind (vars string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str (gensym \"STR\")))\n (labels ((expand (vars &optional (init-pos1 t))\n\t (if (null vars)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str :start ,pos1 :test #'char=))\n\t\t\t (,(car vars) (parse-integer ,str :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr vars) nil))))))\n `(let ((,str ,string))\n (declare (string ,str))\n\t ,@(expand vars)))))\n\n(defstruct (heap (:constructor make-heap\n (size\n &key test (element-type t)\n &aux (data (make-array (1+ size) :element-type element-type)))))\n (data #() :type (simple-array list (*)) :read-only t)\n (test #'< :type function :read-only t)\n (next-position 1 :type (integer 1 #.most-positive-fixnum)))\n\n(declaim (inline heap-push))\n(defun heap-push (obj heap)\n (symbol-macrolet ((data (heap-data heap))\n (next-position (heap-next-position heap)))\n (labels ((compare (p1 p2) (< (the fixnum (cdr p1))\n (the fixnum (cdr p2))))\n (update (pos)\n (unless (= pos 1)\n (let ((parent-pos (floor pos 2)))\n (when (compare (aref data pos) (aref data parent-pos))\n (rotatef (aref data pos) (aref data parent-pos))\n (update parent-pos))))))\n (declare (inline compare))\n (setf (aref data next-position) obj)\n (update next-position)\n (incf next-position)\n heap)))\n\n(declaim (inline heap-pop))\n(defun heap-pop (heap &optional (error t) null-value)\n (symbol-macrolet ((data (heap-data heap))\n (next-position (heap-next-position heap)))\n (labels ((compare (p1 p2) (< (the fixnum (cdr p1))\n (the fixnum (cdr p2))))\n (update (pos)\n (declare ((integer 1 #.most-positive-fixnum) pos))\n (let* ((child-pos1 (+ pos pos))\n (child-pos2 (1+ child-pos1)))\n (when (<= child-pos1 next-position)\n (if (<= child-pos2 next-position)\n (if (compare (aref data child-pos1) (aref data child-pos2))\n (unless (compare (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))\n (update child-pos1))\n (unless (compare (aref data pos) (aref data child-pos2))\n (rotatef (aref data pos) (aref data child-pos2))\n (update child-pos2)))\n (unless (compare (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))))))))\n (declare (inline compare))\n (if (= next-position 1)\n (if error\n (error \"No element in heap\")\n null-value)\n (prog1 (aref data 1)\n (decf next-position)\n (setf (aref data 1) (aref data next-position))\n (update 1))))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (src (- (read) 1))\n (dest (- (read) 1))\n ;; (to . cost)\n (graph-yen (make-array n :element-type 'list :initial-element nil))\n (graph-snook (make-array n :element-type 'list :initial-element nil))\n (table-yen (make-array n :element-type 'fixnum :initial-element most-positive-fixnum))\n (table-snook (make-array n :element-type 'fixnum :initial-element most-positive-fixnum)))\n (declare (uint32 n m src dest))\n (declare )\n (dotimes (i m)\n (split-ints-and-bind (u v a b) (buffered-read-line 50)\n (declare (uint32 u v a b))\n (push (cons (- v 1) a) (aref graph-yen (- u 1)))\n (push (cons (- u 1) a) (aref graph-yen (- v 1)))\n (push (cons (- v 1) b) (aref graph-snook (- u 1)))\n (push (cons (- u 1) b) (aref graph-snook (- v 1)))))\n (labels ((process (city table graph)\n (let ((pqueue (make-heap 200000 :element-type '(cons uint32 fixnum)))\n (visited (make-array n :element-type 'boolean :initial-element nil)))\n (heap-push (cons city 0) pqueue)\n (loop for (current . cost) of-type (fixnum . fixnum) = (heap-pop pqueue nil '(-1 . -1))\n until (= current -1)\n do (unless (aref visited current)\n (setf (aref visited current) t)\n (when (< cost (aref table current))\n (setf (aref table current) cost))\n (dolist (neighbor (aref graph current))\n (heap-push (cons (car neighbor)\n (the fixnum (+ cost (the fixnum (cdr neighbor)))))\n pqueue)))))))\n (process src table-yen graph-yen)\n (process dest table-snook graph-snook)\n (let ((hub-to-cost (make-array n :element-type 'fixnum))\n (year-to-cost (make-array n :element-type 'fixnum))\n (out (make-string-output-stream :element-type 'base-char)))\n (dotimes (i n)\n (setf (aref hub-to-cost i)\n (- #.(expt 10 15) (the fixnum (+ (aref table-yen i) (aref table-snook i))))))\n (loop for y from (- n 1) downto 0 ; (i-1)-th exchange is closed after i years.\n ; i is opened.\n maximize (aref hub-to-cost y) into current-max\n do (setf (aref year-to-cost y) current-max))\n (dotimes (y n (write-string (get-output-stream-string out)))\n (println (aref year-to-cost y) out))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1547820782, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03305.html", "problem_id": "p03305", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03305/input.txt", "sample_output_relpath": "derived/input_output/data/p03305/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03305/Lisp/s082884699.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s082884699", "user_id": "u352600849"}, "prompt_components": {"gold_output": "999999999999998\n999999999999989\n999999999999979\n999999999999897\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #\\Newline))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (setf (schar ,buffer ,idx) ,terminate-char)\n (return (values ,buffer ,idx))))))\n\n(defmacro split-ints-and-bind (vars string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str (gensym \"STR\")))\n (labels ((expand (vars &optional (init-pos1 t))\n\t (if (null vars)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str :start ,pos1 :test #'char=))\n\t\t\t (,(car vars) (parse-integer ,str :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr vars) nil))))))\n `(let ((,str ,string))\n (declare (string ,str))\n\t ,@(expand vars)))))\n\n(defstruct (heap (:constructor make-heap\n (size\n &key test (element-type t)\n &aux (data (make-array (1+ size) :element-type element-type)))))\n (data #() :type (simple-array list (*)) :read-only t)\n (test #'< :type function :read-only t)\n (next-position 1 :type (integer 1 #.most-positive-fixnum)))\n\n(declaim (inline heap-push))\n(defun heap-push (obj heap)\n (symbol-macrolet ((data (heap-data heap))\n (next-position (heap-next-position heap)))\n (labels ((compare (p1 p2) (< (the fixnum (cdr p1))\n (the fixnum (cdr p2))))\n (update (pos)\n (unless (= pos 1)\n (let ((parent-pos (floor pos 2)))\n (when (compare (aref data pos) (aref data parent-pos))\n (rotatef (aref data pos) (aref data parent-pos))\n (update parent-pos))))))\n (declare (inline compare))\n (setf (aref data next-position) obj)\n (update next-position)\n (incf next-position)\n heap)))\n\n(declaim (inline heap-pop))\n(defun heap-pop (heap &optional (error t) null-value)\n (symbol-macrolet ((data (heap-data heap))\n (next-position (heap-next-position heap)))\n (labels ((compare (p1 p2) (< (the fixnum (cdr p1))\n (the fixnum (cdr p2))))\n (update (pos)\n (declare ((integer 1 #.most-positive-fixnum) pos))\n (let* ((child-pos1 (+ pos pos))\n (child-pos2 (1+ child-pos1)))\n (when (<= child-pos1 next-position)\n (if (<= child-pos2 next-position)\n (if (compare (aref data child-pos1) (aref data child-pos2))\n (unless (compare (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))\n (update child-pos1))\n (unless (compare (aref data pos) (aref data child-pos2))\n (rotatef (aref data pos) (aref data child-pos2))\n (update child-pos2)))\n (unless (compare (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))))))))\n (declare (inline compare))\n (if (= next-position 1)\n (if error\n (error \"No element in heap\")\n null-value)\n (prog1 (aref data 1)\n (decf next-position)\n (setf (aref data 1) (aref data next-position))\n (update 1))))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (src (- (read) 1))\n (dest (- (read) 1))\n ;; (to . cost)\n (graph-yen (make-array n :element-type 'list :initial-element nil))\n (graph-snook (make-array n :element-type 'list :initial-element nil))\n (table-yen (make-array n :element-type 'fixnum :initial-element most-positive-fixnum))\n (table-snook (make-array n :element-type 'fixnum :initial-element most-positive-fixnum)))\n (declare (uint32 n m src dest))\n (declare )\n (dotimes (i m)\n (split-ints-and-bind (u v a b) (buffered-read-line 50)\n (declare (uint32 u v a b))\n (push (cons (- v 1) a) (aref graph-yen (- u 1)))\n (push (cons (- u 1) a) (aref graph-yen (- v 1)))\n (push (cons (- v 1) b) (aref graph-snook (- u 1)))\n (push (cons (- u 1) b) (aref graph-snook (- v 1)))))\n (labels ((process (city table graph)\n (let ((pqueue (make-heap 200000 :element-type '(cons uint32 fixnum)))\n (visited (make-array n :element-type 'boolean :initial-element nil)))\n (heap-push (cons city 0) pqueue)\n (loop for (current . cost) of-type (fixnum . fixnum) = (heap-pop pqueue nil '(-1 . -1))\n until (= current -1)\n do (unless (aref visited current)\n (setf (aref visited current) t)\n (when (< cost (aref table current))\n (setf (aref table current) cost))\n (dolist (neighbor (aref graph current))\n (heap-push (cons (car neighbor)\n (the fixnum (+ cost (the fixnum (cdr neighbor)))))\n pqueue)))))))\n (process src table-yen graph-yen)\n (process dest table-snook graph-snook)\n (let ((hub-to-cost (make-array n :element-type 'fixnum))\n (year-to-cost (make-array n :element-type 'fixnum))\n (out (make-string-output-stream :element-type 'base-char)))\n (dotimes (i n)\n (setf (aref hub-to-cost i)\n (- #.(expt 10 15) (the fixnum (+ (aref table-yen i) (aref table-snook i))))))\n (loop for y from (- n 1) downto 0 ; (i-1)-th exchange is closed after i years.\n ; i is opened.\n maximize (aref hub-to-cost y) into current-max\n do (setf (aref year-to-cost y) current-max))\n (dotimes (y n (write-string (get-output-stream-string out)))\n (println (aref year-to-cost y) out))))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nKenkoooo is planning a trip in Republic of Snuke.\nIn this country, there are n cities and m trains running.\nThe cities are numbered 1 through n, and the i-th train connects City u_i and v_i bidirectionally.\nAny city can be reached from any city by changing trains.\n\nTwo currencies are used in the country: yen and snuuk.\nAny train fare can be paid by both yen and snuuk.\nThe fare of the i-th train is a_i yen if paid in yen, and b_i snuuk if paid in snuuk.\n\nIn a city with a money exchange office, you can change 1 yen into 1 snuuk.\nHowever, when you do a money exchange, you have to change all your yen into snuuk.\nThat is, if Kenkoooo does a money exchange when he has X yen, he will then have X snuuk.\nCurrently, there is a money exchange office in every city, but the office in City i will shut down in i years and can never be used in and after that year.\n\nKenkoooo is planning to depart City s with 10^{15} yen in his pocket and head for City t, and change his yen into snuuk in some city while traveling.\nIt is acceptable to do the exchange in City s or City t.\n\nKenkoooo would like to have as much snuuk as possible when he reaches City t by making the optimal choices for the route to travel and the city to do the exchange.\nFor each i=0,...,n-1, find the maximum amount of snuuk that Kenkoooo has when he reaches City t if he goes on a trip from City s to City t after i years.\nYou can assume that the trip finishes within the year.\n\nConstraints\n\n2 \\leq n \\leq 10^5\n\n1 \\leq m \\leq 10^5\n\n1 \\leq s,t \\leq n\n\ns \\neq t\n\n1 \\leq u_i < v_i \\leq n\n\n1 \\leq a_i,b_i \\leq 10^9\n\nIf i\\neq j, then u_i \\neq u_j or v_i \\neq v_j.\n\nAny city can be reached from any city by changing trains.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn m s t\nu_1 v_1 a_1 b_1\n:\nu_m v_m a_m b_m\n\nOutput\n\nPrint n lines.\nIn the i-th line, print the maximum amount of snuuk that Kenkoooo has when he reaches City t if he goes on a trip from City s to City t after i-1 years.\n\nSample Input 1\n\n4 3 2 3\n1 4 1 100\n1 2 1 10\n1 3 20 1\n\nSample Output 1\n\n999999999999998\n999999999999989\n999999999999979\n999999999999897\n\nAfter 0 years, it is optimal to do the exchange in City 1.\n\nAfter 1 years, it is optimal to do the exchange in City 2.\n\nNote that City 1 can still be visited even after the exchange office is closed.\nAlso note that, if it was allowed to keep 1 yen when do the exchange in City 2 and change the remaining yen into snuuk, we could reach City 3 with 999999999999998 snuuk, but this is NOT allowed.\n\nAfter 2 years, it is optimal to do the exchange in City 3.\n\nAfter 3 years, it is optimal to do the exchange in City 4.\nNote that the same train can be used multiple times.\n\nSample Input 2\n\n8 12 3 8\n2 8 685087149 857180777\n6 7 298270585 209942236\n2 4 346080035 234079976\n2 5 131857300 22507157\n4 8 30723332 173476334\n2 6 480845267 448565596\n1 4 181424400 548830121\n4 5 57429995 195056405\n7 8 160277628 479932440\n1 6 475692952 203530153\n3 5 336869679 160714712\n2 7 389775999 199123879\n\nSample Output 2\n\n999999574976994\n999999574976994\n999999574976994\n999999574976994\n999999574976994\n999999574976994\n999999574976994\n999999574976994", "sample_input": "4 3 2 3\n1 4 1 100\n1 2 1 10\n1 3 20 1\n"}, "reference_outputs": ["999999999999998\n999999999999989\n999999999999979\n999999999999897\n"], "source_document_id": "p03305", "source_text": "Score : 400 points\n\nProblem Statement\n\nKenkoooo is planning a trip in Republic of Snuke.\nIn this country, there are n cities and m trains running.\nThe cities are numbered 1 through n, and the i-th train connects City u_i and v_i bidirectionally.\nAny city can be reached from any city by changing trains.\n\nTwo currencies are used in the country: yen and snuuk.\nAny train fare can be paid by both yen and snuuk.\nThe fare of the i-th train is a_i yen if paid in yen, and b_i snuuk if paid in snuuk.\n\nIn a city with a money exchange office, you can change 1 yen into 1 snuuk.\nHowever, when you do a money exchange, you have to change all your yen into snuuk.\nThat is, if Kenkoooo does a money exchange when he has X yen, he will then have X snuuk.\nCurrently, there is a money exchange office in every city, but the office in City i will shut down in i years and can never be used in and after that year.\n\nKenkoooo is planning to depart City s with 10^{15} yen in his pocket and head for City t, and change his yen into snuuk in some city while traveling.\nIt is acceptable to do the exchange in City s or City t.\n\nKenkoooo would like to have as much snuuk as possible when he reaches City t by making the optimal choices for the route to travel and the city to do the exchange.\nFor each i=0,...,n-1, find the maximum amount of snuuk that Kenkoooo has when he reaches City t if he goes on a trip from City s to City t after i years.\nYou can assume that the trip finishes within the year.\n\nConstraints\n\n2 \\leq n \\leq 10^5\n\n1 \\leq m \\leq 10^5\n\n1 \\leq s,t \\leq n\n\ns \\neq t\n\n1 \\leq u_i < v_i \\leq n\n\n1 \\leq a_i,b_i \\leq 10^9\n\nIf i\\neq j, then u_i \\neq u_j or v_i \\neq v_j.\n\nAny city can be reached from any city by changing trains.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn m s t\nu_1 v_1 a_1 b_1\n:\nu_m v_m a_m b_m\n\nOutput\n\nPrint n lines.\nIn the i-th line, print the maximum amount of snuuk that Kenkoooo has when he reaches City t if he goes on a trip from City s to City t after i-1 years.\n\nSample Input 1\n\n4 3 2 3\n1 4 1 100\n1 2 1 10\n1 3 20 1\n\nSample Output 1\n\n999999999999998\n999999999999989\n999999999999979\n999999999999897\n\nAfter 0 years, it is optimal to do the exchange in City 1.\n\nAfter 1 years, it is optimal to do the exchange in City 2.\n\nNote that City 1 can still be visited even after the exchange office is closed.\nAlso note that, if it was allowed to keep 1 yen when do the exchange in City 2 and change the remaining yen into snuuk, we could reach City 3 with 999999999999998 snuuk, but this is NOT allowed.\n\nAfter 2 years, it is optimal to do the exchange in City 3.\n\nAfter 3 years, it is optimal to do the exchange in City 4.\nNote that the same train can be used multiple times.\n\nSample Input 2\n\n8 12 3 8\n2 8 685087149 857180777\n6 7 298270585 209942236\n2 4 346080035 234079976\n2 5 131857300 22507157\n4 8 30723332 173476334\n2 6 480845267 448565596\n1 4 181424400 548830121\n4 5 57429995 195056405\n7 8 160277628 479932440\n1 6 475692952 203530153\n3 5 336869679 160714712\n2 7 389775999 199123879\n\nSample Output 2\n\n999999574976994\n999999574976994\n999999574976994\n999999574976994\n999999574976994\n999999574976994\n999999574976994\n999999574976994", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7654, "cpu_time_ms": 545, "memory_kb": 73316}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s222532847", "group_id": "codeNet:p03306", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n ;; -1: unspecified, 0: red, 1: black\n (colors (make-array n :element-type 'int8 :initial-element -1))\n (dp (make-array n :element-type 'fixnum :initial-element 0)))\n (dotimes (i m)\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1))\n (s (read-fixnum)))\n (push (cons u s) (aref graph v))\n (push (cons v s) (aref graph u))))\n (labels ((write-and-return (x)\n (println x)\n (return-from main))\n (answer ()\n (let ((min0 (loop for v below n\n when (= (aref colors v) 0)\n minimize (aref dp v)))\n (min1 (loop for v below n\n when (= (aref colors v) 1)\n minimize (aref dp v))))\n (write-and-return (max 0 (+ min0 min1 -1)))))\n (dfs (v value color)\n (dbg v value color dp)\n (cond ((= (aref colors v) -1)\n (setf (aref colors v) color\n (aref dp v) value)\n (loop for (neighbor . potential) in (aref graph v)\n do (dfs neighbor\n (- potential value)\n (logxor color 1))))\n ((= (aref colors v) color)\n (unless (= value (aref dp v))\n (write-and-return 0)))\n ;; odd cycle\n ((evenp (- value (aref dp v)))\n (let ((delta (floor (- value (aref dp v)) 2)))\n (dotimes (i n)\n (unless (= (aref colors i) -1)\n (if (= (aref colors i) (aref colors v))\n (incf (aref dp i) delta)\n (decf (aref dp i) delta))))\n (fill colors -1)\n (dfs-odd v (aref dp v))\n (write-and-return\n (if (every (lambda (x) (> x 0)) dp) 1 0))))\n (t (write-and-return 0))))\n (dfs-odd (v value)\n (dbg v value dp)\n (cond ((= (aref colors v) -1)\n (setf (aref colors v) 1\n (aref dp v) value)\n (loop for (neighbor . potential) in (aref graph v)\n do (dfs-odd neighbor (- potential value))))\n ((/= (aref dp v) value)\n (write-and-return 0)))))\n (dfs 0 0 0)\n (answer))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1 2 3\n2 3 5\n1 3 4\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 3\n1 2 6\n2 3 7\n3 4 5\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8 7\n1 2 1000000000\n2 3 2\n3 4 1000000000\n4 5 2\n5 6 1000000000\n6 7 2\n7 8 1000000000\n\"\n \"0\n\")))\n", "language": "Lisp", "metadata": {"date": 1581740825, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03306.html", "problem_id": "p03306", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03306/input.txt", "sample_output_relpath": "derived/input_output/data/p03306/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03306/Lisp/s222532847.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s222532847", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n ;; -1: unspecified, 0: red, 1: black\n (colors (make-array n :element-type 'int8 :initial-element -1))\n (dp (make-array n :element-type 'fixnum :initial-element 0)))\n (dotimes (i m)\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1))\n (s (read-fixnum)))\n (push (cons u s) (aref graph v))\n (push (cons v s) (aref graph u))))\n (labels ((write-and-return (x)\n (println x)\n (return-from main))\n (answer ()\n (let ((min0 (loop for v below n\n when (= (aref colors v) 0)\n minimize (aref dp v)))\n (min1 (loop for v below n\n when (= (aref colors v) 1)\n minimize (aref dp v))))\n (write-and-return (max 0 (+ min0 min1 -1)))))\n (dfs (v value color)\n (dbg v value color dp)\n (cond ((= (aref colors v) -1)\n (setf (aref colors v) color\n (aref dp v) value)\n (loop for (neighbor . potential) in (aref graph v)\n do (dfs neighbor\n (- potential value)\n (logxor color 1))))\n ((= (aref colors v) color)\n (unless (= value (aref dp v))\n (write-and-return 0)))\n ;; odd cycle\n ((evenp (- value (aref dp v)))\n (let ((delta (floor (- value (aref dp v)) 2)))\n (dotimes (i n)\n (unless (= (aref colors i) -1)\n (if (= (aref colors i) (aref colors v))\n (incf (aref dp i) delta)\n (decf (aref dp i) delta))))\n (fill colors -1)\n (dfs-odd v (aref dp v))\n (write-and-return\n (if (every (lambda (x) (> x 0)) dp) 1 0))))\n (t (write-and-return 0))))\n (dfs-odd (v value)\n (dbg v value dp)\n (cond ((= (aref colors v) -1)\n (setf (aref colors v) 1\n (aref dp v) value)\n (loop for (neighbor . potential) in (aref graph v)\n do (dfs-odd neighbor (- potential value))))\n ((/= (aref dp v) value)\n (write-and-return 0)))))\n (dfs 0 0 0)\n (answer))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1 2 3\n2 3 5\n1 3 4\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 3\n1 2 6\n2 3 7\n3 4 5\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8 7\n1 2 1000000000\n2 3 2\n3 4 1000000000\n4 5 2\n5 6 1000000000\n6 7 2\n7 8 1000000000\n\"\n \"0\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nKenkoooo found a simple connected graph.\nThe vertices are numbered 1 through n.\nThe i-th edge connects Vertex u_i and v_i, and has a fixed integer s_i.\n\nKenkoooo is trying to write a positive integer in each vertex so that the following condition is satisfied:\n\nFor every edge i, the sum of the positive integers written in Vertex u_i and v_i is equal to s_i.\n\nFind the number of such ways to write positive integers in the vertices.\n\nConstraints\n\n2 \\leq n \\leq 10^5\n\n1 \\leq m \\leq 10^5\n\n1 \\leq u_i < v_i \\leq n\n\n2 \\leq s_i \\leq 10^9\n\nIf i\\neq j, then u_i \\neq u_j or v_i \\neq v_j.\n\nThe graph is connected.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn m\nu_1 v_1 s_1\n:\nu_m v_m s_m\n\nOutput\n\nPrint the number of ways to write positive integers in the vertices so that the condition is satisfied.\n\nSample Input 1\n\n3 3\n1 2 3\n2 3 5\n1 3 4\n\nSample Output 1\n\n1\n\nThe condition will be satisfied if we write 1,2 and 3 in vertices 1,2 and 3, respectively.\nThere is no other way to satisfy the condition, so the answer is 1.\n\nSample Input 2\n\n4 3\n1 2 6\n2 3 7\n3 4 5\n\nSample Output 2\n\n3\n\nLet a,b,c and d be the numbers to write in vertices 1,2,3 and 4, respectively.\nThere are three quadruples (a,b,c,d) that satisfy the condition:\n\n(a,b,c,d)=(1,5,2,3)\n\n(a,b,c,d)=(2,4,3,2)\n\n(a,b,c,d)=(3,3,4,1)\n\nSample Input 3\n\n8 7\n1 2 1000000000\n2 3 2\n3 4 1000000000\n4 5 2\n5 6 1000000000\n6 7 2\n7 8 1000000000\n\nSample Output 3\n\n0", "sample_input": "3 3\n1 2 3\n2 3 5\n1 3 4\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03306", "source_text": "Score : 600 points\n\nProblem Statement\n\nKenkoooo found a simple connected graph.\nThe vertices are numbered 1 through n.\nThe i-th edge connects Vertex u_i and v_i, and has a fixed integer s_i.\n\nKenkoooo is trying to write a positive integer in each vertex so that the following condition is satisfied:\n\nFor every edge i, the sum of the positive integers written in Vertex u_i and v_i is equal to s_i.\n\nFind the number of such ways to write positive integers in the vertices.\n\nConstraints\n\n2 \\leq n \\leq 10^5\n\n1 \\leq m \\leq 10^5\n\n1 \\leq u_i < v_i \\leq n\n\n2 \\leq s_i \\leq 10^9\n\nIf i\\neq j, then u_i \\neq u_j or v_i \\neq v_j.\n\nThe graph is connected.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn m\nu_1 v_1 s_1\n:\nu_m v_m s_m\n\nOutput\n\nPrint the number of ways to write positive integers in the vertices so that the condition is satisfied.\n\nSample Input 1\n\n3 3\n1 2 3\n2 3 5\n1 3 4\n\nSample Output 1\n\n1\n\nThe condition will be satisfied if we write 1,2 and 3 in vertices 1,2 and 3, respectively.\nThere is no other way to satisfy the condition, so the answer is 1.\n\nSample Input 2\n\n4 3\n1 2 6\n2 3 7\n3 4 5\n\nSample Output 2\n\n3\n\nLet a,b,c and d be the numbers to write in vertices 1,2,3 and 4, respectively.\nThere are three quadruples (a,b,c,d) that satisfy the condition:\n\n(a,b,c,d)=(1,5,2,3)\n\n(a,b,c,d)=(2,4,3,2)\n\n(a,b,c,d)=(3,3,4,1)\n\nSample Input 3\n\n8 7\n1 2 1000000000\n2 3 2\n3 4 1000000000\n4 5 2\n5 6 1000000000\n6 7 2\n7 8 1000000000\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8099, "cpu_time_ms": 280, "memory_kb": 60472}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s608220508", "group_id": "codeNet:p03306", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n ;; -1: unspecified, 0: red, 1: black\n (colors (make-array n :element-type 'int8 :initial-element -1))\n (dp (make-array n :element-type 'fixnum :initial-element 0)))\n (dotimes (i m)\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1))\n (s (read-fixnum)))\n (push (cons u s) (aref graph v))\n (push (cons v s) (aref graph u))))\n (block proc\n (labels ((write-and-return (x)\n (println x)\n (return-from main))\n (answer ()\n (let ((min0 (loop for v below n\n when (= (aref colors v) 0)\n minimize (aref dp v)))\n (min1 (loop for v below n\n when (= (aref colors v) 1)\n minimize (aref dp v))))\n (write-and-return (max 0 (+ min0 min1 -1)))))\n (dfs (v value color loop-count)\n (dbg v value color loop-count)\n (cond ((= (aref colors v) -1)\n (setf (aref colors v) color\n (aref dp v) value)\n (loop for (neighbor . potential) in (aref graph v)\n do (dfs neighbor\n (- potential value)\n (logxor color 1)\n loop-count)))\n ((= (aref colors v) color)\n (unless (= value (aref dp v))\n (write-and-return 0)))\n ;; odd cycle\n ((= (aref dp v) value)\n (dfs-odd v value)\n (write-and-return\n (if (every (lambda (x) (> x 0)) dp) 1 0)))\n ((and (evenp (- value (aref dp v)))\n (zerop loop-count))\n (fill colors -1)\n (fill dp 0)\n (dfs v (ash (+ value (aref dp v)) -1) 0 (+ 1 loop-count))\n (answer))\n (t (write-and-return 0))))\n (dfs-odd (v value)\n (error \"Huh?\")\n (cond ((= (aref colors v) -1)\n (setf (aref colors v) 1\n (aref dp v) value)\n (loop for (neighbor . potential) in (aref graph v)\n do (dfs-odd neighbor (- potential value))))\n ((/= (aref dp v) value)\n (write-and-return 0)))))\n (dfs 0 0 0 0)\n (answer)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1 2 3\n2 3 5\n1 3 4\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 3\n1 2 6\n2 3 7\n3 4 5\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8 7\n1 2 1000000000\n2 3 2\n3 4 1000000000\n4 5 2\n5 6 1000000000\n6 7 2\n7 8 1000000000\n\"\n \"0\n\")))\n", "language": "Lisp", "metadata": {"date": 1581739603, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03306.html", "problem_id": "p03306", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03306/input.txt", "sample_output_relpath": "derived/input_output/data/p03306/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03306/Lisp/s608220508.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s608220508", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n ;; -1: unspecified, 0: red, 1: black\n (colors (make-array n :element-type 'int8 :initial-element -1))\n (dp (make-array n :element-type 'fixnum :initial-element 0)))\n (dotimes (i m)\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1))\n (s (read-fixnum)))\n (push (cons u s) (aref graph v))\n (push (cons v s) (aref graph u))))\n (block proc\n (labels ((write-and-return (x)\n (println x)\n (return-from main))\n (answer ()\n (let ((min0 (loop for v below n\n when (= (aref colors v) 0)\n minimize (aref dp v)))\n (min1 (loop for v below n\n when (= (aref colors v) 1)\n minimize (aref dp v))))\n (write-and-return (max 0 (+ min0 min1 -1)))))\n (dfs (v value color loop-count)\n (dbg v value color loop-count)\n (cond ((= (aref colors v) -1)\n (setf (aref colors v) color\n (aref dp v) value)\n (loop for (neighbor . potential) in (aref graph v)\n do (dfs neighbor\n (- potential value)\n (logxor color 1)\n loop-count)))\n ((= (aref colors v) color)\n (unless (= value (aref dp v))\n (write-and-return 0)))\n ;; odd cycle\n ((= (aref dp v) value)\n (dfs-odd v value)\n (write-and-return\n (if (every (lambda (x) (> x 0)) dp) 1 0)))\n ((and (evenp (- value (aref dp v)))\n (zerop loop-count))\n (fill colors -1)\n (fill dp 0)\n (dfs v (ash (+ value (aref dp v)) -1) 0 (+ 1 loop-count))\n (answer))\n (t (write-and-return 0))))\n (dfs-odd (v value)\n (error \"Huh?\")\n (cond ((= (aref colors v) -1)\n (setf (aref colors v) 1\n (aref dp v) value)\n (loop for (neighbor . potential) in (aref graph v)\n do (dfs-odd neighbor (- potential value))))\n ((/= (aref dp v) value)\n (write-and-return 0)))))\n (dfs 0 0 0 0)\n (answer)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1 2 3\n2 3 5\n1 3 4\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 3\n1 2 6\n2 3 7\n3 4 5\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8 7\n1 2 1000000000\n2 3 2\n3 4 1000000000\n4 5 2\n5 6 1000000000\n6 7 2\n7 8 1000000000\n\"\n \"0\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nKenkoooo found a simple connected graph.\nThe vertices are numbered 1 through n.\nThe i-th edge connects Vertex u_i and v_i, and has a fixed integer s_i.\n\nKenkoooo is trying to write a positive integer in each vertex so that the following condition is satisfied:\n\nFor every edge i, the sum of the positive integers written in Vertex u_i and v_i is equal to s_i.\n\nFind the number of such ways to write positive integers in the vertices.\n\nConstraints\n\n2 \\leq n \\leq 10^5\n\n1 \\leq m \\leq 10^5\n\n1 \\leq u_i < v_i \\leq n\n\n2 \\leq s_i \\leq 10^9\n\nIf i\\neq j, then u_i \\neq u_j or v_i \\neq v_j.\n\nThe graph is connected.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn m\nu_1 v_1 s_1\n:\nu_m v_m s_m\n\nOutput\n\nPrint the number of ways to write positive integers in the vertices so that the condition is satisfied.\n\nSample Input 1\n\n3 3\n1 2 3\n2 3 5\n1 3 4\n\nSample Output 1\n\n1\n\nThe condition will be satisfied if we write 1,2 and 3 in vertices 1,2 and 3, respectively.\nThere is no other way to satisfy the condition, so the answer is 1.\n\nSample Input 2\n\n4 3\n1 2 6\n2 3 7\n3 4 5\n\nSample Output 2\n\n3\n\nLet a,b,c and d be the numbers to write in vertices 1,2,3 and 4, respectively.\nThere are three quadruples (a,b,c,d) that satisfy the condition:\n\n(a,b,c,d)=(1,5,2,3)\n\n(a,b,c,d)=(2,4,3,2)\n\n(a,b,c,d)=(3,3,4,1)\n\nSample Input 3\n\n8 7\n1 2 1000000000\n2 3 2\n3 4 1000000000\n4 5 2\n5 6 1000000000\n6 7 2\n7 8 1000000000\n\nSample Output 3\n\n0", "sample_input": "3 3\n1 2 3\n2 3 5\n1 3 4\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03306", "source_text": "Score : 600 points\n\nProblem Statement\n\nKenkoooo found a simple connected graph.\nThe vertices are numbered 1 through n.\nThe i-th edge connects Vertex u_i and v_i, and has a fixed integer s_i.\n\nKenkoooo is trying to write a positive integer in each vertex so that the following condition is satisfied:\n\nFor every edge i, the sum of the positive integers written in Vertex u_i and v_i is equal to s_i.\n\nFind the number of such ways to write positive integers in the vertices.\n\nConstraints\n\n2 \\leq n \\leq 10^5\n\n1 \\leq m \\leq 10^5\n\n1 \\leq u_i < v_i \\leq n\n\n2 \\leq s_i \\leq 10^9\n\nIf i\\neq j, then u_i \\neq u_j or v_i \\neq v_j.\n\nThe graph is connected.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn m\nu_1 v_1 s_1\n:\nu_m v_m s_m\n\nOutput\n\nPrint the number of ways to write positive integers in the vertices so that the condition is satisfied.\n\nSample Input 1\n\n3 3\n1 2 3\n2 3 5\n1 3 4\n\nSample Output 1\n\n1\n\nThe condition will be satisfied if we write 1,2 and 3 in vertices 1,2 and 3, respectively.\nThere is no other way to satisfy the condition, so the answer is 1.\n\nSample Input 2\n\n4 3\n1 2 6\n2 3 7\n3 4 5\n\nSample Output 2\n\n3\n\nLet a,b,c and d be the numbers to write in vertices 1,2,3 and 4, respectively.\nThere are three quadruples (a,b,c,d) that satisfy the condition:\n\n(a,b,c,d)=(1,5,2,3)\n\n(a,b,c,d)=(2,4,3,2)\n\n(a,b,c,d)=(3,3,4,1)\n\nSample Input 3\n\n8 7\n1 2 1000000000\n2 3 2\n3 4 1000000000\n4 5 2\n5 6 1000000000\n6 7 2\n7 8 1000000000\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8153, "cpu_time_ms": 504, "memory_kb": 134456}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s714602711", "group_id": "codeNet:p03307", "input_text": "(defun hoge ()\n (let ((n (read)))\n (if (oddp n)\n (format t \"~D~%\" (* n 2))\n (format t \"~D~%\" n))))\n\n(hoge)\n", "language": "Lisp", "metadata": {"date": 1587231230, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03307.html", "problem_id": "p03307", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03307/input.txt", "sample_output_relpath": "derived/input_output/data/p03307/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03307/Lisp/s714602711.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s714602711", "user_id": "u777551961"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(defun hoge ()\n (let ((n (read)))\n (if (oddp n)\n (format t \"~D~%\" (* n 2))\n (format t \"~D~%\" n))))\n\n(hoge)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a positive integer N.\nFind the minimum positive integer divisible by both 2 and N.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum positive integer divisible by both 2 and N.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\n6 is divisible by both 2 and 3.\nAlso, there is no positive integer less than 6 that is divisible by both 2 and 3.\nThus, the answer is 6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\n1999999998", "sample_input": "3\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03307", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a positive integer N.\nFind the minimum positive integer divisible by both 2 and N.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum positive integer divisible by both 2 and N.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\n6 is divisible by both 2 and 3.\nAlso, there is no positive integer less than 6 that is divisible by both 2 and 3.\nThus, the answer is 6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\n1999999998", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 125, "cpu_time_ms": 59, "memory_kb": 7268}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s463254583", "group_id": "codeNet:p03307", "input_text": "(defun func (x)\n (if (oddp x)\n\t(* x 2)\n\tx))\n\n(princ (func (read)))\n", "language": "Lisp", "metadata": {"date": 1576899052, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03307.html", "problem_id": "p03307", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03307/input.txt", "sample_output_relpath": "derived/input_output/data/p03307/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03307/Lisp/s463254583.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s463254583", "user_id": "u493610446"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(defun func (x)\n (if (oddp x)\n\t(* x 2)\n\tx))\n\n(princ (func (read)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a positive integer N.\nFind the minimum positive integer divisible by both 2 and N.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum positive integer divisible by both 2 and N.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\n6 is divisible by both 2 and 3.\nAlso, there is no positive integer less than 6 that is divisible by both 2 and 3.\nThus, the answer is 6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\n1999999998", "sample_input": "3\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03307", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a positive integer N.\nFind the minimum positive integer divisible by both 2 and N.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum positive integer divisible by both 2 and N.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\n6 is divisible by both 2 and 3.\nAlso, there is no positive integer less than 6 that is divisible by both 2 and 3.\nThus, the answer is 6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\n1999999998", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 68, "cpu_time_ms": 126, "memory_kb": 12512}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s395531100", "group_id": "codeNet:p03307", "input_text": "(defun ans (n)\n (if (evenp n) n (* n 2)))\n\n\n(format t \"~a~%\" (ans (read)))", "language": "Lisp", "metadata": {"date": 1569025466, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03307.html", "problem_id": "p03307", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03307/input.txt", "sample_output_relpath": "derived/input_output/data/p03307/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03307/Lisp/s395531100.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s395531100", "user_id": "u358554431"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(defun ans (n)\n (if (evenp n) n (* n 2)))\n\n\n(format t \"~a~%\" (ans (read)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a positive integer N.\nFind the minimum positive integer divisible by both 2 and N.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum positive integer divisible by both 2 and N.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\n6 is divisible by both 2 and 3.\nAlso, there is no positive integer less than 6 that is divisible by both 2 and 3.\nThus, the answer is 6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\n1999999998", "sample_input": "3\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03307", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a positive integer N.\nFind the minimum positive integer divisible by both 2 and N.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum positive integer divisible by both 2 and N.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\n6 is divisible by both 2 and 3.\nAlso, there is no positive integer less than 6 that is divisible by both 2 and 3.\nThus, the answer is 6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\n1999999998", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 75, "cpu_time_ms": 122, "memory_kb": 12384}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s021794481", "group_id": "codeNet:p03307", "input_text": "(let* ((n (read)))\n(print (if (mod n 2) n (* n 2))))", "language": "Lisp", "metadata": {"date": 1538090035, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03307.html", "problem_id": "p03307", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03307/input.txt", "sample_output_relpath": "derived/input_output/data/p03307/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03307/Lisp/s021794481.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s021794481", "user_id": "u610490393"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(let* ((n (read)))\n(print (if (mod n 2) n (* n 2))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a positive integer N.\nFind the minimum positive integer divisible by both 2 and N.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum positive integer divisible by both 2 and N.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\n6 is divisible by both 2 and 3.\nAlso, there is no positive integer less than 6 that is divisible by both 2 and 3.\nThus, the answer is 6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\n1999999998", "sample_input": "3\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03307", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a positive integer N.\nFind the minimum positive integer divisible by both 2 and N.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum positive integer divisible by both 2 and N.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\n6 is divisible by both 2 and 3.\nAlso, there is no positive integer less than 6 that is divisible by both 2 and 3.\nThus, the answer is 6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\n1999999998", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 52, "cpu_time_ms": 122, "memory_kb": 10596}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s972181083", "group_id": "codeNet:p03307", "input_text": "(let ((n (read)))\n (declare (fixnum n)\n (optimize (safety 0) (speed 3) (debug 0)))\n (princ (if (zerop (rem n 2))\n n\n (* 2 n))))", "language": "Lisp", "metadata": {"date": 1533472366, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03307.html", "problem_id": "p03307", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03307/input.txt", "sample_output_relpath": "derived/input_output/data/p03307/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03307/Lisp/s972181083.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s972181083", "user_id": "u913204306"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(let ((n (read)))\n (declare (fixnum n)\n (optimize (safety 0) (speed 3) (debug 0)))\n (princ (if (zerop (rem n 2))\n n\n (* 2 n))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a positive integer N.\nFind the minimum positive integer divisible by both 2 and N.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum positive integer divisible by both 2 and N.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\n6 is divisible by both 2 and 3.\nAlso, there is no positive integer less than 6 that is divisible by both 2 and 3.\nThus, the answer is 6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\n1999999998", "sample_input": "3\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03307", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a positive integer N.\nFind the minimum positive integer divisible by both 2 and N.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum positive integer divisible by both 2 and N.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\n6 is divisible by both 2 and 3.\nAlso, there is no positive integer less than 6 that is divisible by both 2 and 3.\nThus, the answer is 6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\n1999999998", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 163, "cpu_time_ms": 21, "memory_kb": 3812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s889681114", "group_id": "codeNet:p03307", "input_text": "(let ((N (read))) (if (oddp N) (princ (* 2 N)) (princ N)))", "language": "Lisp", "metadata": {"date": 1531406688, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03307.html", "problem_id": "p03307", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03307/input.txt", "sample_output_relpath": "derived/input_output/data/p03307/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03307/Lisp/s889681114.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s889681114", "user_id": "u425351967"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(let ((N (read))) (if (oddp N) (princ (* 2 N)) (princ N)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a positive integer N.\nFind the minimum positive integer divisible by both 2 and N.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum positive integer divisible by both 2 and N.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\n6 is divisible by both 2 and 3.\nAlso, there is no positive integer less than 6 that is divisible by both 2 and 3.\nThus, the answer is 6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\n1999999998", "sample_input": "3\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03307", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a positive integer N.\nFind the minimum positive integer divisible by both 2 and N.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum positive integer divisible by both 2 and N.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\n6 is divisible by both 2 and 3.\nAlso, there is no positive integer less than 6 that is divisible by both 2 and 3.\nThus, the answer is 6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\n1999999998", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 58, "cpu_time_ms": 131, "memory_kb": 12384}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s823427361", "group_id": "codeNet:p03307", "input_text": "(defun solver ()\n (let ((n (read)))\n (if (zerop (mod n 2))\n (format t \"~a~%\" n)\n (format t \"~a~%\" (* n 2)))))\n\n(solver)", "language": "Lisp", "metadata": {"date": 1530491523, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03307.html", "problem_id": "p03307", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03307/input.txt", "sample_output_relpath": "derived/input_output/data/p03307/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03307/Lisp/s823427361.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s823427361", "user_id": "u183015556"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(defun solver ()\n (let ((n (read)))\n (if (zerop (mod n 2))\n (format t \"~a~%\" n)\n (format t \"~a~%\" (* n 2)))))\n\n(solver)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a positive integer N.\nFind the minimum positive integer divisible by both 2 and N.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum positive integer divisible by both 2 and N.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\n6 is divisible by both 2 and 3.\nAlso, there is no positive integer less than 6 that is divisible by both 2 and 3.\nThus, the answer is 6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\n1999999998", "sample_input": "3\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03307", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a positive integer N.\nFind the minimum positive integer divisible by both 2 and N.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum positive integer divisible by both 2 and N.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\n6 is divisible by both 2 and 3.\nAlso, there is no positive integer less than 6 that is divisible by both 2 and 3.\nThus, the answer is 6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n10\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\n1999999998", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 137, "cpu_time_ms": 423, "memory_kb": 13152}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s802884140", "group_id": "codeNet:p03308", "input_text": "(defparameter n (read))\n(defparameter s (read-line))\n\n(defun split-py (str)\n (let ((pos (position #\\space str)))\n (cond ((null pos) (list str))\n (t (cons (subseq str 0 pos) (split-py (subseq str (1+ pos))))))))\n\n; incf は1+してsetq\n; 1+ は1+した値を返すだけ\n\n(let ((L (sort (mapcar (lambda (x) (read-from-string x)) (split-py s)) #'<)))\n (princ (- (car (last L)) (first L))))", "language": "Lisp", "metadata": {"date": 1563327791, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03308.html", "problem_id": "p03308", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03308/input.txt", "sample_output_relpath": "derived/input_output/data/p03308/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03308/Lisp/s802884140.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s802884140", "user_id": "u480300350"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defparameter n (read))\n(defparameter s (read-line))\n\n(defun split-py (str)\n (let ((pos (position #\\space str)))\n (cond ((null pos) (list str))\n (t (cons (subseq str 0 pos) (split-py (subseq str (1+ pos))))))))\n\n; incf は1+してsetq\n; 1+ は1+した値を返すだけ\n\n(let ((L (sort (mapcar (lambda (x) (read-from-string x)) (split-py s)) #'<)))\n (princ (- (car (last L)) (first L))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given an integer sequence A of length N.\nFind the maximum absolute difference of two elements (with different indices) in A.\n\nConstraints\n\n2 \\leq N \\leq 100\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum absolute difference of two elements (with different indices) in A.\n\nSample Input 1\n\n4\n1 4 6 3\n\nSample Output 1\n\n5\n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\nSample Input 2\n\n2\n1000000000 1\n\nSample Output 2\n\n999999999\n\nSample Input 3\n\n5\n1 1 1 1 1\n\nSample Output 3\n\n0", "sample_input": "4\n1 4 6 3\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03308", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given an integer sequence A of length N.\nFind the maximum absolute difference of two elements (with different indices) in A.\n\nConstraints\n\n2 \\leq N \\leq 100\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum absolute difference of two elements (with different indices) in A.\n\nSample Input 1\n\n4\n1 4 6 3\n\nSample Output 1\n\n5\n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\nSample Input 2\n\n2\n1000000000 1\n\nSample Output 2\n\n999999999\n\nSample Input 3\n\n5\n1 1 1 1 1\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 402, "cpu_time_ms": 37, "memory_kb": 5096}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s303768930", "group_id": "codeNet:p03309", "input_text": "(defun moge ()\n (let ((n (read))\n (lst nil))\n (dotimes (i n)\n (push (read) lst))\n (reverse lst)))\n\n\n(defun chuou (b-lst)\n (let* ((len (length b-lst))\n (chuou-n (floor len 2))\n (new-lst (sort b-lst #'<)))\n (if (oddp len)\n (nth chuou-n new-lst)\n (let ((c1 (nth chuou-n new-lst))\n (c2 (nth (1- chuou-n) new-lst)))\n (floor (+ c1 c2) 2)))))\n\n(defun hoge ()\n (let* ((lst (moge))\n (b-lst (loop :for a :in lst\n :for i :from 1\n :collect (- a i)))\n (b (chuou b-lst))\n (v (loop :for a :in lst\n :for i :from 1\n :sum (abs (- a (+ b i))))))\n (format t \"~D~%\" v)))\n\n\n(hoge)\n", "language": "Lisp", "metadata": {"date": 1587326867, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03309.html", "problem_id": "p03309", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03309/input.txt", "sample_output_relpath": "derived/input_output/data/p03309/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03309/Lisp/s303768930.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s303768930", "user_id": "u777551961"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun moge ()\n (let ((n (read))\n (lst nil))\n (dotimes (i n)\n (push (read) lst))\n (reverse lst)))\n\n\n(defun chuou (b-lst)\n (let* ((len (length b-lst))\n (chuou-n (floor len 2))\n (new-lst (sort b-lst #'<)))\n (if (oddp len)\n (nth chuou-n new-lst)\n (let ((c1 (nth chuou-n new-lst))\n (c2 (nth (1- chuou-n) new-lst)))\n (floor (+ c1 c2) 2)))))\n\n(defun hoge ()\n (let* ((lst (moge))\n (b-lst (loop :for a :in lst\n :for i :from 1\n :collect (- a i)))\n (b (chuou b-lst))\n (v (loop :for a :in lst\n :for i :from 1\n :sum (abs (- a (+ b i))))))\n (format t \"~D~%\" v)))\n\n\n(hoge)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke has an integer sequence A of length N.\n\nHe will freely choose an integer b.\nHere, he will get sad if A_i and b+i are far from each other.\nMore specifically, the sadness of Snuke is calculated as follows:\n\nabs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))\n\nHere, abs(x) is a function that returns the absolute value of x.\n\nFind the minimum possible sadness of Snuke.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum possible sadness of Snuke.\n\nSample Input 1\n\n5\n2 2 3 5 5\n\nSample Output 1\n\n2\n\nIf we choose b=0, the sadness of Snuke would be abs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2.\nAny choice of b does not make the sadness of Snuke less than 2, so the answer is 2.\n\nSample Input 2\n\n9\n1 2 3 4 5 6 7 8 9\n\nSample Output 2\n\n0\n\nSample Input 3\n\n6\n6 5 4 3 2 1\n\nSample Output 3\n\n18\n\nSample Input 4\n\n7\n1 1 1 1 2 3 4\n\nSample Output 4\n\n6", "sample_input": "5\n2 2 3 5 5\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03309", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke has an integer sequence A of length N.\n\nHe will freely choose an integer b.\nHere, he will get sad if A_i and b+i are far from each other.\nMore specifically, the sadness of Snuke is calculated as follows:\n\nabs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))\n\nHere, abs(x) is a function that returns the absolute value of x.\n\nFind the minimum possible sadness of Snuke.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum possible sadness of Snuke.\n\nSample Input 1\n\n5\n2 2 3 5 5\n\nSample Output 1\n\n2\n\nIf we choose b=0, the sadness of Snuke would be abs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2.\nAny choice of b does not make the sadness of Snuke less than 2, so the answer is 2.\n\nSample Input 2\n\n9\n1 2 3 4 5 6 7 8 9\n\nSample Output 2\n\n0\n\nSample Input 3\n\n6\n6 5 4 3 2 1\n\nSample Output 3\n\n18\n\nSample Input 4\n\n7\n1 1 1 1 2 3 4\n\nSample Output 4\n\n6", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 738, "cpu_time_ms": 627, "memory_kb": 61796}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s167538282", "group_id": "codeNet:p03309", "input_text": "(defun LinearApproximation ()\n (let ((B) (sb 0) (count 0) (*n* (read))\n (dotimes (i *n*)\n (push (- (read) (1+ i)) B))\n (sort B #'<)\n (setf sb (nth (floor *n* 2) B))\n (apply #'+ (mapcar (lambda (Bi)\n (abs (- Bi sb))) B))))\n\n(format t \"~A~%\" (LinearApproximation))", "language": "Lisp", "metadata": {"date": 1531972702, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03309.html", "problem_id": "p03309", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03309/input.txt", "sample_output_relpath": "derived/input_output/data/p03309/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03309/Lisp/s167538282.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s167538282", "user_id": "u231458241"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun LinearApproximation ()\n (let ((B) (sb 0) (count 0) (*n* (read))\n (dotimes (i *n*)\n (push (- (read) (1+ i)) B))\n (sort B #'<)\n (setf sb (nth (floor *n* 2) B))\n (apply #'+ (mapcar (lambda (Bi)\n (abs (- Bi sb))) B))))\n\n(format t \"~A~%\" (LinearApproximation))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke has an integer sequence A of length N.\n\nHe will freely choose an integer b.\nHere, he will get sad if A_i and b+i are far from each other.\nMore specifically, the sadness of Snuke is calculated as follows:\n\nabs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))\n\nHere, abs(x) is a function that returns the absolute value of x.\n\nFind the minimum possible sadness of Snuke.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum possible sadness of Snuke.\n\nSample Input 1\n\n5\n2 2 3 5 5\n\nSample Output 1\n\n2\n\nIf we choose b=0, the sadness of Snuke would be abs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2.\nAny choice of b does not make the sadness of Snuke less than 2, so the answer is 2.\n\nSample Input 2\n\n9\n1 2 3 4 5 6 7 8 9\n\nSample Output 2\n\n0\n\nSample Input 3\n\n6\n6 5 4 3 2 1\n\nSample Output 3\n\n18\n\nSample Input 4\n\n7\n1 1 1 1 2 3 4\n\nSample Output 4\n\n6", "sample_input": "5\n2 2 3 5 5\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03309", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke has an integer sequence A of length N.\n\nHe will freely choose an integer b.\nHere, he will get sad if A_i and b+i are far from each other.\nMore specifically, the sadness of Snuke is calculated as follows:\n\nabs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))\n\nHere, abs(x) is a function that returns the absolute value of x.\n\nFind the minimum possible sadness of Snuke.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum possible sadness of Snuke.\n\nSample Input 1\n\n5\n2 2 3 5 5\n\nSample Output 1\n\n2\n\nIf we choose b=0, the sadness of Snuke would be abs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2.\nAny choice of b does not make the sadness of Snuke less than 2, so the answer is 2.\n\nSample Input 2\n\n9\n1 2 3 4 5 6 7 8 9\n\nSample Output 2\n\n0\n\nSample Input 3\n\n6\n6 5 4 3 2 1\n\nSample Output 3\n\n18\n\nSample Input 4\n\n7\n1 1 1 1 2 3 4\n\nSample Output 4\n\n6", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 296, "cpu_time_ms": 12, "memory_kb": 3432}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s722274311", "group_id": "codeNet:p03310", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint32))\n (cumuls (make-array (+ n 1) :element-type 'uint62 :initial-element 0))\n (res most-positive-fixnum))\n (declare (uint62 n res))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref cumuls (+ i 1)) (+ (aref cumuls i) (aref as i))))\n (labels ((query (l r)\n (- (aref cumuls r) (aref cumuls l))))\n (declare (inline query))\n (loop for pivot from 2 to (- n 2)\n do (labels ((query-pq (i)\n (abs (- (query 0 i) (query i pivot))))\n (query-rs (i)\n (abs (- (query pivot i) (query i n)))))\n (declare (inline query-pq query-rs))\n (let* ((qtile1 (sb-int:named-let bisect ((ng 0) (ok pivot))\n (declare (uint32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ok ng) -1)))\n (if (>= (query-pq (+ mid 1))\n (query-pq mid))\n (bisect ng mid)\n (bisect mid ok))))))\n (qtile3 (sb-int:named-let bisect ((ng pivot) (ok n))\n (declare (uint32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ok ng) -1)))\n (if (>= (query-rs (+ mid 1))\n (query-rs mid))\n (bisect ng mid)\n (bisect mid ok))))))\n (p (query 0 qtile1))\n (q (query qtile1 pivot))\n (r (query pivot qtile3))\n (s (query qtile3 n)))\n (dbg pivot qtile1 qtile3 p q r s)\n (setq res (min res (- (max p q r s) (min p q r s))))))))\n (println res)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1565817736, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03310.html", "problem_id": "p03310", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03310/input.txt", "sample_output_relpath": "derived/input_output/data/p03310/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03310/Lisp/s722274311.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s722274311", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint32))\n (cumuls (make-array (+ n 1) :element-type 'uint62 :initial-element 0))\n (res most-positive-fixnum))\n (declare (uint62 n res))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref cumuls (+ i 1)) (+ (aref cumuls i) (aref as i))))\n (labels ((query (l r)\n (- (aref cumuls r) (aref cumuls l))))\n (declare (inline query))\n (loop for pivot from 2 to (- n 2)\n do (labels ((query-pq (i)\n (abs (- (query 0 i) (query i pivot))))\n (query-rs (i)\n (abs (- (query pivot i) (query i n)))))\n (declare (inline query-pq query-rs))\n (let* ((qtile1 (sb-int:named-let bisect ((ng 0) (ok pivot))\n (declare (uint32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ok ng) -1)))\n (if (>= (query-pq (+ mid 1))\n (query-pq mid))\n (bisect ng mid)\n (bisect mid ok))))))\n (qtile3 (sb-int:named-let bisect ((ng pivot) (ok n))\n (declare (uint32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ok ng) -1)))\n (if (>= (query-rs (+ mid 1))\n (query-rs mid))\n (bisect ng mid)\n (bisect mid ok))))))\n (p (query 0 qtile1))\n (q (query qtile1 pivot))\n (r (query pivot qtile3))\n (s (query qtile3 n)))\n (dbg pivot qtile1 qtile3 p q r s)\n (setq res (min res (- (max p q r s) (min p q r s))))))))\n (println res)))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nSnuke has an integer sequence A of length N.\n\nHe will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E.\nThe positions of the cuts can be freely chosen.\n\nLet P,Q,R,S be the sums of the elements in B,C,D,E, respectively.\nSnuke is happier when the absolute difference of the maximum and the minimum among P,Q,R,S is smaller.\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nConstraints\n\n4 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nSample Input 1\n\n5\n3 2 4 1 2\n\nSample Output 1\n\n2\n\nIf we divide A as B,C,D,E=(3),(2),(4),(1,2), then P=3,Q=2,R=4,S=1+2=3.\nHere, the maximum and the minimum among P,Q,R,S are 4 and 2, with the absolute difference of 2.\nWe cannot make the absolute difference of the maximum and the minimum less than 2, so the answer is 2.\n\nSample Input 2\n\n10\n10 71 84 33 6 47 23 25 52 64\n\nSample Output 2\n\n36\n\nSample Input 3\n\n7\n1 2 3 1000000000 4 5 6\n\nSample Output 3\n\n999999994", "sample_input": "5\n3 2 4 1 2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03310", "source_text": "Score : 600 points\n\nProblem Statement\n\nSnuke has an integer sequence A of length N.\n\nHe will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E.\nThe positions of the cuts can be freely chosen.\n\nLet P,Q,R,S be the sums of the elements in B,C,D,E, respectively.\nSnuke is happier when the absolute difference of the maximum and the minimum among P,Q,R,S is smaller.\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nConstraints\n\n4 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nSample Input 1\n\n5\n3 2 4 1 2\n\nSample Output 1\n\n2\n\nIf we divide A as B,C,D,E=(3),(2),(4),(1,2), then P=3,Q=2,R=4,S=1+2=3.\nHere, the maximum and the minimum among P,Q,R,S are 4 and 2, with the absolute difference of 2.\nWe cannot make the absolute difference of the maximum and the minimum less than 2, so the answer is 2.\n\nSample Input 2\n\n10\n10 71 84 33 6 47 23 25 52 64\n\nSample Output 2\n\n36\n\nSample Input 3\n\n7\n1 2 3 1000000000 4 5 6\n\nSample Output 3\n\n999999994", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4625, "cpu_time_ms": 208, "memory_kb": 24552}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s141454141", "group_id": "codeNet:p03310", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint32))\n (cumuls (make-array (+ n 1) :element-type 'uint62 :initial-element 0))\n (res most-positive-fixnum))\n (declare (uint62 n res))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref cumuls (+ i 1)) (+ (aref cumuls i) (aref as i))))\n (labels ((query (l r)\n (- (aref cumuls r) (aref cumuls l))))\n (loop for pivot from 2 to (- n 2)\n do (labels ((query-pq (i)\n (abs (- (query 0 i) (query i pivot))))\n (query-rs (i)\n (abs (- (query pivot i) (query i n)))))\n (let* ((qtile1 (sb-int:named-let bisect ((ng 0) (ok pivot))\n (declare (uint32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ok ng) -1)))\n (if (>= (query-pq (+ mid 1))\n (query-pq mid))\n (bisect ng mid)\n (bisect mid ok))))))\n (qtile3 (sb-int:named-let bisect ((ng pivot) (ok n))\n (declare (uint32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ok ng) -1)))\n (if (>= (query-rs (+ mid 1))\n (query-rs mid))\n (bisect ng mid)\n (bisect mid ok))))))\n (p (query 0 qtile1))\n (q (query qtile1 pivot))\n (r (query pivot qtile3))\n (s (query qtile3 n)))\n (dbg pivot qtile1 qtile3 p q r s)\n (setq res (min res (- (max p q r s) (min p q r s))))))))\n (println res)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1565817628, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03310.html", "problem_id": "p03310", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03310/input.txt", "sample_output_relpath": "derived/input_output/data/p03310/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03310/Lisp/s141454141.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s141454141", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint32))\n (cumuls (make-array (+ n 1) :element-type 'uint62 :initial-element 0))\n (res most-positive-fixnum))\n (declare (uint62 n res))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref cumuls (+ i 1)) (+ (aref cumuls i) (aref as i))))\n (labels ((query (l r)\n (- (aref cumuls r) (aref cumuls l))))\n (loop for pivot from 2 to (- n 2)\n do (labels ((query-pq (i)\n (abs (- (query 0 i) (query i pivot))))\n (query-rs (i)\n (abs (- (query pivot i) (query i n)))))\n (let* ((qtile1 (sb-int:named-let bisect ((ng 0) (ok pivot))\n (declare (uint32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ok ng) -1)))\n (if (>= (query-pq (+ mid 1))\n (query-pq mid))\n (bisect ng mid)\n (bisect mid ok))))))\n (qtile3 (sb-int:named-let bisect ((ng pivot) (ok n))\n (declare (uint32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (ash (+ ok ng) -1)))\n (if (>= (query-rs (+ mid 1))\n (query-rs mid))\n (bisect ng mid)\n (bisect mid ok))))))\n (p (query 0 qtile1))\n (q (query qtile1 pivot))\n (r (query pivot qtile3))\n (s (query qtile3 n)))\n (dbg pivot qtile1 qtile3 p q r s)\n (setq res (min res (- (max p q r s) (min p q r s))))))))\n (println res)))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nSnuke has an integer sequence A of length N.\n\nHe will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E.\nThe positions of the cuts can be freely chosen.\n\nLet P,Q,R,S be the sums of the elements in B,C,D,E, respectively.\nSnuke is happier when the absolute difference of the maximum and the minimum among P,Q,R,S is smaller.\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nConstraints\n\n4 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nSample Input 1\n\n5\n3 2 4 1 2\n\nSample Output 1\n\n2\n\nIf we divide A as B,C,D,E=(3),(2),(4),(1,2), then P=3,Q=2,R=4,S=1+2=3.\nHere, the maximum and the minimum among P,Q,R,S are 4 and 2, with the absolute difference of 2.\nWe cannot make the absolute difference of the maximum and the minimum less than 2, so the answer is 2.\n\nSample Input 2\n\n10\n10 71 84 33 6 47 23 25 52 64\n\nSample Output 2\n\n36\n\nSample Input 3\n\n7\n1 2 3 1000000000 4 5 6\n\nSample Output 3\n\n999999994", "sample_input": "5\n3 2 4 1 2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03310", "source_text": "Score : 600 points\n\nProblem Statement\n\nSnuke has an integer sequence A of length N.\n\nHe will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E.\nThe positions of the cuts can be freely chosen.\n\nLet P,Q,R,S be the sums of the elements in B,C,D,E, respectively.\nSnuke is happier when the absolute difference of the maximum and the minimum among P,Q,R,S is smaller.\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nConstraints\n\n4 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nSample Input 1\n\n5\n3 2 4 1 2\n\nSample Output 1\n\n2\n\nIf we divide A as B,C,D,E=(3),(2),(4),(1,2), then P=3,Q=2,R=4,S=1+2=3.\nHere, the maximum and the minimum among P,Q,R,S are 4 and 2, with the absolute difference of 2.\nWe cannot make the absolute difference of the maximum and the minimum less than 2, so the answer is 2.\n\nSample Input 2\n\n10\n10 71 84 33 6 47 23 25 52 64\n\nSample Output 2\n\n36\n\nSample Input 3\n\n7\n1 2 3 1000000000 4 5 6\n\nSample Output 3\n\n999999994", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4504, "cpu_time_ms": 247, "memory_kb": 16872}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s438702648", "group_id": "codeNet:p03310", "input_text": "(defun get-max (data start end)\n (if (zerop start)\n (aref data (1- end))\n (- (aref data (1- end))\n (aref data (1- start)))))\n\n(defun get-diff (data start-point second-point end-point)\n (abs (- (get-max data second-point end-point)\n (get-max data start-point second-point))))\n\n(defun equal-cut ()\n (declare (optimize (speed 3) (safety 0) (debug 0) (space 0)))\n (let* ((n (read))\n (data (make-array n :initial-contents (loop repeat n\n sum (read) into summed-a\n collect summed-a))))\n (loop for second-separator from 2 below (1- n)\n with first-separator = 1\n with third-separator = 3\n with minimized-diff = #.(* (* 2 (expt 10 5)) (expt 10 9))\n when (>= second-separator third-separator)\n do (setq third-separator (1+ second-separator))\n do (loop (if (and (< first-separator (1- second-separator))\n (< (get-diff data 0 (1+ first-separator) second-separator)\n (get-diff data 0 first-separator second-separator)))\n (incf first-separator)\n (return)))\n (loop (if (and (< third-separator (1- n))\n (< (get-diff data second-separator (1+ third-separator) n)\n (get-diff data second-separator third-separator n)))\n (incf third-separator)\n (return)))\n (let* ((max-list (list (get-max data 0 first-separator)\n (get-max data first-separator second-separator)\n (get-max data second-separator third-separator)\n (get-max data third-separator n)))\n (diff (- (apply #'max max-list) (apply #'min max-list))))\n (if (< diff minimized-diff)\n (setq minimized-diff diff)))\n finally (princ minimized-diff))))\n\n(equal-cut)", "language": "Lisp", "metadata": {"date": 1533584720, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03310.html", "problem_id": "p03310", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03310/input.txt", "sample_output_relpath": "derived/input_output/data/p03310/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03310/Lisp/s438702648.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s438702648", "user_id": "u913204306"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun get-max (data start end)\n (if (zerop start)\n (aref data (1- end))\n (- (aref data (1- end))\n (aref data (1- start)))))\n\n(defun get-diff (data start-point second-point end-point)\n (abs (- (get-max data second-point end-point)\n (get-max data start-point second-point))))\n\n(defun equal-cut ()\n (declare (optimize (speed 3) (safety 0) (debug 0) (space 0)))\n (let* ((n (read))\n (data (make-array n :initial-contents (loop repeat n\n sum (read) into summed-a\n collect summed-a))))\n (loop for second-separator from 2 below (1- n)\n with first-separator = 1\n with third-separator = 3\n with minimized-diff = #.(* (* 2 (expt 10 5)) (expt 10 9))\n when (>= second-separator third-separator)\n do (setq third-separator (1+ second-separator))\n do (loop (if (and (< first-separator (1- second-separator))\n (< (get-diff data 0 (1+ first-separator) second-separator)\n (get-diff data 0 first-separator second-separator)))\n (incf first-separator)\n (return)))\n (loop (if (and (< third-separator (1- n))\n (< (get-diff data second-separator (1+ third-separator) n)\n (get-diff data second-separator third-separator n)))\n (incf third-separator)\n (return)))\n (let* ((max-list (list (get-max data 0 first-separator)\n (get-max data first-separator second-separator)\n (get-max data second-separator third-separator)\n (get-max data third-separator n)))\n (diff (- (apply #'max max-list) (apply #'min max-list))))\n (if (< diff minimized-diff)\n (setq minimized-diff diff)))\n finally (princ minimized-diff))))\n\n(equal-cut)", "problem_context": "Score : 600 points\n\nProblem Statement\n\nSnuke has an integer sequence A of length N.\n\nHe will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E.\nThe positions of the cuts can be freely chosen.\n\nLet P,Q,R,S be the sums of the elements in B,C,D,E, respectively.\nSnuke is happier when the absolute difference of the maximum and the minimum among P,Q,R,S is smaller.\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nConstraints\n\n4 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nSample Input 1\n\n5\n3 2 4 1 2\n\nSample Output 1\n\n2\n\nIf we divide A as B,C,D,E=(3),(2),(4),(1,2), then P=3,Q=2,R=4,S=1+2=3.\nHere, the maximum and the minimum among P,Q,R,S are 4 and 2, with the absolute difference of 2.\nWe cannot make the absolute difference of the maximum and the minimum less than 2, so the answer is 2.\n\nSample Input 2\n\n10\n10 71 84 33 6 47 23 25 52 64\n\nSample Output 2\n\n36\n\nSample Input 3\n\n7\n1 2 3 1000000000 4 5 6\n\nSample Output 3\n\n999999994", "sample_input": "5\n3 2 4 1 2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03310", "source_text": "Score : 600 points\n\nProblem Statement\n\nSnuke has an integer sequence A of length N.\n\nHe will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E.\nThe positions of the cuts can be freely chosen.\n\nLet P,Q,R,S be the sums of the elements in B,C,D,E, respectively.\nSnuke is happier when the absolute difference of the maximum and the minimum among P,Q,R,S is smaller.\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nConstraints\n\n4 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nSample Input 1\n\n5\n3 2 4 1 2\n\nSample Output 1\n\n2\n\nIf we divide A as B,C,D,E=(3),(2),(4),(1,2), then P=3,Q=2,R=4,S=1+2=3.\nHere, the maximum and the minimum among P,Q,R,S are 4 and 2, with the absolute difference of 2.\nWe cannot make the absolute difference of the maximum and the minimum less than 2, so the answer is 2.\n\nSample Input 2\n\n10\n10 71 84 33 6 47 23 25 52 64\n\nSample Output 2\n\n36\n\nSample Input 3\n\n7\n1 2 3 1000000000 4 5 6\n\nSample Output 3\n\n999999994", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2085, "cpu_time_ms": 611, "memory_kb": 61928}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s199165966", "group_id": "codeNet:p03310", "input_text": "(let ((data))\n (defun init-data (n)\n (setq data (make-array n :initial-contents (loop repeat n for an = (read) sum an into sum-a collect sum-a))))\n\n (defun get-sum (start end)\n (if (zerop start)\n (aref data (1- end))\n (- (aref data (1- end)) (aref data (1- start)))))\n\n (defun get-split-sum (start end)\n (labels ((get-split-sum (current-split-point diff-min split-point)\n (if (< current-split-point end)\n (let ((diff (abs (- (get-sum current-split-point end)\n (get-sum start current-split-point)))))\n (if (< diff diff-min)\n (get-split-sum (1+ current-split-point) diff current-split-point)\n (get-split-sum (1+ current-split-point) diff-min split-point)))\n (values (get-sum start split-point)\n (get-sum split-point end)))))\n (get-split-sum (1+ start) #.(expt 10 9) (1+ start)))))\n\n(defun equal-cut ()\n (declare (optimize (speed 3) (debug 0) (safety 0) (space 0)))\n (let ((n (read))\n (diff-min #.(expt 10 9)))\n (init-data n)\n (loop for second-split-point from 2 below (- n 2) do\n (multiple-value-call #'(lambda (b-sum c-sum d-sum e-sum)\n (let* ((sum-list (list b-sum c-sum d-sum e-sum))\n (diff (- (apply #'max sum-list)\n (apply #'min sum-list))))\n (when (< diff diff-min)\n (setq diff-min diff))))\n (get-split-sum 0 second-split-point)\n (get-split-sum second-split-point n)))\n (princ diff-min)))\n\n(equal-cut)", "language": "Lisp", "metadata": {"date": 1533565064, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03310.html", "problem_id": "p03310", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03310/input.txt", "sample_output_relpath": "derived/input_output/data/p03310/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03310/Lisp/s199165966.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s199165966", "user_id": "u913204306"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((data))\n (defun init-data (n)\n (setq data (make-array n :initial-contents (loop repeat n for an = (read) sum an into sum-a collect sum-a))))\n\n (defun get-sum (start end)\n (if (zerop start)\n (aref data (1- end))\n (- (aref data (1- end)) (aref data (1- start)))))\n\n (defun get-split-sum (start end)\n (labels ((get-split-sum (current-split-point diff-min split-point)\n (if (< current-split-point end)\n (let ((diff (abs (- (get-sum current-split-point end)\n (get-sum start current-split-point)))))\n (if (< diff diff-min)\n (get-split-sum (1+ current-split-point) diff current-split-point)\n (get-split-sum (1+ current-split-point) diff-min split-point)))\n (values (get-sum start split-point)\n (get-sum split-point end)))))\n (get-split-sum (1+ start) #.(expt 10 9) (1+ start)))))\n\n(defun equal-cut ()\n (declare (optimize (speed 3) (debug 0) (safety 0) (space 0)))\n (let ((n (read))\n (diff-min #.(expt 10 9)))\n (init-data n)\n (loop for second-split-point from 2 below (- n 2) do\n (multiple-value-call #'(lambda (b-sum c-sum d-sum e-sum)\n (let* ((sum-list (list b-sum c-sum d-sum e-sum))\n (diff (- (apply #'max sum-list)\n (apply #'min sum-list))))\n (when (< diff diff-min)\n (setq diff-min diff))))\n (get-split-sum 0 second-split-point)\n (get-split-sum second-split-point n)))\n (princ diff-min)))\n\n(equal-cut)", "problem_context": "Score : 600 points\n\nProblem Statement\n\nSnuke has an integer sequence A of length N.\n\nHe will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E.\nThe positions of the cuts can be freely chosen.\n\nLet P,Q,R,S be the sums of the elements in B,C,D,E, respectively.\nSnuke is happier when the absolute difference of the maximum and the minimum among P,Q,R,S is smaller.\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nConstraints\n\n4 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nSample Input 1\n\n5\n3 2 4 1 2\n\nSample Output 1\n\n2\n\nIf we divide A as B,C,D,E=(3),(2),(4),(1,2), then P=3,Q=2,R=4,S=1+2=3.\nHere, the maximum and the minimum among P,Q,R,S are 4 and 2, with the absolute difference of 2.\nWe cannot make the absolute difference of the maximum and the minimum less than 2, so the answer is 2.\n\nSample Input 2\n\n10\n10 71 84 33 6 47 23 25 52 64\n\nSample Output 2\n\n36\n\nSample Input 3\n\n7\n1 2 3 1000000000 4 5 6\n\nSample Output 3\n\n999999994", "sample_input": "5\n3 2 4 1 2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03310", "source_text": "Score : 600 points\n\nProblem Statement\n\nSnuke has an integer sequence A of length N.\n\nHe will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E.\nThe positions of the cuts can be freely chosen.\n\nLet P,Q,R,S be the sums of the elements in B,C,D,E, respectively.\nSnuke is happier when the absolute difference of the maximum and the minimum among P,Q,R,S is smaller.\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nConstraints\n\n4 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nSample Input 1\n\n5\n3 2 4 1 2\n\nSample Output 1\n\n2\n\nIf we divide A as B,C,D,E=(3),(2),(4),(1,2), then P=3,Q=2,R=4,S=1+2=3.\nHere, the maximum and the minimum among P,Q,R,S are 4 and 2, with the absolute difference of 2.\nWe cannot make the absolute difference of the maximum and the minimum less than 2, so the answer is 2.\n\nSample Input 2\n\n10\n10 71 84 33 6 47 23 25 52 64\n\nSample Output 2\n\n36\n\nSample Input 3\n\n7\n1 2 3 1000000000 4 5 6\n\nSample Output 3\n\n999999994", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1734, "cpu_time_ms": 2105, "memory_kb": 61800}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s840507351", "group_id": "codeNet:p03310", "input_text": "(let ((data))\n (defun init-data (n)\n (setq data (make-array n :initial-contents (loop repeat n for an = (read) sum an into sum-a collect sum-a))))\n\n (defun get-sum (start end)\n (if (zerop start)\n (aref data (1- end))\n (- (aref data (1- end)) (aref data (1- start))))))\n\n(defun equal-cut ()\n (let ((n (read))\n (min-diff #.(expt 10 9)))\n (init-data n)\n (loop for i from 1 below (- n 2) do\n (loop for j from (1+ i) below (- n 1) do\n (loop for k from (1+ j) below n do\n (let* ((sum-list (list (get-sum 0 i) (get-sum i j) (get-sum j k) (get-sum k n)))\n (diff (- (apply #'max sum-list) (apply #'min sum-list))))\n (when (< diff min-diff)\n (setq min-diff diff))))))\n (princ min-diff)))\n\n(equal-cut)", "language": "Lisp", "metadata": {"date": 1533516771, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03310.html", "problem_id": "p03310", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03310/input.txt", "sample_output_relpath": "derived/input_output/data/p03310/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03310/Lisp/s840507351.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s840507351", "user_id": "u913204306"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((data))\n (defun init-data (n)\n (setq data (make-array n :initial-contents (loop repeat n for an = (read) sum an into sum-a collect sum-a))))\n\n (defun get-sum (start end)\n (if (zerop start)\n (aref data (1- end))\n (- (aref data (1- end)) (aref data (1- start))))))\n\n(defun equal-cut ()\n (let ((n (read))\n (min-diff #.(expt 10 9)))\n (init-data n)\n (loop for i from 1 below (- n 2) do\n (loop for j from (1+ i) below (- n 1) do\n (loop for k from (1+ j) below n do\n (let* ((sum-list (list (get-sum 0 i) (get-sum i j) (get-sum j k) (get-sum k n)))\n (diff (- (apply #'max sum-list) (apply #'min sum-list))))\n (when (< diff min-diff)\n (setq min-diff diff))))))\n (princ min-diff)))\n\n(equal-cut)", "problem_context": "Score : 600 points\n\nProblem Statement\n\nSnuke has an integer sequence A of length N.\n\nHe will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E.\nThe positions of the cuts can be freely chosen.\n\nLet P,Q,R,S be the sums of the elements in B,C,D,E, respectively.\nSnuke is happier when the absolute difference of the maximum and the minimum among P,Q,R,S is smaller.\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nConstraints\n\n4 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nSample Input 1\n\n5\n3 2 4 1 2\n\nSample Output 1\n\n2\n\nIf we divide A as B,C,D,E=(3),(2),(4),(1,2), then P=3,Q=2,R=4,S=1+2=3.\nHere, the maximum and the minimum among P,Q,R,S are 4 and 2, with the absolute difference of 2.\nWe cannot make the absolute difference of the maximum and the minimum less than 2, so the answer is 2.\n\nSample Input 2\n\n10\n10 71 84 33 6 47 23 25 52 64\n\nSample Output 2\n\n36\n\nSample Input 3\n\n7\n1 2 3 1000000000 4 5 6\n\nSample Output 3\n\n999999994", "sample_input": "5\n3 2 4 1 2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03310", "source_text": "Score : 600 points\n\nProblem Statement\n\nSnuke has an integer sequence A of length N.\n\nHe will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E.\nThe positions of the cuts can be freely chosen.\n\nLet P,Q,R,S be the sums of the elements in B,C,D,E, respectively.\nSnuke is happier when the absolute difference of the maximum and the minimum among P,Q,R,S is smaller.\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nConstraints\n\n4 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nFind the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.\n\nSample Input 1\n\n5\n3 2 4 1 2\n\nSample Output 1\n\n2\n\nIf we divide A as B,C,D,E=(3),(2),(4),(1,2), then P=3,Q=2,R=4,S=1+2=3.\nHere, the maximum and the minimum among P,Q,R,S are 4 and 2, with the absolute difference of 2.\nWe cannot make the absolute difference of the maximum and the minimum less than 2, so the answer is 2.\n\nSample Input 2\n\n10\n10 71 84 33 6 47 23 25 52 64\n\nSample Output 2\n\n36\n\nSample Input 3\n\n7\n1 2 3 1000000000 4 5 6\n\nSample Output 3\n\n999999994", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 790, "cpu_time_ms": 2105, "memory_kb": 63880}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s947550711", "group_id": "codeNet:p03315", "input_text": "(princ (loop for predicate in (map 'list\n (lambda (predicate-char)\n (intern (string predicate-char)))\n (read-line))\n sum (eval `(,predicate 0 1))))", "language": "Lisp", "metadata": {"date": 1533910026, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03315.html", "problem_id": "p03315", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03315/input.txt", "sample_output_relpath": "derived/input_output/data/p03315/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03315/Lisp/s947550711.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s947550711", "user_id": "u913204306"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(princ (loop for predicate in (map 'list\n (lambda (predicate-char)\n (intern (string predicate-char)))\n (read-line))\n sum (eval `(,predicate 0 1))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere is always an integer in Takahashi's mind.\n\nInitially, the integer in Takahashi's mind is 0. Takahashi is now going to eat four symbols, each of which is + or -. When he eats +, the integer in his mind increases by 1; when he eats -, the integer in his mind decreases by 1.\n\nThe symbols Takahashi is going to eat are given to you as a string S. The i-th character in S is the i-th symbol for him to eat.\n\nFind the integer in Takahashi's mind after he eats all the symbols.\n\nConstraints\n\nThe length of S is 4.\n\nEach character in S is + or -.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the integer in Takahashi's mind after he eats all the symbols.\n\nSample Input 1\n\n+-++\n\nSample Output 1\n\n2\n\nInitially, the integer in Takahashi's mind is 0.\n\nThe first integer for him to eat is +. After eating it, the integer in his mind becomes 1.\n\nThe second integer to eat is -. After eating it, the integer in his mind becomes 0.\n\nThe third integer to eat is +. After eating it, the integer in his mind becomes 1.\n\nThe fourth integer to eat is +. After eating it, the integer in his mind becomes 2.\n\nThus, the integer in Takahashi's mind after he eats all the symbols is 2.\n\nSample Input 2\n\n-+--\n\nSample Output 2\n\n-2\n\nSample Input 3\n\n----\n\nSample Output 3\n\n-4", "sample_input": "+-++\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03315", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere is always an integer in Takahashi's mind.\n\nInitially, the integer in Takahashi's mind is 0. Takahashi is now going to eat four symbols, each of which is + or -. When he eats +, the integer in his mind increases by 1; when he eats -, the integer in his mind decreases by 1.\n\nThe symbols Takahashi is going to eat are given to you as a string S. The i-th character in S is the i-th symbol for him to eat.\n\nFind the integer in Takahashi's mind after he eats all the symbols.\n\nConstraints\n\nThe length of S is 4.\n\nEach character in S is + or -.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the integer in Takahashi's mind after he eats all the symbols.\n\nSample Input 1\n\n+-++\n\nSample Output 1\n\n2\n\nInitially, the integer in Takahashi's mind is 0.\n\nThe first integer for him to eat is +. After eating it, the integer in his mind becomes 1.\n\nThe second integer to eat is -. After eating it, the integer in his mind becomes 0.\n\nThe third integer to eat is +. After eating it, the integer in his mind becomes 1.\n\nThe fourth integer to eat is +. After eating it, the integer in his mind becomes 2.\n\nThus, the integer in Takahashi's mind after he eats all the symbols is 2.\n\nSample Input 2\n\n-+--\n\nSample Output 2\n\n-2\n\nSample Input 3\n\n----\n\nSample Output 3\n\n-4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 263, "cpu_time_ms": 35, "memory_kb": 5472}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s275958868", "group_id": "codeNet:p03315", "input_text": "(labels ((solver (predicates num)\n (if predicates\n (solver (cdr predicates) (if (char= #\\+ (car predicates))\n (1+ num)\n (1- num)))\n num)))\n (princ (solver (coerce (read-line) 'list) 0)))", "language": "Lisp", "metadata": {"date": 1533761106, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03315.html", "problem_id": "p03315", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03315/input.txt", "sample_output_relpath": "derived/input_output/data/p03315/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03315/Lisp/s275958868.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s275958868", "user_id": "u913204306"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(labels ((solver (predicates num)\n (if predicates\n (solver (cdr predicates) (if (char= #\\+ (car predicates))\n (1+ num)\n (1- num)))\n num)))\n (princ (solver (coerce (read-line) 'list) 0)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere is always an integer in Takahashi's mind.\n\nInitially, the integer in Takahashi's mind is 0. Takahashi is now going to eat four symbols, each of which is + or -. When he eats +, the integer in his mind increases by 1; when he eats -, the integer in his mind decreases by 1.\n\nThe symbols Takahashi is going to eat are given to you as a string S. The i-th character in S is the i-th symbol for him to eat.\n\nFind the integer in Takahashi's mind after he eats all the symbols.\n\nConstraints\n\nThe length of S is 4.\n\nEach character in S is + or -.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the integer in Takahashi's mind after he eats all the symbols.\n\nSample Input 1\n\n+-++\n\nSample Output 1\n\n2\n\nInitially, the integer in Takahashi's mind is 0.\n\nThe first integer for him to eat is +. After eating it, the integer in his mind becomes 1.\n\nThe second integer to eat is -. After eating it, the integer in his mind becomes 0.\n\nThe third integer to eat is +. After eating it, the integer in his mind becomes 1.\n\nThe fourth integer to eat is +. After eating it, the integer in his mind becomes 2.\n\nThus, the integer in Takahashi's mind after he eats all the symbols is 2.\n\nSample Input 2\n\n-+--\n\nSample Output 2\n\n-2\n\nSample Input 3\n\n----\n\nSample Output 3\n\n-4", "sample_input": "+-++\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03315", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere is always an integer in Takahashi's mind.\n\nInitially, the integer in Takahashi's mind is 0. Takahashi is now going to eat four symbols, each of which is + or -. When he eats +, the integer in his mind increases by 1; when he eats -, the integer in his mind decreases by 1.\n\nThe symbols Takahashi is going to eat are given to you as a string S. The i-th character in S is the i-th symbol for him to eat.\n\nFind the integer in Takahashi's mind after he eats all the symbols.\n\nConstraints\n\nThe length of S is 4.\n\nEach character in S is + or -.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the integer in Takahashi's mind after he eats all the symbols.\n\nSample Input 1\n\n+-++\n\nSample Output 1\n\n2\n\nInitially, the integer in Takahashi's mind is 0.\n\nThe first integer for him to eat is +. After eating it, the integer in his mind becomes 1.\n\nThe second integer to eat is -. After eating it, the integer in his mind becomes 0.\n\nThe third integer to eat is +. After eating it, the integer in his mind becomes 1.\n\nThe fourth integer to eat is +. After eating it, the integer in his mind becomes 2.\n\nThus, the integer in Takahashi's mind after he eats all the symbols is 2.\n\nSample Input 2\n\n-+--\n\nSample Output 2\n\n-2\n\nSample Input 3\n\n----\n\nSample Output 3\n\n-4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 311, "cpu_time_ms": 117, "memory_kb": 10848}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s363862201", "group_id": "codeNet:p03316", "input_text": "(defparameter n (read-line))\n(defparameter digit (read-from-string n))\n(defparameter total \n (reduce #'(lambda (m x) (+ x m)) \n (mapcar (lambda (x) (parse-integer (string x))) (coerce n 'list))))\n\n(if (= (mod digit total) 0) (princ \"Yes\") (princ \"No\"))", "language": "Lisp", "metadata": {"date": 1563312415, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03316.html", "problem_id": "p03316", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03316/input.txt", "sample_output_relpath": "derived/input_output/data/p03316/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03316/Lisp/s363862201.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s363862201", "user_id": "u480300350"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defparameter n (read-line))\n(defparameter digit (read-from-string n))\n(defparameter total \n (reduce #'(lambda (m x) (+ x m)) \n (mapcar (lambda (x) (parse-integer (string x))) (coerce n 'list))))\n\n(if (= (mod digit total) 0) (princ \"Yes\") (princ \"No\"))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nLet S(n) denote the sum of the digits in the decimal notation of n.\nFor example, S(101) = 1 + 0 + 1 = 2.\n\nGiven an integer N, determine if S(N) divides N.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf S(N) divides N, print Yes; if it does not, print No.\n\nSample Input 1\n\n12\n\nSample Output 1\n\nYes\n\nIn this input, N=12.\nAs S(12) = 1 + 2 = 3, S(N) divides N.\n\nSample Input 2\n\n101\n\nSample Output 2\n\nNo\n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\nYes", "sample_input": "12\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03316", "source_text": "Score : 200 points\n\nProblem Statement\n\nLet S(n) denote the sum of the digits in the decimal notation of n.\nFor example, S(101) = 1 + 0 + 1 = 2.\n\nGiven an integer N, determine if S(N) divides N.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf S(N) divides N, print Yes; if it does not, print No.\n\nSample Input 1\n\n12\n\nSample Output 1\n\nYes\n\nIn this input, N=12.\nAs S(12) = 1 + 2 = 3, S(N) divides N.\n\nSample Input 2\n\n101\n\nSample Output 2\n\nNo\n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 256, "cpu_time_ms": 86, "memory_kb": 9444}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s952626654", "group_id": "codeNet:p03316", "input_text": "(let ((n (read)))\n (princ\n (if (= 0\n (mod n\n (apply #'+\n (mapcar (lambda (x) (- (char-int x) 48))\n (coerce (write-to-string n) 'list)))))\n \"Yes\"\n \"No\")))", "language": "Lisp", "metadata": {"date": 1529805341, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03316.html", "problem_id": "p03316", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03316/input.txt", "sample_output_relpath": "derived/input_output/data/p03316/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03316/Lisp/s952626654.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s952626654", "user_id": "u956039157"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((n (read)))\n (princ\n (if (= 0\n (mod n\n (apply #'+\n (mapcar (lambda (x) (- (char-int x) 48))\n (coerce (write-to-string n) 'list)))))\n \"Yes\"\n \"No\")))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nLet S(n) denote the sum of the digits in the decimal notation of n.\nFor example, S(101) = 1 + 0 + 1 = 2.\n\nGiven an integer N, determine if S(N) divides N.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf S(N) divides N, print Yes; if it does not, print No.\n\nSample Input 1\n\n12\n\nSample Output 1\n\nYes\n\nIn this input, N=12.\nAs S(12) = 1 + 2 = 3, S(N) divides N.\n\nSample Input 2\n\n101\n\nSample Output 2\n\nNo\n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\nYes", "sample_input": "12\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03316", "source_text": "Score : 200 points\n\nProblem Statement\n\nLet S(n) denote the sum of the digits in the decimal notation of n.\nFor example, S(101) = 1 + 0 + 1 = 2.\n\nGiven an integer N, determine if S(N) divides N.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf S(N) divides N, print Yes; if it does not, print No.\n\nSample Input 1\n\n12\n\nSample Output 1\n\nYes\n\nIn this input, N=12.\nAs S(12) = 1 + 2 = 3, S(N) divides N.\n\nSample Input 2\n\n101\n\nSample Output 2\n\nNo\n\nAs S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.\n\nSample Input 3\n\n999999999\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 239, "cpu_time_ms": 88, "memory_kb": 9188}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s521958583", "group_id": "codeNet:p03317", "input_text": "(princ (ceiling (1- (read)) (1- (read))))", "language": "Lisp", "metadata": {"date": 1584911847, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03317.html", "problem_id": "p03317", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03317/input.txt", "sample_output_relpath": "derived/input_output/data/p03317/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03317/Lisp/s521958583.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s521958583", "user_id": "u334552723"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(princ (ceiling (1- (read)) (1- (read))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.\n\nOn this sequence, Snuke can perform the following operation:\n\nChoose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.\n\nSnuke would like to make all the elements in this sequence equal by repeating the operation above some number of times.\nFind the minimum number of operations required.\nIt can be proved that, Under the constraints of this problem, this objective is always achievable.\n\nConstraints\n\n2 \\leq K \\leq N \\leq 100000\n\nA_1, A_2, ..., A_N is a permutation of 1, 2, ..., N.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum number of operations required.\n\nSample Input 1\n\n4 3\n2 3 1 4\n\nSample Output 1\n\n2\n\nOne optimal strategy is as follows:\n\nIn the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\nIn the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\nSample Input 2\n\n3 3\n1 2 3\n\nSample Output 2\n\n1\n\nSample Input 3\n\n8 3\n7 3 1 8 4 6 2 5\n\nSample Output 3\n\n4", "sample_input": "4 3\n2 3 1 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03317", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.\n\nOn this sequence, Snuke can perform the following operation:\n\nChoose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.\n\nSnuke would like to make all the elements in this sequence equal by repeating the operation above some number of times.\nFind the minimum number of operations required.\nIt can be proved that, Under the constraints of this problem, this objective is always achievable.\n\nConstraints\n\n2 \\leq K \\leq N \\leq 100000\n\nA_1, A_2, ..., A_N is a permutation of 1, 2, ..., N.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum number of operations required.\n\nSample Input 1\n\n4 3\n2 3 1 4\n\nSample Output 1\n\n2\n\nOne optimal strategy is as follows:\n\nIn the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\nIn the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\nSample Input 2\n\n3 3\n1 2 3\n\nSample Output 2\n\n1\n\nSample Input 3\n\n8 3\n7 3 1 8 4 6 2 5\n\nSample Output 3\n\n4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 41, "cpu_time_ms": 22, "memory_kb": 3936}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s187767285", "group_id": "codeNet:p03317", "input_text": "(let* ((n (read))\n (k (read))\n (a (loop repeat n collect (read))))\n (princ (1+ (ceiling (/ (- n k) (1- k))))))", "language": "Lisp", "metadata": {"date": 1529807664, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03317.html", "problem_id": "p03317", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03317/input.txt", "sample_output_relpath": "derived/input_output/data/p03317/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03317/Lisp/s187767285.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s187767285", "user_id": "u956039157"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (read))\n (k (read))\n (a (loop repeat n collect (read))))\n (princ (1+ (ceiling (/ (- n k) (1- k))))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.\n\nOn this sequence, Snuke can perform the following operation:\n\nChoose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.\n\nSnuke would like to make all the elements in this sequence equal by repeating the operation above some number of times.\nFind the minimum number of operations required.\nIt can be proved that, Under the constraints of this problem, this objective is always achievable.\n\nConstraints\n\n2 \\leq K \\leq N \\leq 100000\n\nA_1, A_2, ..., A_N is a permutation of 1, 2, ..., N.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum number of operations required.\n\nSample Input 1\n\n4 3\n2 3 1 4\n\nSample Output 1\n\n2\n\nOne optimal strategy is as follows:\n\nIn the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\nIn the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\nSample Input 2\n\n3 3\n1 2 3\n\nSample Output 2\n\n1\n\nSample Input 3\n\n8 3\n7 3 1 8 4 6 2 5\n\nSample Output 3\n\n4", "sample_input": "4 3\n2 3 1 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03317", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.\n\nOn this sequence, Snuke can perform the following operation:\n\nChoose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.\n\nSnuke would like to make all the elements in this sequence equal by repeating the operation above some number of times.\nFind the minimum number of operations required.\nIt can be proved that, Under the constraints of this problem, this objective is always achievable.\n\nConstraints\n\n2 \\leq K \\leq N \\leq 100000\n\nA_1, A_2, ..., A_N is a permutation of 1, 2, ..., N.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum number of operations required.\n\nSample Input 1\n\n4 3\n2 3 1 4\n\nSample Output 1\n\n2\n\nOne optimal strategy is as follows:\n\nIn the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\nIn the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\nSample Input 2\n\n3 3\n1 2 3\n\nSample Output 2\n\n1\n\nSample Input 3\n\n8 3\n7 3 1 8 4 6 2 5\n\nSample Output 3\n\n4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 123, "cpu_time_ms": 302, "memory_kb": 61152}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s650279145", "group_id": "codeNet:p03317", "input_text": "(let* ((n (read))\n (k (read))\n (a (loop repeat n collect (read)))\n (pos-1 (position 1 a)))\n (princ\n (+ (ceiling (/ pos-1 (1- k)))\n (ceiling (/ (- n (1+ pos-1)) (1- k))))))", "language": "Lisp", "metadata": {"date": 1529806480, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03317.html", "problem_id": "p03317", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03317/input.txt", "sample_output_relpath": "derived/input_output/data/p03317/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03317/Lisp/s650279145.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s650279145", "user_id": "u956039157"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (read))\n (k (read))\n (a (loop repeat n collect (read)))\n (pos-1 (position 1 a)))\n (princ\n (+ (ceiling (/ pos-1 (1- k)))\n (ceiling (/ (- n (1+ pos-1)) (1- k))))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.\n\nOn this sequence, Snuke can perform the following operation:\n\nChoose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.\n\nSnuke would like to make all the elements in this sequence equal by repeating the operation above some number of times.\nFind the minimum number of operations required.\nIt can be proved that, Under the constraints of this problem, this objective is always achievable.\n\nConstraints\n\n2 \\leq K \\leq N \\leq 100000\n\nA_1, A_2, ..., A_N is a permutation of 1, 2, ..., N.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum number of operations required.\n\nSample Input 1\n\n4 3\n2 3 1 4\n\nSample Output 1\n\n2\n\nOne optimal strategy is as follows:\n\nIn the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\nIn the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\nSample Input 2\n\n3 3\n1 2 3\n\nSample Output 2\n\n1\n\nSample Input 3\n\n8 3\n7 3 1 8 4 6 2 5\n\nSample Output 3\n\n4", "sample_input": "4 3\n2 3 1 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03317", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.\n\nOn this sequence, Snuke can perform the following operation:\n\nChoose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.\n\nSnuke would like to make all the elements in this sequence equal by repeating the operation above some number of times.\nFind the minimum number of operations required.\nIt can be proved that, Under the constraints of this problem, this objective is always achievable.\n\nConstraints\n\n2 \\leq K \\leq N \\leq 100000\n\nA_1, A_2, ..., A_N is a permutation of 1, 2, ..., N.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum number of operations required.\n\nSample Input 1\n\n4 3\n2 3 1 4\n\nSample Output 1\n\n2\n\nOne optimal strategy is as follows:\n\nIn the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\nIn the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\nSample Input 2\n\n3 3\n1 2 3\n\nSample Output 2\n\n1\n\nSample Input 3\n\n8 3\n7 3 1 8 4 6 2 5\n\nSample Output 3\n\n4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 199, "cpu_time_ms": 203, "memory_kb": 60768}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s120393459", "group_id": "codeNet:p03319", "input_text": "(let ((n (read))\n (k (read)))\n (format t \"~A~%\" (+ (floor (/ (- n 2) (- k 1))) 1)))", "language": "Lisp", "metadata": {"date": 1601054019, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03319.html", "problem_id": "p03319", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03319/input.txt", "sample_output_relpath": "derived/input_output/data/p03319/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03319/Lisp/s120393459.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s120393459", "user_id": "u136500538"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((n (read))\n (k (read)))\n (format t \"~A~%\" (+ (floor (/ (- n 2) (- k 1))) 1)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.\n\nOn this sequence, Snuke can perform the following operation:\n\nChoose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.\n\nSnuke would like to make all the elements in this sequence equal by repeating the operation above some number of times.\nFind the minimum number of operations required.\nIt can be proved that, Under the constraints of this problem, this objective is always achievable.\n\nConstraints\n\n2 \\leq K \\leq N \\leq 100000\n\nA_1, A_2, ..., A_N is a permutation of 1, 2, ..., N.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum number of operations required.\n\nSample Input 1\n\n4 3\n2 3 1 4\n\nSample Output 1\n\n2\n\nOne optimal strategy is as follows:\n\nIn the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\nIn the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\nSample Input 2\n\n3 3\n1 2 3\n\nSample Output 2\n\n1\n\nSample Input 3\n\n8 3\n7 3 1 8 4 6 2 5\n\nSample Output 3\n\n4", "sample_input": "4 3\n2 3 1 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03319", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.\n\nOn this sequence, Snuke can perform the following operation:\n\nChoose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.\n\nSnuke would like to make all the elements in this sequence equal by repeating the operation above some number of times.\nFind the minimum number of operations required.\nIt can be proved that, Under the constraints of this problem, this objective is always achievable.\n\nConstraints\n\n2 \\leq K \\leq N \\leq 100000\n\nA_1, A_2, ..., A_N is a permutation of 1, 2, ..., N.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum number of operations required.\n\nSample Input 1\n\n4 3\n2 3 1 4\n\nSample Output 1\n\n2\n\nOne optimal strategy is as follows:\n\nIn the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\nIn the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\nSample Input 2\n\n3 3\n1 2 3\n\nSample Output 2\n\n1\n\nSample Input 3\n\n8 3\n7 3 1 8 4 6 2 5\n\nSample Output 3\n\n4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 89, "cpu_time_ms": 18, "memory_kb": 24024}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s503239798", "group_id": "codeNet:p03320", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline integer-length*))\n(defun integer-length* (x &optional (radix 10))\n \"Returns the length of the integer X when displayed in RADIX. (Returns 0 when\nX = 0. Ignores the negative sign.)\"\n (declare (integer x)\n ((integer 2 #.most-positive-fixnum) radix))\n (loop for length of-type (integer 0 #.most-positive-fixnum) from 0\n for y = (abs x) then (floor y radix)\n until (zerop y)\n finally (return length)))\n\n(declaim (inline digit-sum))\n(defun digit-sum (x &optional (radix 10))\n \"Returns the sum of the each digit of X w.r.t. RADIX. (Returns 0 when X =\n0. Ignores the negative sign.)\"\n (declare (integer x)\n ((integer 2 #.most-positive-fixnum) radix))\n (let ((sum 0)\n (x (abs x)))\n (declare (unsigned-byte x)\n ((integer 0 #.most-positive-fixnum) sum))\n (loop\n (when (zerop x)\n (return sum))\n (multiple-value-bind (quot rem) (floor x radix)\n (incf sum rem)\n (setq x quot)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun frob (function x mask-width)\n (declare (uint62 x)\n (uint8 mask-width)\n (function function))\n (let* ((tens (expt 10 mask-width))\n (nines (- tens 1))\n (upper-base (floor x tens))\n (upper-limit (* 100 (ceiling (+ 1 upper-base) 100))))\n (declare (uint62 tens nines upper-base upper-limit))\n (loop for upper from upper-base below upper-limit\n do (funcall function (+ (* upper tens) nines)))))\n\n(defun calc-next-snuke (n)\n (let ((width (integer-length* n))\n (min-val most-positive-fixnum)\n (res 0))\n (declare (rational min-val)\n (uint62 res))\n (loop for mask-width from 0 below width\n do (frob (lambda (x)\n (declare (uint62 x))\n (let ((val (/ x (digit-sum x))))\n ;; (dbg x val)\n (when (or (< val min-val)\n (and (= val min-val)\n (< x res)))\n (setq res x\n min-val val))))\n n\n mask-width))\n (assert (not (zerop res)))\n res))\n\n(defun main ()\n (let* ((k (read))\n (val 1))\n (dotimes (_ k)\n (println val)\n (setq val (calc-next-snuke (+ val 1))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n\"\n \"1\n2\n3\n4\n5\n6\n7\n8\n9\n19\n\")))\n", "language": "Lisp", "metadata": {"date": 1574910942, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03320.html", "problem_id": "p03320", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03320/input.txt", "sample_output_relpath": "derived/input_output/data/p03320/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03320/Lisp/s503239798.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s503239798", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n2\n3\n4\n5\n6\n7\n8\n9\n19\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline integer-length*))\n(defun integer-length* (x &optional (radix 10))\n \"Returns the length of the integer X when displayed in RADIX. (Returns 0 when\nX = 0. Ignores the negative sign.)\"\n (declare (integer x)\n ((integer 2 #.most-positive-fixnum) radix))\n (loop for length of-type (integer 0 #.most-positive-fixnum) from 0\n for y = (abs x) then (floor y radix)\n until (zerop y)\n finally (return length)))\n\n(declaim (inline digit-sum))\n(defun digit-sum (x &optional (radix 10))\n \"Returns the sum of the each digit of X w.r.t. RADIX. (Returns 0 when X =\n0. Ignores the negative sign.)\"\n (declare (integer x)\n ((integer 2 #.most-positive-fixnum) radix))\n (let ((sum 0)\n (x (abs x)))\n (declare (unsigned-byte x)\n ((integer 0 #.most-positive-fixnum) sum))\n (loop\n (when (zerop x)\n (return sum))\n (multiple-value-bind (quot rem) (floor x radix)\n (incf sum rem)\n (setq x quot)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun frob (function x mask-width)\n (declare (uint62 x)\n (uint8 mask-width)\n (function function))\n (let* ((tens (expt 10 mask-width))\n (nines (- tens 1))\n (upper-base (floor x tens))\n (upper-limit (* 100 (ceiling (+ 1 upper-base) 100))))\n (declare (uint62 tens nines upper-base upper-limit))\n (loop for upper from upper-base below upper-limit\n do (funcall function (+ (* upper tens) nines)))))\n\n(defun calc-next-snuke (n)\n (let ((width (integer-length* n))\n (min-val most-positive-fixnum)\n (res 0))\n (declare (rational min-val)\n (uint62 res))\n (loop for mask-width from 0 below width\n do (frob (lambda (x)\n (declare (uint62 x))\n (let ((val (/ x (digit-sum x))))\n ;; (dbg x val)\n (when (or (< val min-val)\n (and (= val min-val)\n (< x res)))\n (setq res x\n min-val val))))\n n\n mask-width))\n (assert (not (zerop res)))\n res))\n\n(defun main ()\n (let* ((k (read))\n (val 1))\n (dotimes (_ k)\n (println val)\n (setq val (calc-next-snuke (+ val 1))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n\"\n \"1\n2\n3\n4\n5\n6\n7\n8\n9\n19\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nLet S(n) denote the sum of the digits in the decimal notation of n.\nFor example, S(123) = 1 + 2 + 3 = 6.\n\nWe will call an integer n a Snuke number when, for all positive integers m such that m > n, \\frac{n}{S(n)} \\leq \\frac{m}{S(m)} holds.\n\nGiven an integer K, list the K smallest Snuke numbers.\n\nConstraints\n\n1 \\leq K\n\nThe K-th smallest Snuke number is not greater than 10^{15}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint K lines. The i-th line should contain the i-th smallest Snuke number.\n\nSample Input 1\n\n10\n\nSample Output 1\n\n1\n2\n3\n4\n5\n6\n7\n8\n9\n19", "sample_input": "10\n"}, "reference_outputs": ["1\n2\n3\n4\n5\n6\n7\n8\n9\n19\n"], "source_document_id": "p03320", "source_text": "Score : 500 points\n\nProblem Statement\n\nLet S(n) denote the sum of the digits in the decimal notation of n.\nFor example, S(123) = 1 + 2 + 3 = 6.\n\nWe will call an integer n a Snuke number when, for all positive integers m such that m > n, \\frac{n}{S(n)} \\leq \\frac{m}{S(m)} holds.\n\nGiven an integer K, list the K smallest Snuke numbers.\n\nConstraints\n\n1 \\leq K\n\nThe K-th smallest Snuke number is not greater than 10^{15}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint K lines. The i-th line should contain the i-th smallest Snuke number.\n\nSample Input 1\n\n10\n\nSample Output 1\n\n1\n2\n3\n4\n5\n6\n7\n8\n9\n19", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5780, "cpu_time_ms": 805, "memory_kb": 50016}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s121726212", "group_id": "codeNet:p03323", "input_text": "(let ((a (read))\n (b (read)))\n (if (and (< a 9)\n (< b 9))\n (princ \"Yay!\")\n (princ \":(\")))", "language": "Lisp", "metadata": {"date": 1529197851, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03323.html", "problem_id": "p03323", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03323/input.txt", "sample_output_relpath": "derived/input_output/data/p03323/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03323/Lisp/s121726212.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s121726212", "user_id": "u956039157"}, "prompt_components": {"gold_output": "Yay!\n", "input_to_evaluate": "(let ((a (read))\n (b (read)))\n (if (and (< a 9)\n (< b 9))\n (princ \"Yay!\")\n (princ \":(\")))", "problem_context": "Score: 100 points\n\nProblem Statement\n\nE869120's and square1001's 16-th birthday is coming soon.\n\nTakahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-shaped pieces.\n\nE869120 and square1001 were just about to eat A and B of those pieces, respectively,\n\nwhen they found a note attached to the cake saying that \"the same person should not take two adjacent pieces of cake\".\n\nCan both of them obey the instruction in the note and take desired numbers of pieces of cake?\n\nConstraints\n\nA and B are integers between 1 and 16 (inclusive).\n\nA+B is at most 16.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nIf both E869120 and square1001 can obey the instruction in the note and take desired numbers of pieces of cake, print Yay!; otherwise, print :(.\n\nSample Input 1\n\n5 4\n\nSample Output 1\n\nYay!\n\nBoth of them can take desired number of pieces as follows:\n\nSample Input 2\n\n8 8\n\nSample Output 2\n\nYay!\n\nBoth of them can take desired number of pieces as follows:\n\nSample Input 3\n\n11 4\n\nSample Output 3\n\n:(\n\nIn this case, there is no way for them to take desired number of pieces, unfortunately.", "sample_input": "5 4\n"}, "reference_outputs": ["Yay!\n"], "source_document_id": "p03323", "source_text": "Score: 100 points\n\nProblem Statement\n\nE869120's and square1001's 16-th birthday is coming soon.\n\nTakahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-shaped pieces.\n\nE869120 and square1001 were just about to eat A and B of those pieces, respectively,\n\nwhen they found a note attached to the cake saying that \"the same person should not take two adjacent pieces of cake\".\n\nCan both of them obey the instruction in the note and take desired numbers of pieces of cake?\n\nConstraints\n\nA and B are integers between 1 and 16 (inclusive).\n\nA+B is at most 16.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nIf both E869120 and square1001 can obey the instruction in the note and take desired numbers of pieces of cake, print Yay!; otherwise, print :(.\n\nSample Input 1\n\n5 4\n\nSample Output 1\n\nYay!\n\nBoth of them can take desired number of pieces as follows:\n\nSample Input 2\n\n8 8\n\nSample Output 2\n\nYay!\n\nBoth of them can take desired number of pieces as follows:\n\nSample Input 3\n\n11 4\n\nSample Output 3\n\n:(\n\nIn this case, there is no way for them to take desired number of pieces, unfortunately.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 115, "cpu_time_ms": 397, "memory_kb": 8928}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s117202460", "group_id": "codeNet:p03327", "input_text": "(defun app ()\n (if (< (read) 1000)\n (format t \"ABC~%\")\n (format t \"ABD~%\")\n )\n)\n(app)", "language": "Lisp", "metadata": {"date": 1592613692, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03327.html", "problem_id": "p03327", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03327/input.txt", "sample_output_relpath": "derived/input_output/data/p03327/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03327/Lisp/s117202460.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s117202460", "user_id": "u136500538"}, "prompt_components": {"gold_output": "ABC\n", "input_to_evaluate": "(defun app ()\n (if (< (read) 1000)\n (format t \"ABC~%\")\n (format t \"ABD~%\")\n )\n)\n(app)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nDecades have passed since the beginning of AtCoder Beginner Contest.\n\nThe contests are labeled as ABC001, ABC002, ... from the first round, but after the 999-th round ABC999, a problem occurred: how the future rounds should be labeled?\n\nIn the end, the labels for the rounds from the 1000-th to the 1998-th are decided: ABD001, ABD002, ..., ABD999.\n\nYou are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.\n\nConstraints\n\n1 \\leq N \\leq 1998\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the first three characters of the label of the N-th round of AtCoder Beginner Contest.\n\nSample Input 1\n\n999\n\nSample Output 1\n\nABC\n\nThe 999-th round of AtCoder Beginner Contest is labeled as ABC999.\n\nSample Input 2\n\n1000\n\nSample Output 2\n\nABD\n\nThe 1000-th round of AtCoder Beginner Contest is labeled as ABD001.\n\nSample Input 3\n\n1481\n\nSample Output 3\n\nABD\n\nThe 1481-th round of AtCoder Beginner Contest is labeled as ABD482.", "sample_input": "999\n"}, "reference_outputs": ["ABC\n"], "source_document_id": "p03327", "source_text": "Score : 100 points\n\nProblem Statement\n\nDecades have passed since the beginning of AtCoder Beginner Contest.\n\nThe contests are labeled as ABC001, ABC002, ... from the first round, but after the 999-th round ABC999, a problem occurred: how the future rounds should be labeled?\n\nIn the end, the labels for the rounds from the 1000-th to the 1998-th are decided: ABD001, ABD002, ..., ABD999.\n\nYou are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.\n\nConstraints\n\n1 \\leq N \\leq 1998\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the first three characters of the label of the N-th round of AtCoder Beginner Contest.\n\nSample Input 1\n\n999\n\nSample Output 1\n\nABC\n\nThe 999-th round of AtCoder Beginner Contest is labeled as ABC999.\n\nSample Input 2\n\n1000\n\nSample Output 2\n\nABD\n\nThe 1000-th round of AtCoder Beginner Contest is labeled as ABD001.\n\nSample Input 3\n\n1481\n\nSample Output 3\n\nABD\n\nThe 1481-th round of AtCoder Beginner Contest is labeled as ABD482.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 105, "cpu_time_ms": 13, "memory_kb": 23512}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s237840785", "group_id": "codeNet:p03327", "input_text": "(let ((n (read)))\n (if (< n 1000)\n (format t \"ABC~%\")\n (format t \"ABD~%\")))\n ", "language": "Lisp", "metadata": {"date": 1585971562, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03327.html", "problem_id": "p03327", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03327/input.txt", "sample_output_relpath": "derived/input_output/data/p03327/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03327/Lisp/s237840785.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s237840785", "user_id": "u606976120"}, "prompt_components": {"gold_output": "ABC\n", "input_to_evaluate": "(let ((n (read)))\n (if (< n 1000)\n (format t \"ABC~%\")\n (format t \"ABD~%\")))\n ", "problem_context": "Score : 100 points\n\nProblem Statement\n\nDecades have passed since the beginning of AtCoder Beginner Contest.\n\nThe contests are labeled as ABC001, ABC002, ... from the first round, but after the 999-th round ABC999, a problem occurred: how the future rounds should be labeled?\n\nIn the end, the labels for the rounds from the 1000-th to the 1998-th are decided: ABD001, ABD002, ..., ABD999.\n\nYou are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.\n\nConstraints\n\n1 \\leq N \\leq 1998\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the first three characters of the label of the N-th round of AtCoder Beginner Contest.\n\nSample Input 1\n\n999\n\nSample Output 1\n\nABC\n\nThe 999-th round of AtCoder Beginner Contest is labeled as ABC999.\n\nSample Input 2\n\n1000\n\nSample Output 2\n\nABD\n\nThe 1000-th round of AtCoder Beginner Contest is labeled as ABD001.\n\nSample Input 3\n\n1481\n\nSample Output 3\n\nABD\n\nThe 1481-th round of AtCoder Beginner Contest is labeled as ABD482.", "sample_input": "999\n"}, "reference_outputs": ["ABC\n"], "source_document_id": "p03327", "source_text": "Score : 100 points\n\nProblem Statement\n\nDecades have passed since the beginning of AtCoder Beginner Contest.\n\nThe contests are labeled as ABC001, ABC002, ... from the first round, but after the 999-th round ABC999, a problem occurred: how the future rounds should be labeled?\n\nIn the end, the labels for the rounds from the 1000-th to the 1998-th are decided: ABD001, ABD002, ..., ABD999.\n\nYou are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.\n\nConstraints\n\n1 \\leq N \\leq 1998\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the first three characters of the label of the N-th round of AtCoder Beginner Contest.\n\nSample Input 1\n\n999\n\nSample Output 1\n\nABC\n\nThe 999-th round of AtCoder Beginner Contest is labeled as ABC999.\n\nSample Input 2\n\n1000\n\nSample Output 2\n\nABD\n\nThe 1000-th round of AtCoder Beginner Contest is labeled as ABD001.\n\nSample Input 3\n\n1481\n\nSample Output 3\n\nABD\n\nThe 1481-th round of AtCoder Beginner Contest is labeled as ABD482.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 93, "cpu_time_ms": 14, "memory_kb": 3808}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s768879926", "group_id": "codeNet:p03327", "input_text": "(princ (if (< (read) 1000) \"ABC\" \"ABD\"))", "language": "Lisp", "metadata": {"date": 1533765707, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03327.html", "problem_id": "p03327", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03327/input.txt", "sample_output_relpath": "derived/input_output/data/p03327/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03327/Lisp/s768879926.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s768879926", "user_id": "u913204306"}, "prompt_components": {"gold_output": "ABC\n", "input_to_evaluate": "(princ (if (< (read) 1000) \"ABC\" \"ABD\"))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nDecades have passed since the beginning of AtCoder Beginner Contest.\n\nThe contests are labeled as ABC001, ABC002, ... from the first round, but after the 999-th round ABC999, a problem occurred: how the future rounds should be labeled?\n\nIn the end, the labels for the rounds from the 1000-th to the 1998-th are decided: ABD001, ABD002, ..., ABD999.\n\nYou are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.\n\nConstraints\n\n1 \\leq N \\leq 1998\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the first three characters of the label of the N-th round of AtCoder Beginner Contest.\n\nSample Input 1\n\n999\n\nSample Output 1\n\nABC\n\nThe 999-th round of AtCoder Beginner Contest is labeled as ABC999.\n\nSample Input 2\n\n1000\n\nSample Output 2\n\nABD\n\nThe 1000-th round of AtCoder Beginner Contest is labeled as ABD001.\n\nSample Input 3\n\n1481\n\nSample Output 3\n\nABD\n\nThe 1481-th round of AtCoder Beginner Contest is labeled as ABD482.", "sample_input": "999\n"}, "reference_outputs": ["ABC\n"], "source_document_id": "p03327", "source_text": "Score : 100 points\n\nProblem Statement\n\nDecades have passed since the beginning of AtCoder Beginner Contest.\n\nThe contests are labeled as ABC001, ABC002, ... from the first round, but after the 999-th round ABC999, a problem occurred: how the future rounds should be labeled?\n\nIn the end, the labels for the rounds from the 1000-th to the 1998-th are decided: ABD001, ABD002, ..., ABD999.\n\nYou are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.\n\nConstraints\n\n1 \\leq N \\leq 1998\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the first three characters of the label of the N-th round of AtCoder Beginner Contest.\n\nSample Input 1\n\n999\n\nSample Output 1\n\nABC\n\nThe 999-th round of AtCoder Beginner Contest is labeled as ABC999.\n\nSample Input 2\n\n1000\n\nSample Output 2\n\nABD\n\nThe 1000-th round of AtCoder Beginner Contest is labeled as ABD001.\n\nSample Input 3\n\n1481\n\nSample Output 3\n\nABD\n\nThe 1481-th round of AtCoder Beginner Contest is labeled as ABD482.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 40, "cpu_time_ms": 5, "memory_kb": 2788}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s718110896", "group_id": "codeNet:p03327", "input_text": "(princ(if(>(read)999)\"ABD\"\"ABC\"))", "language": "Lisp", "metadata": {"date": 1528680824, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03327.html", "problem_id": "p03327", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03327/input.txt", "sample_output_relpath": "derived/input_output/data/p03327/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03327/Lisp/s718110896.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s718110896", "user_id": "u657913472"}, "prompt_components": {"gold_output": "ABC\n", "input_to_evaluate": "(princ(if(>(read)999)\"ABD\"\"ABC\"))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nDecades have passed since the beginning of AtCoder Beginner Contest.\n\nThe contests are labeled as ABC001, ABC002, ... from the first round, but after the 999-th round ABC999, a problem occurred: how the future rounds should be labeled?\n\nIn the end, the labels for the rounds from the 1000-th to the 1998-th are decided: ABD001, ABD002, ..., ABD999.\n\nYou are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.\n\nConstraints\n\n1 \\leq N \\leq 1998\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the first three characters of the label of the N-th round of AtCoder Beginner Contest.\n\nSample Input 1\n\n999\n\nSample Output 1\n\nABC\n\nThe 999-th round of AtCoder Beginner Contest is labeled as ABC999.\n\nSample Input 2\n\n1000\n\nSample Output 2\n\nABD\n\nThe 1000-th round of AtCoder Beginner Contest is labeled as ABD001.\n\nSample Input 3\n\n1481\n\nSample Output 3\n\nABD\n\nThe 1481-th round of AtCoder Beginner Contest is labeled as ABD482.", "sample_input": "999\n"}, "reference_outputs": ["ABC\n"], "source_document_id": "p03327", "source_text": "Score : 100 points\n\nProblem Statement\n\nDecades have passed since the beginning of AtCoder Beginner Contest.\n\nThe contests are labeled as ABC001, ABC002, ... from the first round, but after the 999-th round ABC999, a problem occurred: how the future rounds should be labeled?\n\nIn the end, the labels for the rounds from the 1000-th to the 1998-th are decided: ABD001, ABD002, ..., ABD999.\n\nYou are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.\n\nConstraints\n\n1 \\leq N \\leq 1998\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the first three characters of the label of the N-th round of AtCoder Beginner Contest.\n\nSample Input 1\n\n999\n\nSample Output 1\n\nABC\n\nThe 999-th round of AtCoder Beginner Contest is labeled as ABC999.\n\nSample Input 2\n\n1000\n\nSample Output 2\n\nABD\n\nThe 1000-th round of AtCoder Beginner Contest is labeled as ABD001.\n\nSample Input 3\n\n1481\n\nSample Output 3\n\nABD\n\nThe 1481-th round of AtCoder Beginner Contest is labeled as ABD482.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 33, "cpu_time_ms": 14, "memory_kb": 3808}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s088547134", "group_id": "codeNet:p03329", "input_text": "#|\n------------------------------------\n| Utils |\n------------------------------------\n|#\n\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n(defconstant +mod+ 1000000007)\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n\n(defmacro read-numbers-to-list (size)\n `(loop repeat ,size collect (read)))\n\n\n(defmacro read-numbers-to-array (size)\n (let ((i (gensym))\n (arr (gensym)))\n `(let ((,arr (make-array ,size\n :element-type 'fixnum)))\n (declare ((array fixnum 1) ,arr))\n (loop for ,i of-type fixnum below ,size do\n (setf (aref ,arr ,i) (read))\n finally\n (return ,arr)))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(defun unwrap (list)\n (format nil \"~{~a~^ ~}\" list))\n\n\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n\n\n\n\n#|\n------------------------------------\n| Body |\n------------------------------------\n|#\n\n(defparameter *inf* 100000000)\n\n\n\n(defun solve (n)\n (let ((memo (make-array (* n 2)\n :initial-element *inf*)))\n (setf (aref memo 0) 0)\n (loop for i from 0 to n do\n (loop with k = 1 while (<= (expt 9 k) n) do\n (setf (aref memo (+ (expt 9 k) i))\n (min (1+ (aref memo i))\n (aref memo (+ (expt 9 k) i))))\n (incf k))\n (loop with k = 1 while (<= (expt 6 k) n) do\n (setf (aref memo (+ (expt 6 k) i))\n (min (1+ (aref memo i))\n (aref memo (+ (expt 6 k) i))))\n (incf k))\n (setf (aref memo (1+ i))\n (min (1+ (aref memo i))\n (aref memo (1+ i))))\n finally\n (return (aref memo n)))))\n\n\n(defun main ()\n (declare #.OPT)\n (let ((n (read)))\n (format t \"~a~&\" (solve n))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1600091793, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03329.html", "problem_id": "p03329", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03329/input.txt", "sample_output_relpath": "derived/input_output/data/p03329/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03329/Lisp/s088547134.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s088547134", "user_id": "u425762225"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "#|\n------------------------------------\n| Utils |\n------------------------------------\n|#\n\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n(defconstant +mod+ 1000000007)\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n\n(defmacro read-numbers-to-list (size)\n `(loop repeat ,size collect (read)))\n\n\n(defmacro read-numbers-to-array (size)\n (let ((i (gensym))\n (arr (gensym)))\n `(let ((,arr (make-array ,size\n :element-type 'fixnum)))\n (declare ((array fixnum 1) ,arr))\n (loop for ,i of-type fixnum below ,size do\n (setf (aref ,arr ,i) (read))\n finally\n (return ,arr)))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(defun unwrap (list)\n (format nil \"~{~a~^ ~}\" list))\n\n\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n\n\n\n\n#|\n------------------------------------\n| Body |\n------------------------------------\n|#\n\n(defparameter *inf* 100000000)\n\n\n\n(defun solve (n)\n (let ((memo (make-array (* n 2)\n :initial-element *inf*)))\n (setf (aref memo 0) 0)\n (loop for i from 0 to n do\n (loop with k = 1 while (<= (expt 9 k) n) do\n (setf (aref memo (+ (expt 9 k) i))\n (min (1+ (aref memo i))\n (aref memo (+ (expt 9 k) i))))\n (incf k))\n (loop with k = 1 while (<= (expt 6 k) n) do\n (setf (aref memo (+ (expt 6 k) i))\n (min (1+ (aref memo i))\n (aref memo (+ (expt 6 k) i))))\n (incf k))\n (setf (aref memo (1+ i))\n (min (1+ (aref memo i))\n (aref memo (1+ i))))\n finally\n (return (aref memo n)))))\n\n\n(defun main ()\n (declare #.OPT)\n (let ((n (read)))\n (format t \"~a~&\" (solve n))))\n\n#-swank (main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTo make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:\n\n1 yen (the currency of Japan)\n\n6 yen, 6^2(=36) yen, 6^3(=216) yen, ...\n\n9 yen, 9^2(=81) yen, 9^3(=729) yen, ...\n\nAt least how many operations are required to withdraw exactly N yen in total?\n\nIt is not allowed to re-deposit the money you withdrew.\n\nConstraints\n\n1 \\leq N \\leq 100000\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf at least x operations are required to withdraw exactly N yen in total, print x.\n\nSample Input 1\n\n127\n\nSample Output 1\n\n4\n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw 127 yen in four operations.\n\nSample Input 2\n\n3\n\nSample Output 2\n\n3\n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\nSample Input 3\n\n44852\n\nSample Output 3\n\n16", "sample_input": "127\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03329", "source_text": "Score : 300 points\n\nProblem Statement\n\nTo make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:\n\n1 yen (the currency of Japan)\n\n6 yen, 6^2(=36) yen, 6^3(=216) yen, ...\n\n9 yen, 9^2(=81) yen, 9^3(=729) yen, ...\n\nAt least how many operations are required to withdraw exactly N yen in total?\n\nIt is not allowed to re-deposit the money you withdrew.\n\nConstraints\n\n1 \\leq N \\leq 100000\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf at least x operations are required to withdraw exactly N yen in total, print x.\n\nSample Input 1\n\n127\n\nSample Output 1\n\n4\n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw 127 yen in four operations.\n\nSample Input 2\n\n3\n\nSample Output 2\n\n3\n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\nSample Input 3\n\n44852\n\nSample Output 3\n\n16", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4081, "cpu_time_ms": 141, "memory_kb": 28848}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s110388713", "group_id": "codeNet:p03329", "input_text": "(defun app ()\n (let* ((n (read))\n (ans n))\n (dotimes (i n)\n (let ((a 0)\n (b i))\n (loop while (> b 0) do\n (progn\n (setq a (+ a (rem b 6)))\n (setq b (floor (/ b 6))))\n )\n (setq b (- n i))\n (loop while (> b 0) do\n (progn\n (setq a (+ a (rem b 9)))\n (setq b (floor (/ b 9))))\n )\n (if (> ans a)\n (setq ans a))\n )\n )\n (format t \"~D~%\" ans)) \n)\n(app)", "language": "Lisp", "metadata": {"date": 1592619789, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03329.html", "problem_id": "p03329", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03329/input.txt", "sample_output_relpath": "derived/input_output/data/p03329/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03329/Lisp/s110388713.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s110388713", "user_id": "u136500538"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun app ()\n (let* ((n (read))\n (ans n))\n (dotimes (i n)\n (let ((a 0)\n (b i))\n (loop while (> b 0) do\n (progn\n (setq a (+ a (rem b 6)))\n (setq b (floor (/ b 6))))\n )\n (setq b (- n i))\n (loop while (> b 0) do\n (progn\n (setq a (+ a (rem b 9)))\n (setq b (floor (/ b 9))))\n )\n (if (> ans a)\n (setq ans a))\n )\n )\n (format t \"~D~%\" ans)) \n)\n(app)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTo make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:\n\n1 yen (the currency of Japan)\n\n6 yen, 6^2(=36) yen, 6^3(=216) yen, ...\n\n9 yen, 9^2(=81) yen, 9^3(=729) yen, ...\n\nAt least how many operations are required to withdraw exactly N yen in total?\n\nIt is not allowed to re-deposit the money you withdrew.\n\nConstraints\n\n1 \\leq N \\leq 100000\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf at least x operations are required to withdraw exactly N yen in total, print x.\n\nSample Input 1\n\n127\n\nSample Output 1\n\n4\n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw 127 yen in four operations.\n\nSample Input 2\n\n3\n\nSample Output 2\n\n3\n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\nSample Input 3\n\n44852\n\nSample Output 3\n\n16", "sample_input": "127\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03329", "source_text": "Score : 300 points\n\nProblem Statement\n\nTo make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:\n\n1 yen (the currency of Japan)\n\n6 yen, 6^2(=36) yen, 6^3(=216) yen, ...\n\n9 yen, 9^2(=81) yen, 9^3(=729) yen, ...\n\nAt least how many operations are required to withdraw exactly N yen in total?\n\nIt is not allowed to re-deposit the money you withdrew.\n\nConstraints\n\n1 \\leq N \\leq 100000\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf at least x operations are required to withdraw exactly N yen in total, print x.\n\nSample Input 1\n\n127\n\nSample Output 1\n\n4\n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw 127 yen in four operations.\n\nSample Input 2\n\n3\n\nSample Output 2\n\n3\n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\nSample Input 3\n\n44852\n\nSample Output 3\n\n16", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 555, "cpu_time_ms": 126, "memory_kb": 56480}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s243721806", "group_id": "codeNet:p03329", "input_text": "(let ((n (read))\n (a '())\n (ans 0))\n (loop for i from 1 while (<= (expt 6 i) n) do\n (setf a (append a (list (expt 6 i) (expt 9 i)))))\n (setf a (sort (copy-list a) #'>))\n (loop for i in a do\n (if (<= i n) (progn (incf ans (floor (/ n i)))\n (setf n (rem n i)))))\n (format t \"~A~%\" (+ ans n)))\n", "language": "Lisp", "metadata": {"date": 1528816016, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03329.html", "problem_id": "p03329", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03329/input.txt", "sample_output_relpath": "derived/input_output/data/p03329/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03329/Lisp/s243721806.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s243721806", "user_id": "u994767958"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let ((n (read))\n (a '())\n (ans 0))\n (loop for i from 1 while (<= (expt 6 i) n) do\n (setf a (append a (list (expt 6 i) (expt 9 i)))))\n (setf a (sort (copy-list a) #'>))\n (loop for i in a do\n (if (<= i n) (progn (incf ans (floor (/ n i)))\n (setf n (rem n i)))))\n (format t \"~A~%\" (+ ans n)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTo make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:\n\n1 yen (the currency of Japan)\n\n6 yen, 6^2(=36) yen, 6^3(=216) yen, ...\n\n9 yen, 9^2(=81) yen, 9^3(=729) yen, ...\n\nAt least how many operations are required to withdraw exactly N yen in total?\n\nIt is not allowed to re-deposit the money you withdrew.\n\nConstraints\n\n1 \\leq N \\leq 100000\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf at least x operations are required to withdraw exactly N yen in total, print x.\n\nSample Input 1\n\n127\n\nSample Output 1\n\n4\n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw 127 yen in four operations.\n\nSample Input 2\n\n3\n\nSample Output 2\n\n3\n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\nSample Input 3\n\n44852\n\nSample Output 3\n\n16", "sample_input": "127\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03329", "source_text": "Score : 300 points\n\nProblem Statement\n\nTo make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:\n\n1 yen (the currency of Japan)\n\n6 yen, 6^2(=36) yen, 6^3(=216) yen, ...\n\n9 yen, 9^2(=81) yen, 9^3(=729) yen, ...\n\nAt least how many operations are required to withdraw exactly N yen in total?\n\nIt is not allowed to re-deposit the money you withdrew.\n\nConstraints\n\n1 \\leq N \\leq 100000\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf at least x operations are required to withdraw exactly N yen in total, print x.\n\nSample Input 1\n\n127\n\nSample Output 1\n\n4\n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw 127 yen in four operations.\n\nSample Input 2\n\n3\n\nSample Output 2\n\n3\n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\nSample Input 3\n\n44852\n\nSample Output 3\n\n16", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 345, "cpu_time_ms": 19, "memory_kb": 6504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s722843272", "group_id": "codeNet:p03329", "input_text": "(let ((n (read))\n (a '())\n (ans 0))\n (loop for i from 1 while (< (expt 6 i) n) do\n (setf a (append a (list (expt 6 i) (expt 9 i)))))\n (setf a (sort (copy-list a) #'>))\n (loop for i in a do\n (if (<= i n) (progn (incf ans (floor (/ n i)))\n (setf n (rem n i)))))\n (format t \"~A~%\" (+ ans n)))\n", "language": "Lisp", "metadata": {"date": 1528815878, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03329.html", "problem_id": "p03329", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03329/input.txt", "sample_output_relpath": "derived/input_output/data/p03329/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03329/Lisp/s722843272.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s722843272", "user_id": "u994767958"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let ((n (read))\n (a '())\n (ans 0))\n (loop for i from 1 while (< (expt 6 i) n) do\n (setf a (append a (list (expt 6 i) (expt 9 i)))))\n (setf a (sort (copy-list a) #'>))\n (loop for i in a do\n (if (<= i n) (progn (incf ans (floor (/ n i)))\n (setf n (rem n i)))))\n (format t \"~A~%\" (+ ans n)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTo make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:\n\n1 yen (the currency of Japan)\n\n6 yen, 6^2(=36) yen, 6^3(=216) yen, ...\n\n9 yen, 9^2(=81) yen, 9^3(=729) yen, ...\n\nAt least how many operations are required to withdraw exactly N yen in total?\n\nIt is not allowed to re-deposit the money you withdrew.\n\nConstraints\n\n1 \\leq N \\leq 100000\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf at least x operations are required to withdraw exactly N yen in total, print x.\n\nSample Input 1\n\n127\n\nSample Output 1\n\n4\n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw 127 yen in four operations.\n\nSample Input 2\n\n3\n\nSample Output 2\n\n3\n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\nSample Input 3\n\n44852\n\nSample Output 3\n\n16", "sample_input": "127\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03329", "source_text": "Score : 300 points\n\nProblem Statement\n\nTo make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:\n\n1 yen (the currency of Japan)\n\n6 yen, 6^2(=36) yen, 6^3(=216) yen, ...\n\n9 yen, 9^2(=81) yen, 9^3(=729) yen, ...\n\nAt least how many operations are required to withdraw exactly N yen in total?\n\nIt is not allowed to re-deposit the money you withdrew.\n\nConstraints\n\n1 \\leq N \\leq 100000\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf at least x operations are required to withdraw exactly N yen in total, print x.\n\nSample Input 1\n\n127\n\nSample Output 1\n\n4\n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw 127 yen in four operations.\n\nSample Input 2\n\n3\n\nSample Output 2\n\n3\n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\nSample Input 3\n\n44852\n\nSample Output 3\n\n16", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 344, "cpu_time_ms": 195, "memory_kb": 16484}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s778808123", "group_id": "codeNet:p03329", "input_text": " (let ((n (read)))\n (labels ((maxpower (n x)\n (labels ((iter (n x c)\n (if (<= (expt x c) n)\n (iter n x (1+ c))\n (expt x (1- c)))))\n (iter n x 1)))\n (f (n n6 n9)\n (let ((nlarge (max n6 n9)))\n (if (= nlarge 1)\n n\n (1+ (let ((new-n (- n nlarge)))\n (f new-n (maxpower new-n 6) (maxpower new-n 9))))))))\n (format t \"~A~%\" (f n (maxpower n 6) (maxpower n 9)))))", "language": "Lisp", "metadata": {"date": 1528684578, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03329.html", "problem_id": "p03329", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03329/input.txt", "sample_output_relpath": "derived/input_output/data/p03329/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03329/Lisp/s778808123.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s778808123", "user_id": "u956039157"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": " (let ((n (read)))\n (labels ((maxpower (n x)\n (labels ((iter (n x c)\n (if (<= (expt x c) n)\n (iter n x (1+ c))\n (expt x (1- c)))))\n (iter n x 1)))\n (f (n n6 n9)\n (let ((nlarge (max n6 n9)))\n (if (= nlarge 1)\n n\n (1+ (let ((new-n (- n nlarge)))\n (f new-n (maxpower new-n 6) (maxpower new-n 9))))))))\n (format t \"~A~%\" (f n (maxpower n 6) (maxpower n 9)))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTo make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:\n\n1 yen (the currency of Japan)\n\n6 yen, 6^2(=36) yen, 6^3(=216) yen, ...\n\n9 yen, 9^2(=81) yen, 9^3(=729) yen, ...\n\nAt least how many operations are required to withdraw exactly N yen in total?\n\nIt is not allowed to re-deposit the money you withdrew.\n\nConstraints\n\n1 \\leq N \\leq 100000\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf at least x operations are required to withdraw exactly N yen in total, print x.\n\nSample Input 1\n\n127\n\nSample Output 1\n\n4\n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw 127 yen in four operations.\n\nSample Input 2\n\n3\n\nSample Output 2\n\n3\n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\nSample Input 3\n\n44852\n\nSample Output 3\n\n16", "sample_input": "127\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03329", "source_text": "Score : 300 points\n\nProblem Statement\n\nTo make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:\n\n1 yen (the currency of Japan)\n\n6 yen, 6^2(=36) yen, 6^3(=216) yen, ...\n\n9 yen, 9^2(=81) yen, 9^3(=729) yen, ...\n\nAt least how many operations are required to withdraw exactly N yen in total?\n\nIt is not allowed to re-deposit the money you withdrew.\n\nConstraints\n\n1 \\leq N \\leq 100000\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf at least x operations are required to withdraw exactly N yen in total, print x.\n\nSample Input 1\n\n127\n\nSample Output 1\n\n4\n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw 127 yen in four operations.\n\nSample Input 2\n\n3\n\nSample Output 2\n\n3\n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\nSample Input 3\n\n44852\n\nSample Output 3\n\n16", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 554, "cpu_time_ms": 873, "memory_kb": 13284}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s986334364", "group_id": "codeNet:p03330", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (c (read))\n (ds (make-array (list c c) :element-type 'uint16))\n (table0 (make-array c :element-type 'uint32))\n (table1 (make-array c :element-type 'uint32))\n (table2 (make-array c :element-type 'uint32)))\n (declare (uint16 n c))\n (dotimes (i c)\n (dotimes (j c)\n (setf (aref ds i j) (read-fixnum))))\n (dotimes (i n)\n (dotimes (j n)\n (let ((col (- (read-fixnum) 1)))\n (ecase (mod (+ i j) 3)\n (0 (incf (aref table0 col)))\n (1 (incf (aref table1 col)))\n (2 (incf (aref table2 col)))))))\n (let ((res #xffffffff))\n (declare (uint32 res))\n (dotimes (col0 c)\n (dotimes (col1 c)\n (dotimes (col2 c)\n (unless (or (= col0 col1) (= col1 col2) (= col2 col0))\n (setf res\n (min res\n (+ (loop for scol below c\n sum (* (aref ds scol col0) (aref table0 scol))\n of-type uint32)\n (loop for scol below c\n sum (* (aref ds scol col1) (aref table1 scol))\n of-type uint32)\n (loop for scol below c\n sum (* (aref ds scol col2) (aref table2 scol))\n of-type uint32))))))))\n (println res))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1560398422, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03330.html", "problem_id": "p03330", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03330/input.txt", "sample_output_relpath": "derived/input_output/data/p03330/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03330/Lisp/s986334364.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s986334364", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (c (read))\n (ds (make-array (list c c) :element-type 'uint16))\n (table0 (make-array c :element-type 'uint32))\n (table1 (make-array c :element-type 'uint32))\n (table2 (make-array c :element-type 'uint32)))\n (declare (uint16 n c))\n (dotimes (i c)\n (dotimes (j c)\n (setf (aref ds i j) (read-fixnum))))\n (dotimes (i n)\n (dotimes (j n)\n (let ((col (- (read-fixnum) 1)))\n (ecase (mod (+ i j) 3)\n (0 (incf (aref table0 col)))\n (1 (incf (aref table1 col)))\n (2 (incf (aref table2 col)))))))\n (let ((res #xffffffff))\n (declare (uint32 res))\n (dotimes (col0 c)\n (dotimes (col1 c)\n (dotimes (col2 c)\n (unless (or (= col0 col1) (= col1 col2) (= col2 col0))\n (setf res\n (min res\n (+ (loop for scol below c\n sum (* (aref ds scol col0) (aref table0 scol))\n of-type uint32)\n (loop for scol below c\n sum (* (aref ds scol col1) (aref table1 scol))\n of-type uint32)\n (loop for scol below c\n sum (* (aref ds scol col2) (aref table2 scol))\n of-type uint32))))))))\n (println res))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left.\n\nThese squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}.\n\nWe say the grid is a good grid when the following condition is met for all i,j,x,y satisfying 1 \\leq i,j,x,y \\leq N:\n\nIf (i+j) \\% 3=(x+y) \\% 3, the color of (i,j) and the color of (x,y) are the same.\n\nIf (i+j) \\% 3 \\neq (x+y) \\% 3, the color of (i,j) and the color of (x,y) are different.\n\nHere, X \\% Y represents X modulo Y.\n\nWe will repaint zero or more squares so that the grid will be a good grid.\n\nFor a square, the wrongness when the color of the square is X before repainting and Y after repainting, is D_{X,Y}.\n\nFind the minimum possible sum of the wrongness of all the squares.\n\nConstraints\n\n1 \\leq N \\leq 500\n\n3 \\leq C \\leq 30\n\n1 \\leq D_{i,j} \\leq 1000 (i \\neq j),D_{i,j}=0 (i=j)\n\n1 \\leq c_{i,j} \\leq C\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN C\nD_{1,1} ... D_{1,C}\n:\nD_{C,1} ... D_{C,C}\nc_{1,1} ... c_{1,N}\n:\nc_{N,1} ... c_{N,N}\n\nOutput\n\nIf the minimum possible sum of the wrongness of all the squares is x, print x.\n\nSample Input 1\n\n2 3\n0 1 1\n1 0 1\n1 4 0\n1 2\n3 3\n\nSample Output 1\n\n3\n\nRepaint (1,1) to Color 2. The wrongness of (1,1) becomes D_{1,2}=1.\n\nRepaint (1,2) to Color 3. The wrongness of (1,2) becomes D_{2,3}=1.\n\nRepaint (2,2) to Color 1. The wrongness of (2,2) becomes D_{3,1}=1.\n\nIn this case, the sum of the wrongness of all the squares is 3.\n\nNote that D_{i,j} \\neq D_{j,i} is possible.\n\nSample Input 2\n\n4 3\n0 12 71\n81 0 53\n14 92 0\n1 1 2 1\n2 1 1 2\n2 2 1 3\n1 1 2 2\n\nSample Output 2\n\n428", "sample_input": "2 3\n0 1 1\n1 0 1\n1 4 0\n1 2\n3 3\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03330", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left.\n\nThese squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}.\n\nWe say the grid is a good grid when the following condition is met for all i,j,x,y satisfying 1 \\leq i,j,x,y \\leq N:\n\nIf (i+j) \\% 3=(x+y) \\% 3, the color of (i,j) and the color of (x,y) are the same.\n\nIf (i+j) \\% 3 \\neq (x+y) \\% 3, the color of (i,j) and the color of (x,y) are different.\n\nHere, X \\% Y represents X modulo Y.\n\nWe will repaint zero or more squares so that the grid will be a good grid.\n\nFor a square, the wrongness when the color of the square is X before repainting and Y after repainting, is D_{X,Y}.\n\nFind the minimum possible sum of the wrongness of all the squares.\n\nConstraints\n\n1 \\leq N \\leq 500\n\n3 \\leq C \\leq 30\n\n1 \\leq D_{i,j} \\leq 1000 (i \\neq j),D_{i,j}=0 (i=j)\n\n1 \\leq c_{i,j} \\leq C\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN C\nD_{1,1} ... D_{1,C}\n:\nD_{C,1} ... D_{C,C}\nc_{1,1} ... c_{1,N}\n:\nc_{N,1} ... c_{N,N}\n\nOutput\n\nIf the minimum possible sum of the wrongness of all the squares is x, print x.\n\nSample Input 1\n\n2 3\n0 1 1\n1 0 1\n1 4 0\n1 2\n3 3\n\nSample Output 1\n\n3\n\nRepaint (1,1) to Color 2. The wrongness of (1,1) becomes D_{1,2}=1.\n\nRepaint (1,2) to Color 3. The wrongness of (1,2) becomes D_{2,3}=1.\n\nRepaint (2,2) to Color 1. The wrongness of (2,2) becomes D_{3,1}=1.\n\nIn this case, the sum of the wrongness of all the squares is 3.\n\nNote that D_{i,j} \\neq D_{j,i} is possible.\n\nSample Input 2\n\n4 3\n0 12 71\n81 0 53\n14 92 0\n1 1 2 1\n2 1 1 2\n2 2 1 3\n1 1 2 2\n\nSample Output 2\n\n428", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3897, "cpu_time_ms": 87, "memory_kb": 14824}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s640806544", "group_id": "codeNet:p03330", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (c (read))\n (ds (make-array (list c c) :element-type 'uint16))\n (table0 (make-array c :element-type 'uint32))\n (table1 (make-array c :element-type 'uint32))\n (table2 (make-array c :element-type 'uint32)))\n (declare (uint16 n c))\n (dotimes (i c)\n (dotimes (j c)\n (setf (aref ds i j) (read-fixnum))))\n (dotimes (i n)\n (dotimes (j n)\n (let ((col (- (read-fixnum) 1)))\n (ecase (mod (+ i j) 3)\n (0 (incf (aref table0 col)))\n (1 (incf (aref table1 col)))\n (2 (incf (aref table2 col)))))))\n (let ((res #xffffffff))\n (declare (uint32 res))\n (dotimes (col0 c)\n (dotimes (col1 c)\n (dotimes (col2 c)\n (unless (or (= col0 col1) (= col1 col2) (= col2 col0))\n (setf res\n (min res\n (+ (loop for scol below c\n sum (* (aref ds scol col0) (aref table0 scol))\n of-type uint32)\n (loop for scol below c\n sum (* (aref ds scol col1) (aref table1 scol))\n of-type uint32)\n (loop for scol below c\n sum (* (aref ds scol col2) (aref table2 scol))\n of-type uint32))))))))\n (println res))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1560398385, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03330.html", "problem_id": "p03330", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03330/input.txt", "sample_output_relpath": "derived/input_output/data/p03330/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03330/Lisp/s640806544.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s640806544", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (c (read))\n (ds (make-array (list c c) :element-type 'uint16))\n (table0 (make-array c :element-type 'uint32))\n (table1 (make-array c :element-type 'uint32))\n (table2 (make-array c :element-type 'uint32)))\n (declare (uint16 n c))\n (dotimes (i c)\n (dotimes (j c)\n (setf (aref ds i j) (read-fixnum))))\n (dotimes (i n)\n (dotimes (j n)\n (let ((col (- (read-fixnum) 1)))\n (ecase (mod (+ i j) 3)\n (0 (incf (aref table0 col)))\n (1 (incf (aref table1 col)))\n (2 (incf (aref table2 col)))))))\n (let ((res #xffffffff))\n (declare (uint32 res))\n (dotimes (col0 c)\n (dotimes (col1 c)\n (dotimes (col2 c)\n (unless (or (= col0 col1) (= col1 col2) (= col2 col0))\n (setf res\n (min res\n (+ (loop for scol below c\n sum (* (aref ds scol col0) (aref table0 scol))\n of-type uint32)\n (loop for scol below c\n sum (* (aref ds scol col1) (aref table1 scol))\n of-type uint32)\n (loop for scol below c\n sum (* (aref ds scol col2) (aref table2 scol))\n of-type uint32))))))))\n (println res))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left.\n\nThese squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}.\n\nWe say the grid is a good grid when the following condition is met for all i,j,x,y satisfying 1 \\leq i,j,x,y \\leq N:\n\nIf (i+j) \\% 3=(x+y) \\% 3, the color of (i,j) and the color of (x,y) are the same.\n\nIf (i+j) \\% 3 \\neq (x+y) \\% 3, the color of (i,j) and the color of (x,y) are different.\n\nHere, X \\% Y represents X modulo Y.\n\nWe will repaint zero or more squares so that the grid will be a good grid.\n\nFor a square, the wrongness when the color of the square is X before repainting and Y after repainting, is D_{X,Y}.\n\nFind the minimum possible sum of the wrongness of all the squares.\n\nConstraints\n\n1 \\leq N \\leq 500\n\n3 \\leq C \\leq 30\n\n1 \\leq D_{i,j} \\leq 1000 (i \\neq j),D_{i,j}=0 (i=j)\n\n1 \\leq c_{i,j} \\leq C\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN C\nD_{1,1} ... D_{1,C}\n:\nD_{C,1} ... D_{C,C}\nc_{1,1} ... c_{1,N}\n:\nc_{N,1} ... c_{N,N}\n\nOutput\n\nIf the minimum possible sum of the wrongness of all the squares is x, print x.\n\nSample Input 1\n\n2 3\n0 1 1\n1 0 1\n1 4 0\n1 2\n3 3\n\nSample Output 1\n\n3\n\nRepaint (1,1) to Color 2. The wrongness of (1,1) becomes D_{1,2}=1.\n\nRepaint (1,2) to Color 3. The wrongness of (1,2) becomes D_{2,3}=1.\n\nRepaint (2,2) to Color 1. The wrongness of (2,2) becomes D_{3,1}=1.\n\nIn this case, the sum of the wrongness of all the squares is 3.\n\nNote that D_{i,j} \\neq D_{j,i} is possible.\n\nSample Input 2\n\n4 3\n0 12 71\n81 0 53\n14 92 0\n1 1 2 1\n2 1 1 2\n2 2 1 3\n1 1 2 2\n\nSample Output 2\n\n428", "sample_input": "2 3\n0 1 1\n1 0 1\n1 4 0\n1 2\n3 3\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03330", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left.\n\nThese squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}.\n\nWe say the grid is a good grid when the following condition is met for all i,j,x,y satisfying 1 \\leq i,j,x,y \\leq N:\n\nIf (i+j) \\% 3=(x+y) \\% 3, the color of (i,j) and the color of (x,y) are the same.\n\nIf (i+j) \\% 3 \\neq (x+y) \\% 3, the color of (i,j) and the color of (x,y) are different.\n\nHere, X \\% Y represents X modulo Y.\n\nWe will repaint zero or more squares so that the grid will be a good grid.\n\nFor a square, the wrongness when the color of the square is X before repainting and Y after repainting, is D_{X,Y}.\n\nFind the minimum possible sum of the wrongness of all the squares.\n\nConstraints\n\n1 \\leq N \\leq 500\n\n3 \\leq C \\leq 30\n\n1 \\leq D_{i,j} \\leq 1000 (i \\neq j),D_{i,j}=0 (i=j)\n\n1 \\leq c_{i,j} \\leq C\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN C\nD_{1,1} ... D_{1,C}\n:\nD_{C,1} ... D_{C,C}\nc_{1,1} ... c_{1,N}\n:\nc_{N,1} ... c_{N,N}\n\nOutput\n\nIf the minimum possible sum of the wrongness of all the squares is x, print x.\n\nSample Input 1\n\n2 3\n0 1 1\n1 0 1\n1 4 0\n1 2\n3 3\n\nSample Output 1\n\n3\n\nRepaint (1,1) to Color 2. The wrongness of (1,1) becomes D_{1,2}=1.\n\nRepaint (1,2) to Color 3. The wrongness of (1,2) becomes D_{2,3}=1.\n\nRepaint (2,2) to Color 1. The wrongness of (2,2) becomes D_{3,1}=1.\n\nIn this case, the sum of the wrongness of all the squares is 3.\n\nNote that D_{i,j} \\neq D_{j,i} is possible.\n\nSample Input 2\n\n4 3\n0 12 71\n81 0 53\n14 92 0\n1 1 2 1\n2 1 1 2\n2 2 1 3\n1 1 2 2\n\nSample Output 2\n\n428", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3861, "cpu_time_ms": 108, "memory_kb": 17380}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s025965407", "group_id": "codeNet:p03331", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline integer-length*))\n(defun integer-length* (x &optional (radix 10))\n \"Returns the length of the integer X when displayed in RADIX. (Returns 0 when\nX = 0. Ignores the negative sign.)\"\n (declare (integer x)\n ((integer 2 #.most-positive-fixnum) radix))\n (loop for length of-type (integer 0 #.most-positive-fixnum) from 0\n for y = (abs x) then (floor y radix)\n until (zerop y)\n finally (return length)))\n\n(declaim (inline digit-sum))\n(defun digit-sum (x &optional (radix 10))\n \"Returns the sum of the each digit of X w.r.t. RADIX. (Returns 0 when X =\n0. Ignores the negative sign.)\"\n (declare (integer x)\n ((integer 2 #.most-positive-fixnum) radix))\n (let ((sum 0)\n (x (abs x)))\n (declare (unsigned-byte x)\n ((integer 0 #.most-positive-fixnum) sum))\n (loop\n (when (zerop x)\n (return sum))\n (multiple-value-bind (quot rem) (floor x radix)\n (incf sum rem)\n (setq x quot)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read)))\n (println\n (loop for a from 1 to (floor n 2)\n for b = (- n a)\n minimize (+ (digit-sum a) (digit-sum b))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"15\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"100000\n\"\n \"10\n\")))\n", "language": "Lisp", "metadata": {"date": 1577967964, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03331.html", "problem_id": "p03331", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03331/input.txt", "sample_output_relpath": "derived/input_output/data/p03331/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03331/Lisp/s025965407.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s025965407", "user_id": "u352600849"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline integer-length*))\n(defun integer-length* (x &optional (radix 10))\n \"Returns the length of the integer X when displayed in RADIX. (Returns 0 when\nX = 0. Ignores the negative sign.)\"\n (declare (integer x)\n ((integer 2 #.most-positive-fixnum) radix))\n (loop for length of-type (integer 0 #.most-positive-fixnum) from 0\n for y = (abs x) then (floor y radix)\n until (zerop y)\n finally (return length)))\n\n(declaim (inline digit-sum))\n(defun digit-sum (x &optional (radix 10))\n \"Returns the sum of the each digit of X w.r.t. RADIX. (Returns 0 when X =\n0. Ignores the negative sign.)\"\n (declare (integer x)\n ((integer 2 #.most-positive-fixnum) radix))\n (let ((sum 0)\n (x (abs x)))\n (declare (unsigned-byte x)\n ((integer 0 #.most-positive-fixnum) sum))\n (loop\n (when (zerop x)\n (return sum))\n (multiple-value-bind (quot rem) (floor x radix)\n (incf sum rem)\n (setq x quot)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read)))\n (println\n (loop for a from 1 to (floor n 2)\n for b = (- n a)\n minimize (+ (digit-sum a) (digit-sum b))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"15\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"100000\n\"\n \"10\n\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi has two positive integers A and B.\n\nIt is known that A plus B equals N.\nFind the minimum possible value of \"the sum of the digits of A\" plus \"the sum of the digits of B\" (in base 10).\n\nConstraints\n\n2 ≤ N ≤ 10^5\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum possible value of \"the sum of the digits of A\" plus \"the sum of the digits of B\".\n\nSample Input 1\n\n15\n\nSample Output 1\n\n6\n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the value in question.\n\nSample Input 2\n\n100000\n\nSample Output 2\n\n10", "sample_input": "15\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03331", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi has two positive integers A and B.\n\nIt is known that A plus B equals N.\nFind the minimum possible value of \"the sum of the digits of A\" plus \"the sum of the digits of B\" (in base 10).\n\nConstraints\n\n2 ≤ N ≤ 10^5\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum possible value of \"the sum of the digits of A\" plus \"the sum of the digits of B\".\n\nSample Input 1\n\n15\n\nSample Output 1\n\n6\n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the value in question.\n\nSample Input 2\n\n100000\n\nSample Output 2\n\n10", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4811, "cpu_time_ms": 54, "memory_kb": 11108}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s758123219", "group_id": "codeNet:p03337", "input_text": "(defun func (a b)\n (max (+ a b) (- a b) (* a b)))\n\n(princ (func (read) (read)))\n", "language": "Lisp", "metadata": {"date": 1576898248, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03337.html", "problem_id": "p03337", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03337/input.txt", "sample_output_relpath": "derived/input_output/data/p03337/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03337/Lisp/s758123219.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s758123219", "user_id": "u493610446"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun func (a b)\n (max (+ a b) (- a b) (* a b)))\n\n(princ (func (read) (read)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given two integers A and B.\nFind the largest value among A+B, A-B and A \\times B.\n\nConstraints\n\n-1000 \\leq A,B \\leq 1000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the largest value among A+B, A-B and A \\times B.\n\nSample Input 1\n\n3 1\n\nSample Output 1\n\n4\n\n3+1=4, 3-1=2 and 3 \\times 1=3. The largest among them is 4.\n\nSample Input 2\n\n4 -2\n\nSample Output 2\n\n6\n\nThe largest is 4 - (-2) = 6.\n\nSample Input 3\n\n0 0\n\nSample Output 3\n\n0", "sample_input": "3 1\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03337", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given two integers A and B.\nFind the largest value among A+B, A-B and A \\times B.\n\nConstraints\n\n-1000 \\leq A,B \\leq 1000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the largest value among A+B, A-B and A \\times B.\n\nSample Input 1\n\n3 1\n\nSample Output 1\n\n4\n\n3+1=4, 3-1=2 and 3 \\times 1=3. The largest among them is 4.\n\nSample Input 2\n\n4 -2\n\nSample Output 2\n\n6\n\nThe largest is 4 - (-2) = 6.\n\nSample Input 3\n\n0 0\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 81, "cpu_time_ms": 12, "memory_kb": 3560}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s936499912", "group_id": "codeNet:p03337", "input_text": "(princ(max(+(setq a(read))(setq b(read)))(- a b)(* a b)))", "language": "Lisp", "metadata": {"date": 1528611838, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03337.html", "problem_id": "p03337", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03337/input.txt", "sample_output_relpath": "derived/input_output/data/p03337/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03337/Lisp/s936499912.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s936499912", "user_id": "u657913472"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(princ(max(+(setq a(read))(setq b(read)))(- a b)(* a b)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given two integers A and B.\nFind the largest value among A+B, A-B and A \\times B.\n\nConstraints\n\n-1000 \\leq A,B \\leq 1000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the largest value among A+B, A-B and A \\times B.\n\nSample Input 1\n\n3 1\n\nSample Output 1\n\n4\n\n3+1=4, 3-1=2 and 3 \\times 1=3. The largest among them is 4.\n\nSample Input 2\n\n4 -2\n\nSample Output 2\n\n6\n\nThe largest is 4 - (-2) = 6.\n\nSample Input 3\n\n0 0\n\nSample Output 3\n\n0", "sample_input": "3 1\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03337", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given two integers A and B.\nFind the largest value among A+B, A-B and A \\times B.\n\nConstraints\n\n-1000 \\leq A,B \\leq 1000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the largest value among A+B, A-B and A \\times B.\n\nSample Input 1\n\n3 1\n\nSample Output 1\n\n4\n\n3+1=4, 3-1=2 and 3 \\times 1=3. The largest among them is 4.\n\nSample Input 2\n\n4 -2\n\nSample Output 2\n\n6\n\nThe largest is 4 - (-2) = 6.\n\nSample Input 3\n\n0 0\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 57, "cpu_time_ms": 21, "memory_kb": 4196}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s921319651", "group_id": "codeNet:p03337", "input_text": "(defun AddSubMul (a b)\n (let ((n (+ a b)) (m (- a b)) (l (* a b)))\n (max n m l)))\n\n(defun split-string (str)\n (let ((string-position (position #\\Space str)))\n (cond\n ((null string-position) (list str))\n (t (cons (subseq str 0 string-position) (split-string (subseq str (1+ string-position))))))))\n\n(format t \"~A~%\" \n (apply #'AddSubMul (mapcar #'parse-integer (split-string (read-line)))))", "language": "Lisp", "metadata": {"date": 1527384123, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03337.html", "problem_id": "p03337", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03337/input.txt", "sample_output_relpath": "derived/input_output/data/p03337/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03337/Lisp/s921319651.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s921319651", "user_id": "u231458241"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun AddSubMul (a b)\n (let ((n (+ a b)) (m (- a b)) (l (* a b)))\n (max n m l)))\n\n(defun split-string (str)\n (let ((string-position (position #\\Space str)))\n (cond\n ((null string-position) (list str))\n (t (cons (subseq str 0 string-position) (split-string (subseq str (1+ string-position))))))))\n\n(format t \"~A~%\" \n (apply #'AddSubMul (mapcar #'parse-integer (split-string (read-line)))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given two integers A and B.\nFind the largest value among A+B, A-B and A \\times B.\n\nConstraints\n\n-1000 \\leq A,B \\leq 1000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the largest value among A+B, A-B and A \\times B.\n\nSample Input 1\n\n3 1\n\nSample Output 1\n\n4\n\n3+1=4, 3-1=2 and 3 \\times 1=3. The largest among them is 4.\n\nSample Input 2\n\n4 -2\n\nSample Output 2\n\n6\n\nThe largest is 4 - (-2) = 6.\n\nSample Input 3\n\n0 0\n\nSample Output 3\n\n0", "sample_input": "3 1\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03337", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given two integers A and B.\nFind the largest value among A+B, A-B and A \\times B.\n\nConstraints\n\n-1000 \\leq A,B \\leq 1000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the largest value among A+B, A-B and A \\times B.\n\nSample Input 1\n\n3 1\n\nSample Output 1\n\n4\n\n3+1=4, 3-1=2 and 3 \\times 1=3. The largest among them is 4.\n\nSample Input 2\n\n4 -2\n\nSample Output 2\n\n6\n\nThe largest is 4 - (-2) = 6.\n\nSample Input 3\n\n0 0\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 408, "cpu_time_ms": 604, "memory_kb": 12516}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s315841360", "group_id": "codeNet:p03339", "input_text": "(let* ((n (read))\n (s (make-array n :initial-contents (concatenate 'list (read-line)))))\n (format t \"~A~%\" (loop for i from 0 below (1- n)\n minimize (+ (count-if (lambda (c) (equal #\\W c)) (subseq s 0 i))\n (count-if (lambda (c) (equal #\\E c)) (subseq s (1+ i)))))))", "language": "Lisp", "metadata": {"date": 1527386937, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03339.html", "problem_id": "p03339", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03339/input.txt", "sample_output_relpath": "derived/input_output/data/p03339/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03339/Lisp/s315841360.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s315841360", "user_id": "u215328090"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let* ((n (read))\n (s (make-array n :initial-contents (concatenate 'list (read-line)))))\n (format t \"~A~%\" (loop for i from 0 below (1- n)\n minimize (+ (count-if (lambda (c) (equal #\\W c)) (subseq s 0 i))\n (count-if (lambda (c) (equal #\\E c)) (subseq s (1+ i)))))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N people standing in a row from west to east.\nEach person is facing east or west.\nThe directions of the people is given as a string S of length N.\nThe i-th person from the west is facing east if S_i = E, and west if S_i = W.\n\nYou will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader.\nHere, we do not care which direction the leader is facing.\n\nThe people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized.\nFind the minimum number of people who have to change their directions.\n\nConstraints\n\n2 \\leq N \\leq 3 \\times 10^5\n\n|S| = N\n\nS_i is E or W.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the minimum number of people who have to change their directions.\n\nSample Input 1\n\n5\nWEEWW\n\nSample Output 1\n\n1\n\nAssume that we appoint the third person from the west as the leader.\nThen, the first person from the west needs to face east and has to turn around.\nThe other people do not need to change their directions, so the number of people who have to change their directions is 1 in this case.\nIt is not possible to have 0 people who have to change their directions, so the answer is 1.\n\nSample Input 2\n\n12\nWEWEWEEEWWWE\n\nSample Output 2\n\n4\n\nSample Input 3\n\n8\nWWWWWEEE\n\nSample Output 3\n\n3", "sample_input": "5\nWEEWW\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03339", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N people standing in a row from west to east.\nEach person is facing east or west.\nThe directions of the people is given as a string S of length N.\nThe i-th person from the west is facing east if S_i = E, and west if S_i = W.\n\nYou will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader.\nHere, we do not care which direction the leader is facing.\n\nThe people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized.\nFind the minimum number of people who have to change their directions.\n\nConstraints\n\n2 \\leq N \\leq 3 \\times 10^5\n\n|S| = N\n\nS_i is E or W.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the minimum number of people who have to change their directions.\n\nSample Input 1\n\n5\nWEEWW\n\nSample Output 1\n\n1\n\nAssume that we appoint the third person from the west as the leader.\nThen, the first person from the west needs to face east and has to turn around.\nThe other people do not need to change their directions, so the number of people who have to change their directions is 1 in this case.\nIt is not possible to have 0 people who have to change their directions, so the answer is 1.\n\nSample Input 2\n\n12\nWEWEWEEEWWWE\n\nSample Output 2\n\n4\n\nSample Input 3\n\n8\nWWWWWEEE\n\nSample Output 3\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 332, "cpu_time_ms": 2105, "memory_kb": 79080}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s728181024", "group_id": "codeNet:p03339", "input_text": "(defun Attention (str-list)\n (let ((saisyou 999999))\n (dotimes (i (length str-list))\n (let ((count 0) (result-count 0))\n (dolist (j str-list)\n (cond\n ((and (< count i) (char= j #\\W)\n (incf result-count)))\n ((and (> count i) (char= j #\\E)\n (incf result-count))))\n (incf count))\n (setf saisyou (min result-count saisyou))))\n (eval saisyou)))\n\n(defun split-string (str)\n (let ((string-position (position #\\Space str)))\n (cond\n ((null string-position) (list str))\n (t (cons (subseq str 0 string-position) \n (split-string (subseq str (1+ string-position))))))))\n\n(read-line)\n(format t \"~A~%\" (Attention (coerce (read-line) 'list)))", "language": "Lisp", "metadata": {"date": 1527385941, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03339.html", "problem_id": "p03339", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03339/input.txt", "sample_output_relpath": "derived/input_output/data/p03339/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03339/Lisp/s728181024.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s728181024", "user_id": "u231458241"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun Attention (str-list)\n (let ((saisyou 999999))\n (dotimes (i (length str-list))\n (let ((count 0) (result-count 0))\n (dolist (j str-list)\n (cond\n ((and (< count i) (char= j #\\W)\n (incf result-count)))\n ((and (> count i) (char= j #\\E)\n (incf result-count))))\n (incf count))\n (setf saisyou (min result-count saisyou))))\n (eval saisyou)))\n\n(defun split-string (str)\n (let ((string-position (position #\\Space str)))\n (cond\n ((null string-position) (list str))\n (t (cons (subseq str 0 string-position) \n (split-string (subseq str (1+ string-position))))))))\n\n(read-line)\n(format t \"~A~%\" (Attention (coerce (read-line) 'list)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N people standing in a row from west to east.\nEach person is facing east or west.\nThe directions of the people is given as a string S of length N.\nThe i-th person from the west is facing east if S_i = E, and west if S_i = W.\n\nYou will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader.\nHere, we do not care which direction the leader is facing.\n\nThe people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized.\nFind the minimum number of people who have to change their directions.\n\nConstraints\n\n2 \\leq N \\leq 3 \\times 10^5\n\n|S| = N\n\nS_i is E or W.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the minimum number of people who have to change their directions.\n\nSample Input 1\n\n5\nWEEWW\n\nSample Output 1\n\n1\n\nAssume that we appoint the third person from the west as the leader.\nThen, the first person from the west needs to face east and has to turn around.\nThe other people do not need to change their directions, so the number of people who have to change their directions is 1 in this case.\nIt is not possible to have 0 people who have to change their directions, so the answer is 1.\n\nSample Input 2\n\n12\nWEWEWEEEWWWE\n\nSample Output 2\n\n4\n\nSample Input 3\n\n8\nWWWWWEEE\n\nSample Output 3\n\n3", "sample_input": "5\nWEEWW\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03339", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N people standing in a row from west to east.\nEach person is facing east or west.\nThe directions of the people is given as a string S of length N.\nThe i-th person from the west is facing east if S_i = E, and west if S_i = W.\n\nYou will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader.\nHere, we do not care which direction the leader is facing.\n\nThe people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized.\nFind the minimum number of people who have to change their directions.\n\nConstraints\n\n2 \\leq N \\leq 3 \\times 10^5\n\n|S| = N\n\nS_i is E or W.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the minimum number of people who have to change their directions.\n\nSample Input 1\n\n5\nWEEWW\n\nSample Output 1\n\n1\n\nAssume that we appoint the third person from the west as the leader.\nThen, the first person from the west needs to face east and has to turn around.\nThe other people do not need to change their directions, so the number of people who have to change their directions is 1 in this case.\nIt is not possible to have 0 people who have to change their directions, so the answer is 1.\n\nSample Input 2\n\n12\nWEWEWEEEWWWE\n\nSample Output 2\n\n4\n\nSample Input 3\n\n8\nWWWWWEEE\n\nSample Output 3\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 748, "cpu_time_ms": 2104, "memory_kb": 12904}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s234530602", "group_id": "codeNet:p03345", "input_text": "(let ((a (read))\n (b (read))\n (c (read))\n (k (read)))\n (format t \"~A~%\" (if (oddp k) (- b a) (- a b))))\n", "language": "Lisp", "metadata": {"date": 1527015214, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03345.html", "problem_id": "p03345", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03345/input.txt", "sample_output_relpath": "derived/input_output/data/p03345/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03345/Lisp/s234530602.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s234530602", "user_id": "u994767958"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (c (read))\n (k (read)))\n (format t \"~A~%\" (if (oddp k) (- b a) (- a b))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively.\nAfter repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get:\n\nEach of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result.\n\nHowever, if the absolute value of the answer exceeds 10^{18}, print Unfair instead.\n\nConstraints\n\n1 \\leq A,B,C \\leq 10^9\n\n0 \\leq K \\leq 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C K\n\nOutput\n\nPrint the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times.\nIf the absolute value of the answer exceeds 10^{18}, print Unfair instead.\n\nSample Input 1\n\n1 2 3 1\n\nSample Output 1\n\n1\n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3, respectively. We should print 5-4=1.\n\nSample Input 2\n\n2 3 2 0\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n1000000000 1000000000 1000000000 1000000000000000000\n\nSample Output 3\n\n0", "sample_input": "1 2 3 1\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03345", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively.\nAfter repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get:\n\nEach of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result.\n\nHowever, if the absolute value of the answer exceeds 10^{18}, print Unfair instead.\n\nConstraints\n\n1 \\leq A,B,C \\leq 10^9\n\n0 \\leq K \\leq 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C K\n\nOutput\n\nPrint the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times.\nIf the absolute value of the answer exceeds 10^{18}, print Unfair instead.\n\nSample Input 1\n\n1 2 3 1\n\nSample Output 1\n\n1\n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3, respectively. We should print 5-4=1.\n\nSample Input 2\n\n2 3 2 0\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n1000000000 1000000000 1000000000 1000000000000000000\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 120, "cpu_time_ms": 119, "memory_kb": 12260}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s263168079", "group_id": "codeNet:p03345", "input_text": "(defun mul (a b)\n (let* ((dim (list (array-dimension a 0)\n (array-dimension b 1)))\n (result (make-array dim :initial-element 0)))\n (loop for i below (array-dimension a 0)\n do (loop for j below (array-dimension b 1)\n do (let ((acc 0))\n (loop for k below (array-dimension a 1)\n do (incf acc (* (aref a i k) (aref b k j))))\n (setf (aref result i j) acc))))\n result))\n\n(defparameter *S* #2a((-1 -1 1)\n ( 0 1 1)\n ( 1 0 1)))\n\n(defparameter *J* #(-1 -1 2))\n\n;; (defparameter *J2* #2a((-1 0 0)\n;; ( 0 -1 0)\n;; ( 0 0 2)))\n\n(defparameter *S^-1* #2a((-1/3 -1/3 2/3)\n (-1/3 2/3 -1/3)\n ( 1/3 1/3 1/3)))\n\n(defun make-diag (x y z)\n (let ((result (make-array '(3 3) :initial-element 0)))\n (setf (aref result 0 0) x\n (aref result 1 1) y\n (aref result 2 2) z)\n result))\n\n(defun solve (a b c k)\n (let* ((diag (make-diag (expt -1 k)\n (expt -1 k)\n (expt 0 k)))\n (x (make-array '(3 1) :initial-contents `((,a) (,b) (,c))))\n (m (mul *S* (mul diag (mul *S^-1* x))))\n (a (- (aref m 0 0) (aref m 1 0))))\n (if (> a 1e18)\n \"Unfair\"\n a)))\n\n(let ((a (read))\n (b (read))\n (c (read))\n (k (read)))\n (princ (solve a b c k))\n (terpri))\n", "language": "Lisp", "metadata": {"date": 1526867774, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03345.html", "problem_id": "p03345", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03345/input.txt", "sample_output_relpath": "derived/input_output/data/p03345/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03345/Lisp/s263168079.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s263168079", "user_id": "u188771036"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun mul (a b)\n (let* ((dim (list (array-dimension a 0)\n (array-dimension b 1)))\n (result (make-array dim :initial-element 0)))\n (loop for i below (array-dimension a 0)\n do (loop for j below (array-dimension b 1)\n do (let ((acc 0))\n (loop for k below (array-dimension a 1)\n do (incf acc (* (aref a i k) (aref b k j))))\n (setf (aref result i j) acc))))\n result))\n\n(defparameter *S* #2a((-1 -1 1)\n ( 0 1 1)\n ( 1 0 1)))\n\n(defparameter *J* #(-1 -1 2))\n\n;; (defparameter *J2* #2a((-1 0 0)\n;; ( 0 -1 0)\n;; ( 0 0 2)))\n\n(defparameter *S^-1* #2a((-1/3 -1/3 2/3)\n (-1/3 2/3 -1/3)\n ( 1/3 1/3 1/3)))\n\n(defun make-diag (x y z)\n (let ((result (make-array '(3 3) :initial-element 0)))\n (setf (aref result 0 0) x\n (aref result 1 1) y\n (aref result 2 2) z)\n result))\n\n(defun solve (a b c k)\n (let* ((diag (make-diag (expt -1 k)\n (expt -1 k)\n (expt 0 k)))\n (x (make-array '(3 1) :initial-contents `((,a) (,b) (,c))))\n (m (mul *S* (mul diag (mul *S^-1* x))))\n (a (- (aref m 0 0) (aref m 1 0))))\n (if (> a 1e18)\n \"Unfair\"\n a)))\n\n(let ((a (read))\n (b (read))\n (c (read))\n (k (read)))\n (princ (solve a b c k))\n (terpri))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively.\nAfter repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get:\n\nEach of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result.\n\nHowever, if the absolute value of the answer exceeds 10^{18}, print Unfair instead.\n\nConstraints\n\n1 \\leq A,B,C \\leq 10^9\n\n0 \\leq K \\leq 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C K\n\nOutput\n\nPrint the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times.\nIf the absolute value of the answer exceeds 10^{18}, print Unfair instead.\n\nSample Input 1\n\n1 2 3 1\n\nSample Output 1\n\n1\n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3, respectively. We should print 5-4=1.\n\nSample Input 2\n\n2 3 2 0\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n1000000000 1000000000 1000000000 1000000000000000000\n\nSample Output 3\n\n0", "sample_input": "1 2 3 1\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03345", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively.\nAfter repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get:\n\nEach of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result.\n\nHowever, if the absolute value of the answer exceeds 10^{18}, print Unfair instead.\n\nConstraints\n\n1 \\leq A,B,C \\leq 10^9\n\n0 \\leq K \\leq 10^{18}\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C K\n\nOutput\n\nPrint the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times.\nIf the absolute value of the answer exceeds 10^{18}, print Unfair instead.\n\nSample Input 1\n\n1 2 3 1\n\nSample Output 1\n\n1\n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3, respectively. We should print 5-4=1.\n\nSample Input 2\n\n2 3 2 0\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n1000000000 1000000000 1000000000 1000000000000000000\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1522, "cpu_time_ms": 251, "memory_kb": 19044}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s840247463", "group_id": "codeNet:p03346", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defun forest-p (graph)\n \"Returns the length of the longest path of a directed GRAPH when it is a\nforest, otherwise NIL.\"\n (declare ((array list (*)) graph))\n (let* ((n (length graph))\n (visited (make-array n :element-type 'bit :initial-element 0))\n (dp (make-array n :element-type 'fixnum :initial-element -1))\n (res 0))\n (declare ((integer 0 #.most-positive-fixnum) res))\n (labels ((recur (vertex)\n (if (= -1 (aref dp vertex))\n (if (= 1 (aref visited vertex))\n (return-from forest-p nil)\n (setf (aref visited vertex) 1\n (aref dp vertex)\n (loop for next in (aref graph vertex)\n maximize (+ 1 (recur next)))))\n (aref dp vertex))))\n (dotimes (i n)\n (when (zerop (aref visited i))\n (setf res (max res (recur i)))))\n res)))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (ps (make-array n :element-type 'uint31 :initial-element 0))\n (invs (make-array n :element-type 'uint31 :initial-element 0))\n (graph (make-array n :element-type 'list :initial-element nil)))\n (dotimes (i n)\n (let ((p (- (read-fixnum) 1)))\n (setf (aref invs p) i)))\n (dotimes (i (- n 1))\n (when (< (aref invs i) (aref invs (+ i 1)))\n (push (+ i 1) (aref graph i))))\n #>graph\n (println (- n (+ 1 (forest-p graph))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1\n3\n2\n4\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n3\n2\n5\n1\n4\n6\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n6\n3\n1\n2\n7\n4\n8\n5\n\"\n \"5\n\")))\n", "language": "Lisp", "metadata": {"date": 1589657629, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03346.html", "problem_id": "p03346", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03346/input.txt", "sample_output_relpath": "derived/input_output/data/p03346/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03346/Lisp/s840247463.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s840247463", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defun forest-p (graph)\n \"Returns the length of the longest path of a directed GRAPH when it is a\nforest, otherwise NIL.\"\n (declare ((array list (*)) graph))\n (let* ((n (length graph))\n (visited (make-array n :element-type 'bit :initial-element 0))\n (dp (make-array n :element-type 'fixnum :initial-element -1))\n (res 0))\n (declare ((integer 0 #.most-positive-fixnum) res))\n (labels ((recur (vertex)\n (if (= -1 (aref dp vertex))\n (if (= 1 (aref visited vertex))\n (return-from forest-p nil)\n (setf (aref visited vertex) 1\n (aref dp vertex)\n (loop for next in (aref graph vertex)\n maximize (+ 1 (recur next)))))\n (aref dp vertex))))\n (dotimes (i n)\n (when (zerop (aref visited i))\n (setf res (max res (recur i)))))\n res)))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (ps (make-array n :element-type 'uint31 :initial-element 0))\n (invs (make-array n :element-type 'uint31 :initial-element 0))\n (graph (make-array n :element-type 'list :initial-element nil)))\n (dotimes (i n)\n (let ((p (- (read-fixnum) 1)))\n (setf (aref invs p) i)))\n (dotimes (i (- n 1))\n (when (< (aref invs i) (aref invs (+ i 1)))\n (push (+ i 1) (aref graph i))))\n #>graph\n (println (- n (+ 1 (forest-p graph))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1\n3\n2\n4\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n3\n2\n5\n1\n4\n6\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n6\n3\n1\n2\n7\n4\n8\n5\n\"\n \"5\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nYou are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N.\nYou would like to sort this sequence in ascending order by repeating the following operation:\n\nChoose an element in the sequence and move it to the beginning or the end of the sequence.\n\nFind the minimum number of operations required.\nIt can be proved that it is actually possible to sort the sequence using this operation.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\n(P_1,P_2,...,P_N) is a permutation of (1,2,...,N).\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1\n:\nP_N\n\nOutput\n\nPrint the minimum number of operations required.\n\nSample Input 1\n\n4\n1\n3\n2\n4\n\nSample Output 1\n\n2\n\nFor example, the sequence can be sorted in ascending order as follows:\n\nMove 2 to the beginning. The sequence is now (2,1,3,4).\n\nMove 1 to the beginning. The sequence is now (1,2,3,4).\n\nSample Input 2\n\n6\n3\n2\n5\n1\n4\n6\n\nSample Output 2\n\n4\n\nSample Input 3\n\n8\n6\n3\n1\n2\n7\n4\n8\n5\n\nSample Output 3\n\n5", "sample_input": "4\n1\n3\n2\n4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03346", "source_text": "Score : 500 points\n\nProblem Statement\n\nYou are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N.\nYou would like to sort this sequence in ascending order by repeating the following operation:\n\nChoose an element in the sequence and move it to the beginning or the end of the sequence.\n\nFind the minimum number of operations required.\nIt can be proved that it is actually possible to sort the sequence using this operation.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\n(P_1,P_2,...,P_N) is a permutation of (1,2,...,N).\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nP_1\n:\nP_N\n\nOutput\n\nPrint the minimum number of operations required.\n\nSample Input 1\n\n4\n1\n3\n2\n4\n\nSample Output 1\n\n2\n\nFor example, the sequence can be sorted in ascending order as follows:\n\nMove 2 to the beginning. The sequence is now (2,1,3,4).\n\nMove 1 to the beginning. The sequence is now (1,2,3,4).\n\nSample Input 2\n\n6\n3\n2\n5\n1\n4\n6\n\nSample Output 2\n\n4\n\nSample Input 3\n\n8\n6\n3\n1\n2\n7\n4\n8\n5\n\nSample Output 3\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6649, "cpu_time_ms": 306, "memory_kb": 62520}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s240582788", "group_id": "codeNet:p03351", "input_text": "(princ (let* ((a (read)) (b (read)) (c (read)) (d (read)))\n (if (<= (abs (- a c)) d) \"Yes\"\n\t(if (<= (min (abs (- a b)) (abs (- b c))) d) \"Yes\" \"No\"))))\n", "language": "Lisp", "metadata": {"date": 1576898008, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03351.html", "problem_id": "p03351", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03351/input.txt", "sample_output_relpath": "derived/input_output/data/p03351/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03351/Lisp/s240582788.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s240582788", "user_id": "u493610446"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(princ (let* ((a (read)) (b (read)) (c (read)) (d (read)))\n (if (<= (abs (- a c)) d) \"Yes\"\n\t(if (<= (min (abs (- a b)) (abs (- b c))) d) \"Yes\" \"No\"))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThree people, A, B and C, are trying to communicate using transceivers.\nThey are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively.\nTwo people can directly communicate when the distance between them is at most d meters.\nDetermine if A and C can communicate, either directly or indirectly.\nHere, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.\n\nConstraints\n\n1 ≤ a,b,c ≤ 100\n\n1 ≤ d ≤ 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b c d\n\nOutput\n\nIf A and C can communicate, print Yes; if they cannot, print No.\n\nSample Input 1\n\n4 7 9 3\n\nSample Output 1\n\nYes\n\nA and B can directly communicate, and also B and C can directly communicate, so we should print Yes.\n\nSample Input 2\n\n100 10 1 2\n\nSample Output 2\n\nNo\n\nThey cannot communicate in this case.\n\nSample Input 3\n\n10 10 10 1\n\nSample Output 3\n\nYes\n\nThere can be multiple people at the same position.\n\nSample Input 4\n\n1 100 2 10\n\nSample Output 4\n\nYes", "sample_input": "4 7 9 3\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03351", "source_text": "Score : 100 points\n\nProblem Statement\n\nThree people, A, B and C, are trying to communicate using transceivers.\nThey are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively.\nTwo people can directly communicate when the distance between them is at most d meters.\nDetermine if A and C can communicate, either directly or indirectly.\nHere, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.\n\nConstraints\n\n1 ≤ a,b,c ≤ 100\n\n1 ≤ d ≤ 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b c d\n\nOutput\n\nIf A and C can communicate, print Yes; if they cannot, print No.\n\nSample Input 1\n\n4 7 9 3\n\nSample Output 1\n\nYes\n\nA and B can directly communicate, and also B and C can directly communicate, so we should print Yes.\n\nSample Input 2\n\n100 10 1 2\n\nSample Output 2\n\nNo\n\nThey cannot communicate in this case.\n\nSample Input 3\n\n10 10 10 1\n\nSample Output 3\n\nYes\n\nThere can be multiple people at the same position.\n\nSample Input 4\n\n1 100 2 10\n\nSample Output 4\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 153, "cpu_time_ms": 15, "memory_kb": 4068}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s734670916", "group_id": "codeNet:p03352", "input_text": "(let* ((n (read)))\n (princ (loop :for a :from 2 :upto (floor (sqrt 10)) :maximize(expt a (floor (log n a))))))", "language": "Lisp", "metadata": {"date": 1560455818, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03352.html", "problem_id": "p03352", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03352/input.txt", "sample_output_relpath": "derived/input_output/data/p03352/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03352/Lisp/s734670916.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s734670916", "user_id": "u610490393"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(let* ((n (read)))\n (princ (loop :for a :from 2 :upto (floor (sqrt 10)) :maximize(expt a (floor (log n a))))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given a positive integer X.\nFind the largest perfect power that is at most X.\nHere, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.\n\nConstraints\n\n1 ≤ X ≤ 1000\n\nX is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the largest perfect power that is at most X.\n\nSample Input 1\n\n10\n\nSample Output 1\n\n9\n\nThere are four perfect powers that are at most 10: 1, 4, 8 and 9.\nWe should print the largest among them, 9.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n1\n\nSample Input 3\n\n999\n\nSample Output 3\n\n961", "sample_input": "10\n"}, "reference_outputs": ["9\n"], "source_document_id": "p03352", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given a positive integer X.\nFind the largest perfect power that is at most X.\nHere, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.\n\nConstraints\n\n1 ≤ X ≤ 1000\n\nX is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the largest perfect power that is at most X.\n\nSample Input 1\n\n10\n\nSample Output 1\n\n9\n\nThere are four perfect powers that are at most 10: 1, 4, 8 and 9.\nWe should print the largest among them, 9.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n1\n\nSample Input 3\n\n999\n\nSample Output 3\n\n961", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 111, "cpu_time_ms": 97, "memory_kb": 10728}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s853485853", "group_id": "codeNet:p03352", "input_text": "(defun f (n a b)\n (cond ((or (= a 1) (= n 1)) b)\n ((= (rem n a) 0) (f (/ n a) a (1+ b)))\n (t 0)))\n\n(let ((n (read))\n (flg t))\n (loop for i from n downto 1 while flg do\n (loop for j from i downto 1 while flg do\n (if (< 1 (f i j 0)) (progn (princ i)\n (setf flg nil)))))\n (if flg (princ 1)))", "language": "Lisp", "metadata": {"date": 1551848679, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03352.html", "problem_id": "p03352", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03352/input.txt", "sample_output_relpath": "derived/input_output/data/p03352/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03352/Lisp/s853485853.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s853485853", "user_id": "u994767958"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(defun f (n a b)\n (cond ((or (= a 1) (= n 1)) b)\n ((= (rem n a) 0) (f (/ n a) a (1+ b)))\n (t 0)))\n\n(let ((n (read))\n (flg t))\n (loop for i from n downto 1 while flg do\n (loop for j from i downto 1 while flg do\n (if (< 1 (f i j 0)) (progn (princ i)\n (setf flg nil)))))\n (if flg (princ 1)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given a positive integer X.\nFind the largest perfect power that is at most X.\nHere, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.\n\nConstraints\n\n1 ≤ X ≤ 1000\n\nX is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the largest perfect power that is at most X.\n\nSample Input 1\n\n10\n\nSample Output 1\n\n9\n\nThere are four perfect powers that are at most 10: 1, 4, 8 and 9.\nWe should print the largest among them, 9.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n1\n\nSample Input 3\n\n999\n\nSample Output 3\n\n961", "sample_input": "10\n"}, "reference_outputs": ["9\n"], "source_document_id": "p03352", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given a positive integer X.\nFind the largest perfect power that is at most X.\nHere, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.\n\nConstraints\n\n1 ≤ X ≤ 1000\n\nX is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the largest perfect power that is at most X.\n\nSample Input 1\n\n10\n\nSample Output 1\n\n9\n\nThere are four perfect powers that are at most 10: 1, 4, 8 and 9.\nWe should print the largest among them, 9.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n1\n\nSample Input 3\n\n999\n\nSample Output 3\n\n961", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 377, "cpu_time_ms": 35, "memory_kb": 5088}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s716503525", "group_id": "codeNet:p03357", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:defknown popcnt ((unsigned-byte 64)) (integer 0 64)\n (sb-c:foldable sb-c:flushable sb-c:movable)\n :overwrite-fndb-silently t)\n\n (sb-c:defknown popcnt ((unsigned-byte 64)) (integer 0 64)\n (sb-c:foldable sb-c:flushable sb-c:movable)\n :overwrite-fndb-silently t)\n\n (sb-vm::define-vop (popcnt)\n (:policy :fast-safe)\n (:translate popcnt)\n (:args (x :scs (sb-vm::unsigned-reg) :target r))\n (:arg-types sb-vm::unsigned-num)\n (:results (r :scs (sb-vm::unsigned-reg)))\n (:result-types sb-vm::unsigned-num)\n (:generator 3\n (unless (sb-vm::location= r x)\n (sb-vm::inst xor r r))\n (sb-vm::inst popcnt r x)))\n\n (sb-vm::define-vop (popcnt/fx)\n (:policy :fast-safe)\n (:translate popcnt)\n (:args (x :scs (sb-vm::unsigned-reg) :target r))\n (:arg-types sb-vm::positive-fixnum)\n (:results (r :scs (sb-vm::unsigned-reg)))\n (:result-types sb-vm::unsigned-num)\n (:generator 2\n (unless (sb-vm::location= r x)\n (sb-vm::inst xor r r))\n (sb-vm::inst popcnt r x))))\n\n(defun popcnt (x)\n (popcnt x))\n\n(declaim (inline shuffle!))\n(defun shuffle! (vector)\n \"Destructively shuffles VECTOR by Fisher-Yates algorithm.\"\n (declare (vector vector))\n (loop for i from (- (length vector) 1) above 0\n for j = (random (+ i 1))\n do (rotatef (aref vector i) (aref vector j)))\n vector)\n\n;;;\n;;; Succinct bit vector\n;;;\n\n;; REVIEW: Is it really better to use the typical three-layer succint bit vector\n;; in competitive programming? It may be efficient to use a two-layer (not\n;; succinct but compact) bit vector preserving the original vector and the\n;; cumulative sum per 64-bit word.\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (assert (= sb-vm:n-word-bits 64)))\n\n(defstruct (succinct-bit-vector (:constructor %make-sucbv (storage blocks))\n (:conc-name sucbv-)\n (:copier nil))\n (storage nil :type simple-bit-vector)\n (blocks nil :type (simple-array (unsigned-byte 31) (*))))\n\n(defun make-sucbv! (vector)\n \"The consequence is undefined when VECTOR is modified after a succinct bit\nvector is created.\"\n (declare (optimize (speed 3)))\n (check-type vector simple-bit-vector)\n (let* ((vector (if (zerop (mod (length vector) sb-vm:n-word-bits))\n vector\n (adjust-array vector\n (* sb-vm:n-word-bits (ceiling (length vector) sb-vm:n-word-bits))\n :initial-element 0)))\n (len (length vector))\n (block-count (floor len sb-vm:n-word-bits))\n (blocks (make-array (+ 1 block-count)\n :element-type '(unsigned-byte 31)\n :initial-element 0))\n (sum 0))\n (declare (simple-bit-vector vector)\n ((integer 0 #.most-positive-fixnum) sum))\n (dotimes (i block-count)\n (setf (aref blocks i) sum)\n (incf sum (popcnt (sb-kernel:%vector-raw-bits vector i))))\n (setf (aref blocks block-count) sum)\n (%make-sucbv vector blocks)))\n\n(declaim (inline sucbv-ref))\n(defun sucbv-ref (sucbv index)\n (sbit (sucbv-storage sucbv) index))\n\n;; NOTE: No error handling.\n(declaim (inline sucbv-rank)\n (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) sucbv-rank))\n(defun sucbv-rank (sucbv end)\n \"Counts the number of 1's in the range [0, END).\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) end))\n (let* ((storage (sucbv-storage sucbv))\n (blocks (sucbv-blocks sucbv))\n (bpos (ash end -6))\n (brem (logand #b111111 end)))\n (+ (aref blocks bpos)\n (if (zerop brem) ; avoid out-of-bounds access\n 0\n (popcnt (ldb (byte brem 0)\n (sb-kernel:%vector-raw-bits storage bpos)))))))\n\n;;;\n;;; Wavelet matrix\n;;;\n\n(deftype wavelet-integer () '(integer 0 #.most-positive-fixnum))\n\n(defstruct (wavelet-matrix (:constructor %make-wavelet-matrix\n (length data zeros\n &aux (depth (array-dimension data 0))))\n (:copier nil)\n (:conc-name wavelet-))\n (depth 0 :type (integer 1 #.most-positive-fixnum))\n (length 0 :type (integer 0 #.most-positive-fixnum))\n (data nil :type (simple-array succinct-bit-vector (*)))\n (zeros nil :type (simple-array (integer 0 #.most-positive-fixnum) (*))))\n\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:defknown make-wavelet ((integer 1 #.most-positive-fixnum) vector)\n wavelet-matrix (sb-c:flushable)\n :overwrite-fndb-silently t))\n\n;; TODO: add deftransform for better type derivation\n(defun make-wavelet (bit-depth vector)\n (declare ((integer 1 #.most-positive-fixnum) bit-depth))\n (let* ((len (length vector))\n (fitted-len (* sb-vm:n-word-bits (ceiling len sb-vm:n-word-bits)))\n (data (locally (declare #+sbcl (muffle-conditions style-warning))\n (make-array bit-depth :element-type 'succinct-bit-vector)))\n (zeros (make-array bit-depth :element-type '(integer 0 #.most-positive-fixnum)))\n (tmp (copy-seq vector))\n (lefts (make-array len :element-type (array-element-type vector)))\n (rights (make-array len :element-type (array-element-type vector)))\n (bits (make-array fitted-len :element-type 'bit)))\n (declare ((integer 0 #.most-positive-fixnum) len fitted-len)\n (vector tmp))\n (loop for d from (- bit-depth 1) downto 0\n do (let ((lpos 0)\n (rpos 0))\n (declare ((integer 0 #.most-positive-fixnum) lpos rpos))\n (dotimes (i len)\n (let ((bit (logand 1 (ash (aref tmp i) (- d)))))\n (if (zerop bit)\n (setf (aref lefts lpos) (aref tmp i)\n lpos (+ lpos 1))\n (setf (aref rights rpos) (aref tmp i)\n rpos (+ rpos 1)))\n (setf (aref bits i) bit)))\n (setf (aref data d) (make-sucbv! (copy-seq bits))\n (aref zeros d) lpos)\n (rotatef lefts tmp)\n (replace tmp rights :start1 lpos :end2 rpos)))\n (%make-wavelet-matrix len data zeros)))\n\n(define-condition invalid-wavelet-index-error (type-error)\n ((wavelet :initarg :wavelet :reader invalid-wavelet-index-error-wavelet)\n (index :initarg :index :reader invalid-wavelet-index-error-index))\n (:report\n (lambda (condition stream)\n (let ((index (invalid-wavelet-index-error-index condition)))\n (if (consp index)\n (format stream \"Invalid range [~W, ~W) for wavelet-matrix ~W.\"\n (car index)\n (cdr index)\n (invalid-wavelet-index-error-wavelet condition))\n (format stream \"Invalid index ~W for wavelet-matrix ~W.\"\n index\n (invalid-wavelet-index-error-wavelet condition)))))))\n\n(declaim (ftype (function * (values (unsigned-byte 31) &optional)) wavelet-range-count))\n(defun wavelet-range-count (wmatrix lo hi &key (start 0) end)\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) lo hi start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (let ((data (wavelet-data wmatrix))\n (zeros (wavelet-zeros wmatrix))\n (end (or end (wavelet-length wmatrix))))\n (labels\n ((dfs (depth start end value)\n (declare ((integer 0 #.most-positive-fixnum) start end value)\n ((integer -1 #.most-positive-fixnum) depth)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (cond ((or (= start end)\n (<= hi value))\n 0)\n ((= depth -1)\n (if (< value lo)\n 0\n (- end start)))\n (t\n (let* ((next-value (logior value\n (the wavelet-integer (ash 1 depth))))\n (upper-bound (logior next-value\n (- (the wavelet-integer (ash 1 depth)) 1))))\n (cond ((< upper-bound lo)\n 0)\n ((and (<= lo value) (< upper-bound hi))\n (- end start))\n (t\n (let ((lcount (sucbv-rank (aref data depth) start))\n (rcount (sucbv-rank (aref data depth) end)))\n (+ (dfs (- depth 1)\n (- start lcount)\n (- end rcount)\n value)\n (dfs (- depth 1)\n (+ (aref zeros depth) lcount)\n (+ (aref zeros depth) rcount)\n next-value))))))))))\n (dfs (- (wavelet-depth wmatrix) 1) start end 0))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ (- (expt 2 11) 1))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (ws-plan (make-array (* 2 n) :element-type 'uint16 :initial-element +inf+))\n (bs-plan (make-array (* 2 n) :element-type 'uint16 :initial-element +inf+))\n (ws-pos (make-array (+ n 1) :element-type 'uint16))\n (bs-pos (make-array (+ n 1) :element-type 'uint16))\n (dp (make-array (list (+ n 1) (+ n 1))\n :element-type 'uint32\n :initial-element 0)))\n (declare (uint16 n))\n (dotimes (i (* 2 n))\n (let ((col (read))\n (a (read)))\n (if (eql col 'w)\n (setf (aref ws-plan i) a\n (aref ws-pos a) i)\n (setf (aref bs-plan i) a\n (aref bs-pos a) i))))\n (let ((ws-plan (make-wavelet 11 ws-plan))\n (bs-plan (make-wavelet 11 bs-plan))\n (values1 (make-array (+ 1 n) :element-type 'uint31))\n (values2 (make-array (+ 1 n) :element-type 'uint31))\n (values3 (make-array (+ 1 n) :element-type 'uint31))\n (values4 (make-array (+ 1 n) :element-type 'uint31)))\n (loop\n for x from 1 to n\n do (setf (aref values1 x)\n (wavelet-range-count ws-plan 0 x :start (+ (aref ws-pos x) 1))\n (aref values2 x)\n (wavelet-range-count ws-plan (+ x 1) 2001 :end (aref ws-pos x))))\n (loop\n for y from 1 to n\n do (setf (aref values3 y)\n (wavelet-range-count bs-plan 0 y :start (+ (aref bs-pos y) 1))\n (aref values4 y)\n (wavelet-range-count bs-plan (+ y 1) 2001 :end (aref bs-pos y))))\n (loop\n for x from 0 to n\n do (loop\n for y from 0 to n\n do (unless (= x y 0)\n (setf (aref dp x y)\n (min\n (if (zerop y)\n #xffffffff\n (let ((pos (aref bs-pos y)))\n (+ (aref dp x (- y 1))\n (wavelet-range-count ws-plan 0 (+ x 1) :start (+ pos 1))\n (aref values3 y)\n (wavelet-range-count ws-plan (+ x 1) 2001 :end pos)\n (aref values4 y))))\n (if (zerop x)\n #xffffffff\n (let ((pos (aref ws-pos x)))\n (+ (aref dp (- x 1) y)\n (aref values1 x)\n (wavelet-range-count bs-plan 0 (+ y 1) :start (+ pos 1))\n (aref values2 x)\n (wavelet-range-count bs-plan (+ y 1) 2001 :end pos))))))))))\n (println (floor (aref dp n n) 2))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"2000~%\")\n (let ((vec (make-array 4000)))\n (dotimes (i 2000)\n (setf (aref vec i) (cons 'w (* i 1))\n (aref vec (+ i 2000)) (cons 'b (+ i 1))))\n (shuffle! vec)\n (loop for (col . num) across vec\n do (format out \"~A ~A~%\" col num)))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\nB 1\nW 2\nB 3\nW 1\nW 3\nB 2\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\nB 4\nW 4\nB 3\nW 3\nB 2\nW 2\nB 1\nW 1\n\"\n \"18\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9\nW 3\nB 1\nB 4\nW 1\nB 5\nW 9\nW 2\nB 6\nW 5\nB 3\nW 8\nB 9\nW 7\nB 2\nB 8\nW 4\nW 6\nB 7\n\"\n \"41\n\")))\n", "language": "Lisp", "metadata": {"date": 1578829011, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03357.html", "problem_id": "p03357", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03357/input.txt", "sample_output_relpath": "derived/input_output/data/p03357/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03357/Lisp/s716503525.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s716503525", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:defknown popcnt ((unsigned-byte 64)) (integer 0 64)\n (sb-c:foldable sb-c:flushable sb-c:movable)\n :overwrite-fndb-silently t)\n\n (sb-c:defknown popcnt ((unsigned-byte 64)) (integer 0 64)\n (sb-c:foldable sb-c:flushable sb-c:movable)\n :overwrite-fndb-silently t)\n\n (sb-vm::define-vop (popcnt)\n (:policy :fast-safe)\n (:translate popcnt)\n (:args (x :scs (sb-vm::unsigned-reg) :target r))\n (:arg-types sb-vm::unsigned-num)\n (:results (r :scs (sb-vm::unsigned-reg)))\n (:result-types sb-vm::unsigned-num)\n (:generator 3\n (unless (sb-vm::location= r x)\n (sb-vm::inst xor r r))\n (sb-vm::inst popcnt r x)))\n\n (sb-vm::define-vop (popcnt/fx)\n (:policy :fast-safe)\n (:translate popcnt)\n (:args (x :scs (sb-vm::unsigned-reg) :target r))\n (:arg-types sb-vm::positive-fixnum)\n (:results (r :scs (sb-vm::unsigned-reg)))\n (:result-types sb-vm::unsigned-num)\n (:generator 2\n (unless (sb-vm::location= r x)\n (sb-vm::inst xor r r))\n (sb-vm::inst popcnt r x))))\n\n(defun popcnt (x)\n (popcnt x))\n\n(declaim (inline shuffle!))\n(defun shuffle! (vector)\n \"Destructively shuffles VECTOR by Fisher-Yates algorithm.\"\n (declare (vector vector))\n (loop for i from (- (length vector) 1) above 0\n for j = (random (+ i 1))\n do (rotatef (aref vector i) (aref vector j)))\n vector)\n\n;;;\n;;; Succinct bit vector\n;;;\n\n;; REVIEW: Is it really better to use the typical three-layer succint bit vector\n;; in competitive programming? It may be efficient to use a two-layer (not\n;; succinct but compact) bit vector preserving the original vector and the\n;; cumulative sum per 64-bit word.\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (assert (= sb-vm:n-word-bits 64)))\n\n(defstruct (succinct-bit-vector (:constructor %make-sucbv (storage blocks))\n (:conc-name sucbv-)\n (:copier nil))\n (storage nil :type simple-bit-vector)\n (blocks nil :type (simple-array (unsigned-byte 31) (*))))\n\n(defun make-sucbv! (vector)\n \"The consequence is undefined when VECTOR is modified after a succinct bit\nvector is created.\"\n (declare (optimize (speed 3)))\n (check-type vector simple-bit-vector)\n (let* ((vector (if (zerop (mod (length vector) sb-vm:n-word-bits))\n vector\n (adjust-array vector\n (* sb-vm:n-word-bits (ceiling (length vector) sb-vm:n-word-bits))\n :initial-element 0)))\n (len (length vector))\n (block-count (floor len sb-vm:n-word-bits))\n (blocks (make-array (+ 1 block-count)\n :element-type '(unsigned-byte 31)\n :initial-element 0))\n (sum 0))\n (declare (simple-bit-vector vector)\n ((integer 0 #.most-positive-fixnum) sum))\n (dotimes (i block-count)\n (setf (aref blocks i) sum)\n (incf sum (popcnt (sb-kernel:%vector-raw-bits vector i))))\n (setf (aref blocks block-count) sum)\n (%make-sucbv vector blocks)))\n\n(declaim (inline sucbv-ref))\n(defun sucbv-ref (sucbv index)\n (sbit (sucbv-storage sucbv) index))\n\n;; NOTE: No error handling.\n(declaim (inline sucbv-rank)\n (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) sucbv-rank))\n(defun sucbv-rank (sucbv end)\n \"Counts the number of 1's in the range [0, END).\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) end))\n (let* ((storage (sucbv-storage sucbv))\n (blocks (sucbv-blocks sucbv))\n (bpos (ash end -6))\n (brem (logand #b111111 end)))\n (+ (aref blocks bpos)\n (if (zerop brem) ; avoid out-of-bounds access\n 0\n (popcnt (ldb (byte brem 0)\n (sb-kernel:%vector-raw-bits storage bpos)))))))\n\n;;;\n;;; Wavelet matrix\n;;;\n\n(deftype wavelet-integer () '(integer 0 #.most-positive-fixnum))\n\n(defstruct (wavelet-matrix (:constructor %make-wavelet-matrix\n (length data zeros\n &aux (depth (array-dimension data 0))))\n (:copier nil)\n (:conc-name wavelet-))\n (depth 0 :type (integer 1 #.most-positive-fixnum))\n (length 0 :type (integer 0 #.most-positive-fixnum))\n (data nil :type (simple-array succinct-bit-vector (*)))\n (zeros nil :type (simple-array (integer 0 #.most-positive-fixnum) (*))))\n\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:defknown make-wavelet ((integer 1 #.most-positive-fixnum) vector)\n wavelet-matrix (sb-c:flushable)\n :overwrite-fndb-silently t))\n\n;; TODO: add deftransform for better type derivation\n(defun make-wavelet (bit-depth vector)\n (declare ((integer 1 #.most-positive-fixnum) bit-depth))\n (let* ((len (length vector))\n (fitted-len (* sb-vm:n-word-bits (ceiling len sb-vm:n-word-bits)))\n (data (locally (declare #+sbcl (muffle-conditions style-warning))\n (make-array bit-depth :element-type 'succinct-bit-vector)))\n (zeros (make-array bit-depth :element-type '(integer 0 #.most-positive-fixnum)))\n (tmp (copy-seq vector))\n (lefts (make-array len :element-type (array-element-type vector)))\n (rights (make-array len :element-type (array-element-type vector)))\n (bits (make-array fitted-len :element-type 'bit)))\n (declare ((integer 0 #.most-positive-fixnum) len fitted-len)\n (vector tmp))\n (loop for d from (- bit-depth 1) downto 0\n do (let ((lpos 0)\n (rpos 0))\n (declare ((integer 0 #.most-positive-fixnum) lpos rpos))\n (dotimes (i len)\n (let ((bit (logand 1 (ash (aref tmp i) (- d)))))\n (if (zerop bit)\n (setf (aref lefts lpos) (aref tmp i)\n lpos (+ lpos 1))\n (setf (aref rights rpos) (aref tmp i)\n rpos (+ rpos 1)))\n (setf (aref bits i) bit)))\n (setf (aref data d) (make-sucbv! (copy-seq bits))\n (aref zeros d) lpos)\n (rotatef lefts tmp)\n (replace tmp rights :start1 lpos :end2 rpos)))\n (%make-wavelet-matrix len data zeros)))\n\n(define-condition invalid-wavelet-index-error (type-error)\n ((wavelet :initarg :wavelet :reader invalid-wavelet-index-error-wavelet)\n (index :initarg :index :reader invalid-wavelet-index-error-index))\n (:report\n (lambda (condition stream)\n (let ((index (invalid-wavelet-index-error-index condition)))\n (if (consp index)\n (format stream \"Invalid range [~W, ~W) for wavelet-matrix ~W.\"\n (car index)\n (cdr index)\n (invalid-wavelet-index-error-wavelet condition))\n (format stream \"Invalid index ~W for wavelet-matrix ~W.\"\n index\n (invalid-wavelet-index-error-wavelet condition)))))))\n\n(declaim (ftype (function * (values (unsigned-byte 31) &optional)) wavelet-range-count))\n(defun wavelet-range-count (wmatrix lo hi &key (start 0) end)\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) lo hi start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (let ((data (wavelet-data wmatrix))\n (zeros (wavelet-zeros wmatrix))\n (end (or end (wavelet-length wmatrix))))\n (labels\n ((dfs (depth start end value)\n (declare ((integer 0 #.most-positive-fixnum) start end value)\n ((integer -1 #.most-positive-fixnum) depth)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (cond ((or (= start end)\n (<= hi value))\n 0)\n ((= depth -1)\n (if (< value lo)\n 0\n (- end start)))\n (t\n (let* ((next-value (logior value\n (the wavelet-integer (ash 1 depth))))\n (upper-bound (logior next-value\n (- (the wavelet-integer (ash 1 depth)) 1))))\n (cond ((< upper-bound lo)\n 0)\n ((and (<= lo value) (< upper-bound hi))\n (- end start))\n (t\n (let ((lcount (sucbv-rank (aref data depth) start))\n (rcount (sucbv-rank (aref data depth) end)))\n (+ (dfs (- depth 1)\n (- start lcount)\n (- end rcount)\n value)\n (dfs (- depth 1)\n (+ (aref zeros depth) lcount)\n (+ (aref zeros depth) rcount)\n next-value))))))))))\n (dfs (- (wavelet-depth wmatrix) 1) start end 0))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ (- (expt 2 11) 1))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (ws-plan (make-array (* 2 n) :element-type 'uint16 :initial-element +inf+))\n (bs-plan (make-array (* 2 n) :element-type 'uint16 :initial-element +inf+))\n (ws-pos (make-array (+ n 1) :element-type 'uint16))\n (bs-pos (make-array (+ n 1) :element-type 'uint16))\n (dp (make-array (list (+ n 1) (+ n 1))\n :element-type 'uint32\n :initial-element 0)))\n (declare (uint16 n))\n (dotimes (i (* 2 n))\n (let ((col (read))\n (a (read)))\n (if (eql col 'w)\n (setf (aref ws-plan i) a\n (aref ws-pos a) i)\n (setf (aref bs-plan i) a\n (aref bs-pos a) i))))\n (let ((ws-plan (make-wavelet 11 ws-plan))\n (bs-plan (make-wavelet 11 bs-plan))\n (values1 (make-array (+ 1 n) :element-type 'uint31))\n (values2 (make-array (+ 1 n) :element-type 'uint31))\n (values3 (make-array (+ 1 n) :element-type 'uint31))\n (values4 (make-array (+ 1 n) :element-type 'uint31)))\n (loop\n for x from 1 to n\n do (setf (aref values1 x)\n (wavelet-range-count ws-plan 0 x :start (+ (aref ws-pos x) 1))\n (aref values2 x)\n (wavelet-range-count ws-plan (+ x 1) 2001 :end (aref ws-pos x))))\n (loop\n for y from 1 to n\n do (setf (aref values3 y)\n (wavelet-range-count bs-plan 0 y :start (+ (aref bs-pos y) 1))\n (aref values4 y)\n (wavelet-range-count bs-plan (+ y 1) 2001 :end (aref bs-pos y))))\n (loop\n for x from 0 to n\n do (loop\n for y from 0 to n\n do (unless (= x y 0)\n (setf (aref dp x y)\n (min\n (if (zerop y)\n #xffffffff\n (let ((pos (aref bs-pos y)))\n (+ (aref dp x (- y 1))\n (wavelet-range-count ws-plan 0 (+ x 1) :start (+ pos 1))\n (aref values3 y)\n (wavelet-range-count ws-plan (+ x 1) 2001 :end pos)\n (aref values4 y))))\n (if (zerop x)\n #xffffffff\n (let ((pos (aref ws-pos x)))\n (+ (aref dp (- x 1) y)\n (aref values1 x)\n (wavelet-range-count bs-plan 0 (+ y 1) :start (+ pos 1))\n (aref values2 x)\n (wavelet-range-count bs-plan (+ y 1) 2001 :end pos))))))))))\n (println (floor (aref dp n n) 2))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"2000~%\")\n (let ((vec (make-array 4000)))\n (dotimes (i 2000)\n (setf (aref vec i) (cons 'w (* i 1))\n (aref vec (+ i 2000)) (cons 'b (+ i 1))))\n (shuffle! vec)\n (loop for (col . num) across vec\n do (format out \"~A ~A~%\" col num)))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\nB 1\nW 2\nB 3\nW 1\nW 3\nB 2\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\nB 4\nW 4\nB 3\nW 3\nB 2\nW 2\nB 1\nW 1\n\"\n \"18\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9\nW 3\nB 1\nB 4\nW 1\nB 5\nW 9\nW 2\nB 6\nW 5\nB 3\nW 8\nB 9\nW 7\nB 2\nB 8\nW 4\nW 6\nB 7\n\"\n \"41\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball.\nThe integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i.\nc_i = W represents the ball is white; c_i = B represents the ball is black.\n\nTakahashi the human wants to achieve the following objective:\n\nFor every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it.\n\nFor every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it.\n\nIn order to achieve this, he can perform the following operation:\n\nSwap two adjacent balls.\n\nFind the minimum number of operations required to achieve the objective.\n\nConstraints\n\n1 ≤ N ≤ 2000\n\n1 ≤ a_i ≤ N\n\nc_i = W or c_i = B.\n\nIf i ≠ j, (a_i,c_i) ≠ (a_j,c_j).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nc_1 a_1\nc_2 a_2\n:\nc_{2N} a_{2N}\n\nOutput\n\nPrint the minimum number of operations required to achieve the objective.\n\nSample Input 1\n\n3\nB 1\nW 2\nB 3\nW 1\nW 3\nB 2\n\nSample Output 1\n\n4\n\nThe objective can be achieved in four operations, for example, as follows:\n\nSwap the black 3 and white 1.\n\nSwap the white 1 and white 2.\n\nSwap the black 3 and white 3.\n\nSwap the black 3 and black 2.\n\nSample Input 2\n\n4\nB 4\nW 4\nB 3\nW 3\nB 2\nW 2\nB 1\nW 1\n\nSample Output 2\n\n18\n\nSample Input 3\n\n9\nW 3\nB 1\nB 4\nW 1\nB 5\nW 9\nW 2\nB 6\nW 5\nB 3\nW 8\nB 9\nW 7\nB 2\nB 8\nW 4\nW 6\nB 7\n\nSample Output 3\n\n41", "sample_input": "3\nB 1\nW 2\nB 3\nW 1\nW 3\nB 2\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03357", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball.\nThe integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i.\nc_i = W represents the ball is white; c_i = B represents the ball is black.\n\nTakahashi the human wants to achieve the following objective:\n\nFor every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it.\n\nFor every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it.\n\nIn order to achieve this, he can perform the following operation:\n\nSwap two adjacent balls.\n\nFind the minimum number of operations required to achieve the objective.\n\nConstraints\n\n1 ≤ N ≤ 2000\n\n1 ≤ a_i ≤ N\n\nc_i = W or c_i = B.\n\nIf i ≠ j, (a_i,c_i) ≠ (a_j,c_j).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nc_1 a_1\nc_2 a_2\n:\nc_{2N} a_{2N}\n\nOutput\n\nPrint the minimum number of operations required to achieve the objective.\n\nSample Input 1\n\n3\nB 1\nW 2\nB 3\nW 1\nW 3\nB 2\n\nSample Output 1\n\n4\n\nThe objective can be achieved in four operations, for example, as follows:\n\nSwap the black 3 and white 1.\n\nSwap the white 1 and white 2.\n\nSwap the black 3 and white 3.\n\nSwap the black 3 and black 2.\n\nSample Input 2\n\n4\nB 4\nW 4\nB 3\nW 3\nB 2\nW 2\nB 1\nW 1\n\nSample Output 2\n\n18\n\nSample Input 3\n\n9\nW 3\nB 1\nB 4\nW 1\nB 5\nW 9\nW 2\nB 6\nW 5\nB 3\nW 8\nB 9\nW 7\nB 2\nB 8\nW 4\nW 6\nB 7\n\nSample Output 3\n\n41", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 16188, "cpu_time_ms": 2106, "memory_kb": 60260}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s824224399", "group_id": "codeNet:p03357", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Succinct bit vector\n;;;\n\n;; REVIEW: Is it really better to use the typical three-layer succint bit vector\n;; in competitive programming? It may be efficient to use a two-layer (not\n;; succinct but compact) bit vector preserving the original vector and the\n;; cumulative sum per 64-bit word.\n\n(defconstant +chunk-width+ (* 64 16))\n;; This constant cannot be changed as the current implementation depends on the\n;; assumption: +BLOCK-WIDTH+ is equal to the word size.\n(defconstant +block-width+ 64)\n(defconstant +block-number+ (floor +chunk-width+ +block-width+))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (assert (zerop (mod +chunk-width+ +block-width+)))\n (assert (= sb-vm:n-word-bits 64)))\n\n(defstruct (succinct-bit-vector (:constructor %make-sucbv (storage chunks blocks))\n (:conc-name sucbv-)\n (:copier nil))\n (storage nil :type simple-bit-vector)\n (chunks nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n (blocks nil :type (simple-array (unsigned-byte 16) (* *))))\n\n(defun make-sucbv! (vector)\n \"The consequence is undefined when VECTOR is modified after a succinct bit\nvector is created.\"\n (declare (optimize (speed 3)))\n (check-type vector simple-bit-vector)\n (let* ((vector (if (zerop (mod (length vector) +chunk-width+))\n vector\n (adjust-array vector\n (* +chunk-width+ (ceiling (length vector) +chunk-width+))\n :initial-element 0)))\n (len (length vector))\n (chunk-count (floor len +chunk-width+))\n (chunks (make-array (+ 1 chunk-count)\n :element-type '(integer 0 #.most-positive-fixnum)\n :initial-element 0))\n (blocks (make-array (list (+ 1 chunk-count) +block-number+)\n :element-type '(unsigned-byte 16)\n :initial-element 0))\n (sum 0))\n (declare (simple-bit-vector vector)\n ((integer 0 #.most-positive-fixnum) sum))\n (dotimes (i chunk-count)\n (setf (aref chunks i) sum)\n (let ((block-sum 0))\n (declare ((integer 0 #.most-positive-fixnum) block-sum))\n (dotimes (j +block-number+)\n (setf (aref blocks i j) block-sum)\n (incf block-sum\n (logcount (sb-kernel:%vector-raw-bits vector (+ (* i +block-number+) j)))))\n (incf sum block-sum)))\n (setf (aref chunks chunk-count) sum)\n (%make-sucbv vector chunks blocks)))\n\n(declaim (inline sucbv-ref))\n(defun sucbv-ref (sucbv index)\n (sbit (sucbv-storage sucbv) index))\n\n;; NOTE: No error handling.\n(declaim (inline sucbv-rank)\n (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) sucbv-rank))\n(defun sucbv-rank (sucbv end)\n \"Counts the number of 1's in the range [0, END).\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) end))\n (let ((storage (sucbv-storage sucbv))\n (chunks (sucbv-chunks sucbv))\n (blocks (sucbv-blocks sucbv)))\n (multiple-value-bind (cpos crem) (floor end +chunk-width+)\n (multiple-value-bind (bpos brem) (floor crem +block-width+)\n (let ((csum (aref chunks cpos))\n (bsum (aref blocks cpos bpos))\n (wordpos (floor end 64)))\n (+ csum\n bsum\n (if (zerop brem) ; avoid out-of-bounds access\n 0\n (logcount (ldb (byte brem 0)\n (sb-kernel:%vector-raw-bits storage wordpos))))))))))\n\n;;;\n;;; Wavelet matrix\n;;;\n\n(deftype wavelet-integer () '(integer 0 #.most-positive-fixnum))\n\n(defstruct (wavelet-matrix (:constructor %make-wavelet-matrix\n (length data zeros\n &aux (depth (array-dimension data 0))))\n (:copier nil)\n (:conc-name wavelet-))\n (depth 0 :type (integer 1 #.most-positive-fixnum))\n (length 0 :type (integer 0 #.most-positive-fixnum))\n (data nil :type (simple-array succinct-bit-vector (*)))\n (zeros nil :type (simple-array (integer 0 #.most-positive-fixnum) (*))))\n\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:defknown make-wavelet ((integer 1 #.most-positive-fixnum) vector)\n wavelet-matrix (sb-c:flushable)\n :overwrite-fndb-silently t))\n\n;; TODO: add deftransform for better type derivation\n(defun make-wavelet (bit-depth vector)\n (declare ((integer 1 #.most-positive-fixnum) bit-depth))\n (let* ((len (length vector))\n (fitted-len (* +chunk-width+ (ceiling len +chunk-width+)))\n (data (locally (declare #+sbcl (muffle-conditions style-warning))\n (make-array bit-depth :element-type 'succinct-bit-vector)))\n (zeros (make-array bit-depth :element-type '(integer 0 #.most-positive-fixnum)))\n (tmp (copy-seq vector))\n (lefts (make-array len :element-type (array-element-type vector)))\n (rights (make-array len :element-type (array-element-type vector)))\n (bits (make-array fitted-len :element-type 'bit)))\n (declare ((integer 0 #.most-positive-fixnum) len fitted-len)\n (vector tmp))\n (loop for d from (- bit-depth 1) downto 0\n do (let ((lpos 0)\n (rpos 0))\n (declare ((integer 0 #.most-positive-fixnum) lpos rpos))\n (dotimes (i len)\n (let ((bit (logand 1 (ash (aref tmp i) (- d)))))\n (if (zerop bit)\n (setf (aref lefts lpos) (aref tmp i)\n lpos (+ lpos 1))\n (setf (aref rights rpos) (aref tmp i)\n rpos (+ rpos 1)))\n (setf (aref bits i) bit)))\n (setf (aref data d) (make-sucbv! (copy-seq bits))\n (aref zeros d) lpos)\n (rotatef lefts tmp)\n (replace tmp rights :start1 lpos :end2 rpos)))\n (%make-wavelet-matrix len data zeros)))\n\n(define-condition invalid-wavelet-index-error (type-error)\n ((wavelet :initarg :wavelet :reader invalid-wavelet-index-error-wavelet)\n (index :initarg :index :reader invalid-wavelet-index-error-index))\n (:report\n (lambda (condition stream)\n (let ((index (invalid-wavelet-index-error-index condition)))\n (if (consp index)\n (format stream \"Invalid range [~W, ~W) for wavelet-matrix ~W.\"\n (car index)\n (cdr index)\n (invalid-wavelet-index-error-wavelet condition))\n (format stream \"Invalid index ~W for wavelet-matrix ~W.\"\n index\n (invalid-wavelet-index-error-wavelet condition)))))))\n\n(declaim (ftype (function * (values (unsigned-byte 31) &optional)) wavelet-range-count))\n(defun wavelet-range-count (wmatrix lo hi &key (start 0) end)\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) lo hi start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (let ((data (wavelet-data wmatrix))\n (zeros (wavelet-zeros wmatrix))\n (end (or end (wavelet-length wmatrix))))\n (labels\n ((dfs (depth start end value)\n (declare ((integer 0 #.most-positive-fixnum) start end value)\n ((integer -1 #.most-positive-fixnum) depth)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (cond ((or (= start end)\n (<= hi value))\n 0)\n ((= depth -1)\n (if (< value lo)\n 0\n (- end start)))\n (t\n (let* ((next-value (logior value\n (the wavelet-integer (ash 1 depth))))\n (upper-bound (logior next-value\n (- (the wavelet-integer (ash 1 depth)) 1))))\n (cond ((< upper-bound lo)\n 0)\n ((and (<= lo value) (< upper-bound hi))\n (- end start))\n (t\n (let ((lcount (sucbv-rank (aref data depth) start))\n (rcount (sucbv-rank (aref data depth) end)))\n (+ (dfs (- depth 1)\n (- start lcount)\n (- end rcount)\n value)\n (dfs (- depth 1)\n (+ (aref zeros depth) lcount)\n (+ (aref zeros depth) rcount)\n next-value))))))))))\n (dfs (- (wavelet-depth wmatrix) 1) start end 0))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ (- (expt 2 11) 1))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (ws-plan (make-array (* 2 n) :element-type 'uint16 :initial-element +inf+))\n (bs-plan (make-array (* 2 n) :element-type 'uint16 :initial-element +inf+))\n (ws-pos (make-array (+ n 1) :element-type 'uint16))\n (bs-pos (make-array (+ n 1) :element-type 'uint16))\n (dp (make-array (list (+ n 1) (+ n 1))\n :element-type 'uint32\n :initial-element 0)))\n (declare (uint16 n))\n (dotimes (i (* 2 n))\n (let ((col (read))\n (a (read)))\n (if (eql col 'w)\n (setf (aref ws-plan i) a\n (aref ws-pos a) i)\n (setf (aref bs-plan i) a\n (aref bs-pos a) i))))\n (let ((ws-plan (make-wavelet 11 ws-plan))\n (bs-plan (make-wavelet 11 bs-plan)))\n (loop\n for x from 0 to n\n do (loop\n for y from 0 to n\n do (unless (= x y 0)\n (setf (aref dp x y)\n (min\n (if (zerop y)\n #xffffffff\n (let ((pos (aref bs-pos y)))\n (+ (aref dp x (- y 1))\n (wavelet-range-count ws-plan 0 (+ x 1) :start (+ pos 1))\n (wavelet-range-count bs-plan 0 y :start (+ pos 1))\n (wavelet-range-count ws-plan (+ x 1) 2001 :end pos)\n (wavelet-range-count bs-plan (+ y 1) 2001 :end pos))))\n (if (zerop x)\n #xffffffff\n (let ((pos (aref ws-pos x)))\n (+ (aref dp (- x 1) y)\n (wavelet-range-count ws-plan 0 x :start (+ pos 1))\n (wavelet-range-count bs-plan 0 (+ y 1) :start (+ pos 1))\n (wavelet-range-count ws-plan (+ x 1) 2001 :end pos)\n (wavelet-range-count bs-plan (+ y 1) 2001 :end pos))))))))))\n #>dp\n (println (floor (aref dp n n) 2))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\nB 1\nW 2\nB 3\nW 1\nW 3\nB 2\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\nB 4\nW 4\nB 3\nW 3\nB 2\nW 2\nB 1\nW 1\n\"\n \"18\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9\nW 3\nB 1\nB 4\nW 1\nB 5\nW 9\nW 2\nB 6\nW 5\nB 3\nW 8\nB 9\nW 7\nB 2\nB 8\nW 4\nW 6\nB 7\n\"\n \"41\n\")))\n", "language": "Lisp", "metadata": {"date": 1578826323, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03357.html", "problem_id": "p03357", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03357/input.txt", "sample_output_relpath": "derived/input_output/data/p03357/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03357/Lisp/s824224399.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s824224399", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Succinct bit vector\n;;;\n\n;; REVIEW: Is it really better to use the typical three-layer succint bit vector\n;; in competitive programming? It may be efficient to use a two-layer (not\n;; succinct but compact) bit vector preserving the original vector and the\n;; cumulative sum per 64-bit word.\n\n(defconstant +chunk-width+ (* 64 16))\n;; This constant cannot be changed as the current implementation depends on the\n;; assumption: +BLOCK-WIDTH+ is equal to the word size.\n(defconstant +block-width+ 64)\n(defconstant +block-number+ (floor +chunk-width+ +block-width+))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (assert (zerop (mod +chunk-width+ +block-width+)))\n (assert (= sb-vm:n-word-bits 64)))\n\n(defstruct (succinct-bit-vector (:constructor %make-sucbv (storage chunks blocks))\n (:conc-name sucbv-)\n (:copier nil))\n (storage nil :type simple-bit-vector)\n (chunks nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n (blocks nil :type (simple-array (unsigned-byte 16) (* *))))\n\n(defun make-sucbv! (vector)\n \"The consequence is undefined when VECTOR is modified after a succinct bit\nvector is created.\"\n (declare (optimize (speed 3)))\n (check-type vector simple-bit-vector)\n (let* ((vector (if (zerop (mod (length vector) +chunk-width+))\n vector\n (adjust-array vector\n (* +chunk-width+ (ceiling (length vector) +chunk-width+))\n :initial-element 0)))\n (len (length vector))\n (chunk-count (floor len +chunk-width+))\n (chunks (make-array (+ 1 chunk-count)\n :element-type '(integer 0 #.most-positive-fixnum)\n :initial-element 0))\n (blocks (make-array (list (+ 1 chunk-count) +block-number+)\n :element-type '(unsigned-byte 16)\n :initial-element 0))\n (sum 0))\n (declare (simple-bit-vector vector)\n ((integer 0 #.most-positive-fixnum) sum))\n (dotimes (i chunk-count)\n (setf (aref chunks i) sum)\n (let ((block-sum 0))\n (declare ((integer 0 #.most-positive-fixnum) block-sum))\n (dotimes (j +block-number+)\n (setf (aref blocks i j) block-sum)\n (incf block-sum\n (logcount (sb-kernel:%vector-raw-bits vector (+ (* i +block-number+) j)))))\n (incf sum block-sum)))\n (setf (aref chunks chunk-count) sum)\n (%make-sucbv vector chunks blocks)))\n\n(declaim (inline sucbv-ref))\n(defun sucbv-ref (sucbv index)\n (sbit (sucbv-storage sucbv) index))\n\n;; NOTE: No error handling.\n(declaim (inline sucbv-rank)\n (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) sucbv-rank))\n(defun sucbv-rank (sucbv end)\n \"Counts the number of 1's in the range [0, END).\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) end))\n (let ((storage (sucbv-storage sucbv))\n (chunks (sucbv-chunks sucbv))\n (blocks (sucbv-blocks sucbv)))\n (multiple-value-bind (cpos crem) (floor end +chunk-width+)\n (multiple-value-bind (bpos brem) (floor crem +block-width+)\n (let ((csum (aref chunks cpos))\n (bsum (aref blocks cpos bpos))\n (wordpos (floor end 64)))\n (+ csum\n bsum\n (if (zerop brem) ; avoid out-of-bounds access\n 0\n (logcount (ldb (byte brem 0)\n (sb-kernel:%vector-raw-bits storage wordpos))))))))))\n\n;;;\n;;; Wavelet matrix\n;;;\n\n(deftype wavelet-integer () '(integer 0 #.most-positive-fixnum))\n\n(defstruct (wavelet-matrix (:constructor %make-wavelet-matrix\n (length data zeros\n &aux (depth (array-dimension data 0))))\n (:copier nil)\n (:conc-name wavelet-))\n (depth 0 :type (integer 1 #.most-positive-fixnum))\n (length 0 :type (integer 0 #.most-positive-fixnum))\n (data nil :type (simple-array succinct-bit-vector (*)))\n (zeros nil :type (simple-array (integer 0 #.most-positive-fixnum) (*))))\n\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:defknown make-wavelet ((integer 1 #.most-positive-fixnum) vector)\n wavelet-matrix (sb-c:flushable)\n :overwrite-fndb-silently t))\n\n;; TODO: add deftransform for better type derivation\n(defun make-wavelet (bit-depth vector)\n (declare ((integer 1 #.most-positive-fixnum) bit-depth))\n (let* ((len (length vector))\n (fitted-len (* +chunk-width+ (ceiling len +chunk-width+)))\n (data (locally (declare #+sbcl (muffle-conditions style-warning))\n (make-array bit-depth :element-type 'succinct-bit-vector)))\n (zeros (make-array bit-depth :element-type '(integer 0 #.most-positive-fixnum)))\n (tmp (copy-seq vector))\n (lefts (make-array len :element-type (array-element-type vector)))\n (rights (make-array len :element-type (array-element-type vector)))\n (bits (make-array fitted-len :element-type 'bit)))\n (declare ((integer 0 #.most-positive-fixnum) len fitted-len)\n (vector tmp))\n (loop for d from (- bit-depth 1) downto 0\n do (let ((lpos 0)\n (rpos 0))\n (declare ((integer 0 #.most-positive-fixnum) lpos rpos))\n (dotimes (i len)\n (let ((bit (logand 1 (ash (aref tmp i) (- d)))))\n (if (zerop bit)\n (setf (aref lefts lpos) (aref tmp i)\n lpos (+ lpos 1))\n (setf (aref rights rpos) (aref tmp i)\n rpos (+ rpos 1)))\n (setf (aref bits i) bit)))\n (setf (aref data d) (make-sucbv! (copy-seq bits))\n (aref zeros d) lpos)\n (rotatef lefts tmp)\n (replace tmp rights :start1 lpos :end2 rpos)))\n (%make-wavelet-matrix len data zeros)))\n\n(define-condition invalid-wavelet-index-error (type-error)\n ((wavelet :initarg :wavelet :reader invalid-wavelet-index-error-wavelet)\n (index :initarg :index :reader invalid-wavelet-index-error-index))\n (:report\n (lambda (condition stream)\n (let ((index (invalid-wavelet-index-error-index condition)))\n (if (consp index)\n (format stream \"Invalid range [~W, ~W) for wavelet-matrix ~W.\"\n (car index)\n (cdr index)\n (invalid-wavelet-index-error-wavelet condition))\n (format stream \"Invalid index ~W for wavelet-matrix ~W.\"\n index\n (invalid-wavelet-index-error-wavelet condition)))))))\n\n(declaim (ftype (function * (values (unsigned-byte 31) &optional)) wavelet-range-count))\n(defun wavelet-range-count (wmatrix lo hi &key (start 0) end)\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) lo hi start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (let ((data (wavelet-data wmatrix))\n (zeros (wavelet-zeros wmatrix))\n (end (or end (wavelet-length wmatrix))))\n (labels\n ((dfs (depth start end value)\n (declare ((integer 0 #.most-positive-fixnum) start end value)\n ((integer -1 #.most-positive-fixnum) depth)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (cond ((or (= start end)\n (<= hi value))\n 0)\n ((= depth -1)\n (if (< value lo)\n 0\n (- end start)))\n (t\n (let* ((next-value (logior value\n (the wavelet-integer (ash 1 depth))))\n (upper-bound (logior next-value\n (- (the wavelet-integer (ash 1 depth)) 1))))\n (cond ((< upper-bound lo)\n 0)\n ((and (<= lo value) (< upper-bound hi))\n (- end start))\n (t\n (let ((lcount (sucbv-rank (aref data depth) start))\n (rcount (sucbv-rank (aref data depth) end)))\n (+ (dfs (- depth 1)\n (- start lcount)\n (- end rcount)\n value)\n (dfs (- depth 1)\n (+ (aref zeros depth) lcount)\n (+ (aref zeros depth) rcount)\n next-value))))))))))\n (dfs (- (wavelet-depth wmatrix) 1) start end 0))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ (- (expt 2 11) 1))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (ws-plan (make-array (* 2 n) :element-type 'uint16 :initial-element +inf+))\n (bs-plan (make-array (* 2 n) :element-type 'uint16 :initial-element +inf+))\n (ws-pos (make-array (+ n 1) :element-type 'uint16))\n (bs-pos (make-array (+ n 1) :element-type 'uint16))\n (dp (make-array (list (+ n 1) (+ n 1))\n :element-type 'uint32\n :initial-element 0)))\n (declare (uint16 n))\n (dotimes (i (* 2 n))\n (let ((col (read))\n (a (read)))\n (if (eql col 'w)\n (setf (aref ws-plan i) a\n (aref ws-pos a) i)\n (setf (aref bs-plan i) a\n (aref bs-pos a) i))))\n (let ((ws-plan (make-wavelet 11 ws-plan))\n (bs-plan (make-wavelet 11 bs-plan)))\n (loop\n for x from 0 to n\n do (loop\n for y from 0 to n\n do (unless (= x y 0)\n (setf (aref dp x y)\n (min\n (if (zerop y)\n #xffffffff\n (let ((pos (aref bs-pos y)))\n (+ (aref dp x (- y 1))\n (wavelet-range-count ws-plan 0 (+ x 1) :start (+ pos 1))\n (wavelet-range-count bs-plan 0 y :start (+ pos 1))\n (wavelet-range-count ws-plan (+ x 1) 2001 :end pos)\n (wavelet-range-count bs-plan (+ y 1) 2001 :end pos))))\n (if (zerop x)\n #xffffffff\n (let ((pos (aref ws-pos x)))\n (+ (aref dp (- x 1) y)\n (wavelet-range-count ws-plan 0 x :start (+ pos 1))\n (wavelet-range-count bs-plan 0 (+ y 1) :start (+ pos 1))\n (wavelet-range-count ws-plan (+ x 1) 2001 :end pos)\n (wavelet-range-count bs-plan (+ y 1) 2001 :end pos))))))))))\n #>dp\n (println (floor (aref dp n n) 2))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\nB 1\nW 2\nB 3\nW 1\nW 3\nB 2\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\nB 4\nW 4\nB 3\nW 3\nB 2\nW 2\nB 1\nW 1\n\"\n \"18\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9\nW 3\nB 1\nB 4\nW 1\nB 5\nW 9\nW 2\nB 6\nW 5\nB 3\nW 8\nB 9\nW 7\nB 2\nB 8\nW 4\nW 6\nB 7\n\"\n \"41\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball.\nThe integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i.\nc_i = W represents the ball is white; c_i = B represents the ball is black.\n\nTakahashi the human wants to achieve the following objective:\n\nFor every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it.\n\nFor every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it.\n\nIn order to achieve this, he can perform the following operation:\n\nSwap two adjacent balls.\n\nFind the minimum number of operations required to achieve the objective.\n\nConstraints\n\n1 ≤ N ≤ 2000\n\n1 ≤ a_i ≤ N\n\nc_i = W or c_i = B.\n\nIf i ≠ j, (a_i,c_i) ≠ (a_j,c_j).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nc_1 a_1\nc_2 a_2\n:\nc_{2N} a_{2N}\n\nOutput\n\nPrint the minimum number of operations required to achieve the objective.\n\nSample Input 1\n\n3\nB 1\nW 2\nB 3\nW 1\nW 3\nB 2\n\nSample Output 1\n\n4\n\nThe objective can be achieved in four operations, for example, as follows:\n\nSwap the black 3 and white 1.\n\nSwap the white 1 and white 2.\n\nSwap the black 3 and white 3.\n\nSwap the black 3 and black 2.\n\nSample Input 2\n\n4\nB 4\nW 4\nB 3\nW 3\nB 2\nW 2\nB 1\nW 1\n\nSample Output 2\n\n18\n\nSample Input 3\n\n9\nW 3\nB 1\nB 4\nW 1\nB 5\nW 9\nW 2\nB 6\nW 5\nB 3\nW 8\nB 9\nW 7\nB 2\nB 8\nW 4\nW 6\nB 7\n\nSample Output 3\n\n41", "sample_input": "3\nB 1\nW 2\nB 3\nW 1\nW 3\nB 2\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03357", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball.\nThe integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i.\nc_i = W represents the ball is white; c_i = B represents the ball is black.\n\nTakahashi the human wants to achieve the following objective:\n\nFor every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it.\n\nFor every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it.\n\nIn order to achieve this, he can perform the following operation:\n\nSwap two adjacent balls.\n\nFind the minimum number of operations required to achieve the objective.\n\nConstraints\n\n1 ≤ N ≤ 2000\n\n1 ≤ a_i ≤ N\n\nc_i = W or c_i = B.\n\nIf i ≠ j, (a_i,c_i) ≠ (a_j,c_j).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nc_1 a_1\nc_2 a_2\n:\nc_{2N} a_{2N}\n\nOutput\n\nPrint the minimum number of operations required to achieve the objective.\n\nSample Input 1\n\n3\nB 1\nW 2\nB 3\nW 1\nW 3\nB 2\n\nSample Output 1\n\n4\n\nThe objective can be achieved in four operations, for example, as follows:\n\nSwap the black 3 and white 1.\n\nSwap the white 1 and white 2.\n\nSwap the black 3 and white 3.\n\nSwap the black 3 and black 2.\n\nSample Input 2\n\n4\nB 4\nW 4\nB 3\nW 3\nB 2\nW 2\nB 1\nW 1\n\nSample Output 2\n\n18\n\nSample Input 3\n\n9\nW 3\nB 1\nB 4\nW 1\nB 5\nW 9\nW 2\nB 6\nW 5\nB 3\nW 8\nB 9\nW 7\nB 2\nB 8\nW 4\nW 6\nB 7\n\nSample Output 3\n\n41", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 14904, "cpu_time_ms": 2105, "memory_kb": 56036}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s752650537", "group_id": "codeNet:p03359", "input_text": "(princ (min (read) (read)))\n", "language": "Lisp", "metadata": {"date": 1576897602, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03359.html", "problem_id": "p03359", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03359/input.txt", "sample_output_relpath": "derived/input_output/data/p03359/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03359/Lisp/s752650537.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s752650537", "user_id": "u493610446"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(princ (min (read) (read)))\n", "problem_context": "Score: 100 points\n\nProblem Statement\n\nIn AtCoder Kingdom, Gregorian calendar is used, and dates are written in the \"year-month-day\" order, or the \"month-day\" order without the year.\n\nFor example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.\n\nIn this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.\n\nHow many days from 2018-1-1 through 2018-a-b are Takahashi?\n\nConstraints\n\na is an integer between 1 and 12 (inclusive).\n\nb is an integer between 1 and 31 (inclusive).\n\n2018-a-b is a valid date in Gregorian calendar.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nPrint the number of days from 2018-1-1 through 2018-a-b that are Takahashi.\n\nSample Input 1\n\n5 5\n\nSample Output 1\n\n5\n\nThere are five days that are Takahashi: 1-1, 2-2, 3-3, 4-4 and 5-5.\n\nSample Input 2\n\n2 1\n\nSample Output 2\n\n1\n\nThere is only one day that is Takahashi: 1-1.\n\nSample Input 3\n\n11 30\n\nSample Output 3\n\n11\n\nThere are eleven days that are Takahashi: 1-1, 2-2, 3-3, 4-4, 5-5, 6-6, 7-7, 8-8, 9-9, 10-10 and 11-11.", "sample_input": "5 5\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03359", "source_text": "Score: 100 points\n\nProblem Statement\n\nIn AtCoder Kingdom, Gregorian calendar is used, and dates are written in the \"year-month-day\" order, or the \"month-day\" order without the year.\n\nFor example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.\n\nIn this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.\n\nHow many days from 2018-1-1 through 2018-a-b are Takahashi?\n\nConstraints\n\na is an integer between 1 and 12 (inclusive).\n\nb is an integer between 1 and 31 (inclusive).\n\n2018-a-b is a valid date in Gregorian calendar.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nPrint the number of days from 2018-1-1 through 2018-a-b that are Takahashi.\n\nSample Input 1\n\n5 5\n\nSample Output 1\n\n5\n\nThere are five days that are Takahashi: 1-1, 2-2, 3-3, 4-4 and 5-5.\n\nSample Input 2\n\n2 1\n\nSample Output 2\n\n1\n\nThere is only one day that is Takahashi: 1-1.\n\nSample Input 3\n\n11 30\n\nSample Output 3\n\n11\n\nThere are eleven days that are Takahashi: 1-1, 2-2, 3-3, 4-4, 5-5, 6-6, 7-7, 8-8, 9-9, 10-10 and 11-11.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 28, "cpu_time_ms": 5, "memory_kb": 2792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s253904032", "group_id": "codeNet:p03359", "input_text": "(defun taka (a b)\n (if (> a b)\n (1- a)\n a)))\n(format t \"~A~%\" (taka (read) (read)))", "language": "Lisp", "metadata": {"date": 1573537206, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03359.html", "problem_id": "p03359", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03359/input.txt", "sample_output_relpath": "derived/input_output/data/p03359/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03359/Lisp/s253904032.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s253904032", "user_id": "u672956630"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defun taka (a b)\n (if (> a b)\n (1- a)\n a)))\n(format t \"~A~%\" (taka (read) (read)))", "problem_context": "Score: 100 points\n\nProblem Statement\n\nIn AtCoder Kingdom, Gregorian calendar is used, and dates are written in the \"year-month-day\" order, or the \"month-day\" order without the year.\n\nFor example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.\n\nIn this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.\n\nHow many days from 2018-1-1 through 2018-a-b are Takahashi?\n\nConstraints\n\na is an integer between 1 and 12 (inclusive).\n\nb is an integer between 1 and 31 (inclusive).\n\n2018-a-b is a valid date in Gregorian calendar.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nPrint the number of days from 2018-1-1 through 2018-a-b that are Takahashi.\n\nSample Input 1\n\n5 5\n\nSample Output 1\n\n5\n\nThere are five days that are Takahashi: 1-1, 2-2, 3-3, 4-4 and 5-5.\n\nSample Input 2\n\n2 1\n\nSample Output 2\n\n1\n\nThere is only one day that is Takahashi: 1-1.\n\nSample Input 3\n\n11 30\n\nSample Output 3\n\n11\n\nThere are eleven days that are Takahashi: 1-1, 2-2, 3-3, 4-4, 5-5, 6-6, 7-7, 8-8, 9-9, 10-10 and 11-11.", "sample_input": "5 5\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03359", "source_text": "Score: 100 points\n\nProblem Statement\n\nIn AtCoder Kingdom, Gregorian calendar is used, and dates are written in the \"year-month-day\" order, or the \"month-day\" order without the year.\n\nFor example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.\n\nIn this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.\n\nHow many days from 2018-1-1 through 2018-a-b are Takahashi?\n\nConstraints\n\na is an integer between 1 and 12 (inclusive).\n\nb is an integer between 1 and 31 (inclusive).\n\n2018-a-b is a valid date in Gregorian calendar.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nPrint the number of days from 2018-1-1 through 2018-a-b that are Takahashi.\n\nSample Input 1\n\n5 5\n\nSample Output 1\n\n5\n\nThere are five days that are Takahashi: 1-1, 2-2, 3-3, 4-4 and 5-5.\n\nSample Input 2\n\n2 1\n\nSample Output 2\n\n1\n\nThere is only one day that is Takahashi: 1-1.\n\nSample Input 3\n\n11 30\n\nSample Output 3\n\n11\n\nThere are eleven days that are Takahashi: 1-1, 2-2, 3-3, 4-4, 5-5, 6-6, 7-7, 8-8, 9-9, 10-10 and 11-11.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 94, "cpu_time_ms": 160, "memory_kb": 14304}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s251564799", "group_id": "codeNet:p03360", "input_text": "(let ((lst (sort (list (read) (read) (read)) #'>)))\n (push (* (pop lst) (expt 2 (read))) lst)\n (format t \"~A\" (reduce #'+ lst)))", "language": "Lisp", "metadata": {"date": 1539901638, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03360.html", "problem_id": "p03360", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03360/input.txt", "sample_output_relpath": "derived/input_output/data/p03360/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03360/Lisp/s251564799.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s251564799", "user_id": "u610490393"}, "prompt_components": {"gold_output": "30\n", "input_to_evaluate": "(let ((lst (sort (list (read) (read) (read)) #'>)))\n (push (* (pop lst) (expt 2 (read))) lst)\n (format t \"~A\" (reduce #'+ lst)))", "problem_context": "Score: 200 points\n\nProblem Statement\n\nThere are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:\n\nChoose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.\n\nWhat is the largest possible sum of the integers written on the blackboard after K operations?\n\nConstraints\n\nA, B and C are integers between 1 and 50 (inclusive).\n\nK is an integer between 1 and 10 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\nK\n\nOutput\n\nPrint the largest possible sum of the integers written on the blackboard after K operations by E869220.\n\nSample Input 1\n\n5 3 11\n1\n\nSample Output 1\n\n30\n\nIn this sample, 5, 3, 11 are initially written on the blackboard, and E869120 can perform the operation once.\n\nThere are three choices:\n\nDouble 5: The integers written on the board after the operation are 10, 3, 11.\n\nDouble 3: The integers written on the board after the operation are 5, 6, 11.\n\nDouble 11: The integers written on the board after the operation are 5, 3, 22.\n\nIf he chooses 3., the sum of the integers written on the board afterwards is 5 + 3 + 22 = 30, which is the largest among 1. through 3.\n\nSample Input 2\n\n3 3 4\n2\n\nSample Output 2\n\n22\n\nE869120 can perform the operation twice. The sum of the integers eventually written on the blackboard is maximized as follows:\n\nFirst, double 4. The integers written on the board are now 3, 3, 8.\n\nNext, double 8. The integers written on the board are now 3, 3, 16.\n\nThen, the sum of the integers eventually written on the blackboard is 3 + 3 + 16 = 22.", "sample_input": "5 3 11\n1\n"}, "reference_outputs": ["30\n"], "source_document_id": "p03360", "source_text": "Score: 200 points\n\nProblem Statement\n\nThere are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:\n\nChoose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.\n\nWhat is the largest possible sum of the integers written on the blackboard after K operations?\n\nConstraints\n\nA, B and C are integers between 1 and 50 (inclusive).\n\nK is an integer between 1 and 10 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\nK\n\nOutput\n\nPrint the largest possible sum of the integers written on the blackboard after K operations by E869220.\n\nSample Input 1\n\n5 3 11\n1\n\nSample Output 1\n\n30\n\nIn this sample, 5, 3, 11 are initially written on the blackboard, and E869120 can perform the operation once.\n\nThere are three choices:\n\nDouble 5: The integers written on the board after the operation are 10, 3, 11.\n\nDouble 3: The integers written on the board after the operation are 5, 6, 11.\n\nDouble 11: The integers written on the board after the operation are 5, 3, 22.\n\nIf he chooses 3., the sum of the integers written on the board afterwards is 5 + 3 + 22 = 30, which is the largest among 1. through 3.\n\nSample Input 2\n\n3 3 4\n2\n\nSample Output 2\n\n22\n\nE869120 can perform the operation twice. The sum of the integers eventually written on the blackboard is maximized as follows:\n\nFirst, double 4. The integers written on the board are now 3, 3, 8.\n\nNext, double 8. The integers written on the board are now 3, 3, 16.\n\nThen, the sum of the integers eventually written on the blackboard is 3 + 3 + 16 = 22.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 136, "cpu_time_ms": 24, "memory_kb": 4320}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s246034436", "group_id": "codeNet:p03360", "input_text": "(defun pow (x n)\n (if (= n 0)\n 1\n (* x (pow x (1- n)))))\n\n\n(let (\n\t\t(a (read))\n\t\t(b (read))\n\t\t(c (read))\n\t\t(k (read))\n\t\t(maxvalue 0)\n\t\t(shit 0))\n\t(setf maxvalue (max a b c))\n\t(setf shit (- (+ a b c) maxvalue))\n\t(setf maxvalue (* maxvalue (pow 2 k)))\n\t(format t \"~D~%\" (+ shit maxvalue)))", "language": "Lisp", "metadata": {"date": 1525570659, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03360.html", "problem_id": "p03360", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03360/input.txt", "sample_output_relpath": "derived/input_output/data/p03360/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03360/Lisp/s246034436.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s246034436", "user_id": "u143397629"}, "prompt_components": {"gold_output": "30\n", "input_to_evaluate": "(defun pow (x n)\n (if (= n 0)\n 1\n (* x (pow x (1- n)))))\n\n\n(let (\n\t\t(a (read))\n\t\t(b (read))\n\t\t(c (read))\n\t\t(k (read))\n\t\t(maxvalue 0)\n\t\t(shit 0))\n\t(setf maxvalue (max a b c))\n\t(setf shit (- (+ a b c) maxvalue))\n\t(setf maxvalue (* maxvalue (pow 2 k)))\n\t(format t \"~D~%\" (+ shit maxvalue)))", "problem_context": "Score: 200 points\n\nProblem Statement\n\nThere are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:\n\nChoose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.\n\nWhat is the largest possible sum of the integers written on the blackboard after K operations?\n\nConstraints\n\nA, B and C are integers between 1 and 50 (inclusive).\n\nK is an integer between 1 and 10 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\nK\n\nOutput\n\nPrint the largest possible sum of the integers written on the blackboard after K operations by E869220.\n\nSample Input 1\n\n5 3 11\n1\n\nSample Output 1\n\n30\n\nIn this sample, 5, 3, 11 are initially written on the blackboard, and E869120 can perform the operation once.\n\nThere are three choices:\n\nDouble 5: The integers written on the board after the operation are 10, 3, 11.\n\nDouble 3: The integers written on the board after the operation are 5, 6, 11.\n\nDouble 11: The integers written on the board after the operation are 5, 3, 22.\n\nIf he chooses 3., the sum of the integers written on the board afterwards is 5 + 3 + 22 = 30, which is the largest among 1. through 3.\n\nSample Input 2\n\n3 3 4\n2\n\nSample Output 2\n\n22\n\nE869120 can perform the operation twice. The sum of the integers eventually written on the blackboard is maximized as follows:\n\nFirst, double 4. The integers written on the board are now 3, 3, 8.\n\nNext, double 8. The integers written on the board are now 3, 3, 16.\n\nThen, the sum of the integers eventually written on the blackboard is 3 + 3 + 16 = 22.", "sample_input": "5 3 11\n1\n"}, "reference_outputs": ["30\n"], "source_document_id": "p03360", "source_text": "Score: 200 points\n\nProblem Statement\n\nThere are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:\n\nChoose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.\n\nWhat is the largest possible sum of the integers written on the blackboard after K operations?\n\nConstraints\n\nA, B and C are integers between 1 and 50 (inclusive).\n\nK is an integer between 1 and 10 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\nK\n\nOutput\n\nPrint the largest possible sum of the integers written on the blackboard after K operations by E869220.\n\nSample Input 1\n\n5 3 11\n1\n\nSample Output 1\n\n30\n\nIn this sample, 5, 3, 11 are initially written on the blackboard, and E869120 can perform the operation once.\n\nThere are three choices:\n\nDouble 5: The integers written on the board after the operation are 10, 3, 11.\n\nDouble 3: The integers written on the board after the operation are 5, 6, 11.\n\nDouble 11: The integers written on the board after the operation are 5, 3, 22.\n\nIf he chooses 3., the sum of the integers written on the board afterwards is 5 + 3 + 22 = 30, which is the largest among 1. through 3.\n\nSample Input 2\n\n3 3 4\n2\n\nSample Output 2\n\n22\n\nE869120 can perform the operation twice. The sum of the integers eventually written on the blackboard is maximized as follows:\n\nFirst, double 4. The integers written on the board are now 3, 3, 8.\n\nNext, double 8. The integers written on the board are now 3, 3, 16.\n\nThen, the sum of the integers eventually written on the blackboard is 3 + 3 + 16 = 22.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 304, "cpu_time_ms": 145, "memory_kb": 14692}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s655714226", "group_id": "codeNet:p03361", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"256MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun range-0-n (n &optional (step 1))\n (loop for i from 0 below n by step collect i))\n\n(defun range-1-n (n &optional (step 1))\n (loop for i from 1 below n by step collect i))\n\n(defun range-a-b (a b &optional (step 1))\n (loop for i from a below b by step collect i))\n\n(defun map-0-n (function n &optional (step 1))\n (mapcar function (range-0-n n step)))\n\n(defun map-1-n (function n &optional (step 1))\n (mapcar function (range-1-n n step)))\n\n(defun map-a-b (function a b &optional (step 1))\n (mapcar function (range-a-b a b step)))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (and result (is-empty char))\n do (return (concatenate 'string (nreverse result)))\n when (null (is-empty char))\n do (push char result))))\n\n(defun merge-sort (lst &optional (compare #'<))\n (let ((turn 0))\n (labels ((merge-list (a b a-length b-length)\n (cond ((zerop a-length) b)\n ((zerop b-length) a)\n ((funcall compare (car b) (car a))\n (incf turn a-length)\n (cons (car b)\n (merge-list a (cdr b) a-length (1- b-length))))\n (t\n (cons (car a)\n (merge-list (cdr a) b (1- a-length) b-length)))))\n (f (lst length)\n (if (= length 1)\n lst\n (let ((mid (ash length -1)))\n (merge-list (f (subseq lst 0 mid) mid)\n (f (subseq lst mid) (- length mid))\n mid\n (- length mid))))))\n (values (f lst (length lst)) turn))))\n\n(defun group (lst &optional (test #'eql) (key nil))\n (let ((table (make-hash-table :test test)))\n (mapc (lambda (x)\n (push x (gethash (if key (funcall key x) x) table)))\n lst)\n (loop for value being each hash-value in table\n collect value)))\n\n(defun nearby (&rest args)\n (let ((current (subseq args 0 (ash (length args) -1)))\n (validator (subseq args (ash (length args) -1)))\n (res nil))\n (labels ((check (pos)\n (every (lambda (x y) (and (<= 0 x) (< x y)))\n pos validator))\n (f (lst)\n (unless lst (return-from f))\n (incf (car lst))\n (when (check lst) (push (copy-list current) res))\n (decf (car lst) 2)\n (when (check lst) (push (copy-list current) res))\n (incf (car lst))\n (f (cdr lst))))\n (f current)\n res)))\n\n\n\n(defun main (h w map)\n (every\n (lambda (y)\n (every\n (lambda (x)\n (or (char= (aref map y x) #\\.)\n (some (lambda (pos)\n (char= (aref map (nth 0 pos) (nth 1 pos)) #\\#))\n (nearby y x h w))))\n (range-0-n w)))\n (range-0-n h)))\n\n\n(let ((h (read))\n (w (read)))\n (format t \"~a~%\"\n (if (main h w\n (make-array\n (list h w)\n :initial-contents (collect-times h (read-line))))\n \"Yes\"\n \"No\")))\n", "language": "Lisp", "metadata": {"date": 1589582964, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03361.html", "problem_id": "p03361", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03361/input.txt", "sample_output_relpath": "derived/input_output/data/p03361/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03361/Lisp/s655714226.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s655714226", "user_id": "u493610446"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n \"I refered from https://competitive12.blogspot.com/2020/03/common-lisp.html thank you!\"\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"256MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun range-0-n (n &optional (step 1))\n (loop for i from 0 below n by step collect i))\n\n(defun range-1-n (n &optional (step 1))\n (loop for i from 1 below n by step collect i))\n\n(defun range-a-b (a b &optional (step 1))\n (loop for i from a below b by step collect i))\n\n(defun map-0-n (function n &optional (step 1))\n (mapcar function (range-0-n n step)))\n\n(defun map-1-n (function n &optional (step 1))\n (mapcar function (range-1-n n step)))\n\n(defun map-a-b (function a b &optional (step 1))\n (mapcar function (range-a-b a b step)))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (and result (is-empty char))\n do (return (concatenate 'string (nreverse result)))\n when (null (is-empty char))\n do (push char result))))\n\n(defun merge-sort (lst &optional (compare #'<))\n (let ((turn 0))\n (labels ((merge-list (a b a-length b-length)\n (cond ((zerop a-length) b)\n ((zerop b-length) a)\n ((funcall compare (car b) (car a))\n (incf turn a-length)\n (cons (car b)\n (merge-list a (cdr b) a-length (1- b-length))))\n (t\n (cons (car a)\n (merge-list (cdr a) b (1- a-length) b-length)))))\n (f (lst length)\n (if (= length 1)\n lst\n (let ((mid (ash length -1)))\n (merge-list (f (subseq lst 0 mid) mid)\n (f (subseq lst mid) (- length mid))\n mid\n (- length mid))))))\n (values (f lst (length lst)) turn))))\n\n(defun group (lst &optional (test #'eql) (key nil))\n (let ((table (make-hash-table :test test)))\n (mapc (lambda (x)\n (push x (gethash (if key (funcall key x) x) table)))\n lst)\n (loop for value being each hash-value in table\n collect value)))\n\n(defun nearby (&rest args)\n (let ((current (subseq args 0 (ash (length args) -1)))\n (validator (subseq args (ash (length args) -1)))\n (res nil))\n (labels ((check (pos)\n (every (lambda (x y) (and (<= 0 x) (< x y)))\n pos validator))\n (f (lst)\n (unless lst (return-from f))\n (incf (car lst))\n (when (check lst) (push (copy-list current) res))\n (decf (car lst) 2)\n (when (check lst) (push (copy-list current) res))\n (incf (car lst))\n (f (cdr lst))))\n (f current)\n res)))\n\n\n\n(defun main (h w map)\n (every\n (lambda (y)\n (every\n (lambda (x)\n (or (char= (aref map y x) #\\.)\n (some (lambda (pos)\n (char= (aref map (nth 0 pos) (nth 1 pos)) #\\#))\n (nearby y x h w))))\n (range-0-n w)))\n (range-0-n h)))\n\n\n(let ((h (read))\n (w (read)))\n (format t \"~a~%\"\n (if (main h w\n (make-array\n (list h w)\n :initial-contents (collect-times h (read-line))))\n \"Yes\"\n \"No\")))\n", "problem_context": "Score: 300 points\n\nProblem Statement\n\nWe have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).\n\nInitially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= #, and to make Square (i, j) white when s_{i, j}= ..\n\nHowever, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.\n\nDetermine if square1001 can achieve his objective.\n\nConstraints\n\nH is an integer between 1 and 50 (inclusive).\n\nW is an integer between 1 and 50 (inclusive).\n\nFor every (i, j) (1 \\leq i \\leq H, 1 \\leq j \\leq W), s_{i, j} is # or ..\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\ns_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}\ns_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}\n: :\ns_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}\n\nOutput\n\nIf square1001 can achieve his objective, print Yes; if he cannot, print No.\n\nSample Input 1\n\n3 3\n.#.\n###\n.#.\n\nSample Output 1\n\nYes\n\nOne possible way to achieve the objective is shown in the figure below. Here, the squares being painted are marked by stars.\n\nSample Input 2\n\n5 5\n#.#.#\n.#.#.\n#.#.#\n.#.#.\n#.#.#\n\nSample Output 2\n\nNo\n\nsquare1001 cannot achieve his objective here.\n\nSample Input 3\n\n11 11\n...#####...\n.##.....##.\n#..##.##..#\n#..##.##..#\n#.........#\n#...###...#\n.#########.\n.#.#.#.#.#.\n##.#.#.#.##\n..##.#.##..\n.##..#..##.\n\nSample Output 3\n\nYes", "sample_input": "3 3\n.#.\n###\n.#.\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03361", "source_text": "Score: 300 points\n\nProblem Statement\n\nWe have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).\n\nInitially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= #, and to make Square (i, j) white when s_{i, j}= ..\n\nHowever, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.\n\nDetermine if square1001 can achieve his objective.\n\nConstraints\n\nH is an integer between 1 and 50 (inclusive).\n\nW is an integer between 1 and 50 (inclusive).\n\nFor every (i, j) (1 \\leq i \\leq H, 1 \\leq j \\leq W), s_{i, j} is # or ..\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\ns_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}\ns_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}\n: :\ns_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}\n\nOutput\n\nIf square1001 can achieve his objective, print Yes; if he cannot, print No.\n\nSample Input 1\n\n3 3\n.#.\n###\n.#.\n\nSample Output 1\n\nYes\n\nOne possible way to achieve the objective is shown in the figure below. Here, the squares being painted are marked by stars.\n\nSample Input 2\n\n5 5\n#.#.#\n.#.#.\n#.#.#\n.#.#.\n#.#.#\n\nSample Output 2\n\nNo\n\nsquare1001 cannot achieve his objective here.\n\nSample Input 3\n\n11 11\n...#####...\n.##.....##.\n#..##.##..#\n#..##.##..#\n#.........#\n#...###...#\n.#########.\n.#.#.#.#.#.\n##.#.#.#.##\n..##.#.##..\n.##..#..##.\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5467, "cpu_time_ms": 297, "memory_kb": 64056}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s789518724", "group_id": "codeNet:p03362", "input_text": "(setf *random-state* (make-random-state t))\n\n(defun primep (n)\n (cond\n ((or (= n 2) (= n 3)) t)\n ((or (< n 2) (evenp n)) nil)\n ((loop for i from 3 by 2\n when (> (expt i 2) n) return t\n when (zerop (mod n i)) return nil))))\n\n(defun prime-sieve (end)\n (let ((array (make-array (1+ end) :initial-element t)) (primes nil))\n (loop for i from 2 to end do\n (when (svref array i) (push i primes)\n (loop for j from (* i 2) to end by i do\n (setf (svref array j) nil))))\n (coerce (reverse primes) 'vector)))\n\n(defun not-solve-p (a b c d e)\n (primep (+ a b c d e)))\n\n(defun solver ()\n (let* ((n (read))\n (primes (prime-sieve 55555))\n (vec (make-array n)))\n (setf (svref vec 0) 2)\n (loop do\n (loop for i fixnum from 1 below n do\n (setf (svref vec i) (svref primes (random 5637))))\n (loop named inner repeat (expt n 4) do\n (when (not-solve-p (svref vec (random n))\n (svref vec (random n))\n (svref vec (random n))\n (svref vec (random n))\n (svref vec (random n)))\n (return-from inner)))\n (return-from solver (format t \"~{~A ~^~}~%\" (coerce vec 'list))))))\n\n(solver)\n", "language": "Lisp", "metadata": {"date": 1525574283, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03362.html", "problem_id": "p03362", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03362/input.txt", "sample_output_relpath": "derived/input_output/data/p03362/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03362/Lisp/s789518724.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s789518724", "user_id": "u183015556"}, "prompt_components": {"gold_output": "3 5 7 11 31\n", "input_to_evaluate": "(setf *random-state* (make-random-state t))\n\n(defun primep (n)\n (cond\n ((or (= n 2) (= n 3)) t)\n ((or (< n 2) (evenp n)) nil)\n ((loop for i from 3 by 2\n when (> (expt i 2) n) return t\n when (zerop (mod n i)) return nil))))\n\n(defun prime-sieve (end)\n (let ((array (make-array (1+ end) :initial-element t)) (primes nil))\n (loop for i from 2 to end do\n (when (svref array i) (push i primes)\n (loop for j from (* i 2) to end by i do\n (setf (svref array j) nil))))\n (coerce (reverse primes) 'vector)))\n\n(defun not-solve-p (a b c d e)\n (primep (+ a b c d e)))\n\n(defun solver ()\n (let* ((n (read))\n (primes (prime-sieve 55555))\n (vec (make-array n)))\n (setf (svref vec 0) 2)\n (loop do\n (loop for i fixnum from 1 below n do\n (setf (svref vec i) (svref primes (random 5637))))\n (loop named inner repeat (expt n 4) do\n (when (not-solve-p (svref vec (random n))\n (svref vec (random n))\n (svref vec (random n))\n (svref vec (random n))\n (svref vec (random n)))\n (return-from inner)))\n (return-from solver (format t \"~{~A ~^~}~%\" (coerce vec 'list))))))\n\n(solver)\n", "problem_context": "Score: 400 points\n\nProblem Statement\n\nPrint a sequence a_1, a_2, ..., a_N whose length is N that satisfies the following conditions:\n\na_i (1 \\leq i \\leq N) is a prime number at most 55 555.\n\nThe values of a_1, a_2, ..., a_N are all different.\n\nIn every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.\n\nIf there are multiple such sequences, printing any of them is accepted.\n\nNotes\n\nAn integer N not less than 2 is called a prime number if it cannot be divided evenly by any integers except 1 and N, and called a composite number otherwise.\n\nConstraints\n\nN is an integer between 5 and 55 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.\n\nSample Input 1\n\n5\n\nSample Output 1\n\n3 5 7 11 31\n\nLet us see if this output actually satisfies the conditions.\n\nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime numbers.\n\nThe only way to choose five among them is to choose all of them, whose sum is a_1+a_2+a_3+a_4+a_5=57, which is a composite number.\n\nThere are also other possible outputs, such as 2 3 5 7 13, 11 13 17 19 31 and 7 11 5 31 3.\n\nSample Input 2\n\n6\n\nSample Output 2\n\n2 3 5 7 11 13\n\n2, 3, 5, 7, 11, 13 are all different prime numbers.\n\n2+3+5+7+11=28 is a composite number.\n\n2+3+5+7+13=30 is a composite number.\n\n2+3+5+11+13=34 is a composite number.\n\n2+3+7+11+13=36 is a composite number.\n\n2+5+7+11+13=38 is a composite number.\n\n3+5+7+11+13=39 is a composite number.\n\nThus, the sequence 2 3 5 7 11 13 satisfies the conditions.\n\nSample Input 3\n\n8\n\nSample Output 3\n\n2 5 7 13 19 37 67 79", "sample_input": "5\n"}, "reference_outputs": ["3 5 7 11 31\n"], "source_document_id": "p03362", "source_text": "Score: 400 points\n\nProblem Statement\n\nPrint a sequence a_1, a_2, ..., a_N whose length is N that satisfies the following conditions:\n\na_i (1 \\leq i \\leq N) is a prime number at most 55 555.\n\nThe values of a_1, a_2, ..., a_N are all different.\n\nIn every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.\n\nIf there are multiple such sequences, printing any of them is accepted.\n\nNotes\n\nAn integer N not less than 2 is called a prime number if it cannot be divided evenly by any integers except 1 and N, and called a composite number otherwise.\n\nConstraints\n\nN is an integer between 5 and 55 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.\n\nSample Input 1\n\n5\n\nSample Output 1\n\n3 5 7 11 31\n\nLet us see if this output actually satisfies the conditions.\n\nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime numbers.\n\nThe only way to choose five among them is to choose all of them, whose sum is a_1+a_2+a_3+a_4+a_5=57, which is a composite number.\n\nThere are also other possible outputs, such as 2 3 5 7 13, 11 13 17 19 31 and 7 11 5 31 3.\n\nSample Input 2\n\n6\n\nSample Output 2\n\n2 3 5 7 11 13\n\n2, 3, 5, 7, 11, 13 are all different prime numbers.\n\n2+3+5+7+11=28 is a composite number.\n\n2+3+5+7+13=30 is a composite number.\n\n2+3+5+11+13=34 is a composite number.\n\n2+3+7+11+13=36 is a composite number.\n\n2+5+7+11+13=38 is a composite number.\n\n3+5+7+11+13=39 is a composite number.\n\nThus, the sequence 2 3 5 7 11 13 satisfies the conditions.\n\nSample Input 3\n\n8\n\nSample Output 3\n\n2 5 7 13 19 37 67 79", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1367, "cpu_time_ms": 219, "memory_kb": 19684}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s822261752", "group_id": "codeNet:p03363", "input_text": ";; AGC 023\n(let* ((n (read))\n (s (make-array (list (1+ n)) :initial-element 0))\n (c (make-hash-table :size n :test 'equal))\n (ans 0))\n (setf (gethash 0 c) 1)\n (loop :for i :from 1 :to n\n :do (progn\n (setf (aref s i) (+ (aref s (1- i)) (read)))\n (if (gethash (aref s i) c)\n (incf (gethash (aref s i) c))\n (setf (gethash (aref s i) c) 1))))\n (maphash (lambda (key value)\n (declare (ignore key))\n (incf ans (/ (* value (1- value)) 2)))\n c)\n (format t \"~A~%\" ans))\n", "language": "Lisp", "metadata": {"date": 1593653651, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03363.html", "problem_id": "p03363", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03363/input.txt", "sample_output_relpath": "derived/input_output/data/p03363/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03363/Lisp/s822261752.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s822261752", "user_id": "u608227593"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; AGC 023\n(let* ((n (read))\n (s (make-array (list (1+ n)) :initial-element 0))\n (c (make-hash-table :size n :test 'equal))\n (ans 0))\n (setf (gethash 0 c) 1)\n (loop :for i :from 1 :to n\n :do (progn\n (setf (aref s i) (+ (aref s (1- i)) (read)))\n (if (gethash (aref s i) c)\n (incf (gethash (aref s i) c))\n (setf (gethash (aref s i) c) 1))))\n (maphash (lambda (key value)\n (declare (ignore key))\n (incf ans (/ (* value (1- value)) 2)))\n c)\n (format t \"~A~%\" ans))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have an integer sequence A, whose length is N.\n\nFind the number of the non-empty contiguous subsequences of A whose sums are 0.\nNote that we are counting the ways to take out subsequences.\nThat is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n-10^9 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nFind the number of the non-empty contiguous subsequences of A whose sum is 0.\n\nSample Input 1\n\n6\n1 3 -4 2 2 -2\n\nSample Output 1\n\n3\n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2) and (2,-2).\n\nSample Input 2\n\n7\n1 -1 1 -1 1 -1 1\n\nSample Output 2\n\n12\n\nIn this case, some subsequences that have the same contents but are taken from different positions are counted individually.\nFor example, three occurrences of (1, -1) are counted.\n\nSample Input 3\n\n5\n1 -2 3 -4 5\n\nSample Output 3\n\n0\n\nThere are no contiguous subsequences whose sums are 0.", "sample_input": "6\n1 3 -4 2 2 -2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03363", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have an integer sequence A, whose length is N.\n\nFind the number of the non-empty contiguous subsequences of A whose sums are 0.\nNote that we are counting the ways to take out subsequences.\nThat is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n-10^9 \\leq A_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nFind the number of the non-empty contiguous subsequences of A whose sum is 0.\n\nSample Input 1\n\n6\n1 3 -4 2 2 -2\n\nSample Output 1\n\n3\n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2) and (2,-2).\n\nSample Input 2\n\n7\n1 -1 1 -1 1 -1 1\n\nSample Output 2\n\n12\n\nIn this case, some subsequences that have the same contents but are taken from different positions are counted individually.\nFor example, three occurrences of (1, -1) are counted.\n\nSample Input 3\n\n5\n1 -2 3 -4 5\n\nSample Output 3\n\n0\n\nThere are no contiguous subsequences whose sums are 0.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 584, "cpu_time_ms": 287, "memory_kb": 84320}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s571983532", "group_id": "codeNet:p03364", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline print-matrix))\n(defun print-matrix (array &optional (separator #\\ ))\n (declare ((array * 2) array))\n (destructuring-bind (h w) (array-dimensions array)\n (declare ((integer 0 #.most-positive-fixnum) h w))\n (dotimes (i h)\n (dotimes (j w)\n (unless (zerop j) (princ separator))\n (write (aref array i j)))\n (terpri))))\n\n(declaim (inline fast-read-char))\n(defun fast-read-char (&optional (stream *standard-input*))\n (declare #-swank (sb-kernel:ansi-stream stream)\n (inline read-byte))\n #+swank (read-char stream nil #\\Newline) ; on SLIME\n #-swank (code-char (read-byte stream nil #.(char-code #\\Newline))))\n\n;;;\n;;; 2D rolling hash (32-bit)\n;;;\n\n(defstruct (rhash2d (:constructor %make-rhash2d (mod1 base1 mod2 base2 table)))\n ;; horizontal\n (mod1 2147483647 :type (unsigned-byte 32))\n (base1 1059428526 :type (unsigned-byte 32))\n ;; vertical\n (mod2 2147483629 :type (unsigned-byte 32))\n (base2 2090066834 :type (unsigned-byte 32))\n (table nil :type (simple-array (unsigned-byte 32) (* *))))\n\n;; This table consists of pairs of primes less than 2^32 and the random\n;; primitive roots modulo them larger than 10^9. We randomly choose a pair and\n;; adopt the prime as modulus and the primitive root as base.\n(declaim ((simple-array (unsigned-byte 32) (100)) *moduli-table* *base-table*))\n(defparameter *moduli-table*\n (make-array 100 :element-type '(unsigned-byte 32)\n :initial-contents '(4294967291 4294967279 4294967231 4294967197 4294967189 4294967161 4294967143\n 4294967111 4294967087 4294967029 4294966997 4294966981 4294966943 4294966927\n 4294966909 4294966877 4294966829 4294966813 4294966769 4294966667 4294966661\n 4294966657 4294966651 4294966639 4294966619 4294966591 4294966583 4294966553\n 4294966477 4294966447 4294966441 4294966427 4294966373 4294966367 4294966337\n 4294966297 4294966243 4294966237 4294966231 4294966217 4294966187 4294966177\n 4294966163 4294966153 4294966129 4294966121 4294966099 4294966087 4294966073\n 4294966043 4294966007 4294966001 4294965977 4294965971 4294965967 4294965949\n 4294965937 4294965911 4294965887 4294965847 4294965841 4294965839 4294965821\n 4294965793 4294965767 4294965757 4294965737 4294965733 4294965721 4294965691\n 4294965683 4294965679 4294965673 4294965671 4294965659 4294965641 4294965617\n 4294965613 4294965601 4294965581 4294965529 4294965487 4294965461 4294965457\n 4294965413 4294965383 4294965361 4294965347 4294965331 4294965313 4294965307\n 4294965263 4294965251 4294965229 4294965203 4294965193 4294965161 4294965151\n 4294965137 4294965131)))\n(defparameter *base-table*\n (make-array 100 :element-type '(unsigned-byte 32)\n :initial-contents '(2247433164 2139372809 2609807693 2343117402 3096734379 2843084587 3022604264\n 3725165355 1310011850 3271696819 3710639434 4215251668 2971116345 1291563131\n 2125491020 1561805191 3225016848 4113447491 3038900010 3636011022 2479454799\n 1990556577 2661169605 3088947962 1926120766 4105365454 4171519129 2043031086\n 1810297004 1391329364 3781496513 3524912702 2014602604 3608350570 2970210993\n 4041943368 3843309586 1048071792 2527337250 4207345339 3745845437 3780181639\n 1843103547 1471147023 2925746977 2571168523 1911322179 2533579172 2577088289\n 3082429185 3636817029 3517246253 2141978180 2042755180 1656982819 2160802626\n 3780428251 1987808226 3883058504 1973235694 3022446019 3414211768 2747857698\n 1121927034 2368051231 1585372041 2942376489 1760007658 1731546725 3503068146\n 3139298718 3516795165 3838735245 3491469147 2711077678 1556341778 2556545397\n 1528640652 1183190693 2870857999 3301248018 4114187491 2653041143 1757252280\n 3464064684 1655297946 4217483675 2809928527 2757106005 3401026515 2587333052\n 1757998238 1398188339 4075136024 2780360736 2566409334 2544620190 1754492744\n 2431582005 1565067593)))\n\n(defun %choose-moduli (mod1 mod2 base1 base2 rhash2d)\n \"Chooses two appropriate pairs of moduli and bases.\"\n (declare ((or null (unsigned-byte 32)) mod1 mod2 base1 base2))\n (when rhash2d\n (return-from %choose-moduli\n (values (rhash2d-mod1 rhash2d)\n (rhash2d-mod2 rhash2d)\n (rhash2d-base1 rhash2d)\n (rhash2d-base2 rhash2d))))\n (let* ((rand1 (random (length *moduli-table*)))\n ;; avoid the same modulus\n (rand2 (loop (let ((tmp (random (length *moduli-table*))))\n (unless (= tmp rand1)\n (return tmp))))))\n (if mod1\n (progn\n #+sbcl (assert (sb-int:positive-primep mod1))\n (setq base1 (or base1 (+ 1 (random (- mod1 1))))))\n (progn\n (setq mod1 (or mod1 (aref *moduli-table* rand1)))\n (if base1\n (assert (<= 1 base1 (- mod1 1)))\n (setq base1 (aref *base-table* rand1)))))\n (if mod2\n (progn\n #+sbcl (assert (sb-int:positive-primep mod2))\n (setq base2 (or base2 (+ 1 (random (- mod2 1))))))\n (progn\n (setq mod2 (or mod2 (aref *moduli-table* rand2)))\n (if base2\n (assert (<= 1 base2 (- mod2 1)))\n (setq base2 (aref *base-table* rand2))))))\n (values mod1 mod2 base1 base2))\n\n(defun make-rhash2d (matrix h w &key (key #'identity) mod1 mod2 base1 base2 rhash2d)\n \"Returns the table of the hash value of each subrectangle of size H * W on\nMATRIX modulo MOD1 and MOD2.\n\nKEY is applied to each element of MATRIX prior to computing the hash value. If\nmoduli and bases are NIL, this function randomly chooses them. If RHASH2D is\nspecified, the same moduli and bases as RHASH2D is adopted.\n\nMOD[1|2] := NIL | unsigned 32-bit prime number\nBASE1 := NIL | 1 | 2 | ... | MOD1 - 1\nBASE2 := NIL | 1 | 2 | ... | MOD2 - 1\nKEY := FUNCTION returning FIXNUM\nRHASH2D := NIL | RHASH2D\"\n (declare (optimize (speed 3))\n ((array * (* *)) matrix)\n ((integer 0 #.most-positive-fixnum) h w)\n ((or null (unsigned-byte 32)) mod1 mod2 base1 base2)\n (function key))\n (multiple-value-bind (mod1 mod2 base1 base2) (%choose-moduli mod1 mod2 base1 base2 rhash2d)\n (declare ((unsigned-byte 32) mod1 mod2 base1 base2))\n (labels ((power (base exp mod)\n (declare ((unsigned-byte 32) base exp mod))\n (let ((res 1))\n (declare ((unsigned-byte 32) res))\n (dotimes (i exp res)\n (setq res (mod (* res base) mod)))))\n (get-cell (i j) ; Returns MATRIX[i][j] as (unsigned-byte 32).\n (declare ((integer 0 #.most-positive-fixnum) i j))\n (the (unsigned-byte 32)\n (mod (the fixnum (funcall key (aref matrix i j))) mod1))))\n (destructuring-bind (src-h src-w) (array-dimensions matrix)\n (declare ((integer 0 #.most-positive-fixnum) src-h src-w))\n (assert (and (<= h src-h) (<= w src-w)))\n (let* ((table-h (+ 1 (- src-h h)))\n (table-w (+ 1 (- src-w w)))\n (tmp-table (make-array (list src-h table-w)\n :element-type '(unsigned-byte 32)))\n (table (make-array (list table-h table-w)\n :element-type '(unsigned-byte 32)))\n (coef-row (power base1 w mod1))\n (coef-col (power base2 h mod2)))\n (declare ((integer 0 #.most-positive-fixnum) table-h table-w))\n ;; compute hash values in the horizontal direction\n (dotimes (i src-h)\n (let ((val 0))\n (declare ((unsigned-byte 32) val))\n (dotimes (j w)\n (setq val (mod (+ (* val base1) (get-cell i j)) mod1)))\n (dotimes (j table-w)\n (setf (aref tmp-table i j) val)\n (when (< j (- src-w w))\n (setq val (mod (+ (mod (* val base1) mod1)\n (- mod1 (mod (* coef-row (get-cell i j)) mod1))\n (get-cell i (+ j w)))\n mod1))))))\n ;; compute hash values in the vertical direction\n (dotimes (j table-w)\n (let ((val 0))\n (declare ((unsigned-byte 32) val))\n (dotimes (i h)\n (setq val (mod (+ (* val base2) (aref tmp-table i j)) mod2)))\n (dotimes (i table-h)\n (setf (aref table i j) val)\n (when (< i (- src-h h))\n (setq val (mod (+ (mod (* val base2) mod2)\n (- mod2 (mod (* coef-col (aref tmp-table i j)) mod2))\n (aref tmp-table (the fixnum (+ i h)) j))\n mod2))))))\n (%make-rhash2d mod1 base1 mod2 base2 table))))))\n\n(declaim (inline rhash2d-query)\n (ftype (function * (values (unsigned-byte 32) &optional)) rhash2d-query))\n(defun rhash2d-query (rhash2d i j)\n \"Returns the hash value of the subrectangle whose upper left corner is at\n(i, j).\"\n (declare ((integer 0 #.most-positive-fixnum) i j))\n (aref (rhash2d-table rhash2d) i j))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (plan (make-array (list (* 2 n) (* 2 n)) :element-type 'base-char))\n (transposed (make-array (list (* 2 n) (* 2 n)) :element-type 'base-char)))\n (declare (uint16 n))\n (dotimes (i n)\n (dotimes (j n)\n (let ((c (fast-read-char)))\n (setf (aref plan i j) c\n (aref plan (+ i n) j) c\n (aref plan i (+ j n)) c\n (aref plan (+ i n) (+ j n)) c)))\n (fast-read-char))\n (dotimes (i (* 2 n))\n (dotimes (j (* 2 n))\n (setf (aref transposed j i) (aref plan i j))))\n (let* ((rhash1 (make-rhash2d plan n n :key #'char-code))\n (rhash2 (make-rhash2d transposed n n :key #'char-code :rhash2d rhash1))\n (res 0))\n (declare (uint32 res))\n (dotimes (i n)\n (dotimes (j n)\n (when (= (rhash2d-query rhash1 i j)\n (rhash2d-query rhash2 j i))\n (incf res))))\n (println res))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1566946910, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03364.html", "problem_id": "p03364", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03364/input.txt", "sample_output_relpath": "derived/input_output/data/p03364/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03364/Lisp/s571983532.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s571983532", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline print-matrix))\n(defun print-matrix (array &optional (separator #\\ ))\n (declare ((array * 2) array))\n (destructuring-bind (h w) (array-dimensions array)\n (declare ((integer 0 #.most-positive-fixnum) h w))\n (dotimes (i h)\n (dotimes (j w)\n (unless (zerop j) (princ separator))\n (write (aref array i j)))\n (terpri))))\n\n(declaim (inline fast-read-char))\n(defun fast-read-char (&optional (stream *standard-input*))\n (declare #-swank (sb-kernel:ansi-stream stream)\n (inline read-byte))\n #+swank (read-char stream nil #\\Newline) ; on SLIME\n #-swank (code-char (read-byte stream nil #.(char-code #\\Newline))))\n\n;;;\n;;; 2D rolling hash (32-bit)\n;;;\n\n(defstruct (rhash2d (:constructor %make-rhash2d (mod1 base1 mod2 base2 table)))\n ;; horizontal\n (mod1 2147483647 :type (unsigned-byte 32))\n (base1 1059428526 :type (unsigned-byte 32))\n ;; vertical\n (mod2 2147483629 :type (unsigned-byte 32))\n (base2 2090066834 :type (unsigned-byte 32))\n (table nil :type (simple-array (unsigned-byte 32) (* *))))\n\n;; This table consists of pairs of primes less than 2^32 and the random\n;; primitive roots modulo them larger than 10^9. We randomly choose a pair and\n;; adopt the prime as modulus and the primitive root as base.\n(declaim ((simple-array (unsigned-byte 32) (100)) *moduli-table* *base-table*))\n(defparameter *moduli-table*\n (make-array 100 :element-type '(unsigned-byte 32)\n :initial-contents '(4294967291 4294967279 4294967231 4294967197 4294967189 4294967161 4294967143\n 4294967111 4294967087 4294967029 4294966997 4294966981 4294966943 4294966927\n 4294966909 4294966877 4294966829 4294966813 4294966769 4294966667 4294966661\n 4294966657 4294966651 4294966639 4294966619 4294966591 4294966583 4294966553\n 4294966477 4294966447 4294966441 4294966427 4294966373 4294966367 4294966337\n 4294966297 4294966243 4294966237 4294966231 4294966217 4294966187 4294966177\n 4294966163 4294966153 4294966129 4294966121 4294966099 4294966087 4294966073\n 4294966043 4294966007 4294966001 4294965977 4294965971 4294965967 4294965949\n 4294965937 4294965911 4294965887 4294965847 4294965841 4294965839 4294965821\n 4294965793 4294965767 4294965757 4294965737 4294965733 4294965721 4294965691\n 4294965683 4294965679 4294965673 4294965671 4294965659 4294965641 4294965617\n 4294965613 4294965601 4294965581 4294965529 4294965487 4294965461 4294965457\n 4294965413 4294965383 4294965361 4294965347 4294965331 4294965313 4294965307\n 4294965263 4294965251 4294965229 4294965203 4294965193 4294965161 4294965151\n 4294965137 4294965131)))\n(defparameter *base-table*\n (make-array 100 :element-type '(unsigned-byte 32)\n :initial-contents '(2247433164 2139372809 2609807693 2343117402 3096734379 2843084587 3022604264\n 3725165355 1310011850 3271696819 3710639434 4215251668 2971116345 1291563131\n 2125491020 1561805191 3225016848 4113447491 3038900010 3636011022 2479454799\n 1990556577 2661169605 3088947962 1926120766 4105365454 4171519129 2043031086\n 1810297004 1391329364 3781496513 3524912702 2014602604 3608350570 2970210993\n 4041943368 3843309586 1048071792 2527337250 4207345339 3745845437 3780181639\n 1843103547 1471147023 2925746977 2571168523 1911322179 2533579172 2577088289\n 3082429185 3636817029 3517246253 2141978180 2042755180 1656982819 2160802626\n 3780428251 1987808226 3883058504 1973235694 3022446019 3414211768 2747857698\n 1121927034 2368051231 1585372041 2942376489 1760007658 1731546725 3503068146\n 3139298718 3516795165 3838735245 3491469147 2711077678 1556341778 2556545397\n 1528640652 1183190693 2870857999 3301248018 4114187491 2653041143 1757252280\n 3464064684 1655297946 4217483675 2809928527 2757106005 3401026515 2587333052\n 1757998238 1398188339 4075136024 2780360736 2566409334 2544620190 1754492744\n 2431582005 1565067593)))\n\n(defun %choose-moduli (mod1 mod2 base1 base2 rhash2d)\n \"Chooses two appropriate pairs of moduli and bases.\"\n (declare ((or null (unsigned-byte 32)) mod1 mod2 base1 base2))\n (when rhash2d\n (return-from %choose-moduli\n (values (rhash2d-mod1 rhash2d)\n (rhash2d-mod2 rhash2d)\n (rhash2d-base1 rhash2d)\n (rhash2d-base2 rhash2d))))\n (let* ((rand1 (random (length *moduli-table*)))\n ;; avoid the same modulus\n (rand2 (loop (let ((tmp (random (length *moduli-table*))))\n (unless (= tmp rand1)\n (return tmp))))))\n (if mod1\n (progn\n #+sbcl (assert (sb-int:positive-primep mod1))\n (setq base1 (or base1 (+ 1 (random (- mod1 1))))))\n (progn\n (setq mod1 (or mod1 (aref *moduli-table* rand1)))\n (if base1\n (assert (<= 1 base1 (- mod1 1)))\n (setq base1 (aref *base-table* rand1)))))\n (if mod2\n (progn\n #+sbcl (assert (sb-int:positive-primep mod2))\n (setq base2 (or base2 (+ 1 (random (- mod2 1))))))\n (progn\n (setq mod2 (or mod2 (aref *moduli-table* rand2)))\n (if base2\n (assert (<= 1 base2 (- mod2 1)))\n (setq base2 (aref *base-table* rand2))))))\n (values mod1 mod2 base1 base2))\n\n(defun make-rhash2d (matrix h w &key (key #'identity) mod1 mod2 base1 base2 rhash2d)\n \"Returns the table of the hash value of each subrectangle of size H * W on\nMATRIX modulo MOD1 and MOD2.\n\nKEY is applied to each element of MATRIX prior to computing the hash value. If\nmoduli and bases are NIL, this function randomly chooses them. If RHASH2D is\nspecified, the same moduli and bases as RHASH2D is adopted.\n\nMOD[1|2] := NIL | unsigned 32-bit prime number\nBASE1 := NIL | 1 | 2 | ... | MOD1 - 1\nBASE2 := NIL | 1 | 2 | ... | MOD2 - 1\nKEY := FUNCTION returning FIXNUM\nRHASH2D := NIL | RHASH2D\"\n (declare (optimize (speed 3))\n ((array * (* *)) matrix)\n ((integer 0 #.most-positive-fixnum) h w)\n ((or null (unsigned-byte 32)) mod1 mod2 base1 base2)\n (function key))\n (multiple-value-bind (mod1 mod2 base1 base2) (%choose-moduli mod1 mod2 base1 base2 rhash2d)\n (declare ((unsigned-byte 32) mod1 mod2 base1 base2))\n (labels ((power (base exp mod)\n (declare ((unsigned-byte 32) base exp mod))\n (let ((res 1))\n (declare ((unsigned-byte 32) res))\n (dotimes (i exp res)\n (setq res (mod (* res base) mod)))))\n (get-cell (i j) ; Returns MATRIX[i][j] as (unsigned-byte 32).\n (declare ((integer 0 #.most-positive-fixnum) i j))\n (the (unsigned-byte 32)\n (mod (the fixnum (funcall key (aref matrix i j))) mod1))))\n (destructuring-bind (src-h src-w) (array-dimensions matrix)\n (declare ((integer 0 #.most-positive-fixnum) src-h src-w))\n (assert (and (<= h src-h) (<= w src-w)))\n (let* ((table-h (+ 1 (- src-h h)))\n (table-w (+ 1 (- src-w w)))\n (tmp-table (make-array (list src-h table-w)\n :element-type '(unsigned-byte 32)))\n (table (make-array (list table-h table-w)\n :element-type '(unsigned-byte 32)))\n (coef-row (power base1 w mod1))\n (coef-col (power base2 h mod2)))\n (declare ((integer 0 #.most-positive-fixnum) table-h table-w))\n ;; compute hash values in the horizontal direction\n (dotimes (i src-h)\n (let ((val 0))\n (declare ((unsigned-byte 32) val))\n (dotimes (j w)\n (setq val (mod (+ (* val base1) (get-cell i j)) mod1)))\n (dotimes (j table-w)\n (setf (aref tmp-table i j) val)\n (when (< j (- src-w w))\n (setq val (mod (+ (mod (* val base1) mod1)\n (- mod1 (mod (* coef-row (get-cell i j)) mod1))\n (get-cell i (+ j w)))\n mod1))))))\n ;; compute hash values in the vertical direction\n (dotimes (j table-w)\n (let ((val 0))\n (declare ((unsigned-byte 32) val))\n (dotimes (i h)\n (setq val (mod (+ (* val base2) (aref tmp-table i j)) mod2)))\n (dotimes (i table-h)\n (setf (aref table i j) val)\n (when (< i (- src-h h))\n (setq val (mod (+ (mod (* val base2) mod2)\n (- mod2 (mod (* coef-col (aref tmp-table i j)) mod2))\n (aref tmp-table (the fixnum (+ i h)) j))\n mod2))))))\n (%make-rhash2d mod1 base1 mod2 base2 table))))))\n\n(declaim (inline rhash2d-query)\n (ftype (function * (values (unsigned-byte 32) &optional)) rhash2d-query))\n(defun rhash2d-query (rhash2d i j)\n \"Returns the hash value of the subrectangle whose upper left corner is at\n(i, j).\"\n (declare ((integer 0 #.most-positive-fixnum) i j))\n (aref (rhash2d-table rhash2d) i j))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (plan (make-array (list (* 2 n) (* 2 n)) :element-type 'base-char))\n (transposed (make-array (list (* 2 n) (* 2 n)) :element-type 'base-char)))\n (declare (uint16 n))\n (dotimes (i n)\n (dotimes (j n)\n (let ((c (fast-read-char)))\n (setf (aref plan i j) c\n (aref plan (+ i n) j) c\n (aref plan i (+ j n)) c\n (aref plan (+ i n) (+ j n)) c)))\n (fast-read-char))\n (dotimes (i (* 2 n))\n (dotimes (j (* 2 n))\n (setf (aref transposed j i) (aref plan i j))))\n (let* ((rhash1 (make-rhash2d plan n n :key #'char-code))\n (rhash2 (make-rhash2d transposed n n :key #'char-code :rhash2d rhash1))\n (res 0))\n (declare (uint32 res))\n (dotimes (i n)\n (dotimes (j n)\n (when (= (rhash2d-query rhash1 i j)\n (rhash2d-query rhash2 j i))\n (incf res))))\n (println res))))\n\n#-swank (main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nSnuke has two boards, each divided into a grid with N rows and N columns.\nFor both of these boards, the square at the i-th row from the top and the j-th column from the left is called Square (i,j).\n\nThere is a lowercase English letter written in each square on the first board. The letter written in Square (i,j) is S_{i,j}. On the second board, nothing is written yet.\n\nSnuke will write letters on the second board, as follows:\n\nFirst, choose two integers A and B ( 0 \\leq A, B < N ).\n\nWrite one letter in each square on the second board.\nSpecifically, write the letter written in Square ( i+A, j+B ) on the first board into Square (i,j) on the second board.\nHere, the k-th row is also represented as the (N+k)-th row, and the k-th column is also represented as the (N+k)-th column.\n\nAfter this operation, the second board is called a good board when, for every i and j ( 1 \\leq i, j \\leq N ), the letter in Square (i,j) and the letter in Square (j,i) are equal.\n\nFind the number of the ways to choose integers A and B ( 0 \\leq A, B < N ) such that the second board is a good board.\n\nConstraints\n\n1 \\leq N \\leq 300\n\nS_{i,j} ( 1 \\leq i, j \\leq N ) is a lowercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_{1,1}S_{1,2}..S_{1,N}\nS_{2,1}S_{2,2}..S_{2,N}\n:\nS_{N,1}S_{N,2}..S_{N,N}\n\nOutput\n\nPrint the number of the ways to choose integers A and B ( 0 \\leq A, B < N ) such that the second board is a good board.\n\nSample Input 1\n\n2\nab\nca\n\nSample Output 1\n\n2\n\nFor each pair of A and B, the second board will look as shown below:\n\nThe second board is a good board when (A,B) = (0,1) or (A,B) = (1,0), thus the answer is 2.\n\nSample Input 2\n\n4\naaaa\naaaa\naaaa\naaaa\n\nSample Output 2\n\n16\n\nEvery possible choice of A and B makes the second board good.\n\nSample Input 3\n\n5\nabcde\nfghij\nklmno\npqrst\nuvwxy\n\nSample Output 3\n\n0\n\nNo possible choice of A and B makes the second board good.", "sample_input": "2\nab\nca\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03364", "source_text": "Score : 500 points\n\nProblem Statement\n\nSnuke has two boards, each divided into a grid with N rows and N columns.\nFor both of these boards, the square at the i-th row from the top and the j-th column from the left is called Square (i,j).\n\nThere is a lowercase English letter written in each square on the first board. The letter written in Square (i,j) is S_{i,j}. On the second board, nothing is written yet.\n\nSnuke will write letters on the second board, as follows:\n\nFirst, choose two integers A and B ( 0 \\leq A, B < N ).\n\nWrite one letter in each square on the second board.\nSpecifically, write the letter written in Square ( i+A, j+B ) on the first board into Square (i,j) on the second board.\nHere, the k-th row is also represented as the (N+k)-th row, and the k-th column is also represented as the (N+k)-th column.\n\nAfter this operation, the second board is called a good board when, for every i and j ( 1 \\leq i, j \\leq N ), the letter in Square (i,j) and the letter in Square (j,i) are equal.\n\nFind the number of the ways to choose integers A and B ( 0 \\leq A, B < N ) such that the second board is a good board.\n\nConstraints\n\n1 \\leq N \\leq 300\n\nS_{i,j} ( 1 \\leq i, j \\leq N ) is a lowercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_{1,1}S_{1,2}..S_{1,N}\nS_{2,1}S_{2,2}..S_{2,N}\n:\nS_{N,1}S_{N,2}..S_{N,N}\n\nOutput\n\nPrint the number of the ways to choose integers A and B ( 0 \\leq A, B < N ) such that the second board is a good board.\n\nSample Input 1\n\n2\nab\nca\n\nSample Output 1\n\n2\n\nFor each pair of A and B, the second board will look as shown below:\n\nThe second board is a good board when (A,B) = (0,1) or (A,B) = (1,0), thus the answer is 2.\n\nSample Input 2\n\n4\naaaa\naaaa\naaaa\naaaa\n\nSample Output 2\n\n16\n\nEvery possible choice of A and B makes the second board good.\n\nSample Input 3\n\n5\nabcde\nfghij\nklmno\npqrst\nuvwxy\n\nSample Output 3\n\n0\n\nNo possible choice of A and B makes the second board good.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11337, "cpu_time_ms": 325, "memory_kb": 44004}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s552444442", "group_id": "codeNet:p03369", "input_text": ";;; Utils\n\n(defmacro read-numbers-to-list ()\n `(read-from-string\n (concatenate 'string \"(\" (read-line) \")\")))\n\n\n(defmacro read-line-to-array (dimension)\n (if (< dimension 0)\n (error \"invalid arguments for dimension.\")\n `(make-array ,dimension :initial-contents (read-numbers-to-list))))\n\n(defmacro read-line-to--char-list ()\n `(concatenate 'list (read-line)))\n\n(defmethod make-cumlative-sum ((sequence list))\n (labels ((inner (sequence &optional (acc '(0)))\n (if (null sequence)\n (reverse acc)\n (inner (rest sequence) (cons (+ (first sequence)\n (first acc))\n acc)))))\n (inner sequence)))\n\n\n\n\n\n(defmethod princ-for-each-line ((sequence list))\n (labels ((inner (sequence)\n (if (null sequence)\n nil\n (progn\n (fresh-line)\n (princ (first sequence))\n (inner (rest sequence))))))\n (inner sequence)))\n\n(defmethod princ-for-each-line ((sequence array))\n (dotimes (i (length sequence))\n (fresh-line)\n (princ (aref sequence i))))\n\n\n\n\n;;; Write code here\n\n(defun solve (s)\n (+ 700\n (* (count #\\o s :test #'char-equal)\n 100)))\n\n\n(defun main ()\n (let ((s (read-line)))\n (format t \"~a~%\" (solve s))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1598851860, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03369.html", "problem_id": "p03369", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03369/input.txt", "sample_output_relpath": "derived/input_output/data/p03369/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03369/Lisp/s552444442.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s552444442", "user_id": "u425762225"}, "prompt_components": {"gold_output": "900\n", "input_to_evaluate": ";;; Utils\n\n(defmacro read-numbers-to-list ()\n `(read-from-string\n (concatenate 'string \"(\" (read-line) \")\")))\n\n\n(defmacro read-line-to-array (dimension)\n (if (< dimension 0)\n (error \"invalid arguments for dimension.\")\n `(make-array ,dimension :initial-contents (read-numbers-to-list))))\n\n(defmacro read-line-to--char-list ()\n `(concatenate 'list (read-line)))\n\n(defmethod make-cumlative-sum ((sequence list))\n (labels ((inner (sequence &optional (acc '(0)))\n (if (null sequence)\n (reverse acc)\n (inner (rest sequence) (cons (+ (first sequence)\n (first acc))\n acc)))))\n (inner sequence)))\n\n\n\n\n\n(defmethod princ-for-each-line ((sequence list))\n (labels ((inner (sequence)\n (if (null sequence)\n nil\n (progn\n (fresh-line)\n (princ (first sequence))\n (inner (rest sequence))))))\n (inner sequence)))\n\n(defmethod princ-for-each-line ((sequence array))\n (dotimes (i (length sequence))\n (fresh-line)\n (princ (aref sequence i))))\n\n\n\n\n;;; Write code here\n\n(defun solve (s)\n (+ 700\n (* (count #\\o s :test #'char-equal)\n 100)))\n\n\n(defun main ()\n (let ((s (read-line)))\n (format t \"~a~%\" (solve s))))\n\n(main)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIn \"Takahashi-ya\", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions).\n\nA customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is o, it means the ramen should be topped with boiled egg; if that character is x, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen.\n\nWrite a program that, when S is given, prints the price of the corresponding bowl of ramen.\n\nConstraints\n\nS is a string of length 3.\n\nEach character in S is o or x.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the price of the bowl of ramen corresponding to S.\n\nSample Input 1\n\noxo\n\nSample Output 1\n\n900\n\nThe price of a ramen topped with two kinds of toppings, boiled egg and green onions, is 700 + 100 \\times 2 = 900 yen.\n\nSample Input 2\n\nooo\n\nSample Output 2\n\n1000\n\nThe price of a ramen topped with all three kinds of toppings is 700 + 100 \\times 3 = 1000 yen.\n\nSample Input 3\n\nxxx\n\nSample Output 3\n\n700\n\nThe price of a ramen without any toppings is 700 yen.", "sample_input": "oxo\n"}, "reference_outputs": ["900\n"], "source_document_id": "p03369", "source_text": "Score : 100 points\n\nProblem Statement\n\nIn \"Takahashi-ya\", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions).\n\nA customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is o, it means the ramen should be topped with boiled egg; if that character is x, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen.\n\nWrite a program that, when S is given, prints the price of the corresponding bowl of ramen.\n\nConstraints\n\nS is a string of length 3.\n\nEach character in S is o or x.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the price of the bowl of ramen corresponding to S.\n\nSample Input 1\n\noxo\n\nSample Output 1\n\n900\n\nThe price of a ramen topped with two kinds of toppings, boiled egg and green onions, is 700 + 100 \\times 2 = 900 yen.\n\nSample Input 2\n\nooo\n\nSample Output 2\n\n1000\n\nThe price of a ramen topped with all three kinds of toppings is 700 + 100 \\times 3 = 1000 yen.\n\nSample Input 3\n\nxxx\n\nSample Output 3\n\n700\n\nThe price of a ramen without any toppings is 700 yen.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1376, "cpu_time_ms": 22, "memory_kb": 25080}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s926003970", "group_id": "codeNet:p03370", "input_text": ";;; Utils\n\n(defmacro read-numbers-to-list ()\n `(read-from-string\n (concatenate 'string \"(\" (read-line) \")\")))\n\n\n(defmacro read-line-to-array (dimension)\n (if (< dimension 0)\n (error \"invalid arguments for dimension.\")\n `(make-array ,dimension :initial-contents (read-numbers-to-list))))\n\n(defmacro read-line-to--char-list ()\n `(concatenate 'list (read-line)))\n\n(defmethod make-cumlative-sum ((sequence list))\n (labels ((inner (sequence &optional (acc '(0)))\n (if (null sequence)\n (reverse acc)\n (inner (rest sequence) (cons (+ (first sequence)\n (first acc))\n acc)))))\n (inner sequence)))\n\n\n\n\n\n(defmethod princ-for-each-line ((sequence list))\n (labels ((inner (sequence)\n (if (null sequence)\n nil\n (progn\n (fresh-line)\n (princ (first sequence))\n (inner (rest sequence))))))\n (inner sequence)))\n\n(defmethod princ-for-each-line ((sequence array))\n (dotimes (i (length sequence))\n (fresh-line)\n (princ (aref sequence i))))\n\n\n\n;;; Write code here\n\n(defun solve (n x weights)\n (let ((min-weight (reduce #'min weights))\n (counter n)\n (weight-rest (- x (reduce #'+ weights))))\n (assert (>= weight-rest 0))\n (+ counter\n (floor weight-rest min-weight))))\n\n\n(defun main ()\n (let* ((n (read))\n (x (read))\n (weights (coerce (loop repeat n collect (read)) 'vector)))\n (assert (and\n (every #'numberp weights)))\n (format t \"~a~%\" (solve n x weights))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1598852840, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03370.html", "problem_id": "p03370", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03370/input.txt", "sample_output_relpath": "derived/input_output/data/p03370/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03370/Lisp/s926003970.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s926003970", "user_id": "u425762225"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": ";;; Utils\n\n(defmacro read-numbers-to-list ()\n `(read-from-string\n (concatenate 'string \"(\" (read-line) \")\")))\n\n\n(defmacro read-line-to-array (dimension)\n (if (< dimension 0)\n (error \"invalid arguments for dimension.\")\n `(make-array ,dimension :initial-contents (read-numbers-to-list))))\n\n(defmacro read-line-to--char-list ()\n `(concatenate 'list (read-line)))\n\n(defmethod make-cumlative-sum ((sequence list))\n (labels ((inner (sequence &optional (acc '(0)))\n (if (null sequence)\n (reverse acc)\n (inner (rest sequence) (cons (+ (first sequence)\n (first acc))\n acc)))))\n (inner sequence)))\n\n\n\n\n\n(defmethod princ-for-each-line ((sequence list))\n (labels ((inner (sequence)\n (if (null sequence)\n nil\n (progn\n (fresh-line)\n (princ (first sequence))\n (inner (rest sequence))))))\n (inner sequence)))\n\n(defmethod princ-for-each-line ((sequence array))\n (dotimes (i (length sequence))\n (fresh-line)\n (princ (aref sequence i))))\n\n\n\n;;; Write code here\n\n(defun solve (n x weights)\n (let ((min-weight (reduce #'min weights))\n (counter n)\n (weight-rest (- x (reduce #'+ weights))))\n (assert (>= weight-rest 0))\n (+ counter\n (floor weight-rest min-weight))))\n\n\n(defun main ()\n (let* ((n (read))\n (x (read))\n (weights (coerce (loop repeat n collect (read)) 'vector)))\n (assert (and\n (every #'numberp weights)))\n (format t \"~a~%\" (solve n x weights))))\n\n(main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nAkaki, a patissier, can make N kinds of doughnut using only a certain powder called \"Okashi no Moto\" (literally \"material of pastry\", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts.\n\nNow, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:\n\nFor each of the N kinds of doughnuts, make at least one doughnut of that kind.\n\nAt most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.\n\nConstraints\n\n2 ≤ N ≤ 100\n\n1 ≤ m_i ≤ 1000\n\nm_1 + m_2 + ... + m_N ≤ X ≤ 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X\nm_1\nm_2\n:\nm_N\n\nOutput\n\nPrint the maximum number of doughnuts that can be made under the condition.\n\nSample Input 1\n\n3 1000\n120\n100\n140\n\nSample Output 1\n\n9\n\nShe has 1000 grams of Moto and can make three kinds of doughnuts. If she makes one doughnut for each of the three kinds, she consumes 120 + 100 + 140 = 360 grams of Moto. From the 640 grams of Moto that remains here, she can make additional six Doughnuts 2. This is how she can made a total of nine doughnuts, which is the maximum.\n\nSample Input 2\n\n4 360\n90\n90\n90\n90\n\nSample Output 2\n\n4\n\nMaking one doughnut for each of the four kinds consumes all of her Moto.\n\nSample Input 3\n\n5 3000\n150\n130\n150\n130\n110\n\nSample Output 3\n\n26", "sample_input": "3 1000\n120\n100\n140\n"}, "reference_outputs": ["9\n"], "source_document_id": "p03370", "source_text": "Score : 200 points\n\nProblem Statement\n\nAkaki, a patissier, can make N kinds of doughnut using only a certain powder called \"Okashi no Moto\" (literally \"material of pastry\", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts.\n\nNow, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:\n\nFor each of the N kinds of doughnuts, make at least one doughnut of that kind.\n\nAt most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.\n\nConstraints\n\n2 ≤ N ≤ 100\n\n1 ≤ m_i ≤ 1000\n\nm_1 + m_2 + ... + m_N ≤ X ≤ 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X\nm_1\nm_2\n:\nm_N\n\nOutput\n\nPrint the maximum number of doughnuts that can be made under the condition.\n\nSample Input 1\n\n3 1000\n120\n100\n140\n\nSample Output 1\n\n9\n\nShe has 1000 grams of Moto and can make three kinds of doughnuts. If she makes one doughnut for each of the three kinds, she consumes 120 + 100 + 140 = 360 grams of Moto. From the 640 grams of Moto that remains here, she can make additional six Doughnuts 2. This is how she can made a total of nine doughnuts, which is the maximum.\n\nSample Input 2\n\n4 360\n90\n90\n90\n90\n\nSample Output 2\n\n4\n\nMaking one doughnut for each of the four kinds consumes all of her Moto.\n\nSample Input 3\n\n5 3000\n150\n130\n150\n130\n110\n\nSample Output 3\n\n26", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1673, "cpu_time_ms": 20, "memory_kb": 25152}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s777121160", "group_id": "codeNet:p03370", "input_text": "(setq n(read))\n(setq m(read))\n(setq s 10000000)\n(loop for i from 1 to n do(setq a(read))(decf m a)(setq s(min s a)))\n(princ(+(floor m s)n))", "language": "Lisp", "metadata": {"date": 1533112501, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03370.html", "problem_id": "p03370", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03370/input.txt", "sample_output_relpath": "derived/input_output/data/p03370/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03370/Lisp/s777121160.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s777121160", "user_id": "u657913472"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(setq n(read))\n(setq m(read))\n(setq s 10000000)\n(loop for i from 1 to n do(setq a(read))(decf m a)(setq s(min s a)))\n(princ(+(floor m s)n))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nAkaki, a patissier, can make N kinds of doughnut using only a certain powder called \"Okashi no Moto\" (literally \"material of pastry\", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts.\n\nNow, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:\n\nFor each of the N kinds of doughnuts, make at least one doughnut of that kind.\n\nAt most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.\n\nConstraints\n\n2 ≤ N ≤ 100\n\n1 ≤ m_i ≤ 1000\n\nm_1 + m_2 + ... + m_N ≤ X ≤ 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X\nm_1\nm_2\n:\nm_N\n\nOutput\n\nPrint the maximum number of doughnuts that can be made under the condition.\n\nSample Input 1\n\n3 1000\n120\n100\n140\n\nSample Output 1\n\n9\n\nShe has 1000 grams of Moto and can make three kinds of doughnuts. If she makes one doughnut for each of the three kinds, she consumes 120 + 100 + 140 = 360 grams of Moto. From the 640 grams of Moto that remains here, she can make additional six Doughnuts 2. This is how she can made a total of nine doughnuts, which is the maximum.\n\nSample Input 2\n\n4 360\n90\n90\n90\n90\n\nSample Output 2\n\n4\n\nMaking one doughnut for each of the four kinds consumes all of her Moto.\n\nSample Input 3\n\n5 3000\n150\n130\n150\n130\n110\n\nSample Output 3\n\n26", "sample_input": "3 1000\n120\n100\n140\n"}, "reference_outputs": ["9\n"], "source_document_id": "p03370", "source_text": "Score : 200 points\n\nProblem Statement\n\nAkaki, a patissier, can make N kinds of doughnut using only a certain powder called \"Okashi no Moto\" (literally \"material of pastry\", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts.\n\nNow, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:\n\nFor each of the N kinds of doughnuts, make at least one doughnut of that kind.\n\nAt most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.\n\nConstraints\n\n2 ≤ N ≤ 100\n\n1 ≤ m_i ≤ 1000\n\nm_1 + m_2 + ... + m_N ≤ X ≤ 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X\nm_1\nm_2\n:\nm_N\n\nOutput\n\nPrint the maximum number of doughnuts that can be made under the condition.\n\nSample Input 1\n\n3 1000\n120\n100\n140\n\nSample Output 1\n\n9\n\nShe has 1000 grams of Moto and can make three kinds of doughnuts. If she makes one doughnut for each of the three kinds, she consumes 120 + 100 + 140 = 360 grams of Moto. From the 640 grams of Moto that remains here, she can make additional six Doughnuts 2. This is how she can made a total of nine doughnuts, which is the maximum.\n\nSample Input 2\n\n4 360\n90\n90\n90\n90\n\nSample Output 2\n\n4\n\nMaking one doughnut for each of the four kinds consumes all of her Moto.\n\nSample Input 3\n\n5 3000\n150\n130\n150\n130\n110\n\nSample Output 3\n\n26", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 139, "cpu_time_ms": 139, "memory_kb": 13152}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s329773485", "group_id": "codeNet:p03371", "input_text": "(let ((a (read))\n (b (read))\n (c (read))\n (x (read))\n (y (read))\n (ans 0))\n\n (loop for i from 0 to (max x y) do\n (let ((ab_count (* 2 i))\n (a_count (- x i))\n (b_count (- y i))\n (tmp 0))\n (if (< a_count 0) (setq a_count 0))\n (if (< b_count 0) (setq b_count 0))\n (setq tmp (+ (* a a_count) (* b b_count) (* c ab_count)))\n (if (or (= ans 0) (> ans tmp))\n (setq ans tmp)\n )\n )\n )\n (princ ans)\n)", "language": "Lisp", "metadata": {"date": 1594602550, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03371.html", "problem_id": "p03371", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03371/input.txt", "sample_output_relpath": "derived/input_output/data/p03371/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03371/Lisp/s329773485.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s329773485", "user_id": "u136500538"}, "prompt_components": {"gold_output": "7900\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (c (read))\n (x (read))\n (y (read))\n (ans 0))\n\n (loop for i from 0 to (max x y) do\n (let ((ab_count (* 2 i))\n (a_count (- x i))\n (b_count (- y i))\n (tmp 0))\n (if (< a_count 0) (setq a_count 0))\n (if (< b_count 0) (setq b_count 0))\n (setq tmp (+ (* a a_count) (* b b_count) (* c ab_count)))\n (if (or (= ans 0) (> ans tmp))\n (setq ans tmp)\n )\n )\n )\n (princ ans)\n)", "problem_context": "Score : 300 points\n\nProblem Statement\n\n\"Pizza At\", a fast food chain, offers three kinds of pizza: \"A-pizza\", \"B-pizza\" and \"AB-pizza\". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.\n\nNakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.\n\nConstraints\n\n1 ≤ A, B, C ≤ 5000\n\n1 ≤ X, Y ≤ 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C X Y\n\nOutput\n\nPrint the minimum amount of money required to prepare X A-pizzas and Y B-pizzas.\n\nSample Input 1\n\n1500 2000 1600 3 2\n\nSample Output 1\n\n7900\n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and two B-pizzas, then buy additional one A-pizza.\n\nSample Input 2\n\n1500 2000 1900 3 2\n\nSample Output 2\n\n8500\n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\nSample Input 3\n\n1500 2000 500 90000 100000\n\nSample Output 3\n\n100000000\n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas and 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that is fine.", "sample_input": "1500 2000 1600 3 2\n"}, "reference_outputs": ["7900\n"], "source_document_id": "p03371", "source_text": "Score : 300 points\n\nProblem Statement\n\n\"Pizza At\", a fast food chain, offers three kinds of pizza: \"A-pizza\", \"B-pizza\" and \"AB-pizza\". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.\n\nNakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.\n\nConstraints\n\n1 ≤ A, B, C ≤ 5000\n\n1 ≤ X, Y ≤ 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C X Y\n\nOutput\n\nPrint the minimum amount of money required to prepare X A-pizzas and Y B-pizzas.\n\nSample Input 1\n\n1500 2000 1600 3 2\n\nSample Output 1\n\n7900\n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and two B-pizzas, then buy additional one A-pizza.\n\nSample Input 2\n\n1500 2000 1900 3 2\n\nSample Output 2\n\n8500\n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\nSample Input 3\n\n1500 2000 500 90000 100000\n\nSample Output 3\n\n100000000\n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas and 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that is fine.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 531, "cpu_time_ms": 28, "memory_kb": 24224}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s479292463", "group_id": "codeNet:p03371", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun mapa-b (fn a b &optional (step 1))\n (do ((i a (+ i step))\n (result nil))\n ((> i b) (nreverse result))\n (push (funcall fn i) result)))\n\n(defun map0-n (fn n)\n (mapa-b fn 0 n))\n\n(defun map1-n (fn n)\n (mapa-b fn 1 n))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (is-empty char)\n do (return (concatenate 'string (nreverse result)))\n do (push char result))))\n\n\n(defun main (a b ab x y)\n (labels ((cul-cost (ab-time)\n (+ (* ab-time ab)\n (* (max 0 (- x (ash ab-time -1))) a)\n (* (max 0 (- y (ash ab-time -1))) b))))\n (reduce #'min (map0-n #'cul-cost (* (max x y) 2)))))\n\n\n(let ((a (read))\n (b (read))\n (ab (read))\n (x (read))\n (y (read)))\n (princ (main a b ab x y)))\n", "language": "Lisp", "metadata": {"date": 1589144450, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03371.html", "problem_id": "p03371", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03371/input.txt", "sample_output_relpath": "derived/input_output/data/p03371/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03371/Lisp/s479292463.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s479292463", "user_id": "u493610446"}, "prompt_components": {"gold_output": "7900\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun mapa-b (fn a b &optional (step 1))\n (do ((i a (+ i step))\n (result nil))\n ((> i b) (nreverse result))\n (push (funcall fn i) result)))\n\n(defun map0-n (fn n)\n (mapa-b fn 0 n))\n\n(defun map1-n (fn n)\n (mapa-b fn 1 n))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (is-empty char)\n do (return (concatenate 'string (nreverse result)))\n do (push char result))))\n\n\n(defun main (a b ab x y)\n (labels ((cul-cost (ab-time)\n (+ (* ab-time ab)\n (* (max 0 (- x (ash ab-time -1))) a)\n (* (max 0 (- y (ash ab-time -1))) b))))\n (reduce #'min (map0-n #'cul-cost (* (max x y) 2)))))\n\n\n(let ((a (read))\n (b (read))\n (ab (read))\n (x (read))\n (y (read)))\n (princ (main a b ab x y)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\n\"Pizza At\", a fast food chain, offers three kinds of pizza: \"A-pizza\", \"B-pizza\" and \"AB-pizza\". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.\n\nNakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.\n\nConstraints\n\n1 ≤ A, B, C ≤ 5000\n\n1 ≤ X, Y ≤ 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C X Y\n\nOutput\n\nPrint the minimum amount of money required to prepare X A-pizzas and Y B-pizzas.\n\nSample Input 1\n\n1500 2000 1600 3 2\n\nSample Output 1\n\n7900\n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and two B-pizzas, then buy additional one A-pizza.\n\nSample Input 2\n\n1500 2000 1900 3 2\n\nSample Output 2\n\n8500\n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\nSample Input 3\n\n1500 2000 500 90000 100000\n\nSample Output 3\n\n100000000\n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas and 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that is fine.", "sample_input": "1500 2000 1600 3 2\n"}, "reference_outputs": ["7900\n"], "source_document_id": "p03371", "source_text": "Score : 300 points\n\nProblem Statement\n\n\"Pizza At\", a fast food chain, offers three kinds of pizza: \"A-pizza\", \"B-pizza\" and \"AB-pizza\". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.\n\nNakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.\n\nConstraints\n\n1 ≤ A, B, C ≤ 5000\n\n1 ≤ X, Y ≤ 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C X Y\n\nOutput\n\nPrint the minimum amount of money required to prepare X A-pizzas and Y B-pizzas.\n\nSample Input 1\n\n1500 2000 1600 3 2\n\nSample Output 1\n\n7900\n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and two B-pizzas, then buy additional one A-pizza.\n\nSample Input 2\n\n1500 2000 1900 3 2\n\nSample Output 2\n\n8500\n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\nSample Input 3\n\n1500 2000 500 90000 100000\n\nSample Output 3\n\n100000000\n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas and 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that is fine.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2978, "cpu_time_ms": 162, "memory_kb": 23736}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s706525437", "group_id": "codeNet:p03371", "input_text": "(let* ((a (read))\n (b (read))\n (c (read))\n (x (read))\n (y (read)))\n (if (< (* 2 c) (* 2 (+ a b)))\n (princ (+ (* 2 c (min x y)) (* a (- x (min x y))) (* b (- y (min x y)))))\n (princ (+ (* a x) (* b y)))))", "language": "Lisp", "metadata": {"date": 1576520895, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03371.html", "problem_id": "p03371", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03371/input.txt", "sample_output_relpath": "derived/input_output/data/p03371/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03371/Lisp/s706525437.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s706525437", "user_id": "u610490393"}, "prompt_components": {"gold_output": "7900\n", "input_to_evaluate": "(let* ((a (read))\n (b (read))\n (c (read))\n (x (read))\n (y (read)))\n (if (< (* 2 c) (* 2 (+ a b)))\n (princ (+ (* 2 c (min x y)) (* a (- x (min x y))) (* b (- y (min x y)))))\n (princ (+ (* a x) (* b y)))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\n\"Pizza At\", a fast food chain, offers three kinds of pizza: \"A-pizza\", \"B-pizza\" and \"AB-pizza\". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.\n\nNakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.\n\nConstraints\n\n1 ≤ A, B, C ≤ 5000\n\n1 ≤ X, Y ≤ 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C X Y\n\nOutput\n\nPrint the minimum amount of money required to prepare X A-pizzas and Y B-pizzas.\n\nSample Input 1\n\n1500 2000 1600 3 2\n\nSample Output 1\n\n7900\n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and two B-pizzas, then buy additional one A-pizza.\n\nSample Input 2\n\n1500 2000 1900 3 2\n\nSample Output 2\n\n8500\n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\nSample Input 3\n\n1500 2000 500 90000 100000\n\nSample Output 3\n\n100000000\n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas and 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that is fine.", "sample_input": "1500 2000 1600 3 2\n"}, "reference_outputs": ["7900\n"], "source_document_id": "p03371", "source_text": "Score : 300 points\n\nProblem Statement\n\n\"Pizza At\", a fast food chain, offers three kinds of pizza: \"A-pizza\", \"B-pizza\" and \"AB-pizza\". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.\n\nNakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.\n\nConstraints\n\n1 ≤ A, B, C ≤ 5000\n\n1 ≤ X, Y ≤ 10^5\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C X Y\n\nOutput\n\nPrint the minimum amount of money required to prepare X A-pizzas and Y B-pizzas.\n\nSample Input 1\n\n1500 2000 1600 3 2\n\nSample Output 1\n\n7900\n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and two B-pizzas, then buy additional one A-pizza.\n\nSample Input 2\n\n1500 2000 1900 3 2\n\nSample Output 2\n\n8500\n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\nSample Input 3\n\n1500 2000 500 90000 100000\n\nSample Output 3\n\n100000000\n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas and 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that is fine.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 238, "cpu_time_ms": 13, "memory_kb": 3944}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s979560406", "group_id": "codeNet:p03377", "input_text": "(let((a(read))(b(read))(x(read)))(princ(if(<= a x (+ a b))\"YES\"\"NO\")))", "language": "Lisp", "metadata": {"date": 1525425140, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03377.html", "problem_id": "p03377", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03377/input.txt", "sample_output_relpath": "derived/input_output/data/p03377/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03377/Lisp/s979560406.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s979560406", "user_id": "u657913472"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(let((a(read))(b(read))(x(read)))(princ(if(<= a x (+ a b))\"YES\"\"NO\")))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are a total of A + B cats and dogs.\nAmong them, A are known to be cats, but the remaining B are not known to be either cats or dogs.\n\nDetermine if it is possible that there are exactly X cats among these A + B animals.\n\nConstraints\n\n1 \\leq A \\leq 100\n\n1 \\leq B \\leq 100\n\n1 \\leq X \\leq 200\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B X\n\nOutput\n\nIf it is possible that there are exactly X cats, print YES; if it is impossible, print NO.\n\nSample Input 1\n\n3 5 4\n\nSample Output 1\n\nYES\n\nIf there are one cat and four dogs among the B = 5 animals, there are X = 4 cats in total.\n\nSample Input 2\n\n2 2 6\n\nSample Output 2\n\nNO\n\nEven if all of the B = 2 animals are cats, there are less than X = 6 cats in total.\n\nSample Input 3\n\n5 3 2\n\nSample Output 3\n\nNO\n\nEven if all of the B = 3 animals are dogs, there are more than X = 2 cats in total.", "sample_input": "3 5 4\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03377", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are a total of A + B cats and dogs.\nAmong them, A are known to be cats, but the remaining B are not known to be either cats or dogs.\n\nDetermine if it is possible that there are exactly X cats among these A + B animals.\n\nConstraints\n\n1 \\leq A \\leq 100\n\n1 \\leq B \\leq 100\n\n1 \\leq X \\leq 200\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B X\n\nOutput\n\nIf it is possible that there are exactly X cats, print YES; if it is impossible, print NO.\n\nSample Input 1\n\n3 5 4\n\nSample Output 1\n\nYES\n\nIf there are one cat and four dogs among the B = 5 animals, there are X = 4 cats in total.\n\nSample Input 2\n\n2 2 6\n\nSample Output 2\n\nNO\n\nEven if all of the B = 2 animals are cats, there are less than X = 6 cats in total.\n\nSample Input 3\n\n5 3 2\n\nSample Output 3\n\nNO\n\nEven if all of the B = 3 animals are dogs, there are more than X = 2 cats in total.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 70, "cpu_time_ms": 48, "memory_kb": 5992}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s099616720", "group_id": "codeNet:p03379", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro with-output-buffer (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT (inline sort))\n (let* ((n (read))\n (xs (make-array n :element-type 'uint32))\n (sorted-xs (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (let ((x (read-fixnum)))\n (setf (aref xs i) x\n (aref sorted-xs i) x)))\n (setf sorted-xs (sort sorted-xs #'<))\n (with-output-buffer\n (let ((lo-x (aref sorted-xs (- (floor n 2) 1)))\n (hi-x (aref sorted-xs (floor n 2))))\n (loop for x across xs\n do (println (if (<= x lo-x)\n hi-x\n lo-x)))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1558842250, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03379.html", "problem_id": "p03379", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03379/input.txt", "sample_output_relpath": "derived/input_output/data/p03379/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03379/Lisp/s099616720.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s099616720", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n3\n3\n4\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro with-output-buffer (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT (inline sort))\n (let* ((n (read))\n (xs (make-array n :element-type 'uint32))\n (sorted-xs (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (let ((x (read-fixnum)))\n (setf (aref xs i) x\n (aref sorted-xs i) x)))\n (setf sorted-xs (sort sorted-xs #'<))\n (with-output-buffer\n (let ((lo-x (aref sorted-xs (- (floor n 2) 1)))\n (hi-x (aref sorted-xs (floor n 2))))\n (loop for x across xs\n do (println (if (<= x lo-x)\n hi-x\n lo-x)))))))\n\n#-swank(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWhen l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.\n\nYou are given N numbers X_1, X_2, ..., X_N, where N is an even number.\nFor each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.\n\nFind B_i for each i = 1, 2, ..., N.\n\nConstraints\n\n2 \\leq N \\leq 200000\n\nN is even.\n\n1 \\leq X_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nX_1 X_2 ... X_N\n\nOutput\n\nPrint N lines.\nThe i-th line should contain B_i.\n\nSample Input 1\n\n4\n2 4 4 3\n\nSample Output 1\n\n4\n3\n3\n4\n\nSince the median of X_2, X_3, X_4 is 4, B_1 = 4.\n\nSince the median of X_1, X_3, X_4 is 3, B_2 = 3.\n\nSince the median of X_1, X_2, X_4 is 3, B_3 = 3.\n\nSince the median of X_1, X_2, X_3 is 4, B_4 = 4.\n\nSample Input 2\n\n2\n1 2\n\nSample Output 2\n\n2\n1\n\nSample Input 3\n\n6\n5 5 4 4 3 3\n\nSample Output 3\n\n4\n4\n4\n4\n4\n4", "sample_input": "4\n2 4 4 3\n"}, "reference_outputs": ["4\n3\n3\n4\n"], "source_document_id": "p03379", "source_text": "Score : 300 points\n\nProblem Statement\n\nWhen l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.\n\nYou are given N numbers X_1, X_2, ..., X_N, where N is an even number.\nFor each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.\n\nFind B_i for each i = 1, 2, ..., N.\n\nConstraints\n\n2 \\leq N \\leq 200000\n\nN is even.\n\n1 \\leq X_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nX_1 X_2 ... X_N\n\nOutput\n\nPrint N lines.\nThe i-th line should contain B_i.\n\nSample Input 1\n\n4\n2 4 4 3\n\nSample Output 1\n\n4\n3\n3\n4\n\nSince the median of X_2, X_3, X_4 is 4, B_1 = 4.\n\nSince the median of X_1, X_3, X_4 is 3, B_2 = 3.\n\nSince the median of X_1, X_2, X_4 is 3, B_3 = 3.\n\nSince the median of X_1, X_2, X_3 is 4, B_4 = 4.\n\nSample Input 2\n\n2\n1 2\n\nSample Output 2\n\n2\n1\n\nSample Input 3\n\n6\n5 5 4 4 3 3\n\nSample Output 3\n\n4\n4\n4\n4\n4\n4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3399, "cpu_time_ms": 280, "memory_kb": 33252}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s147571114", "group_id": "codeNet:p03379", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare (inline sort))\n (let* ((n (read))\n (xs (make-array n :element-type 'uint32))\n (sorted-xs (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (let ((x (read-fixnum)))\n (setf (aref xs i) x\n (aref sorted-xs i) x)))\n (setf sorted-xs (sort sorted-xs #'<))\n (let ((mid (- (floor n 2) 1))\n (mid+1 (floor n 2)))\n (loop for x across xs\n do (if (<= x (aref sorted-xs mid))\n (println (aref sorted-xs mid+1))\n (println (aref sorted-xs mid)))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1558842146, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03379.html", "problem_id": "p03379", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03379/input.txt", "sample_output_relpath": "derived/input_output/data/p03379/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03379/Lisp/s147571114.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s147571114", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n3\n3\n4\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare (inline sort))\n (let* ((n (read))\n (xs (make-array n :element-type 'uint32))\n (sorted-xs (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (let ((x (read-fixnum)))\n (setf (aref xs i) x\n (aref sorted-xs i) x)))\n (setf sorted-xs (sort sorted-xs #'<))\n (let ((mid (- (floor n 2) 1))\n (mid+1 (floor n 2)))\n (loop for x across xs\n do (if (<= x (aref sorted-xs mid))\n (println (aref sorted-xs mid+1))\n (println (aref sorted-xs mid)))))))\n\n#-swank(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWhen l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.\n\nYou are given N numbers X_1, X_2, ..., X_N, where N is an even number.\nFor each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.\n\nFind B_i for each i = 1, 2, ..., N.\n\nConstraints\n\n2 \\leq N \\leq 200000\n\nN is even.\n\n1 \\leq X_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nX_1 X_2 ... X_N\n\nOutput\n\nPrint N lines.\nThe i-th line should contain B_i.\n\nSample Input 1\n\n4\n2 4 4 3\n\nSample Output 1\n\n4\n3\n3\n4\n\nSince the median of X_2, X_3, X_4 is 4, B_1 = 4.\n\nSince the median of X_1, X_3, X_4 is 3, B_2 = 3.\n\nSince the median of X_1, X_2, X_4 is 3, B_3 = 3.\n\nSince the median of X_1, X_2, X_3 is 4, B_4 = 4.\n\nSample Input 2\n\n2\n1 2\n\nSample Output 2\n\n2\n1\n\nSample Input 3\n\n6\n5 5 4 4 3 3\n\nSample Output 3\n\n4\n4\n4\n4\n4\n4", "sample_input": "4\n2 4 4 3\n"}, "reference_outputs": ["4\n3\n3\n4\n"], "source_document_id": "p03379", "source_text": "Score : 300 points\n\nProblem Statement\n\nWhen l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.\n\nYou are given N numbers X_1, X_2, ..., X_N, where N is an even number.\nFor each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.\n\nFind B_i for each i = 1, 2, ..., N.\n\nConstraints\n\n2 \\leq N \\leq 200000\n\nN is even.\n\n1 \\leq X_i \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nX_1 X_2 ... X_N\n\nOutput\n\nPrint N lines.\nThe i-th line should contain B_i.\n\nSample Input 1\n\n4\n2 4 4 3\n\nSample Output 1\n\n4\n3\n3\n4\n\nSince the median of X_2, X_3, X_4 is 4, B_1 = 4.\n\nSince the median of X_1, X_3, X_4 is 3, B_2 = 3.\n\nSince the median of X_1, X_2, X_4 is 3, B_3 = 3.\n\nSince the median of X_1, X_2, X_3 is 4, B_4 = 4.\n\nSample Input 2\n\n2\n1 2\n\nSample Output 2\n\n2\n1\n\nSample Input 3\n\n6\n5 5 4 4 3 3\n\nSample Output 3\n\n4\n4\n4\n4\n4\n4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2899, "cpu_time_ms": 761, "memory_kb": 33632}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s937947849", "group_id": "codeNet:p03380", "input_text": "(unless (member :child-sbcl *features*)\n #-swank (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\"\n \"--disable-ldb\"\n \"--lose-on-corruption\"\n \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(eval-when (:compile-toplevel)\n #-swank (proclaim '(optimize (speed 3) (debug 0) (safety 0))))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (labels ((array-reference-reader (stream c n)\n \"Reader macro #&(array index) => (aref array index)\"\n (declare (ignore c n))\n (let ((list (read stream)))\n `(aref ,(car list) ,@(cdr list)))))\n (setf *readtable* (copy-readtable))\n (set-dispatch-macro-character #\\# #\\& #'array-reference-reader)))\n\n(defconstant mod-number 1000000007)\n\n(defmacro let-if (var cond tbody &optional fbody)\n `(let ((,var ,cond))\n (if ,var\n ,tbody\n ,fbody)))\n\n(defmacro named-let (name binds &body body)\n (let ((params (mapcar #'car binds))\n (args (mapcar #'cadr binds)))\n `(labels ((,name (,@params)\n ,@body))\n (,name ,@args))))\n\n(defun unfold (p f g seed &optional (tail-gen (lambda () '())))\n (if (p seed)\n (tail-gen seed)\n (cons (f seed)\n (unfold p f g (g seed) tail-gen))))\n\n(defun iota (c &optional (s 0) (step 1) (acc nil))\n (if (zerop c)\n (nreverse acc)\n (iota (1- c) (+ s step) step (cons s acc))))\n\n(defun sum (list &optional (init 0))\n (reduce #'+ list :initial-value init))\n\n(defun chomp (str)\n (string-right-trim '(#\\Return #\\Linefeed) str))\n\n(defun diff (a b)\n (abs (- a b)))\n\n(defun read-integer (&optional (in *standard-input*))\n (declare (inline read-byte))\n (labels ((number-char-p (b)\n (<= #.(char-code #\\0) b #.(char-code #\\9)))\n (minus-char-p (b)\n (= b #.(char-code #\\-)))\n (to-number (b)\n (- b #.(char-code #\\0))))\n (declare (inline number-char-p minus-char-p to-number))\n (macrolet ((%read-byte ()\n '(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (read-byte in nil 0))))\n (let* ((minus-p nil)\n (x (loop for b = (%read-byte)\n if (number-char-p b)\n return (to-number b)\n end\n if (minus-char-p b)\n do (setf minus-p t))))\n (declare (boolean minus-p) (fixnum x))\n (the fixnum (loop for b = (%read-byte)\n and y = x then (+ (* y 10) (to-number b))\n unless (number-char-p b)\n return (funcall (if minus-p #'- #'+) y)))))))\n\n(defun split (x str &optional (acc nil))\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (split x (subseq str (+ pos size)) (cons (subseq str 0 pos) acc))\n (nreverse (cons str acc)))))\n\n(defmacro minf (field &rest x)\n `(setf ,field (min ,field ,@x)))\n\n(defmacro maxf (field &rest x)\n `(setf ,field (max ,field ,@x)))\n\n(defmacro debug-print (x)\n `(let ((y ,x))\n (format t \"~A: ~A~%\" ',x y)\n y))\n\n(eval-when (:compile-toplevel)\n (defun definput-helper-integer (bind)\n (let ((var (second bind)))\n `(defparameter ,var (read))))\n \n (defun definput-helper-string (bind))\n (defun set-read-to-array (type array dimensions)\n (let ((input (case (second type)\n ('integer #'read)\n ('string #'read-line)))\n (size (array-total-size array)))\n (dotimes (i size)\n (setf (row-major-aref array i) (funcall input)))))\n \n (defun definput-helper-array (bind)\n (destructuring-bind (type var dimensions) bind\n (if (atom dimensions)\n (setf dimensions (list dimensions)))\n `(prog1\n (defparameter ,var (make-array (mapcar #'symbol-value ',dimensions)))\n (set-read-to-array ',type ,var ',dimensions))))\n \n (defun definput-helper-list (bind)\n (let ((type (second (first bind)))\n (var (second bind))\n (size (third bind)))\n `(defparameter ,var\n (named-let rec ((i ,size)\n (acc nil))\n (if (zerop i)\n (nreverse acc)\n (rec (1- i)\n (cons (read) acc)))))))\n \n (defun definput-helper (bind)\n (let ((type (first bind)))\n (funcall (case type\n ('integer #'definput-helper-integer)\n ('string #'definput-helper-string)\n (otherwise (case (car type)\n ('array #'definput-helper-array)\n ('list #'definput-helper-list))))\n bind))))\n\n(defmacro definput (binds)\n (cons 'progn (mapcar #'definput-helper binds)))\n\n(defmacro defdp (name args &body body)\n (let ((argc (length args))\n (key (gensym)))\n `(let ((dp (make-hash-table :test #'equal)))\n (defun ,name ,args\n (let ((,key ,@(if (= argc 1) args `((list ,@args)))))\n (let-if memo (gethash ,key dp)\n memo\n (setf (gethash ,key dp)\n (progn ,@body))))))))\n\n;;; ここまで\n\n(definput\n ((integer n)\n ((list integer) a n)))\n\n(defparameter a-max (apply #'max a))\n\n(defun solve (x)\n (let ((center (floor a-max 2)))\n (if (evenp a-max)\n (min (diff center x) (diff (1+ center) x))\n (diff center x))))\n\n(format t \"~A ~A~%\" a-max (first (reduce\n (lambda (acc x)\n (let ((d (solve x)))\n (cond ((= x a-max) acc)\n ((< d (second acc)) (list x d))\n (t acc))))\n a\n :initial-value `(0 ,most-positive-fixnum))))\n\n", "language": "Lisp", "metadata": {"date": 1599095464, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03380.html", "problem_id": "p03380", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03380/input.txt", "sample_output_relpath": "derived/input_output/data/p03380/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03380/Lisp/s937947849.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s937947849", "user_id": "u684901760"}, "prompt_components": {"gold_output": "11 6\n", "input_to_evaluate": "(unless (member :child-sbcl *features*)\n #-swank (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\"\n \"--disable-ldb\"\n \"--lose-on-corruption\"\n \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(eval-when (:compile-toplevel)\n #-swank (proclaim '(optimize (speed 3) (debug 0) (safety 0))))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (labels ((array-reference-reader (stream c n)\n \"Reader macro #&(array index) => (aref array index)\"\n (declare (ignore c n))\n (let ((list (read stream)))\n `(aref ,(car list) ,@(cdr list)))))\n (setf *readtable* (copy-readtable))\n (set-dispatch-macro-character #\\# #\\& #'array-reference-reader)))\n\n(defconstant mod-number 1000000007)\n\n(defmacro let-if (var cond tbody &optional fbody)\n `(let ((,var ,cond))\n (if ,var\n ,tbody\n ,fbody)))\n\n(defmacro named-let (name binds &body body)\n (let ((params (mapcar #'car binds))\n (args (mapcar #'cadr binds)))\n `(labels ((,name (,@params)\n ,@body))\n (,name ,@args))))\n\n(defun unfold (p f g seed &optional (tail-gen (lambda () '())))\n (if (p seed)\n (tail-gen seed)\n (cons (f seed)\n (unfold p f g (g seed) tail-gen))))\n\n(defun iota (c &optional (s 0) (step 1) (acc nil))\n (if (zerop c)\n (nreverse acc)\n (iota (1- c) (+ s step) step (cons s acc))))\n\n(defun sum (list &optional (init 0))\n (reduce #'+ list :initial-value init))\n\n(defun chomp (str)\n (string-right-trim '(#\\Return #\\Linefeed) str))\n\n(defun diff (a b)\n (abs (- a b)))\n\n(defun read-integer (&optional (in *standard-input*))\n (declare (inline read-byte))\n (labels ((number-char-p (b)\n (<= #.(char-code #\\0) b #.(char-code #\\9)))\n (minus-char-p (b)\n (= b #.(char-code #\\-)))\n (to-number (b)\n (- b #.(char-code #\\0))))\n (declare (inline number-char-p minus-char-p to-number))\n (macrolet ((%read-byte ()\n '(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (read-byte in nil 0))))\n (let* ((minus-p nil)\n (x (loop for b = (%read-byte)\n if (number-char-p b)\n return (to-number b)\n end\n if (minus-char-p b)\n do (setf minus-p t))))\n (declare (boolean minus-p) (fixnum x))\n (the fixnum (loop for b = (%read-byte)\n and y = x then (+ (* y 10) (to-number b))\n unless (number-char-p b)\n return (funcall (if minus-p #'- #'+) y)))))))\n\n(defun split (x str &optional (acc nil))\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (split x (subseq str (+ pos size)) (cons (subseq str 0 pos) acc))\n (nreverse (cons str acc)))))\n\n(defmacro minf (field &rest x)\n `(setf ,field (min ,field ,@x)))\n\n(defmacro maxf (field &rest x)\n `(setf ,field (max ,field ,@x)))\n\n(defmacro debug-print (x)\n `(let ((y ,x))\n (format t \"~A: ~A~%\" ',x y)\n y))\n\n(eval-when (:compile-toplevel)\n (defun definput-helper-integer (bind)\n (let ((var (second bind)))\n `(defparameter ,var (read))))\n \n (defun definput-helper-string (bind))\n (defun set-read-to-array (type array dimensions)\n (let ((input (case (second type)\n ('integer #'read)\n ('string #'read-line)))\n (size (array-total-size array)))\n (dotimes (i size)\n (setf (row-major-aref array i) (funcall input)))))\n \n (defun definput-helper-array (bind)\n (destructuring-bind (type var dimensions) bind\n (if (atom dimensions)\n (setf dimensions (list dimensions)))\n `(prog1\n (defparameter ,var (make-array (mapcar #'symbol-value ',dimensions)))\n (set-read-to-array ',type ,var ',dimensions))))\n \n (defun definput-helper-list (bind)\n (let ((type (second (first bind)))\n (var (second bind))\n (size (third bind)))\n `(defparameter ,var\n (named-let rec ((i ,size)\n (acc nil))\n (if (zerop i)\n (nreverse acc)\n (rec (1- i)\n (cons (read) acc)))))))\n \n (defun definput-helper (bind)\n (let ((type (first bind)))\n (funcall (case type\n ('integer #'definput-helper-integer)\n ('string #'definput-helper-string)\n (otherwise (case (car type)\n ('array #'definput-helper-array)\n ('list #'definput-helper-list))))\n bind))))\n\n(defmacro definput (binds)\n (cons 'progn (mapcar #'definput-helper binds)))\n\n(defmacro defdp (name args &body body)\n (let ((argc (length args))\n (key (gensym)))\n `(let ((dp (make-hash-table :test #'equal)))\n (defun ,name ,args\n (let ((,key ,@(if (= argc 1) args `((list ,@args)))))\n (let-if memo (gethash ,key dp)\n memo\n (setf (gethash ,key dp)\n (progn ,@body))))))))\n\n;;; ここまで\n\n(definput\n ((integer n)\n ((list integer) a n)))\n\n(defparameter a-max (apply #'max a))\n\n(defun solve (x)\n (let ((center (floor a-max 2)))\n (if (evenp a-max)\n (min (diff center x) (diff (1+ center) x))\n (diff center x))))\n\n(format t \"~A ~A~%\" a-max (first (reduce\n (lambda (acc x)\n (let ((d (solve x)))\n (cond ((= x a-max) acc)\n ((< d (second acc)) (list x d))\n (t acc))))\n a\n :initial-value `(0 ,most-positive-fixnum))))\n\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nLet {\\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.\nFrom n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\\rm comb}(a_i,a_j) is maximized.\nIf there are multiple pairs that maximize the value, any of them is accepted.\n\nConstraints\n\n2 \\leq n \\leq 10^5\n\n0 \\leq a_i \\leq 10^9\n\na_1,a_2,...,a_n are pairwise distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\na_1 a_2 ... a_n\n\nOutput\n\nPrint a_i and a_j that you selected, with a space in between.\n\nSample Input 1\n\n5\n6 9 4 2 11\n\nSample Output 1\n\n11 6\n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n\\rm{comb}(4,2)=6\n\n\\rm{comb}(6,2)=15\n\n\\rm{comb}(6,4)=15\n\n\\rm{comb}(9,2)=36\n\n\\rm{comb}(9,4)=126\n\n\\rm{comb}(9,6)=84\n\n\\rm{comb}(11,2)=55\n\n\\rm{comb}(11,4)=330\n\n\\rm{comb}(11,6)=462\n\n\\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\nSample Input 2\n\n2\n100 0\n\nSample Output 2\n\n100 0", "sample_input": "5\n6 9 4 2 11\n"}, "reference_outputs": ["11 6\n"], "source_document_id": "p03380", "source_text": "Score : 400 points\n\nProblem Statement\n\nLet {\\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.\nFrom n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\\rm comb}(a_i,a_j) is maximized.\nIf there are multiple pairs that maximize the value, any of them is accepted.\n\nConstraints\n\n2 \\leq n \\leq 10^5\n\n0 \\leq a_i \\leq 10^9\n\na_1,a_2,...,a_n are pairwise distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\na_1 a_2 ... a_n\n\nOutput\n\nPrint a_i and a_j that you selected, with a space in between.\n\nSample Input 1\n\n5\n6 9 4 2 11\n\nSample Output 1\n\n11 6\n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n\\rm{comb}(4,2)=6\n\n\\rm{comb}(6,2)=15\n\n\\rm{comb}(6,4)=15\n\n\\rm{comb}(9,2)=36\n\n\\rm{comb}(9,4)=126\n\n\\rm{comb}(9,6)=84\n\n\\rm{comb}(11,2)=55\n\n\\rm{comb}(11,4)=330\n\n\\rm{comb}(11,6)=462\n\n\\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\nSample Input 2\n\n2\n100 0\n\nSample Output 2\n\n100 0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6346, "cpu_time_ms": 162, "memory_kb": 80616}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s835062751", "group_id": "codeNet:p03380", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))\n (declare (string string)\n (function key)\n ((array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop with position = 0\n for idx from offset below (length dest-vector)\n do (setf (values (aref dest-vector idx) position)\n (parse-integer string :start position :junk-allowed t))\n (setf (aref dest-vector idx) (funcall key (aref dest-vector idx)))\n finally (return dest-vector)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n(declaim ((simple-array double-float (*)) *bernoulli*))\n(defparameter *bernoulli*\n #.(coerce\n (mapcar (lambda (x) (float x 1d0))\n '(1 -1/2 1/6 0 -1/30 0 1/42 0 -1/30 0 5/66 0 -691/2730 0 7/6 0 -3617/510 0 43867/798 0 -174611/330 0 854513/138 0 -236364091/2730 0 8553103/6 0 -23749461029/870 0 8615841276005/14332))\n '(simple-array double-float (*))))\n\n(declaim (ftype (function * (values double-float &optional)) log-factorial))\n(defun log-factorial (n &optional (terms 2))\n (declare (optimize (speed 3) (safety 0))\n ((integer 0) n)\n ((unsigned-byte 8) terms))\n (let ((n (float n 1d0)))\n (+ #.(log (sqrt (* 2 pi)))\n (* (+ n 0.5d0) (log n))\n (- n)\n (loop for i2 from 2 to (* terms 2) by 2\n sum (/ (aref *bernoulli* i2)\n (* i2 (- i2 1) (expt n (- i2 1))))\n of-type double-float))))\n\n(defun log-binomial (n k &optional (terms 2))\n (declare ((integer 0) n k))\n (assert (>= n k))\n (if (zerop k)\n 1d0\n (- (log-factorial n terms)\n (log-factorial (- n k) terms)\n (log-factorial k terms))))\n\n(declaim (inline bisect-nearest))\n(defun bisect-nearest (value vector &key (start 0) end)\n (if (<= value (aref vector start))\n (aref vector start)\n (labels ((%bisect (lo hi)\n (declare ((integer 0 #.most-positive-fixnum) hi lo))\n (if (<= (- hi lo) 1)\n (if (or (= (length vector) hi)\n (>= (- (aref vector hi) value)\n (- value (aref vector lo))))\n (aref vector lo)\n (aref vector hi))\n (let ((mid (ash (+ hi lo) -1)))\n (if (<= (aref vector mid) value)\n (%bisect mid hi)\n (%bisect lo mid))))))\n (%bisect start (or end (length vector))))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint31)))\n (split-ints-into-vector (read-line) as)\n (setf as (sort as #'<))\n (loop for i from 1 below n\n with max = -1\n with a1 = -1\n with a2 = -1\n do (let* ((a/2 (bisect-nearest (* 0.5d0 (aref as i)) as :end i))\n (b (log-binomial (aref as i) a/2)))\n (when (< max b)\n (setf max b\n a1 (aref as i)\n a2 a/2)))\n finally (format t \"~A ~A~%\" a1 a2))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1549045109, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03380.html", "problem_id": "p03380", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03380/input.txt", "sample_output_relpath": "derived/input_output/data/p03380/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03380/Lisp/s835062751.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s835062751", "user_id": "u352600849"}, "prompt_components": {"gold_output": "11 6\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))\n (declare (string string)\n (function key)\n ((array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop with position = 0\n for idx from offset below (length dest-vector)\n do (setf (values (aref dest-vector idx) position)\n (parse-integer string :start position :junk-allowed t))\n (setf (aref dest-vector idx) (funcall key (aref dest-vector idx)))\n finally (return dest-vector)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n(declaim ((simple-array double-float (*)) *bernoulli*))\n(defparameter *bernoulli*\n #.(coerce\n (mapcar (lambda (x) (float x 1d0))\n '(1 -1/2 1/6 0 -1/30 0 1/42 0 -1/30 0 5/66 0 -691/2730 0 7/6 0 -3617/510 0 43867/798 0 -174611/330 0 854513/138 0 -236364091/2730 0 8553103/6 0 -23749461029/870 0 8615841276005/14332))\n '(simple-array double-float (*))))\n\n(declaim (ftype (function * (values double-float &optional)) log-factorial))\n(defun log-factorial (n &optional (terms 2))\n (declare (optimize (speed 3) (safety 0))\n ((integer 0) n)\n ((unsigned-byte 8) terms))\n (let ((n (float n 1d0)))\n (+ #.(log (sqrt (* 2 pi)))\n (* (+ n 0.5d0) (log n))\n (- n)\n (loop for i2 from 2 to (* terms 2) by 2\n sum (/ (aref *bernoulli* i2)\n (* i2 (- i2 1) (expt n (- i2 1))))\n of-type double-float))))\n\n(defun log-binomial (n k &optional (terms 2))\n (declare ((integer 0) n k))\n (assert (>= n k))\n (if (zerop k)\n 1d0\n (- (log-factorial n terms)\n (log-factorial (- n k) terms)\n (log-factorial k terms))))\n\n(declaim (inline bisect-nearest))\n(defun bisect-nearest (value vector &key (start 0) end)\n (if (<= value (aref vector start))\n (aref vector start)\n (labels ((%bisect (lo hi)\n (declare ((integer 0 #.most-positive-fixnum) hi lo))\n (if (<= (- hi lo) 1)\n (if (or (= (length vector) hi)\n (>= (- (aref vector hi) value)\n (- value (aref vector lo))))\n (aref vector lo)\n (aref vector hi))\n (let ((mid (ash (+ hi lo) -1)))\n (if (<= (aref vector mid) value)\n (%bisect mid hi)\n (%bisect lo mid))))))\n (%bisect start (or end (length vector))))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint31)))\n (split-ints-into-vector (read-line) as)\n (setf as (sort as #'<))\n (loop for i from 1 below n\n with max = -1\n with a1 = -1\n with a2 = -1\n do (let* ((a/2 (bisect-nearest (* 0.5d0 (aref as i)) as :end i))\n (b (log-binomial (aref as i) a/2)))\n (when (< max b)\n (setf max b\n a1 (aref as i)\n a2 a/2)))\n finally (format t \"~A ~A~%\" a1 a2))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nLet {\\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.\nFrom n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\\rm comb}(a_i,a_j) is maximized.\nIf there are multiple pairs that maximize the value, any of them is accepted.\n\nConstraints\n\n2 \\leq n \\leq 10^5\n\n0 \\leq a_i \\leq 10^9\n\na_1,a_2,...,a_n are pairwise distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\na_1 a_2 ... a_n\n\nOutput\n\nPrint a_i and a_j that you selected, with a space in between.\n\nSample Input 1\n\n5\n6 9 4 2 11\n\nSample Output 1\n\n11 6\n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n\\rm{comb}(4,2)=6\n\n\\rm{comb}(6,2)=15\n\n\\rm{comb}(6,4)=15\n\n\\rm{comb}(9,2)=36\n\n\\rm{comb}(9,4)=126\n\n\\rm{comb}(9,6)=84\n\n\\rm{comb}(11,2)=55\n\n\\rm{comb}(11,4)=330\n\n\\rm{comb}(11,6)=462\n\n\\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\nSample Input 2\n\n2\n100 0\n\nSample Output 2\n\n100 0", "sample_input": "5\n6 9 4 2 11\n"}, "reference_outputs": ["11 6\n"], "source_document_id": "p03380", "source_text": "Score : 400 points\n\nProblem Statement\n\nLet {\\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.\nFrom n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\\rm comb}(a_i,a_j) is maximized.\nIf there are multiple pairs that maximize the value, any of them is accepted.\n\nConstraints\n\n2 \\leq n \\leq 10^5\n\n0 \\leq a_i \\leq 10^9\n\na_1,a_2,...,a_n are pairwise distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\na_1 a_2 ... a_n\n\nOutput\n\nPrint a_i and a_j that you selected, with a space in between.\n\nSample Input 1\n\n5\n6 9 4 2 11\n\nSample Output 1\n\n11 6\n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n\\rm{comb}(4,2)=6\n\n\\rm{comb}(6,2)=15\n\n\\rm{comb}(6,4)=15\n\n\\rm{comb}(9,2)=36\n\n\\rm{comb}(9,4)=126\n\n\\rm{comb}(9,6)=84\n\n\\rm{comb}(11,2)=55\n\n\\rm{comb}(11,4)=330\n\n\\rm{comb}(11,6)=462\n\n\\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\nSample Input 2\n\n2\n100 0\n\nSample Output 2\n\n100 0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4049, "cpu_time_ms": 527, "memory_kb": 46816}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s016684569", "group_id": "codeNet:p03380", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))\n (declare (string string)\n (function key)\n ((array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop with position = 0\n for idx from offset below (length dest-vector)\n do (setf (values (aref dest-vector idx) position)\n (parse-integer string :start position :junk-allowed t))\n (setf (aref dest-vector idx) (funcall key (aref dest-vector idx)))\n finally (return dest-vector)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n(declaim ((simple-array double-float (*)) *bernoulli*))\n(defparameter *bernoulli*\n #.(coerce\n (mapcar (lambda (x) (float x 1d0))\n '(1 -1/2 1/6 0 -1/30 0 1/42 0 -1/30 0 5/66 0 -691/2730 0 7/6 0 -3617/510 0 43867/798 0 -174611/330 0 854513/138 0 -236364091/2730 0 8553103/6 0 -23749461029/870 0 8615841276005/14332))\n '(simple-array double-float (*))))\n\n(declaim (ftype (function * (values double-float &optional)) log-factorial))\n(defun log-factorial (n &optional (terms 2))\n (declare ((integer 0) n)\n ((unsigned-byte 8) terms))\n (let ((n (float n 1d0)))\n (+ #.(log (sqrt (* 2 pi)))\n (* (+ n 0.5d0) (log n))\n (- n)\n (loop for i2 from 2 to (* terms 2) by 2\n sum (/ (aref *bernoulli* i2)\n (* i2 (- i2 1) (expt n (- i2 1))))\n of-type double-float))))\n\n(defun log-binomial (n k &optional (terms 2))\n (declare ((integer 0) n k))\n (assert (>= n k))\n (if (zerop k)\n (float n 1d0)\n (- (log-factorial n terms)\n (log-factorial (- n k) terms)\n (log-factorial k terms))))\n\n(defun bisect-nearest (value vector &key (start 0) end)\n (if (<= value (aref vector start))\n (aref vector start)\n (labels ((%bisect (lo hi)\n (if (<= (- hi lo) 1)\n (if (or (= (length vector) hi)\n (>= (- (aref vector hi) value)\n (- value (aref vector lo))))\n (aref vector lo)\n (aref vector hi))\n (let ((mid (ash (+ hi lo) -1)))\n (if (<= (aref vector mid) value)\n (%bisect mid hi)\n (%bisect lo mid))))))\n (%bisect start (or end (length vector))))))\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint31)))\n (split-ints-into-vector (read-line) as)\n (setf as (sort as #'<))\n (loop for i from 1 below n\n with max = -1\n with a1 = -1\n with a2 = -1\n do (let* ((a/2 (bisect-nearest (* 0.5 (aref as i)) as :end i))\n (b (log-binomial (aref as i) a/2)))\n (when (< max b)\n (setf max b\n a1 (aref as i)\n a2 a/2)))\n finally (format t \"~A ~A~%\" a1 a2))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1549044063, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03380.html", "problem_id": "p03380", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03380/input.txt", "sample_output_relpath": "derived/input_output/data/p03380/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03380/Lisp/s016684569.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s016684569", "user_id": "u352600849"}, "prompt_components": {"gold_output": "11 6\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))\n (declare (string string)\n (function key)\n ((array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop with position = 0\n for idx from offset below (length dest-vector)\n do (setf (values (aref dest-vector idx) position)\n (parse-integer string :start position :junk-allowed t))\n (setf (aref dest-vector idx) (funcall key (aref dest-vector idx)))\n finally (return dest-vector)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n(declaim ((simple-array double-float (*)) *bernoulli*))\n(defparameter *bernoulli*\n #.(coerce\n (mapcar (lambda (x) (float x 1d0))\n '(1 -1/2 1/6 0 -1/30 0 1/42 0 -1/30 0 5/66 0 -691/2730 0 7/6 0 -3617/510 0 43867/798 0 -174611/330 0 854513/138 0 -236364091/2730 0 8553103/6 0 -23749461029/870 0 8615841276005/14332))\n '(simple-array double-float (*))))\n\n(declaim (ftype (function * (values double-float &optional)) log-factorial))\n(defun log-factorial (n &optional (terms 2))\n (declare ((integer 0) n)\n ((unsigned-byte 8) terms))\n (let ((n (float n 1d0)))\n (+ #.(log (sqrt (* 2 pi)))\n (* (+ n 0.5d0) (log n))\n (- n)\n (loop for i2 from 2 to (* terms 2) by 2\n sum (/ (aref *bernoulli* i2)\n (* i2 (- i2 1) (expt n (- i2 1))))\n of-type double-float))))\n\n(defun log-binomial (n k &optional (terms 2))\n (declare ((integer 0) n k))\n (assert (>= n k))\n (if (zerop k)\n (float n 1d0)\n (- (log-factorial n terms)\n (log-factorial (- n k) terms)\n (log-factorial k terms))))\n\n(defun bisect-nearest (value vector &key (start 0) end)\n (if (<= value (aref vector start))\n (aref vector start)\n (labels ((%bisect (lo hi)\n (if (<= (- hi lo) 1)\n (if (or (= (length vector) hi)\n (>= (- (aref vector hi) value)\n (- value (aref vector lo))))\n (aref vector lo)\n (aref vector hi))\n (let ((mid (ash (+ hi lo) -1)))\n (if (<= (aref vector mid) value)\n (%bisect mid hi)\n (%bisect lo mid))))))\n (%bisect start (or end (length vector))))))\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint31)))\n (split-ints-into-vector (read-line) as)\n (setf as (sort as #'<))\n (loop for i from 1 below n\n with max = -1\n with a1 = -1\n with a2 = -1\n do (let* ((a/2 (bisect-nearest (* 0.5 (aref as i)) as :end i))\n (b (log-binomial (aref as i) a/2)))\n (when (< max b)\n (setf max b\n a1 (aref as i)\n a2 a/2)))\n finally (format t \"~A ~A~%\" a1 a2))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nLet {\\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.\nFrom n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\\rm comb}(a_i,a_j) is maximized.\nIf there are multiple pairs that maximize the value, any of them is accepted.\n\nConstraints\n\n2 \\leq n \\leq 10^5\n\n0 \\leq a_i \\leq 10^9\n\na_1,a_2,...,a_n are pairwise distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\na_1 a_2 ... a_n\n\nOutput\n\nPrint a_i and a_j that you selected, with a space in between.\n\nSample Input 1\n\n5\n6 9 4 2 11\n\nSample Output 1\n\n11 6\n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n\\rm{comb}(4,2)=6\n\n\\rm{comb}(6,2)=15\n\n\\rm{comb}(6,4)=15\n\n\\rm{comb}(9,2)=36\n\n\\rm{comb}(9,4)=126\n\n\\rm{comb}(9,6)=84\n\n\\rm{comb}(11,2)=55\n\n\\rm{comb}(11,4)=330\n\n\\rm{comb}(11,6)=462\n\n\\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\nSample Input 2\n\n2\n100 0\n\nSample Output 2\n\n100 0", "sample_input": "5\n6 9 4 2 11\n"}, "reference_outputs": ["11 6\n"], "source_document_id": "p03380", "source_text": "Score : 400 points\n\nProblem Statement\n\nLet {\\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.\nFrom n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\\rm comb}(a_i,a_j) is maximized.\nIf there are multiple pairs that maximize the value, any of them is accepted.\n\nConstraints\n\n2 \\leq n \\leq 10^5\n\n0 \\leq a_i \\leq 10^9\n\na_1,a_2,...,a_n are pairwise distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\na_1 a_2 ... a_n\n\nOutput\n\nPrint a_i and a_j that you selected, with a space in between.\n\nSample Input 1\n\n5\n6 9 4 2 11\n\nSample Output 1\n\n11 6\n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n\\rm{comb}(4,2)=6\n\n\\rm{comb}(6,2)=15\n\n\\rm{comb}(6,4)=15\n\n\\rm{comb}(9,2)=36\n\n\\rm{comb}(9,4)=126\n\n\\rm{comb}(9,6)=84\n\n\\rm{comb}(11,2)=55\n\n\\rm{comb}(11,4)=330\n\n\\rm{comb}(11,6)=462\n\n\\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\nSample Input 2\n\n2\n100 0\n\nSample Output 2\n\n100 0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3892, "cpu_time_ms": 681, "memory_kb": 49760}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s389215586", "group_id": "codeNet:p03382", "input_text": "(defun input (n)\n (let ((a (make-array n)))\n (loop for i below n do (setf (aref a i) (read)))\n a)) \n\n(defun solve (n A)\n (let ((ans nil)\n (f 150000000)\n (maxi (reduce #'max A)))\n (loop for i from 0 below n \n for ai = (aref A i)\n for x = (abs (- (/ maxi 2) ai))\n when (and (< x f) (not (= ai maxi)))\n do (progn (setq ans ai)\n (setq f x)))\n (cons maxi ans))) \n\n(let* ((n (read))\n (a (input n))\n (e (solve n a)))\n (format t \"~A ~A~%\" (car e) (cdr e)))", "language": "Lisp", "metadata": {"date": 1523825524, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03382.html", "problem_id": "p03382", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03382/input.txt", "sample_output_relpath": "derived/input_output/data/p03382/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03382/Lisp/s389215586.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s389215586", "user_id": "u672956630"}, "prompt_components": {"gold_output": "11 6\n", "input_to_evaluate": "(defun input (n)\n (let ((a (make-array n)))\n (loop for i below n do (setf (aref a i) (read)))\n a)) \n\n(defun solve (n A)\n (let ((ans nil)\n (f 150000000)\n (maxi (reduce #'max A)))\n (loop for i from 0 below n \n for ai = (aref A i)\n for x = (abs (- (/ maxi 2) ai))\n when (and (< x f) (not (= ai maxi)))\n do (progn (setq ans ai)\n (setq f x)))\n (cons maxi ans))) \n\n(let* ((n (read))\n (a (input n))\n (e (solve n a)))\n (format t \"~A ~A~%\" (car e) (cdr e)))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nLet {\\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.\nFrom n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\\rm comb}(a_i,a_j) is maximized.\nIf there are multiple pairs that maximize the value, any of them is accepted.\n\nConstraints\n\n2 \\leq n \\leq 10^5\n\n0 \\leq a_i \\leq 10^9\n\na_1,a_2,...,a_n are pairwise distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\na_1 a_2 ... a_n\n\nOutput\n\nPrint a_i and a_j that you selected, with a space in between.\n\nSample Input 1\n\n5\n6 9 4 2 11\n\nSample Output 1\n\n11 6\n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n\\rm{comb}(4,2)=6\n\n\\rm{comb}(6,2)=15\n\n\\rm{comb}(6,4)=15\n\n\\rm{comb}(9,2)=36\n\n\\rm{comb}(9,4)=126\n\n\\rm{comb}(9,6)=84\n\n\\rm{comb}(11,2)=55\n\n\\rm{comb}(11,4)=330\n\n\\rm{comb}(11,6)=462\n\n\\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\nSample Input 2\n\n2\n100 0\n\nSample Output 2\n\n100 0", "sample_input": "5\n6 9 4 2 11\n"}, "reference_outputs": ["11 6\n"], "source_document_id": "p03382", "source_text": "Score : 400 points\n\nProblem Statement\n\nLet {\\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.\nFrom n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\\rm comb}(a_i,a_j) is maximized.\nIf there are multiple pairs that maximize the value, any of them is accepted.\n\nConstraints\n\n2 \\leq n \\leq 10^5\n\n0 \\leq a_i \\leq 10^9\n\na_1,a_2,...,a_n are pairwise distinct.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\na_1 a_2 ... a_n\n\nOutput\n\nPrint a_i and a_j that you selected, with a space in between.\n\nSample Input 1\n\n5\n6 9 4 2 11\n\nSample Output 1\n\n11 6\n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n\\rm{comb}(4,2)=6\n\n\\rm{comb}(6,2)=15\n\n\\rm{comb}(6,4)=15\n\n\\rm{comb}(9,2)=36\n\n\\rm{comb}(9,4)=126\n\n\\rm{comb}(9,6)=84\n\n\\rm{comb}(11,2)=55\n\n\\rm{comb}(11,4)=330\n\n\\rm{comb}(11,6)=462\n\n\\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\nSample Input 2\n\n2\n100 0\n\nSample Output 2\n\n100 0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 542, "cpu_time_ms": 366, "memory_kb": 67808}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s265549456", "group_id": "codeNet:p03385", "input_text": "(let ((s (concatenate 'string (sort (concatenate 'list (read-line))\n #'char-lessp))))\n\n (format t \"~A~%\"\n (if (string= s \"abc\")\n \"Yes\"\n \"No\")))\n", "language": "Lisp", "metadata": {"date": 1598681726, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03385.html", "problem_id": "p03385", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03385/input.txt", "sample_output_relpath": "derived/input_output/data/p03385/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03385/Lisp/s265549456.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s265549456", "user_id": "u336541610"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((s (concatenate 'string (sort (concatenate 'list (read-line))\n #'char-lessp))))\n\n (format t \"~A~%\"\n (if (string= s \"abc\")\n \"Yes\"\n \"No\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a string S of length 3 consisting of a, b and c. Determine if S can be obtained by permuting abc.\n\nConstraints\n\n|S|=3\n\nS consists of a, b and c.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S can be obtained by permuting abc, print Yes; otherwise, print No.\n\nSample Input 1\n\nbac\n\nSample Output 1\n\nYes\n\nSwapping the first and second characters in bac results in abc.\n\nSample Input 2\n\nbab\n\nSample Output 2\n\nNo\n\nSample Input 3\n\nabc\n\nSample Output 3\n\nYes\n\nSample Input 4\n\naaa\n\nSample Output 4\n\nNo", "sample_input": "bac\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03385", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a string S of length 3 consisting of a, b and c. Determine if S can be obtained by permuting abc.\n\nConstraints\n\n|S|=3\n\nS consists of a, b and c.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S can be obtained by permuting abc, print Yes; otherwise, print No.\n\nSample Input 1\n\nbac\n\nSample Output 1\n\nYes\n\nSwapping the first and second characters in bac results in abc.\n\nSample Input 2\n\nbab\n\nSample Output 2\n\nNo\n\nSample Input 3\n\nabc\n\nSample Output 3\n\nYes\n\nSample Input 4\n\naaa\n\nSample Output 4\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 211, "cpu_time_ms": 21, "memory_kb": 24108}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s961115809", "group_id": "codeNet:p03387", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun mapa-b (fn a b &optional (step 1))\n (do ((i a (+ i step))\n (result nil))\n ((> i b) (nreverse result))\n (push (funcall fn i) result)))\n\n(defun map0-n (fn n)\n (mapa-b fn 0 n))\n\n(defun map1-n (fn n)\n (mapa-b fn 1 n))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (is-empty char)\n do (return (concatenate 'string (nreverse result)))\n do (push char result))))\n\n(defun main (lst)\n (let* ((max (reduce #'max lst))\n (dis (- (* 3 max) (reduce #'+ lst))))\n (if (evenp dis)\n (/ dis 2)\n (/ (+ dis 3) 2))))\n\n(princ (main (read-times 3)))\n", "language": "Lisp", "metadata": {"date": 1589147319, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03387.html", "problem_id": "p03387", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03387/input.txt", "sample_output_relpath": "derived/input_output/data/p03387/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03387/Lisp/s961115809.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s961115809", "user_id": "u493610446"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun mapa-b (fn a b &optional (step 1))\n (do ((i a (+ i step))\n (result nil))\n ((> i b) (nreverse result))\n (push (funcall fn i) result)))\n\n(defun map0-n (fn n)\n (mapa-b fn 0 n))\n\n(defun map1-n (fn n)\n (mapa-b fn 1 n))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (is-empty char)\n do (return (concatenate 'string (nreverse result)))\n do (push char result))))\n\n(defun main (lst)\n (let* ((max (reduce #'max lst))\n (dis (- (* 3 max) (reduce #'+ lst))))\n (if (evenp dis)\n (/ dis 2)\n (/ (+ dis 3) 2))))\n\n(princ (main (read-times 3)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order:\n\nChoose two among A, B and C, then increase both by 1.\n\nChoose one among A, B and C, then increase it by 2.\n\nIt can be proved that we can always make A, B and C all equal by repeatedly performing these operations.\n\nConstraints\n\n0 \\leq A,B,C \\leq 50\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the minimum number of operations required to make A, B and C all equal.\n\nSample Input 1\n\n2 5 4\n\nSample Output 1\n\n2\n\nWe can make A, B and C all equal by the following operations:\n\nIncrease A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n\nIncrease A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\nSample Input 2\n\n2 6 3\n\nSample Output 2\n\n5\n\nSample Input 3\n\n31 41 5\n\nSample Output 3\n\n23", "sample_input": "2 5 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03387", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order:\n\nChoose two among A, B and C, then increase both by 1.\n\nChoose one among A, B and C, then increase it by 2.\n\nIt can be proved that we can always make A, B and C all equal by repeatedly performing these operations.\n\nConstraints\n\n0 \\leq A,B,C \\leq 50\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the minimum number of operations required to make A, B and C all equal.\n\nSample Input 1\n\n2 5 4\n\nSample Output 1\n\n2\n\nWe can make A, B and C all equal by the following operations:\n\nIncrease A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n\nIncrease A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\nSample Input 2\n\n2 6 3\n\nSample Output 2\n\n5\n\nSample Input 3\n\n31 41 5\n\nSample Output 3\n\n23", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2801, "cpu_time_ms": 55, "memory_kb": 13752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s168262128", "group_id": "codeNet:p03387", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((a (read))\n (b (read))\n (c (read))\n (res 0))\n (when (> a b) (rotatef a b))\n (when (> b c) (rotatef b c))\n (when (> a b) (rotatef a b))\n (loop (when (>= (+ a 1) c)\n (return))\n (incf a 2)\n (incf res))\n (loop (when (>= (+ b 1) c)\n (return))\n (incf b 2)\n (incf res))\n (dbg a b c)\n (println\n (cond ((= a b c) res)\n ((= (+ a 1) b c)\n (+ res 2))\n ((= a (+ b 1) c)\n (+ res 2))\n ((= (+ a 1) (+ b 1) c)\n (+ res 1))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 5 4\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 6 3\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"31 41 5\n\"\n \"23\n\")))\n", "language": "Lisp", "metadata": {"date": 1570765931, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03387.html", "problem_id": "p03387", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03387/input.txt", "sample_output_relpath": "derived/input_output/data/p03387/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03387/Lisp/s168262128.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s168262128", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((a (read))\n (b (read))\n (c (read))\n (res 0))\n (when (> a b) (rotatef a b))\n (when (> b c) (rotatef b c))\n (when (> a b) (rotatef a b))\n (loop (when (>= (+ a 1) c)\n (return))\n (incf a 2)\n (incf res))\n (loop (when (>= (+ b 1) c)\n (return))\n (incf b 2)\n (incf res))\n (dbg a b c)\n (println\n (cond ((= a b c) res)\n ((= (+ a 1) b c)\n (+ res 2))\n ((= a (+ b 1) c)\n (+ res 2))\n ((= (+ a 1) (+ b 1) c)\n (+ res 1))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 5 4\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 6 3\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"31 41 5\n\"\n \"23\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order:\n\nChoose two among A, B and C, then increase both by 1.\n\nChoose one among A, B and C, then increase it by 2.\n\nIt can be proved that we can always make A, B and C all equal by repeatedly performing these operations.\n\nConstraints\n\n0 \\leq A,B,C \\leq 50\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the minimum number of operations required to make A, B and C all equal.\n\nSample Input 1\n\n2 5 4\n\nSample Output 1\n\n2\n\nWe can make A, B and C all equal by the following operations:\n\nIncrease A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n\nIncrease A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\nSample Input 2\n\n2 6 3\n\nSample Output 2\n\n5\n\nSample Input 3\n\n31 41 5\n\nSample Output 3\n\n23", "sample_input": "2 5 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03387", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order:\n\nChoose two among A, B and C, then increase both by 1.\n\nChoose one among A, B and C, then increase it by 2.\n\nIt can be proved that we can always make A, B and C all equal by repeatedly performing these operations.\n\nConstraints\n\n0 \\leq A,B,C \\leq 50\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the minimum number of operations required to make A, B and C all equal.\n\nSample Input 1\n\n2 5 4\n\nSample Output 1\n\n2\n\nWe can make A, B and C all equal by the following operations:\n\nIncrease A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n\nIncrease A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\nSample Input 2\n\n2 6 3\n\nSample Output 2\n\n5\n\nSample Input 3\n\n31 41 5\n\nSample Output 3\n\n23", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4118, "cpu_time_ms": 221, "memory_kb": 15456}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s371647168", "group_id": "codeNet:p03395", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Memoization macro\n;;;\n\n;;\n;; Basic usage:\n;;\n;; (with-cache (:hash-table :test #'equal :key #'cons)\n;; (defun add (a b)\n;; (+ a b)))\n;; This function caches the returned values for already passed combinations of\n;; arguments. In this case ADD stores the key (CONS A B) and the returned value\n;; to a hash-table when (ADD A B) is evaluated for the first time. ADD returns\n;; the stored value when it is called with the same arguments (w.r.t. EQUAL)\n;; again.\n;;\n;; The storage for cache can be hash-table or array. Let's see an example for\n;; array:\n;; (with-cache (:array (10 20 30) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c) ... ))\n;; This form stores the value of FOO in an array created by (make-array (list 10\n;; 20 30) :initial-element -1 :element-type 'fixnum). Note that INITIAL-ELEMENT\n;; must always be given here as it is used as the flag expressing `not yet\n;; stored'. (Therefore INITIAL-ELEMENT should be a value FOO never takes.)\n;;\n;; If you want to ignore some arguments, you can put `*' in dimensions:\n;; (with-cache (:array (10 10 * 10) :initial-element -1)\n;; (defun foo (a b c d) ...)) ; then C is ignored when querying or storing cache\n;;\n;; Available definition forms in WITH-CACHE are DEFUN, LABELS, FLET, and\n;; SB-INT:NAMED-LET.\n;;\n;; You can trace the memoized function by :TRACE option:\n;; (with-cache (:array (10 10) :initial-element -1 :trace t)\n;; (defun foo (x y) ...))\n;; Then FOO is traced as with CL:TRACE.\n;;\n\n;; TODO & NOTE: Currently a memoized function is not enclosed with a block of\n;; the function name.\n\n;; FIXME: *RECURSION-DEPTH* should be included within the macro.\n(declaim (type (integer 0 #.most-positive-fixnum) *recursion-depth*))\n(defparameter *recursion-depth* 0)\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun %enclose-with-trace (fname args form)\n (let ((value (gensym)))\n `(progn\n (format t \"~&~A~A: (~A ~{~A~^ ~}) =>\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args))\n (let ((,value (let ((*recursion-depth* (1+ *recursion-depth*)))\n ,form)))\n (format t \"~&~A~A: (~A ~{~A~^ ~}) => ~A\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args)\n ,value)\n ,value))))\n\n (defun %extract-declarations (body)\n (remove-if-not (lambda (form) (and (consp form) (eql 'declare (car form))))\n body))\n\n (defun %parse-cache-form (cache-specifier)\n (let ((cache-type (car cache-specifier))\n (cache-attribs (cdr cache-specifier)))\n (assert (member cache-type '(:hash-table :array)))\n (let* ((dims-with-* (when (eql cache-type :array) (first cache-attribs)))\n (dims (remove '* dims-with-*))\n (rank (length dims))\n (rest-attribs (ecase cache-type\n (:hash-table cache-attribs)\n (:array (cdr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (trace-p (prog1 (getf rest-attribs :trace) (remf rest-attribs :trace)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array (list ,@dims) ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym \"CACHE\"))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels\n ((make-cache-querier (cache-type name args)\n (let ((res (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key '#'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (assert (= (length args) (length dims-with-*)))\n (let ((memoized-args (loop for dimension in dims-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value))))))))\n (if trace-p\n (%enclose-with-trace name args res)\n res)))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n ;; TODO: portable fill\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name)))))\n (values cache cache-form cache-type name-alias\n #'make-reset-name\n #'make-reset-form\n #'make-cache-querier)))))))\n\n(defmacro with-cache ((cache-type &rest cache-attribs) def-form)\n \"CACHE-TYPE := :HASH-TABLE | :ARRAY.\nDEF-FORM := definition form with DEFUN, LABELS, FLET, or SB-INT:NAMED-LET.\"\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form\n make-cache-querier)\n (%parse-cache-form (cons cache-type cache-attribs))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (defun ,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (defun ,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form)\n ((,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args)))\n ,@(cdr definitions))\n (declare (ignorable #',(funcall make-reset-name name)))\n ,@labels-body)))))\n ((nlet #+sbcl sb-int:named-let)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form) ,name ,bindings\n ,@(%extract-declarations body)\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))))))\n\n(defmacro with-caches (cache-specs def-form)\n \"DEF-FORM := definition form by LABELS or FLET.\n\n (with-caches (cache-spec1 cache-spec2)\n (labels ((f (x) ...) (g (y) ...))))\nis equivalent to the line up of\n (with-cache cache-spec1 (labels ((f (x) ...))))\nand\n (with-cache cache-spec2 (labels ((g (y) ...))))\n\nThis macro will be useful to do mutual recursion between memoized local\nfunctions.\"\n (assert (member (car def-form) '(labels flet)))\n (let (cache-symbol-list cache-form-list cache-type-list name-alias-list make-reset-name-list make-reset-form-list make-cache-querier-list)\n (dolist (cache-spec (reverse cache-specs))\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form make-cache-querier)\n (%parse-cache-form cache-spec)\n (push cache-symbol cache-symbol-list)\n (push cache-form cache-form-list)\n (push cache-type cache-type-list)\n (push name-alias name-alias-list)\n (push make-reset-name make-reset-name-list)\n (push make-reset-form make-reset-form-list)\n (push make-cache-querier make-cache-querier-list)))\n (labels ((def-name (def) (first def))\n (def-args (def) (second def))\n (def-body (def) (cddr def)))\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n `(let ,(loop for cache-symbol in cache-symbol-list\n for cache-form in cache-form-list\n collect `(,cache-symbol ,cache-form))\n (,(car def-form)\n (,@(loop for def in definitions\n for cache-type in cache-type-list\n for make-reset-name in make-reset-name-list\n for make-reset-form in make-reset-form-list\n collect `(,(funcall make-reset-name (def-name def)) ()\n ,(funcall make-reset-form cache-type)))\n ,@(loop for def in definitions\n for cache-type in cache-type-list\n for name-alias in name-alias-list\n for make-cache-querier in make-cache-querier-list\n collect `(,(def-name def) ,(def-args def)\n ,@(%extract-declarations (def-body def))\n (labels ((,name-alias ,(def-args def) ,@(def-body def)))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type (def-name def) (def-args def))))))\n (declare (ignorable ,@(loop for def in definitions\n for make-reset-name in make-reset-name-list\n collect `#',(funcall make-reset-name\n (def-name def)))))\n ,@labels-body))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n;; (defun proc1 (n as bs table)\n;; (let ((flags (make-array n :element-type ')))))\n\n;; (defun test (size)\n;; (let ((mat (make-array (list (+ size 1) (+ size 1))\n;; :element-type 'uint8\n;; :initial-element #xff)))\n;; (loop for y from 1 to size\n;; do (loop for x from (+ 1 (* 2 x)) to size\n;; do (let ((y y))\n;; (dotimes (i #x100)\n;; (when (= y x))))))))\n\n\n(defun preprocess ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint8))\n (bs (make-array n :element-type 'uint8)))\n (dotimes (i n)\n (setf (aref as i) (read)))\n (dotimes (i n)\n (setf (aref bs i) (read)))\n (loop named outer\n do (dotimes (i (length as) (return-from outer))\n (when (= (aref as i) (aref bs i))\n (setq as (concatenate '(simple-array uint8 (*))\n (subseq as 0 i) (subseq as (+ i 1))))\n (setq bs (concatenate '(simple-array uint8 (*))\n (subseq bs 0 i) (subseq bs (+ i 1))))\n (return))))\n (values (length as) as bs)))\n\n(defun calc-min (from to)\n (when (= from to)\n (return-from calc-min 0))\n (when (<= from (* 2 to))\n (return-from calc-min #xff))\n (let ((res 0))\n (loop\n ;; (dbg from to)\n (when (= from to)\n (return res))\n (loop for x from 1 to 100\n for rem = (mod from x)\n do (when (or (= rem to) (> rem (* 2 to)))\n (setq from rem)\n (setq res (max res x))\n (return))))))\n\n(defun main ()\n (multiple-value-bind (n as bs) (preprocess)\n (loop for a across as\n for b across bs\n unless (>= a (+ 1 (* 2 b)))\n do (println -1)\n (return-from main))\n (with-cache (:hash-table :test #'equal)\n (labels ((dp (x y bits)\n (dbg x y bits)\n (labels ((dfs (x pos)\n (cond ((= x y) 0)\n ((<= x (* 2 y)) #xff)\n ((= pos 0)\n (calc-min x y))\n ((and (<= pos x) (logbitp pos bits))\n (min (dfs (mod x pos) (- pos 1))\n (dfs x (- pos 1))))\n (t\n (dfs x (- pos 1))))))\n #>(dfs x 26))))\n (let ((bits 0))\n (loop repeat 10\n do (let ((x (loop for a across as\n for b across bs\n maximize (dp a b bits))))\n (when (zerop x)\n (return))\n (setf (ldb (byte 1 x) bits) 1))\n #>bits)\n (println bits))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n19 10 14\n0 3 4\n\"\n \"160\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n19 15 14\n0 0 0\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n8 13\n5 13\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n2 0 1 8\n2 0 1 8\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n50\n13\n\"\n \"137438953472\n\")))\n", "language": "Lisp", "metadata": {"date": 1584686593, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03395.html", "problem_id": "p03395", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03395/input.txt", "sample_output_relpath": "derived/input_output/data/p03395/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03395/Lisp/s371647168.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s371647168", "user_id": "u352600849"}, "prompt_components": {"gold_output": "160\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Memoization macro\n;;;\n\n;;\n;; Basic usage:\n;;\n;; (with-cache (:hash-table :test #'equal :key #'cons)\n;; (defun add (a b)\n;; (+ a b)))\n;; This function caches the returned values for already passed combinations of\n;; arguments. In this case ADD stores the key (CONS A B) and the returned value\n;; to a hash-table when (ADD A B) is evaluated for the first time. ADD returns\n;; the stored value when it is called with the same arguments (w.r.t. EQUAL)\n;; again.\n;;\n;; The storage for cache can be hash-table or array. Let's see an example for\n;; array:\n;; (with-cache (:array (10 20 30) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c) ... ))\n;; This form stores the value of FOO in an array created by (make-array (list 10\n;; 20 30) :initial-element -1 :element-type 'fixnum). Note that INITIAL-ELEMENT\n;; must always be given here as it is used as the flag expressing `not yet\n;; stored'. (Therefore INITIAL-ELEMENT should be a value FOO never takes.)\n;;\n;; If you want to ignore some arguments, you can put `*' in dimensions:\n;; (with-cache (:array (10 10 * 10) :initial-element -1)\n;; (defun foo (a b c d) ...)) ; then C is ignored when querying or storing cache\n;;\n;; Available definition forms in WITH-CACHE are DEFUN, LABELS, FLET, and\n;; SB-INT:NAMED-LET.\n;;\n;; You can trace the memoized function by :TRACE option:\n;; (with-cache (:array (10 10) :initial-element -1 :trace t)\n;; (defun foo (x y) ...))\n;; Then FOO is traced as with CL:TRACE.\n;;\n\n;; TODO & NOTE: Currently a memoized function is not enclosed with a block of\n;; the function name.\n\n;; FIXME: *RECURSION-DEPTH* should be included within the macro.\n(declaim (type (integer 0 #.most-positive-fixnum) *recursion-depth*))\n(defparameter *recursion-depth* 0)\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun %enclose-with-trace (fname args form)\n (let ((value (gensym)))\n `(progn\n (format t \"~&~A~A: (~A ~{~A~^ ~}) =>\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args))\n (let ((,value (let ((*recursion-depth* (1+ *recursion-depth*)))\n ,form)))\n (format t \"~&~A~A: (~A ~{~A~^ ~}) => ~A\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',fname\n (list ,@args)\n ,value)\n ,value))))\n\n (defun %extract-declarations (body)\n (remove-if-not (lambda (form) (and (consp form) (eql 'declare (car form))))\n body))\n\n (defun %parse-cache-form (cache-specifier)\n (let ((cache-type (car cache-specifier))\n (cache-attribs (cdr cache-specifier)))\n (assert (member cache-type '(:hash-table :array)))\n (let* ((dims-with-* (when (eql cache-type :array) (first cache-attribs)))\n (dims (remove '* dims-with-*))\n (rank (length dims))\n (rest-attribs (ecase cache-type\n (:hash-table cache-attribs)\n (:array (cdr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (trace-p (prog1 (getf rest-attribs :trace) (remf rest-attribs :trace)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array (list ,@dims) ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym \"CACHE\"))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels\n ((make-cache-querier (cache-type name args)\n (let ((res (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key '#'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (assert (= (length args) (length dims-with-*)))\n (let ((memoized-args (loop for dimension in dims-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value))))))))\n (if trace-p\n (%enclose-with-trace name args res)\n res)))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n ;; TODO: portable fill\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name)))))\n (values cache cache-form cache-type name-alias\n #'make-reset-name\n #'make-reset-form\n #'make-cache-querier)))))))\n\n(defmacro with-cache ((cache-type &rest cache-attribs) def-form)\n \"CACHE-TYPE := :HASH-TABLE | :ARRAY.\nDEF-FORM := definition form with DEFUN, LABELS, FLET, or SB-INT:NAMED-LET.\"\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form\n make-cache-querier)\n (%parse-cache-form (cons cache-type cache-attribs))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (defun ,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (defun ,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form)\n ((,(funcall make-reset-name name) ()\n ,(funcall make-reset-form cache-type))\n (,name ,args\n ,@(%extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args)))\n ,@(cdr definitions))\n (declare (ignorable #',(funcall make-reset-name name)))\n ,@labels-body)))))\n ((nlet #+sbcl sb-int:named-let)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache-symbol ,cache-form))\n (,(car def-form) ,name ,bindings\n ,@(%extract-declarations body)\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type name args))))))))))\n\n(defmacro with-caches (cache-specs def-form)\n \"DEF-FORM := definition form by LABELS or FLET.\n\n (with-caches (cache-spec1 cache-spec2)\n (labels ((f (x) ...) (g (y) ...))))\nis equivalent to the line up of\n (with-cache cache-spec1 (labels ((f (x) ...))))\nand\n (with-cache cache-spec2 (labels ((g (y) ...))))\n\nThis macro will be useful to do mutual recursion between memoized local\nfunctions.\"\n (assert (member (car def-form) '(labels flet)))\n (let (cache-symbol-list cache-form-list cache-type-list name-alias-list make-reset-name-list make-reset-form-list make-cache-querier-list)\n (dolist (cache-spec (reverse cache-specs))\n (multiple-value-bind (cache-symbol cache-form cache-type name-alias\n make-reset-name make-reset-form make-cache-querier)\n (%parse-cache-form cache-spec)\n (push cache-symbol cache-symbol-list)\n (push cache-form cache-form-list)\n (push cache-type cache-type-list)\n (push name-alias name-alias-list)\n (push make-reset-name make-reset-name-list)\n (push make-reset-form make-reset-form-list)\n (push make-cache-querier make-cache-querier-list)))\n (labels ((def-name (def) (first def))\n (def-args (def) (second def))\n (def-body (def) (cddr def)))\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n `(let ,(loop for cache-symbol in cache-symbol-list\n for cache-form in cache-form-list\n collect `(,cache-symbol ,cache-form))\n (,(car def-form)\n (,@(loop for def in definitions\n for cache-type in cache-type-list\n for make-reset-name in make-reset-name-list\n for make-reset-form in make-reset-form-list\n collect `(,(funcall make-reset-name (def-name def)) ()\n ,(funcall make-reset-form cache-type)))\n ,@(loop for def in definitions\n for cache-type in cache-type-list\n for name-alias in name-alias-list\n for make-cache-querier in make-cache-querier-list\n collect `(,(def-name def) ,(def-args def)\n ,@(%extract-declarations (def-body def))\n (labels ((,name-alias ,(def-args def) ,@(def-body def)))\n (declare (inline ,name-alias))\n ,(funcall make-cache-querier cache-type (def-name def) (def-args def))))))\n (declare (ignorable ,@(loop for def in definitions\n for make-reset-name in make-reset-name-list\n collect `#',(funcall make-reset-name\n (def-name def)))))\n ,@labels-body))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n;; (defun proc1 (n as bs table)\n;; (let ((flags (make-array n :element-type ')))))\n\n;; (defun test (size)\n;; (let ((mat (make-array (list (+ size 1) (+ size 1))\n;; :element-type 'uint8\n;; :initial-element #xff)))\n;; (loop for y from 1 to size\n;; do (loop for x from (+ 1 (* 2 x)) to size\n;; do (let ((y y))\n;; (dotimes (i #x100)\n;; (when (= y x))))))))\n\n\n(defun preprocess ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint8))\n (bs (make-array n :element-type 'uint8)))\n (dotimes (i n)\n (setf (aref as i) (read)))\n (dotimes (i n)\n (setf (aref bs i) (read)))\n (loop named outer\n do (dotimes (i (length as) (return-from outer))\n (when (= (aref as i) (aref bs i))\n (setq as (concatenate '(simple-array uint8 (*))\n (subseq as 0 i) (subseq as (+ i 1))))\n (setq bs (concatenate '(simple-array uint8 (*))\n (subseq bs 0 i) (subseq bs (+ i 1))))\n (return))))\n (values (length as) as bs)))\n\n(defun calc-min (from to)\n (when (= from to)\n (return-from calc-min 0))\n (when (<= from (* 2 to))\n (return-from calc-min #xff))\n (let ((res 0))\n (loop\n ;; (dbg from to)\n (when (= from to)\n (return res))\n (loop for x from 1 to 100\n for rem = (mod from x)\n do (when (or (= rem to) (> rem (* 2 to)))\n (setq from rem)\n (setq res (max res x))\n (return))))))\n\n(defun main ()\n (multiple-value-bind (n as bs) (preprocess)\n (loop for a across as\n for b across bs\n unless (>= a (+ 1 (* 2 b)))\n do (println -1)\n (return-from main))\n (with-cache (:hash-table :test #'equal)\n (labels ((dp (x y bits)\n (dbg x y bits)\n (labels ((dfs (x pos)\n (cond ((= x y) 0)\n ((<= x (* 2 y)) #xff)\n ((= pos 0)\n (calc-min x y))\n ((and (<= pos x) (logbitp pos bits))\n (min (dfs (mod x pos) (- pos 1))\n (dfs x (- pos 1))))\n (t\n (dfs x (- pos 1))))))\n #>(dfs x 26))))\n (let ((bits 0))\n (loop repeat 10\n do (let ((x (loop for a across as\n for b across bs\n maximize (dp a b bits))))\n (when (zerop x)\n (return))\n (setf (ldb (byte 1 x) bits) 1))\n #>bits)\n (println bits))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n19 10 14\n0 3 4\n\"\n \"160\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n19 15 14\n0 0 0\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n8 13\n5 13\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n2 0 1 8\n2 0 1 8\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n50\n13\n\"\n \"137438953472\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nAoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :\n\nChoose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).\n\nAoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.\n\nConstraints\n\n1 \\leq N \\leq 50\n\n0 \\leq a_{i}, b_{i} \\leq 50\n\nAll values in the input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_{1} a_{2} ... a_{N}\nb_{1} b_{2} ... b_{N}\n\nOutput\n\nPrint the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.\n\nSample Input 1\n\n3\n19 10 14\n0 3 4\n\nSample Output 1\n\n160\n\nHere's a possible sequence of operations :\n\nChoose k = 7. Replace 19 with 5, 10 with 3 and do nothing to 14. The sequence is now 5, 3, 14.\n\nChoose k = 5. Replace 5 with 0, do nothing to 3 and replace 14 with 4. The sequence is now 0, 3, 4.\n\nThe total cost is 2^{7} + 2^{5} = 160.\n\nSample Input 2\n\n3\n19 15 14\n0 0 0\n\nSample Output 2\n\n2\n\nAoki can just choose k = 1 and turn everything into 0. The cost is 2^{1} = 2.\n\nSample Input 3\n\n2\n8 13\n5 13\n\nSample Output 3\n\n-1\n\nThe task is impossible because we can never turn 8 into 5 using the given operation.\n\nSample Input 4\n\n4\n2 0 1 8\n2 0 1 8\n\nSample Output 4\n\n0\n\nAoki doesn't need to do anything here. The cost is 0.\n\nSample Input 5\n\n1\n50\n13\n\nSample Output 5\n\n137438953472\n\nBeware of overflow issues.", "sample_input": "3\n19 10 14\n0 3 4\n"}, "reference_outputs": ["160\n"], "source_document_id": "p03395", "source_text": "Score : 700 points\n\nProblem Statement\n\nAoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :\n\nChoose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).\n\nAoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.\n\nConstraints\n\n1 \\leq N \\leq 50\n\n0 \\leq a_{i}, b_{i} \\leq 50\n\nAll values in the input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_{1} a_{2} ... a_{N}\nb_{1} b_{2} ... b_{N}\n\nOutput\n\nPrint the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.\n\nSample Input 1\n\n3\n19 10 14\n0 3 4\n\nSample Output 1\n\n160\n\nHere's a possible sequence of operations :\n\nChoose k = 7. Replace 19 with 5, 10 with 3 and do nothing to 14. The sequence is now 5, 3, 14.\n\nChoose k = 5. Replace 5 with 0, do nothing to 3 and replace 14 with 4. The sequence is now 0, 3, 4.\n\nThe total cost is 2^{7} + 2^{5} = 160.\n\nSample Input 2\n\n3\n19 15 14\n0 0 0\n\nSample Output 2\n\n2\n\nAoki can just choose k = 1 and turn everything into 0. The cost is 2^{1} = 2.\n\nSample Input 3\n\n2\n8 13\n5 13\n\nSample Output 3\n\n-1\n\nThe task is impossible because we can never turn 8 into 5 using the given operation.\n\nSample Input 4\n\n4\n2 0 1 8\n2 0 1 8\n\nSample Output 4\n\n0\n\nAoki doesn't need to do anything here. The cost is 0.\n\nSample Input 5\n\n1\n50\n13\n\nSample Output 5\n\n137438953472\n\nBeware of overflow issues.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 18775, "cpu_time_ms": 266, "memory_kb": 34788}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s214833276", "group_id": "codeNet:p03407", "input_text": "(let ((a (read))\n (b (read))\n (c (read)))\n (if (>= (+ a b) c) (princ \"Yes\") (princ \"No\")))", "language": "Lisp", "metadata": {"date": 1540862615, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03407.html", "problem_id": "p03407", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03407/input.txt", "sample_output_relpath": "derived/input_output/data/p03407/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03407/Lisp/s214833276.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s214833276", "user_id": "u610490393"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (c (read)))\n (if (>= (+ a b) c) (princ \"Yes\") (princ \"No\")))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nAn elementary school student Takahashi has come to a variety store.\n\nHe has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it?\n\nNote that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.\n\nConstraints\n\nAll input values are integers.\n\n1 \\leq A, B \\leq 500\n\n1 \\leq C \\leq 1000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf Takahashi can buy the toy, print Yes; if he cannot, print No.\n\nSample Input 1\n\n50 100 120\n\nSample Output 1\n\nYes\n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\nSample Input 2\n\n500 100 1000\n\nSample Output 2\n\nNo\n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\nSample Input 3\n\n19 123 143\n\nSample Output 3\n\nNo\n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard to use.\n\nSample Input 4\n\n19 123 142\n\nSample Output 4\n\nYes", "sample_input": "50 100 120\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03407", "source_text": "Score : 100 points\n\nProblem Statement\n\nAn elementary school student Takahashi has come to a variety store.\n\nHe has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it?\n\nNote that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.\n\nConstraints\n\nAll input values are integers.\n\n1 \\leq A, B \\leq 500\n\n1 \\leq C \\leq 1000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf Takahashi can buy the toy, print Yes; if he cannot, print No.\n\nSample Input 1\n\n50 100 120\n\nSample Output 1\n\nYes\n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\nSample Input 2\n\n500 100 1000\n\nSample Output 2\n\nNo\n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\nSample Input 3\n\n19 123 143\n\nSample Output 3\n\nNo\n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard to use.\n\nSample Input 4\n\n19 123 142\n\nSample Output 4\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 101, "cpu_time_ms": 156, "memory_kb": 10596}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s472553986", "group_id": "codeNet:p03407", "input_text": "(princ (if (< (+ (read) (read)) (read)) \"NO\" \"YES\")) (format t \"~%\")\n", "language": "Lisp", "metadata": {"date": 1522539059, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03407.html", "problem_id": "p03407", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03407/input.txt", "sample_output_relpath": "derived/input_output/data/p03407/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03407/Lisp/s472553986.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s472553986", "user_id": "u948374595"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(princ (if (< (+ (read) (read)) (read)) \"NO\" \"YES\")) (format t \"~%\")\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nAn elementary school student Takahashi has come to a variety store.\n\nHe has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it?\n\nNote that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.\n\nConstraints\n\nAll input values are integers.\n\n1 \\leq A, B \\leq 500\n\n1 \\leq C \\leq 1000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf Takahashi can buy the toy, print Yes; if he cannot, print No.\n\nSample Input 1\n\n50 100 120\n\nSample Output 1\n\nYes\n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\nSample Input 2\n\n500 100 1000\n\nSample Output 2\n\nNo\n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\nSample Input 3\n\n19 123 143\n\nSample Output 3\n\nNo\n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard to use.\n\nSample Input 4\n\n19 123 142\n\nSample Output 4\n\nYes", "sample_input": "50 100 120\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03407", "source_text": "Score : 100 points\n\nProblem Statement\n\nAn elementary school student Takahashi has come to a variety store.\n\nHe has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it?\n\nNote that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.\n\nConstraints\n\nAll input values are integers.\n\n1 \\leq A, B \\leq 500\n\n1 \\leq C \\leq 1000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf Takahashi can buy the toy, print Yes; if he cannot, print No.\n\nSample Input 1\n\n50 100 120\n\nSample Output 1\n\nYes\n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\nSample Input 2\n\n500 100 1000\n\nSample Output 2\n\nNo\n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\nSample Input 3\n\n19 123 143\n\nSample Output 3\n\nNo\n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard to use.\n\nSample Input 4\n\n19 123 142\n\nSample Output 4\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 69, "cpu_time_ms": 5, "memory_kb": 2792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s356548392", "group_id": "codeNet:p03408", "input_text": "(let* ((n (read))\n (l1 (loop repeat n\n collect (read-line)))\n (m (read))\n (l2 (loop repeat m\n collect (read-line))))\n (format t \"~A~%\"\n (max 0\n (loop for i in l1\n maximize (- (count i l1 :test #'string=) (count i l2 :test #'string=))))))\n", "language": "Lisp", "metadata": {"date": 1598594660, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03408.html", "problem_id": "p03408", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03408/input.txt", "sample_output_relpath": "derived/input_output/data/p03408/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03408/Lisp/s356548392.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s356548392", "user_id": "u336541610"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (read))\n (l1 (loop repeat n\n collect (read-line)))\n (m (read))\n (l2 (loop repeat m\n collect (read-line))))\n (format t \"~A~%\"\n (max 0\n (loop for i in l1\n maximize (- (count i l1 :test #'string=) (count i l2 :test #'string=))))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi has N blue cards and M red cards.\nA string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i.\n\nTakahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen.\n\nHere, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces atcoder, he will not earn money even if there are blue cards with atcoderr, atcode, btcoder, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.)\n\nAt most how much can he earn on balance?\n\nNote that the same string may be written on multiple cards.\n\nConstraints\n\nN and M are integers.\n\n1 \\leq N, M \\leq 100\n\ns_1, s_2, ..., s_N, t_1, t_2, ..., t_M are all strings of lengths between 1 and 10 (inclusive) consisting of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\ns_1\ns_2\n:\ns_N\nM\nt_1\nt_2\n:\nt_M\n\nOutput\n\nIf Takahashi can earn at most X yen on balance, print X.\n\nSample Input 1\n\n3\napple\norange\napple\n1\ngrape\n\nSample Output 1\n\n2\n\nHe can earn 2 yen by announcing apple.\n\nSample Input 2\n\n3\napple\norange\napple\n5\napple\napple\napple\napple\napple\n\nSample Output 2\n\n1\n\nIf he announces apple, he will lose 3 yen. If he announces orange, he can earn 1 yen.\n\nSample Input 3\n\n1\nvoldemort\n10\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\n\nSample Output 3\n\n0\n\nIf he announces voldemort, he will lose 9 yen. If he announces orange, for example, he can avoid losing a yen.\n\nSample Input 4\n\n6\nred\nred\nblue\nyellow\nyellow\nred\n5\nred\nred\nyellow\ngreen\nblue\n\nSample Output 4\n\n1", "sample_input": "3\napple\norange\napple\n1\ngrape\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03408", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi has N blue cards and M red cards.\nA string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i.\n\nTakahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen.\n\nHere, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces atcoder, he will not earn money even if there are blue cards with atcoderr, atcode, btcoder, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.)\n\nAt most how much can he earn on balance?\n\nNote that the same string may be written on multiple cards.\n\nConstraints\n\nN and M are integers.\n\n1 \\leq N, M \\leq 100\n\ns_1, s_2, ..., s_N, t_1, t_2, ..., t_M are all strings of lengths between 1 and 10 (inclusive) consisting of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\ns_1\ns_2\n:\ns_N\nM\nt_1\nt_2\n:\nt_M\n\nOutput\n\nIf Takahashi can earn at most X yen on balance, print X.\n\nSample Input 1\n\n3\napple\norange\napple\n1\ngrape\n\nSample Output 1\n\n2\n\nHe can earn 2 yen by announcing apple.\n\nSample Input 2\n\n3\napple\norange\napple\n5\napple\napple\napple\napple\napple\n\nSample Output 2\n\n1\n\nIf he announces apple, he will lose 3 yen. If he announces orange, he can earn 1 yen.\n\nSample Input 3\n\n1\nvoldemort\n10\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\n\nSample Output 3\n\n0\n\nIf he announces voldemort, he will lose 9 yen. If he announces orange, for example, he can avoid losing a yen.\n\nSample Input 4\n\n6\nred\nred\nblue\nyellow\nyellow\nred\n5\nred\nred\nyellow\ngreen\nblue\n\nSample Output 4\n\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 332, "cpu_time_ms": 18, "memory_kb": 24516}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s751337189", "group_id": "codeNet:p03408", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun mapa-b (fn a b &optional (step 1))\n (do ((i a (+ i step))\n (result nil))\n ((> i b) (nreverse result))\n (push (funcall fn i) result)))\n\n(defun map0-n (fn n)\n (mapa-b fn 0 n))\n\n(defun map1-n (fn n)\n (mapa-b fn 1 n))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (is-empty char)\n do (return (concatenate 'string (nreverse result)))\n do (push char result))))\n\n(defun main (a b)\n (reduce #'max\n (mapcar (lambda (x) (- (count x a :test #'equal)\n (count x b :test #'equal)))\n a)\n :initial-value 0))\n\n(princ (main (collect-times (read) (read-string)) (collect-times (read) (read-string))))\n", "language": "Lisp", "metadata": {"date": 1589147104, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03408.html", "problem_id": "p03408", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03408/input.txt", "sample_output_relpath": "derived/input_output/data/p03408/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03408/Lisp/s751337189.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s751337189", "user_id": "u493610446"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun mapa-b (fn a b &optional (step 1))\n (do ((i a (+ i step))\n (result nil))\n ((> i b) (nreverse result))\n (push (funcall fn i) result)))\n\n(defun map0-n (fn n)\n (mapa-b fn 0 n))\n\n(defun map1-n (fn n)\n (mapa-b fn 1 n))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (is-empty char)\n do (return (concatenate 'string (nreverse result)))\n do (push char result))))\n\n(defun main (a b)\n (reduce #'max\n (mapcar (lambda (x) (- (count x a :test #'equal)\n (count x b :test #'equal)))\n a)\n :initial-value 0))\n\n(princ (main (collect-times (read) (read-string)) (collect-times (read) (read-string))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi has N blue cards and M red cards.\nA string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i.\n\nTakahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen.\n\nHere, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces atcoder, he will not earn money even if there are blue cards with atcoderr, atcode, btcoder, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.)\n\nAt most how much can he earn on balance?\n\nNote that the same string may be written on multiple cards.\n\nConstraints\n\nN and M are integers.\n\n1 \\leq N, M \\leq 100\n\ns_1, s_2, ..., s_N, t_1, t_2, ..., t_M are all strings of lengths between 1 and 10 (inclusive) consisting of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\ns_1\ns_2\n:\ns_N\nM\nt_1\nt_2\n:\nt_M\n\nOutput\n\nIf Takahashi can earn at most X yen on balance, print X.\n\nSample Input 1\n\n3\napple\norange\napple\n1\ngrape\n\nSample Output 1\n\n2\n\nHe can earn 2 yen by announcing apple.\n\nSample Input 2\n\n3\napple\norange\napple\n5\napple\napple\napple\napple\napple\n\nSample Output 2\n\n1\n\nIf he announces apple, he will lose 3 yen. If he announces orange, he can earn 1 yen.\n\nSample Input 3\n\n1\nvoldemort\n10\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\n\nSample Output 3\n\n0\n\nIf he announces voldemort, he will lose 9 yen. If he announces orange, for example, he can avoid losing a yen.\n\nSample Input 4\n\n6\nred\nred\nblue\nyellow\nyellow\nred\n5\nred\nred\nyellow\ngreen\nblue\n\nSample Output 4\n\n1", "sample_input": "3\napple\norange\napple\n1\ngrape\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03408", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi has N blue cards and M red cards.\nA string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i.\n\nTakahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen.\n\nHere, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces atcoder, he will not earn money even if there are blue cards with atcoderr, atcode, btcoder, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.)\n\nAt most how much can he earn on balance?\n\nNote that the same string may be written on multiple cards.\n\nConstraints\n\nN and M are integers.\n\n1 \\leq N, M \\leq 100\n\ns_1, s_2, ..., s_N, t_1, t_2, ..., t_M are all strings of lengths between 1 and 10 (inclusive) consisting of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\ns_1\ns_2\n:\ns_N\nM\nt_1\nt_2\n:\nt_M\n\nOutput\n\nIf Takahashi can earn at most X yen on balance, print X.\n\nSample Input 1\n\n3\napple\norange\napple\n1\ngrape\n\nSample Output 1\n\n2\n\nHe can earn 2 yen by announcing apple.\n\nSample Input 2\n\n3\napple\norange\napple\n5\napple\napple\napple\napple\napple\n\nSample Output 2\n\n1\n\nIf he announces apple, he will lose 3 yen. If he announces orange, he can earn 1 yen.\n\nSample Input 3\n\n1\nvoldemort\n10\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\n\nSample Output 3\n\n0\n\nIf he announces voldemort, he will lose 9 yen. If he announces orange, for example, he can avoid losing a yen.\n\nSample Input 4\n\n6\nred\nred\nblue\nyellow\nyellow\nred\n5\nred\nred\nyellow\ngreen\nblue\n\nSample Output 4\n\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2900, "cpu_time_ms": 55, "memory_kb": 13372}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s619727800", "group_id": "codeNet:p03415", "input_text": "(defun solver ()\n (let ((ar (make-array 12 :fill-pointer 0)))\n (loop repeat 12 do\n (vector-push (read-char) ar))\n (format t \"~a~a~a~%\" (aref ar 0) (aref ar 5) (aref ar 10))))\n\n(solver)", "language": "Lisp", "metadata": {"date": 1521780863, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03415.html", "problem_id": "p03415", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03415/input.txt", "sample_output_relpath": "derived/input_output/data/p03415/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03415/Lisp/s619727800.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s619727800", "user_id": "u183015556"}, "prompt_components": {"gold_output": "abc\n", "input_to_evaluate": "(defun solver ()\n (let ((ar (make-array 12 :fill-pointer 0)))\n (loop repeat 12 do\n (vector-push (read-char) ar))\n (format t \"~a~a~a~%\" (aref ar 0) (aref ar 5) (aref ar 10))))\n\n(solver)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe have a 3×3 square grid, where each square contains a lowercase English letters.\nThe letter in the square at the i-th row from the top and j-th column from the left is c_{ij}.\n\nPrint the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.\n\nConstraints\n\nInput consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nc_{11}c_{12}c_{13}\nc_{21}c_{22}c_{23}\nc_{31}c_{32}c_{33}\n\nOutput\n\nPrint the string of length 3 that can be obtained by concatenating the letters on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.\n\nSample Input 1\n\nant\nobe\nrec\n\nSample Output 1\n\nabc\n\nThe letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid are a, b and c from top-right to bottom-left. Concatenate these letters and print abc.\n\nSample Input 2\n\nedu\ncat\nion\n\nSample Output 2\n\nean", "sample_input": "ant\nobe\nrec\n"}, "reference_outputs": ["abc\n"], "source_document_id": "p03415", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe have a 3×3 square grid, where each square contains a lowercase English letters.\nThe letter in the square at the i-th row from the top and j-th column from the left is c_{ij}.\n\nPrint the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.\n\nConstraints\n\nInput consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nc_{11}c_{12}c_{13}\nc_{21}c_{22}c_{23}\nc_{31}c_{32}c_{33}\n\nOutput\n\nPrint the string of length 3 that can be obtained by concatenating the letters on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.\n\nSample Input 1\n\nant\nobe\nrec\n\nSample Output 1\n\nabc\n\nThe letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid are a, b and c from top-right to bottom-left. Concatenate these letters and print abc.\n\nSample Input 2\n\nedu\ncat\nion\n\nSample Output 2\n\nean", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 208, "cpu_time_ms": 20, "memory_kb": 4328}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s295313857", "group_id": "codeNet:p03416", "input_text": "(defun f (p)\n (concatenate 'list (write-to-string p)))\n\n\n(defun g (lst)\n (if (and (char= (car lst) (car (reverse lst)))\n (char= (cadr lst) (cadr (reverse lst))))\n t\n nil))\n\n\n(let ((a (read))\n (b (read)))\n\n (format t \"~A~%\"\n (loop for i from a to b\n when (g (f i))\n count i)))\n\n", "language": "Lisp", "metadata": {"date": 1598579842, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03416.html", "problem_id": "p03416", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03416/input.txt", "sample_output_relpath": "derived/input_output/data/p03416/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03416/Lisp/s295313857.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s295313857", "user_id": "u336541610"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun f (p)\n (concatenate 'list (write-to-string p)))\n\n\n(defun g (lst)\n (if (and (char= (car lst) (car (reverse lst)))\n (char= (cadr lst) (cadr (reverse lst))))\n t\n nil))\n\n\n(let ((a (read))\n (b (read)))\n\n (format t \"~A~%\"\n (loop for i from a to b\n when (g (f i))\n count i)))\n\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nFind the number of palindromic numbers among the integers between A and B (inclusive).\nHere, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.\n\nConstraints\n\n10000 \\leq A \\leq B \\leq 99999\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the number of palindromic numbers among the integers between A and B (inclusive).\n\nSample Input 1\n\n11009 11332\n\nSample Output 1\n\n4\n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and 11311.\n\nSample Input 2\n\n31415 92653\n\nSample Output 2\n\n612", "sample_input": "11009 11332\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03416", "source_text": "Score : 200 points\n\nProblem Statement\n\nFind the number of palindromic numbers among the integers between A and B (inclusive).\nHere, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.\n\nConstraints\n\n10000 \\leq A \\leq B \\leq 99999\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the number of palindromic numbers among the integers between A and B (inclusive).\n\nSample Input 1\n\n11009 11332\n\nSample Output 1\n\n4\n\nThere are four integers that satisfy the conditions: 11011, 11111, 11211 and 11311.\n\nSample Input 2\n\n31415 92653\n\nSample Output 2\n\n612", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 340, "cpu_time_ms": 53, "memory_kb": 44712}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s198572568", "group_id": "codeNet:p03423", "input_text": "(princ (floor (read)))", "language": "Lisp", "metadata": {"date": 1541722431, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03423.html", "problem_id": "p03423", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03423/input.txt", "sample_output_relpath": "derived/input_output/data/p03423/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03423/Lisp/s198572568.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s198572568", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(princ (floor (read)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are N students in a school.\n\nWe will divide these students into some groups, and in each group they will discuss some themes.\n\nYou think that groups consisting of two or less students cannot have an effective discussion, so you want to have as many groups consisting of three or more students as possible.\n\nDivide the students so that the number of groups consisting of three or more students is maximized.\n\nConstraints\n\n1 \\leq N \\leq 1000\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf you can form at most x groups consisting of three or more students, print x.\n\nSample Input 1\n\n8\n\nSample Output 1\n\n2\n\nFor example, you can form a group of three students and another of five students.\n\nSample Input 2\n\n2\n\nSample Output 2\n\n0\n\nSometimes you cannot form any group consisting of three or more students, regardless of how you divide the students.\n\nSample Input 3\n\n9\n\nSample Output 3\n\n3", "sample_input": "8\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03423", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are N students in a school.\n\nWe will divide these students into some groups, and in each group they will discuss some themes.\n\nYou think that groups consisting of two or less students cannot have an effective discussion, so you want to have as many groups consisting of three or more students as possible.\n\nDivide the students so that the number of groups consisting of three or more students is maximized.\n\nConstraints\n\n1 \\leq N \\leq 1000\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf you can form at most x groups consisting of three or more students, print x.\n\nSample Input 1\n\n8\n\nSample Output 1\n\n2\n\nFor example, you can form a group of three students and another of five students.\n\nSample Input 2\n\n2\n\nSample Output 2\n\n0\n\nSometimes you cannot form any group consisting of three or more students, regardless of how you divide the students.\n\nSample Input 3\n\n9\n\nSample Output 3\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 22, "cpu_time_ms": 22, "memory_kb": 3816}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s443183755", "group_id": "codeNet:p03424", "input_text": "(defun input (n)\n (let ((A (make-array n)))\n (loop for i below n do (setf (aref A i) (read)))\n A))\n\n(defun solve (A)\n (if (find 'Y A) \"Four\" \"Three\"))\n\n(let* ((n (read))\n (a (input n)))\n (princ (solve a)))", "language": "Lisp", "metadata": {"date": 1523415355, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03424.html", "problem_id": "p03424", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03424/input.txt", "sample_output_relpath": "derived/input_output/data/p03424/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03424/Lisp/s443183755.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s443183755", "user_id": "u672956630"}, "prompt_components": {"gold_output": "Four\n", "input_to_evaluate": "(defun input (n)\n (let ((A (make-array n)))\n (loop for i below n do (setf (aref A i) (read)))\n A))\n\n(defun solve (A)\n (if (find 'Y A) \"Four\" \"Three\"))\n\n(let* ((n (read))\n (a (input n)))\n (princ (solve a)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nIn Japan, people make offerings called hina arare, colorful crackers, on March 3.\n\nWe have a bag that contains N hina arare. (From here, we call them arare.)\n\nIt is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow.\n\nWe have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: P, white: W, green: G, yellow: Y.\n\nIf the number of colors of the arare in the bag was three, print Three; if the number of colors was four, print Four.\n\nConstraints\n\n1 \\leq N \\leq 100\n\nS_i is P, W, G or Y.\n\nThere always exist i, j and k such that S_i=P, S_j=W and S_k=G.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1 S_2 ... S_N\n\nOutput\n\nIf the number of colors of the arare in the bag was three, print Three; if the number of colors was four, print Four.\n\nSample Input 1\n\n6\nG W Y P Y W\n\nSample Output 1\n\nFour\n\nThe bag contained arare in four colors, so you should print Four.\n\nSample Input 2\n\n9\nG W W G P W P G G\n\nSample Output 2\n\nThree\n\nThe bag contained arare in three colors, so you should print Three.\n\nSample Input 3\n\n8\nP Y W G Y W Y Y\n\nSample Output 3\n\nFour", "sample_input": "6\nG W Y P Y W\n"}, "reference_outputs": ["Four\n"], "source_document_id": "p03424", "source_text": "Score : 200 points\n\nProblem Statement\n\nIn Japan, people make offerings called hina arare, colorful crackers, on March 3.\n\nWe have a bag that contains N hina arare. (From here, we call them arare.)\n\nIt is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow.\n\nWe have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: P, white: W, green: G, yellow: Y.\n\nIf the number of colors of the arare in the bag was three, print Three; if the number of colors was four, print Four.\n\nConstraints\n\n1 \\leq N \\leq 100\n\nS_i is P, W, G or Y.\n\nThere always exist i, j and k such that S_i=P, S_j=W and S_k=G.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1 S_2 ... S_N\n\nOutput\n\nIf the number of colors of the arare in the bag was three, print Three; if the number of colors was four, print Four.\n\nSample Input 1\n\n6\nG W Y P Y W\n\nSample Output 1\n\nFour\n\nThe bag contained arare in four colors, so you should print Four.\n\nSample Input 2\n\n9\nG W W G P W P G G\n\nSample Output 2\n\nThree\n\nThe bag contained arare in three colors, so you should print Three.\n\nSample Input 3\n\n8\nP Y W G Y W Y Y\n\nSample Output 3\n\nFour", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 219, "cpu_time_ms": 140, "memory_kb": 13412}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s997937080", "group_id": "codeNet:p03424", "input_text": "(let ((n (read))\n (s (read-line))\n (ans \"Three\"))\n (dotimes (x (- (* n 2) 1))\n (if (equal (char s x) #\\Y) (setf ans \"Four\")))\n (format t \"~A~%\" ans))\n", "language": "Lisp", "metadata": {"date": 1520217527, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03424.html", "problem_id": "p03424", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03424/input.txt", "sample_output_relpath": "derived/input_output/data/p03424/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03424/Lisp/s997937080.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s997937080", "user_id": "u994767958"}, "prompt_components": {"gold_output": "Four\n", "input_to_evaluate": "(let ((n (read))\n (s (read-line))\n (ans \"Three\"))\n (dotimes (x (- (* n 2) 1))\n (if (equal (char s x) #\\Y) (setf ans \"Four\")))\n (format t \"~A~%\" ans))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nIn Japan, people make offerings called hina arare, colorful crackers, on March 3.\n\nWe have a bag that contains N hina arare. (From here, we call them arare.)\n\nIt is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow.\n\nWe have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: P, white: W, green: G, yellow: Y.\n\nIf the number of colors of the arare in the bag was three, print Three; if the number of colors was four, print Four.\n\nConstraints\n\n1 \\leq N \\leq 100\n\nS_i is P, W, G or Y.\n\nThere always exist i, j and k such that S_i=P, S_j=W and S_k=G.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1 S_2 ... S_N\n\nOutput\n\nIf the number of colors of the arare in the bag was three, print Three; if the number of colors was four, print Four.\n\nSample Input 1\n\n6\nG W Y P Y W\n\nSample Output 1\n\nFour\n\nThe bag contained arare in four colors, so you should print Four.\n\nSample Input 2\n\n9\nG W W G P W P G G\n\nSample Output 2\n\nThree\n\nThe bag contained arare in three colors, so you should print Three.\n\nSample Input 3\n\n8\nP Y W G Y W Y Y\n\nSample Output 3\n\nFour", "sample_input": "6\nG W Y P Y W\n"}, "reference_outputs": ["Four\n"], "source_document_id": "p03424", "source_text": "Score : 200 points\n\nProblem Statement\n\nIn Japan, people make offerings called hina arare, colorful crackers, on March 3.\n\nWe have a bag that contains N hina arare. (From here, we call them arare.)\n\nIt is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow.\n\nWe have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: P, white: W, green: G, yellow: Y.\n\nIf the number of colors of the arare in the bag was three, print Three; if the number of colors was four, print Four.\n\nConstraints\n\n1 \\leq N \\leq 100\n\nS_i is P, W, G or Y.\n\nThere always exist i, j and k such that S_i=P, S_j=W and S_k=G.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1 S_2 ... S_N\n\nOutput\n\nIf the number of colors of the arare in the bag was three, print Three; if the number of colors was four, print Four.\n\nSample Input 1\n\n6\nG W Y P Y W\n\nSample Output 1\n\nFour\n\nThe bag contained arare in four colors, so you should print Four.\n\nSample Input 2\n\n9\nG W W G P W P G G\n\nSample Output 2\n\nThree\n\nThe bag contained arare in three colors, so you should print Three.\n\nSample Input 3\n\n8\nP Y W G Y W Y Y\n\nSample Output 3\n\nFour", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 165, "cpu_time_ms": 968, "memory_kb": 13416}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s374169575", "group_id": "codeNet:p03424", "input_text": ";; -*- coding:utf-8 -*-\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter O3 '(optimize (speed 3) (safety 0) (debug 0)))\n (defparameter O2 '(optimize (speed 3) (safety 1))))\n\n(defmacro print-line (obj &optional (stream '*standard-output*))\n `(prog1 (princ ,obj ,stream) (terpri ,stream)))\n\n\n;; Hauptteil\n\n(deftype unum nil `(integer 0 ,(expt 10 9)))\n(defun main ()\n (let ((n (read)))\n (loop repeat n\n do (when (eql (read) 'Y)\n\t (print-line \"Four\")\n\t (return-from main))\n finally (print-line \"Three\")\n\t )))\n\n#-swank(main)\n\n\n;; Für Test\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n(defun test ()\n (with-input-from-string (*standard-input* (delete #\\return (get-clipbrd)))\n (main)))\n\n\n;; Für Benchmark\n(defparameter *file-path* *load-pathname*)\n(defparameter *dir-path* (pathname (directory-namestring *file-path*)))\n(defparameter *dat-path* (merge-pathnames \"test.dat\" *dir-path*))\n\n#+swank\n(defun gendat ()\n (with-open-file (out *dat-path*\n\t\t :direction :output :if-exists :supersede)\n ))\n\n(defun bench ()\n (let ((*standard-output* (make-broadcast-stream)))\n (with-open-file (*standard-input* *dat-path*)\n (time (main)))))\n", "language": "Lisp", "metadata": {"date": 1520216948, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03424.html", "problem_id": "p03424", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03424/input.txt", "sample_output_relpath": "derived/input_output/data/p03424/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03424/Lisp/s374169575.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s374169575", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Four\n", "input_to_evaluate": ";; -*- coding:utf-8 -*-\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter O3 '(optimize (speed 3) (safety 0) (debug 0)))\n (defparameter O2 '(optimize (speed 3) (safety 1))))\n\n(defmacro print-line (obj &optional (stream '*standard-output*))\n `(prog1 (princ ,obj ,stream) (terpri ,stream)))\n\n\n;; Hauptteil\n\n(deftype unum nil `(integer 0 ,(expt 10 9)))\n(defun main ()\n (let ((n (read)))\n (loop repeat n\n do (when (eql (read) 'Y)\n\t (print-line \"Four\")\n\t (return-from main))\n finally (print-line \"Three\")\n\t )))\n\n#-swank(main)\n\n\n;; Für Test\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n(defun test ()\n (with-input-from-string (*standard-input* (delete #\\return (get-clipbrd)))\n (main)))\n\n\n;; Für Benchmark\n(defparameter *file-path* *load-pathname*)\n(defparameter *dir-path* (pathname (directory-namestring *file-path*)))\n(defparameter *dat-path* (merge-pathnames \"test.dat\" *dir-path*))\n\n#+swank\n(defun gendat ()\n (with-open-file (out *dat-path*\n\t\t :direction :output :if-exists :supersede)\n ))\n\n(defun bench ()\n (let ((*standard-output* (make-broadcast-stream)))\n (with-open-file (*standard-input* *dat-path*)\n (time (main)))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nIn Japan, people make offerings called hina arare, colorful crackers, on March 3.\n\nWe have a bag that contains N hina arare. (From here, we call them arare.)\n\nIt is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow.\n\nWe have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: P, white: W, green: G, yellow: Y.\n\nIf the number of colors of the arare in the bag was three, print Three; if the number of colors was four, print Four.\n\nConstraints\n\n1 \\leq N \\leq 100\n\nS_i is P, W, G or Y.\n\nThere always exist i, j and k such that S_i=P, S_j=W and S_k=G.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1 S_2 ... S_N\n\nOutput\n\nIf the number of colors of the arare in the bag was three, print Three; if the number of colors was four, print Four.\n\nSample Input 1\n\n6\nG W Y P Y W\n\nSample Output 1\n\nFour\n\nThe bag contained arare in four colors, so you should print Four.\n\nSample Input 2\n\n9\nG W W G P W P G G\n\nSample Output 2\n\nThree\n\nThe bag contained arare in three colors, so you should print Three.\n\nSample Input 3\n\n8\nP Y W G Y W Y Y\n\nSample Output 3\n\nFour", "sample_input": "6\nG W Y P Y W\n"}, "reference_outputs": ["Four\n"], "source_document_id": "p03424", "source_text": "Score : 200 points\n\nProblem Statement\n\nIn Japan, people make offerings called hina arare, colorful crackers, on March 3.\n\nWe have a bag that contains N hina arare. (From here, we call them arare.)\n\nIt is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow.\n\nWe have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: P, white: W, green: G, yellow: Y.\n\nIf the number of colors of the arare in the bag was three, print Three; if the number of colors was four, print Four.\n\nConstraints\n\n1 \\leq N \\leq 100\n\nS_i is P, W, G or Y.\n\nThere always exist i, j and k such that S_i=P, S_j=W and S_k=G.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1 S_2 ... S_N\n\nOutput\n\nIf the number of colors of the arare in the bag was three, print Three; if the number of colors was four, print Four.\n\nSample Input 1\n\n6\nG W Y P Y W\n\nSample Output 1\n\nFour\n\nThe bag contained arare in four colors, so you should print Four.\n\nSample Input 2\n\n9\nG W W G P W P G G\n\nSample Output 2\n\nThree\n\nThe bag contained arare in three colors, so you should print Three.\n\nSample Input 3\n\n8\nP Y W G Y W Y Y\n\nSample Output 3\n\nFour", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1283, "cpu_time_ms": 368, "memory_kb": 16736}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s676283585", "group_id": "codeNet:p03426", "input_text": ";; -*- coding:utf-8 -*-\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter O3 '(optimize (speed 3) (safety 0) (debug 0)))\n (defparameter O2 '(optimize (speed 3) (safety 1))))\n\n(defmacro print-line (obj &optional (stream '*standard-output*))\n `(prog1 (princ ,obj ,stream) (terpri ,stream)))\n\n\n;; Hauptteil\n\n(defmacro split-and-bind (arg-lst string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str-evaled (gensym \"STR\")))\n (labels ((expand (arg-lst &optional (init-pos1 t))\n\t (if (null arg-lst)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str-evaled :start ,pos1 :test #'char=))\n\t\t\t (,(car arg-lst) (parse-integer ,str-evaled :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr arg-lst) nil))))))\n `(let ((,str-evaled ,string))\n\t ,@(expand arg-lst)))))\n\n(declaim (inline l1-norm))\n(defun l1-norm (x1 y1 x2 y2)\n (+ (abs (- x1 x2)) (abs (- y1 y2))))\n\n(deftype unum nil `(integer 0 ,(expt 10 9)))\n(defun main ()\n (declare #.O3)\n (let* ((height (read))\n\t (width (read))\n\t (delta (read))\n\t (adict-row (make-array (+ (* width height) 1)\n\t\t\t\t:initial-element -1 :element-type 'fixnum))\n\t (adict-col (make-array (+ (* width height) 1)\n\t\t\t\t:initial-element -1 :element-type 'fixnum)))\n (declare (unum width height delta))\n (loop for row from 1 to height do\n\t (loop for col from 1 to width do\n\t (let ((a (read)))\n\t\t(setf (aref adict-row a) row)\n\t\t(setf (aref adict-col a) col))))\n (let* ((q (read))\n\t (l-arr (make-array q :initial-element 0 :element-type 'fixnum))\n\t (r-arr (make-array q :initial-element 0 :element-type 'fixnum))\n\t (cache (make-hash-table :test #'eql)))\n (dotimes (idx q)\n\t(split-and-bind (l r) (the string (read-line))\n\t (setf (aref l-arr idx) l\n\t\t(aref r-arr idx) r)))\n (labels ((get-mp (start left left-row left-col dest mp-consumed)\n\t\t (declare (unum start left dest))\n\t\t (multiple-value-bind (val exists)\n\t\t (gethash (* left dest) cache)\n\t\t (if exists\n\t\t (+ mp-consumed val)\n\t\t (multiple-value-bind (val exists)\n\t\t\t (gethash (* start left) cache)\n\t\t\t (unless exists\n\t\t\t (setf (gethash (* start left) cache) mp-consumed))\n\t\t\t (if (= left dest)\n\t\t\t (progn\n\t\t\t (setf (gethash (* start dest) cache) mp-consumed)\n\t\t\t mp-consumed)\n\t\t\t (let* ((next-left (+ left delta))\n\t\t\t\t (next-row (aref adict-row next-left))\n\t\t\t\t (next-col (aref adict-col next-left)))\n\t\t\t (get-mp\n\t\t\t\tstart\n\t\t\t\tnext-left\n\t\t\t\tnext-row\n\t\t\t\tnext-col\n\t\t\t\tdest\n\t\t\t\t(+ mp-consumed\n\t\t\t\t (l1-norm left-row left-col next-row next-col))))))))))\n\t(loop for idx from 0 below q\n\t do (print-line\n\t (let* ((left (aref l-arr idx))\n\t\t (right (aref r-arr idx))\n\t\t (left-row (aref adict-row left))\n\t\t (left-col (aref adict-col left)))\n\t\t (get-mp left left left-row left-col right 0))))))))\n\t\t \n\n\n#-swank(main)\n\n\n;; Für Test\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n(defun test ()\n (with-input-from-string (*standard-input* (delete #\\return (get-clipbrd)))\n (main)))\n\n\n;; Für Benchmark\n(defparameter *file-path* *load-pathname*)\n(defparameter *dir-path* (pathname (directory-namestring *file-path*)))\n(defparameter *dat-path* (merge-pathnames \"test.dat\" *dir-path*))\n\n#+swank\n(defun gendat ()\n (with-open-file (out *dat-path*\n\t\t :direction :output :if-exists :supersede)\n ))\n\n(defun bench ()\n (let ((*standard-output* (make-broadcast-stream)))\n (with-open-file (*standard-input* *dat-path*)\n (time (main)))))\n", "language": "Lisp", "metadata": {"date": 1520219737, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03426.html", "problem_id": "p03426", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03426/input.txt", "sample_output_relpath": "derived/input_output/data/p03426/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03426/Lisp/s676283585.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s676283585", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": ";; -*- coding:utf-8 -*-\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter O3 '(optimize (speed 3) (safety 0) (debug 0)))\n (defparameter O2 '(optimize (speed 3) (safety 1))))\n\n(defmacro print-line (obj &optional (stream '*standard-output*))\n `(prog1 (princ ,obj ,stream) (terpri ,stream)))\n\n\n;; Hauptteil\n\n(defmacro split-and-bind (arg-lst string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str-evaled (gensym \"STR\")))\n (labels ((expand (arg-lst &optional (init-pos1 t))\n\t (if (null arg-lst)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str-evaled :start ,pos1 :test #'char=))\n\t\t\t (,(car arg-lst) (parse-integer ,str-evaled :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr arg-lst) nil))))))\n `(let ((,str-evaled ,string))\n\t ,@(expand arg-lst)))))\n\n(declaim (inline l1-norm))\n(defun l1-norm (x1 y1 x2 y2)\n (+ (abs (- x1 x2)) (abs (- y1 y2))))\n\n(deftype unum nil `(integer 0 ,(expt 10 9)))\n(defun main ()\n (declare #.O3)\n (let* ((height (read))\n\t (width (read))\n\t (delta (read))\n\t (adict-row (make-array (+ (* width height) 1)\n\t\t\t\t:initial-element -1 :element-type 'fixnum))\n\t (adict-col (make-array (+ (* width height) 1)\n\t\t\t\t:initial-element -1 :element-type 'fixnum)))\n (declare (unum width height delta))\n (loop for row from 1 to height do\n\t (loop for col from 1 to width do\n\t (let ((a (read)))\n\t\t(setf (aref adict-row a) row)\n\t\t(setf (aref adict-col a) col))))\n (let* ((q (read))\n\t (l-arr (make-array q :initial-element 0 :element-type 'fixnum))\n\t (r-arr (make-array q :initial-element 0 :element-type 'fixnum))\n\t (cache (make-hash-table :test #'eql)))\n (dotimes (idx q)\n\t(split-and-bind (l r) (the string (read-line))\n\t (setf (aref l-arr idx) l\n\t\t(aref r-arr idx) r)))\n (labels ((get-mp (start left left-row left-col dest mp-consumed)\n\t\t (declare (unum start left dest))\n\t\t (multiple-value-bind (val exists)\n\t\t (gethash (* left dest) cache)\n\t\t (if exists\n\t\t (+ mp-consumed val)\n\t\t (multiple-value-bind (val exists)\n\t\t\t (gethash (* start left) cache)\n\t\t\t (unless exists\n\t\t\t (setf (gethash (* start left) cache) mp-consumed))\n\t\t\t (if (= left dest)\n\t\t\t (progn\n\t\t\t (setf (gethash (* start dest) cache) mp-consumed)\n\t\t\t mp-consumed)\n\t\t\t (let* ((next-left (+ left delta))\n\t\t\t\t (next-row (aref adict-row next-left))\n\t\t\t\t (next-col (aref adict-col next-left)))\n\t\t\t (get-mp\n\t\t\t\tstart\n\t\t\t\tnext-left\n\t\t\t\tnext-row\n\t\t\t\tnext-col\n\t\t\t\tdest\n\t\t\t\t(+ mp-consumed\n\t\t\t\t (l1-norm left-row left-col next-row next-col))))))))))\n\t(loop for idx from 0 below q\n\t do (print-line\n\t (let* ((left (aref l-arr idx))\n\t\t (right (aref r-arr idx))\n\t\t (left-row (aref adict-row left))\n\t\t (left-col (aref adict-col left)))\n\t\t (get-mp left left left-row left-col right 0))))))))\n\t\t \n\n\n#-swank(main)\n\n\n;; Für Test\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n(defun test ()\n (with-input-from-string (*standard-input* (delete #\\return (get-clipbrd)))\n (main)))\n\n\n;; Für Benchmark\n(defparameter *file-path* *load-pathname*)\n(defparameter *dir-path* (pathname (directory-namestring *file-path*)))\n(defparameter *dat-path* (merge-pathnames \"test.dat\" *dir-path*))\n\n#+swank\n(defun gendat ()\n (with-open-file (out *dat-path*\n\t\t :direction :output :if-exists :supersede)\n ))\n\n(defun bench ()\n (let ((*standard-output* (make-broadcast-stream)))\n (with-open-file (*standard-input* *dat-path*)\n (time (main)))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j).\n\nThe integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}.\n\nYou, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points.\n\nYou now have to take Q practical tests of your ability as a magical girl.\n\nThe i-th test will be conducted as follows:\n\nInitially, a piece is placed on the square where the integer L_i is written.\n\nLet x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i.\n\nHere, it is guaranteed that R_i-L_i is a multiple of D.\n\nFor each test, find the sum of magic points consumed during that test.\n\nConstraints\n\n1 \\leq H,W \\leq 300\n\n1 \\leq D \\leq H×W\n\n1 \\leq A_{i,j} \\leq H×W\n\nA_{i,j} \\neq A_{x,y} ((i,j) \\neq (x,y))\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq L_i \\leq R_i \\leq H×W\n\n(R_i-L_i) is a multiple of D.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W D\nA_{1,1} A_{1,2} ... A_{1,W}\n:\nA_{H,1} A_{H,2} ... A_{H,W}\nQ\nL_1 R_1\n:\nL_Q R_Q\n\nOutput\n\nFor each test, print the sum of magic points consumed during that test.\n\nOutput should be in the order the tests are conducted.\n\nSample Input 1\n\n3 3 2\n1 4 3\n2 5 7\n8 9 6\n1\n4 8\n\nSample Output 1\n\n5\n\n4 is written in Square (1,2).\n\n6 is written in Square (3,3).\n\n8 is written in Square (3,1).\n\nThus, the sum of magic points consumed during the first test is (|3-1|+|3-2|)+(|3-3|+|1-3|)=5.\n\nSample Input 2\n\n4 2 3\n3 7\n1 4\n5 2\n6 8\n2\n2 2\n2 2\n\nSample Output 2\n\n0\n0\n\nNote that there may be a test where the piece is not moved at all, and there may be multiple identical tests.\n\nSample Input 3\n\n5 5 4\n13 25 7 15 17\n16 22 20 2 9\n14 11 12 1 19\n10 6 23 8 18\n3 21 5 24 4\n3\n13 13\n2 10\n13 13\n\nSample Output 3\n\n0\n5\n0", "sample_input": "3 3 2\n1 4 3\n2 5 7\n8 9 6\n1\n4 8\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03426", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j).\n\nThe integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}.\n\nYou, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points.\n\nYou now have to take Q practical tests of your ability as a magical girl.\n\nThe i-th test will be conducted as follows:\n\nInitially, a piece is placed on the square where the integer L_i is written.\n\nLet x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i.\n\nHere, it is guaranteed that R_i-L_i is a multiple of D.\n\nFor each test, find the sum of magic points consumed during that test.\n\nConstraints\n\n1 \\leq H,W \\leq 300\n\n1 \\leq D \\leq H×W\n\n1 \\leq A_{i,j} \\leq H×W\n\nA_{i,j} \\neq A_{x,y} ((i,j) \\neq (x,y))\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq L_i \\leq R_i \\leq H×W\n\n(R_i-L_i) is a multiple of D.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W D\nA_{1,1} A_{1,2} ... A_{1,W}\n:\nA_{H,1} A_{H,2} ... A_{H,W}\nQ\nL_1 R_1\n:\nL_Q R_Q\n\nOutput\n\nFor each test, print the sum of magic points consumed during that test.\n\nOutput should be in the order the tests are conducted.\n\nSample Input 1\n\n3 3 2\n1 4 3\n2 5 7\n8 9 6\n1\n4 8\n\nSample Output 1\n\n5\n\n4 is written in Square (1,2).\n\n6 is written in Square (3,3).\n\n8 is written in Square (3,1).\n\nThus, the sum of magic points consumed during the first test is (|3-1|+|3-2|)+(|3-3|+|1-3|)=5.\n\nSample Input 2\n\n4 2 3\n3 7\n1 4\n5 2\n6 8\n2\n2 2\n2 2\n\nSample Output 2\n\n0\n0\n\nNote that there may be a test where the piece is not moved at all, and there may be multiple identical tests.\n\nSample Input 3\n\n5 5 4\n13 25 7 15 17\n16 22 20 2 9\n14 11 12 1 19\n10 6 23 8 18\n3 21 5 24 4\n3\n13 13\n2 10\n13 13\n\nSample Output 3\n\n0\n5\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3610, "cpu_time_ms": 2106, "memory_kb": 389984}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s739215990", "group_id": "codeNet:p03427", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun mapa-b (fn a b &optional (step 1))\n (do ((i a (+ i step))\n (result nil))\n ((> i b) (nreverse result))\n (push (funcall fn i) result)))\n\n(defun map0-n (fn n)\n (mapa-b fn 0 n))\n\n(defun map1-n (fn n)\n (mapa-b fn 1 n))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (is-empty char)\n do (return (concatenate 'string (nreverse result)))\n do (push char result))))\n\n(defun main (n)\n (if (< n 10)\n n\n (+ (read-from-string (string (aref (write-to-string n) 0)))(* (1- (length (write-to-string n))) 9) -1)))\n\n(let ((n (read)))\n (princ (main n)))\n", "language": "Lisp", "metadata": {"date": 1589143703, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03427.html", "problem_id": "p03427", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03427/input.txt", "sample_output_relpath": "derived/input_output/data/p03427/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03427/Lisp/s739215990.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s739215990", "user_id": "u493610446"}, "prompt_components": {"gold_output": "18\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n (if it ,then ,else)))\n\n(defmacro awhen (expr &rest then)\n `(aif ,expr (progn ,@then) nil))\n\n(defun comulative (function list &key base)\n (if base\n (comulative function (cons base list))\n (do ((lst (cdr list) (cdr lst))\n (acc (list (car list))))\n ((null lst) (reverse acc))\n (push (funcall function (car acc) (car lst)) acc))))\n\n(defun binary-search (function left right\n &optional\n (eps 1)\n (average-function (lambda (x y) (ash (+ x y) -1))))\n (if (<= (abs (- left right)) eps)\n right\n (let ((mid (funcall average-function left right)))\n (if (funcall function mid)\n (binary-search function left mid eps average-function)\n (binary-search function mid right eps average-function)))))\n\n(defun arithmetic-mean (&rest body)\n (/ (apply #'+ body) (length body)))\n\n(defvar +MOD+ (+ (expt 10 9) 7))\n\n(defun mapa-b (fn a b &optional (step 1))\n (do ((i a (+ i step))\n (result nil))\n ((> i b) (nreverse result))\n (push (funcall fn i) result)))\n\n(defun map0-n (fn n)\n (mapa-b fn 0 n))\n\n(defun map1-n (fn n)\n (mapa-b fn 1 n))\n\n(defun read-string (&optional (stream *standard-input*))\n (labels ((is-empty (x)\n (or (char= x #\\space) (char= x #\\newline))))\n (loop for char = (read-char stream)\n with result\n when (is-empty char)\n do (return (concatenate 'string (nreverse result)))\n do (push char result))))\n\n(defun main (n)\n (if (< n 10)\n n\n (+ (read-from-string (string (aref (write-to-string n) 0)))(* (1- (length (write-to-string n))) 9) -1)))\n\n(let ((n (read)))\n (princ (main n)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nFind the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.\n\nConstraints\n\n1\\leq N \\leq 10^{16}\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.\n\nSample Input 1\n\n100\n\nSample Output 1\n\n18\n\nFor example, the sum of the digits in 99 is 18, which turns out to be the maximum value.\n\nSample Input 2\n\n9995\n\nSample Output 2\n\n35\n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the maximum value.\n\nSample Input 3\n\n3141592653589793\n\nSample Output 3\n\n137", "sample_input": "100\n"}, "reference_outputs": ["18\n"], "source_document_id": "p03427", "source_text": "Score : 300 points\n\nProblem Statement\n\nFind the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.\n\nConstraints\n\n1\\leq N \\leq 10^{16}\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.\n\nSample Input 1\n\n100\n\nSample Output 1\n\n18\n\nFor example, the sum of the digits in 99 is 18, which turns out to be the maximum value.\n\nSample Input 2\n\n9995\n\nSample Output 2\n\n35\n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the maximum value.\n\nSample Input 3\n\n3141592653589793\n\nSample Output 3\n\n137", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2795, "cpu_time_ms": 196, "memory_kb": 23988}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s090766123", "group_id": "codeNet:p03433", "input_text": "(format t\"~a~&\"(if(<=(rem(read)500)(read))\"Yes\"\"No\"))", "language": "Lisp", "metadata": {"date": 1599546803, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03433.html", "problem_id": "p03433", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03433/input.txt", "sample_output_relpath": "derived/input_output/data/p03433/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03433/Lisp/s090766123.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s090766123", "user_id": "u425762225"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(format t\"~a~&\"(if(<=(rem(read)500)(read))\"Yes\"\"No\"))", "problem_context": "Score: 100 points\n\nProblem Statement\n\nE869120 has A 1-yen coins and infinitely many 500-yen coins.\n\nDetermine if he can pay exactly N yen using only these coins.\n\nConstraints\n\nN is an integer between 1 and 10000 (inclusive).\n\nA is an integer between 0 and 1000 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA\n\nOutput\n\nIf E869120 can pay exactly N yen using only his 1-yen and 500-yen coins, print Yes; otherwise, print No.\n\nSample Input 1\n\n2018\n218\n\nSample Output 1\n\nYes\n\nWe can pay 2018 yen with four 500-yen coins and 18 1-yen coins, so the answer is Yes.\n\nSample Input 2\n\n2763\n0\n\nSample Output 2\n\nNo\n\nWhen we have no 1-yen coins, we can only pay a multiple of 500 yen using only 500-yen coins. Since 2763 is not a multiple of 500, we cannot pay this amount.\n\nSample Input 3\n\n37\n514\n\nSample Output 3\n\nYes", "sample_input": "2018\n218\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03433", "source_text": "Score: 100 points\n\nProblem Statement\n\nE869120 has A 1-yen coins and infinitely many 500-yen coins.\n\nDetermine if he can pay exactly N yen using only these coins.\n\nConstraints\n\nN is an integer between 1 and 10000 (inclusive).\n\nA is an integer between 0 and 1000 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA\n\nOutput\n\nIf E869120 can pay exactly N yen using only his 1-yen and 500-yen coins, print Yes; otherwise, print No.\n\nSample Input 1\n\n2018\n218\n\nSample Output 1\n\nYes\n\nWe can pay 2018 yen with four 500-yen coins and 18 1-yen coins, so the answer is Yes.\n\nSample Input 2\n\n2763\n0\n\nSample Output 2\n\nNo\n\nWhen we have no 1-yen coins, we can only pay a multiple of 500 yen using only 500-yen coins. Since 2763 is not a multiple of 500, we cannot pay this amount.\n\nSample Input 3\n\n37\n514\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 53, "cpu_time_ms": 20, "memory_kb": 24416}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s740266392", "group_id": "codeNet:p03433", "input_text": "(let ((n (read))\n (a (read)))\n (format t \"~A~%\" (if (<= (mod n 500) a) \"Yes\" \"No\")))\n", "language": "Lisp", "metadata": {"date": 1519013067, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03433.html", "problem_id": "p03433", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03433/input.txt", "sample_output_relpath": "derived/input_output/data/p03433/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03433/Lisp/s740266392.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s740266392", "user_id": "u994767958"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((n (read))\n (a (read)))\n (format t \"~A~%\" (if (<= (mod n 500) a) \"Yes\" \"No\")))\n", "problem_context": "Score: 100 points\n\nProblem Statement\n\nE869120 has A 1-yen coins and infinitely many 500-yen coins.\n\nDetermine if he can pay exactly N yen using only these coins.\n\nConstraints\n\nN is an integer between 1 and 10000 (inclusive).\n\nA is an integer between 0 and 1000 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA\n\nOutput\n\nIf E869120 can pay exactly N yen using only his 1-yen and 500-yen coins, print Yes; otherwise, print No.\n\nSample Input 1\n\n2018\n218\n\nSample Output 1\n\nYes\n\nWe can pay 2018 yen with four 500-yen coins and 18 1-yen coins, so the answer is Yes.\n\nSample Input 2\n\n2763\n0\n\nSample Output 2\n\nNo\n\nWhen we have no 1-yen coins, we can only pay a multiple of 500 yen using only 500-yen coins. Since 2763 is not a multiple of 500, we cannot pay this amount.\n\nSample Input 3\n\n37\n514\n\nSample Output 3\n\nYes", "sample_input": "2018\n218\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03433", "source_text": "Score: 100 points\n\nProblem Statement\n\nE869120 has A 1-yen coins and infinitely many 500-yen coins.\n\nDetermine if he can pay exactly N yen using only these coins.\n\nConstraints\n\nN is an integer between 1 and 10000 (inclusive).\n\nA is an integer between 0 and 1000 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA\n\nOutput\n\nIf E869120 can pay exactly N yen using only his 1-yen and 500-yen coins, print Yes; otherwise, print No.\n\nSample Input 1\n\n2018\n218\n\nSample Output 1\n\nYes\n\nWe can pay 2018 yen with four 500-yen coins and 18 1-yen coins, so the answer is Yes.\n\nSample Input 2\n\n2763\n0\n\nSample Output 2\n\nNo\n\nWhen we have no 1-yen coins, we can only pay a multiple of 500 yen using only 500-yen coins. Since 2763 is not a multiple of 500, we cannot pay this amount.\n\nSample Input 3\n\n37\n514\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 91, "cpu_time_ms": 13, "memory_kb": 3944}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s711639288", "group_id": "codeNet:p03434", "input_text": "(defun get-alice (lst &optional (acc nil))\n (if (null lst)\n acc\n (get-alice (cddr lst) (cons (car lst) acc))))\n\n\n(defun get-bob (lst &optional (acc nil))\n (get-alice (cdr lst)))\n\n\n(let* ((n (read))\n (l (sort (loop repeat n\n collect (read))\n #'>))\n (alice (get-alice l))\n (bob (get-bob l)))\n\n (format t \"~A~%\" (- (reduce #'+ alice) (reduce #'+ bob))))\n", "language": "Lisp", "metadata": {"date": 1598576317, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03434.html", "problem_id": "p03434", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03434/input.txt", "sample_output_relpath": "derived/input_output/data/p03434/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03434/Lisp/s711639288.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s711639288", "user_id": "u336541610"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun get-alice (lst &optional (acc nil))\n (if (null lst)\n acc\n (get-alice (cddr lst) (cons (car lst) acc))))\n\n\n(defun get-bob (lst &optional (acc nil))\n (get-alice (cdr lst)))\n\n\n(let* ((n (read))\n (l (sort (loop repeat n\n collect (read))\n #'>))\n (alice (get-alice l))\n (bob (get-bob l)))\n\n (format t \"~A~%\" (- (reduce #'+ alice) (reduce #'+ bob))))\n", "problem_context": "Score: 200 points\n\nProblem Statement\n\nWe have N cards. A number a_i is written on the i-th card.\n\nAlice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.\n\nThe game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.\n\nConstraints\n\nN is an integer between 1 and 100 (inclusive).\n\na_i \\ (1 \\leq i \\leq N) is an integer between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 a_3 ... a_N\n\nOutput\n\nPrint Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.\n\nSample Input 1\n\n2\n3 1\n\nSample Output 1\n\n2\n\nFirst, Alice will take the card with 3. Then, Bob will take the card with 1.\nThe difference of their scores will be 3 - 1 = 2.\n\nSample Input 2\n\n3\n2 7 4\n\nSample Output 2\n\n5\n\nFirst, Alice will take the card with 7. Then, Bob will take the card with 4. Lastly, Alice will take the card with 2. The difference of their scores will be 7 - 4 + 2 = 5. The difference of their scores will be 3 - 1 = 2.\n\nSample Input 3\n\n4\n20 18 2 18\n\nSample Output 3\n\n18", "sample_input": "2\n3 1\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03434", "source_text": "Score: 200 points\n\nProblem Statement\n\nWe have N cards. A number a_i is written on the i-th card.\n\nAlice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.\n\nThe game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.\n\nConstraints\n\nN is an integer between 1 and 100 (inclusive).\n\na_i \\ (1 \\leq i \\leq N) is an integer between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 a_3 ... a_N\n\nOutput\n\nPrint Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.\n\nSample Input 1\n\n2\n3 1\n\nSample Output 1\n\n2\n\nFirst, Alice will take the card with 3. Then, Bob will take the card with 1.\nThe difference of their scores will be 3 - 1 = 2.\n\nSample Input 2\n\n3\n2 7 4\n\nSample Output 2\n\n5\n\nFirst, Alice will take the card with 7. Then, Bob will take the card with 4. Lastly, Alice will take the card with 2. The difference of their scores will be 7 - 4 + 2 = 5. The difference of their scores will be 3 - 1 = 2.\n\nSample Input 3\n\n4\n20 18 2 18\n\nSample Output 3\n\n18", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 414, "cpu_time_ms": 20, "memory_kb": 24364}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s870753196", "group_id": "codeNet:p03434", "input_text": "(defun game-for-two (data flg)\n (cond\n ((eq data nil) 0)\n ((eq flg t)\n (+ (game-for-two (cdr data) (not flg))\n\t (car data)))\n (\n (- (game-for-two (cdr data) (not flg))\n\t (car data)))))\n\n(defun input (n data)\n (if (eq n 0)\n data\n (input (1- n) (cons (read) data))))\n\n(format t \"~A~%\" (game-for-two (sort (input (read) nil) #'>) t))", "language": "Lisp", "metadata": {"date": 1576962347, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03434.html", "problem_id": "p03434", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03434/input.txt", "sample_output_relpath": "derived/input_output/data/p03434/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03434/Lisp/s870753196.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s870753196", "user_id": "u691380397"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun game-for-two (data flg)\n (cond\n ((eq data nil) 0)\n ((eq flg t)\n (+ (game-for-two (cdr data) (not flg))\n\t (car data)))\n (\n (- (game-for-two (cdr data) (not flg))\n\t (car data)))))\n\n(defun input (n data)\n (if (eq n 0)\n data\n (input (1- n) (cons (read) data))))\n\n(format t \"~A~%\" (game-for-two (sort (input (read) nil) #'>) t))", "problem_context": "Score: 200 points\n\nProblem Statement\n\nWe have N cards. A number a_i is written on the i-th card.\n\nAlice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.\n\nThe game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.\n\nConstraints\n\nN is an integer between 1 and 100 (inclusive).\n\na_i \\ (1 \\leq i \\leq N) is an integer between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 a_3 ... a_N\n\nOutput\n\nPrint Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.\n\nSample Input 1\n\n2\n3 1\n\nSample Output 1\n\n2\n\nFirst, Alice will take the card with 3. Then, Bob will take the card with 1.\nThe difference of their scores will be 3 - 1 = 2.\n\nSample Input 2\n\n3\n2 7 4\n\nSample Output 2\n\n5\n\nFirst, Alice will take the card with 7. Then, Bob will take the card with 4. Lastly, Alice will take the card with 2. The difference of their scores will be 7 - 4 + 2 = 5. The difference of their scores will be 3 - 1 = 2.\n\nSample Input 3\n\n4\n20 18 2 18\n\nSample Output 3\n\n18", "sample_input": "2\n3 1\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03434", "source_text": "Score: 200 points\n\nProblem Statement\n\nWe have N cards. A number a_i is written on the i-th card.\n\nAlice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.\n\nThe game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.\n\nConstraints\n\nN is an integer between 1 and 100 (inclusive).\n\na_i \\ (1 \\leq i \\leq N) is an integer between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 a_3 ... a_N\n\nOutput\n\nPrint Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.\n\nSample Input 1\n\n2\n3 1\n\nSample Output 1\n\n2\n\nFirst, Alice will take the card with 3. Then, Bob will take the card with 1.\nThe difference of their scores will be 3 - 1 = 2.\n\nSample Input 2\n\n3\n2 7 4\n\nSample Output 2\n\n5\n\nFirst, Alice will take the card with 7. Then, Bob will take the card with 4. Lastly, Alice will take the card with 2. The difference of their scores will be 7 - 4 + 2 = 5. The difference of their scores will be 3 - 1 = 2.\n\nSample Input 3\n\n4\n20 18 2 18\n\nSample Output 3\n\n18", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 361, "cpu_time_ms": 132, "memory_kb": 10848}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s866680818", "group_id": "codeNet:p03434", "input_text": "(defun num-list-from-string (n) \n (read-from-string (concatenate 'string \"(\" n \")\")))\n\n(defun alice-cards-helper (alis lis)\n (if (eq lis nil) \n alis\n (alice-cards-helper (+ alis (car lis)) (cddr lis)))) \n\n(defun main () \n (let ((l (sort (num-list-from-string (read-line)) #'> ))) \n (format t \"~a\" (- (alice-cards-helper 0 l) (alice-cards-helper 0 (cdr l)))))) \n\n(read)\n(main)", "language": "Lisp", "metadata": {"date": 1557892909, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03434.html", "problem_id": "p03434", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03434/input.txt", "sample_output_relpath": "derived/input_output/data/p03434/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03434/Lisp/s866680818.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s866680818", "user_id": "u418126641"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun num-list-from-string (n) \n (read-from-string (concatenate 'string \"(\" n \")\")))\n\n(defun alice-cards-helper (alis lis)\n (if (eq lis nil) \n alis\n (alice-cards-helper (+ alis (car lis)) (cddr lis)))) \n\n(defun main () \n (let ((l (sort (num-list-from-string (read-line)) #'> ))) \n (format t \"~a\" (- (alice-cards-helper 0 l) (alice-cards-helper 0 (cdr l)))))) \n\n(read)\n(main)", "problem_context": "Score: 200 points\n\nProblem Statement\n\nWe have N cards. A number a_i is written on the i-th card.\n\nAlice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.\n\nThe game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.\n\nConstraints\n\nN is an integer between 1 and 100 (inclusive).\n\na_i \\ (1 \\leq i \\leq N) is an integer between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 a_3 ... a_N\n\nOutput\n\nPrint Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.\n\nSample Input 1\n\n2\n3 1\n\nSample Output 1\n\n2\n\nFirst, Alice will take the card with 3. Then, Bob will take the card with 1.\nThe difference of their scores will be 3 - 1 = 2.\n\nSample Input 2\n\n3\n2 7 4\n\nSample Output 2\n\n5\n\nFirst, Alice will take the card with 7. Then, Bob will take the card with 4. Lastly, Alice will take the card with 2. The difference of their scores will be 7 - 4 + 2 = 5. The difference of their scores will be 3 - 1 = 2.\n\nSample Input 3\n\n4\n20 18 2 18\n\nSample Output 3\n\n18", "sample_input": "2\n3 1\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03434", "source_text": "Score: 200 points\n\nProblem Statement\n\nWe have N cards. A number a_i is written on the i-th card.\n\nAlice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.\n\nThe game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.\n\nConstraints\n\nN is an integer between 1 and 100 (inclusive).\n\na_i \\ (1 \\leq i \\leq N) is an integer between 1 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 a_3 ... a_N\n\nOutput\n\nPrint Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.\n\nSample Input 1\n\n2\n3 1\n\nSample Output 1\n\n2\n\nFirst, Alice will take the card with 3. Then, Bob will take the card with 1.\nThe difference of their scores will be 3 - 1 = 2.\n\nSample Input 2\n\n3\n2 7 4\n\nSample Output 2\n\n5\n\nFirst, Alice will take the card with 7. Then, Bob will take the card with 4. Lastly, Alice will take the card with 2. The difference of their scores will be 7 - 4 + 2 = 5. The difference of their scores will be 3 - 1 = 2.\n\nSample Input 3\n\n4\n20 18 2 18\n\nSample Output 3\n\n18", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 677, "cpu_time_ms": 14, "memory_kb": 3944}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s306376939", "group_id": "codeNet:p03435", "input_text": "(let ((lst (loop :repeat 3 :collect (loop :repeat 3 :collect (read)))))\n (defun f (a b c d)\n (- (nth a (nth b lst)) (nth c (nth d lst))))\n (if (and (= (f 0 0 0 1) (f 1 0 1 1) (f 2 0 2 1))\n (= (f 0 1 0 2) (f 1 1 1 2) (f 2 1 2 2))\n (= (f 0 0 1 0) (f 0 1 1 1) (f 0 2 1 2))\n (= (f 1 0 2 0) (f 1 1 2 1) (f 1 2 2 2)))\n (princ \"Yes\")\n (princ \"No\")))", "language": "Lisp", "metadata": {"date": 1556339600, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03435.html", "problem_id": "p03435", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03435/input.txt", "sample_output_relpath": "derived/input_output/data/p03435/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03435/Lisp/s306376939.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s306376939", "user_id": "u610490393"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((lst (loop :repeat 3 :collect (loop :repeat 3 :collect (read)))))\n (defun f (a b c d)\n (- (nth a (nth b lst)) (nth c (nth d lst))))\n (if (and (= (f 0 0 0 1) (f 1 0 1 1) (f 2 0 2 1))\n (= (f 0 1 0 2) (f 1 1 1 2) (f 2 1 2 2))\n (= (f 0 0 1 0) (f 0 1 1 1) (f 0 2 1 2))\n (= (f 1 0 2 0) (f 1 1 2 1) (f 1 2 2 2)))\n (princ \"Yes\")\n (princ \"No\")))", "problem_context": "Score: 300 points\n\nProblem Statement\n\nWe have a 3 \\times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left.\n\nAccording to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j.\n\nDetermine if he is correct.\n\nConstraints\n\nc_{i, j} \\ (1 \\leq i \\leq 3, 1 \\leq j \\leq 3) is an integer between 0 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nc_{1,1} c_{1,2} c_{1,3}\nc_{2,1} c_{2,2} c_{2,3}\nc_{3,1} c_{3,2} c_{3,3}\n\nOutput\n\nIf Takahashi's statement is correct, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 0 1\n2 1 2\n1 0 1\n\nSample Output 1\n\nYes\n\nTakahashi is correct, since there are possible sets of integers such as: a_1=0,a_2=1,a_3=0,b_1=1,b_2=0,b_3=1.\n\nSample Input 2\n\n2 2 2\n2 1 2\n2 2 2\n\nSample Output 2\n\nNo\n\nTakahashi is incorrect in this case.\n\nSample Input 3\n\n0 8 8\n0 8 8\n0 8 8\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n1 8 6\n2 9 7\n0 7 7\n\nSample Output 4\n\nNo", "sample_input": "1 0 1\n2 1 2\n1 0 1\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03435", "source_text": "Score: 300 points\n\nProblem Statement\n\nWe have a 3 \\times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left.\n\nAccording to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j.\n\nDetermine if he is correct.\n\nConstraints\n\nc_{i, j} \\ (1 \\leq i \\leq 3, 1 \\leq j \\leq 3) is an integer between 0 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nc_{1,1} c_{1,2} c_{1,3}\nc_{2,1} c_{2,2} c_{2,3}\nc_{3,1} c_{3,2} c_{3,3}\n\nOutput\n\nIf Takahashi's statement is correct, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 0 1\n2 1 2\n1 0 1\n\nSample Output 1\n\nYes\n\nTakahashi is correct, since there are possible sets of integers such as: a_1=0,a_2=1,a_3=0,b_1=1,b_2=0,b_3=1.\n\nSample Input 2\n\n2 2 2\n2 1 2\n2 2 2\n\nSample Output 2\n\nNo\n\nTakahashi is incorrect in this case.\n\nSample Input 3\n\n0 8 8\n0 8 8\n0 8 8\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n1 8 6\n2 9 7\n0 7 7\n\nSample Output 4\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 387, "cpu_time_ms": 40, "memory_kb": 5344}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s770529523", "group_id": "codeNet:p03435", "input_text": "(defun solver ()\n (let ((c1 (make-array 9 :fill-pointer 0))\n (c2 (make-array 9))\n (a (make-array 3))\n (b (make-array 3)))\n (loop repeat 9 do\n (vector-push (read) c1))\n (setf (aref a 0) 0\n (aref b 0) (aref c1 0)\n (aref b 1) (aref c1 1)\n (aref b 2) (aref c1 2)\n (aref a 1) (- (aref c1 3) (aref b 0))\n (aref a 2) (- (aref c1 6) (aref b 0)))\n (loop for i from 0 to 2 do\n (setf (aref c2 i) (+ (aref a 0) (aref b i))\n (aref c2 (+ i 3)) (+ (aref a 1) (aref b i))\n (aref c2 (+ i 6)) (+ (aref a 2) (aref b i))))\n (if (equalp c1 c2)\n (format t \"Yes~%\")\n (format t \"No~%\"))))\n\n(solver)\n", "language": "Lisp", "metadata": {"date": 1519992983, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03435.html", "problem_id": "p03435", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03435/input.txt", "sample_output_relpath": "derived/input_output/data/p03435/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03435/Lisp/s770529523.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s770529523", "user_id": "u183015556"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun solver ()\n (let ((c1 (make-array 9 :fill-pointer 0))\n (c2 (make-array 9))\n (a (make-array 3))\n (b (make-array 3)))\n (loop repeat 9 do\n (vector-push (read) c1))\n (setf (aref a 0) 0\n (aref b 0) (aref c1 0)\n (aref b 1) (aref c1 1)\n (aref b 2) (aref c1 2)\n (aref a 1) (- (aref c1 3) (aref b 0))\n (aref a 2) (- (aref c1 6) (aref b 0)))\n (loop for i from 0 to 2 do\n (setf (aref c2 i) (+ (aref a 0) (aref b i))\n (aref c2 (+ i 3)) (+ (aref a 1) (aref b i))\n (aref c2 (+ i 6)) (+ (aref a 2) (aref b i))))\n (if (equalp c1 c2)\n (format t \"Yes~%\")\n (format t \"No~%\"))))\n\n(solver)\n", "problem_context": "Score: 300 points\n\nProblem Statement\n\nWe have a 3 \\times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left.\n\nAccording to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j.\n\nDetermine if he is correct.\n\nConstraints\n\nc_{i, j} \\ (1 \\leq i \\leq 3, 1 \\leq j \\leq 3) is an integer between 0 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nc_{1,1} c_{1,2} c_{1,3}\nc_{2,1} c_{2,2} c_{2,3}\nc_{3,1} c_{3,2} c_{3,3}\n\nOutput\n\nIf Takahashi's statement is correct, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 0 1\n2 1 2\n1 0 1\n\nSample Output 1\n\nYes\n\nTakahashi is correct, since there are possible sets of integers such as: a_1=0,a_2=1,a_3=0,b_1=1,b_2=0,b_3=1.\n\nSample Input 2\n\n2 2 2\n2 1 2\n2 2 2\n\nSample Output 2\n\nNo\n\nTakahashi is incorrect in this case.\n\nSample Input 3\n\n0 8 8\n0 8 8\n0 8 8\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n1 8 6\n2 9 7\n0 7 7\n\nSample Output 4\n\nNo", "sample_input": "1 0 1\n2 1 2\n1 0 1\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03435", "source_text": "Score: 300 points\n\nProblem Statement\n\nWe have a 3 \\times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left.\n\nAccording to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j.\n\nDetermine if he is correct.\n\nConstraints\n\nc_{i, j} \\ (1 \\leq i \\leq 3, 1 \\leq j \\leq 3) is an integer between 0 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nc_{1,1} c_{1,2} c_{1,3}\nc_{2,1} c_{2,2} c_{2,3}\nc_{3,1} c_{3,2} c_{3,3}\n\nOutput\n\nIf Takahashi's statement is correct, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 0 1\n2 1 2\n1 0 1\n\nSample Output 1\n\nYes\n\nTakahashi is correct, since there are possible sets of integers such as: a_1=0,a_2=1,a_3=0,b_1=1,b_2=0,b_3=1.\n\nSample Input 2\n\n2 2 2\n2 1 2\n2 2 2\n\nSample Output 2\n\nNo\n\nTakahashi is incorrect in this case.\n\nSample Input 3\n\n0 8 8\n0 8 8\n0 8 8\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n1 8 6\n2 9 7\n0 7 7\n\nSample Output 4\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 716, "cpu_time_ms": 30, "memory_kb": 6632}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s254193642", "group_id": "codeNet:p03436", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Queue with singly linked list\n;;;\n\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Removes and returns the element at the front of QUEUE. Returns NIL if QUEUE\nis empty.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline queue-peek))\n(defun queue-peek (queue)\n (car (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #xffffffff)\n(defun main ()\n (let* ((h (read))\n (w (read))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0))\n (black 0)\n (que (make-queue))\n (dists (make-array (list h w) :element-type 'uint32 :initial-element +inf+)))\n (declare (uint8 h w))\n (dotimes (y h)\n (dotimes (x w (read-char))\n (when (char= #\\# (read-char))\n (setf (aref plan y x) 1)\n (incf black))))\n (labels ((visit (y x new-dist)\n (when (and (<= 0 y (- h 1))\n (<= 0 x (- w 1))\n (= (aref dists y x) +inf+)\n (zerop (aref plan y x)))\n (enqueue (cons y x) que)\n (setf (aref dists y x) new-dist))))\n (visit 0 0 1)\n (loop until (queue-empty-p que)\n for (y . x) = (dequeue que)\n for dist = (aref dists y x)\n do (visit (- y 1) x (+ dist 1))\n (visit (+ y 1) x (+ dist 1))\n (visit y (- x 1) (+ dist 1))\n (visit y (+ x 1) (+ dist 1)))\n (let ((res (aref dists (- h 1) (- w 1))))\n (println\n (if (= res +inf+)\n -1\n (- (- (* h w) res) black)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n..#\n#..\n...\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 37\n.....................................\n...#...####...####..###...###...###..\n..#.#..#...#.##....#...#.#...#.#...#.\n..#.#..#...#.#.....#...#.#...#.#...#.\n.#...#.#..##.#.....#...#.#.###.#.###.\n.#####.####..#.....#...#..##....##...\n.#...#.#...#.#.....#...#.#...#.#...#.\n.#...#.#...#.##....#...#.#...#.#...#.\n.#...#.####...####..###...###...###..\n.....................................\n\"\n \"209\n\")))\n", "language": "Lisp", "metadata": {"date": 1579940297, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03436.html", "problem_id": "p03436", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03436/input.txt", "sample_output_relpath": "derived/input_output/data/p03436/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03436/Lisp/s254193642.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s254193642", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Queue with singly linked list\n;;;\n\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Removes and returns the element at the front of QUEUE. Returns NIL if QUEUE\nis empty.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline queue-peek))\n(defun queue-peek (queue)\n (car (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #xffffffff)\n(defun main ()\n (let* ((h (read))\n (w (read))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0))\n (black 0)\n (que (make-queue))\n (dists (make-array (list h w) :element-type 'uint32 :initial-element +inf+)))\n (declare (uint8 h w))\n (dotimes (y h)\n (dotimes (x w (read-char))\n (when (char= #\\# (read-char))\n (setf (aref plan y x) 1)\n (incf black))))\n (labels ((visit (y x new-dist)\n (when (and (<= 0 y (- h 1))\n (<= 0 x (- w 1))\n (= (aref dists y x) +inf+)\n (zerop (aref plan y x)))\n (enqueue (cons y x) que)\n (setf (aref dists y x) new-dist))))\n (visit 0 0 1)\n (loop until (queue-empty-p que)\n for (y . x) = (dequeue que)\n for dist = (aref dists y x)\n do (visit (- y 1) x (+ dist 1))\n (visit (+ y 1) x (+ dist 1))\n (visit y (- x 1) (+ dist 1))\n (visit y (+ x 1) (+ dist 1)))\n (let ((res (aref dists (- h 1) (- w 1))))\n (println\n (if (= res +inf+)\n -1\n (- (- (* h w) res) black)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n..#\n#..\n...\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 37\n.....................................\n...#...####...####..###...###...###..\n..#.#..#...#.##....#...#.#...#.#...#.\n..#.#..#...#.#.....#...#.#...#.#...#.\n.#...#.#..##.#.....#...#.#.###.#.###.\n.#####.####..#.....#...#..##....##...\n.#...#.#...#.#.....#...#.#...#.#...#.\n.#...#.#...#.##....#...#.#...#.#...#.\n.#...#.####...####..###...###...###..\n.....................................\n\"\n \"209\n\")))\n", "problem_context": "Score: 400 points\n\nProblem statement\n\nWe have an H \\times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j).\n\nSnuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares.\n\nBefore Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game.\n\nWhen the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares.\n\nThe color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is .; if square (i, j) is initially painted by black, s_{i, j} is #.\n\nConstraints\n\nH is an integer between 2 and 50 (inclusive).\n\nW is an integer between 2 and 50 (inclusive).\n\ns_{i, j} is . or # (1 \\leq i \\leq H, 1 \\leq j \\leq W).\n\ns_{1, 1} and s_{H, W} are ..\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\ns_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W}\ns_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W}\n: :\ns_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}\n\nOutput\n\nPrint the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed.\n\nSample Input 1\n\n3 3\n..#\n#..\n...\n\nSample Output 1\n\n2\n\nThe score 2 can be achieved by changing the color of squares as follows:\n\nSample Input 2\n\n10 37\n.....................................\n...#...####...####..###...###...###..\n..#.#..#...#.##....#...#.#...#.#...#.\n..#.#..#...#.#.....#...#.#...#.#...#.\n.#...#.#..##.#.....#...#.#.###.#.###.\n.#####.####..#.....#...#..##....##...\n.#...#.#...#.#.....#...#.#...#.#...#.\n.#...#.#...#.##....#...#.#...#.#...#.\n.#...#.####...####..###...###...###..\n.....................................\n\nSample Output 2\n\n209", "sample_input": "3 3\n..#\n#..\n...\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03436", "source_text": "Score: 400 points\n\nProblem statement\n\nWe have an H \\times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j).\n\nSnuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares.\n\nBefore Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game.\n\nWhen the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares.\n\nThe color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is .; if square (i, j) is initially painted by black, s_{i, j} is #.\n\nConstraints\n\nH is an integer between 2 and 50 (inclusive).\n\nW is an integer between 2 and 50 (inclusive).\n\ns_{i, j} is . or # (1 \\leq i \\leq H, 1 \\leq j \\leq W).\n\ns_{1, 1} and s_{H, W} are ..\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\ns_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W}\ns_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W}\n: :\ns_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}\n\nOutput\n\nPrint the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed.\n\nSample Input 1\n\n3 3\n..#\n#..\n...\n\nSample Output 1\n\n2\n\nThe score 2 can be achieved by changing the color of squares as follows:\n\nSample Input 2\n\n10 37\n.....................................\n...#...####...####..###...###...###..\n..#.#..#...#.##....#...#.#...#.#...#.\n..#.#..#...#.#.....#...#.#...#.#...#.\n.#...#.#..##.#.....#...#.#.###.#.###.\n.#####.####..#.....#...#..##....##...\n.#...#.#...#.#.....#...#.#...#.#...#.\n.#...#.#...#.##....#...#.#...#.#...#.\n.#...#.####...####..###...###...###..\n.....................................\n\nSample Output 2\n\n209", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6521, "cpu_time_ms": 211, "memory_kb": 27364}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s012524678", "group_id": "codeNet:p03440", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Disjoint set by Union-Find algorithm\n;;;\n\n(defstruct (disjoint-set\n (:constructor make-disjoint-set\n (size &aux (data (make-array size :element-type 'fixnum :initial-element -1))))\n (:conc-name ds-))\n (data nil :type (simple-array fixnum (*))))\n\n(declaim (ftype (function * (values (mod #.array-total-size-limit) &optional)) ds-root))\n(defun ds-root (disjoint-set x)\n \"Returns the root of X.\"\n (declare (optimize (speed 3))\n ((mod #.array-total-size-limit) x))\n (let ((data (ds-data disjoint-set)))\n (if (< (aref data x) 0)\n x\n (setf (aref data x)\n (ds-root disjoint-set (aref data x))))))\n\n(declaim (inline ds-unite!))\n(defun ds-unite! (disjoint-set x1 x2)\n \"Destructively unites X1 and X2 and returns true iff X1 and X2 become\nconnected for the first time.\"\n (let ((root1 (ds-root disjoint-set x1))\n (root2 (ds-root disjoint-set x2)))\n (unless (= root1 root2)\n (let ((data (ds-data disjoint-set)))\n ;; ensure the size of root1 >= the size of root2\n (when (> (aref data root1) (aref data root2))\n (rotatef root1 root2))\n (incf (aref data root1) (aref data root2))\n (setf (aref data root2) root1)))))\n\n(declaim (inline ds-connected-p))\n(defun ds-connected-p (disjoint-set x1 x2)\n \"Returns true iff X1 and X2 have the same root.\"\n (= (ds-root disjoint-set x1) (ds-root disjoint-set x2)))\n\n(declaim (inline ds-size))\n(defun ds-size (disjoint-set x)\n \"Returns the size of the connected component to which X belongs.\"\n (- (aref (ds-data disjoint-set)\n (ds-root disjoint-set x))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;;;\n;;; Meldable heap (pairing heap)\n;;;\n;;; Reference:\n;;; https://topcoder.g.hatena.ne.jp/spaghetti_source/20120929/1348886107\n;;;\n\n;; Note: An empty heap is NIL.\n;; TODO: handle the order of heap independently\n(defstruct (pheap (:constructor %make-pheap (key))\n (:conc-name %pheap-)\n (:copier nil)\n (:predicate nil))\n (key nil :type uint62)\n (next nil :type (or null pheap))\n (head nil :type (or null pheap)) ; head of children\n )\n\n(declaim (inline pheap-merge))\n(defun pheap-merge (node1 node2 order)\n (cond ((null node1) node2)\n ((null node2) node1)\n (t\n ;; ensure NODE1 < NODE2\n (when (funcall order (%pheap-key node2) (%pheap-key node1))\n (rotatef node1 node2))\n (setf (%pheap-next node2) (%pheap-head node1)\n (%pheap-head node1) node2)\n node1)))\n\n(declaim (inline %pheap-merge-list1 %pheap-merge-list2 %pheap-merge-list3))\n\n;; NOTE: Three implementations are available for MERGE-LIST, each of which has\n;; good points and bad points.\n\n;; Implementation 1, naive recursion\n;; Pros: fastest on SBCL, no consing\n;; Cons: there is a risk of stack exhaustion\n\n(defun %pheap-merge-list1 (node order)\n (labels ((recur (node)\n (when node\n (let* ((a node)\n (b (%pheap-next node)))\n (if b\n (let ((next (%pheap-next b)))\n (setf (%pheap-next b) nil)\n (let ((a+b (pheap-merge a b order)))\n (pheap-merge a+b (recur next) order)))\n a)))))\n (recur node)))\n\n;; Implementation 2, manual stack by list\n;; Pros: stack safe\n;; Cons: most consing, 15% slower\n\n(defun %pheap-merge-list2 (node order)\n (let (stack)\n (loop\n (unless node (return))\n (let ((a node)\n b)\n (setf node (%pheap-next node)\n (%pheap-next a) nil)\n (when node\n (setf b node\n node (%pheap-next node)\n (%pheap-next b) nil))\n (push (pheap-merge a b order) stack)))\n (dolist (part stack)\n (setf node (pheap-merge part node order)))\n node))\n\n;; Implementation 3, manual stack by PHEAP\n;; Pros: stack safe, no consing\n;; Cons: a bit trickey, 5% slower\n\n(defun %pheap-merge-list3 (node order)\n (let ((stack (load-time-value (sb-mop:class-prototype (find-class 'pheap)))))\n (setf (%pheap-next stack) nil)\n (loop\n (unless node (return))\n (let ((a node)\n b)\n (setf node (%pheap-next node)\n (%pheap-next a) nil)\n (when node\n (setf b node\n node (%pheap-next node)\n (%pheap-next b) nil))\n (setf a (pheap-merge a b order)\n (%pheap-next a) (%pheap-next stack)\n (%pheap-next stack) a)))\n (loop\n (unless (%pheap-next stack) (return))\n (let ((next (%pheap-next stack)))\n (setf (%pheap-next stack)\n (%pheap-next (%pheap-next stack)))\n (setf node (pheap-merge next node order))))\n node))\n\n(declaim (inline pheep-peek))\n(defun pheap-peek (node)\n (%pheap-key node))\n\n;; Here we adopt clojure-like terms CONJ/DISJ as these are not operations to\n;; make use of side effects, unlike PUSH/POP.\n(declaim (inline pheap-conj))\n(defun pheap-conj (node key order)\n (pheap-merge node (%make-pheap key) order))\n\n(declaim (inline pheap-disj))\n(defun pheap-disj (node order)\n (declare (pheap node))\n (%pheap-merge-list3 (%pheap-head node) order))\n\n(defmacro pheap-push (key node order)\n `(setf ,node (pheap-conj ,node ,key ,order)))\n\n(defmacro pheap-pop (node order)\n `(prog1 (pheap-peek ,node)\n (setf ,node (pheap-disj ,node ,order))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (as (make-array n :element-type 'uint32))\n (comps (make-array n :element-type '(or null pheap) :initial-element nil))\n (dset (make-disjoint-set n))\n (que nil)\n (comp-n (- n m))\n (res 0))\n (declare (uint32 n m)\n (uint62 res))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i m)\n (let ((x (read-fixnum))\n (y (read-fixnum)))\n (ds-unite! dset x y)))\n (when (= comp-n 1)\n (println 0)\n (return-from main))\n (dotimes (i n)\n (let ((root (ds-root dset i)))\n (pheap-push (aref as i) (aref comps root) #'<)))\n #>comps\n (dotimes (i n)\n (let ((comp (aref comps i)))\n (when (aref comps i)\n (let ((top (pheap-pop comp #'<)))\n (incf res top)\n (setf que (pheap-merge que comp #'<))))))\n #>res\n (dotimes (i (- n m 2))\n (unless que\n (write-line \"Impossible\")\n (return-from main))\n (incf res (pheap-pop que #'<)))\n (println res)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1569990880, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03440.html", "problem_id": "p03440", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03440/input.txt", "sample_output_relpath": "derived/input_output/data/p03440/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03440/Lisp/s012524678.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s012524678", "user_id": "u352600849"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Disjoint set by Union-Find algorithm\n;;;\n\n(defstruct (disjoint-set\n (:constructor make-disjoint-set\n (size &aux (data (make-array size :element-type 'fixnum :initial-element -1))))\n (:conc-name ds-))\n (data nil :type (simple-array fixnum (*))))\n\n(declaim (ftype (function * (values (mod #.array-total-size-limit) &optional)) ds-root))\n(defun ds-root (disjoint-set x)\n \"Returns the root of X.\"\n (declare (optimize (speed 3))\n ((mod #.array-total-size-limit) x))\n (let ((data (ds-data disjoint-set)))\n (if (< (aref data x) 0)\n x\n (setf (aref data x)\n (ds-root disjoint-set (aref data x))))))\n\n(declaim (inline ds-unite!))\n(defun ds-unite! (disjoint-set x1 x2)\n \"Destructively unites X1 and X2 and returns true iff X1 and X2 become\nconnected for the first time.\"\n (let ((root1 (ds-root disjoint-set x1))\n (root2 (ds-root disjoint-set x2)))\n (unless (= root1 root2)\n (let ((data (ds-data disjoint-set)))\n ;; ensure the size of root1 >= the size of root2\n (when (> (aref data root1) (aref data root2))\n (rotatef root1 root2))\n (incf (aref data root1) (aref data root2))\n (setf (aref data root2) root1)))))\n\n(declaim (inline ds-connected-p))\n(defun ds-connected-p (disjoint-set x1 x2)\n \"Returns true iff X1 and X2 have the same root.\"\n (= (ds-root disjoint-set x1) (ds-root disjoint-set x2)))\n\n(declaim (inline ds-size))\n(defun ds-size (disjoint-set x)\n \"Returns the size of the connected component to which X belongs.\"\n (- (aref (ds-data disjoint-set)\n (ds-root disjoint-set x))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;;;\n;;; Meldable heap (pairing heap)\n;;;\n;;; Reference:\n;;; https://topcoder.g.hatena.ne.jp/spaghetti_source/20120929/1348886107\n;;;\n\n;; Note: An empty heap is NIL.\n;; TODO: handle the order of heap independently\n(defstruct (pheap (:constructor %make-pheap (key))\n (:conc-name %pheap-)\n (:copier nil)\n (:predicate nil))\n (key nil :type uint62)\n (next nil :type (or null pheap))\n (head nil :type (or null pheap)) ; head of children\n )\n\n(declaim (inline pheap-merge))\n(defun pheap-merge (node1 node2 order)\n (cond ((null node1) node2)\n ((null node2) node1)\n (t\n ;; ensure NODE1 < NODE2\n (when (funcall order (%pheap-key node2) (%pheap-key node1))\n (rotatef node1 node2))\n (setf (%pheap-next node2) (%pheap-head node1)\n (%pheap-head node1) node2)\n node1)))\n\n(declaim (inline %pheap-merge-list1 %pheap-merge-list2 %pheap-merge-list3))\n\n;; NOTE: Three implementations are available for MERGE-LIST, each of which has\n;; good points and bad points.\n\n;; Implementation 1, naive recursion\n;; Pros: fastest on SBCL, no consing\n;; Cons: there is a risk of stack exhaustion\n\n(defun %pheap-merge-list1 (node order)\n (labels ((recur (node)\n (when node\n (let* ((a node)\n (b (%pheap-next node)))\n (if b\n (let ((next (%pheap-next b)))\n (setf (%pheap-next b) nil)\n (let ((a+b (pheap-merge a b order)))\n (pheap-merge a+b (recur next) order)))\n a)))))\n (recur node)))\n\n;; Implementation 2, manual stack by list\n;; Pros: stack safe\n;; Cons: most consing, 15% slower\n\n(defun %pheap-merge-list2 (node order)\n (let (stack)\n (loop\n (unless node (return))\n (let ((a node)\n b)\n (setf node (%pheap-next node)\n (%pheap-next a) nil)\n (when node\n (setf b node\n node (%pheap-next node)\n (%pheap-next b) nil))\n (push (pheap-merge a b order) stack)))\n (dolist (part stack)\n (setf node (pheap-merge part node order)))\n node))\n\n;; Implementation 3, manual stack by PHEAP\n;; Pros: stack safe, no consing\n;; Cons: a bit trickey, 5% slower\n\n(defun %pheap-merge-list3 (node order)\n (let ((stack (load-time-value (sb-mop:class-prototype (find-class 'pheap)))))\n (setf (%pheap-next stack) nil)\n (loop\n (unless node (return))\n (let ((a node)\n b)\n (setf node (%pheap-next node)\n (%pheap-next a) nil)\n (when node\n (setf b node\n node (%pheap-next node)\n (%pheap-next b) nil))\n (setf a (pheap-merge a b order)\n (%pheap-next a) (%pheap-next stack)\n (%pheap-next stack) a)))\n (loop\n (unless (%pheap-next stack) (return))\n (let ((next (%pheap-next stack)))\n (setf (%pheap-next stack)\n (%pheap-next (%pheap-next stack)))\n (setf node (pheap-merge next node order))))\n node))\n\n(declaim (inline pheep-peek))\n(defun pheap-peek (node)\n (%pheap-key node))\n\n;; Here we adopt clojure-like terms CONJ/DISJ as these are not operations to\n;; make use of side effects, unlike PUSH/POP.\n(declaim (inline pheap-conj))\n(defun pheap-conj (node key order)\n (pheap-merge node (%make-pheap key) order))\n\n(declaim (inline pheap-disj))\n(defun pheap-disj (node order)\n (declare (pheap node))\n (%pheap-merge-list3 (%pheap-head node) order))\n\n(defmacro pheap-push (key node order)\n `(setf ,node (pheap-conj ,node ,key ,order)))\n\n(defmacro pheap-pop (node order)\n `(prog1 (pheap-peek ,node)\n (setf ,node (pheap-disj ,node ,order))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (as (make-array n :element-type 'uint32))\n (comps (make-array n :element-type '(or null pheap) :initial-element nil))\n (dset (make-disjoint-set n))\n (que nil)\n (comp-n (- n m))\n (res 0))\n (declare (uint32 n m)\n (uint62 res))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i m)\n (let ((x (read-fixnum))\n (y (read-fixnum)))\n (ds-unite! dset x y)))\n (when (= comp-n 1)\n (println 0)\n (return-from main))\n (dotimes (i n)\n (let ((root (ds-root dset i)))\n (pheap-push (aref as i) (aref comps root) #'<)))\n #>comps\n (dotimes (i n)\n (let ((comp (aref comps i)))\n (when (aref comps i)\n (let ((top (pheap-pop comp #'<)))\n (incf res top)\n (setf que (pheap-merge que comp #'<))))))\n #>res\n (dotimes (i (- n m 2))\n (unless que\n (write-line \"Impossible\")\n (return-from main))\n (incf res (pheap-pop que #'<)))\n (println res)))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nYou are given a forest with N vertices and M edges. The vertices are numbered 0 through N-1.\nThe edges are given in the format (x_i,y_i), which means that Vertex x_i and y_i are connected by an edge.\n\nEach vertex i has a value a_i.\nYou want to add edges in the given forest so that the forest becomes connected.\nTo add an edge, you choose two different vertices i and j, then span an edge between i and j.\nThis operation costs a_i + a_j dollars, and afterward neither Vertex i nor j can be selected again.\n\nFind the minimum total cost required to make the forest connected, or print Impossible if it is impossible.\n\nConstraints\n\n1 ≤ N ≤ 100,000\n\n0 ≤ M ≤ N-1\n\n1 ≤ a_i ≤ 10^9\n\n0 ≤ x_i,y_i ≤ N-1\n\nThe given graph is a forest.\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_0 a_1 .. a_{N-1}\nx_1 y_1\nx_2 y_2\n:\nx_M y_M\n\nOutput\n\nPrint the minimum total cost required to make the forest connected, or print Impossible if it is impossible.\n\nSample Input 1\n\n7 5\n1 2 3 4 5 6 7\n3 0\n4 0\n1 2\n1 3\n5 6\n\nSample Output 1\n\n7\n\nIf we connect vertices 0 and 5, the graph becomes connected, for the cost of 1 + 6 = 7 dollars.\n\nSample Input 2\n\n5 0\n3 1 4 1 5\n\nSample Output 2\n\nImpossible\n\nWe can't make the graph connected.\n\nSample Input 3\n\n1 0\n5\n\nSample Output 3\n\n0\n\nThe graph is already connected, so we do not need to add any edges.", "sample_input": "7 5\n1 2 3 4 5 6 7\n3 0\n4 0\n1 2\n1 3\n5 6\n"}, "reference_outputs": ["7\n"], "source_document_id": "p03440", "source_text": "Score : 600 points\n\nProblem Statement\n\nYou are given a forest with N vertices and M edges. The vertices are numbered 0 through N-1.\nThe edges are given in the format (x_i,y_i), which means that Vertex x_i and y_i are connected by an edge.\n\nEach vertex i has a value a_i.\nYou want to add edges in the given forest so that the forest becomes connected.\nTo add an edge, you choose two different vertices i and j, then span an edge between i and j.\nThis operation costs a_i + a_j dollars, and afterward neither Vertex i nor j can be selected again.\n\nFind the minimum total cost required to make the forest connected, or print Impossible if it is impossible.\n\nConstraints\n\n1 ≤ N ≤ 100,000\n\n0 ≤ M ≤ N-1\n\n1 ≤ a_i ≤ 10^9\n\n0 ≤ x_i,y_i ≤ N-1\n\nThe given graph is a forest.\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_0 a_1 .. a_{N-1}\nx_1 y_1\nx_2 y_2\n:\nx_M y_M\n\nOutput\n\nPrint the minimum total cost required to make the forest connected, or print Impossible if it is impossible.\n\nSample Input 1\n\n7 5\n1 2 3 4 5 6 7\n3 0\n4 0\n1 2\n1 3\n5 6\n\nSample Output 1\n\n7\n\nIf we connect vertices 0 and 5, the graph becomes connected, for the cost of 1 + 6 = 7 dollars.\n\nSample Input 2\n\n5 0\n3 1 4 1 5\n\nSample Output 2\n\nImpossible\n\nWe can't make the graph connected.\n\nSample Input 3\n\n1 0\n5\n\nSample Output 3\n\n0\n\nThe graph is already connected, so we do not need to add any edges.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8929, "cpu_time_ms": 299, "memory_kb": 39908}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s644872553", "group_id": "codeNet:p03447", "input_text": "(let* ((x (read))\n (a (read))\n (b (read))\n (y (- x a)))\n\n (format t \"~A~%\"\n (mod y b)))\n", "language": "Lisp", "metadata": {"date": 1597965210, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03447.html", "problem_id": "p03447", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03447/input.txt", "sample_output_relpath": "derived/input_output/data/p03447/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03447/Lisp/s644872553.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s644872553", "user_id": "u336541610"}, "prompt_components": {"gold_output": "84\n", "input_to_evaluate": "(let* ((x (read))\n (a (read))\n (b (read))\n (y (- x a)))\n\n (format t \"~A~%\"\n (mod y b)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou went shopping to buy cakes and donuts with X yen (the currency of Japan).\n\nFirst, you bought one cake for A yen at a cake shop.\nThen, you bought as many donuts as possible for B yen each, at a donut shop.\n\nHow much do you have left after shopping?\n\nConstraints\n\n1 \\leq A, B \\leq 1 000\n\nA + B \\leq X \\leq 10 000\n\nX, A and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\nA\nB\n\nOutput\n\nPrint the amount you have left after shopping.\n\nSample Input 1\n\n1234\n150\n100\n\nSample Output 1\n\n84\n\nYou have 1234 - 150 = 1084 yen left after buying a cake.\nWith this amount, you can buy 10 donuts, after which you have 84 yen left.\n\nSample Input 2\n\n1000\n108\n108\n\nSample Output 2\n\n28\n\nSample Input 3\n\n579\n123\n456\n\nSample Output 3\n\n0\n\nSample Input 4\n\n7477\n549\n593\n\nSample Output 4\n\n405", "sample_input": "1234\n150\n100\n"}, "reference_outputs": ["84\n"], "source_document_id": "p03447", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou went shopping to buy cakes and donuts with X yen (the currency of Japan).\n\nFirst, you bought one cake for A yen at a cake shop.\nThen, you bought as many donuts as possible for B yen each, at a donut shop.\n\nHow much do you have left after shopping?\n\nConstraints\n\n1 \\leq A, B \\leq 1 000\n\nA + B \\leq X \\leq 10 000\n\nX, A and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\nA\nB\n\nOutput\n\nPrint the amount you have left after shopping.\n\nSample Input 1\n\n1234\n150\n100\n\nSample Output 1\n\n84\n\nYou have 1234 - 150 = 1084 yen left after buying a cake.\nWith this amount, you can buy 10 donuts, after which you have 84 yen left.\n\nSample Input 2\n\n1000\n108\n108\n\nSample Output 2\n\n28\n\nSample Input 3\n\n579\n123\n456\n\nSample Output 3\n\n0\n\nSample Input 4\n\n7477\n549\n593\n\nSample Output 4\n\n405", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 116, "cpu_time_ms": 17, "memory_kb": 24252}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s006748395", "group_id": "codeNet:p03447", "input_text": "(let* ((n (read))\n (a (read))\n (b (read)))\n (format t \"~a~%\" (mod (- n a) b)))\n", "language": "Lisp", "metadata": {"date": 1517716009, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03447.html", "problem_id": "p03447", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03447/input.txt", "sample_output_relpath": "derived/input_output/data/p03447/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03447/Lisp/s006748395.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s006748395", "user_id": "u994767958"}, "prompt_components": {"gold_output": "84\n", "input_to_evaluate": "(let* ((n (read))\n (a (read))\n (b (read)))\n (format t \"~a~%\" (mod (- n a) b)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou went shopping to buy cakes and donuts with X yen (the currency of Japan).\n\nFirst, you bought one cake for A yen at a cake shop.\nThen, you bought as many donuts as possible for B yen each, at a donut shop.\n\nHow much do you have left after shopping?\n\nConstraints\n\n1 \\leq A, B \\leq 1 000\n\nA + B \\leq X \\leq 10 000\n\nX, A and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\nA\nB\n\nOutput\n\nPrint the amount you have left after shopping.\n\nSample Input 1\n\n1234\n150\n100\n\nSample Output 1\n\n84\n\nYou have 1234 - 150 = 1084 yen left after buying a cake.\nWith this amount, you can buy 10 donuts, after which you have 84 yen left.\n\nSample Input 2\n\n1000\n108\n108\n\nSample Output 2\n\n28\n\nSample Input 3\n\n579\n123\n456\n\nSample Output 3\n\n0\n\nSample Input 4\n\n7477\n549\n593\n\nSample Output 4\n\n405", "sample_input": "1234\n150\n100\n"}, "reference_outputs": ["84\n"], "source_document_id": "p03447", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou went shopping to buy cakes and donuts with X yen (the currency of Japan).\n\nFirst, you bought one cake for A yen at a cake shop.\nThen, you bought as many donuts as possible for B yen each, at a donut shop.\n\nHow much do you have left after shopping?\n\nConstraints\n\n1 \\leq A, B \\leq 1 000\n\nA + B \\leq X \\leq 10 000\n\nX, A and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\nA\nB\n\nOutput\n\nPrint the amount you have left after shopping.\n\nSample Input 1\n\n1234\n150\n100\n\nSample Output 1\n\n84\n\nYou have 1234 - 150 = 1084 yen left after buying a cake.\nWith this amount, you can buy 10 donuts, after which you have 84 yen left.\n\nSample Input 2\n\n1000\n108\n108\n\nSample Output 2\n\n28\n\nSample Input 3\n\n579\n123\n456\n\nSample Output 3\n\n0\n\nSample Input 4\n\n7477\n549\n593\n\nSample Output 4\n\n405", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 92, "cpu_time_ms": 129, "memory_kb": 12768}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s179516306", "group_id": "codeNet:p03450", "input_text": ";; -*- coding:utf-8 -*-\n\n(defparameter *file-path* *load-pathname*)\n\n(defun clip-to-string ()\n (with-output-to-string (out)\n (sb-ext:run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n(defun test ()\n (with-input-from-string (*standard-input* (clip-to-string))\n (load *file-path*)))\n\n\n(defstruct (queue (:constructor\n\t\t $make-queue))\n arr\n (start 0 :type fixnum)\n (end 0 :type fixnum))\n\n(defun make-queue (size)\n ($make-queue :arr (make-array size :initial-element nil)\n\t :start 0\n\t :end 0))\n\n(defun null-queue (queue)\n \"Gibt T zurück, wenn QUEUE leer ist.\"\n (= (queue-start queue) (queue-end queue)))\n\n(defun enqueue (obj queue)\n (setf (aref (queue-arr queue) (queue-end queue)) obj)\n (incf (queue-end queue))\n queue)\n\n(defun enqueue-list (lst queue)\n (if (null lst)\n queue\n (enqueue-list (cdr lst)\n\t\t (enqueue queue (car lst)))))\n\t\n\n(defun dequeue (queue)\n (if (null-queue queue)\n (error \"QUEUE ist leer.\")\n (prog1 (aref (queue-arr queue) (queue-start queue))\n\t(incf (queue-start queue)))))\n\n(defun reset-queue (queue)\n (setf (queue-start queue) 0\n\t(queue-end queue) 0))\n\n(defstruct edge\n (dest 0 :type fixnum)\n (weight 0 :type fixnum))\n\n(defun read-graph (n m)\n (let ((graph (make-array n :element-type 'list :initial-element nil)))\n (dotimes (x m graph)\n (let* ((left (- (read) 1))\n\t (right (- (read) 1))\n\t (dist (read)))\n\t(push (make-edge :dest right :weight dist)\n\t (aref graph left))\n\t(push (make-edge :dest left :weight (- dist))\n\t (aref graph right))))))\n\n(defun find-new-idx (graph table)\n (loop for idx from 0 below (length graph)\n do (when (and (aref graph idx)\n\t\t (= (aref table idx) most-negative-fixnum))\n\t (return idx))\n finally (return -1)))\n\n(defun valid-p (graph)\n \"Breitensuche.\"\n (let* ((size (length graph))\n\t (queue (make-queue size))\n\t (table (make-array size\n\t\t\t :element-type 'fixnum\n\t\t\t :initial-element most-negative-fixnum)))\n (loop named main-loop\n for new-idx = (find-new-idx graph table)\n until (= -1 new-idx)\n finally (return-from main-loop t)\n do\n\t (reset-queue queue)\n\t (enqueue new-idx queue)\n\t (setf (aref table new-idx) 0) ; Die erste Zahl ist egal.\n\t (loop named sub-loop\n\t until (null-queue queue)\n\t do (let* ((start-idx (dequeue queue))\n\t\t (start-number (aref table start-idx))\n\t\t (edges (aref graph start-idx)))\n\t\t (dolist (edge edges)\n\t\t (let ((dest-idx (edge-dest edge))\n\t\t\t (dest-number (+ start-number (edge-weight edge))))\n\t\t (cond ((= most-negative-fixnum (aref table dest-idx))\n\t\t\t (setf (aref table dest-idx) dest-number)\n\t\t\t (enqueue dest-idx queue))\n\t\t\t ((/= (aref table dest-idx) dest-number)\n\t\t\t (return-from main-loop nil))))))))))\n\t \n\t\n\n(defun main ()\n (let* ((n (read))\n\t (m (read))\n\t (graph (read-graph n m)))\n (format t (if (valid-p graph)\n\t\t \"Yes~%\"\n\t\t \"No~%\"))))\n\t\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1519459297, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03450.html", "problem_id": "p03450", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03450/input.txt", "sample_output_relpath": "derived/input_output/data/p03450/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03450/Lisp/s179516306.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s179516306", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": ";; -*- coding:utf-8 -*-\n\n(defparameter *file-path* *load-pathname*)\n\n(defun clip-to-string ()\n (with-output-to-string (out)\n (sb-ext:run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n(defun test ()\n (with-input-from-string (*standard-input* (clip-to-string))\n (load *file-path*)))\n\n\n(defstruct (queue (:constructor\n\t\t $make-queue))\n arr\n (start 0 :type fixnum)\n (end 0 :type fixnum))\n\n(defun make-queue (size)\n ($make-queue :arr (make-array size :initial-element nil)\n\t :start 0\n\t :end 0))\n\n(defun null-queue (queue)\n \"Gibt T zurück, wenn QUEUE leer ist.\"\n (= (queue-start queue) (queue-end queue)))\n\n(defun enqueue (obj queue)\n (setf (aref (queue-arr queue) (queue-end queue)) obj)\n (incf (queue-end queue))\n queue)\n\n(defun enqueue-list (lst queue)\n (if (null lst)\n queue\n (enqueue-list (cdr lst)\n\t\t (enqueue queue (car lst)))))\n\t\n\n(defun dequeue (queue)\n (if (null-queue queue)\n (error \"QUEUE ist leer.\")\n (prog1 (aref (queue-arr queue) (queue-start queue))\n\t(incf (queue-start queue)))))\n\n(defun reset-queue (queue)\n (setf (queue-start queue) 0\n\t(queue-end queue) 0))\n\n(defstruct edge\n (dest 0 :type fixnum)\n (weight 0 :type fixnum))\n\n(defun read-graph (n m)\n (let ((graph (make-array n :element-type 'list :initial-element nil)))\n (dotimes (x m graph)\n (let* ((left (- (read) 1))\n\t (right (- (read) 1))\n\t (dist (read)))\n\t(push (make-edge :dest right :weight dist)\n\t (aref graph left))\n\t(push (make-edge :dest left :weight (- dist))\n\t (aref graph right))))))\n\n(defun find-new-idx (graph table)\n (loop for idx from 0 below (length graph)\n do (when (and (aref graph idx)\n\t\t (= (aref table idx) most-negative-fixnum))\n\t (return idx))\n finally (return -1)))\n\n(defun valid-p (graph)\n \"Breitensuche.\"\n (let* ((size (length graph))\n\t (queue (make-queue size))\n\t (table (make-array size\n\t\t\t :element-type 'fixnum\n\t\t\t :initial-element most-negative-fixnum)))\n (loop named main-loop\n for new-idx = (find-new-idx graph table)\n until (= -1 new-idx)\n finally (return-from main-loop t)\n do\n\t (reset-queue queue)\n\t (enqueue new-idx queue)\n\t (setf (aref table new-idx) 0) ; Die erste Zahl ist egal.\n\t (loop named sub-loop\n\t until (null-queue queue)\n\t do (let* ((start-idx (dequeue queue))\n\t\t (start-number (aref table start-idx))\n\t\t (edges (aref graph start-idx)))\n\t\t (dolist (edge edges)\n\t\t (let ((dest-idx (edge-dest edge))\n\t\t\t (dest-number (+ start-number (edge-weight edge))))\n\t\t (cond ((= most-negative-fixnum (aref table dest-idx))\n\t\t\t (setf (aref table dest-idx) dest-number)\n\t\t\t (enqueue dest-idx queue))\n\t\t\t ((/= (aref table dest-idx) dest-number)\n\t\t\t (return-from main-loop nil))))))))))\n\t \n\t\n\n(defun main ()\n (let* ((n (read))\n\t (m (read))\n\t (graph (read-graph n m)))\n (format t (if (valid-p graph)\n\t\t \"Yes~%\"\n\t\t \"No~%\"))))\n\t\n\n(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are N people standing on the x-axis.\nLet the coordinate of Person i be x_i.\nFor every i, x_i is an integer between 0 and 10^9 (inclusive).\nIt is possible that more than one person is standing at the same coordinate.\n\nYou will given M pieces of information regarding the positions of these people.\nThe i-th piece of information has the form (L_i, R_i, D_i).\nThis means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds.\n\nIt turns out that some of these M pieces of information may be incorrect.\nDetermine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.\n\nConstraints\n\n1 \\leq N \\leq 100 000\n\n0 \\leq M \\leq 200 000\n\n1 \\leq L_i, R_i \\leq N (1 \\leq i \\leq M)\n\n0 \\leq D_i \\leq 10 000 (1 \\leq i \\leq M)\n\nL_i \\neq R_i (1 \\leq i \\leq M)\n\nIf i \\neq j, then (L_i, R_i) \\neq (L_j, R_j) and (L_i, R_i) \\neq (R_j, L_j).\n\nD_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nL_1 R_1 D_1\nL_2 R_2 D_2\n:\nL_M R_M D_M\n\nOutput\n\nIf there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print Yes; if it does not exist, print No.\n\nSample Input 1\n\n3 3\n1 2 1\n2 3 1\n1 3 2\n\nSample Output 1\n\nYes\n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102, 103).\n\nSample Input 2\n\n3 3\n1 2 1\n2 3 1\n1 3 5\n\nSample Output 2\n\nNo\n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which is contradictory to the last piece of information.\n\nSample Input 3\n\n4 3\n2 1 1\n2 3 5\n3 4 2\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n10 3\n8 7 100\n7 9 100\n9 8 100\n\nSample Output 4\n\nNo\n\nSample Input 5\n\n100 0\n\nSample Output 5\n\nYes", "sample_input": "3 3\n1 2 1\n2 3 1\n1 3 2\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03450", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are N people standing on the x-axis.\nLet the coordinate of Person i be x_i.\nFor every i, x_i is an integer between 0 and 10^9 (inclusive).\nIt is possible that more than one person is standing at the same coordinate.\n\nYou will given M pieces of information regarding the positions of these people.\nThe i-th piece of information has the form (L_i, R_i, D_i).\nThis means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds.\n\nIt turns out that some of these M pieces of information may be incorrect.\nDetermine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.\n\nConstraints\n\n1 \\leq N \\leq 100 000\n\n0 \\leq M \\leq 200 000\n\n1 \\leq L_i, R_i \\leq N (1 \\leq i \\leq M)\n\n0 \\leq D_i \\leq 10 000 (1 \\leq i \\leq M)\n\nL_i \\neq R_i (1 \\leq i \\leq M)\n\nIf i \\neq j, then (L_i, R_i) \\neq (L_j, R_j) and (L_i, R_i) \\neq (R_j, L_j).\n\nD_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nL_1 R_1 D_1\nL_2 R_2 D_2\n:\nL_M R_M D_M\n\nOutput\n\nIf there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print Yes; if it does not exist, print No.\n\nSample Input 1\n\n3 3\n1 2 1\n2 3 1\n1 3 2\n\nSample Output 1\n\nYes\n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102, 103).\n\nSample Input 2\n\n3 3\n1 2 1\n2 3 1\n1 3 5\n\nSample Output 2\n\nNo\n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which is contradictory to the last piece of information.\n\nSample Input 3\n\n4 3\n2 1 1\n2 3 5\n3 4 2\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n10 3\n8 7 100\n7 9 100\n9 8 100\n\nSample Output 4\n\nNo\n\nSample Input 5\n\n100 0\n\nSample Output 5\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2931, "cpu_time_ms": 1279, "memory_kb": 88768}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s138837594", "group_id": "codeNet:p03452", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +nan+ #x7fffffff)\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (potentials (make-array n :element-type 'int32 :initial-element +nan+)))\n (dotimes (i m)\n (let ((l (- (read-fixnum) 1))\n (r (- (read-fixnum) 1))\n (d (read-fixnum)))\n (push (cons r d) (aref graph l))\n (push (cons l (- d)) (aref graph r))))\n (labels ((dfs (v pot)\n (cond ((= +nan+ (aref potentials v))\n (setf (aref potentials v) pot)\n (loop for (next . d) in (aref graph v)\n do (dfs next (+ pot d))))\n ((/= pot (aref potentials v))\n (write-line \"No\")\n (return-from main)))))\n (dotimes (v n)\n (when (= +nan+ (aref potentials v))\n (dfs v 0)))\n (write-line \"Yes\"))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1 2 1\n2 3 1\n1 3 2\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1 2 1\n2 3 1\n1 3 5\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 3\n2 1 1\n2 3 5\n3 4 2\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 3\n8 7 100\n7 9 100\n9 8 100\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"100 0\n\"\n \"Yes\n\")))\n", "language": "Lisp", "metadata": {"date": 1596078243, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03452.html", "problem_id": "p03452", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03452/input.txt", "sample_output_relpath": "derived/input_output/data/p03452/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03452/Lisp/s138837594.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s138837594", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +nan+ #x7fffffff)\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (potentials (make-array n :element-type 'int32 :initial-element +nan+)))\n (dotimes (i m)\n (let ((l (- (read-fixnum) 1))\n (r (- (read-fixnum) 1))\n (d (read-fixnum)))\n (push (cons r d) (aref graph l))\n (push (cons l (- d)) (aref graph r))))\n (labels ((dfs (v pot)\n (cond ((= +nan+ (aref potentials v))\n (setf (aref potentials v) pot)\n (loop for (next . d) in (aref graph v)\n do (dfs next (+ pot d))))\n ((/= pot (aref potentials v))\n (write-line \"No\")\n (return-from main)))))\n (dotimes (v n)\n (when (= +nan+ (aref potentials v))\n (dfs v 0)))\n (write-line \"Yes\"))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1 2 1\n2 3 1\n1 3 2\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1 2 1\n2 3 1\n1 3 5\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 3\n2 1 1\n2 3 5\n3 4 2\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 3\n8 7 100\n7 9 100\n9 8 100\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"100 0\n\"\n \"Yes\n\")))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are N people standing on the x-axis.\nLet the coordinate of Person i be x_i.\nFor every i, x_i is an integer between 0 and 10^9 (inclusive).\nIt is possible that more than one person is standing at the same coordinate.\n\nYou will given M pieces of information regarding the positions of these people.\nThe i-th piece of information has the form (L_i, R_i, D_i).\nThis means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds.\n\nIt turns out that some of these M pieces of information may be incorrect.\nDetermine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.\n\nConstraints\n\n1 \\leq N \\leq 100 000\n\n0 \\leq M \\leq 200 000\n\n1 \\leq L_i, R_i \\leq N (1 \\leq i \\leq M)\n\n0 \\leq D_i \\leq 10 000 (1 \\leq i \\leq M)\n\nL_i \\neq R_i (1 \\leq i \\leq M)\n\nIf i \\neq j, then (L_i, R_i) \\neq (L_j, R_j) and (L_i, R_i) \\neq (R_j, L_j).\n\nD_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nL_1 R_1 D_1\nL_2 R_2 D_2\n:\nL_M R_M D_M\n\nOutput\n\nIf there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print Yes; if it does not exist, print No.\n\nSample Input 1\n\n3 3\n1 2 1\n2 3 1\n1 3 2\n\nSample Output 1\n\nYes\n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102, 103).\n\nSample Input 2\n\n3 3\n1 2 1\n2 3 1\n1 3 5\n\nSample Output 2\n\nNo\n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which is contradictory to the last piece of information.\n\nSample Input 3\n\n4 3\n2 1 1\n2 3 5\n3 4 2\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n10 3\n8 7 100\n7 9 100\n9 8 100\n\nSample Output 4\n\nNo\n\nSample Input 5\n\n100 0\n\nSample Output 5\n\nYes", "sample_input": "3 3\n1 2 1\n2 3 1\n1 3 2\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03452", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are N people standing on the x-axis.\nLet the coordinate of Person i be x_i.\nFor every i, x_i is an integer between 0 and 10^9 (inclusive).\nIt is possible that more than one person is standing at the same coordinate.\n\nYou will given M pieces of information regarding the positions of these people.\nThe i-th piece of information has the form (L_i, R_i, D_i).\nThis means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds.\n\nIt turns out that some of these M pieces of information may be incorrect.\nDetermine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.\n\nConstraints\n\n1 \\leq N \\leq 100 000\n\n0 \\leq M \\leq 200 000\n\n1 \\leq L_i, R_i \\leq N (1 \\leq i \\leq M)\n\n0 \\leq D_i \\leq 10 000 (1 \\leq i \\leq M)\n\nL_i \\neq R_i (1 \\leq i \\leq M)\n\nIf i \\neq j, then (L_i, R_i) \\neq (L_j, R_j) and (L_i, R_i) \\neq (R_j, L_j).\n\nD_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nL_1 R_1 D_1\nL_2 R_2 D_2\n:\nL_M R_M D_M\n\nOutput\n\nIf there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print Yes; if it does not exist, print No.\n\nSample Input 1\n\n3 3\n1 2 1\n2 3 1\n1 3 2\n\nSample Output 1\n\nYes\n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102, 103).\n\nSample Input 2\n\n3 3\n1 2 1\n2 3 1\n1 3 5\n\nSample Output 2\n\nNo\n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which is contradictory to the last piece of information.\n\nSample Input 3\n\n4 3\n2 1 1\n2 3 5\n3 4 2\n\nSample Output 3\n\nYes\n\nSample Input 4\n\n10 3\n8 7 100\n7 9 100\n9 8 100\n\nSample Output 4\n\nNo\n\nSample Input 5\n\n100 0\n\nSample Output 5\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6360, "cpu_time_ms": 103, "memory_kb": 48336}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s498000811", "group_id": "codeNet:p03453", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n;;;\n;;; Binary heap\n;;;\n\n(define-condition heap-empty-error (error)\n ((heap :initarg :heap :reader heap-empty-error-heap))\n (:report\n (lambda (condition stream)\n (format stream \"Attempted to pop empty heap ~W\" (heap-empty-error-heap condition)))))\n\n(defmacro define-binary-heap (name &key (order '#'>) (element-type 'fixnum))\n \"Defines a binary heap specialized for the given order and the element\ntype. This macro defines a structure of the given NAME and relevant functions:\nMAKE-, -PUSH, -POP, -REINITIALIZE, -EMPTY-P,\n-COUNT, and -PEEK.\"\n (check-type name symbol)\n (let* ((string-name (string name))\n (fname-push (intern (format nil \"~A-PUSH\" string-name)))\n (fname-pop (intern (format nil \"~A-POP\" string-name)))\n (fname-reinitialize (intern (format nil \"~A-REINITIALIZE\" string-name)))\n (fname-empty-p (intern (format nil \"~A-EMPTY-P\" string-name)))\n (fname-count (intern (format nil \"~A-COUNT\" string-name)))\n (fname-peek (intern (format nil \"~A-PEEK\" string-name)))\n (fname-make (intern (format nil \"MAKE-~A\" string-name)))\n (acc-position (intern (format nil \"~A-POSITION\" string-name)))\n (acc-data (intern (format nil \"~A-DATA\" string-name))))\n `(progn\n (locally\n ;; prevent style warnings\n (declare #+sbcl (muffle-conditions style-warning))\n (defstruct (,name\n (:constructor ,fname-make\n (size\n &aux\n (data (make-array (1+ size)\n :element-type ',(if (eql element-type '*) t element-type))))))\n (data nil :type (simple-array ,element-type (*)))\n (position 1 :type (integer 1 #.array-total-size-limit))))\n\n (declaim #+sbcl (sb-ext:maybe-inline ,fname-push))\n (defun ,fname-push (obj heap)\n \"Adds OBJ to HEAP.\"\n (declare (optimize (speed 3))\n (type ,name heap))\n (symbol-macrolet ((position (,acc-position heap)))\n (when (>= position (length (,acc-data heap)))\n (setf (,acc-data heap)\n (adjust-array (,acc-data heap)\n (min (- array-total-size-limit 1)\n (* position 2)))))\n (let ((data (,acc-data heap)))\n (declare ((simple-array ,element-type (*)) data))\n (labels ((heapify (pos)\n (declare (optimize (speed 3) (safety 0)))\n (unless (= pos 1)\n (let ((parent-pos (ash pos -1)))\n (when (funcall ,order (aref data pos) (aref data parent-pos))\n (rotatef (aref data pos) (aref data parent-pos))\n (heapify parent-pos))))))\n (setf (aref data position) obj)\n (heapify position)\n (incf position)\n heap))))\n\n (declaim #+sbcl (sb-ext:maybe-inline ,fname-pop))\n (defun ,fname-pop (heap)\n \"Removes and returns the element at the top of HEAP.\"\n (declare (optimize (speed 3))\n (type ,name heap))\n (symbol-macrolet ((position (,acc-position heap)))\n (let ((data (,acc-data heap)))\n (declare ((simple-array ,element-type (*)) data))\n (labels ((heapify (pos)\n (declare (optimize (speed 3) (safety 0))\n ((integer 1 #.array-total-size-limit) pos))\n (let* ((child-pos1 (+ pos pos))\n (child-pos2 (1+ child-pos1)))\n (when (<= child-pos1 position)\n (if (<= child-pos2 position)\n (if (funcall ,order (aref data child-pos1) (aref data child-pos2))\n (unless (funcall ,order (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))\n (heapify child-pos1))\n (unless (funcall ,order (aref data pos) (aref data child-pos2))\n (rotatef (aref data pos) (aref data child-pos2))\n (heapify child-pos2)))\n (unless (funcall ,order (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))))))))\n (when (= position 1)\n (error 'heap-empty-error :heap heap))\n (prog1 (aref data 1)\n (decf position)\n (setf (aref data 1) (aref data position))\n (heapify 1))))))\n\n (declaim (inline ,fname-reinitialize))\n (defun ,fname-reinitialize (heap)\n \"Makes HEAP empty.\"\n (setf (,acc-position heap) 1)\n heap)\n\n (declaim (inline ,fname-empty-p))\n (defun ,fname-empty-p (heap)\n \"Returns true iff HEAP is empty.\"\n (= 1 (,acc-position heap)))\n\n (declaim (inline ,fname-count))\n (defun ,fname-count (heap)\n \"Returns the current number of the elements in HEAP.\"\n (- (,acc-position heap) 1))\n\n (declaim (inline ,fname-peek))\n (defun ,fname-peek (heap)\n \"Returns the topmost element of HEAP.\"\n (if (= 1 (,acc-position heap))\n (error 'heap-empty-error :heap heap)\n (aref (,acc-data heap) 1))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n;; dist . v\n(define-binary-heap heap\n :order (lambda (x y)\n (< (the fixnum (car x)) (the fixnum (car y))))\n :element-type list)\n\n(define-mod-operations +mod+)\n\n(defconstant +inf+ most-positive-fixnum)\n(defun make-dists (n m src graph)\n (declare #.opt\n ((simple-array list (*)) graph))\n (let* ((dists (make-array n :element-type 'uint62 :initial-element +inf+))\n (que (make-heap m)))\n (setf (aref dists src) 0)\n (heap-push (cons 0 src) que)\n (loop until (heap-empty-p que)\n for (dist . v) of-type (uint62 . uint62) = (heap-pop que)\n when (= dist (aref dists v))\n do (loop for (next . d) of-type (uint62 . uint62) in (aref graph v)\n for next-dist = (+ d dist)\n when (< next-dist (aref dists next))\n do (setf (aref dists next) next-dist)\n (heap-push (cons next-dist next) que)))\n (let ((dp (make-array n :element-type 'uint31 :initial-element 0))\n (visited (make-array n :element-type 'bit :initial-element 0))\n ords)\n (setf (aref dp src) 1)\n (sb-int:named-let dfs ((v src))\n (when (zerop (aref visited v))\n (setf (aref visited v) 1)\n (loop for (next . d) of-type (uint62 . uint62) in (aref graph v)\n when (= (+ (aref dists v) d) (aref dists next))\n do (dfs next))\n (push v ords)))\n (dolist (v ords)\n (loop for (next . d) of-type (uint62 . uint62) in (aref graph v)\n when (= (+ (aref dists v) d) (aref dists next))\n do (incfmod (aref dp next) (aref dp v))))\n (values dists dp))))\n\n(defun main ()\n (declare #.opt)\n (let* ((n (read))\n (m (read))\n (ss (- (read) 1))\n (tt (- (read) 1))\n (graph (make-array n :element-type 'list :initial-element nil)))\n (declare (uint31 n m ss tt))\n (dotimes (i m)\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1))\n (d (read-fixnum)))\n (push (cons u d) (aref graph v))\n (push (cons v d) (aref graph u))))\n (multiple-value-bind (dists+ dp+) (make-dists n m ss graph)\n (multiple-value-bind (dists- dp-) (make-dists n m tt graph)\n (declare ((simple-array uint62 (*)) dists+ dists-)\n ((simple-array uint31 (*)) dp+ dp-))\n (let ((l (aref dists+ tt))\n (res (mod* (aref dp+ tt) (aref dp- ss))))\n (declare (uint31 res))\n (dotimes (v n)\n (when (= (+ (aref dists+ v) (aref dists- v)) l)\n (when (= (* 2 (aref dists+ v)) l)\n (decfmod res (mod* (aref dp+ v) (aref dp- v)\n (aref dp+ v) (aref dp- v))))\n (when (< (* 2 (aref dists+ v)) l)\n (loop for (next . d) in (aref graph v)\n when (and (< (* 2 (aref dists- next)) l)\n (= l (+ (aref dists+ v) (aref dists- next) d)))\n do (decfmod res (mod* (aref dp+ v) (aref dp- next)\n (aref dp+ v) (aref dp- next)))))))\n (println res))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 4\n1 3\n1 2 1\n2 3 1\n3 4 1\n4 1 1\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1 3\n1 2 1\n2 3 1\n3 1 2\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8 13\n4 2\n7 3 9\n6 2 3\n1 6 4\n7 6 9\n3 8 9\n1 2 2\n2 8 12\n8 6 9\n2 5 5\n4 2 18\n5 3 7\n5 1 515371567\n4 8 6\n\"\n \"6\n\")))\n", "language": "Lisp", "metadata": {"date": 1596084358, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03453.html", "problem_id": "p03453", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03453/input.txt", "sample_output_relpath": "derived/input_output/data/p03453/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03453/Lisp/s498000811.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s498000811", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.opt)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n;;;\n;;; Binary heap\n;;;\n\n(define-condition heap-empty-error (error)\n ((heap :initarg :heap :reader heap-empty-error-heap))\n (:report\n (lambda (condition stream)\n (format stream \"Attempted to pop empty heap ~W\" (heap-empty-error-heap condition)))))\n\n(defmacro define-binary-heap (name &key (order '#'>) (element-type 'fixnum))\n \"Defines a binary heap specialized for the given order and the element\ntype. This macro defines a structure of the given NAME and relevant functions:\nMAKE-, -PUSH, -POP, -REINITIALIZE, -EMPTY-P,\n-COUNT, and -PEEK.\"\n (check-type name symbol)\n (let* ((string-name (string name))\n (fname-push (intern (format nil \"~A-PUSH\" string-name)))\n (fname-pop (intern (format nil \"~A-POP\" string-name)))\n (fname-reinitialize (intern (format nil \"~A-REINITIALIZE\" string-name)))\n (fname-empty-p (intern (format nil \"~A-EMPTY-P\" string-name)))\n (fname-count (intern (format nil \"~A-COUNT\" string-name)))\n (fname-peek (intern (format nil \"~A-PEEK\" string-name)))\n (fname-make (intern (format nil \"MAKE-~A\" string-name)))\n (acc-position (intern (format nil \"~A-POSITION\" string-name)))\n (acc-data (intern (format nil \"~A-DATA\" string-name))))\n `(progn\n (locally\n ;; prevent style warnings\n (declare #+sbcl (muffle-conditions style-warning))\n (defstruct (,name\n (:constructor ,fname-make\n (size\n &aux\n (data (make-array (1+ size)\n :element-type ',(if (eql element-type '*) t element-type))))))\n (data nil :type (simple-array ,element-type (*)))\n (position 1 :type (integer 1 #.array-total-size-limit))))\n\n (declaim #+sbcl (sb-ext:maybe-inline ,fname-push))\n (defun ,fname-push (obj heap)\n \"Adds OBJ to HEAP.\"\n (declare (optimize (speed 3))\n (type ,name heap))\n (symbol-macrolet ((position (,acc-position heap)))\n (when (>= position (length (,acc-data heap)))\n (setf (,acc-data heap)\n (adjust-array (,acc-data heap)\n (min (- array-total-size-limit 1)\n (* position 2)))))\n (let ((data (,acc-data heap)))\n (declare ((simple-array ,element-type (*)) data))\n (labels ((heapify (pos)\n (declare (optimize (speed 3) (safety 0)))\n (unless (= pos 1)\n (let ((parent-pos (ash pos -1)))\n (when (funcall ,order (aref data pos) (aref data parent-pos))\n (rotatef (aref data pos) (aref data parent-pos))\n (heapify parent-pos))))))\n (setf (aref data position) obj)\n (heapify position)\n (incf position)\n heap))))\n\n (declaim #+sbcl (sb-ext:maybe-inline ,fname-pop))\n (defun ,fname-pop (heap)\n \"Removes and returns the element at the top of HEAP.\"\n (declare (optimize (speed 3))\n (type ,name heap))\n (symbol-macrolet ((position (,acc-position heap)))\n (let ((data (,acc-data heap)))\n (declare ((simple-array ,element-type (*)) data))\n (labels ((heapify (pos)\n (declare (optimize (speed 3) (safety 0))\n ((integer 1 #.array-total-size-limit) pos))\n (let* ((child-pos1 (+ pos pos))\n (child-pos2 (1+ child-pos1)))\n (when (<= child-pos1 position)\n (if (<= child-pos2 position)\n (if (funcall ,order (aref data child-pos1) (aref data child-pos2))\n (unless (funcall ,order (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))\n (heapify child-pos1))\n (unless (funcall ,order (aref data pos) (aref data child-pos2))\n (rotatef (aref data pos) (aref data child-pos2))\n (heapify child-pos2)))\n (unless (funcall ,order (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))))))))\n (when (= position 1)\n (error 'heap-empty-error :heap heap))\n (prog1 (aref data 1)\n (decf position)\n (setf (aref data 1) (aref data position))\n (heapify 1))))))\n\n (declaim (inline ,fname-reinitialize))\n (defun ,fname-reinitialize (heap)\n \"Makes HEAP empty.\"\n (setf (,acc-position heap) 1)\n heap)\n\n (declaim (inline ,fname-empty-p))\n (defun ,fname-empty-p (heap)\n \"Returns true iff HEAP is empty.\"\n (= 1 (,acc-position heap)))\n\n (declaim (inline ,fname-count))\n (defun ,fname-count (heap)\n \"Returns the current number of the elements in HEAP.\"\n (- (,acc-position heap) 1))\n\n (declaim (inline ,fname-peek))\n (defun ,fname-peek (heap)\n \"Returns the topmost element of HEAP.\"\n (if (= 1 (,acc-position heap))\n (error 'heap-empty-error :heap heap)\n (aref (,acc-data heap) 1))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n;; dist . v\n(define-binary-heap heap\n :order (lambda (x y)\n (< (the fixnum (car x)) (the fixnum (car y))))\n :element-type list)\n\n(define-mod-operations +mod+)\n\n(defconstant +inf+ most-positive-fixnum)\n(defun make-dists (n m src graph)\n (declare #.opt\n ((simple-array list (*)) graph))\n (let* ((dists (make-array n :element-type 'uint62 :initial-element +inf+))\n (que (make-heap m)))\n (setf (aref dists src) 0)\n (heap-push (cons 0 src) que)\n (loop until (heap-empty-p que)\n for (dist . v) of-type (uint62 . uint62) = (heap-pop que)\n when (= dist (aref dists v))\n do (loop for (next . d) of-type (uint62 . uint62) in (aref graph v)\n for next-dist = (+ d dist)\n when (< next-dist (aref dists next))\n do (setf (aref dists next) next-dist)\n (heap-push (cons next-dist next) que)))\n (let ((dp (make-array n :element-type 'uint31 :initial-element 0))\n (visited (make-array n :element-type 'bit :initial-element 0))\n ords)\n (setf (aref dp src) 1)\n (sb-int:named-let dfs ((v src))\n (when (zerop (aref visited v))\n (setf (aref visited v) 1)\n (loop for (next . d) of-type (uint62 . uint62) in (aref graph v)\n when (= (+ (aref dists v) d) (aref dists next))\n do (dfs next))\n (push v ords)))\n (dolist (v ords)\n (loop for (next . d) of-type (uint62 . uint62) in (aref graph v)\n when (= (+ (aref dists v) d) (aref dists next))\n do (incfmod (aref dp next) (aref dp v))))\n (values dists dp))))\n\n(defun main ()\n (declare #.opt)\n (let* ((n (read))\n (m (read))\n (ss (- (read) 1))\n (tt (- (read) 1))\n (graph (make-array n :element-type 'list :initial-element nil)))\n (declare (uint31 n m ss tt))\n (dotimes (i m)\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1))\n (d (read-fixnum)))\n (push (cons u d) (aref graph v))\n (push (cons v d) (aref graph u))))\n (multiple-value-bind (dists+ dp+) (make-dists n m ss graph)\n (multiple-value-bind (dists- dp-) (make-dists n m tt graph)\n (declare ((simple-array uint62 (*)) dists+ dists-)\n ((simple-array uint31 (*)) dp+ dp-))\n (let ((l (aref dists+ tt))\n (res (mod* (aref dp+ tt) (aref dp- ss))))\n (declare (uint31 res))\n (dotimes (v n)\n (when (= (+ (aref dists+ v) (aref dists- v)) l)\n (when (= (* 2 (aref dists+ v)) l)\n (decfmod res (mod* (aref dp+ v) (aref dp- v)\n (aref dp+ v) (aref dp- v))))\n (when (< (* 2 (aref dists+ v)) l)\n (loop for (next . d) in (aref graph v)\n when (and (< (* 2 (aref dists- next)) l)\n (= l (+ (aref dists+ v) (aref dists- next) d)))\n do (decfmod res (mod* (aref dp+ v) (aref dp- next)\n (aref dp+ v) (aref dp- next)))))))\n (println res))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 4\n1 3\n1 2 1\n2 3 1\n3 4 1\n4 1 1\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1 3\n1 2 1\n2 3 1\n3 1 2\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8 13\n4 2\n7 3 9\n6 2 3\n1 6 4\n7 6 9\n3 8 9\n1 2 2\n2 8 12\n8 6 9\n2 5 5\n4 2 18\n5 3 7\n5 1 515371567\n4 8 6\n\"\n \"6\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nWe have a graph with N vertices and M edges, and there are two people on the graph: Takahashi and Aoki.\n\nThe i-th edge connects Vertex U_i and Vertex V_i.\nThe time it takes to traverse this edge is D_i minutes, regardless of direction and who traverses the edge (Takahashi or Aoki).\n\nTakahashi departs Vertex S and Aoki departs Vertex T at the same time. Takahashi travels to Vertex T and Aoki travels to Vertex S, both in the shortest time possible.\nFind the number of the pairs of ways for Takahashi and Aoki to choose their shortest paths such that they never meet (at a vertex or on an edge) during the travel, modulo 10^9 + 7.\n\nConstraints\n\n1 \\leq N \\leq 100 000\n\n1 \\leq M \\leq 200 000\n\n1 \\leq S, T \\leq N\n\nS \\neq T\n\n1 \\leq U_i, V_i \\leq N (1 \\leq i \\leq M)\n\n1 \\leq D_i \\leq 10^9 (1 \\leq i \\leq M)\n\nIf i \\neq j, then (U_i, V_i) \\neq (U_j, V_j) and (U_i, V_i) \\neq (V_j, U_j).\n\nU_i \\neq V_i (1 \\leq i \\leq M)\n\nD_i are integers.\n\nThe given graph is connected.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nS T\nU_1 V_1 D_1\nU_2 V_2 D_2\n:\nU_M V_M D_M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n4 4\n1 3\n1 2 1\n2 3 1\n3 4 1\n4 1 1\n\nSample Output 1\n\n2\n\nThere are two ways to choose shortest paths that satisfies the condition:\n\nTakahashi chooses the path 1 \\rightarrow 2 \\rightarrow 3, and Aoki chooses the path 3 \\rightarrow 4 \\rightarrow 1.\n\nTakahashi chooses the path 1 \\rightarrow 4 \\rightarrow 3, and Aoki chooses the path 3 \\rightarrow 2 \\rightarrow 1.\n\nSample Input 2\n\n3 3\n1 3\n1 2 1\n2 3 1\n3 1 2\n\nSample Output 2\n\n2\n\nSample Input 3\n\n3 3\n1 3\n1 2 1\n2 3 1\n3 1 2\n\nSample Output 3\n\n2\n\nSample Input 4\n\n8 13\n4 2\n7 3 9\n6 2 3\n1 6 4\n7 6 9\n3 8 9\n1 2 2\n2 8 12\n8 6 9\n2 5 5\n4 2 18\n5 3 7\n5 1 515371567\n4 8 6\n\nSample Output 4\n\n6", "sample_input": "4 4\n1 3\n1 2 1\n2 3 1\n3 4 1\n4 1 1\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03453", "source_text": "Score : 700 points\n\nProblem Statement\n\nWe have a graph with N vertices and M edges, and there are two people on the graph: Takahashi and Aoki.\n\nThe i-th edge connects Vertex U_i and Vertex V_i.\nThe time it takes to traverse this edge is D_i minutes, regardless of direction and who traverses the edge (Takahashi or Aoki).\n\nTakahashi departs Vertex S and Aoki departs Vertex T at the same time. Takahashi travels to Vertex T and Aoki travels to Vertex S, both in the shortest time possible.\nFind the number of the pairs of ways for Takahashi and Aoki to choose their shortest paths such that they never meet (at a vertex or on an edge) during the travel, modulo 10^9 + 7.\n\nConstraints\n\n1 \\leq N \\leq 100 000\n\n1 \\leq M \\leq 200 000\n\n1 \\leq S, T \\leq N\n\nS \\neq T\n\n1 \\leq U_i, V_i \\leq N (1 \\leq i \\leq M)\n\n1 \\leq D_i \\leq 10^9 (1 \\leq i \\leq M)\n\nIf i \\neq j, then (U_i, V_i) \\neq (U_j, V_j) and (U_i, V_i) \\neq (V_j, U_j).\n\nU_i \\neq V_i (1 \\leq i \\leq M)\n\nD_i are integers.\n\nThe given graph is connected.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nS T\nU_1 V_1 D_1\nU_2 V_2 D_2\n:\nU_M V_M D_M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n4 4\n1 3\n1 2 1\n2 3 1\n3 4 1\n4 1 1\n\nSample Output 1\n\n2\n\nThere are two ways to choose shortest paths that satisfies the condition:\n\nTakahashi chooses the path 1 \\rightarrow 2 \\rightarrow 3, and Aoki chooses the path 3 \\rightarrow 4 \\rightarrow 1.\n\nTakahashi chooses the path 1 \\rightarrow 4 \\rightarrow 3, and Aoki chooses the path 3 \\rightarrow 2 \\rightarrow 1.\n\nSample Input 2\n\n3 3\n1 3\n1 2 1\n2 3 1\n3 1 2\n\nSample Output 2\n\n2\n\nSample Input 3\n\n3 3\n1 3\n1 2 1\n2 3 1\n3 1 2\n\nSample Output 3\n\n2\n\nSample Input 4\n\n8 13\n4 2\n7 3 9\n6 2 3\n1 6 4\n7 6 9\n3 8 9\n1 2 2\n2 8 12\n8 6 9\n2 5 5\n4 2 18\n5 3 7\n5 1 515371567\n4 8 6\n\nSample Output 4\n\n6", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 15253, "cpu_time_ms": 266, "memory_kb": 59692}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s419026087", "group_id": "codeNet:p03456", "input_text": "(defun digit (n &optional (c 0))\n (cond\n ((= n 0) c)\n (t (digit (floor n 10) (1+ c)))))\n\n(let* ((int1 (read))\n (int2 (read))\n (n (+ (* int1 (expt 10 (digit int2))) int2)))\n (if (= (expt (floor (sqrt n)) 2) n)\n (princ \"Yes\")\n (princ \"No\")))", "language": "Lisp", "metadata": {"date": 1591155735, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03456.html", "problem_id": "p03456", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03456/input.txt", "sample_output_relpath": "derived/input_output/data/p03456/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03456/Lisp/s419026087.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s419026087", "user_id": "u425762225"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun digit (n &optional (c 0))\n (cond\n ((= n 0) c)\n (t (digit (floor n 10) (1+ c)))))\n\n(let* ((int1 (read))\n (int2 (read))\n (n (+ (* int1 (expt 10 (digit int2))) int2)))\n (if (= (expt (floor (sqrt n)) 2) n)\n (princ \"Yes\")\n (princ \"No\")))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nAtCoDeer the deer has found two positive integers, a and b.\nDetermine whether the concatenation of a and b in this order is a square number.\n\nConstraints\n\n1 ≤ a,b ≤ 100\n\na and b are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf the concatenation of a and b in this order is a square number, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 21\n\nSample Output 1\n\nYes\n\nAs 121 = 11 × 11, it is a square number.\n\nSample Input 2\n\n100 100\n\nSample Output 2\n\nNo\n\n100100 is not a square number.\n\nSample Input 3\n\n12 10\n\nSample Output 3\n\nNo", "sample_input": "1 21\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03456", "source_text": "Score : 200 points\n\nProblem Statement\n\nAtCoDeer the deer has found two positive integers, a and b.\nDetermine whether the concatenation of a and b in this order is a square number.\n\nConstraints\n\n1 ≤ a,b ≤ 100\n\na and b are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf the concatenation of a and b in this order is a square number, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 21\n\nSample Output 1\n\nYes\n\nAs 121 = 11 × 11, it is a square number.\n\nSample Input 2\n\n100 100\n\nSample Output 2\n\nNo\n\n100100 is not a square number.\n\nSample Input 3\n\n12 10\n\nSample Output 3\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 287, "cpu_time_ms": 152, "memory_kb": 15968}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s902169315", "group_id": "codeNet:p03456", "input_text": "(def sqrtp (x)\n (equal 0.0 (rem (sqrt x) 1)))\n(def joint (x y)\n (if (> x 9)\n (+ (* 100 x) y)\n (+ (* 10 x) y)))\n(def yn (x)\n (if x \"Yes\" \"No\"))\n \n(format t (yn (sqrtp (joint (read) (read)))))", "language": "Lisp", "metadata": {"date": 1585854754, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03456.html", "problem_id": "p03456", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03456/input.txt", "sample_output_relpath": "derived/input_output/data/p03456/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03456/Lisp/s902169315.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s902169315", "user_id": "u123011403"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(def sqrtp (x)\n (equal 0.0 (rem (sqrt x) 1)))\n(def joint (x y)\n (if (> x 9)\n (+ (* 100 x) y)\n (+ (* 10 x) y)))\n(def yn (x)\n (if x \"Yes\" \"No\"))\n \n(format t (yn (sqrtp (joint (read) (read)))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nAtCoDeer the deer has found two positive integers, a and b.\nDetermine whether the concatenation of a and b in this order is a square number.\n\nConstraints\n\n1 ≤ a,b ≤ 100\n\na and b are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf the concatenation of a and b in this order is a square number, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 21\n\nSample Output 1\n\nYes\n\nAs 121 = 11 × 11, it is a square number.\n\nSample Input 2\n\n100 100\n\nSample Output 2\n\nNo\n\n100100 is not a square number.\n\nSample Input 3\n\n12 10\n\nSample Output 3\n\nNo", "sample_input": "1 21\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03456", "source_text": "Score : 200 points\n\nProblem Statement\n\nAtCoDeer the deer has found two positive integers, a and b.\nDetermine whether the concatenation of a and b in this order is a square number.\n\nConstraints\n\n1 ≤ a,b ≤ 100\n\na and b are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf the concatenation of a and b in this order is a square number, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 21\n\nSample Output 1\n\nYes\n\nAs 121 = 11 × 11, it is a square number.\n\nSample Input 2\n\n100 100\n\nSample Output 2\n\nNo\n\n100100 is not a square number.\n\nSample Input 3\n\n12 10\n\nSample Output 3\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 203, "cpu_time_ms": 132, "memory_kb": 15972}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s711090581", "group_id": "codeNet:p03463", "input_text": "(let ((n (read))\n (a (read))\n (b (read)))\n (if (= (mod (- b a) 2) 0)\n (princ \"Alice\")\n (princ \"Borys\")))", "language": "Lisp", "metadata": {"date": 1517368890, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03463.html", "problem_id": "p03463", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03463/input.txt", "sample_output_relpath": "derived/input_output/data/p03463/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03463/Lisp/s711090581.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s711090581", "user_id": "u672956630"}, "prompt_components": {"gold_output": "Alice\n", "input_to_evaluate": "(let ((n (read))\n (a (read))\n (b (read)))\n (if (= (mod (- b a) 2) 0)\n (princ \"Alice\")\n (princ \"Borys\")))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nA game is played on a strip consisting of N cells consecutively numbered from 1 to N.\n\nAlice has her token on cell A. Borys has his token on a different cell B.\n\nPlayers take turns, Alice moves first.\nThe moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1.\nNote that it's disallowed to move the token outside the strip or to the cell with the other player's token.\nIn one turn, the token of the moving player must be shifted exactly once.\n\nThe player who can't make a move loses, and the other player wins.\n\nBoth players want to win. Who wins if they play optimally?\n\nConstraints\n\n2 \\leq N \\leq 100\n\n1 \\leq A < B \\leq N\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint Alice if Alice wins, Borys if Borys wins, and Draw if nobody wins.\n\nSample Input 1\n\n5 2 4\n\nSample Output 1\n\nAlice\n\nAlice can move her token to cell 3.\nAfter that, Borys will be unable to move his token to cell 3, so he will have to move his token to cell 5.\nThen, Alice moves her token to cell 4. Borys can't make a move and loses.\n\nSample Input 2\n\n2 1 2\n\nSample Output 2\n\nBorys\n\nAlice can't make the very first move and loses.\n\nSample Input 3\n\n58 23 42\n\nSample Output 3\n\nBorys", "sample_input": "5 2 4\n"}, "reference_outputs": ["Alice\n"], "source_document_id": "p03463", "source_text": "Score : 300 points\n\nProblem Statement\n\nA game is played on a strip consisting of N cells consecutively numbered from 1 to N.\n\nAlice has her token on cell A. Borys has his token on a different cell B.\n\nPlayers take turns, Alice moves first.\nThe moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1.\nNote that it's disallowed to move the token outside the strip or to the cell with the other player's token.\nIn one turn, the token of the moving player must be shifted exactly once.\n\nThe player who can't make a move loses, and the other player wins.\n\nBoth players want to win. Who wins if they play optimally?\n\nConstraints\n\n2 \\leq N \\leq 100\n\n1 \\leq A < B \\leq N\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nPrint Alice if Alice wins, Borys if Borys wins, and Draw if nobody wins.\n\nSample Input 1\n\n5 2 4\n\nSample Output 1\n\nAlice\n\nAlice can move her token to cell 3.\nAfter that, Borys will be unable to move his token to cell 3, so he will have to move his token to cell 5.\nThen, Alice moves her token to cell 4. Borys can't make a move and loses.\n\nSample Input 2\n\n2 1 2\n\nSample Output 2\n\nBorys\n\nAlice can't make the very first move and loses.\n\nSample Input 3\n\n58 23 42\n\nSample Output 3\n\nBorys", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 121, "cpu_time_ms": 139, "memory_kb": 12256}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s404699518", "group_id": "codeNet:p03469", "input_text": "(let ((da (concatenate 'list (read-line))))\n (setf (nth 3 da) #\\8)\n (princ (concatenate 'string da)))\n", "language": "Lisp", "metadata": {"date": 1542930025, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03469.html", "problem_id": "p03469", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03469/input.txt", "sample_output_relpath": "derived/input_output/data/p03469/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03469/Lisp/s404699518.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s404699518", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2018/01/07\n", "input_to_evaluate": "(let ((da (concatenate 'list (read-line))))\n (setf (nth 3 da) #\\8)\n (princ (concatenate 'string da)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nOn some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in yyyy/mm/dd format. For example, January 23, 2018 should be written as 2018/01/23.\n\nAfter finishing the document, she noticed that she had mistakenly wrote 2017 at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to 2018 and prints it.\n\nConstraints\n\nS is a string of length 10.\n\nThe first eight characters in S are 2017/01/.\n\nThe last two characters in S are digits and represent an integer between 1 and 31 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nReplace the first four characters in S with 2018 and print it.\n\nSample Input 1\n\n2017/01/07\n\nSample Output 1\n\n2018/01/07\n\nSample Input 2\n\n2017/01/31\n\nSample Output 2\n\n2018/01/31", "sample_input": "2017/01/07\n"}, "reference_outputs": ["2018/01/07\n"], "source_document_id": "p03469", "source_text": "Score : 100 points\n\nProblem Statement\n\nOn some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in yyyy/mm/dd format. For example, January 23, 2018 should be written as 2018/01/23.\n\nAfter finishing the document, she noticed that she had mistakenly wrote 2017 at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to 2018 and prints it.\n\nConstraints\n\nS is a string of length 10.\n\nThe first eight characters in S are 2017/01/.\n\nThe last two characters in S are digits and represent an integer between 1 and 31 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nReplace the first four characters in S with 2018 and print it.\n\nSample Input 1\n\n2017/01/07\n\nSample Output 1\n\n2018/01/07\n\nSample Input 2\n\n2017/01/31\n\nSample Output 2\n\n2018/01/31", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 104, "cpu_time_ms": 77, "memory_kb": 7652}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s620724667", "group_id": "codeNet:p03470", "input_text": "(defun card-game-for-two (n a)\n (let ((alice 0)\n (bob 0))\n (setf a (sort a #'>))\n (dotimes (i n)\n (if (zerop (rem i 2))\n (setf alice (+ alice (aref a i)))\n (setf bob (+ bob (aref a i)))))\n (- alice bob)))\n\n(defun create-data ()\n (let* ((n (read))\n (a (make-array `(,n))))\n (dotimes (i n)\n (setf (aref a i) (read)))\n (values n a)))\n\n(multiple-value-bind (n a) (create-data)\n (format t \"~A~%\" (card-game-for-two n a)))", "language": "Lisp", "metadata": {"date": 1590961061, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03470.html", "problem_id": "p03470", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03470/input.txt", "sample_output_relpath": "derived/input_output/data/p03470/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03470/Lisp/s620724667.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s620724667", "user_id": "u324761590"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun card-game-for-two (n a)\n (let ((alice 0)\n (bob 0))\n (setf a (sort a #'>))\n (dotimes (i n)\n (if (zerop (rem i 2))\n (setf alice (+ alice (aref a i)))\n (setf bob (+ bob (aref a i)))))\n (- alice bob)))\n\n(defun create-data ()\n (let* ((n (read))\n (a (make-array `(,n))))\n (dotimes (i n)\n (setf (aref a i) (read)))\n (values n a)))\n\n(multiple-value-bind (n a) (create-data)\n (format t \"~A~%\" (card-game-for-two n a)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nAn X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi.\n\nLunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?\n\nConstraints\n\n1 ≤ N ≤ 100\n\n1 ≤ d_i ≤ 100\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nd_1\n:\nd_N\n\nOutput\n\nPrint the maximum number of layers in a kagami mochi that can be made.\n\nSample Input 1\n\n4\n10\n8\n8\n6\n\nSample Output 1\n\n3\n\nIf we stack the mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, we have a 3-layered kagami mochi, which is the maximum number of layers.\n\nSample Input 2\n\n3\n15\n15\n15\n\nSample Output 2\n\n1\n\nWhen all the mochi have the same diameter, we can only have a 1-layered kagami mochi.\n\nSample Input 3\n\n7\n50\n30\n50\n100\n50\n80\n30\n\nSample Output 3\n\n4", "sample_input": "4\n10\n8\n8\n6\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03470", "source_text": "Score : 200 points\n\nProblem Statement\n\nAn X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi.\n\nLunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?\n\nConstraints\n\n1 ≤ N ≤ 100\n\n1 ≤ d_i ≤ 100\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nd_1\n:\nd_N\n\nOutput\n\nPrint the maximum number of layers in a kagami mochi that can be made.\n\nSample Input 1\n\n4\n10\n8\n8\n6\n\nSample Output 1\n\n3\n\nIf we stack the mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, we have a 3-layered kagami mochi, which is the maximum number of layers.\n\nSample Input 2\n\n3\n15\n15\n15\n\nSample Output 2\n\n1\n\nWhen all the mochi have the same diameter, we can only have a 1-layered kagami mochi.\n\nSample Input 3\n\n7\n50\n30\n50\n100\n50\n80\n30\n\nSample Output 3\n\n4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 477, "cpu_time_ms": 157, "memory_kb": 17636}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s222444210", "group_id": "codeNet:p03470", "input_text": "(defun solver ()\n (let* ((n (read)) (d (make-array n :fill-pointer 0)) (count 1))\n (loop repeat n do\n (vector-push (read) d))\n (sort d #'<)\n (loop for i from 0 to (- n 2) do\n (when (< (aref d i) (aref d (1+ i)))\n (incf count)))\n (format t \"~a~%\" count)))\n\n(solver)", "language": "Lisp", "metadata": {"date": 1520096399, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03470.html", "problem_id": "p03470", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03470/input.txt", "sample_output_relpath": "derived/input_output/data/p03470/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03470/Lisp/s222444210.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s222444210", "user_id": "u183015556"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun solver ()\n (let* ((n (read)) (d (make-array n :fill-pointer 0)) (count 1))\n (loop repeat n do\n (vector-push (read) d))\n (sort d #'<)\n (loop for i from 0 to (- n 2) do\n (when (< (aref d i) (aref d (1+ i)))\n (incf count)))\n (format t \"~a~%\" count)))\n\n(solver)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nAn X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi.\n\nLunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?\n\nConstraints\n\n1 ≤ N ≤ 100\n\n1 ≤ d_i ≤ 100\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nd_1\n:\nd_N\n\nOutput\n\nPrint the maximum number of layers in a kagami mochi that can be made.\n\nSample Input 1\n\n4\n10\n8\n8\n6\n\nSample Output 1\n\n3\n\nIf we stack the mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, we have a 3-layered kagami mochi, which is the maximum number of layers.\n\nSample Input 2\n\n3\n15\n15\n15\n\nSample Output 2\n\n1\n\nWhen all the mochi have the same diameter, we can only have a 1-layered kagami mochi.\n\nSample Input 3\n\n7\n50\n30\n50\n100\n50\n80\n30\n\nSample Output 3\n\n4", "sample_input": "4\n10\n8\n8\n6\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03470", "source_text": "Score : 200 points\n\nProblem Statement\n\nAn X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi.\n\nLunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?\n\nConstraints\n\n1 ≤ N ≤ 100\n\n1 ≤ d_i ≤ 100\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nd_1\n:\nd_N\n\nOutput\n\nPrint the maximum number of layers in a kagami mochi that can be made.\n\nSample Input 1\n\n4\n10\n8\n8\n6\n\nSample Output 1\n\n3\n\nIf we stack the mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, we have a 3-layered kagami mochi, which is the maximum number of layers.\n\nSample Input 2\n\n3\n15\n15\n15\n\nSample Output 2\n\n1\n\nWhen all the mochi have the same diameter, we can only have a 1-layered kagami mochi.\n\nSample Input 3\n\n7\n50\n30\n50\n100\n50\n80\n30\n\nSample Output 3\n\n4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 306, "cpu_time_ms": 584, "memory_kb": 16740}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s050925662", "group_id": "codeNet:p03470", "input_text": "(print (length (remove-duplicates (loop repeat (read) collect (read)))))", "language": "Lisp", "metadata": {"date": 1515388902, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03470.html", "problem_id": "p03470", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03470/input.txt", "sample_output_relpath": "derived/input_output/data/p03470/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03470/Lisp/s050925662.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s050925662", "user_id": "u140665374"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(print (length (remove-duplicates (loop repeat (read) collect (read)))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nAn X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi.\n\nLunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?\n\nConstraints\n\n1 ≤ N ≤ 100\n\n1 ≤ d_i ≤ 100\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nd_1\n:\nd_N\n\nOutput\n\nPrint the maximum number of layers in a kagami mochi that can be made.\n\nSample Input 1\n\n4\n10\n8\n8\n6\n\nSample Output 1\n\n3\n\nIf we stack the mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, we have a 3-layered kagami mochi, which is the maximum number of layers.\n\nSample Input 2\n\n3\n15\n15\n15\n\nSample Output 2\n\n1\n\nWhen all the mochi have the same diameter, we can only have a 1-layered kagami mochi.\n\nSample Input 3\n\n7\n50\n30\n50\n100\n50\n80\n30\n\nSample Output 3\n\n4", "sample_input": "4\n10\n8\n8\n6\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03470", "source_text": "Score : 200 points\n\nProblem Statement\n\nAn X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi.\n\nLunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?\n\nConstraints\n\n1 ≤ N ≤ 100\n\n1 ≤ d_i ≤ 100\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nd_1\n:\nd_N\n\nOutput\n\nPrint the maximum number of layers in a kagami mochi that can be made.\n\nSample Input 1\n\n4\n10\n8\n8\n6\n\nSample Output 1\n\n3\n\nIf we stack the mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, we have a 3-layered kagami mochi, which is the maximum number of layers.\n\nSample Input 2\n\n3\n15\n15\n15\n\nSample Output 2\n\n1\n\nWhen all the mochi have the same diameter, we can only have a 1-layered kagami mochi.\n\nSample Input 3\n\n7\n50\n30\n50\n100\n50\n80\n30\n\nSample Output 3\n\n4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 72, "cpu_time_ms": 260, "memory_kb": 19304}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s653652472", "group_id": "codeNet:p03473", "input_text": "(princ (- 48 (read)))\n(fresh-line)", "language": "Lisp", "metadata": {"date": 1593835922, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03473.html", "problem_id": "p03473", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03473/input.txt", "sample_output_relpath": "derived/input_output/data/p03473/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03473/Lisp/s653652472.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s653652472", "user_id": "u425762225"}, "prompt_components": {"gold_output": "27\n", "input_to_evaluate": "(princ (- 48 (read)))\n(fresh-line)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nHow many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?\n\nConstraints\n\n1≤M≤23\n\nM is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nM\n\nOutput\n\nIf we have x hours until New Year at M o'clock on 30th, December, print x.\n\nSample Input 1\n\n21\n\nSample Output 1\n\n27\n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\nSample Input 2\n\n12\n\nSample Output 2\n\n36", "sample_input": "21\n"}, "reference_outputs": ["27\n"], "source_document_id": "p03473", "source_text": "Score : 100 points\n\nProblem Statement\n\nHow many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?\n\nConstraints\n\n1≤M≤23\n\nM is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nM\n\nOutput\n\nIf we have x hours until New Year at M o'clock on 30th, December, print x.\n\nSample Input 1\n\n21\n\nSample Output 1\n\n27\n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\nSample Input 2\n\n12\n\nSample Output 2\n\n36", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 34, "cpu_time_ms": 17, "memory_kb": 24364}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s396889827", "group_id": "codeNet:p03473", "input_text": "(write (- 48 (read)))\n", "language": "Lisp", "metadata": {"date": 1576893945, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03473.html", "problem_id": "p03473", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03473/input.txt", "sample_output_relpath": "derived/input_output/data/p03473/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03473/Lisp/s396889827.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s396889827", "user_id": "u493610446"}, "prompt_components": {"gold_output": "27\n", "input_to_evaluate": "(write (- 48 (read)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nHow many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?\n\nConstraints\n\n1≤M≤23\n\nM is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nM\n\nOutput\n\nIf we have x hours until New Year at M o'clock on 30th, December, print x.\n\nSample Input 1\n\n21\n\nSample Output 1\n\n27\n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\nSample Input 2\n\n12\n\nSample Output 2\n\n36", "sample_input": "21\n"}, "reference_outputs": ["27\n"], "source_document_id": "p03473", "source_text": "Score : 100 points\n\nProblem Statement\n\nHow many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?\n\nConstraints\n\n1≤M≤23\n\nM is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nM\n\nOutput\n\nIf we have x hours until New Year at M o'clock on 30th, December, print x.\n\nSample Input 1\n\n21\n\nSample Output 1\n\n27\n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\nSample Input 2\n\n12\n\nSample Output 2\n\n36", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 22, "cpu_time_ms": 5, "memory_kb": 2792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s885068868", "group_id": "codeNet:p03473", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(deftype int32 () '(signed-byte 32))\n(deftype int64 () '(signed-byte 64))\n\n\n;;macros\n(defmacro println (n)\n `(format t \"~a~%\" ,n))\n(defmacro vint-out (vec)\n `(progn\n (rep i (length ,vec)\n (princ (vref ,vec i))\n (princ \" \"))\n (fresh-line)))\n\n\n;;vector\n(defmacro vec (type &optional (num 100) (val 0))\n (let* ((g (gensym)))\n `(let* ((,g ,num))\n (make-array ,g :element-type ',type :initial-element ,val\n :adjustable nil :fill-pointer ,g))))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vint (&optional (num 0) (val 0))\n `(vec int32 ,num ,val))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vref (vector pos &optional value)\n (let ((g (gensym)))\n `(let ((,g ,value))\n (if ,g\n (setf (aref ,vector ,pos) ,g)\n (aref ,vector ,pos)))))\n\n(defmacro chvar (sym comp predicate)\n (let ((g (gensym)))\n `(let ((,g ,comp))\n (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))\n (setf ,sym ,g)))))\n\n(defmacro chmax (sym comp &optional (predicate #'>))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro chmin (sym comp &optional (predicate #'<))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro defchangef (name op default-val)\n `(defmacro ,name (var &optional (val ,default-val))\n `(setq ,var (,',op ,val ,var))))\n\n;;本体\n(defun main ()\n (let ((a (read)))\n (println (+ 24 (- 24 a)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1559162599, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03473.html", "problem_id": "p03473", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03473/input.txt", "sample_output_relpath": "derived/input_output/data/p03473/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03473/Lisp/s885068868.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s885068868", "user_id": "u432998668"}, "prompt_components": {"gold_output": "27\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(deftype int32 () '(signed-byte 32))\n(deftype int64 () '(signed-byte 64))\n\n\n;;macros\n(defmacro println (n)\n `(format t \"~a~%\" ,n))\n(defmacro vint-out (vec)\n `(progn\n (rep i (length ,vec)\n (princ (vref ,vec i))\n (princ \" \"))\n (fresh-line)))\n\n\n;;vector\n(defmacro vec (type &optional (num 100) (val 0))\n (let* ((g (gensym)))\n `(let* ((,g ,num))\n (make-array ,g :element-type ',type :initial-element ,val\n :adjustable nil :fill-pointer ,g))))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vint (&optional (num 0) (val 0))\n `(vec int32 ,num ,val))\n\n(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))\n `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))\n\n(defmacro vref (vector pos &optional value)\n (let ((g (gensym)))\n `(let ((,g ,value))\n (if ,g\n (setf (aref ,vector ,pos) ,g)\n (aref ,vector ,pos)))))\n\n(defmacro chvar (sym comp predicate)\n (let ((g (gensym)))\n `(let ((,g ,comp))\n (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))\n (setf ,sym ,g)))))\n\n(defmacro chmax (sym comp &optional (predicate #'>))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro chmin (sym comp &optional (predicate #'<))\n `(chvar ,sym ,comp ,predicate))\n\n(defmacro defchangef (name op default-val)\n `(defmacro ,name (var &optional (val ,default-val))\n `(setq ,var (,',op ,val ,var))))\n\n;;本体\n(defun main ()\n (let ((a (read)))\n (println (+ 24 (- 24 a)))))\n\n#-swank(main)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nHow many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?\n\nConstraints\n\n1≤M≤23\n\nM is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nM\n\nOutput\n\nIf we have x hours until New Year at M o'clock on 30th, December, print x.\n\nSample Input 1\n\n21\n\nSample Output 1\n\n27\n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\nSample Input 2\n\n12\n\nSample Output 2\n\n36", "sample_input": "21\n"}, "reference_outputs": ["27\n"], "source_document_id": "p03473", "source_text": "Score : 100 points\n\nProblem Statement\n\nHow many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?\n\nConstraints\n\n1≤M≤23\n\nM is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nM\n\nOutput\n\nIf we have x hours until New Year at M o'clock on 30th, December, print x.\n\nSample Input 1\n\n21\n\nSample Output 1\n\n27\n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\nSample Input 2\n\n12\n\nSample Output 2\n\n36", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1909, "cpu_time_ms": 40, "memory_kb": 9060}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s419950902", "group_id": "codeNet:p03473", "input_text": "(print (- 48 (read)))", "language": "Lisp", "metadata": {"date": 1515359397, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03473.html", "problem_id": "p03473", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03473/input.txt", "sample_output_relpath": "derived/input_output/data/p03473/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03473/Lisp/s419950902.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s419950902", "user_id": "u648138491"}, "prompt_components": {"gold_output": "27\n", "input_to_evaluate": "(print (- 48 (read)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nHow many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?\n\nConstraints\n\n1≤M≤23\n\nM is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nM\n\nOutput\n\nIf we have x hours until New Year at M o'clock on 30th, December, print x.\n\nSample Input 1\n\n21\n\nSample Output 1\n\n27\n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\nSample Input 2\n\n12\n\nSample Output 2\n\n36", "sample_input": "21\n"}, "reference_outputs": ["27\n"], "source_document_id": "p03473", "source_text": "Score : 100 points\n\nProblem Statement\n\nHow many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?\n\nConstraints\n\n1≤M≤23\n\nM is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nM\n\nOutput\n\nIf we have x hours until New Year at M o'clock on 30th, December, print x.\n\nSample Input 1\n\n21\n\nSample Output 1\n\n27\n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\nSample Input 2\n\n12\n\nSample Output 2\n\n36", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 21, "cpu_time_ms": 9, "memory_kb": 2912}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s565802861", "group_id": "codeNet:p03474", "input_text": "(defun solver ()\n (let ((a (read)) (b (read))\n (s (read-line)))\n (if (and (parse-integer s :start 0 :end a :junk-allowed t)\n (char= (char s a) #\\-)\n (parse-integer s :start (+ a 1) :end (+ a b 1) :junk-allowed t))\n (format t \"Yes~%\")\n (format t \"No~%\"))))\n\n(solver)", "language": "Lisp", "metadata": {"date": 1520106822, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03474.html", "problem_id": "p03474", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03474/input.txt", "sample_output_relpath": "derived/input_output/data/p03474/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03474/Lisp/s565802861.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s565802861", "user_id": "u183015556"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun solver ()\n (let ((a (read)) (b (read))\n (s (read-line)))\n (if (and (parse-integer s :start 0 :end a :junk-allowed t)\n (char= (char s a) #\\-)\n (parse-integer s :start (+ a 1) :end (+ a b 1) :junk-allowed t))\n (format t \"Yes~%\")\n (format t \"No~%\"))))\n\n(solver)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThe postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen -, and the other characters are digits from 0 through 9.\n\nYou are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.\n\nConstraints\n\n1≤A,B≤5\n\n|S|=A+B+1\n\nS consists of - and digits from 0 through 9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\nS\n\nOutput\n\nPrint Yes if S follows the postal code format in AtCoder Kingdom; print No otherwise.\n\nSample Input 1\n\n3 4\n269-6650\n\nSample Output 1\n\nYes\n\nThe (A+1)-th character of S is -, and the other characters are digits from 0 through 9, so it follows the format.\n\nSample Input 2\n\n1 1\n---\n\nSample Output 2\n\nNo\n\nS contains unnecessary -s other than the (A+1)-th character, so it does not follow the format.\n\nSample Input 3\n\n1 2\n7444\n\nSample Output 3\n\nNo", "sample_input": "3 4\n269-6650\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03474", "source_text": "Score : 200 points\n\nProblem Statement\n\nThe postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen -, and the other characters are digits from 0 through 9.\n\nYou are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.\n\nConstraints\n\n1≤A,B≤5\n\n|S|=A+B+1\n\nS consists of - and digits from 0 through 9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\nS\n\nOutput\n\nPrint Yes if S follows the postal code format in AtCoder Kingdom; print No otherwise.\n\nSample Input 1\n\n3 4\n269-6650\n\nSample Output 1\n\nYes\n\nThe (A+1)-th character of S is -, and the other characters are digits from 0 through 9, so it follows the format.\n\nSample Input 2\n\n1 1\n---\n\nSample Output 2\n\nNo\n\nS contains unnecessary -s other than the (A+1)-th character, so it does not follow the format.\n\nSample Input 3\n\n1 2\n7444\n\nSample Output 3\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 314, "cpu_time_ms": 130, "memory_kb": 12648}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s339086082", "group_id": "codeNet:p03474", "input_text": "(let ((a (read))\n (b (read))\n (s (read-line)))\n (princ\n (if (and (= (length s) (+ a b 1))\n (char= (aref s a) #\\-)\n (not (member #\\- (concatenate 'list\n (subseq s 0 a)\n (subseq s (1+ a) (+ a b 1))))))\n \"Yes\"\n \"No\"))\n (terpri))", "language": "Lisp", "metadata": {"date": 1514686773, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03474.html", "problem_id": "p03474", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03474/input.txt", "sample_output_relpath": "derived/input_output/data/p03474/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03474/Lisp/s339086082.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s339086082", "user_id": "u188771036"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (s (read-line)))\n (princ\n (if (and (= (length s) (+ a b 1))\n (char= (aref s a) #\\-)\n (not (member #\\- (concatenate 'list\n (subseq s 0 a)\n (subseq s (1+ a) (+ a b 1))))))\n \"Yes\"\n \"No\"))\n (terpri))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThe postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen -, and the other characters are digits from 0 through 9.\n\nYou are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.\n\nConstraints\n\n1≤A,B≤5\n\n|S|=A+B+1\n\nS consists of - and digits from 0 through 9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\nS\n\nOutput\n\nPrint Yes if S follows the postal code format in AtCoder Kingdom; print No otherwise.\n\nSample Input 1\n\n3 4\n269-6650\n\nSample Output 1\n\nYes\n\nThe (A+1)-th character of S is -, and the other characters are digits from 0 through 9, so it follows the format.\n\nSample Input 2\n\n1 1\n---\n\nSample Output 2\n\nNo\n\nS contains unnecessary -s other than the (A+1)-th character, so it does not follow the format.\n\nSample Input 3\n\n1 2\n7444\n\nSample Output 3\n\nNo", "sample_input": "3 4\n269-6650\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03474", "source_text": "Score : 200 points\n\nProblem Statement\n\nThe postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen -, and the other characters are digits from 0 through 9.\n\nYou are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.\n\nConstraints\n\n1≤A,B≤5\n\n|S|=A+B+1\n\nS consists of - and digits from 0 through 9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\nS\n\nOutput\n\nPrint Yes if S follows the postal code format in AtCoder Kingdom; print No otherwise.\n\nSample Input 1\n\n3 4\n269-6650\n\nSample Output 1\n\nYes\n\nThe (A+1)-th character of S is -, and the other characters are digits from 0 through 9, so it follows the format.\n\nSample Input 2\n\n1 1\n---\n\nSample Output 2\n\nNo\n\nS contains unnecessary -s other than the (A+1)-th character, so it does not follow the format.\n\nSample Input 3\n\n1 2\n7444\n\nSample Output 3\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 355, "cpu_time_ms": 782, "memory_kb": 13284}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s861265189", "group_id": "codeNet:p03477", "input_text": "(let ((l (+ (read) (read)))\n (r (+ (read) (read))))\n\n (format t \"~A~%\"\n (cond ((= l r) \"Balanced\")\n ((< l r) \"Right\")\n (t \"Left\"))))\n", "language": "Lisp", "metadata": {"date": 1597879143, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03477.html", "problem_id": "p03477", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03477/input.txt", "sample_output_relpath": "derived/input_output/data/p03477/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03477/Lisp/s861265189.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s861265189", "user_id": "u336541610"}, "prompt_components": {"gold_output": "Left\n", "input_to_evaluate": "(let ((l (+ (read) (read)))\n (r (+ (read) (read))))\n\n (format t \"~A~%\"\n (cond ((= l r) \"Balanced\")\n ((< l r) \"Right\")\n (t \"Left\"))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nA balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L8, we should print Left.\n\nSample Input 2\n\n3 4 5 2\n\nSample Output 2\n\nBalanced\n\nThe total weight of the masses on the left pan is 7, and the total weight of the masses on the right pan is 7. Since 7=7, we should print Balanced.\n\nSample Input 3\n\n1 7 6 4\n\nSample Output 3\n\nRight\n\nThe total weight of the masses on the left pan is 8, and the total weight of the masses on the right pan is 10. Since 8<10, we should print Right.", "sample_input": "3 8 7 1\n"}, "reference_outputs": ["Left\n"], "source_document_id": "p03477", "source_text": "Score : 100 points\n\nProblem Statement\n\nA balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L8, we should print Left.\n\nSample Input 2\n\n3 4 5 2\n\nSample Output 2\n\nBalanced\n\nThe total weight of the masses on the left pan is 7, and the total weight of the masses on the right pan is 7. Since 7=7, we should print Balanced.\n\nSample Input 3\n\n1 7 6 4\n\nSample Output 3\n\nRight\n\nThe total weight of the masses on the left pan is 8, and the total weight of the masses on the right pan is 10. Since 8<10, we should print Right.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 178, "cpu_time_ms": 24, "memory_kb": 23472}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s545020581", "group_id": "codeNet:p03477", "input_text": "(let ( (left (+ (read) (read))) (right (+ (read) (read))) )\n (format t \"~a~%\"\n (cond\n ((= left right)\n \"Balanced\")\n ((< left right)\n \"Right\")\n (t\n \"Left\")))\n )\n ", "language": "Lisp", "metadata": {"date": 1514092813, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03477.html", "problem_id": "p03477", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03477/input.txt", "sample_output_relpath": "derived/input_output/data/p03477/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03477/Lisp/s545020581.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s545020581", "user_id": "u396817842"}, "prompt_components": {"gold_output": "Left\n", "input_to_evaluate": "(let ( (left (+ (read) (read))) (right (+ (read) (read))) )\n (format t \"~a~%\"\n (cond\n ((= left right)\n \"Balanced\")\n ((< left right)\n \"Right\")\n (t\n \"Left\")))\n )\n ", "problem_context": "Score : 100 points\n\nProblem Statement\n\nA balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L8, we should print Left.\n\nSample Input 2\n\n3 4 5 2\n\nSample Output 2\n\nBalanced\n\nThe total weight of the masses on the left pan is 7, and the total weight of the masses on the right pan is 7. Since 7=7, we should print Balanced.\n\nSample Input 3\n\n1 7 6 4\n\nSample Output 3\n\nRight\n\nThe total weight of the masses on the left pan is 8, and the total weight of the masses on the right pan is 10. Since 8<10, we should print Right.", "sample_input": "3 8 7 1\n"}, "reference_outputs": ["Left\n"], "source_document_id": "p03477", "source_text": "Score : 100 points\n\nProblem Statement\n\nA balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L8, we should print Left.\n\nSample Input 2\n\n3 4 5 2\n\nSample Output 2\n\nBalanced\n\nThe total weight of the masses on the left pan is 7, and the total weight of the masses on the right pan is 7. Since 7=7, we should print Balanced.\n\nSample Input 3\n\n1 7 6 4\n\nSample Output 3\n\nRight\n\nThe total weight of the masses on the left pan is 8, and the total weight of the masses on the right pan is 10. Since 8<10, we should print Right.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 276, "cpu_time_ms": 119, "memory_kb": 11364}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s628114129", "group_id": "codeNet:p03479", "input_text": "(let ((a (read))\n (b (read))\n (ans 1))\n (setf b (floor (/ b a)))\n (loop for i from 1 while (<= (expt 2 i) b) do (incf ans))\n (format t \"~A~%\" ans))\n", "language": "Lisp", "metadata": {"date": 1527912713, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03479.html", "problem_id": "p03479", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03479/input.txt", "sample_output_relpath": "derived/input_output/data/p03479/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03479/Lisp/s628114129.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s628114129", "user_id": "u994767958"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (ans 1))\n (setf b (floor (/ b a)))\n (loop for i from 1 while (<= (expt 2 i) b) do (incf ans))\n (format t \"~A~%\" ans))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nAs a token of his gratitude, Takahashi has decided to give his mother an integer sequence.\nThe sequence A needs to satisfy the conditions below:\n\nA consists of integers between X and Y (inclusive).\n\nFor each 1\\leq i \\leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.\n\nFind the maximum possible length of the sequence.\n\nConstraints\n\n1 \\leq X \\leq Y \\leq 10^{18}\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nPrint the maximum possible length of the sequence.\n\nSample Input 1\n\n3 20\n\nSample Output 1\n\n3\n\nThe sequence 3,6,18 satisfies the conditions.\n\nSample Input 2\n\n25 100\n\nSample Output 2\n\n3\n\nSample Input 3\n\n314159265 358979323846264338\n\nSample Output 3\n\n31", "sample_input": "3 20\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03479", "source_text": "Score : 300 points\n\nProblem Statement\n\nAs a token of his gratitude, Takahashi has decided to give his mother an integer sequence.\nThe sequence A needs to satisfy the conditions below:\n\nA consists of integers between X and Y (inclusive).\n\nFor each 1\\leq i \\leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.\n\nFind the maximum possible length of the sequence.\n\nConstraints\n\n1 \\leq X \\leq Y \\leq 10^{18}\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nPrint the maximum possible length of the sequence.\n\nSample Input 1\n\n3 20\n\nSample Output 1\n\n3\n\nThe sequence 3,6,18 satisfies the conditions.\n\nSample Input 2\n\n25 100\n\nSample Output 2\n\n3\n\nSample Input 3\n\n314159265 358979323846264338\n\nSample Output 3\n\n31", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 161, "cpu_time_ms": 182, "memory_kb": 13924}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s096649371", "group_id": "codeNet:p03479", "input_text": "(defun solver ()\n (let ((x (read)) (y (read)) (count 0))\n (loop do\n (if (< y x)\n (return (format t \"~a~%\" count))\n (progn (setf x (* x 2)) (incf count))))))\n\n(solver)", "language": "Lisp", "metadata": {"date": 1520118623, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03479.html", "problem_id": "p03479", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03479/input.txt", "sample_output_relpath": "derived/input_output/data/p03479/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03479/Lisp/s096649371.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s096649371", "user_id": "u183015556"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun solver ()\n (let ((x (read)) (y (read)) (count 0))\n (loop do\n (if (< y x)\n (return (format t \"~a~%\" count))\n (progn (setf x (* x 2)) (incf count))))))\n\n(solver)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nAs a token of his gratitude, Takahashi has decided to give his mother an integer sequence.\nThe sequence A needs to satisfy the conditions below:\n\nA consists of integers between X and Y (inclusive).\n\nFor each 1\\leq i \\leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.\n\nFind the maximum possible length of the sequence.\n\nConstraints\n\n1 \\leq X \\leq Y \\leq 10^{18}\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nPrint the maximum possible length of the sequence.\n\nSample Input 1\n\n3 20\n\nSample Output 1\n\n3\n\nThe sequence 3,6,18 satisfies the conditions.\n\nSample Input 2\n\n25 100\n\nSample Output 2\n\n3\n\nSample Input 3\n\n314159265 358979323846264338\n\nSample Output 3\n\n31", "sample_input": "3 20\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03479", "source_text": "Score : 300 points\n\nProblem Statement\n\nAs a token of his gratitude, Takahashi has decided to give his mother an integer sequence.\nThe sequence A needs to satisfy the conditions below:\n\nA consists of integers between X and Y (inclusive).\n\nFor each 1\\leq i \\leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.\n\nFind the maximum possible length of the sequence.\n\nConstraints\n\n1 \\leq X \\leq Y \\leq 10^{18}\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nPrint the maximum possible length of the sequence.\n\nSample Input 1\n\n3 20\n\nSample Output 1\n\n3\n\nThe sequence 3,6,18 satisfies the conditions.\n\nSample Input 2\n\n25 100\n\nSample Output 2\n\n3\n\nSample Input 3\n\n314159265 358979323846264338\n\nSample Output 3\n\n31", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 205, "cpu_time_ms": 134, "memory_kb": 12264}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s118420228", "group_id": "codeNet:p03479", "input_text": "(let ((x (read))\n (y (read)))\n (format t \"~A~%\"\n (loop for i = x then (* 2 i)\n until (< y i)\n count i)))", "language": "Lisp", "metadata": {"date": 1514085435, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03479.html", "problem_id": "p03479", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03479/input.txt", "sample_output_relpath": "derived/input_output/data/p03479/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03479/Lisp/s118420228.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s118420228", "user_id": "u275710783"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((x (read))\n (y (read)))\n (format t \"~A~%\"\n (loop for i = x then (* 2 i)\n until (< y i)\n count i)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nAs a token of his gratitude, Takahashi has decided to give his mother an integer sequence.\nThe sequence A needs to satisfy the conditions below:\n\nA consists of integers between X and Y (inclusive).\n\nFor each 1\\leq i \\leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.\n\nFind the maximum possible length of the sequence.\n\nConstraints\n\n1 \\leq X \\leq Y \\leq 10^{18}\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nPrint the maximum possible length of the sequence.\n\nSample Input 1\n\n3 20\n\nSample Output 1\n\n3\n\nThe sequence 3,6,18 satisfies the conditions.\n\nSample Input 2\n\n25 100\n\nSample Output 2\n\n3\n\nSample Input 3\n\n314159265 358979323846264338\n\nSample Output 3\n\n31", "sample_input": "3 20\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03479", "source_text": "Score : 300 points\n\nProblem Statement\n\nAs a token of his gratitude, Takahashi has decided to give his mother an integer sequence.\nThe sequence A needs to satisfy the conditions below:\n\nA consists of integers between X and Y (inclusive).\n\nFor each 1\\leq i \\leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.\n\nFind the maximum possible length of the sequence.\n\nConstraints\n\n1 \\leq X \\leq Y \\leq 10^{18}\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nPrint the maximum possible length of the sequence.\n\nSample Input 1\n\n3 20\n\nSample Output 1\n\n3\n\nThe sequence 3,6,18 satisfies the conditions.\n\nSample Input 2\n\n25 100\n\nSample Output 2\n\n3\n\nSample Input 3\n\n314159265 358979323846264338\n\nSample Output 3\n\n31", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 149, "cpu_time_ms": 353, "memory_kb": 12392}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s263728884", "group_id": "codeNet:p03480", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun count-consecutive-chars (s)\n (let ((res 0))\n (loop with base = 0\n with base-c = (aref s base)\n for i below (length s)\n do (unless (char= base-c (aref s i))\n (setf res (max res (- i base))\n base i\n base-c (aref s i)))\n finally (setf res (max res (- i base))))\n res))\n\n(defun main ()\n (let* ((s (read-line))\n (len (length s)))\n (println\n (max (count-consecutive-chars s)\n (ceiling len 2)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1554894378, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03480.html", "problem_id": "p03480", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03480/input.txt", "sample_output_relpath": "derived/input_output/data/p03480/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03480/Lisp/s263728884.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s263728884", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun count-consecutive-chars (s)\n (let ((res 0))\n (loop with base = 0\n with base-c = (aref s base)\n for i below (length s)\n do (unless (char= base-c (aref s i))\n (setf res (max res (- i base))\n base i\n base-c (aref s i)))\n finally (setf res (max res (- i base))))\n res))\n\n(defun main ()\n (let* ((s (read-line))\n (len (length s)))\n (println\n (max (count-consecutive-chars s)\n (ceiling len 2)))))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nYou are given a string S consisting of 0 and 1.\nFind the maximum integer K not greater than |S| such that we can turn all the characters of S into 0 by repeating the following operation some number of times.\n\nChoose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\\geq K must be satisfied). For each integer i such that l\\leq i\\leq r, do the following: if S_i is 0, replace it with 1; if S_i is 1, replace it with 0.\n\nConstraints\n\n1\\leq |S|\\leq 10^5\n\nS_i(1\\leq i\\leq N) is either 0 or 1.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the maximum integer K such that we can turn all the characters of S into 0 by repeating the operation some number of times.\n\nSample Input 1\n\n010\n\nSample Output 1\n\n2\n\nWe can turn all the characters of S into 0 by the following operations:\n\nPerform the operation on the segment S[1,3] with length 3. S is now 101.\n\nPerform the operation on the segment S[1,2] with length 2. S is now 011.\n\nPerform the operation on the segment S[2,3] with length 2. S is now 000.\n\nSample Input 2\n\n100000000\n\nSample Output 2\n\n8\n\nSample Input 3\n\n00001111\n\nSample Output 3\n\n4", "sample_input": "010\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03480", "source_text": "Score : 500 points\n\nProblem Statement\n\nYou are given a string S consisting of 0 and 1.\nFind the maximum integer K not greater than |S| such that we can turn all the characters of S into 0 by repeating the following operation some number of times.\n\nChoose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\\geq K must be satisfied). For each integer i such that l\\leq i\\leq r, do the following: if S_i is 0, replace it with 1; if S_i is 1, replace it with 0.\n\nConstraints\n\n1\\leq |S|\\leq 10^5\n\nS_i(1\\leq i\\leq N) is either 0 or 1.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the maximum integer K such that we can turn all the characters of S into 0 by repeating the operation some number of times.\n\nSample Input 1\n\n010\n\nSample Output 1\n\n2\n\nWe can turn all the characters of S into 0 by the following operations:\n\nPerform the operation on the segment S[1,3] with length 3. S is now 101.\n\nPerform the operation on the segment S[1,2] with length 2. S is now 011.\n\nPerform the operation on the segment S[2,3] with length 2. S is now 000.\n\nSample Input 2\n\n100000000\n\nSample Output 2\n\n8\n\nSample Input 3\n\n00001111\n\nSample Output 3\n\n4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1710, "cpu_time_ms": 178, "memory_kb": 19040}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s477685472", "group_id": "codeNet:p03483", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; ARRAY-ELEMENT-TYPE is not constant-folded on SBCL version earlier than\n;;; 1.5.0. See\n;;; https://github.com/sbcl/sbcl/commit/9f0d12e7ab961828931d01c0b2a76a5885ad35d2\n;;;\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:deftransform array-element-type ((array))\n (let ((type (sb-c::lvar-type array)))\n (flet ((element-type (type)\n (and (sb-c::array-type-p type)\n (sb-int:neq (sb-kernel::array-type-specialized-element-type type) sb-kernel:*wild-type*)\n (sb-kernel:type-specifier (sb-kernel::array-type-specialized-element-type type)))))\n (cond ((let ((type (element-type type)))\n (and type\n `',type)))\n ((sb-kernel:union-type-p type)\n (let (result)\n (loop for type in (sb-kernel:union-type-types type)\n for et = (element-type type)\n unless (and et\n (if result\n (equal result et)\n (setf result et)))\n do (sb-c::give-up-ir1-transform))\n `',result))\n ((sb-kernel:intersection-type-p type)\n (loop for type in (sb-kernel:intersection-type-types type)\n for et = (element-type type)\n when et\n return `',et\n finally (sb-c::give-up-ir1-transform)))\n (t\n (sb-c::give-up-ir1-transform)))))))\n\n;;;\n;;; Compute inversion number by merge sort\n;;;\n\n(declaim (inline %merge-count))\n(defun %merge-count (l mid r source-vec dest-vec predicate)\n (declare ((integer 0 #.array-total-size-limit) l mid r)\n (function predicate))\n (loop with count of-type (integer 0 #.most-positive-fixnum) = 0\n with i = l\n with j = mid\n for idx from l\n when (= i mid)\n do (loop for j from j below r\n for idx from idx\n do (setf (aref dest-vec idx)\n (aref source-vec j))\n finally (return-from %merge-count count))\n when (= j r)\n do (loop for i from i below mid\n for idx from idx\n do (setf (aref dest-vec idx)\n (aref source-vec i))\n finally (return-from %merge-count count))\n do (if (funcall predicate\n (aref source-vec j)\n (aref source-vec i))\n (setf (aref dest-vec idx) (aref source-vec j)\n j (1+ j)\n count (+ count (- mid i)))\n (setf (aref dest-vec idx) (aref source-vec i)\n i (1+ i)))))\n\n(defmacro with-fixnum+ (form)\n (let ((fixnum+ '(integer 0 #.most-positive-fixnum)))\n `(the ,fixnum+\n ,(reduce (lambda (f1 f2)`(,(car form)\n (the ,fixnum+ ,f1)\n (the ,fixnum+ ,f2)))\n\t (cdr form)))))\n\n(declaim (inline %calc-by-insertion-sort!))\n(defun %calc-by-insertion-sort! (vec predicate l r)\n (declare (function predicate)\n ((integer 0 #.array-total-size-limit) l r))\n (loop with inv-count of-type (integer 0 #.most-positive-fixnum) = 0\n for end from (+ l 1) below r\n do (loop for i from end above l\n while (funcall predicate (aref vec i) (aref vec (- i 1)))\n do (rotatef (aref vec (- i 1)) (aref vec i))\n (incf inv-count))\n finally (return inv-count)))\n\n;; NOTE: This function is slow on SBCL version earlier than 1.5.0 as\n;; constant-folding of ARRAY-ELEMENT-TYPE doesn't work. Use\n;; array-element-type.lisp if necessary.\n(declaim (inline count-inversions!))\n(defun count-inversions! (vector predicate &key (start 0) end)\n \"Calculates the number of the inversions of VECTOR w.r.t. the strict order\nPREDICATE. This function sorts VECTOR as a side effect.\"\n (declare (vector vector)\n (function predicate))\n (let ((end (or end (length vector))))\n (declare ((integer 0 #.array-total-size-limit) start end))\n (assert (<= start end))\n (let ((buffer (make-array end :element-type (array-element-type vector))))\n (labels\n ((recur (l r merge-to-vec1-p)\n (declare (optimize (safety 0))\n ((integer 0 #.array-total-size-limit) l r))\n (cond ((= l r) 0)\n ((= (+ l 1) r)\n (unless merge-to-vec1-p\n (setf (aref buffer l) (aref vector l)))\n 0)\n ;; It is faster to use insertion sort. I don't adopt it\n ;; by default, however, because that makes it hard to\n ;; change the code to fit some special settings.\n ;; ((and (<= (- r l) 24) merge-to-vec1-p)\n ;; (%calc-by-insertion-sort! vector predicate l r))\n (t\n (let ((mid (floor (+ l r) 2)))\n (with-fixnum+\n (+ (recur l mid (not merge-to-vec1-p))\n (recur mid r (not merge-to-vec1-p))\n (if merge-to-vec1-p\n (%merge-count l mid r buffer vector predicate)\n (%merge-count l mid r vector buffer predicate)))))))))\n (recur start end t)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline to-code))\n(defun to-code (c)\n (- (char-code c) #.(char-code #\\a)))\n\n(declaim (inline make-histogram))\n(defun make-histogram (s)\n (let ((res (make-array 26 :element-type 'uint32 :initial-element 0)))\n (sb-int:dovector (c s res)\n (incf (aref res (to-code c))))))\n\n(defun solve-even (s)\n (declare (simple-base-string s))\n (let* ((len (length s))\n (len/2 (floor len 2))\n (histo (make-histogram s))\n (histo1 (make-array 26 :element-type 'uint32 :initial-element 0))\n (histo2 (make-array 26 :element-type 'uint32 :initial-element 0))\n (in-left (make-array len :fill-pointer 0))\n (to-right (make-array len :fill-pointer 0))\n (in-right (make-array len :fill-pointer 0))\n (to-left (make-array len :fill-pointer 0))\n (difference 0)\n (res 0))\n (declare (uint62 difference res))\n (assert (evenp len))\n (dotimes (i len/2 (fill histo1 0))\n (let* ((c (aref s i))\n (code (to-code c)))\n (incf (aref histo1 code))\n (when (> (aref histo1 code) (floor (aref histo code) 2))\n (incf difference))))\n (let ((delta difference))\n (declare (uint62 delta))\n (dotimes (i len/2)\n (let* ((c (aref s i))\n (code (to-code c)))\n (incf (aref histo1 code))\n (if (> (aref histo1 code) (floor (aref histo code) 2))\n (progn\n (vector-push (cons c i) to-right)\n (incf res (- (- len/2 delta) i))\n (decf delta))\n (vector-push (cons c i) in-left)))))\n (let ((delta difference))\n (declare (uint62 delta))\n (loop for i from (- len 1) downto len/2\n do (let* ((c (aref s i))\n (code (to-code c)))\n (incf (aref histo2 code))\n (if (> (aref histo2 code) (floor (aref histo code) 2))\n (progn\n (vector-push (cons c i) to-left)\n (incf res (- i (+ len/2 delta -1)))\n (decf delta))\n (vector-push (cons c i) in-right)))\n finally (setq to-left (nreverse to-left)\n in-right (nreverse in-right))))\n (assert (= (length to-right) (length to-left)))\n (incf res (expt (length to-right) 2))\n (let ((tmp-left (map 'simple-base-string #'car (concatenate 'simple-vector in-left to-left)))\n (tmp-right (map 'simple-base-string #'car (concatenate 'simple-vector to-right in-right)))\n (ords (make-array 26 :element-type 'list :initial-element nil)))\n (loop for i from (- len/2 1) downto 0\n for ord from 0 below len/2\n do (push ord (aref ords (to-code (aref tmp-left i)))))\n (dotimes (i 26)\n (setf (aref ords i) (nreverse (aref ords i))))\n (let ((ord-right (map '(simple-array uint32 (*))\n (lambda (c)\n (pop (aref ords (to-code c))))\n tmp-right)))\n (incf res (count-inversions! ord-right #'<)))\n res)))\n\n(defun main ()\n (let* ((s (coerce (read-line) 'simple-base-string))\n (len (length s))\n (len/2 (floor len 2))\n (histo (make-histogram s)))\n (println\n (if (evenp len)\n (if (every #'evenp histo)\n (solve-even s)\n -1)\n (let ((odd-chars (loop for i below 26\n for x across histo\n when (oddp x)\n collect (code-char (+ 97 i)))))\n (if (= (length odd-chars) 1)\n (let* ((odd-char (car odd-chars))\n (pos0 (or (position odd-char s :end len/2 :from-end t)\n most-negative-fixnum))\n (pos1 (or (position odd-char s :start len/2)\n most-positive-fixnum))\n (pos (if (<= (- len/2 pos0) (- pos1 len/2))\n pos0\n pos1))\n (s (concatenate 'simple-base-string\n (subseq s 0 pos)\n (subseq s (+ pos 1))))\n (res (min (- len/2 pos0) (- pos1 len/2))))\n (+ res (solve-even s)))\n -1))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1569013582, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03483.html", "problem_id": "p03483", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03483/input.txt", "sample_output_relpath": "derived/input_output/data/p03483/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03483/Lisp/s477685472.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s477685472", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; ARRAY-ELEMENT-TYPE is not constant-folded on SBCL version earlier than\n;;; 1.5.0. See\n;;; https://github.com/sbcl/sbcl/commit/9f0d12e7ab961828931d01c0b2a76a5885ad35d2\n;;;\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:deftransform array-element-type ((array))\n (let ((type (sb-c::lvar-type array)))\n (flet ((element-type (type)\n (and (sb-c::array-type-p type)\n (sb-int:neq (sb-kernel::array-type-specialized-element-type type) sb-kernel:*wild-type*)\n (sb-kernel:type-specifier (sb-kernel::array-type-specialized-element-type type)))))\n (cond ((let ((type (element-type type)))\n (and type\n `',type)))\n ((sb-kernel:union-type-p type)\n (let (result)\n (loop for type in (sb-kernel:union-type-types type)\n for et = (element-type type)\n unless (and et\n (if result\n (equal result et)\n (setf result et)))\n do (sb-c::give-up-ir1-transform))\n `',result))\n ((sb-kernel:intersection-type-p type)\n (loop for type in (sb-kernel:intersection-type-types type)\n for et = (element-type type)\n when et\n return `',et\n finally (sb-c::give-up-ir1-transform)))\n (t\n (sb-c::give-up-ir1-transform)))))))\n\n;;;\n;;; Compute inversion number by merge sort\n;;;\n\n(declaim (inline %merge-count))\n(defun %merge-count (l mid r source-vec dest-vec predicate)\n (declare ((integer 0 #.array-total-size-limit) l mid r)\n (function predicate))\n (loop with count of-type (integer 0 #.most-positive-fixnum) = 0\n with i = l\n with j = mid\n for idx from l\n when (= i mid)\n do (loop for j from j below r\n for idx from idx\n do (setf (aref dest-vec idx)\n (aref source-vec j))\n finally (return-from %merge-count count))\n when (= j r)\n do (loop for i from i below mid\n for idx from idx\n do (setf (aref dest-vec idx)\n (aref source-vec i))\n finally (return-from %merge-count count))\n do (if (funcall predicate\n (aref source-vec j)\n (aref source-vec i))\n (setf (aref dest-vec idx) (aref source-vec j)\n j (1+ j)\n count (+ count (- mid i)))\n (setf (aref dest-vec idx) (aref source-vec i)\n i (1+ i)))))\n\n(defmacro with-fixnum+ (form)\n (let ((fixnum+ '(integer 0 #.most-positive-fixnum)))\n `(the ,fixnum+\n ,(reduce (lambda (f1 f2)`(,(car form)\n (the ,fixnum+ ,f1)\n (the ,fixnum+ ,f2)))\n\t (cdr form)))))\n\n(declaim (inline %calc-by-insertion-sort!))\n(defun %calc-by-insertion-sort! (vec predicate l r)\n (declare (function predicate)\n ((integer 0 #.array-total-size-limit) l r))\n (loop with inv-count of-type (integer 0 #.most-positive-fixnum) = 0\n for end from (+ l 1) below r\n do (loop for i from end above l\n while (funcall predicate (aref vec i) (aref vec (- i 1)))\n do (rotatef (aref vec (- i 1)) (aref vec i))\n (incf inv-count))\n finally (return inv-count)))\n\n;; NOTE: This function is slow on SBCL version earlier than 1.5.0 as\n;; constant-folding of ARRAY-ELEMENT-TYPE doesn't work. Use\n;; array-element-type.lisp if necessary.\n(declaim (inline count-inversions!))\n(defun count-inversions! (vector predicate &key (start 0) end)\n \"Calculates the number of the inversions of VECTOR w.r.t. the strict order\nPREDICATE. This function sorts VECTOR as a side effect.\"\n (declare (vector vector)\n (function predicate))\n (let ((end (or end (length vector))))\n (declare ((integer 0 #.array-total-size-limit) start end))\n (assert (<= start end))\n (let ((buffer (make-array end :element-type (array-element-type vector))))\n (labels\n ((recur (l r merge-to-vec1-p)\n (declare (optimize (safety 0))\n ((integer 0 #.array-total-size-limit) l r))\n (cond ((= l r) 0)\n ((= (+ l 1) r)\n (unless merge-to-vec1-p\n (setf (aref buffer l) (aref vector l)))\n 0)\n ;; It is faster to use insertion sort. I don't adopt it\n ;; by default, however, because that makes it hard to\n ;; change the code to fit some special settings.\n ;; ((and (<= (- r l) 24) merge-to-vec1-p)\n ;; (%calc-by-insertion-sort! vector predicate l r))\n (t\n (let ((mid (floor (+ l r) 2)))\n (with-fixnum+\n (+ (recur l mid (not merge-to-vec1-p))\n (recur mid r (not merge-to-vec1-p))\n (if merge-to-vec1-p\n (%merge-count l mid r buffer vector predicate)\n (%merge-count l mid r vector buffer predicate)))))))))\n (recur start end t)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline to-code))\n(defun to-code (c)\n (- (char-code c) #.(char-code #\\a)))\n\n(declaim (inline make-histogram))\n(defun make-histogram (s)\n (let ((res (make-array 26 :element-type 'uint32 :initial-element 0)))\n (sb-int:dovector (c s res)\n (incf (aref res (to-code c))))))\n\n(defun solve-even (s)\n (declare (simple-base-string s))\n (let* ((len (length s))\n (len/2 (floor len 2))\n (histo (make-histogram s))\n (histo1 (make-array 26 :element-type 'uint32 :initial-element 0))\n (histo2 (make-array 26 :element-type 'uint32 :initial-element 0))\n (in-left (make-array len :fill-pointer 0))\n (to-right (make-array len :fill-pointer 0))\n (in-right (make-array len :fill-pointer 0))\n (to-left (make-array len :fill-pointer 0))\n (difference 0)\n (res 0))\n (declare (uint62 difference res))\n (assert (evenp len))\n (dotimes (i len/2 (fill histo1 0))\n (let* ((c (aref s i))\n (code (to-code c)))\n (incf (aref histo1 code))\n (when (> (aref histo1 code) (floor (aref histo code) 2))\n (incf difference))))\n (let ((delta difference))\n (declare (uint62 delta))\n (dotimes (i len/2)\n (let* ((c (aref s i))\n (code (to-code c)))\n (incf (aref histo1 code))\n (if (> (aref histo1 code) (floor (aref histo code) 2))\n (progn\n (vector-push (cons c i) to-right)\n (incf res (- (- len/2 delta) i))\n (decf delta))\n (vector-push (cons c i) in-left)))))\n (let ((delta difference))\n (declare (uint62 delta))\n (loop for i from (- len 1) downto len/2\n do (let* ((c (aref s i))\n (code (to-code c)))\n (incf (aref histo2 code))\n (if (> (aref histo2 code) (floor (aref histo code) 2))\n (progn\n (vector-push (cons c i) to-left)\n (incf res (- i (+ len/2 delta -1)))\n (decf delta))\n (vector-push (cons c i) in-right)))\n finally (setq to-left (nreverse to-left)\n in-right (nreverse in-right))))\n (assert (= (length to-right) (length to-left)))\n (incf res (expt (length to-right) 2))\n (let ((tmp-left (map 'simple-base-string #'car (concatenate 'simple-vector in-left to-left)))\n (tmp-right (map 'simple-base-string #'car (concatenate 'simple-vector to-right in-right)))\n (ords (make-array 26 :element-type 'list :initial-element nil)))\n (loop for i from (- len/2 1) downto 0\n for ord from 0 below len/2\n do (push ord (aref ords (to-code (aref tmp-left i)))))\n (dotimes (i 26)\n (setf (aref ords i) (nreverse (aref ords i))))\n (let ((ord-right (map '(simple-array uint32 (*))\n (lambda (c)\n (pop (aref ords (to-code c))))\n tmp-right)))\n (incf res (count-inversions! ord-right #'<)))\n res)))\n\n(defun main ()\n (let* ((s (coerce (read-line) 'simple-base-string))\n (len (length s))\n (len/2 (floor len 2))\n (histo (make-histogram s)))\n (println\n (if (evenp len)\n (if (every #'evenp histo)\n (solve-even s)\n -1)\n (let ((odd-chars (loop for i below 26\n for x across histo\n when (oddp x)\n collect (code-char (+ 97 i)))))\n (if (= (length odd-chars) 1)\n (let* ((odd-char (car odd-chars))\n (pos0 (or (position odd-char s :end len/2 :from-end t)\n most-negative-fixnum))\n (pos1 (or (position odd-char s :start len/2)\n most-positive-fixnum))\n (pos (if (<= (- len/2 pos0) (- pos1 len/2))\n pos0\n pos1))\n (s (concatenate 'simple-base-string\n (subseq s 0 pos)\n (subseq s (+ pos 1))))\n (res (min (- len/2 pos0) (- pos1 len/2))))\n (+ res (solve-even s)))\n -1))))))\n\n#-swank (main)\n", "problem_context": "Score : 800 points\n\nProblem Statement\n\nYou are given a string S consisting of lowercase English letters.\nDetermine whether we can turn S into a palindrome by repeating the operation of swapping two adjacent characters. If it is possible, find the minimum required number of operations.\n\nConstraints\n\n1 \\leq |S| \\leq 2 × 10^5\n\nS consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf we cannot turn S into a palindrome, print -1. Otherwise, print the minimum required number of operations.\n\nSample Input 1\n\neel\n\nSample Output 1\n\n1\n\nWe can turn S into a palindrome by the following operation:\n\nSwap the 2-nd and 3-rd characters. S is now ele.\n\nSample Input 2\n\nataatmma\n\nSample Output 2\n\n4\n\nWe can turn S into a palindrome by the following operation:\n\nSwap the 5-th and 6-th characters. S is now ataamtma.\n\nSwap the 4-th and 5-th characters. S is now atamatma.\n\nSwap the 3-rd and 4-th characters. S is now atmaatma.\n\nSwap the 2-nd and 3-rd characters. S is now amtaatma.\n\nSample Input 3\n\nsnuke\n\nSample Output 3\n\n-1\n\nWe cannot turn S into a palindrome.", "sample_input": "eel\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03483", "source_text": "Score : 800 points\n\nProblem Statement\n\nYou are given a string S consisting of lowercase English letters.\nDetermine whether we can turn S into a palindrome by repeating the operation of swapping two adjacent characters. If it is possible, find the minimum required number of operations.\n\nConstraints\n\n1 \\leq |S| \\leq 2 × 10^5\n\nS consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf we cannot turn S into a palindrome, print -1. Otherwise, print the minimum required number of operations.\n\nSample Input 1\n\neel\n\nSample Output 1\n\n1\n\nWe can turn S into a palindrome by the following operation:\n\nSwap the 2-nd and 3-rd characters. S is now ele.\n\nSample Input 2\n\nataatmma\n\nSample Output 2\n\n4\n\nWe can turn S into a palindrome by the following operation:\n\nSwap the 5-th and 6-th characters. S is now ataamtma.\n\nSwap the 4-th and 5-th characters. S is now atamatma.\n\nSwap the 3-rd and 4-th characters. S is now atmaatma.\n\nSwap the 2-nd and 3-rd characters. S is now amtaatma.\n\nSample Input 3\n\nsnuke\n\nSample Output 3\n\n-1\n\nWe cannot turn S into a palindrome.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11201, "cpu_time_ms": 357, "memory_kb": 64352}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s293823986", "group_id": "codeNet:p03485", "input_text": "(format t \"~A~%\"\n (ceiling (/ (+ (read) (read)) 2)))\n", "language": "Lisp", "metadata": {"date": 1597441711, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03485.html", "problem_id": "p03485", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03485/input.txt", "sample_output_relpath": "derived/input_output/data/p03485/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03485/Lisp/s293823986.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s293823986", "user_id": "u336541610"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(format t \"~A~%\"\n (ceiling (/ (+ (read) (read)) 2)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given two positive integers a and b.\nLet x be the average of a and b.\nPrint x rounded up to the nearest integer.\n\nConstraints\n\na and b are integers.\n\n1 \\leq a, b \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nPrint x rounded up to the nearest integer.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\n2\n\nThe average of 1 and 3 is 2.0, and it will be rounded up to the nearest integer, 2.\n\nSample Input 2\n\n7 4\n\nSample Output 2\n\n6\n\nThe average of 7 and 4 is 5.5, and it will be rounded up to the nearest integer, 6.\n\nSample Input 3\n\n5 5\n\nSample Output 3\n\n5", "sample_input": "1 3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03485", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given two positive integers a and b.\nLet x be the average of a and b.\nPrint x rounded up to the nearest integer.\n\nConstraints\n\na and b are integers.\n\n1 \\leq a, b \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nPrint x rounded up to the nearest integer.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\n2\n\nThe average of 1 and 3 is 2.0, and it will be rounded up to the nearest integer, 2.\n\nSample Input 2\n\n7 4\n\nSample Output 2\n\n6\n\nThe average of 7 and 4 is 5.5, and it will be rounded up to the nearest integer, 6.\n\nSample Input 3\n\n5 5\n\nSample Output 3\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 60, "cpu_time_ms": 15, "memory_kb": 24008}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s516228803", "group_id": "codeNet:p03485", "input_text": "(princ (ceiling (+ (read) (read)) 2))", "language": "Lisp", "metadata": {"date": 1551753754, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03485.html", "problem_id": "p03485", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03485/input.txt", "sample_output_relpath": "derived/input_output/data/p03485/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03485/Lisp/s516228803.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s516228803", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(princ (ceiling (+ (read) (read)) 2))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given two positive integers a and b.\nLet x be the average of a and b.\nPrint x rounded up to the nearest integer.\n\nConstraints\n\na and b are integers.\n\n1 \\leq a, b \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nPrint x rounded up to the nearest integer.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\n2\n\nThe average of 1 and 3 is 2.0, and it will be rounded up to the nearest integer, 2.\n\nSample Input 2\n\n7 4\n\nSample Output 2\n\n6\n\nThe average of 7 and 4 is 5.5, and it will be rounded up to the nearest integer, 6.\n\nSample Input 3\n\n5 5\n\nSample Output 3\n\n5", "sample_input": "1 3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03485", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given two positive integers a and b.\nLet x be the average of a and b.\nPrint x rounded up to the nearest integer.\n\nConstraints\n\na and b are integers.\n\n1 \\leq a, b \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nPrint x rounded up to the nearest integer.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\n2\n\nThe average of 1 and 3 is 2.0, and it will be rounded up to the nearest integer, 2.\n\nSample Input 2\n\n7 4\n\nSample Output 2\n\n6\n\nThe average of 7 and 4 is 5.5, and it will be rounded up to the nearest integer, 6.\n\nSample Input 3\n\n5 5\n\nSample Output 3\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 37, "cpu_time_ms": 22, "memory_kb": 3808}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s201849212", "group_id": "codeNet:p03485", "input_text": "(let ((a (read))\n (b (read)))\n (format t \"~A~%\" (truncate (+ a b 1) 2)))", "language": "Lisp", "metadata": {"date": 1513537209, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03485.html", "problem_id": "p03485", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03485/input.txt", "sample_output_relpath": "derived/input_output/data/p03485/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03485/Lisp/s201849212.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s201849212", "user_id": "u275710783"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((a (read))\n (b (read)))\n (format t \"~A~%\" (truncate (+ a b 1) 2)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given two positive integers a and b.\nLet x be the average of a and b.\nPrint x rounded up to the nearest integer.\n\nConstraints\n\na and b are integers.\n\n1 \\leq a, b \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nPrint x rounded up to the nearest integer.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\n2\n\nThe average of 1 and 3 is 2.0, and it will be rounded up to the nearest integer, 2.\n\nSample Input 2\n\n7 4\n\nSample Output 2\n\n6\n\nThe average of 7 and 4 is 5.5, and it will be rounded up to the nearest integer, 6.\n\nSample Input 3\n\n5 5\n\nSample Output 3\n\n5", "sample_input": "1 3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03485", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given two positive integers a and b.\nLet x be the average of a and b.\nPrint x rounded up to the nearest integer.\n\nConstraints\n\na and b are integers.\n\n1 \\leq a, b \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nPrint x rounded up to the nearest integer.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\n2\n\nThe average of 1 and 3 is 2.0, and it will be rounded up to the nearest integer, 2.\n\nSample Input 2\n\n7 4\n\nSample Output 2\n\n6\n\nThe average of 7 and 4 is 5.5, and it will be rounded up to the nearest integer, 6.\n\nSample Input 3\n\n5 5\n\nSample Output 3\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 78, "cpu_time_ms": 123, "memory_kb": 11492}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s084508081", "group_id": "codeNet:p03486", "input_text": "(let* ((a (read-line))\n (b (read-line)))\n (if (string< (sort a #'char<)\n (sort b #'char>))\n (princ \"Yes\")\n (princ \"No\")))\n", "language": "Lisp", "metadata": {"date": 1579239914, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03486.html", "problem_id": "p03486", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03486/input.txt", "sample_output_relpath": "derived/input_output/data/p03486/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03486/Lisp/s084508081.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s084508081", "user_id": "u245103825"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let* ((a (read-line))\n (b (read-line)))\n (if (string< (sort a #'char<)\n (sort b #'char>))\n (princ \"Yes\")\n (princ \"No\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given strings s and t, consisting of lowercase English letters.\nYou will create a string s' by freely rearranging the characters in s.\nYou will also create a string t' by freely rearranging the characters in t.\nDetermine whether it is possible to satisfy s' < t' for the lexicographic order.\n\nNotes\n\nFor a string a = a_1 a_2 ... a_N of length N and a string b = b_1 b_2 ... b_M of length M, we say a < b for the lexicographic order if either one of the following two conditions holds true:\n\nN < M and a_1 = b_1, a_2 = b_2, ..., a_N = b_N.\n\nThere exists i (1 \\leq i \\leq N, M) such that a_1 = b_1, a_2 = b_2, ..., a_{i - 1} = b_{i - 1} and a_i < b_i. Here, letters are compared using alphabetical order.\n\nFor example, xy < xya and atcoder < atlas.\n\nConstraints\n\nThe lengths of s and t are between 1 and 100 (inclusive).\n\ns and t consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\nt\n\nOutput\n\nIf it is possible to satisfy s' < t', print Yes; if it is not, print No.\n\nSample Input 1\n\nyx\naxy\n\nSample Output 1\n\nYes\n\nWe can, for example, rearrange yx into xy and axy into yxa. Then, xy < yxa.\n\nSample Input 2\n\nratcode\natlas\n\nSample Output 2\n\nYes\n\nWe can, for example, rearrange ratcode into acdeort and atlas into tslaa. Then, acdeort < tslaa.\n\nSample Input 3\n\ncd\nabc\n\nSample Output 3\n\nNo\n\nNo matter how we rearrange cd and abc, we cannot achieve our objective.\n\nSample Input 4\n\nw\nww\n\nSample Output 4\n\nYes\n\nSample Input 5\n\nzzz\nzzz\n\nSample Output 5\n\nNo", "sample_input": "yx\naxy\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03486", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given strings s and t, consisting of lowercase English letters.\nYou will create a string s' by freely rearranging the characters in s.\nYou will also create a string t' by freely rearranging the characters in t.\nDetermine whether it is possible to satisfy s' < t' for the lexicographic order.\n\nNotes\n\nFor a string a = a_1 a_2 ... a_N of length N and a string b = b_1 b_2 ... b_M of length M, we say a < b for the lexicographic order if either one of the following two conditions holds true:\n\nN < M and a_1 = b_1, a_2 = b_2, ..., a_N = b_N.\n\nThere exists i (1 \\leq i \\leq N, M) such that a_1 = b_1, a_2 = b_2, ..., a_{i - 1} = b_{i - 1} and a_i < b_i. Here, letters are compared using alphabetical order.\n\nFor example, xy < xya and atcoder < atlas.\n\nConstraints\n\nThe lengths of s and t are between 1 and 100 (inclusive).\n\ns and t consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\nt\n\nOutput\n\nIf it is possible to satisfy s' < t', print Yes; if it is not, print No.\n\nSample Input 1\n\nyx\naxy\n\nSample Output 1\n\nYes\n\nWe can, for example, rearrange yx into xy and axy into yxa. Then, xy < yxa.\n\nSample Input 2\n\nratcode\natlas\n\nSample Output 2\n\nYes\n\nWe can, for example, rearrange ratcode into acdeort and atlas into tslaa. Then, acdeort < tslaa.\n\nSample Input 3\n\ncd\nabc\n\nSample Output 3\n\nNo\n\nNo matter how we rearrange cd and abc, we cannot achieve our objective.\n\nSample Input 4\n\nw\nww\n\nSample Output 4\n\nYes\n\nSample Input 5\n\nzzz\nzzz\n\nSample Output 5\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 153, "cpu_time_ms": 10, "memory_kb": 3432}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s471498537", "group_id": "codeNet:p03486", "input_text": "\n(defun answer (l r)\n (let ((ll (sort l #'char<))\n\t(rr (sort r #'char>)))\n (if (string< ll rr)\n\t\"Yes\"\n\t\"No\")))\n\n(print (answer (read-line) (read-line)))\t", "language": "Lisp", "metadata": {"date": 1514579321, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03486.html", "problem_id": "p03486", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03486/input.txt", "sample_output_relpath": "derived/input_output/data/p03486/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03486/Lisp/s471498537.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s471498537", "user_id": "u396817842"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "\n(defun answer (l r)\n (let ((ll (sort l #'char<))\n\t(rr (sort r #'char>)))\n (if (string< ll rr)\n\t\"Yes\"\n\t\"No\")))\n\n(print (answer (read-line) (read-line)))\t", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given strings s and t, consisting of lowercase English letters.\nYou will create a string s' by freely rearranging the characters in s.\nYou will also create a string t' by freely rearranging the characters in t.\nDetermine whether it is possible to satisfy s' < t' for the lexicographic order.\n\nNotes\n\nFor a string a = a_1 a_2 ... a_N of length N and a string b = b_1 b_2 ... b_M of length M, we say a < b for the lexicographic order if either one of the following two conditions holds true:\n\nN < M and a_1 = b_1, a_2 = b_2, ..., a_N = b_N.\n\nThere exists i (1 \\leq i \\leq N, M) such that a_1 = b_1, a_2 = b_2, ..., a_{i - 1} = b_{i - 1} and a_i < b_i. Here, letters are compared using alphabetical order.\n\nFor example, xy < xya and atcoder < atlas.\n\nConstraints\n\nThe lengths of s and t are between 1 and 100 (inclusive).\n\ns and t consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\nt\n\nOutput\n\nIf it is possible to satisfy s' < t', print Yes; if it is not, print No.\n\nSample Input 1\n\nyx\naxy\n\nSample Output 1\n\nYes\n\nWe can, for example, rearrange yx into xy and axy into yxa. Then, xy < yxa.\n\nSample Input 2\n\nratcode\natlas\n\nSample Output 2\n\nYes\n\nWe can, for example, rearrange ratcode into acdeort and atlas into tslaa. Then, acdeort < tslaa.\n\nSample Input 3\n\ncd\nabc\n\nSample Output 3\n\nNo\n\nNo matter how we rearrange cd and abc, we cannot achieve our objective.\n\nSample Input 4\n\nw\nww\n\nSample Output 4\n\nYes\n\nSample Input 5\n\nzzz\nzzz\n\nSample Output 5\n\nNo", "sample_input": "yx\naxy\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03486", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given strings s and t, consisting of lowercase English letters.\nYou will create a string s' by freely rearranging the characters in s.\nYou will also create a string t' by freely rearranging the characters in t.\nDetermine whether it is possible to satisfy s' < t' for the lexicographic order.\n\nNotes\n\nFor a string a = a_1 a_2 ... a_N of length N and a string b = b_1 b_2 ... b_M of length M, we say a < b for the lexicographic order if either one of the following two conditions holds true:\n\nN < M and a_1 = b_1, a_2 = b_2, ..., a_N = b_N.\n\nThere exists i (1 \\leq i \\leq N, M) such that a_1 = b_1, a_2 = b_2, ..., a_{i - 1} = b_{i - 1} and a_i < b_i. Here, letters are compared using alphabetical order.\n\nFor example, xy < xya and atcoder < atlas.\n\nConstraints\n\nThe lengths of s and t are between 1 and 100 (inclusive).\n\ns and t consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\nt\n\nOutput\n\nIf it is possible to satisfy s' < t', print Yes; if it is not, print No.\n\nSample Input 1\n\nyx\naxy\n\nSample Output 1\n\nYes\n\nWe can, for example, rearrange yx into xy and axy into yxa. Then, xy < yxa.\n\nSample Input 2\n\nratcode\natlas\n\nSample Output 2\n\nYes\n\nWe can, for example, rearrange ratcode into acdeort and atlas into tslaa. Then, acdeort < tslaa.\n\nSample Input 3\n\ncd\nabc\n\nSample Output 3\n\nNo\n\nNo matter how we rearrange cd and abc, we cannot achieve our objective.\n\nSample Input 4\n\nw\nww\n\nSample Output 4\n\nYes\n\nSample Input 5\n\nzzz\nzzz\n\nSample Output 5\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 157, "cpu_time_ms": 85, "memory_kb": 8676}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s705444058", "group_id": "codeNet:p03488", "input_text": "(defun tl (d)\n (let ((nd (1+ d)))\n (if (< 3 nd) 0 nd)))\n\n(defun tr (d)\n (let ((nd (1- d)))\n (if (< nd 0) 3 nd)))\n\n(defun move (x y d)\n (case d\n (0 (values (1+ x) y))\n (1 (values x (1- y)))\n (2 (values (1- x) y))\n (3 (values x (1+ y)))))\n\n(defun dfs (s sidx slen gx gy x y d)\n (if (< sidx slen)\n (case (char s sidx)\n (#\\F\n (multiple-value-setq (x y) (move x y d))\n (dfs s (1+ sidx) slen gx gy x y d))\n (#\\T\n (or (dfs s (1+ sidx) slen gx gy x y (tl d))\n (dfs s (1+ sidx) slen gx gy x y (tr d)))))\n (when (and (= gx x)\n (= gy y))\n t)))\n\n(let ((s (read-line))\n (gx (read))\n (gy (read)))\n (format t \"~A~%\"\n (if (dfs s 0 (length s) gx gy 0 0 0)\n \"Yes\" \"No\")))", "language": "Lisp", "metadata": {"date": 1513540053, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03488.html", "problem_id": "p03488", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03488/input.txt", "sample_output_relpath": "derived/input_output/data/p03488/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03488/Lisp/s705444058.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s705444058", "user_id": "u275710783"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun tl (d)\n (let ((nd (1+ d)))\n (if (< 3 nd) 0 nd)))\n\n(defun tr (d)\n (let ((nd (1- d)))\n (if (< nd 0) 3 nd)))\n\n(defun move (x y d)\n (case d\n (0 (values (1+ x) y))\n (1 (values x (1- y)))\n (2 (values (1- x) y))\n (3 (values x (1+ y)))))\n\n(defun dfs (s sidx slen gx gy x y d)\n (if (< sidx slen)\n (case (char s sidx)\n (#\\F\n (multiple-value-setq (x y) (move x y d))\n (dfs s (1+ sidx) slen gx gy x y d))\n (#\\T\n (or (dfs s (1+ sidx) slen gx gy x y (tl d))\n (dfs s (1+ sidx) slen gx gy x y (tr d)))))\n (when (and (= gx x)\n (= gy y))\n t)))\n\n(let ((s (read-line))\n (gx (read))\n (gy (read)))\n (format t \"~A~%\"\n (if (dfs s 0 (length s) gx gy 0 0 0)\n \"Yes\" \"No\")))", "problem_context": "Score : 500 points\n\nProblem Statement\n\nA robot is put at the origin in a two-dimensional plane.\nInitially, the robot is facing in the positive x-axis direction.\n\nThis robot will be given an instruction sequence s.\ns consists of the following two kinds of letters, and will be executed in order from front to back.\n\nF : Move in the current direction by distance 1.\n\nT : Turn 90 degrees, either clockwise or counterclockwise.\n\nThe objective of the robot is to be at coordinates (x, y) after all the instructions are executed.\nDetermine whether this objective is achievable.\n\nConstraints\n\ns consists of F and T.\n\n1 \\leq |s| \\leq 8 000\n\nx and y are integers.\n\n|x|, |y| \\leq |s|\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\nx y\n\nOutput\n\nIf the objective is achievable, print Yes; if it is not, print No.\n\nSample Input 1\n\nFTFFTFFF\n4 2\n\nSample Output 1\n\nYes\n\nThe objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T.\n\nSample Input 2\n\nFTFFTFFF\n-2 -2\n\nSample Output 2\n\nYes\n\nThe objective can be achieved by, for example, turning clockwise in the first T and turning clockwise in the second T.\n\nSample Input 3\n\nFF\n1 0\n\nSample Output 3\n\nNo\n\nSample Input 4\n\nTF\n1 0\n\nSample Output 4\n\nNo\n\nSample Input 5\n\nFFTTFF\n0 0\n\nSample Output 5\n\nYes\n\nThe objective can be achieved by, for example, turning counterclockwise in the first T and turning counterclockwise in the second T.\n\nSample Input 6\n\nTTTT\n1 0\n\nSample Output 6\n\nNo", "sample_input": "FTFFTFFF\n4 2\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03488", "source_text": "Score : 500 points\n\nProblem Statement\n\nA robot is put at the origin in a two-dimensional plane.\nInitially, the robot is facing in the positive x-axis direction.\n\nThis robot will be given an instruction sequence s.\ns consists of the following two kinds of letters, and will be executed in order from front to back.\n\nF : Move in the current direction by distance 1.\n\nT : Turn 90 degrees, either clockwise or counterclockwise.\n\nThe objective of the robot is to be at coordinates (x, y) after all the instructions are executed.\nDetermine whether this objective is achievable.\n\nConstraints\n\ns consists of F and T.\n\n1 \\leq |s| \\leq 8 000\n\nx and y are integers.\n\n|x|, |y| \\leq |s|\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\nx y\n\nOutput\n\nIf the objective is achievable, print Yes; if it is not, print No.\n\nSample Input 1\n\nFTFFTFFF\n4 2\n\nSample Output 1\n\nYes\n\nThe objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T.\n\nSample Input 2\n\nFTFFTFFF\n-2 -2\n\nSample Output 2\n\nYes\n\nThe objective can be achieved by, for example, turning clockwise in the first T and turning clockwise in the second T.\n\nSample Input 3\n\nFF\n1 0\n\nSample Output 3\n\nNo\n\nSample Input 4\n\nTF\n1 0\n\nSample Output 4\n\nNo\n\nSample Input 5\n\nFFTTFF\n0 0\n\nSample Output 5\n\nYes\n\nThe objective can be achieved by, for example, turning counterclockwise in the first T and turning counterclockwise in the second T.\n\nSample Input 6\n\nTTTT\n1 0\n\nSample Output 6\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 791, "cpu_time_ms": 2104, "memory_kb": 7912}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s221048953", "group_id": "codeNet:p03491", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"64MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n;; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Trie\n;;;\n\n;; ASCII code:\n;; #\\A: 65\n;; #\\a: 97\n;; #\\0: 48\n(declaim (inline trie-char-encode))\n(defun trie-char-encode (x)\n (if (char= #\\0 x) 0 1))\n\n(defconstant +trie-alphabet-size+ 2)\n\n;; TODO: enable to set VALUE to NIL by distinguishing null and unbound.\n(declaim (inline %make-trie-node))\n(defstruct (trie-node (:constructor %make-trie-node\n (&optional value\n &aux (children (make-array #.+trie-alphabet-size+\n :element-type t\n :initial-element 0)))))\n (value nil)\n (children nil :type (simple-array t (#.+trie-alphabet-size+))))\n\n(declaim (inline make-trie))\n(defun make-trie () (%make-trie-node))\n\n(declaim (inline trie-add!))\n(defun trie-add! (trie-node string &optional (value t))\n \"Adds STRING to the trie and assigns VALUE to it. Note that null value means\nthe string doesn't exist in the trie: that is, (trie-add! \nnil) virtually works as a deletion of .\"\n (declare (vector string))\n (let ((end (length string)))\n (labels ((recur (node position)\n (if (= position end)\n (unless (trie-node-value node)\n (setf (trie-node-value node) value))\n (let ((children (trie-node-children node))\n (char (trie-char-encode (aref string position))))\n (when (eql 0 (aref children char))\n (setf (aref children char) (%make-trie-node)))\n (recur (aref children char) (+ 1 position))))))\n (recur trie-node 0)\n trie-node)))\n\n(declaim (inline trie-query))\n(defun trie-query (trie-node string function &key (start 0) end)\n \"Calls FUNCTION for each prefix of STRING existing in TRIE-NODE. FUNCTION\ntakes two arguments: the end position and the assigned value.\"\n (declare (vector string)\n ((integer 0 #.most-positive-fixnum) start)\n ((or null (integer 0 #.most-positive-fixnum)) end)\n (function function))\n (let ((end (or end (length string))))\n (labels ((recur (node position)\n (when (trie-node-value node)\n (funcall function position (trie-node-value node)))\n (unless (= position end)\n (let ((children (trie-node-children node))\n (char (trie-char-encode (aref string position))))\n (unless (eql 0 (aref children char))\n (recur (aref children char) (+ 1 position)))))))\n (recur trie-node start))))\n\n(defun trie-get (trie-node string &key (start 0) end)\n \"Finds STRING in TRIE-NODE and returns the assigned value if it exists,\n otherwise NIL.\"\n (declare (vector string)\n ((integer 0 #.most-positive-fixnum) start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (let ((end (or end (length string))))\n (labels ((recur (node position)\n (if (= position end)\n (trie-node-value node)\n (let ((children (trie-node-children node))\n (char (trie-char-encode (aref string position))))\n (unless (eql 0 (aref children char))\n (recur (aref children char) (+ 1 position)))))))\n (recur trie-node start))))\n\n(defun trie-query-longest (trie-node string &key (start 0) end)\n \"Returns the end position and the value of the longest word in TRIE-NODE which\ncoincides with a prefix of STRING. Returns NIL when no such words exist.\"\n (declare (vector string)\n ((integer 0 #.most-positive-fixnum) start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (let ((end (or end (length string)))\n result-position\n result-value)\n (declare ((or null (integer 0 #.most-positive-fixnum)) result-position))\n (labels ((recur (node position)\n (when (trie-node-value node)\n (setq result-position position\n result-value (trie-node-value node)))\n (unless (= position end)\n (let ((children (trie-node-children node))\n (char (trie-char-encode (aref string position))))\n (unless (eql 0 (aref children char))\n (recur (aref children char) (+ 1 position)))))))\n (recur trie-node start)\n (values result-position result-value))))\n\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(declaim (inline grundy))\n(defun grundy (depth max-depth)\n (declare (uint62 depth max-depth))\n (if (= depth max-depth)\n 0\n (let ((x (- max-depth depth))\n (res 1))\n (declare (uint62 x res))\n (loop while (evenp x)\n do (setf res (* res 2))\n (setf x (floor x 2)))\n res)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (l (read))\n (trie (make-trie)))\n (declare (uint62 n l))\n (dotimes (i n)\n (trie-add! trie (the simple-string (read-line))))\n (labels ((dfs (node depth)\n (declare (uint62 depth)\n (values uint62))\n (if (eql 0 node)\n (grundy (- depth 1) l)\n (let ((children (trie-node-children node)))\n (logxor (dfs (aref children 0) (+ depth 1))\n (dfs (aref children 1) (+ depth 1)))))))\n (if (zerop (dfs trie 0))\n (write-line \"Bob\")\n (write-line \"Alice\")))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1564194071, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03491.html", "problem_id": "p03491", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03491/input.txt", "sample_output_relpath": "derived/input_output/data/p03491/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03491/Lisp/s221048953.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s221048953", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Alice\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"64MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n;; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Trie\n;;;\n\n;; ASCII code:\n;; #\\A: 65\n;; #\\a: 97\n;; #\\0: 48\n(declaim (inline trie-char-encode))\n(defun trie-char-encode (x)\n (if (char= #\\0 x) 0 1))\n\n(defconstant +trie-alphabet-size+ 2)\n\n;; TODO: enable to set VALUE to NIL by distinguishing null and unbound.\n(declaim (inline %make-trie-node))\n(defstruct (trie-node (:constructor %make-trie-node\n (&optional value\n &aux (children (make-array #.+trie-alphabet-size+\n :element-type t\n :initial-element 0)))))\n (value nil)\n (children nil :type (simple-array t (#.+trie-alphabet-size+))))\n\n(declaim (inline make-trie))\n(defun make-trie () (%make-trie-node))\n\n(declaim (inline trie-add!))\n(defun trie-add! (trie-node string &optional (value t))\n \"Adds STRING to the trie and assigns VALUE to it. Note that null value means\nthe string doesn't exist in the trie: that is, (trie-add! \nnil) virtually works as a deletion of .\"\n (declare (vector string))\n (let ((end (length string)))\n (labels ((recur (node position)\n (if (= position end)\n (unless (trie-node-value node)\n (setf (trie-node-value node) value))\n (let ((children (trie-node-children node))\n (char (trie-char-encode (aref string position))))\n (when (eql 0 (aref children char))\n (setf (aref children char) (%make-trie-node)))\n (recur (aref children char) (+ 1 position))))))\n (recur trie-node 0)\n trie-node)))\n\n(declaim (inline trie-query))\n(defun trie-query (trie-node string function &key (start 0) end)\n \"Calls FUNCTION for each prefix of STRING existing in TRIE-NODE. FUNCTION\ntakes two arguments: the end position and the assigned value.\"\n (declare (vector string)\n ((integer 0 #.most-positive-fixnum) start)\n ((or null (integer 0 #.most-positive-fixnum)) end)\n (function function))\n (let ((end (or end (length string))))\n (labels ((recur (node position)\n (when (trie-node-value node)\n (funcall function position (trie-node-value node)))\n (unless (= position end)\n (let ((children (trie-node-children node))\n (char (trie-char-encode (aref string position))))\n (unless (eql 0 (aref children char))\n (recur (aref children char) (+ 1 position)))))))\n (recur trie-node start))))\n\n(defun trie-get (trie-node string &key (start 0) end)\n \"Finds STRING in TRIE-NODE and returns the assigned value if it exists,\n otherwise NIL.\"\n (declare (vector string)\n ((integer 0 #.most-positive-fixnum) start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (let ((end (or end (length string))))\n (labels ((recur (node position)\n (if (= position end)\n (trie-node-value node)\n (let ((children (trie-node-children node))\n (char (trie-char-encode (aref string position))))\n (unless (eql 0 (aref children char))\n (recur (aref children char) (+ 1 position)))))))\n (recur trie-node start))))\n\n(defun trie-query-longest (trie-node string &key (start 0) end)\n \"Returns the end position and the value of the longest word in TRIE-NODE which\ncoincides with a prefix of STRING. Returns NIL when no such words exist.\"\n (declare (vector string)\n ((integer 0 #.most-positive-fixnum) start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (let ((end (or end (length string)))\n result-position\n result-value)\n (declare ((or null (integer 0 #.most-positive-fixnum)) result-position))\n (labels ((recur (node position)\n (when (trie-node-value node)\n (setq result-position position\n result-value (trie-node-value node)))\n (unless (= position end)\n (let ((children (trie-node-children node))\n (char (trie-char-encode (aref string position))))\n (unless (eql 0 (aref children char))\n (recur (aref children char) (+ 1 position)))))))\n (recur trie-node start)\n (values result-position result-value))))\n\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(declaim (inline grundy))\n(defun grundy (depth max-depth)\n (declare (uint62 depth max-depth))\n (if (= depth max-depth)\n 0\n (let ((x (- max-depth depth))\n (res 1))\n (declare (uint62 x res))\n (loop while (evenp x)\n do (setf res (* res 2))\n (setf x (floor x 2)))\n res)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (l (read))\n (trie (make-trie)))\n (declare (uint62 n l))\n (dotimes (i n)\n (trie-add! trie (the simple-string (read-line))))\n (labels ((dfs (node depth)\n (declare (uint62 depth)\n (values uint62))\n (if (eql 0 node)\n (grundy (- depth 1) l)\n (let ((children (trie-node-children node)))\n (logxor (dfs (aref children 0) (+ depth 1))\n (dfs (aref children 1) (+ depth 1)))))))\n (if (zerop (dfs trie 0))\n (write-line \"Bob\")\n (write-line \"Alice\")))))\n\n#-swank (main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nFor strings s and t, we will say that s and t are prefix-free when neither is a prefix of the other.\n\nLet L be a positive integer. A set of strings S is a good string set when the following conditions hold true:\n\nEach string in S has a length between 1 and L (inclusive) and consists of the characters 0 and 1.\n\nAny two distinct strings in S are prefix-free.\n\nWe have a good string set S = \\{ s_1, s_2, ..., s_N \\}. Alice and Bob will play a game against each other. They will alternately perform the following operation, starting from Alice:\n\nAdd a new string to S. After addition, S must still be a good string set.\n\nThe first player who becomes unable to perform the operation loses the game. Determine the winner of the game when both players play optimally.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq L \\leq 10^{18}\n\ns_1, s_2, ..., s_N are all distinct.\n\n{ s_1, s_2, ..., s_N } is a good string set.\n\n|s_1| + |s_2| + ... + |s_N| \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN L\ns_1\ns_2\n:\ns_N\n\nOutput\n\nIf Alice will win, print Alice; if Bob will win, print Bob.\n\nSample Input 1\n\n2 2\n00\n01\n\nSample Output 1\n\nAlice\n\nIf Alice adds 1, Bob will be unable to add a new string.\n\nSample Input 2\n\n2 2\n00\n11\n\nSample Output 2\n\nBob\n\nThere are two strings that Alice can add on the first turn: 01 and 10.\nIn case she adds 01, if Bob add 10, she will be unable to add a new string.\nAlso, in case she adds 10, if Bob add 01, she will be unable to add a new string.\n\nSample Input 3\n\n3 3\n0\n10\n110\n\nSample Output 3\n\nAlice\n\nIf Alice adds 111, Bob will be unable to add a new string.\n\nSample Input 4\n\n2 1\n0\n1\n\nSample Output 4\n\nBob\n\nAlice is unable to add a new string on the first turn.\n\nSample Input 5\n\n1 2\n11\n\nSample Output 5\n\nAlice\n\nSample Input 6\n\n2 3\n101\n11\n\nSample Output 6\n\nBob", "sample_input": "2 2\n00\n01\n"}, "reference_outputs": ["Alice\n"], "source_document_id": "p03491", "source_text": "Score : 700 points\n\nProblem Statement\n\nFor strings s and t, we will say that s and t are prefix-free when neither is a prefix of the other.\n\nLet L be a positive integer. A set of strings S is a good string set when the following conditions hold true:\n\nEach string in S has a length between 1 and L (inclusive) and consists of the characters 0 and 1.\n\nAny two distinct strings in S are prefix-free.\n\nWe have a good string set S = \\{ s_1, s_2, ..., s_N \\}. Alice and Bob will play a game against each other. They will alternately perform the following operation, starting from Alice:\n\nAdd a new string to S. After addition, S must still be a good string set.\n\nThe first player who becomes unable to perform the operation loses the game. Determine the winner of the game when both players play optimally.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq L \\leq 10^{18}\n\ns_1, s_2, ..., s_N are all distinct.\n\n{ s_1, s_2, ..., s_N } is a good string set.\n\n|s_1| + |s_2| + ... + |s_N| \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN L\ns_1\ns_2\n:\ns_N\n\nOutput\n\nIf Alice will win, print Alice; if Bob will win, print Bob.\n\nSample Input 1\n\n2 2\n00\n01\n\nSample Output 1\n\nAlice\n\nIf Alice adds 1, Bob will be unable to add a new string.\n\nSample Input 2\n\n2 2\n00\n11\n\nSample Output 2\n\nBob\n\nThere are two strings that Alice can add on the first turn: 01 and 10.\nIn case she adds 01, if Bob add 10, she will be unable to add a new string.\nAlso, in case she adds 10, if Bob add 01, she will be unable to add a new string.\n\nSample Input 3\n\n3 3\n0\n10\n110\n\nSample Output 3\n\nAlice\n\nIf Alice adds 111, Bob will be unable to add a new string.\n\nSample Input 4\n\n2 1\n0\n1\n\nSample Output 4\n\nBob\n\nAlice is unable to add a new string on the first turn.\n\nSample Input 5\n\n1 2\n11\n\nSample Output 5\n\nAlice\n\nSample Input 6\n\n2 3\n101\n11\n\nSample Output 6\n\nBob", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7206, "cpu_time_ms": 95, "memory_kb": 29748}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s482681768", "group_id": "codeNet:p03494", "input_text": "(defun shift-only (n a)\n (let ((res 0)\n\t(exist-odd nil))\n (loop\n ;; (dotimes (i n)\n ;; \t(if (not (zerop (rem (aref a i) 2)))\n ;; \t (setf exist-odd t)))\n (if (oddp (apply #'+ a;; (coerce temp 'list)\n\t\t ))\n\t (setf exist-odd t))\n (if (eq exist-odd t) (return))\n (dotimes (i n)\n\t;; (setf (aref a i) (/ (aref a i) 2))\n\t((setf (nth i a) (/ (nth i a) 2))))\n (incf res))\n res))\n\n(defun create-data ()\n (let* ((n (read))\n\t (a ;; (make-array `(,n)) \n\t (loop for i to (- n 1) collect i)))\n (dotimes (i n)\n ;; (setf (aref a i) (read))\n (setf (nth i a) (read)))\n (values n a)))\n;; (create-data)\n\n(multiple-value-bind (n a) (create-data)\n (format t \"~a~%\" (shift-only n a)))", "language": "Lisp", "metadata": {"date": 1556077015, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03494.html", "problem_id": "p03494", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03494/input.txt", "sample_output_relpath": "derived/input_output/data/p03494/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03494/Lisp/s482681768.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s482681768", "user_id": "u839737417"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun shift-only (n a)\n (let ((res 0)\n\t(exist-odd nil))\n (loop\n ;; (dotimes (i n)\n ;; \t(if (not (zerop (rem (aref a i) 2)))\n ;; \t (setf exist-odd t)))\n (if (oddp (apply #'+ a;; (coerce temp 'list)\n\t\t ))\n\t (setf exist-odd t))\n (if (eq exist-odd t) (return))\n (dotimes (i n)\n\t;; (setf (aref a i) (/ (aref a i) 2))\n\t((setf (nth i a) (/ (nth i a) 2))))\n (incf res))\n res))\n\n(defun create-data ()\n (let* ((n (read))\n\t (a ;; (make-array `(,n)) \n\t (loop for i to (- n 1) collect i)))\n (dotimes (i n)\n ;; (setf (aref a i) (read))\n (setf (nth i a) (read)))\n (values n a)))\n;; (create-data)\n\n(multiple-value-bind (n a) (create-data)\n (format t \"~a~%\" (shift-only n a)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N positive integers written on a blackboard: A_1, ..., A_N.\n\nSnuke can perform the following operation when all integers on the blackboard are even:\n\nReplace each integer X on the blackboard by X divided by 2.\n\nFind the maximum possible number of operations that Snuke can perform.\n\nConstraints\n\n1 \\leq N \\leq 200\n\n1 \\leq A_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible number of operations that Snuke can perform.\n\nSample Input 1\n\n3\n8 12 40\n\nSample Output 1\n\n2\n\nInitially, [8, 12, 40] are written on the blackboard.\nSince all those integers are even, Snuke can perform the operation.\n\nAfter the operation is performed once, [4, 6, 20] are written on the blackboard.\nSince all those integers are again even, he can perform the operation.\n\nAfter the operation is performed twice, [2, 3, 10] are written on the blackboard.\nNow, there is an odd number 3 on the blackboard, so he cannot perform the operation any more.\n\nThus, Snuke can perform the operation at most twice.\n\nSample Input 2\n\n4\n5 6 8 10\n\nSample Output 2\n\n0\n\nSince there is an odd number 5 on the blackboard already in the beginning, Snuke cannot perform the operation at all.\n\nSample Input 3\n\n6\n382253568 723152896 37802240 379425024 404894720 471526144\n\nSample Output 3\n\n8", "sample_input": "3\n8 12 40\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03494", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N positive integers written on a blackboard: A_1, ..., A_N.\n\nSnuke can perform the following operation when all integers on the blackboard are even:\n\nReplace each integer X on the blackboard by X divided by 2.\n\nFind the maximum possible number of operations that Snuke can perform.\n\nConstraints\n\n1 \\leq N \\leq 200\n\n1 \\leq A_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible number of operations that Snuke can perform.\n\nSample Input 1\n\n3\n8 12 40\n\nSample Output 1\n\n2\n\nInitially, [8, 12, 40] are written on the blackboard.\nSince all those integers are even, Snuke can perform the operation.\n\nAfter the operation is performed once, [4, 6, 20] are written on the blackboard.\nSince all those integers are again even, he can perform the operation.\n\nAfter the operation is performed twice, [2, 3, 10] are written on the blackboard.\nNow, there is an odd number 3 on the blackboard, so he cannot perform the operation any more.\n\nThus, Snuke can perform the operation at most twice.\n\nSample Input 2\n\n4\n5 6 8 10\n\nSample Output 2\n\n0\n\nSince there is an odd number 5 on the blackboard already in the beginning, Snuke cannot perform the operation at all.\n\nSample Input 3\n\n6\n382253568 723152896 37802240 379425024 404894720 471526144\n\nSample Output 3\n\n8", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 732, "cpu_time_ms": 166, "memory_kb": 16100}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s983850543", "group_id": "codeNet:p03494", "input_text": "(defun odd-helper (n)\n (find-if #'oddp n))\n\n(defun zero-helper (n)\n (find-if #'zerop n))\n\n(defun main (&rest n)\n (shiftonly 0 n))\n\n(defun shiftonly (ans lis)\n (if (odd-helper lis)\n (format t \"~a~%\" ans)\n (if (zero-helper lis)\n (format t \"~a~%\" ans)\n (shiftonly (+ 1 ans) (mapcar #'(lambda (x) (/ x 2)) lis)))))\n\n(read)\n(main (read))\n", "language": "Lisp", "metadata": {"date": 1555047557, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03494.html", "problem_id": "p03494", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03494/input.txt", "sample_output_relpath": "derived/input_output/data/p03494/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03494/Lisp/s983850543.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s983850543", "user_id": "u418126641"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun odd-helper (n)\n (find-if #'oddp n))\n\n(defun zero-helper (n)\n (find-if #'zerop n))\n\n(defun main (&rest n)\n (shiftonly 0 n))\n\n(defun shiftonly (ans lis)\n (if (odd-helper lis)\n (format t \"~a~%\" ans)\n (if (zero-helper lis)\n (format t \"~a~%\" ans)\n (shiftonly (+ 1 ans) (mapcar #'(lambda (x) (/ x 2)) lis)))))\n\n(read)\n(main (read))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N positive integers written on a blackboard: A_1, ..., A_N.\n\nSnuke can perform the following operation when all integers on the blackboard are even:\n\nReplace each integer X on the blackboard by X divided by 2.\n\nFind the maximum possible number of operations that Snuke can perform.\n\nConstraints\n\n1 \\leq N \\leq 200\n\n1 \\leq A_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible number of operations that Snuke can perform.\n\nSample Input 1\n\n3\n8 12 40\n\nSample Output 1\n\n2\n\nInitially, [8, 12, 40] are written on the blackboard.\nSince all those integers are even, Snuke can perform the operation.\n\nAfter the operation is performed once, [4, 6, 20] are written on the blackboard.\nSince all those integers are again even, he can perform the operation.\n\nAfter the operation is performed twice, [2, 3, 10] are written on the blackboard.\nNow, there is an odd number 3 on the blackboard, so he cannot perform the operation any more.\n\nThus, Snuke can perform the operation at most twice.\n\nSample Input 2\n\n4\n5 6 8 10\n\nSample Output 2\n\n0\n\nSince there is an odd number 5 on the blackboard already in the beginning, Snuke cannot perform the operation at all.\n\nSample Input 3\n\n6\n382253568 723152896 37802240 379425024 404894720 471526144\n\nSample Output 3\n\n8", "sample_input": "3\n8 12 40\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03494", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N positive integers written on a blackboard: A_1, ..., A_N.\n\nSnuke can perform the following operation when all integers on the blackboard are even:\n\nReplace each integer X on the blackboard by X divided by 2.\n\nFind the maximum possible number of operations that Snuke can perform.\n\nConstraints\n\n1 \\leq N \\leq 200\n\n1 \\leq A_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible number of operations that Snuke can perform.\n\nSample Input 1\n\n3\n8 12 40\n\nSample Output 1\n\n2\n\nInitially, [8, 12, 40] are written on the blackboard.\nSince all those integers are even, Snuke can perform the operation.\n\nAfter the operation is performed once, [4, 6, 20] are written on the blackboard.\nSince all those integers are again even, he can perform the operation.\n\nAfter the operation is performed twice, [2, 3, 10] are written on the blackboard.\nNow, there is an odd number 3 on the blackboard, so he cannot perform the operation any more.\n\nThus, Snuke can perform the operation at most twice.\n\nSample Input 2\n\n4\n5 6 8 10\n\nSample Output 2\n\n0\n\nSince there is an odd number 5 on the blackboard already in the beginning, Snuke cannot perform the operation at all.\n\nSample Input 3\n\n6\n382253568 723152896 37802240 379425024 404894720 471526144\n\nSample Output 3\n\n8", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 365, "cpu_time_ms": 18, "memory_kb": 4328}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s370934350", "group_id": "codeNet:p03495", "input_text": "\n(defun group-and-rest (lst k)\n (cond\n ((null lst) lst)\n ((= 0 k) lst)\n ((not (equal (first lst) (second lst)))\n (group-and-rest (cdr lst) (1- k)))\n (t\n (group-and-rest (cdr lst) k))))\n\n(defun read-input (N)\n (sort (loop for n from 1 upto N collect (read))\n #'<))\n\n(defun main ()\n (let ((N (read)) (K (read)))\n (format t \"~a~%\"\n (length (group-and-rest (read-input N) K)))))\n(main)", "language": "Lisp", "metadata": {"date": 1513022646, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03495.html", "problem_id": "p03495", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03495/input.txt", "sample_output_relpath": "derived/input_output/data/p03495/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03495/Lisp/s370934350.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s370934350", "user_id": "u396817842"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "\n(defun group-and-rest (lst k)\n (cond\n ((null lst) lst)\n ((= 0 k) lst)\n ((not (equal (first lst) (second lst)))\n (group-and-rest (cdr lst) (1- k)))\n (t\n (group-and-rest (cdr lst) k))))\n\n(defun read-input (N)\n (sort (loop for n from 1 upto N collect (read))\n #'<))\n\n(defun main ()\n (let ((N (read)) (K (read)))\n (format t \"~a~%\"\n (length (group-and-rest (read-input N) K)))))\n(main)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi has N balls. Initially, an integer A_i is written on the i-th ball.\n\nHe would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.\n\nFind the minimum number of balls that Takahashi needs to rewrite the integers on them.\n\nConstraints\n\n1 \\leq K \\leq N \\leq 200000\n\n1 \\leq A_i \\leq N\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum number of balls that Takahashi needs to rewrite the integers on them.\n\nSample Input 1\n\n5 2\n1 1 2 2 5\n\nSample Output 1\n\n1\n\nFor example, if we rewrite the integer on the fifth ball to 2, there are two different integers written on the balls: 1 and 2.\nOn the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1.\n\nSample Input 2\n\n4 4\n1 1 2 2\n\nSample Output 2\n\n0\n\nAlready in the beginning, there are two different integers written on the balls, so we do not need to rewrite anything.\n\nSample Input 3\n\n10 3\n5 1 3 2 4 1 1 2 3 4\n\nSample Output 3\n\n3", "sample_input": "5 2\n1 1 2 2 5\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03495", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi has N balls. Initially, an integer A_i is written on the i-th ball.\n\nHe would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.\n\nFind the minimum number of balls that Takahashi needs to rewrite the integers on them.\n\nConstraints\n\n1 \\leq K \\leq N \\leq 200000\n\n1 \\leq A_i \\leq N\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum number of balls that Takahashi needs to rewrite the integers on them.\n\nSample Input 1\n\n5 2\n1 1 2 2 5\n\nSample Output 1\n\n1\n\nFor example, if we rewrite the integer on the fifth ball to 2, there are two different integers written on the balls: 1 and 2.\nOn the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1.\n\nSample Input 2\n\n4 4\n1 1 2 2\n\nSample Output 2\n\n0\n\nAlready in the beginning, there are two different integers written on the balls, so we do not need to rewrite anything.\n\nSample Input 3\n\n10 3\n5 1 3 2 4 1 1 2 3 4\n\nSample Output 3\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 425, "cpu_time_ms": 778, "memory_kb": 59752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s657473029", "group_id": "codeNet:p03497", "input_text": "(let ((n (read))\n (k (read))\n (a (make-array 200000))\n (ans 0))\n (loop for i below n do\n (incf (aref a (read)))\n )\n (setf a (delete-if (lambda (x) (= x 0)) a))\n (sort a '<)\n (if (> (- (length a) k) 0)\n (setq ans (loop for i across (subseq a 0 (- (length a) k)) sum i))\n )\n (format t \"~d~%\" ans)\n)", "language": "Lisp", "metadata": {"date": 1601313861, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03497.html", "problem_id": "p03497", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03497/input.txt", "sample_output_relpath": "derived/input_output/data/p03497/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03497/Lisp/s657473029.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s657473029", "user_id": "u136500538"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let ((n (read))\n (k (read))\n (a (make-array 200000))\n (ans 0))\n (loop for i below n do\n (incf (aref a (read)))\n )\n (setf a (delete-if (lambda (x) (= x 0)) a))\n (sort a '<)\n (if (> (- (length a) k) 0)\n (setq ans (loop for i across (subseq a 0 (- (length a) k)) sum i))\n )\n (format t \"~d~%\" ans)\n)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi has N balls. Initially, an integer A_i is written on the i-th ball.\n\nHe would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.\n\nFind the minimum number of balls that Takahashi needs to rewrite the integers on them.\n\nConstraints\n\n1 \\leq K \\leq N \\leq 200000\n\n1 \\leq A_i \\leq N\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum number of balls that Takahashi needs to rewrite the integers on them.\n\nSample Input 1\n\n5 2\n1 1 2 2 5\n\nSample Output 1\n\n1\n\nFor example, if we rewrite the integer on the fifth ball to 2, there are two different integers written on the balls: 1 and 2.\nOn the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1.\n\nSample Input 2\n\n4 4\n1 1 2 2\n\nSample Output 2\n\n0\n\nAlready in the beginning, there are two different integers written on the balls, so we do not need to rewrite anything.\n\nSample Input 3\n\n10 3\n5 1 3 2 4 1 1 2 3 4\n\nSample Output 3\n\n3", "sample_input": "5 2\n1 1 2 2 5\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03497", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi has N balls. Initially, an integer A_i is written on the i-th ball.\n\nHe would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.\n\nFind the minimum number of balls that Takahashi needs to rewrite the integers on them.\n\nConstraints\n\n1 \\leq K \\leq N \\leq 200000\n\n1 \\leq A_i \\leq N\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum number of balls that Takahashi needs to rewrite the integers on them.\n\nSample Input 1\n\n5 2\n1 1 2 2 5\n\nSample Output 1\n\n1\n\nFor example, if we rewrite the integer on the fifth ball to 2, there are two different integers written on the balls: 1 and 2.\nOn the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1.\n\nSample Input 2\n\n4 4\n1 1 2 2\n\nSample Output 2\n\n0\n\nAlready in the beginning, there are two different integers written on the balls, so we do not need to rewrite anything.\n\nSample Input 3\n\n10 3\n5 1 3 2 4 1 1 2 3 4\n\nSample Output 3\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 340, "cpu_time_ms": 211, "memory_kb": 78468}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s924525064", "group_id": "codeNet:p03501", "input_text": "(let ((n (read))\n (a (read))\n (b (read)))\n (format t \"~A~%\"\n (min (* n a)\n b)))", "language": "Lisp", "metadata": {"date": 1512353604, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03501.html", "problem_id": "p03501", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03501/input.txt", "sample_output_relpath": "derived/input_output/data/p03501/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03501/Lisp/s924525064.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s924525064", "user_id": "u275710783"}, "prompt_components": {"gold_output": "119\n", "input_to_evaluate": "(let ((n (read))\n (a (read))\n (b (read)))\n (format t \"~A~%\"\n (min (* n a)\n b)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are parking at a parking lot. You can choose from the following two fee plans:\n\nPlan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours.\n\nPlan 2: The fee will be B yen, regardless of the duration.\n\nFind the minimum fee when you park for N hours.\n\nConstraints\n\n1≤N≤20\n\n1≤A≤100\n\n1≤B≤2000\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nWhen the minimum fee is x yen, print the value of x.\n\nSample Input 1\n\n7 17 120\n\nSample Output 1\n\n119\n\nIf you choose Plan 1, the fee will be 7×17=119 yen.\n\nIf you choose Plan 2, the fee will be 120 yen.\n\nThus, the minimum fee is 119 yen.\n\nSample Input 2\n\n5 20 100\n\nSample Output 2\n\n100\n\nThe fee might be the same in the two plans.\n\nSample Input 3\n\n6 18 100\n\nSample Output 3\n\n100", "sample_input": "7 17 120\n"}, "reference_outputs": ["119\n"], "source_document_id": "p03501", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are parking at a parking lot. You can choose from the following two fee plans:\n\nPlan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours.\n\nPlan 2: The fee will be B yen, regardless of the duration.\n\nFind the minimum fee when you park for N hours.\n\nConstraints\n\n1≤N≤20\n\n1≤A≤100\n\n1≤B≤2000\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\n\nOutput\n\nWhen the minimum fee is x yen, print the value of x.\n\nSample Input 1\n\n7 17 120\n\nSample Output 1\n\n119\n\nIf you choose Plan 1, the fee will be 7×17=119 yen.\n\nIf you choose Plan 2, the fee will be 120 yen.\n\nThus, the minimum fee is 119 yen.\n\nSample Input 2\n\n5 20 100\n\nSample Output 2\n\n100\n\nThe fee might be the same in the two plans.\n\nSample Input 3\n\n6 18 100\n\nSample Output 3\n\n100", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 113, "cpu_time_ms": 403, "memory_kb": 12136}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s733012986", "group_id": "codeNet:p03502", "input_text": "(let* ((n (read-line))\n (fx (loop for ch across n sum (- (char-code ch) (char-code #\\0)))))\n (if (= 0 (mod (parse-integer n) fx))\n (format t \"Yes~%\")\n (format t \"No~%\")))", "language": "Lisp", "metadata": {"date": 1512355173, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03502.html", "problem_id": "p03502", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03502/input.txt", "sample_output_relpath": "derived/input_output/data/p03502/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03502/Lisp/s733012986.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s733012986", "user_id": "u275710783"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let* ((n (read-line))\n (fx (loop for ch across n sum (- (char-code ch) (char-code #\\0)))))\n (if (= 0 (mod (parse-integer n) fx))\n (format t \"Yes~%\")\n (format t \"No~%\")))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nAn integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10.\n\nGiven an integer N, determine whether it is a Harshad number.\n\nConstraints\n\n1?N?10^8\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint Yes if N is a Harshad number; print No otherwise.\n\nSample Input 1\n\n12\n\nSample Output 1\n\nYes\n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\nSample Input 2\n\n57\n\nSample Output 2\n\nNo\n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\nSample Input 3\n\n148\n\nSample Output 3\n\nNo", "sample_input": "12\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03502", "source_text": "Score : 200 points\n\nProblem Statement\n\nAn integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10.\n\nGiven an integer N, determine whether it is a Harshad number.\n\nConstraints\n\n1?N?10^8\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint Yes if N is a Harshad number; print No otherwise.\n\nSample Input 1\n\n12\n\nSample Output 1\n\nYes\n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\nSample Input 2\n\n57\n\nSample Output 2\n\nNo\n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\nSample Input 3\n\n148\n\nSample Output 3\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 187, "cpu_time_ms": 407, "memory_kb": 14564}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s114280420", "group_id": "codeNet:p03502", "input_text": "(let* ((n (read-line))\n (fx (loop for ch across n sum (- (char-code ch) (char-code #\\0)))))\n (if (= 0 (mod (parse-integer n) fx))\n (format t \"Yes~%\")\n (format t \"NO~&\")))", "language": "Lisp", "metadata": {"date": 1512353772, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03502.html", "problem_id": "p03502", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03502/input.txt", "sample_output_relpath": "derived/input_output/data/p03502/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03502/Lisp/s114280420.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s114280420", "user_id": "u275710783"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let* ((n (read-line))\n (fx (loop for ch across n sum (- (char-code ch) (char-code #\\0)))))\n (if (= 0 (mod (parse-integer n) fx))\n (format t \"Yes~%\")\n (format t \"NO~&\")))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nAn integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10.\n\nGiven an integer N, determine whether it is a Harshad number.\n\nConstraints\n\n1?N?10^8\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint Yes if N is a Harshad number; print No otherwise.\n\nSample Input 1\n\n12\n\nSample Output 1\n\nYes\n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\nSample Input 2\n\n57\n\nSample Output 2\n\nNo\n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\nSample Input 3\n\n148\n\nSample Output 3\n\nNo", "sample_input": "12\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03502", "source_text": "Score : 200 points\n\nProblem Statement\n\nAn integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10.\n\nGiven an integer N, determine whether it is a Harshad number.\n\nConstraints\n\n1?N?10^8\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint Yes if N is a Harshad number; print No otherwise.\n\nSample Input 1\n\n12\n\nSample Output 1\n\nYes\n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\nSample Input 2\n\n57\n\nSample Output 2\n\nNo\n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\nSample Input 3\n\n148\n\nSample Output 3\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 187, "cpu_time_ms": 544, "memory_kb": 14564}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s809887143", "group_id": "codeNet:p03503", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (fs (make-array (list n 10) :element-type 'bit :initial-element 0))\n (ps (make-array (list n 11) :element-type 'int32 :initial-element 0)))\n (dotimes (i n)\n (dotimes (j 10)\n (setf (aref fs i j) (read))))\n (dotimes (i n)\n (dotimes (j 11)\n (setf (aref ps i j) (read))))\n (println\n (loop\n for bits from 1 below (expt 2 10)\n maximize (loop for i below n\n for cumul = (loop\n for j below 10\n sum (logand (aref fs i j)\n (ldb (byte 1 j) bits)))\n sum (aref ps i cumul))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n1 1 0 1 0 0 0 1 0 1\n3 4 5 6 7 8 9 -2 -3 4 -2\n\"\n \"8\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 1 1 1 1 0 0 0 0 0\n0 0 0 0 0 1 1 1 1 1\n0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1\n0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1\n\"\n \"-2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 1 1 1 1 1 0 0 1 1\n0 1 0 1 1 1 1 0 1 0\n1 0 1 1 0 1 0 1 0 1\n-8 6 -2 -8 -8 4 8 7 -6 2 2\n-9 2 0 1 7 -5 0 -2 -6 5 5\n6 -6 7 -9 6 -5 8 0 -9 -7 -7\n\"\n \"23\n\")))\n", "language": "Lisp", "metadata": {"date": 1577704069, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03503.html", "problem_id": "p03503", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03503/input.txt", "sample_output_relpath": "derived/input_output/data/p03503/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03503/Lisp/s809887143.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s809887143", "user_id": "u352600849"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (fs (make-array (list n 10) :element-type 'bit :initial-element 0))\n (ps (make-array (list n 11) :element-type 'int32 :initial-element 0)))\n (dotimes (i n)\n (dotimes (j 10)\n (setf (aref fs i j) (read))))\n (dotimes (i n)\n (dotimes (j 11)\n (setf (aref ps i j) (read))))\n (println\n (loop\n for bits from 1 below (expt 2 10)\n maximize (loop for i below n\n for cumul = (loop\n for j below 10\n sum (logand (aref fs i j)\n (ldb (byte 1 j) bits)))\n sum (aref ps i cumul))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n1 1 0 1 0 0 0 1 0 1\n3 4 5 6 7 8 9 -2 -3 4 -2\n\"\n \"8\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 1 1 1 1 0 0 0 0 0\n0 0 0 0 0 1 1 1 1 1\n0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1\n0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1\n\"\n \"-2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 1 1 1 1 1 0 0 1 1\n0 1 0 1 1 1 1 0 1 0\n1 0 1 1 0 1 0 1 0 1\n-8 6 -2 -8 -8 4 8 7 -6 2 2\n-9 2 0 1 7 -5 0 -2 -6 5 5\n6 -6 7 -9 6 -5 8 0 -9 -7 -7\n\"\n \"23\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nJoisino is planning to open a shop in a shopping street.\n\nEach of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods.\n\nThere are already N stores in the street, numbered 1 through N.\n\nYou are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2.\n\nLet c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}.\n\nFind the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.\n\nConstraints\n\n1≤N≤100\n\n0≤F_{i,j,k}≤1\n\nFor every integer i such that 1≤i≤N, there exists at least one pair (j,k) such that F_{i,j,k}=1.\n\n-10^7≤P_{i,j}≤10^7\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nF_{1,1,1} F_{1,1,2} ... F_{1,5,1} F_{1,5,2}\n:\nF_{N,1,1} F_{N,1,2} ... F_{N,5,1} F_{N,5,2}\nP_{1,0} ... P_{1,10}\n:\nP_{N,0} ... P_{N,10}\n\nOutput\n\nPrint the maximum possible profit of Joisino's shop.\n\nSample Input 1\n\n1\n1 1 0 1 0 0 0 1 0 1\n3 4 5 6 7 8 9 -2 -3 4 -2\n\nSample Output 1\n\n8\n\nIf her shop is open only during the periods when Shop 1 is opened, the profit will be 8, which is the maximum possible profit.\n\nSample Input 2\n\n2\n1 1 1 1 1 0 0 0 0 0\n0 0 0 0 0 1 1 1 1 1\n0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1\n0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1\n\nSample Output 2\n\n-2\n\nNote that a shop must be open during at least one period, and the profit may be negative.\n\nSample Input 3\n\n3\n1 1 1 1 1 1 0 0 1 1\n0 1 0 1 1 1 1 0 1 0\n1 0 1 1 0 1 0 1 0 1\n-8 6 -2 -8 -8 4 8 7 -6 2 2\n-9 2 0 1 7 -5 0 -2 -6 5 5\n6 -6 7 -9 6 -5 8 0 -9 -7 -7\n\nSample Output 3\n\n23", "sample_input": "1\n1 1 0 1 0 0 0 1 0 1\n3 4 5 6 7 8 9 -2 -3 4 -2\n"}, "reference_outputs": ["8\n"], "source_document_id": "p03503", "source_text": "Score : 300 points\n\nProblem Statement\n\nJoisino is planning to open a shop in a shopping street.\n\nEach of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods.\n\nThere are already N stores in the street, numbered 1 through N.\n\nYou are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2.\n\nLet c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}.\n\nFind the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.\n\nConstraints\n\n1≤N≤100\n\n0≤F_{i,j,k}≤1\n\nFor every integer i such that 1≤i≤N, there exists at least one pair (j,k) such that F_{i,j,k}=1.\n\n-10^7≤P_{i,j}≤10^7\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nF_{1,1,1} F_{1,1,2} ... F_{1,5,1} F_{1,5,2}\n:\nF_{N,1,1} F_{N,1,2} ... F_{N,5,1} F_{N,5,2}\nP_{1,0} ... P_{1,10}\n:\nP_{N,0} ... P_{N,10}\n\nOutput\n\nPrint the maximum possible profit of Joisino's shop.\n\nSample Input 1\n\n1\n1 1 0 1 0 0 0 1 0 1\n3 4 5 6 7 8 9 -2 -3 4 -2\n\nSample Output 1\n\n8\n\nIf her shop is open only during the periods when Shop 1 is opened, the profit will be 8, which is the maximum possible profit.\n\nSample Input 2\n\n2\n1 1 1 1 1 0 0 0 0 0\n0 0 0 0 0 1 1 1 1 1\n0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1\n0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1\n\nSample Output 2\n\n-2\n\nNote that a shop must be open during at least one period, and the profit may be negative.\n\nSample Input 3\n\n3\n1 1 1 1 1 1 0 0 1 1\n0 1 0 1 1 1 1 0 1 0\n1 0 1 1 0 1 0 1 0 1\n-8 6 -2 -8 -8 4 8 7 -6 2 2\n-9 2 0 1 7 -5 0 -2 -6 5 5\n6 -6 7 -9 6 -5 8 0 -9 -7 -7\n\nSample Output 3\n\n23", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4730, "cpu_time_ms": 61, "memory_kb": 13156}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s574037104", "group_id": "codeNet:p03504", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (c (read))\n (timeline (make-array 100002 :element-type 'int32 :initial-element 0)))\n (declare (uint32 n) (ignore c))\n (dotimes (i n)\n (let ((begin (read-fixnum))\n (end (+ (read-fixnum) 1))\n (channel (read-fixnum)))\n (declare (ignore channel))\n (incf (aref timeline begin))\n (decf (aref timeline end))))\n (dotimes (i 100001)\n (incf (aref timeline (+ i 1)) (aref timeline i)))\n (println (reduce #'max timeline))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1558413661, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03504.html", "problem_id": "p03504", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03504/input.txt", "sample_output_relpath": "derived/input_output/data/p03504/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03504/Lisp/s574037104.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s574037104", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (c (read))\n (timeline (make-array 100002 :element-type 'int32 :initial-element 0)))\n (declare (uint32 n) (ignore c))\n (dotimes (i n)\n (let ((begin (read-fixnum))\n (end (+ (read-fixnum) 1))\n (channel (read-fixnum)))\n (declare (ignore channel))\n (incf (aref timeline begin))\n (decf (aref timeline end))))\n (dotimes (i 100001)\n (incf (aref timeline (+ i 1)) (aref timeline i)))\n (println (reduce #'max timeline))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nJoisino is planning to record N TV programs with recorders.\n\nThe TV can receive C channels numbered 1 through C.\n\nThe i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i.\n\nHere, there will never be more than one program that are broadcast on the same channel at the same time.\n\nWhen the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T).\n\nFind the minimum number of recorders required to record the channels so that all the N programs are completely recorded.\n\nConstraints\n\n1≤N≤10^5\n\n1≤C≤30\n\n1≤s_i (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (map 'list #'digit-char-p (read-line))))\n (sb-int:named-let recur ((rest (cdr n)) (sum (car n)) (res (list (car n))))\n (if (null rest)\n (when (= sum 7)\n (map () #'princ (reverse res))\n (write-line \"=7\")\n (return-from main))\n (progn\n (recur (cdr rest) (+ sum (car rest)) `(,(car rest) #\\+ ,@res))\n (recur (cdr rest) (- sum (car rest)) `(,(car rest) #\\- ,@res)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1222\n\"\n \"1+2+2+2=7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"0290\n\"\n \"0-2+9+0=7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3242\n\"\n \"3+2+4-2=7\n\")))\n", "language": "Lisp", "metadata": {"date": 1587019153, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03545.html", "problem_id": "p03545", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03545/input.txt", "sample_output_relpath": "derived/input_output/data/p03545/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03545/Lisp/s356813131.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s356813131", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1+2+2+2=7\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (map 'list #'digit-char-p (read-line))))\n (sb-int:named-let recur ((rest (cdr n)) (sum (car n)) (res (list (car n))))\n (if (null rest)\n (when (= sum 7)\n (map () #'princ (reverse res))\n (write-line \"=7\")\n (return-from main))\n (progn\n (recur (cdr rest) (+ sum (car rest)) `(,(car rest) #\\+ ,@res))\n (recur (cdr rest) (- sum (car rest)) `(,(car rest) #\\- ,@res)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1222\n\"\n \"1+2+2+2=7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"0290\n\"\n \"0-2+9+0=7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3242\n\"\n \"3+2+4-2=7\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSitting in a station waiting room, Joisino is gazing at her train ticket.\n\nThe ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive).\n\nIn the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with + or - so that the formula holds.\n\nThe given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.\n\nConstraints\n\n0≤A,B,C,D≤9\n\nAll input values are integers.\n\nIt is guaranteed that there is a solution.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nABCD\n\nOutput\n\nPrint the formula you made, including the part =7.\n\nUse the signs + and -.\n\nDo not print a space between a digit and a sign.\n\nSample Input 1\n\n1222\n\nSample Output 1\n\n1+2+2+2=7\n\nThis is the only valid solution.\n\nSample Input 2\n\n0290\n\nSample Output 2\n\n0-2+9+0=7\n\n0 - 2 + 9 - 0 = 7 is also a valid solution.\n\nSample Input 3\n\n3242\n\nSample Output 3\n\n3+2+4-2=7", "sample_input": "1222\n"}, "reference_outputs": ["1+2+2+2=7\n"], "source_document_id": "p03545", "source_text": "Score : 300 points\n\nProblem Statement\n\nSitting in a station waiting room, Joisino is gazing at her train ticket.\n\nThe ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive).\n\nIn the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with + or - so that the formula holds.\n\nThe given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.\n\nConstraints\n\n0≤A,B,C,D≤9\n\nAll input values are integers.\n\nIt is guaranteed that there is a solution.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nABCD\n\nOutput\n\nPrint the formula you made, including the part =7.\n\nUse the signs + and -.\n\nDo not print a space between a digit and a sign.\n\nSample Input 1\n\n1222\n\nSample Output 1\n\n1+2+2+2=7\n\nThis is the only valid solution.\n\nSample Input 2\n\n0290\n\nSample Output 2\n\n0-2+9+0=7\n\n0 - 2 + 9 - 0 = 7 is also a valid solution.\n\nSample Input 3\n\n3242\n\nSample Output 3\n\n3+2+4-2=7", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4082, "cpu_time_ms": 25, "memory_kb": 6504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s778052995", "group_id": "codeNet:p03546", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #\\Newline))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (setf (schar ,buffer ,idx) ,terminate-char)\n (return (values ,buffer ,idx))))))\n\n(declaim (inline split-integers-into-array))\n(defun split-integers-into-array (string dest-array row &key (offset 0))\n (declare (string string)\n ((simple-array * (* *)) dest-array)\n ((integer 0 #.most-positive-fixnum) row offset))\n (loop for idx from offset below (array-dimension dest-array 1)\n for pos1 = 0 then (1+ pos2)\n for pos2 = (position #\\space string :start pos1 :test #'char=)\n do (setf (aref dest-array row idx)\n (parse-integer string :start pos1 :end pos2))\n finally (return dest-array)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(defun main ()\n (let* ((h (read))\n (w (read))\n (costs (make-array '(10 10) :element-type 'uint16))\n (wall (make-array (list h w) :element-type 'int16)))\n (dotimes (i 10)\n (split-integers-into-array (buffered-read-line 80) costs i))\n (dotimes (i h)\n (split-integers-into-array (buffered-read-line 800) wall i))\n (dotimes (k 10)\n (dotimes (i 10)\n (dotimes (j 10)\n (when (> (aref costs i j) (+ (aref costs i k) (aref costs k j)))\n (setf (aref costs i j) (+ (aref costs i k) (aref costs k j)))))))\n (println\n (loop for i below h\n sum (loop for j below w\n sum (if (= -1 (aref wall i j))\n 0\n (aref costs (aref wall i j) 1)))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1547712868, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03546.html", "problem_id": "p03546", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03546/input.txt", "sample_output_relpath": "derived/input_output/data/p03546/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03546/Lisp/s778052995.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s778052995", "user_id": "u352600849"}, "prompt_components": {"gold_output": "12\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #\\Newline))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (setf (schar ,buffer ,idx) ,terminate-char)\n (return (values ,buffer ,idx))))))\n\n(declaim (inline split-integers-into-array))\n(defun split-integers-into-array (string dest-array row &key (offset 0))\n (declare (string string)\n ((simple-array * (* *)) dest-array)\n ((integer 0 #.most-positive-fixnum) row offset))\n (loop for idx from offset below (array-dimension dest-array 1)\n for pos1 = 0 then (1+ pos2)\n for pos2 = (position #\\space string :start pos1 :test #'char=)\n do (setf (aref dest-array row idx)\n (parse-integer string :start pos1 :end pos2))\n finally (return dest-array)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(defun main ()\n (let* ((h (read))\n (w (read))\n (costs (make-array '(10 10) :element-type 'uint16))\n (wall (make-array (list h w) :element-type 'int16)))\n (dotimes (i 10)\n (split-integers-into-array (buffered-read-line 80) costs i))\n (dotimes (i h)\n (split-integers-into-array (buffered-read-line 800) wall i))\n (dotimes (k 10)\n (dotimes (i 10)\n (dotimes (j 10)\n (when (> (aref costs i j) (+ (aref costs i k) (aref costs k j)))\n (setf (aref costs i j) (+ (aref costs i k) (aref costs k j)))))))\n (println\n (loop for i below h\n sum (loop for j below w\n sum (if (= -1 (aref wall i j))\n 0\n (aref costs (aref wall i j) 1)))))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nJoisino the magical girl has decided to turn every single digit that exists on this world into 1.\n\nRewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).\n\nShe is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).\n\nYou are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:\n\nIf A_{i,j}≠-1, the square contains a digit A_{i,j}.\n\nIf A_{i,j}=-1, the square does not contain a digit.\n\nFind the minimum total amount of MP required to turn every digit on this wall into 1 in the end.\n\nConstraints\n\n1≤H,W≤200\n\n1≤c_{i,j}≤10^3 (i≠j)\n\nc_{i,j}=0 (i=j)\n\n-1≤A_{i,j}≤9\n\nAll input values are integers.\n\nThere is at least one digit on the wall.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nc_{0,0} ... c_{0,9}\n:\nc_{9,0} ... c_{9,9}\nA_{1,1} ... A_{1,W}\n:\nA_{H,1} ... A_{H,W}\n\nOutput\n\nPrint the minimum total amount of MP required to turn every digit on the wall into 1 in the end.\n\nSample Input 1\n\n2 4\n0 9 9 9 9 9 9 9 9 9\n9 0 9 9 9 9 9 9 9 9\n9 9 0 9 9 9 9 9 9 9\n9 9 9 0 9 9 9 9 9 9\n9 9 9 9 0 9 9 9 9 2\n9 9 9 9 9 0 9 9 9 9\n9 9 9 9 9 9 0 9 9 9\n9 9 9 9 9 9 9 0 9 9\n9 9 9 9 2 9 9 9 0 9\n9 2 9 9 9 9 9 9 9 0\n-1 -1 -1 -1\n8 1 1 8\n\nSample Output 1\n\n12\n\nTo turn a single 8 into 1, it is optimal to first turn 8 into 4, then turn 4 into 9, and finally turn 9 into 1, costing 6 MP.\n\nThe wall contains two 8s, so the minimum total MP required is 6×2=12.\n\nSample Input 2\n\n5 5\n0 999 999 999 999 999 999 999 999 999\n999 0 999 999 999 999 999 999 999 999\n999 999 0 999 999 999 999 999 999 999\n999 999 999 0 999 999 999 999 999 999\n999 999 999 999 0 999 999 999 999 999\n999 999 999 999 999 0 999 999 999 999\n999 999 999 999 999 999 0 999 999 999\n999 999 999 999 999 999 999 0 999 999\n999 999 999 999 999 999 999 999 0 999\n999 999 999 999 999 999 999 999 999 0\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n\nSample Output 2\n\n0\n\nNote that she may not need to change any digit.\n\nSample Input 3\n\n3 5\n0 4 3 6 2 7 2 5 3 3\n4 0 5 3 7 5 3 7 2 7\n5 7 0 7 2 9 3 2 9 1\n3 6 2 0 2 4 6 4 2 3\n3 5 7 4 0 6 9 7 6 7\n9 8 5 2 2 0 4 7 6 5\n5 4 6 3 2 3 0 5 4 3\n3 6 2 3 4 2 4 0 8 9\n4 6 5 4 3 5 3 2 0 8\n2 1 3 4 5 7 8 6 4 0\n3 5 2 6 1\n2 5 3 2 1\n6 9 2 5 6\n\nSample Output 3\n\n47", "sample_input": "2 4\n0 9 9 9 9 9 9 9 9 9\n9 0 9 9 9 9 9 9 9 9\n9 9 0 9 9 9 9 9 9 9\n9 9 9 0 9 9 9 9 9 9\n9 9 9 9 0 9 9 9 9 2\n9 9 9 9 9 0 9 9 9 9\n9 9 9 9 9 9 0 9 9 9\n9 9 9 9 9 9 9 0 9 9\n9 9 9 9 2 9 9 9 0 9\n9 2 9 9 9 9 9 9 9 0\n-1 -1 -1 -1\n8 1 1 8\n"}, "reference_outputs": ["12\n"], "source_document_id": "p03546", "source_text": "Score : 400 points\n\nProblem Statement\n\nJoisino the magical girl has decided to turn every single digit that exists on this world into 1.\n\nRewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).\n\nShe is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).\n\nYou are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:\n\nIf A_{i,j}≠-1, the square contains a digit A_{i,j}.\n\nIf A_{i,j}=-1, the square does not contain a digit.\n\nFind the minimum total amount of MP required to turn every digit on this wall into 1 in the end.\n\nConstraints\n\n1≤H,W≤200\n\n1≤c_{i,j}≤10^3 (i≠j)\n\nc_{i,j}=0 (i=j)\n\n-1≤A_{i,j}≤9\n\nAll input values are integers.\n\nThere is at least one digit on the wall.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nc_{0,0} ... c_{0,9}\n:\nc_{9,0} ... c_{9,9}\nA_{1,1} ... A_{1,W}\n:\nA_{H,1} ... A_{H,W}\n\nOutput\n\nPrint the minimum total amount of MP required to turn every digit on the wall into 1 in the end.\n\nSample Input 1\n\n2 4\n0 9 9 9 9 9 9 9 9 9\n9 0 9 9 9 9 9 9 9 9\n9 9 0 9 9 9 9 9 9 9\n9 9 9 0 9 9 9 9 9 9\n9 9 9 9 0 9 9 9 9 2\n9 9 9 9 9 0 9 9 9 9\n9 9 9 9 9 9 0 9 9 9\n9 9 9 9 9 9 9 0 9 9\n9 9 9 9 2 9 9 9 0 9\n9 2 9 9 9 9 9 9 9 0\n-1 -1 -1 -1\n8 1 1 8\n\nSample Output 1\n\n12\n\nTo turn a single 8 into 1, it is optimal to first turn 8 into 4, then turn 4 into 9, and finally turn 9 into 1, costing 6 MP.\n\nThe wall contains two 8s, so the minimum total MP required is 6×2=12.\n\nSample Input 2\n\n5 5\n0 999 999 999 999 999 999 999 999 999\n999 0 999 999 999 999 999 999 999 999\n999 999 0 999 999 999 999 999 999 999\n999 999 999 0 999 999 999 999 999 999\n999 999 999 999 0 999 999 999 999 999\n999 999 999 999 999 0 999 999 999 999\n999 999 999 999 999 999 0 999 999 999\n999 999 999 999 999 999 999 0 999 999\n999 999 999 999 999 999 999 999 0 999\n999 999 999 999 999 999 999 999 999 0\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n\nSample Output 2\n\n0\n\nNote that she may not need to change any digit.\n\nSample Input 3\n\n3 5\n0 4 3 6 2 7 2 5 3 3\n4 0 5 3 7 5 3 7 2 7\n5 7 0 7 2 9 3 2 9 1\n3 6 2 0 2 4 6 4 2 3\n3 5 7 4 0 6 9 7 6 7\n9 8 5 2 2 0 4 7 6 5\n5 4 6 3 2 3 0 5 4 3\n3 6 2 3 4 2 4 0 8 9\n4 6 5 4 3 5 3 2 0 8\n2 1 3 4 5 7 8 6 4 0\n3 5 2 6 1\n2 5 3 2 1\n6 9 2 5 6\n\nSample Output 3\n\n47", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3107, "cpu_time_ms": 112, "memory_kb": 21348}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s153368029", "group_id": "codeNet:p03548", "input_text": "(princ(floor(-(read)(setq c(read)))(+(read)c)))", "language": "Lisp", "metadata": {"date": 1534800527, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03548.html", "problem_id": "p03548", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03548/input.txt", "sample_output_relpath": "derived/input_output/data/p03548/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03548/Lisp/s153368029.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s153368029", "user_id": "u657913472"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(princ(floor(-(read)(setq c(read)))(+(read)c)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have a long seat of width X centimeters.\nThere are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters.\n\nWe would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person.\n\nAt most how many people can sit on the seat?\n\nConstraints\n\nAll input values are integers.\n\n1 \\leq X, Y, Z \\leq 10^5\n\nY+2Z \\leq X\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y Z\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n13 3 1\n\nSample Output 1\n\n3\n\nThere is just enough room for three, as shown below:\n\nFigure\n\nSample Input 2\n\n12 3 1\n\nSample Output 2\n\n2\n\nSample Input 3\n\n100000 1 1\n\nSample Output 3\n\n49999\n\nSample Input 4\n\n64146 123 456\n\nSample Output 4\n\n110\n\nSample Input 5\n\n64145 123 456\n\nSample Output 5\n\n109", "sample_input": "13 3 1\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03548", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have a long seat of width X centimeters.\nThere are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters.\n\nWe would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person.\n\nAt most how many people can sit on the seat?\n\nConstraints\n\nAll input values are integers.\n\n1 \\leq X, Y, Z \\leq 10^5\n\nY+2Z \\leq X\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y Z\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n13 3 1\n\nSample Output 1\n\n3\n\nThere is just enough room for three, as shown below:\n\nFigure\n\nSample Input 2\n\n12 3 1\n\nSample Output 2\n\n2\n\nSample Input 3\n\n100000 1 1\n\nSample Output 3\n\n49999\n\nSample Input 4\n\n64146 123 456\n\nSample Output 4\n\n110\n\nSample Input 5\n\n64145 123 456\n\nSample Output 5\n\n109", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 47, "cpu_time_ms": 24, "memory_kb": 4324}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s296921555", "group_id": "codeNet:p03549", "input_text": "(let((n(read))(m(read)))(princ(*(+(* 100 n)(* 1800 m))(ash 1 m))))", "language": "Lisp", "metadata": {"date": 1551134751, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03549.html", "problem_id": "p03549", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03549/input.txt", "sample_output_relpath": "derived/input_output/data/p03549/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03549/Lisp/s296921555.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s296921555", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3800\n", "input_to_evaluate": "(let((n(read))(m(read)))(princ(*(+(* 100 n)(* 1800 m))(ash 1 m))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi is now competing in a programming contest, but he received TLE in a problem where the answer is YES or NO.\n\nWhen he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases.\n\nThen, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds.\n\nNow, he goes through the following process:\n\nSubmit the code.\n\nWait until the code finishes execution on all the cases.\n\nIf the code fails to correctly solve some of the M cases, submit it again.\n\nRepeat until the code correctly solve all the cases in one submission.\n\nLet the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).\n\nConstraints\n\nAll input values are integers.\n\n1 \\leq N \\leq 100\n\n1 \\leq M \\leq {\\rm min}(N, 5)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nPrint X, the expected value of the total execution time of the code, as an integer. It can be proved that, under the constraints in this problem, X is an integer not exceeding 10^9.\n\nSample Input 1\n\n1 1\n\nSample Output 1\n\n3800\n\nIn this input, there is only one case. Takahashi will repeatedly submit the code that correctly solves this case with 1/2 probability in 1900 milliseconds.\n\nThe code will succeed in one attempt with 1/2 probability, in two attempts with 1/4 probability, and in three attempts with 1/8 probability, and so on.\n\nThus, the answer is 1900 \\times 1/2 + (2 \\times 1900) \\times 1/4 + (3 \\times 1900) \\times 1/8 + ... = 3800.\n\nSample Input 2\n\n10 2\n\nSample Output 2\n\n18400\n\nThe code will take 1900 milliseconds in each of the 2 cases, and 100 milliseconds in each of the 10-2=8 cases. The probability of the code correctly solving all the cases is 1/2 \\times 1/2 = 1/4.\n\nSample Input 3\n\n100 5\n\nSample Output 3\n\n608000", "sample_input": "1 1\n"}, "reference_outputs": ["3800\n"], "source_document_id": "p03549", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi is now competing in a programming contest, but he received TLE in a problem where the answer is YES or NO.\n\nWhen he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases.\n\nThen, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds.\n\nNow, he goes through the following process:\n\nSubmit the code.\n\nWait until the code finishes execution on all the cases.\n\nIf the code fails to correctly solve some of the M cases, submit it again.\n\nRepeat until the code correctly solve all the cases in one submission.\n\nLet the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).\n\nConstraints\n\nAll input values are integers.\n\n1 \\leq N \\leq 100\n\n1 \\leq M \\leq {\\rm min}(N, 5)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nPrint X, the expected value of the total execution time of the code, as an integer. It can be proved that, under the constraints in this problem, X is an integer not exceeding 10^9.\n\nSample Input 1\n\n1 1\n\nSample Output 1\n\n3800\n\nIn this input, there is only one case. Takahashi will repeatedly submit the code that correctly solves this case with 1/2 probability in 1900 milliseconds.\n\nThe code will succeed in one attempt with 1/2 probability, in two attempts with 1/4 probability, and in three attempts with 1/8 probability, and so on.\n\nThus, the answer is 1900 \\times 1/2 + (2 \\times 1900) \\times 1/4 + (3 \\times 1900) \\times 1/8 + ... = 3800.\n\nSample Input 2\n\n10 2\n\nSample Output 2\n\n18400\n\nThe code will take 1900 milliseconds in each of the 2 cases, and 100 milliseconds in each of the 10-2=8 cases. The probability of the code correctly solving all the cases is 1/2 \\times 1/2 = 1/4.\n\nSample Input 3\n\n100 5\n\nSample Output 3\n\n608000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 66, "cpu_time_ms": 500, "memory_kb": 10596}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s290614094", "group_id": "codeNet:p03555", "input_text": "(let ((c1 (concatenate 'list (read-line)))\n (c2 (concatenate 'list (read-line))))\n\n (format t \"~A~%\"\n (if (equal (reverse c1) c2)\n 'yes\n 'no)))\n", "language": "Lisp", "metadata": {"date": 1595205581, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03555.html", "problem_id": "p03555", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03555/input.txt", "sample_output_relpath": "derived/input_output/data/p03555/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03555/Lisp/s290614094.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s290614094", "user_id": "u336541610"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(let ((c1 (concatenate 'list (read-line)))\n (c2 (concatenate 'list (read-line))))\n\n (format t \"~A~%\"\n (if (equal (reverse c1) c2)\n 'yes\n 'no)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a grid with 2 rows and 3 columns of squares.\nThe color of the square at the i-th row and j-th column is represented by the character C_{ij}.\n\nWrite a program that prints YES if this grid remains the same when rotated 180 degrees, and prints NO otherwise.\n\nConstraints\n\nC_{i,j}(1 \\leq i \\leq 2, 1 \\leq j \\leq 3) is a lowercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nC_{11}C_{12}C_{13}\nC_{21}C_{22}C_{23}\n\nOutput\n\nPrint YES if this grid remains the same when rotated 180 degrees; print NO otherwise.\n\nSample Input 1\n\npot\ntop\n\nSample Output 1\n\nYES\n\nThis grid remains the same when rotated 180 degrees.\n\nSample Input 2\n\ntab\nbet\n\nSample Output 2\n\nNO\n\nThis grid does not remain the same when rotated 180 degrees.\n\nSample Input 3\n\neye\neel\n\nSample Output 3\n\nNO", "sample_input": "pot\ntop\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03555", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a grid with 2 rows and 3 columns of squares.\nThe color of the square at the i-th row and j-th column is represented by the character C_{ij}.\n\nWrite a program that prints YES if this grid remains the same when rotated 180 degrees, and prints NO otherwise.\n\nConstraints\n\nC_{i,j}(1 \\leq i \\leq 2, 1 \\leq j \\leq 3) is a lowercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nC_{11}C_{12}C_{13}\nC_{21}C_{22}C_{23}\n\nOutput\n\nPrint YES if this grid remains the same when rotated 180 degrees; print NO otherwise.\n\nSample Input 1\n\npot\ntop\n\nSample Output 1\n\nYES\n\nThis grid remains the same when rotated 180 degrees.\n\nSample Input 2\n\ntab\nbet\n\nSample Output 2\n\nNO\n\nThis grid does not remain the same when rotated 180 degrees.\n\nSample Input 3\n\neye\neel\n\nSample Output 3\n\nNO", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 181, "cpu_time_ms": 18, "memory_kb": 23312}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s544468015", "group_id": "codeNet:p03555", "input_text": "(if (equal \n (read-line)\n (reverse (read-line))\n )\n (format t \"YES~%\")\n (format t \"NO~%\")\n )\n", "language": "Lisp", "metadata": {"date": 1558301786, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03555.html", "problem_id": "p03555", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03555/input.txt", "sample_output_relpath": "derived/input_output/data/p03555/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03555/Lisp/s544468015.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s544468015", "user_id": "u493610446"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(if (equal \n (read-line)\n (reverse (read-line))\n )\n (format t \"YES~%\")\n (format t \"NO~%\")\n )\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a grid with 2 rows and 3 columns of squares.\nThe color of the square at the i-th row and j-th column is represented by the character C_{ij}.\n\nWrite a program that prints YES if this grid remains the same when rotated 180 degrees, and prints NO otherwise.\n\nConstraints\n\nC_{i,j}(1 \\leq i \\leq 2, 1 \\leq j \\leq 3) is a lowercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nC_{11}C_{12}C_{13}\nC_{21}C_{22}C_{23}\n\nOutput\n\nPrint YES if this grid remains the same when rotated 180 degrees; print NO otherwise.\n\nSample Input 1\n\npot\ntop\n\nSample Output 1\n\nYES\n\nThis grid remains the same when rotated 180 degrees.\n\nSample Input 2\n\ntab\nbet\n\nSample Output 2\n\nNO\n\nThis grid does not remain the same when rotated 180 degrees.\n\nSample Input 3\n\neye\neel\n\nSample Output 3\n\nNO", "sample_input": "pot\ntop\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03555", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a grid with 2 rows and 3 columns of squares.\nThe color of the square at the i-th row and j-th column is represented by the character C_{ij}.\n\nWrite a program that prints YES if this grid remains the same when rotated 180 degrees, and prints NO otherwise.\n\nConstraints\n\nC_{i,j}(1 \\leq i \\leq 2, 1 \\leq j \\leq 3) is a lowercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nC_{11}C_{12}C_{13}\nC_{21}C_{22}C_{23}\n\nOutput\n\nPrint YES if this grid remains the same when rotated 180 degrees; print NO otherwise.\n\nSample Input 1\n\npot\ntop\n\nSample Output 1\n\nYES\n\nThis grid remains the same when rotated 180 degrees.\n\nSample Input 2\n\ntab\nbet\n\nSample Output 2\n\nNO\n\nThis grid does not remain the same when rotated 180 degrees.\n\nSample Input 3\n\neye\neel\n\nSample Output 3\n\nNO", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 117, "cpu_time_ms": 17, "memory_kb": 3688}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s524374270", "group_id": "codeNet:p03556", "input_text": "(let* ((a (read))\n (ans 1))\n (loop :while (<= (expt ans 2) a) :do(setf ans (1+ ans)))\n (princ (expt (1- ans) 2)))", "language": "Lisp", "metadata": {"date": 1551679984, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03556.html", "problem_id": "p03556", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03556/input.txt", "sample_output_relpath": "derived/input_output/data/p03556/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03556/Lisp/s524374270.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s524374270", "user_id": "u610490393"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(let* ((a (read))\n (ans 1))\n (loop :while (<= (expt ans 2) a) :do(setf ans (1+ ans)))\n (princ (expt (1- ans) 2)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nFind the largest square number not exceeding N. Here, a square number is an integer that can be represented as the square of an integer.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the largest square number not exceeding N.\n\nSample Input 1\n\n10\n\nSample Output 1\n\n9\n\n10 is not square, but 9 = 3 × 3 is. Thus, we print 9.\n\nSample Input 2\n\n81\n\nSample Output 2\n\n81\n\nSample Input 3\n\n271828182\n\nSample Output 3\n\n271821169", "sample_input": "10\n"}, "reference_outputs": ["9\n"], "source_document_id": "p03556", "source_text": "Score : 200 points\n\nProblem Statement\n\nFind the largest square number not exceeding N. Here, a square number is an integer that can be represented as the square of an integer.\n\nConstraints\n\n1 \\leq N \\leq 10^9\n\nN is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the largest square number not exceeding N.\n\nSample Input 1\n\n10\n\nSample Output 1\n\n9\n\n10 is not square, but 9 = 3 × 3 is. Thus, we print 9.\n\nSample Input 2\n\n81\n\nSample Output 2\n\n81\n\nSample Input 3\n\n271828182\n\nSample Output 3\n\n271821169", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 121, "cpu_time_ms": 14, "memory_kb": 3556}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s930039229", "group_id": "codeNet:p03557", "input_text": "(defun lower-bound (predicate &optional (ok 0) (ng (expt 10 10)))\n (if (<= (abs (- ng ok)) 1)\n ok\n (let ((mid (floor (+ ng ok) 2)))\n (if (funcall predicate mid)\n (lower-bound predicate mid ng)\n (lower-bound predicate ok mid)))))\n\n\n(defun smaller-p (xs index b-size)\n (< (aref xs index) b-size))\n\n\n(defun bigger-p (xs index b-size)\n (> (aref xs index) b-size))\n\n\n(defun solve (a b c &optional (res 0))\n (declare (optimize speed))\n (declare (type (array fixnum) a b c))\n (declare (type integer res))\n (the integer\n (dotimes (j (length b) res)\n (incf res (* (lower-bound #'(lambda (x)\n (smaller-p a x (aref b j)))\n 0\n (length a))\n (lower-bound #'(lambda (x)\n (bigger-p c x (aref b j)))\n 0\n (length c)))))))\n\n\n(defparameter *inf* (1+ (expt 10 9)))\n\n\n\n(locally\n (declare (inline sort))\n (let* ((n (read))\n (a (make-array (1+ n) :element-type 'fixnum))\n (b (make-array n :element-type 'fixnum))\n (c (make-array (1+ n) :element-type 'fixnum)))\n (declare (type fixnum n))\n (setf (aref a (1- (length a))) 0)\n (setf (aref c (1- (length c))) *inf*)\n (dotimes (i n)\n (setf (aref a i) (read)))\n (dotimes (i n)\n (setf (aref b i) (read)))\n (dotimes (i n)\n (setf (aref c i) (read)))\n (sort a #'<)\n (sort c #'>)\n (princ (solve a b c))\n (fresh-line)))\n\n", "language": "Lisp", "metadata": {"date": 1596560871, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03557.html", "problem_id": "p03557", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03557/input.txt", "sample_output_relpath": "derived/input_output/data/p03557/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03557/Lisp/s930039229.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s930039229", "user_id": "u425762225"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun lower-bound (predicate &optional (ok 0) (ng (expt 10 10)))\n (if (<= (abs (- ng ok)) 1)\n ok\n (let ((mid (floor (+ ng ok) 2)))\n (if (funcall predicate mid)\n (lower-bound predicate mid ng)\n (lower-bound predicate ok mid)))))\n\n\n(defun smaller-p (xs index b-size)\n (< (aref xs index) b-size))\n\n\n(defun bigger-p (xs index b-size)\n (> (aref xs index) b-size))\n\n\n(defun solve (a b c &optional (res 0))\n (declare (optimize speed))\n (declare (type (array fixnum) a b c))\n (declare (type integer res))\n (the integer\n (dotimes (j (length b) res)\n (incf res (* (lower-bound #'(lambda (x)\n (smaller-p a x (aref b j)))\n 0\n (length a))\n (lower-bound #'(lambda (x)\n (bigger-p c x (aref b j)))\n 0\n (length c)))))))\n\n\n(defparameter *inf* (1+ (expt 10 9)))\n\n\n\n(locally\n (declare (inline sort))\n (let* ((n (read))\n (a (make-array (1+ n) :element-type 'fixnum))\n (b (make-array n :element-type 'fixnum))\n (c (make-array (1+ n) :element-type 'fixnum)))\n (declare (type fixnum n))\n (setf (aref a (1- (length a))) 0)\n (setf (aref c (1- (length c))) *inf*)\n (dotimes (i n)\n (setf (aref a i) (read)))\n (dotimes (i n)\n (setf (aref b i) (read)))\n (dotimes (i n)\n (setf (aref c i) (read)))\n (sort a #'<)\n (sort c #'>)\n (princ (solve a b c))\n (fresh-line)))\n\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThe season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.\n\nHe has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.\n\nTo build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.\n\nHow many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^9(1\\leq i\\leq N)\n\n1 \\leq B_i \\leq 10^9(1\\leq i\\leq N)\n\n1 \\leq C_i \\leq 10^9(1\\leq i\\leq N)\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 ... A_N\nB_1 ... B_N\nC_1 ... C_N\n\nOutput\n\nPrint the number of different altars that Ringo can build.\n\nSample Input 1\n\n2\n1 5\n2 4\n3 6\n\nSample Output 1\n\n3\n\nThe following three altars can be built:\n\nUpper: 1-st part, Middle: 1-st part, Lower: 1-st part\n\nUpper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n\nUpper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\nSample Input 2\n\n3\n1 1 1\n2 2 2\n3 3 3\n\nSample Output 2\n\n27\n\nSample Input 3\n\n6\n3 14 159 2 6 53\n58 9 79 323 84 6\n2643 383 2 79 50 288\n\nSample Output 3\n\n87", "sample_input": "2\n1 5\n2 4\n3 6\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03557", "source_text": "Score : 300 points\n\nProblem Statement\n\nThe season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.\n\nHe has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.\n\nTo build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.\n\nHow many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^9(1\\leq i\\leq N)\n\n1 \\leq B_i \\leq 10^9(1\\leq i\\leq N)\n\n1 \\leq C_i \\leq 10^9(1\\leq i\\leq N)\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 ... A_N\nB_1 ... B_N\nC_1 ... C_N\n\nOutput\n\nPrint the number of different altars that Ringo can build.\n\nSample Input 1\n\n2\n1 5\n2 4\n3 6\n\nSample Output 1\n\n3\n\nThe following three altars can be built:\n\nUpper: 1-st part, Middle: 1-st part, Lower: 1-st part\n\nUpper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n\nUpper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\nSample Input 2\n\n3\n1 1 1\n2 2 2\n3 3 3\n\nSample Output 2\n\n27\n\nSample Input 3\n\n6\n3 14 159 2 6 53\n58 9 79 323 84 6\n2643 383 2 79 50 288\n\nSample Output 3\n\n87", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1604, "cpu_time_ms": 549, "memory_kb": 78716}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s157751106", "group_id": "codeNet:p03557", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (test #'<) (key #'identity))\n \"TARGET := vector | function\nTEST := strict order\n\nReturns the smallest index (or input) i that fulfills TARGET[i] >= VALUE, where\n'>=' is the complement of TEST. TARGET must be monotonically non-decreasing with\nrespect to TEST. Returns END if VALUE exceeds TARGET[END-1]. Note that the range\n[START, END) is half-open. END must be specified If TARGET is function. KEY is\napplied to each element of TARGET before comparison.\"\n (declare (function key test)\n ((integer 0 #.most-positive-fixnum) start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (macrolet\n ((body (accessor &optional declaration)\n `(cond ((assert (<= start end)))\n ((= start end) end)\n ((funcall test (funcall key (,accessor target (- end 1))) value)\n end)\n (t (labels ((%bisect-left (l r)\n ,@(list declaration)\n (let ((mid (floor (+ l r) 2)))\n (if (= mid l)\n (if (funcall test (funcall key (,accessor target l)) value)\n r\n l)\n (if (funcall test (funcall key (,accessor target mid)) value)\n (%bisect-left mid r)\n (%bisect-left l mid))))))\n (%bisect-left start (- end 1)))))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (body aref (declare ((integer 0 #.most-positive-fixnum) l r)))))\n (function\n (assert end)\n (body funcall)))))\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (test #'<) (key #'identity))\n \"TARGET := vector | function\nTEST := strict order\n\nReturns the smallest index (or input) i that fulfills TARGET[i] > VALUE. TARGET\nmust be monotonically non-decreasing with respect to TEST. Returns END if VALUE\nexceeds TARGET[END-1]. Note that the range [START, END) is half-open. END must\nbe specified if TARGET is function. KEY is applied to each element of TARGET\nbefore comparison.\"\n (declare (function key test)\n ((integer 0 #.most-positive-fixnum) start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (macrolet\n ((body (accessor &optional declaration)\n `(cond ((assert (<= start end)))\n ((= start end) end)\n ((funcall test value (funcall key (,accessor target (- end 1))))\n (labels ((%bisect-right (l r)\n ,@(list declaration)\n (let ((mid (floor (+ l r) 2)))\n (if (= mid l)\n (if (funcall test value (funcall key (,accessor target l)))\n l\n r)\n (if (funcall test value (funcall key (,accessor target mid)))\n (%bisect-right l mid)\n (%bisect-right mid r))))))\n \n (%bisect-right start (- end 1))))\n (t end))))\n (etypecase target\n (vector\n (when (null end)\n (setf end (length target)))\n (body aref (declare ((integer 0 #.most-positive-fixnum) l r))))\n (function\n (assert end)\n (body funcall)))))\n\n(declaim (inline read-line-into))\n(defun read-line-into (buffer-string &key (in *standard-input*) (terminate-char #\\Space))\n (declare (simple-base-string buffer-string))\n (loop for c of-type base-char =\n #-swank (code-char (read-byte in nil #\\Newline))\n #+swank (read-char in nil #\\Newline)\n for idx from 0\n until (char= c #\\Newline)\n do (setf (schar buffer-string idx) c)\n finally (setf (schar buffer-string idx) terminate-char)\n (return (values buffer-string idx))))\n\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))\n (declare (string string)\n (function key)\n ((simple-array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop for idx from offset below (length dest-vector)\n for pos1 = 0 then (1+ pos2)\n for pos2 = (position #\\space string :start pos1 :test #'char=)\n do (setf (aref dest-vector idx)\n (funcall key (parse-integer string :start pos1 :end pos2)))\n finally (return dest-vector)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint32))\n (bs (make-array n :element-type 'uint32))\n (cs (make-array n :element-type 'uint32))\n (buf (make-string 1200000 :element-type 'base-char)))\n (dolist (seq (list as bs cs))\n (declare ((simple-array uint32 (*)) seq))\n (split-ints-into-vector (read-line-into buf) seq))\n (setf as (stable-sort as #'<)\n cs (stable-sort cs #'<))\n (println\n (loop for b across bs\n sum (* (the uint31 (bisect-left as b))\n (the uint31 (- n (bisect-right cs b))))\n of-type fixnum))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1548348546, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03557.html", "problem_id": "p03557", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03557/input.txt", "sample_output_relpath": "derived/input_output/data/p03557/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03557/Lisp/s157751106.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s157751106", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline bisect-left))\n(defun bisect-left (target value &key (start 0) end (test #'<) (key #'identity))\n \"TARGET := vector | function\nTEST := strict order\n\nReturns the smallest index (or input) i that fulfills TARGET[i] >= VALUE, where\n'>=' is the complement of TEST. TARGET must be monotonically non-decreasing with\nrespect to TEST. Returns END if VALUE exceeds TARGET[END-1]. Note that the range\n[START, END) is half-open. END must be specified If TARGET is function. KEY is\napplied to each element of TARGET before comparison.\"\n (declare (function key test)\n ((integer 0 #.most-positive-fixnum) start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (macrolet\n ((body (accessor &optional declaration)\n `(cond ((assert (<= start end)))\n ((= start end) end)\n ((funcall test (funcall key (,accessor target (- end 1))) value)\n end)\n (t (labels ((%bisect-left (l r)\n ,@(list declaration)\n (let ((mid (floor (+ l r) 2)))\n (if (= mid l)\n (if (funcall test (funcall key (,accessor target l)) value)\n r\n l)\n (if (funcall test (funcall key (,accessor target mid)) value)\n (%bisect-left mid r)\n (%bisect-left l mid))))))\n (%bisect-left start (- end 1)))))))\n (etypecase target\n (vector\n (let ((end (or end (length target))))\n (body aref (declare ((integer 0 #.most-positive-fixnum) l r)))))\n (function\n (assert end)\n (body funcall)))))\n\n(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (test #'<) (key #'identity))\n \"TARGET := vector | function\nTEST := strict order\n\nReturns the smallest index (or input) i that fulfills TARGET[i] > VALUE. TARGET\nmust be monotonically non-decreasing with respect to TEST. Returns END if VALUE\nexceeds TARGET[END-1]. Note that the range [START, END) is half-open. END must\nbe specified if TARGET is function. KEY is applied to each element of TARGET\nbefore comparison.\"\n (declare (function key test)\n ((integer 0 #.most-positive-fixnum) start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (macrolet\n ((body (accessor &optional declaration)\n `(cond ((assert (<= start end)))\n ((= start end) end)\n ((funcall test value (funcall key (,accessor target (- end 1))))\n (labels ((%bisect-right (l r)\n ,@(list declaration)\n (let ((mid (floor (+ l r) 2)))\n (if (= mid l)\n (if (funcall test value (funcall key (,accessor target l)))\n l\n r)\n (if (funcall test value (funcall key (,accessor target mid)))\n (%bisect-right l mid)\n (%bisect-right mid r))))))\n \n (%bisect-right start (- end 1))))\n (t end))))\n (etypecase target\n (vector\n (when (null end)\n (setf end (length target)))\n (body aref (declare ((integer 0 #.most-positive-fixnum) l r))))\n (function\n (assert end)\n (body funcall)))))\n\n(declaim (inline read-line-into))\n(defun read-line-into (buffer-string &key (in *standard-input*) (terminate-char #\\Space))\n (declare (simple-base-string buffer-string))\n (loop for c of-type base-char =\n #-swank (code-char (read-byte in nil #\\Newline))\n #+swank (read-char in nil #\\Newline)\n for idx from 0\n until (char= c #\\Newline)\n do (setf (schar buffer-string idx) c)\n finally (setf (schar buffer-string idx) terminate-char)\n (return (values buffer-string idx))))\n\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))\n (declare (string string)\n (function key)\n ((simple-array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop for idx from offset below (length dest-vector)\n for pos1 = 0 then (1+ pos2)\n for pos2 = (position #\\space string :start pos1 :test #'char=)\n do (setf (aref dest-vector idx)\n (funcall key (parse-integer string :start pos1 :end pos2)))\n finally (return dest-vector)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint32))\n (bs (make-array n :element-type 'uint32))\n (cs (make-array n :element-type 'uint32))\n (buf (make-string 1200000 :element-type 'base-char)))\n (dolist (seq (list as bs cs))\n (declare ((simple-array uint32 (*)) seq))\n (split-ints-into-vector (read-line-into buf) seq))\n (setf as (stable-sort as #'<)\n cs (stable-sort cs #'<))\n (println\n (loop for b across bs\n sum (* (the uint31 (bisect-left as b))\n (the uint31 (- n (bisect-right cs b))))\n of-type fixnum))))\n\n#-swank(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThe season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.\n\nHe has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.\n\nTo build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.\n\nHow many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^9(1\\leq i\\leq N)\n\n1 \\leq B_i \\leq 10^9(1\\leq i\\leq N)\n\n1 \\leq C_i \\leq 10^9(1\\leq i\\leq N)\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 ... A_N\nB_1 ... B_N\nC_1 ... C_N\n\nOutput\n\nPrint the number of different altars that Ringo can build.\n\nSample Input 1\n\n2\n1 5\n2 4\n3 6\n\nSample Output 1\n\n3\n\nThe following three altars can be built:\n\nUpper: 1-st part, Middle: 1-st part, Lower: 1-st part\n\nUpper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n\nUpper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\nSample Input 2\n\n3\n1 1 1\n2 2 2\n3 3 3\n\nSample Output 2\n\n27\n\nSample Input 3\n\n6\n3 14 159 2 6 53\n58 9 79 323 84 6\n2643 383 2 79 50 288\n\nSample Output 3\n\n87", "sample_input": "2\n1 5\n2 4\n3 6\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03557", "source_text": "Score : 300 points\n\nProblem Statement\n\nThe season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.\n\nHe has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.\n\nTo build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.\n\nHow many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^9(1\\leq i\\leq N)\n\n1 \\leq B_i \\leq 10^9(1\\leq i\\leq N)\n\n1 \\leq C_i \\leq 10^9(1\\leq i\\leq N)\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 ... A_N\nB_1 ... B_N\nC_1 ... C_N\n\nOutput\n\nPrint the number of different altars that Ringo can build.\n\nSample Input 1\n\n2\n1 5\n2 4\n3 6\n\nSample Output 1\n\n3\n\nThe following three altars can be built:\n\nUpper: 1-st part, Middle: 1-st part, Lower: 1-st part\n\nUpper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n\nUpper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\nSample Input 2\n\n3\n1 1 1\n2 2 2\n3 3 3\n\nSample Output 2\n\n27\n\nSample Input 3\n\n6\n3 14 159 2 6 53\n58 9 79 323 84 6\n2643 383 2 79 50 288\n\nSample Output 3\n\n87", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6331, "cpu_time_ms": 394, "memory_kb": 33256}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s791421843", "group_id": "codeNet:p03557", "input_text": "(defun split (string &key (delimiterp #'delimiterp))\n (loop :for beg = (position-if-not delimiterp string)\n :then (position-if-not delimiterp string :start (1+ end))\n :for end = (and beg (position-if delimiterp string :start beg))\n :when beg :collect (subseq string beg end)\n :while end))\n(defun delimiterp (c) (position c \" ,.;/\"))\n\n(defun make-array-from-list (l)\n (make-array (list (length l)) :initial-contents l)\n )\n\n(defun bisect-left (n arr)\n (bisect-left_ n 0 (length arr) arr))\n(defun bisect-left_ (n lo hi arr)\n (cond ((>= lo hi) (return-from bisect-left_ lo))\n (t\n (let ((mid (floor (/ (+ lo hi) 2))))\n (cond ((<= n (aref arr mid)) (return-from bisect-left_\n (bisect-left_ n lo mid arr)))\n (t (return-from bisect-left_ (bisect-left_ n (1+ mid) hi arr))))))\n ))\n\n(defun bisect-right (n arr)\n (bisect-right_ n 0 (length arr) arr))\n(defun bisect-right_ (n lo hi arr)\n (cond ((>= lo hi) (return-from bisect-right_ hi))\n (t\n (let ((mid (floor (/ (+ lo hi) 2))))\n (cond ((< n (aref arr mid)) (return-from bisect-right_\n (bisect-right_ n lo mid arr)))\n (t (return-from bisect-right_ (bisect-right_ n (1+ mid) hi arr))))))\n ))\n\n(defun main()\n (let ((n (read))\n (as (sort (make-array-from-list (map 'list #'parse-integer (split (read-line)))) #'<))\n (bs (map 'list #'parse-integer (split (read-line))))\n (cs (sort (make-array-from-list (map 'list #'parse-integer (split (read-line)))) #'<))\n )\n\n (princ (reduce #'+ (loop :for b :in bs :collect\n (* (bisect-left b as) (- n (bisect-right b cs))))))\n (princ #\\newline)\n )\n)\n(main)", "language": "Lisp", "metadata": {"date": 1510267576, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03557.html", "problem_id": "p03557", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03557/input.txt", "sample_output_relpath": "derived/input_output/data/p03557/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03557/Lisp/s791421843.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s791421843", "user_id": "u055459962"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun split (string &key (delimiterp #'delimiterp))\n (loop :for beg = (position-if-not delimiterp string)\n :then (position-if-not delimiterp string :start (1+ end))\n :for end = (and beg (position-if delimiterp string :start beg))\n :when beg :collect (subseq string beg end)\n :while end))\n(defun delimiterp (c) (position c \" ,.;/\"))\n\n(defun make-array-from-list (l)\n (make-array (list (length l)) :initial-contents l)\n )\n\n(defun bisect-left (n arr)\n (bisect-left_ n 0 (length arr) arr))\n(defun bisect-left_ (n lo hi arr)\n (cond ((>= lo hi) (return-from bisect-left_ lo))\n (t\n (let ((mid (floor (/ (+ lo hi) 2))))\n (cond ((<= n (aref arr mid)) (return-from bisect-left_\n (bisect-left_ n lo mid arr)))\n (t (return-from bisect-left_ (bisect-left_ n (1+ mid) hi arr))))))\n ))\n\n(defun bisect-right (n arr)\n (bisect-right_ n 0 (length arr) arr))\n(defun bisect-right_ (n lo hi arr)\n (cond ((>= lo hi) (return-from bisect-right_ hi))\n (t\n (let ((mid (floor (/ (+ lo hi) 2))))\n (cond ((< n (aref arr mid)) (return-from bisect-right_\n (bisect-right_ n lo mid arr)))\n (t (return-from bisect-right_ (bisect-right_ n (1+ mid) hi arr))))))\n ))\n\n(defun main()\n (let ((n (read))\n (as (sort (make-array-from-list (map 'list #'parse-integer (split (read-line)))) #'<))\n (bs (map 'list #'parse-integer (split (read-line))))\n (cs (sort (make-array-from-list (map 'list #'parse-integer (split (read-line)))) #'<))\n )\n\n (princ (reduce #'+ (loop :for b :in bs :collect\n (* (bisect-left b as) (- n (bisect-right b cs))))))\n (princ #\\newline)\n )\n)\n(main)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThe season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.\n\nHe has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.\n\nTo build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.\n\nHow many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^9(1\\leq i\\leq N)\n\n1 \\leq B_i \\leq 10^9(1\\leq i\\leq N)\n\n1 \\leq C_i \\leq 10^9(1\\leq i\\leq N)\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 ... A_N\nB_1 ... B_N\nC_1 ... C_N\n\nOutput\n\nPrint the number of different altars that Ringo can build.\n\nSample Input 1\n\n2\n1 5\n2 4\n3 6\n\nSample Output 1\n\n3\n\nThe following three altars can be built:\n\nUpper: 1-st part, Middle: 1-st part, Lower: 1-st part\n\nUpper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n\nUpper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\nSample Input 2\n\n3\n1 1 1\n2 2 2\n3 3 3\n\nSample Output 2\n\n27\n\nSample Input 3\n\n6\n3 14 159 2 6 53\n58 9 79 323 84 6\n2643 383 2 79 50 288\n\nSample Output 3\n\n87", "sample_input": "2\n1 5\n2 4\n3 6\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03557", "source_text": "Score : 300 points\n\nProblem Statement\n\nThe season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.\n\nHe has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.\n\nTo build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.\n\nHow many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^9(1\\leq i\\leq N)\n\n1 \\leq B_i \\leq 10^9(1\\leq i\\leq N)\n\n1 \\leq C_i \\leq 10^9(1\\leq i\\leq N)\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 ... A_N\nB_1 ... B_N\nC_1 ... C_N\n\nOutput\n\nPrint the number of different altars that Ringo can build.\n\nSample Input 1\n\n2\n1 5\n2 4\n3 6\n\nSample Output 1\n\n3\n\nThe following three altars can be built:\n\nUpper: 1-st part, Middle: 1-st part, Lower: 1-st part\n\nUpper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n\nUpper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\nSample Input 2\n\n3\n1 1 1\n2 2 2\n3 3 3\n\nSample Output 2\n\n27\n\nSample Input 3\n\n6\n3 14 159 2 6 53\n58 9 79 323 84 6\n2643 383 2 79 50 288\n\nSample Output 3\n\n87", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1816, "cpu_time_ms": 1386, "memory_kb": 93028}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s179486083", "group_id": "codeNet:p03558", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Real FFT\n;;;\n;;; Reference:\n;;; http://www.kurims.kyoto-u.ac.jp/~ooura/fftman/ftmn2_12.html#sec2_1_2\n;;;\n\n(deftype fft-float () 'single-float)\n\n(declaim (inline power2-p))\n(defun power2-p (x)\n \"Checks if X is a power of 2.\"\n (zerop (logand x (- x 1))))\n\n;; For FFT of fixed length, preparing the table of cos(i*theta) and sin\n;; (i*theta) will be efficient.\n(defun %make-trifunc-table (n)\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) n))\n (assert (power2-p n))\n (let* ((cos-table (make-array (ash n -2) :element-type 'fft-float))\n (sin-table (make-array (ash n -2) :element-type 'fft-float))\n (theta (/ (coerce (* 2 pi) 'fft-float) n)))\n (dotimes (i (ash n -2))\n (setf (aref cos-table i) (cos (* i theta))\n (aref sin-table i) (sin (* i theta))))\n (values cos-table sin-table)))\n\n(defparameter *cos-table* nil)\n(defparameter *sin-table* nil)\n\n(defmacro with-fixed-base (size &body body)\n \"Makes FFT faster when the SIZE of target vectors is fixed in BODY. This macro\ncomputes and holds the roots of unity for SIZE, which DFT! and INVERSE-DFT!\ncalled in BODY automatically detects; they will signal an error when they\nreceive a vector of different size.\"\n (let ((s (gensym)))\n `(let ((,s ,size))\n (multiple-value-bind (*cos-table* *sin-table*) (%make-trifunc-table ,s)\n ,@body))))\n\n(defun %dft-fixed-base! (f)\n (declare #.OPT\n ((simple-array fft-float (*)) f))\n (prog1 f\n (let* ((n (length f))\n (cos-table *cos-table*)\n (sin-table *sin-table*)\n (factor n))\n (declare ((integer 0 #.most-positive-fixnum) factor)\n ((simple-array fft-float (*)) cos-table sin-table))\n (assert (power2-p n))\n (assert (= (ash n -2) (length cos-table)))\n ;; bit-reverse ordering\n (let ((i 0))\n (declare ((integer 0 #.most-positive-fixnum) i))\n (loop for j from 1 below (- n 1)\n do (loop for k of-type (integer 0 #.most-positive-fixnum)\n = (ash n -1) then (ash k -1)\n while (> k (setq i (logxor i k))))\n (when (< j i)\n (rotatef (aref f i) (aref f j)))))\n (do* ((mh 1 m)\n (m (ash mh 1) (ash mh 1)))\n ((> m n))\n (declare ((integer 0 #.most-positive-fixnum) mh m))\n (let ((mq (ash mh -1)))\n (setq factor (ash factor -1))\n (do ((jr 0 (+ jr m)))\n ((>= jr n))\n (declare ((integer 0 #.most-positive-fixnum) jr))\n (let ((xreal (aref f (+ jr mh))))\n (setf (aref f (+ jr mh)) (- (aref f jr) xreal))\n (incf (aref f jr) xreal)))\n (do ((i 1 (+ i 1))\n (table-index factor (+ table-index factor)))\n ((>= i mq))\n (declare ((integer 0 #.most-positive-fixnum) i table-index))\n (let* ((wreal (aref cos-table table-index))\n (wimag (- (aref sin-table table-index))))\n (do ((j 0 (+ j m)))\n ((>= j n))\n (let* ((j+mh (+ j mh))\n (j+m-i (- (+ j m) i))\n (xreal (+ (* wreal (aref f (+ j+mh i)))\n (* wimag (aref f j+m-i))))\n (ximag (- (* wreal (aref f j+m-i))\n (* wimag (aref f (+ j+mh i))))))\n (declare ((integer 0 #.most-positive-fixnum) j+mh j+m-i))\n (setf (aref f (+ j+mh i))\n (+ (- (aref f (- j+mh i))) ximag))\n (setf (aref f j+m-i)\n (+ (aref f (- j+mh i)) ximag))\n (setf (aref f (- j+mh i))\n (+ (aref f (+ j i)) (- xreal)))\n (incf (aref f (+ j i)) xreal))))))))))\n\n(defun %inverse-dft-fixed-base! (f)\n (declare #.OPT\n ((simple-array fft-float (*)) f))\n (prog1 f\n (let* ((n (length f))\n (cos-table *cos-table*)\n (sin-table *sin-table*)\n (factor 1))\n (declare ((integer 0 #.most-positive-fixnum) factor)\n ((simple-array fft-float (*)) cos-table sin-table))\n (assert (power2-p n))\n (assert (= (ash n -2) (length cos-table)))\n (setf (aref f 0)\n (/ (aref f 0) 2))\n (setf (aref f (ash n -1))\n (/ (aref f (ash n -1)) 2))\n (do* ((m n mh)\n (mh (ash m -1) (ash m -1)))\n ((zerop mh))\n (declare ((integer 0 #.most-positive-fixnum) m mh))\n (let ((mq (ash mh -1)))\n (do ((jr 0 (+ jr m)))\n ((>= jr n))\n (declare ((integer 0 #.most-positive-fixnum) jr))\n (let ((xreal (- (aref f jr) (aref f (+ jr mh)))))\n (incf (aref f jr) (aref f (+ jr mh)))\n (setf (aref f (+ jr mh)) xreal)))\n (do ((i 1 (+ i 1))\n (table-index factor (+ factor table-index)))\n ((>= i mq))\n (declare ((integer 0 #.most-positive-fixnum) i table-index))\n (let* ((wreal (aref cos-table table-index))\n (wimag (aref sin-table table-index)))\n (do ((j 0 (+ j m)))\n ((>= j n))\n (let* ((j+mh (+ j mh))\n (j+m-i (- (+ j m) i))\n (xreal (- (aref f (+ j i)) (aref f (- j+mh i))))\n (ximag (+ (aref f j+m-i) (aref f (+ j+mh i)))))\n (declare ((integer 0 #.most-positive-fixnum) j+mh j+m-i))\n (incf (aref f (+ j i)) (aref f (- j+mh i)))\n (setf (aref f (- j+mh i))\n (- (aref f j+m-i) (aref f (+ j+mh i))))\n (setf (aref f (+ j+mh i))\n (+ (* wreal xreal) (* wimag ximag)))\n (setf (aref f j+m-i)\n (- (* wreal ximag) (* wimag xreal))))))))\n (setq factor (ash factor 1)))\n ;; bit-reverse ordering\n (let ((i 0))\n (declare ((integer 0 #.most-positive-fixnum) i))\n (loop for j from 1 below (- n 1)\n do (loop for k of-type (integer 0 #.most-positive-fixnum)\n = (ash n -1) then (ash k -1)\n while (> k (setq i (logxor i k))))\n (when (< j i)\n (rotatef (aref f i) (aref f j))))))))\n\n(declaim (inline dft!))\n(defun dft! (f)\n (declare ((simple-array fft-float (*)) f))\n (if (zerop (length f))\n f\n (%dft-fixed-base! f)))\n\n(declaim (inline inverse-dft!))\n(defun inverse-dft! (f)\n (declare ((simple-array fft-float (*)) f))\n (prog1 f\n (let ((n (length f)))\n (unless (zerop n)\n (let ((factor (* 2 (/ (coerce n 'fft-float)))))\n (%inverse-dft-fixed-base! f)\n (dotimes (i n)\n (setf (aref f i) (* (aref f i) factor))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; Body\n(defconstant +dp-size+ (ash 1 18))\n\n(defun main ()\n (declare #.OPT)\n (let* ((k (read))\n (dp (make-array +dp-size+ :element-type 'fft-float :initial-element 0f0))\n (multiplier (make-array +dp-size+ :element-type 'fft-float :initial-element 0f0)))\n (declare ((integer 0 100000) k)\n ((simple-array fft-float (#.+dp-size+)) dp multiplier))\n (loop for i = 1 then (rem (* i 10) k)\n while (= 0f0 (aref dp i))\n do (setf (aref dp i) 1f0\n (aref multiplier i) 1f0))\n (with-fixed-base +dp-size+\n (dft! multiplier)\n (loop for i from 1 to 45\n do (when (= 1f0 (aref dp 0))\n (println i)\n (return-from main))\n (when (= 44 i)\n (println 45)\n (return-from main))\n (dft! dp)\n (setf (aref dp 0)\n (* (aref dp 0) (aref multiplier 0)))\n (setf (aref dp (ash +dp-size+ -1))\n (* (aref dp (ash +dp-size+ -1)) (aref multiplier (ash +dp-size+ -1))))\n (loop for i from 1 below (ash +dp-size+ -1)\n for value1 = (- (* (aref dp i) (aref multiplier i))\n (* (aref dp (- +dp-size+ i)) (aref multiplier (- +dp-size+ i))))\n for value2 = (+ (* (aref dp i) (aref multiplier (- +dp-size+ i)))\n (* (aref dp (- +dp-size+ i)) (aref multiplier i)))\n do (setf (aref dp i) value1\n (aref dp (- +dp-size+ i)) value2))\n (inverse-dft! dp)\n (dotimes (i k)\n (if (or (> (aref dp i) 0.5f0)\n (> (aref dp (+ i k)) 0.5f0))\n (setf (aref dp i) 1f0)\n (setf (aref dp i) 0f0))\n (setf (aref dp (+ i k)) 0f0))\n (loop for i from (* 2 k) below +dp-size+\n do (setf (aref dp i) 0f0))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1562360128, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03558.html", "problem_id": "p03558", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03558/input.txt", "sample_output_relpath": "derived/input_output/data/p03558/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03558/Lisp/s179486083.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s179486083", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Real FFT\n;;;\n;;; Reference:\n;;; http://www.kurims.kyoto-u.ac.jp/~ooura/fftman/ftmn2_12.html#sec2_1_2\n;;;\n\n(deftype fft-float () 'single-float)\n\n(declaim (inline power2-p))\n(defun power2-p (x)\n \"Checks if X is a power of 2.\"\n (zerop (logand x (- x 1))))\n\n;; For FFT of fixed length, preparing the table of cos(i*theta) and sin\n;; (i*theta) will be efficient.\n(defun %make-trifunc-table (n)\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) n))\n (assert (power2-p n))\n (let* ((cos-table (make-array (ash n -2) :element-type 'fft-float))\n (sin-table (make-array (ash n -2) :element-type 'fft-float))\n (theta (/ (coerce (* 2 pi) 'fft-float) n)))\n (dotimes (i (ash n -2))\n (setf (aref cos-table i) (cos (* i theta))\n (aref sin-table i) (sin (* i theta))))\n (values cos-table sin-table)))\n\n(defparameter *cos-table* nil)\n(defparameter *sin-table* nil)\n\n(defmacro with-fixed-base (size &body body)\n \"Makes FFT faster when the SIZE of target vectors is fixed in BODY. This macro\ncomputes and holds the roots of unity for SIZE, which DFT! and INVERSE-DFT!\ncalled in BODY automatically detects; they will signal an error when they\nreceive a vector of different size.\"\n (let ((s (gensym)))\n `(let ((,s ,size))\n (multiple-value-bind (*cos-table* *sin-table*) (%make-trifunc-table ,s)\n ,@body))))\n\n(defun %dft-fixed-base! (f)\n (declare #.OPT\n ((simple-array fft-float (*)) f))\n (prog1 f\n (let* ((n (length f))\n (cos-table *cos-table*)\n (sin-table *sin-table*)\n (factor n))\n (declare ((integer 0 #.most-positive-fixnum) factor)\n ((simple-array fft-float (*)) cos-table sin-table))\n (assert (power2-p n))\n (assert (= (ash n -2) (length cos-table)))\n ;; bit-reverse ordering\n (let ((i 0))\n (declare ((integer 0 #.most-positive-fixnum) i))\n (loop for j from 1 below (- n 1)\n do (loop for k of-type (integer 0 #.most-positive-fixnum)\n = (ash n -1) then (ash k -1)\n while (> k (setq i (logxor i k))))\n (when (< j i)\n (rotatef (aref f i) (aref f j)))))\n (do* ((mh 1 m)\n (m (ash mh 1) (ash mh 1)))\n ((> m n))\n (declare ((integer 0 #.most-positive-fixnum) mh m))\n (let ((mq (ash mh -1)))\n (setq factor (ash factor -1))\n (do ((jr 0 (+ jr m)))\n ((>= jr n))\n (declare ((integer 0 #.most-positive-fixnum) jr))\n (let ((xreal (aref f (+ jr mh))))\n (setf (aref f (+ jr mh)) (- (aref f jr) xreal))\n (incf (aref f jr) xreal)))\n (do ((i 1 (+ i 1))\n (table-index factor (+ table-index factor)))\n ((>= i mq))\n (declare ((integer 0 #.most-positive-fixnum) i table-index))\n (let* ((wreal (aref cos-table table-index))\n (wimag (- (aref sin-table table-index))))\n (do ((j 0 (+ j m)))\n ((>= j n))\n (let* ((j+mh (+ j mh))\n (j+m-i (- (+ j m) i))\n (xreal (+ (* wreal (aref f (+ j+mh i)))\n (* wimag (aref f j+m-i))))\n (ximag (- (* wreal (aref f j+m-i))\n (* wimag (aref f (+ j+mh i))))))\n (declare ((integer 0 #.most-positive-fixnum) j+mh j+m-i))\n (setf (aref f (+ j+mh i))\n (+ (- (aref f (- j+mh i))) ximag))\n (setf (aref f j+m-i)\n (+ (aref f (- j+mh i)) ximag))\n (setf (aref f (- j+mh i))\n (+ (aref f (+ j i)) (- xreal)))\n (incf (aref f (+ j i)) xreal))))))))))\n\n(defun %inverse-dft-fixed-base! (f)\n (declare #.OPT\n ((simple-array fft-float (*)) f))\n (prog1 f\n (let* ((n (length f))\n (cos-table *cos-table*)\n (sin-table *sin-table*)\n (factor 1))\n (declare ((integer 0 #.most-positive-fixnum) factor)\n ((simple-array fft-float (*)) cos-table sin-table))\n (assert (power2-p n))\n (assert (= (ash n -2) (length cos-table)))\n (setf (aref f 0)\n (/ (aref f 0) 2))\n (setf (aref f (ash n -1))\n (/ (aref f (ash n -1)) 2))\n (do* ((m n mh)\n (mh (ash m -1) (ash m -1)))\n ((zerop mh))\n (declare ((integer 0 #.most-positive-fixnum) m mh))\n (let ((mq (ash mh -1)))\n (do ((jr 0 (+ jr m)))\n ((>= jr n))\n (declare ((integer 0 #.most-positive-fixnum) jr))\n (let ((xreal (- (aref f jr) (aref f (+ jr mh)))))\n (incf (aref f jr) (aref f (+ jr mh)))\n (setf (aref f (+ jr mh)) xreal)))\n (do ((i 1 (+ i 1))\n (table-index factor (+ factor table-index)))\n ((>= i mq))\n (declare ((integer 0 #.most-positive-fixnum) i table-index))\n (let* ((wreal (aref cos-table table-index))\n (wimag (aref sin-table table-index)))\n (do ((j 0 (+ j m)))\n ((>= j n))\n (let* ((j+mh (+ j mh))\n (j+m-i (- (+ j m) i))\n (xreal (- (aref f (+ j i)) (aref f (- j+mh i))))\n (ximag (+ (aref f j+m-i) (aref f (+ j+mh i)))))\n (declare ((integer 0 #.most-positive-fixnum) j+mh j+m-i))\n (incf (aref f (+ j i)) (aref f (- j+mh i)))\n (setf (aref f (- j+mh i))\n (- (aref f j+m-i) (aref f (+ j+mh i))))\n (setf (aref f (+ j+mh i))\n (+ (* wreal xreal) (* wimag ximag)))\n (setf (aref f j+m-i)\n (- (* wreal ximag) (* wimag xreal))))))))\n (setq factor (ash factor 1)))\n ;; bit-reverse ordering\n (let ((i 0))\n (declare ((integer 0 #.most-positive-fixnum) i))\n (loop for j from 1 below (- n 1)\n do (loop for k of-type (integer 0 #.most-positive-fixnum)\n = (ash n -1) then (ash k -1)\n while (> k (setq i (logxor i k))))\n (when (< j i)\n (rotatef (aref f i) (aref f j))))))))\n\n(declaim (inline dft!))\n(defun dft! (f)\n (declare ((simple-array fft-float (*)) f))\n (if (zerop (length f))\n f\n (%dft-fixed-base! f)))\n\n(declaim (inline inverse-dft!))\n(defun inverse-dft! (f)\n (declare ((simple-array fft-float (*)) f))\n (prog1 f\n (let ((n (length f)))\n (unless (zerop n)\n (let ((factor (* 2 (/ (coerce n 'fft-float)))))\n (%inverse-dft-fixed-base! f)\n (dotimes (i n)\n (setf (aref f i) (* (aref f i) factor))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; Body\n(defconstant +dp-size+ (ash 1 18))\n\n(defun main ()\n (declare #.OPT)\n (let* ((k (read))\n (dp (make-array +dp-size+ :element-type 'fft-float :initial-element 0f0))\n (multiplier (make-array +dp-size+ :element-type 'fft-float :initial-element 0f0)))\n (declare ((integer 0 100000) k)\n ((simple-array fft-float (#.+dp-size+)) dp multiplier))\n (loop for i = 1 then (rem (* i 10) k)\n while (= 0f0 (aref dp i))\n do (setf (aref dp i) 1f0\n (aref multiplier i) 1f0))\n (with-fixed-base +dp-size+\n (dft! multiplier)\n (loop for i from 1 to 45\n do (when (= 1f0 (aref dp 0))\n (println i)\n (return-from main))\n (when (= 44 i)\n (println 45)\n (return-from main))\n (dft! dp)\n (setf (aref dp 0)\n (* (aref dp 0) (aref multiplier 0)))\n (setf (aref dp (ash +dp-size+ -1))\n (* (aref dp (ash +dp-size+ -1)) (aref multiplier (ash +dp-size+ -1))))\n (loop for i from 1 below (ash +dp-size+ -1)\n for value1 = (- (* (aref dp i) (aref multiplier i))\n (* (aref dp (- +dp-size+ i)) (aref multiplier (- +dp-size+ i))))\n for value2 = (+ (* (aref dp i) (aref multiplier (- +dp-size+ i)))\n (* (aref dp (- +dp-size+ i)) (aref multiplier i)))\n do (setf (aref dp i) value1\n (aref dp (- +dp-size+ i)) value2))\n (inverse-dft! dp)\n (dotimes (i k)\n (if (or (> (aref dp i) 0.5f0)\n (> (aref dp (+ i k)) 0.5f0))\n (setf (aref dp i) 1f0)\n (setf (aref dp i) 0f0))\n (setf (aref dp (+ i k)) 0f0))\n (loop for i from (* 2 k) below +dp-size+\n do (setf (aref dp i) 0f0))))))\n\n#-swank(main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nFind the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nConstraints\n\n2 \\leq K \\leq 10^5\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nSample Input 1\n\n6\n\nSample Output 1\n\n3\n\n12=6×2 yields the smallest sum.\n\nSample Input 2\n\n41\n\nSample Output 2\n\n5\n\n11111=41×271 yields the smallest sum.\n\nSample Input 3\n\n79992\n\nSample Output 3\n\n36", "sample_input": "6\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03558", "source_text": "Score : 700 points\n\nProblem Statement\n\nFind the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nConstraints\n\n2 \\leq K \\leq 10^5\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nSample Input 1\n\n6\n\nSample Output 1\n\n3\n\n12=6×2 yields the smallest sum.\n\nSample Input 2\n\n41\n\nSample Output 2\n\n5\n\n11111=41×271 yields the smallest sum.\n\nSample Input 3\n\n79992\n\nSample Output 3\n\n36", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9810, "cpu_time_ms": 1654, "memory_kb": 23016}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s857008668", "group_id": "codeNet:p03560", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; -*- coding:utf-8 -*-\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n (pop (queue-list queue)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n(defun main ()\n (declare #.OPT)\n (sb-int:with-progressive-timeout (remaining-time :seconds 1.92)\n (let* ((k (read))\n (queue (make-queue))\n (power10-table (make-array k :element-type 'bit :initial-element 0))\n (dist-table (make-array k :element-type 'uint8 :initial-element #xff)))\n (declare (uint32 k))\n (loop for x = 1 then (mod (* x 10) k)\n until (= 1 (aref power10-table x))\n do (setf (aref power10-table x) 1\n (aref dist-table x) 1)\n (enqueue x queue)\n (when (zerop x)\n (println 1)\n (return-from main)))\n (let ((delta-vec (make-array (count 1 power10-table) :element-type 'uint32))\n (index 0)\n (counter 0))\n (declare (uint32 counter))\n (dotimes (x k)\n (when (= 1 (aref power10-table x))\n (setf (aref delta-vec index) x)\n (incf index)))\n (loop for x of-type uint32 = (dequeue queue)\n do (sb-int:dovector (delta delta-vec)\n (incf counter)\n (let ((dest (mod (+ delta x) k)))\n (when (zerop dest)\n (println (+ 1 (aref dist-table x)))\n (return-from main))\n (when (= #xff (aref dist-table dest))\n (setf (aref dist-table dest)\n (+ 1 (aref dist-table x)))\n (enqueue dest queue))))\n (when (>= counter 100000)\n (setq counter 0)\n (when (zerop (remaining-time))\n (println 3)\n (return-from main))))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1562444593, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03560.html", "problem_id": "p03560", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03560/input.txt", "sample_output_relpath": "derived/input_output/data/p03560/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03560/Lisp/s857008668.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s857008668", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; -*- coding:utf-8 -*-\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n (pop (queue-list queue)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n(defun main ()\n (declare #.OPT)\n (sb-int:with-progressive-timeout (remaining-time :seconds 1.92)\n (let* ((k (read))\n (queue (make-queue))\n (power10-table (make-array k :element-type 'bit :initial-element 0))\n (dist-table (make-array k :element-type 'uint8 :initial-element #xff)))\n (declare (uint32 k))\n (loop for x = 1 then (mod (* x 10) k)\n until (= 1 (aref power10-table x))\n do (setf (aref power10-table x) 1\n (aref dist-table x) 1)\n (enqueue x queue)\n (when (zerop x)\n (println 1)\n (return-from main)))\n (let ((delta-vec (make-array (count 1 power10-table) :element-type 'uint32))\n (index 0)\n (counter 0))\n (declare (uint32 counter))\n (dotimes (x k)\n (when (= 1 (aref power10-table x))\n (setf (aref delta-vec index) x)\n (incf index)))\n (loop for x of-type uint32 = (dequeue queue)\n do (sb-int:dovector (delta delta-vec)\n (incf counter)\n (let ((dest (mod (+ delta x) k)))\n (when (zerop dest)\n (println (+ 1 (aref dist-table x)))\n (return-from main))\n (when (= #xff (aref dist-table dest))\n (setf (aref dist-table dest)\n (+ 1 (aref dist-table x)))\n (enqueue dest queue))))\n (when (>= counter 100000)\n (setq counter 0)\n (when (zerop (remaining-time))\n (println 3)\n (return-from main))))))))\n\n#-swank(main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nFind the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nConstraints\n\n2 \\leq K \\leq 10^5\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nSample Input 1\n\n6\n\nSample Output 1\n\n3\n\n12=6×2 yields the smallest sum.\n\nSample Input 2\n\n41\n\nSample Output 2\n\n5\n\n11111=41×271 yields the smallest sum.\n\nSample Input 3\n\n79992\n\nSample Output 3\n\n36", "sample_input": "6\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03560", "source_text": "Score : 700 points\n\nProblem Statement\n\nFind the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nConstraints\n\n2 \\leq K \\leq 10^5\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nSample Input 1\n\n6\n\nSample Output 1\n\n3\n\n12=6×2 yields the smallest sum.\n\nSample Input 2\n\n41\n\nSample Output 2\n\n5\n\n11111=41×271 yields the smallest sum.\n\nSample Input 3\n\n79992\n\nSample Output 3\n\n36", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3476, "cpu_time_ms": 1990, "memory_kb": 16872}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s890836002", "group_id": "codeNet:p03560", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; -*- coding:utf-8 -*-\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n (pop (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n(defun calc-order (k)\n (let* ((power10-table (make-array k :element-type 'bit :initial-element 0)))\n (declare (uint32 k))\n (loop for x = 1 then (mod (* x 10) k)\n until (= 1 (aref power10-table x))\n do (setf (aref power10-table x) 1))\n (count 1 power10-table)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((start-time (get-internal-real-time))\n (k (read))\n (queue (make-queue))\n (power10-table (make-array k :element-type 'bit :initial-element 0))\n (dist-table (make-array k :element-type 'uint32 :initial-element #xffffffff)))\n (declare (uint32 k))\n (loop for x = 1 then (mod (* x 10) k)\n until (= 1 (aref power10-table x))\n do (setf (aref power10-table x) 1\n (aref dist-table x) 1)\n (enqueue x queue)\n (when (zerop x)\n (println 1)\n (return-from main)))\n (let ((delta-vec (make-array (count 1 power10-table) :element-type 'uint32))\n (index 0)\n (counter 0))\n (declare (uint32 counter))\n (dotimes (x k)\n (when (= 1 (aref power10-table x))\n (setf (aref delta-vec index) x)\n (incf index)))\n (loop for x of-type uint32 = (dequeue queue)\n do (sb-int:dovector (delta delta-vec)\n (incf counter)\n (let ((dest (mod (+ delta x) k)))\n (when (zerop dest)\n (println (+ 1 (aref dist-table x)))\n (return-from main))\n (when (= #xffffffff (aref dist-table dest))\n (setf (aref dist-table dest)\n (+ 1 (aref dist-table x)))\n (enqueue dest queue))))\n (when (>= counter 100000)\n (setq counter 0)\n (when (>= (- (get-internal-real-time) start-time) 1870)\n (println 3)\n (return-from main)))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1562374102, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03560.html", "problem_id": "p03560", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03560/input.txt", "sample_output_relpath": "derived/input_output/data/p03560/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03560/Lisp/s890836002.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s890836002", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; -*- coding:utf-8 -*-\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n (pop (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n(defun calc-order (k)\n (let* ((power10-table (make-array k :element-type 'bit :initial-element 0)))\n (declare (uint32 k))\n (loop for x = 1 then (mod (* x 10) k)\n until (= 1 (aref power10-table x))\n do (setf (aref power10-table x) 1))\n (count 1 power10-table)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((start-time (get-internal-real-time))\n (k (read))\n (queue (make-queue))\n (power10-table (make-array k :element-type 'bit :initial-element 0))\n (dist-table (make-array k :element-type 'uint32 :initial-element #xffffffff)))\n (declare (uint32 k))\n (loop for x = 1 then (mod (* x 10) k)\n until (= 1 (aref power10-table x))\n do (setf (aref power10-table x) 1\n (aref dist-table x) 1)\n (enqueue x queue)\n (when (zerop x)\n (println 1)\n (return-from main)))\n (let ((delta-vec (make-array (count 1 power10-table) :element-type 'uint32))\n (index 0)\n (counter 0))\n (declare (uint32 counter))\n (dotimes (x k)\n (when (= 1 (aref power10-table x))\n (setf (aref delta-vec index) x)\n (incf index)))\n (loop for x of-type uint32 = (dequeue queue)\n do (sb-int:dovector (delta delta-vec)\n (incf counter)\n (let ((dest (mod (+ delta x) k)))\n (when (zerop dest)\n (println (+ 1 (aref dist-table x)))\n (return-from main))\n (when (= #xffffffff (aref dist-table dest))\n (setf (aref dist-table dest)\n (+ 1 (aref dist-table x)))\n (enqueue dest queue))))\n (when (>= counter 100000)\n (setq counter 0)\n (when (>= (- (get-internal-real-time) start-time) 1870)\n (println 3)\n (return-from main)))))))\n\n#-swank(main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nFind the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nConstraints\n\n2 \\leq K \\leq 10^5\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nSample Input 1\n\n6\n\nSample Output 1\n\n3\n\n12=6×2 yields the smallest sum.\n\nSample Input 2\n\n41\n\nSample Output 2\n\n5\n\n11111=41×271 yields the smallest sum.\n\nSample Input 3\n\n79992\n\nSample Output 3\n\n36", "sample_input": "6\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03560", "source_text": "Score : 700 points\n\nProblem Statement\n\nFind the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nConstraints\n\n2 \\leq K \\leq 10^5\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nSample Input 1\n\n6\n\nSample Output 1\n\n3\n\n12=6×2 yields the smallest sum.\n\nSample Input 2\n\n41\n\nSample Output 2\n\n5\n\n11111=41×271 yields the smallest sum.\n\nSample Input 3\n\n79992\n\nSample Output 3\n\n36", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3991, "cpu_time_ms": 1961, "memory_kb": 29148}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s340936414", "group_id": "codeNet:p03560", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; -*- coding:utf-8 -*-\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n (pop (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n(defun calc-order (k)\n (let* ((power10-table (make-array k :element-type 'bit :initial-element 0)))\n (declare (uint32 k))\n (loop for x = 1 then (mod (* x 10) k)\n until (= 1 (aref power10-table x))\n do (setf (aref power10-table x) 1))\n (count 1 power10-table)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((start-time (get-internal-real-time))\n (k (read))\n (queue (make-queue))\n (power10-table (make-array k :element-type 'bit :initial-element 0))\n (dist-table (make-array k :element-type 'uint32 :initial-element #xffffffff)))\n (declare (uint32 k))\n (loop for x = 1 then (mod (* x 10) k)\n until (= 1 (aref power10-table x))\n do (setf (aref power10-table x) 1\n (aref dist-table x) 1)\n (enqueue x queue)\n (when (zerop x)\n (println 1)\n (return-from main)))\n (let ((delta-vec (make-array (count 1 power10-table) :element-type 'uint32))\n (index 0)\n (counter 0))\n (declare (uint32 counter))\n (dotimes (x k)\n (when (= 1 (aref power10-table x))\n (setf (aref delta-vec index) x)\n (incf index)))\n (loop for x of-type uint32 = (dequeue queue)\n do (sb-int:dovector (delta delta-vec)\n (incf counter)\n (let ((dest (mod (+ delta x) k)))\n (when (zerop dest)\n (println (+ 1 (aref dist-table x)))\n (return-from main))\n (when (= #xffffffff (aref dist-table dest))\n (setf (aref dist-table dest)\n (+ 1 (aref dist-table x)))\n (enqueue dest queue))))\n (when (>= counter 100000)\n (setq counter 0)\n (when (>= (- (get-internal-real-time) start-time) 1800)\n (println 3)\n (return-from main)))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1562374007, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03560.html", "problem_id": "p03560", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03560/input.txt", "sample_output_relpath": "derived/input_output/data/p03560/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03560/Lisp/s340936414.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s340936414", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; -*- coding:utf-8 -*-\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n (pop (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n(defun calc-order (k)\n (let* ((power10-table (make-array k :element-type 'bit :initial-element 0)))\n (declare (uint32 k))\n (loop for x = 1 then (mod (* x 10) k)\n until (= 1 (aref power10-table x))\n do (setf (aref power10-table x) 1))\n (count 1 power10-table)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((start-time (get-internal-real-time))\n (k (read))\n (queue (make-queue))\n (power10-table (make-array k :element-type 'bit :initial-element 0))\n (dist-table (make-array k :element-type 'uint32 :initial-element #xffffffff)))\n (declare (uint32 k))\n (loop for x = 1 then (mod (* x 10) k)\n until (= 1 (aref power10-table x))\n do (setf (aref power10-table x) 1\n (aref dist-table x) 1)\n (enqueue x queue)\n (when (zerop x)\n (println 1)\n (return-from main)))\n (let ((delta-vec (make-array (count 1 power10-table) :element-type 'uint32))\n (index 0)\n (counter 0))\n (declare (uint32 counter))\n (dotimes (x k)\n (when (= 1 (aref power10-table x))\n (setf (aref delta-vec index) x)\n (incf index)))\n (loop for x of-type uint32 = (dequeue queue)\n do (sb-int:dovector (delta delta-vec)\n (incf counter)\n (let ((dest (mod (+ delta x) k)))\n (when (zerop dest)\n (println (+ 1 (aref dist-table x)))\n (return-from main))\n (when (= #xffffffff (aref dist-table dest))\n (setf (aref dist-table dest)\n (+ 1 (aref dist-table x)))\n (enqueue dest queue))))\n (when (>= counter 100000)\n (setq counter 0)\n (when (>= (- (get-internal-real-time) start-time) 1800)\n (println 3)\n (return-from main)))))))\n\n#-swank(main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nFind the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nConstraints\n\n2 \\leq K \\leq 10^5\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nSample Input 1\n\n6\n\nSample Output 1\n\n3\n\n12=6×2 yields the smallest sum.\n\nSample Input 2\n\n41\n\nSample Output 2\n\n5\n\n11111=41×271 yields the smallest sum.\n\nSample Input 3\n\n79992\n\nSample Output 3\n\n36", "sample_input": "6\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03560", "source_text": "Score : 700 points\n\nProblem Statement\n\nFind the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nConstraints\n\n2 \\leq K \\leq 10^5\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nSample Input 1\n\n6\n\nSample Output 1\n\n3\n\n12=6×2 yields the smallest sum.\n\nSample Input 2\n\n41\n\nSample Output 2\n\n5\n\n11111=41×271 yields the smallest sum.\n\nSample Input 3\n\n79992\n\nSample Output 3\n\n36", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3991, "cpu_time_ms": 1897, "memory_kb": 37600}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s015767432", "group_id": "codeNet:p03560", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; -*- coding:utf-8 -*-\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n (pop (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n(defun calc-order (k)\n (let* ((power10-table (make-array k :element-type 'bit :initial-element 0)))\n (declare (uint32 k))\n (loop for x = 1 then (mod (* x 10) k)\n until (= 1 (aref power10-table x))\n do (setf (aref power10-table x) 1))\n (count 1 power10-table)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((k (read))\n (queue (make-queue))\n (power10-table (make-array k :element-type 'bit :initial-element 0))\n (dist-table (make-array k :element-type 'uint32 :initial-element #xffffffff)))\n (declare (uint32 k))\n (loop for x = 1 then (mod (* x 10) k)\n until (= 1 (aref power10-table x))\n do (setf (aref power10-table x) 1\n (aref dist-table x) 1)\n (enqueue x queue)\n (when (zerop x)\n (println 1)\n (return-from main)))\n (let ((delta-vec (make-array (count 1 power10-table) :element-type 'uint32))\n (index 0))\n (dotimes (x k)\n (when (= 1 (aref power10-table x))\n (setf (aref delta-vec index) x)\n (incf index)))\n (loop for x of-type uint32 = (dequeue queue)\n do (sb-int:dovector (delta delta-vec)\n (let ((dest (mod (+ delta x) k)))\n (when (zerop dest)\n (println (+ 1 (aref dist-table x)))\n (return-from main))\n (when (= #xffffffff (aref dist-table dest))\n (setf (aref dist-table dest)\n (+ 1 (aref dist-table x)))\n (enqueue dest queue))))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1562368742, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03560.html", "problem_id": "p03560", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03560/input.txt", "sample_output_relpath": "derived/input_output/data/p03560/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03560/Lisp/s015767432.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s015767432", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; -*- coding:utf-8 -*-\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n (pop (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n(defun calc-order (k)\n (let* ((power10-table (make-array k :element-type 'bit :initial-element 0)))\n (declare (uint32 k))\n (loop for x = 1 then (mod (* x 10) k)\n until (= 1 (aref power10-table x))\n do (setf (aref power10-table x) 1))\n (count 1 power10-table)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((k (read))\n (queue (make-queue))\n (power10-table (make-array k :element-type 'bit :initial-element 0))\n (dist-table (make-array k :element-type 'uint32 :initial-element #xffffffff)))\n (declare (uint32 k))\n (loop for x = 1 then (mod (* x 10) k)\n until (= 1 (aref power10-table x))\n do (setf (aref power10-table x) 1\n (aref dist-table x) 1)\n (enqueue x queue)\n (when (zerop x)\n (println 1)\n (return-from main)))\n (let ((delta-vec (make-array (count 1 power10-table) :element-type 'uint32))\n (index 0))\n (dotimes (x k)\n (when (= 1 (aref power10-table x))\n (setf (aref delta-vec index) x)\n (incf index)))\n (loop for x of-type uint32 = (dequeue queue)\n do (sb-int:dovector (delta delta-vec)\n (let ((dest (mod (+ delta x) k)))\n (when (zerop dest)\n (println (+ 1 (aref dist-table x)))\n (return-from main))\n (when (= #xffffffff (aref dist-table dest))\n (setf (aref dist-table dest)\n (+ 1 (aref dist-table x)))\n (enqueue dest queue))))))))\n\n#-swank(main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nFind the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nConstraints\n\n2 \\leq K \\leq 10^5\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nSample Input 1\n\n6\n\nSample Output 1\n\n3\n\n12=6×2 yields the smallest sum.\n\nSample Input 2\n\n41\n\nSample Output 2\n\n5\n\n11111=41×271 yields the smallest sum.\n\nSample Input 3\n\n79992\n\nSample Output 3\n\n36", "sample_input": "6\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03560", "source_text": "Score : 700 points\n\nProblem Statement\n\nFind the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nConstraints\n\n2 \\leq K \\leq 10^5\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nSample Input 1\n\n6\n\nSample Output 1\n\n3\n\n12=6×2 yields the smallest sum.\n\nSample Input 2\n\n41\n\nSample Output 2\n\n5\n\n11111=41×271 yields the smallest sum.\n\nSample Input 3\n\n79992\n\nSample Output 3\n\n36", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3638, "cpu_time_ms": 2104, "memory_kb": 29792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s658807025", "group_id": "codeNet:p03560", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; -*- coding:utf-8 -*-\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n (pop (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n(defun solve (k)\n ;; (num . cost)\n (declare #.OPT\n (uint31 k))\n (if (= k 1)\n 1\n (let ((queue (make-queue))\n (marked (make-array k :element-type 'bit :initial-element 0)))\n (enqueue (cons 1 1) queue)\n (setf (aref marked 1) 1)\n (loop for (num . cost) of-type (uint32 . uint62) = (dequeue queue)\n do (when (zerop num)\n (return cost))\n (let ((num*10 (mod (* 10 num) k)))\n (when (zerop (aref marked num*10))\n (setf (aref marked num*10) 1)\n (enqueue-front (cons num*10 cost) queue)))\n (let ((num+1 (mod (+ num 1) k)))\n (when (zerop (aref marked num+1))\n (setf (aref marked num+1) 1)\n (enqueue (cons num+1 (+ cost 1)) queue)))))))\n\n(defun main ()\n (let* ((k (read)))\n (println (solve k))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1554955640, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03560.html", "problem_id": "p03560", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03560/input.txt", "sample_output_relpath": "derived/input_output/data/p03560/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03560/Lisp/s658807025.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s658807025", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; -*- coding:utf-8 -*-\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n (pop (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n(defun solve (k)\n ;; (num . cost)\n (declare #.OPT\n (uint31 k))\n (if (= k 1)\n 1\n (let ((queue (make-queue))\n (marked (make-array k :element-type 'bit :initial-element 0)))\n (enqueue (cons 1 1) queue)\n (setf (aref marked 1) 1)\n (loop for (num . cost) of-type (uint32 . uint62) = (dequeue queue)\n do (when (zerop num)\n (return cost))\n (let ((num*10 (mod (* 10 num) k)))\n (when (zerop (aref marked num*10))\n (setf (aref marked num*10) 1)\n (enqueue-front (cons num*10 cost) queue)))\n (let ((num+1 (mod (+ num 1) k)))\n (when (zerop (aref marked num+1))\n (setf (aref marked num+1) 1)\n (enqueue (cons num+1 (+ cost 1)) queue)))))))\n\n(defun main ()\n (let* ((k (read)))\n (println (solve k))))\n\n#-swank(main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nFind the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nConstraints\n\n2 \\leq K \\leq 10^5\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nSample Input 1\n\n6\n\nSample Output 1\n\n3\n\n12=6×2 yields the smallest sum.\n\nSample Input 2\n\n41\n\nSample Output 2\n\n5\n\n11111=41×271 yields the smallest sum.\n\nSample Input 3\n\n79992\n\nSample Output 3\n\n36", "sample_input": "6\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03560", "source_text": "Score : 700 points\n\nProblem Statement\n\nFind the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nConstraints\n\n2 \\leq K \\leq 10^5\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint the smallest possible sum of the digits in the decimal notation of a positive multiple of K.\n\nSample Input 1\n\n6\n\nSample Output 1\n\n3\n\n12=6×2 yields the smallest sum.\n\nSample Input 2\n\n41\n\nSample Output 2\n\n5\n\n11111=41×271 yields the smallest sum.\n\nSample Input 3\n\n79992\n\nSample Output 3\n\n36", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2962, "cpu_time_ms": 243, "memory_kb": 23528}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s465191020", "group_id": "codeNet:p03563", "input_text": "(setq A (read))\n(setq B (read))\n(format t \"~D~%\"\n (+\n (-\n B\n A\n )\n B\n )\n )\n", "language": "Lisp", "metadata": {"date": 1558274751, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03563.html", "problem_id": "p03563", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03563/input.txt", "sample_output_relpath": "derived/input_output/data/p03563/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03563/Lisp/s465191020.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s465191020", "user_id": "u493610446"}, "prompt_components": {"gold_output": "2032\n", "input_to_evaluate": "(setq A (read))\n(setq B (read))\n(format t \"~D~%\"\n (+\n (-\n B\n A\n )\n B\n )\n )\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi is a user of a site that hosts programming contests.\n\nWhen a user competes in a contest, the rating of the user (not necessarily an integer) changes according to the performance of the user, as follows:\n\nLet the current rating of the user be a.\n\nSuppose that the performance of the user in the contest is b.\n\nThen, the new rating of the user will be the avarage of a and b.\n\nFor example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000.\n\nTakahashi's current rating is R, and he wants his rating to be exactly G after the next contest.\n\nFind the performance required to achieve it.\n\nConstraints\n\n0 \\leq R, G \\leq 4500\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR\nG\n\nOutput\n\nPrint the performance required to achieve the objective.\n\nSample Input 1\n\n2002\n2017\n\nSample Output 1\n\n2032\n\nTakahashi's current rating is 2002.\n\nIf his performance in the contest is 2032, his rating will be the average of 2002 and 2032, which is equal to the desired rating, 2017.\n\nSample Input 2\n\n4500\n0\n\nSample Output 2\n\n-4500\n\nAlthough the current and desired ratings are between 0 and 4500, the performance of a user can be below 0.", "sample_input": "2002\n2017\n"}, "reference_outputs": ["2032\n"], "source_document_id": "p03563", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi is a user of a site that hosts programming contests.\n\nWhen a user competes in a contest, the rating of the user (not necessarily an integer) changes according to the performance of the user, as follows:\n\nLet the current rating of the user be a.\n\nSuppose that the performance of the user in the contest is b.\n\nThen, the new rating of the user will be the avarage of a and b.\n\nFor example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000.\n\nTakahashi's current rating is R, and he wants his rating to be exactly G after the next contest.\n\nFind the performance required to achieve it.\n\nConstraints\n\n0 \\leq R, G \\leq 4500\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR\nG\n\nOutput\n\nPrint the performance required to achieve the objective.\n\nSample Input 1\n\n2002\n2017\n\nSample Output 1\n\n2032\n\nTakahashi's current rating is 2002.\n\nIf his performance in the contest is 2032, his rating will be the average of 2002 and 2032, which is equal to the desired rating, 2017.\n\nSample Input 2\n\n4500\n0\n\nSample Output 2\n\n-4500\n\nAlthough the current and desired ratings are between 0 and 4500, the performance of a user can be below 0.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 149, "cpu_time_ms": 83, "memory_kb": 8288}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s438605213", "group_id": "codeNet:p03564", "input_text": "(let* ((a (read))\n (b (read))\n (ans 1))\n (loop :repeat a :do(if (< b ans)\n (setq ans (+ ans b))\n (setq ans (+ ans ans))))\n (princ ans))", "language": "Lisp", "metadata": {"date": 1551727277, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03564.html", "problem_id": "p03564", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03564/input.txt", "sample_output_relpath": "derived/input_output/data/p03564/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03564/Lisp/s438605213.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s438605213", "user_id": "u610490393"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(let* ((a (read))\n (b (read))\n (ans 1))\n (loop :repeat a :do(if (< b ans)\n (setq ans (+ ans b))\n (setq ans (+ ans ans))))\n (princ ans))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nSquare1001 has seen an electric bulletin board displaying the integer 1.\nHe can perform the following operations A and B to change this value:\n\nOperation A: The displayed value is doubled.\n\nOperation B: The displayed value increases by K.\n\nSquare1001 needs to perform these operations N times in total.\nFind the minimum possible value displayed in the board after N operations.\n\nConstraints\n\n1 \\leq N, K \\leq 10\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nK\n\nOutput\n\nPrint the minimum possible value displayed in the board after N operations.\n\nSample Input 1\n\n4\n3\n\nSample Output 1\n\n10\n\nThe value will be minimized when the operations are performed in the following order: A, A, B, B.\n\nIn this case, the value will change as follows: 1 → 2 → 4 → 7 → 10.\n\nSample Input 2\n\n10\n10\n\nSample Output 2\n\n76\n\nThe value will be minimized when the operations are performed in the following order: A, A, A, A, B, B, B, B, B, B.\n\nIn this case, the value will change as follows: 1 → 2 → 4 → 8 → 16 → 26 → 36 → 46 → 56 → 66 → 76.\n\nBy the way, this contest is AtCoder Beginner Contest 076.", "sample_input": "4\n3\n"}, "reference_outputs": ["10\n"], "source_document_id": "p03564", "source_text": "Score : 200 points\n\nProblem Statement\n\nSquare1001 has seen an electric bulletin board displaying the integer 1.\nHe can perform the following operations A and B to change this value:\n\nOperation A: The displayed value is doubled.\n\nOperation B: The displayed value increases by K.\n\nSquare1001 needs to perform these operations N times in total.\nFind the minimum possible value displayed in the board after N operations.\n\nConstraints\n\n1 \\leq N, K \\leq 10\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nK\n\nOutput\n\nPrint the minimum possible value displayed in the board after N operations.\n\nSample Input 1\n\n4\n3\n\nSample Output 1\n\n10\n\nThe value will be minimized when the operations are performed in the following order: A, A, B, B.\n\nIn this case, the value will change as follows: 1 → 2 → 4 → 7 → 10.\n\nSample Input 2\n\n10\n10\n\nSample Output 2\n\n76\n\nThe value will be minimized when the operations are performed in the following order: A, A, A, A, B, B, B, B, B, B.\n\nIn this case, the value will change as follows: 1 → 2 → 4 → 8 → 16 → 26 → 36 → 46 → 56 → 66 → 76.\n\nBy the way, this contest is AtCoder Beginner Contest 076.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 197, "cpu_time_ms": 138, "memory_kb": 12768}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s612976690", "group_id": "codeNet:p03566", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the fixnum (* result 10))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (ts (make-array n :element-type 'uint16))\n (cumul-ts (make-array (+ 1 n) :element-type 'uint16 :initial-element 0))\n (vs (make-array (+ n 1) :element-type 'uint16)))\n (dotimes (i n) (setf (aref ts i) (* 2 (read-fixnum))))\n (dotimes (i n) (setf (aref vs i) (* 2 (read-fixnum))))\n ;; (loop for i from n downto 1\n ;; do (when (> (aref vs (- i 1)) (aref vs i))\n ;; (setf (aref vs (- i 1))\n ;; (min (aref vs (- i 1))\n ;; (+ (aref vs i) (aref ts (- i 1)))))))\n (dotimes (i n)\n (setf (aref cumul-ts (+ i 1))\n (+ (aref cumul-ts i) (aref ts i))))\n (let* ((total-time (reduce #'+ ts))\n (next-points (make-array total-time :element-type 'uint16))\n (prev-points (make-array total-time :element-type 'uint16))\n (time-vs (make-array total-time :element-type 'uint16))\n (time-next-vs (make-array total-time :element-type 'uint16))\n (time-prev-vs (make-array total-time :element-type 'uint16))\n (timeline (make-array (+ total-time 1) :element-type 'uint16 :initial-element 0)))\n (dotimes (i n)\n (loop for time from (aref cumul-ts i) below (aref cumul-ts (+ i 1))\n do (setf (aref next-points time) (aref cumul-ts (+ i 1))\n (aref prev-points time) (aref cumul-ts i)\n (aref time-vs time) (aref vs i)\n (aref time-next-vs time) (aref vs (+ i 1))\n (aref time-prev-vs time) (if (zerop i) 0 (aref vs (- i 1))))))\n (dotimes (time total-time)\n (setf (aref timeline time)\n (min (aref time-vs time)\n (+ (aref time-next-vs time)\n (- (aref next-points time) time))\n (+ (aref time-prev-vs time)\n (- time (aref prev-points time))))))\n (println (/ (loop for time from 0 below total-time\n sum (+ (aref timeline time) (aref timeline (+ 1 time))))\n 8d0)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1555938181, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03566.html", "problem_id": "p03566", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03566/input.txt", "sample_output_relpath": "derived/input_output/data/p03566/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03566/Lisp/s612976690.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s612976690", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2100.000000000000000\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the fixnum (* result 10))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (ts (make-array n :element-type 'uint16))\n (cumul-ts (make-array (+ 1 n) :element-type 'uint16 :initial-element 0))\n (vs (make-array (+ n 1) :element-type 'uint16)))\n (dotimes (i n) (setf (aref ts i) (* 2 (read-fixnum))))\n (dotimes (i n) (setf (aref vs i) (* 2 (read-fixnum))))\n ;; (loop for i from n downto 1\n ;; do (when (> (aref vs (- i 1)) (aref vs i))\n ;; (setf (aref vs (- i 1))\n ;; (min (aref vs (- i 1))\n ;; (+ (aref vs i) (aref ts (- i 1)))))))\n (dotimes (i n)\n (setf (aref cumul-ts (+ i 1))\n (+ (aref cumul-ts i) (aref ts i))))\n (let* ((total-time (reduce #'+ ts))\n (next-points (make-array total-time :element-type 'uint16))\n (prev-points (make-array total-time :element-type 'uint16))\n (time-vs (make-array total-time :element-type 'uint16))\n (time-next-vs (make-array total-time :element-type 'uint16))\n (time-prev-vs (make-array total-time :element-type 'uint16))\n (timeline (make-array (+ total-time 1) :element-type 'uint16 :initial-element 0)))\n (dotimes (i n)\n (loop for time from (aref cumul-ts i) below (aref cumul-ts (+ i 1))\n do (setf (aref next-points time) (aref cumul-ts (+ i 1))\n (aref prev-points time) (aref cumul-ts i)\n (aref time-vs time) (aref vs i)\n (aref time-next-vs time) (aref vs (+ i 1))\n (aref time-prev-vs time) (if (zerop i) 0 (aref vs (- i 1))))))\n (dotimes (time total-time)\n (setf (aref timeline time)\n (min (aref time-vs time)\n (+ (aref time-next-vs time)\n (- (aref next-points time) time))\n (+ (aref time-prev-vs time)\n (- time (aref prev-points time))))))\n (println (/ (loop for time from 0 below total-time\n sum (+ (aref timeline time) (aref timeline (+ 1 time))))\n 8d0)))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nIn the year 2168, AtCoder Inc., which is much larger than now, is starting a limited express train service called AtCoder Express.\n\nIn the plan developed by the president Takahashi, the trains will run as follows:\n\nA train will run for (t_1 + t_2 + t_3 + ... + t_N) seconds.\n\nIn the first t_1 seconds, a train must run at a speed of at most v_1 m/s (meters per second). Similarly, in the subsequent t_2 seconds, a train must run at a speed of at most v_2 m/s, and so on.\n\nAccording to the specifications of the trains, the acceleration of a train must be always within ±1m/s^2. Additionally, a train must stop at the beginning and the end of the run.\n\nFind the maximum possible distance that a train can cover in the run.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq t_i \\leq 200\n\n1 \\leq v_i \\leq 100\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nt_1 t_2 t_3 … t_N\nv_1 v_2 v_3 … v_N\n\nOutput\n\nPrint the maximum possible that a train can cover in the run.\n\nOutput is considered correct if its absolute difference from the judge's output is at most 10^{-3}.\n\nSample Input 1\n\n1\n100\n30\n\nSample Output 1\n\n2100.000000000000000\n\nThe maximum distance is achieved when a train runs as follows:\n\nIn the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n\nIn the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n\nIn the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 + 1200 + 450 = 2100 meters.\n\nSample Input 2\n\n2\n60 50\n34 38\n\nSample Output 2\n\n2632.000000000000000\n\nThe maximum distance is achieved when a train runs as follows:\n\nIn the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n\nIn the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n\nIn the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n\nIn the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n\nIn the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 + 884 + 144 + 304 + 722 = 2632 meters.\n\nSample Input 3\n\n3\n12 14 2\n6 2 7\n\nSample Output 3\n\n76.000000000000000\n\nThe maximum distance is achieved when a train runs as follows:\n\nIn the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n\nIn the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n\nIn the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n\nIn the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n\nIn the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 + 12 + 16 + 28 + 2 = 76 meters.\n\nSample Input 4\n\n1\n9\n10\n\nSample Output 4\n\n20.250000000000000000\n\nThe maximum distance is achieved when a train runs as follows:\n\nIn the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n\nIn the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 + 10.125 = 20.25 meters.\n\nSample Input 5\n\n10\n64 55 27 35 76 119 7 18 49 100\n29 19 31 39 27 48 41 87 55 70\n\nSample Output 5\n\n20291.000000000000", "sample_input": "1\n100\n30\n"}, "reference_outputs": ["2100.000000000000000\n"], "source_document_id": "p03566", "source_text": "Score : 400 points\n\nProblem Statement\n\nIn the year 2168, AtCoder Inc., which is much larger than now, is starting a limited express train service called AtCoder Express.\n\nIn the plan developed by the president Takahashi, the trains will run as follows:\n\nA train will run for (t_1 + t_2 + t_3 + ... + t_N) seconds.\n\nIn the first t_1 seconds, a train must run at a speed of at most v_1 m/s (meters per second). Similarly, in the subsequent t_2 seconds, a train must run at a speed of at most v_2 m/s, and so on.\n\nAccording to the specifications of the trains, the acceleration of a train must be always within ±1m/s^2. Additionally, a train must stop at the beginning and the end of the run.\n\nFind the maximum possible distance that a train can cover in the run.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq t_i \\leq 200\n\n1 \\leq v_i \\leq 100\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nt_1 t_2 t_3 … t_N\nv_1 v_2 v_3 … v_N\n\nOutput\n\nPrint the maximum possible that a train can cover in the run.\n\nOutput is considered correct if its absolute difference from the judge's output is at most 10^{-3}.\n\nSample Input 1\n\n1\n100\n30\n\nSample Output 1\n\n2100.000000000000000\n\nThe maximum distance is achieved when a train runs as follows:\n\nIn the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n\nIn the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n\nIn the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 + 1200 + 450 = 2100 meters.\n\nSample Input 2\n\n2\n60 50\n34 38\n\nSample Output 2\n\n2632.000000000000000\n\nThe maximum distance is achieved when a train runs as follows:\n\nIn the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n\nIn the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n\nIn the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n\nIn the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n\nIn the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 + 884 + 144 + 304 + 722 = 2632 meters.\n\nSample Input 3\n\n3\n12 14 2\n6 2 7\n\nSample Output 3\n\n76.000000000000000\n\nThe maximum distance is achieved when a train runs as follows:\n\nIn the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n\nIn the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n\nIn the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n\nIn the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n\nIn the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 + 12 + 16 + 28 + 2 = 76 meters.\n\nSample Input 4\n\n1\n9\n10\n\nSample Output 4\n\n20.250000000000000000\n\nThe maximum distance is achieved when a train runs as follows:\n\nIn the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n\nIn the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 + 10.125 = 20.25 meters.\n\nSample Input 5\n\n10\n64 55 27 35 76 119 7 18 49 100\n29 19 31 39 27 48 41 87 55 70\n\nSample Output 5\n\n20291.000000000000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4404, "cpu_time_ms": 83, "memory_kb": 16872}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s396387106", "group_id": "codeNet:p03570", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun solve (n s)\n (declare #.OPT\n (uint31 n)\n ((simple-array uint32 (*)) s))\n (let* ((cumul (make-array (+ n 1) :element-type 'uint32 :initial-element 0))\n (highest (make-hash-table :size n :test #'eq)))\n (dotimes (i n)\n (setf (aref cumul (+ i 1))\n (logxor (aref cumul i) (aref s i))))\n (dotimes (i (+ n 1))\n (push i (gethash (aref cumul i) highest)))\n (when (zerop (aref cumul n))\n (return-from solve 1))\n (let ((dp (make-array (+ n 1) :element-type 'uint32 :initial-element #xffffffff)))\n (setf (aref dp 0) 0)\n (dotimes (x n)\n ;; all even\n (let* ((target (aref cumul x))\n (nexts (gethash target highest)))\n (loop repeat 10\n for next of-type (or null uint32) in nexts\n while (and next (> next x))\n do (minf (aref dp next) (+ 1 (aref dp x)))))\n ;; a to z\n (unless (= #xffffffff (aref dp x))\n (dotimes (c 26)\n (let* ((mask (ash 1 c))\n (target (logxor (aref cumul x) mask))\n (nexts (gethash target highest)))\n (loop repeat 10\n for next of-type (or null uint32) in nexts\n while (and next (> next x))\n do (minf (aref dp next) (+ 1 (aref dp x))))))))\n (assert (/= #xffffffff (aref dp n)))\n (aref dp n))))\n\n(defun main ()\n (let* ((orig-s (read-line))\n (n (length orig-s))\n (s (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (let ((c (aref orig-s i)))\n (setf (aref s i) (ash 1 (- (char-code c) 97)))))\n (println (min (solve n s)\n (solve n (reverse s))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"aabxyyzz\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"byebye\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"abcdefghijklmnopqrstuvwxyz\n\"\n \"26\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"abcabcxabcx\n\"\n \"3\n\")))\n", "language": "Lisp", "metadata": {"date": 1586960055, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03570.html", "problem_id": "p03570", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03570/input.txt", "sample_output_relpath": "derived/input_output/data/p03570/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03570/Lisp/s396387106.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s396387106", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun solve (n s)\n (declare #.OPT\n (uint31 n)\n ((simple-array uint32 (*)) s))\n (let* ((cumul (make-array (+ n 1) :element-type 'uint32 :initial-element 0))\n (highest (make-hash-table :size n :test #'eq)))\n (dotimes (i n)\n (setf (aref cumul (+ i 1))\n (logxor (aref cumul i) (aref s i))))\n (dotimes (i (+ n 1))\n (push i (gethash (aref cumul i) highest)))\n (when (zerop (aref cumul n))\n (return-from solve 1))\n (let ((dp (make-array (+ n 1) :element-type 'uint32 :initial-element #xffffffff)))\n (setf (aref dp 0) 0)\n (dotimes (x n)\n ;; all even\n (let* ((target (aref cumul x))\n (nexts (gethash target highest)))\n (loop repeat 10\n for next of-type (or null uint32) in nexts\n while (and next (> next x))\n do (minf (aref dp next) (+ 1 (aref dp x)))))\n ;; a to z\n (unless (= #xffffffff (aref dp x))\n (dotimes (c 26)\n (let* ((mask (ash 1 c))\n (target (logxor (aref cumul x) mask))\n (nexts (gethash target highest)))\n (loop repeat 10\n for next of-type (or null uint32) in nexts\n while (and next (> next x))\n do (minf (aref dp next) (+ 1 (aref dp x))))))))\n (assert (/= #xffffffff (aref dp n)))\n (aref dp n))))\n\n(defun main ()\n (let* ((orig-s (read-line))\n (n (length orig-s))\n (s (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (let ((c (aref orig-s i)))\n (setf (aref s i) (ash 1 (- (char-code c) 97)))))\n (println (min (solve n s)\n (solve n (reverse s))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"aabxyyzz\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"byebye\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"abcdefghijklmnopqrstuvwxyz\n\"\n \"26\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"abcabcxabcx\n\"\n \"3\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nWe have a string s consisting of lowercase English letters.\nSnuke is partitioning s into some number of non-empty substrings.\nLet the subtrings obtained be s_1, s_2, ..., s_N from left to right. (Here, s = s_1 + s_2 + ... + s_N holds.)\nSnuke wants to satisfy the following condition:\n\nFor each i (1 \\leq i \\leq N), it is possible to permute the characters in s_i and obtain a palindrome.\n\nFind the minimum possible value of N when the partition satisfies the condition.\n\nConstraints\n\n1 \\leq |s| \\leq 2 \\times 10^5\n\ns consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the minimum possible value of N when the partition satisfies the condition.\n\nSample Input 1\n\naabxyyzz\n\nSample Output 1\n\n2\n\nThe solution is to partition s as aabxyyzz = aab + xyyzz.\nHere, aab can be permuted to form a palindrome aba, and xyyzz can be permuted to form a palindrome zyxyz.\n\nSample Input 2\n\nbyebye\n\nSample Output 2\n\n1\n\nbyebye can be permuted to form a palindrome byeeyb.\n\nSample Input 3\n\nabcdefghijklmnopqrstuvwxyz\n\nSample Output 3\n\n26\n\nSample Input 4\n\nabcabcxabcx\n\nSample Output 4\n\n3\n\nThe solution is to partition s as abcabcxabcx = a + b + cabcxabcx.", "sample_input": "aabxyyzz\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03570", "source_text": "Score : 700 points\n\nProblem Statement\n\nWe have a string s consisting of lowercase English letters.\nSnuke is partitioning s into some number of non-empty substrings.\nLet the subtrings obtained be s_1, s_2, ..., s_N from left to right. (Here, s = s_1 + s_2 + ... + s_N holds.)\nSnuke wants to satisfy the following condition:\n\nFor each i (1 \\leq i \\leq N), it is possible to permute the characters in s_i and obtain a palindrome.\n\nFind the minimum possible value of N when the partition satisfies the condition.\n\nConstraints\n\n1 \\leq |s| \\leq 2 \\times 10^5\n\ns consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the minimum possible value of N when the partition satisfies the condition.\n\nSample Input 1\n\naabxyyzz\n\nSample Output 1\n\n2\n\nThe solution is to partition s as aabxyyzz = aab + xyyzz.\nHere, aab can be permuted to form a palindrome aba, and xyyzz can be permuted to form a palindrome zyxyz.\n\nSample Input 2\n\nbyebye\n\nSample Output 2\n\n1\n\nbyebye can be permuted to form a palindrome byeeyb.\n\nSample Input 3\n\nabcdefghijklmnopqrstuvwxyz\n\nSample Output 3\n\n26\n\nSample Input 4\n\nabcabcxabcx\n\nSample Output 4\n\n3\n\nThe solution is to partition s as abcabcxabcx = a + b + cabcxabcx.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5631, "cpu_time_ms": 1014, "memory_kb": 64100}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s289937439", "group_id": "codeNet:p03570", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun solve (n s)\n (declare #.OPT\n (uint31 n)\n ((simple-array uint32 (*)) s))\n (let* ((cumul (make-array (+ n 1) :element-type 'uint32 :initial-element 0))\n (highest (make-hash-table :size n :test #'eq)))\n (dotimes (i n)\n (setf (aref cumul (+ i 1))\n (logxor (aref cumul i) (aref s i))))\n (dotimes (i (+ n 1))\n (push i (gethash (aref cumul i) highest)))\n (when (zerop (aref cumul n))\n (return-from solve 1))\n (let ((dp (make-array (+ n 1) :element-type 'uint32 :initial-element #xffffffff)))\n (setf (aref dp 0) 0)\n (dotimes (x n)\n ;; a to z\n (unless (= #xffffffff (aref dp x))\n (dotimes (c 26)\n (let* ((mask (ash 1 c))\n (target (logxor (aref cumul x) mask))\n (nexts (gethash target highest)))\n (loop repeat 100\n for next of-type (or null uint32) in nexts\n while (and next (> next x))\n do (minf (aref dp next) (+ 1 (aref dp x))))))))\n (assert (/= #xffffffff (aref dp n)))\n (aref dp n))))\n\n(defun main ()\n (let* ((orig-s (read-line))\n (n (length orig-s))\n (s (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (let ((c (aref orig-s i)))\n (setf (aref s i) (ash 1 (- (char-code c) 97)))))\n (println (min (solve n s)\n (solve n (reverse s))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"aabxyyzz\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"byebye\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"abcdefghijklmnopqrstuvwxyz\n\"\n \"26\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"abcabcxabcx\n\"\n \"3\n\")))\n", "language": "Lisp", "metadata": {"date": 1586959968, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03570.html", "problem_id": "p03570", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03570/input.txt", "sample_output_relpath": "derived/input_output/data/p03570/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03570/Lisp/s289937439.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s289937439", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun solve (n s)\n (declare #.OPT\n (uint31 n)\n ((simple-array uint32 (*)) s))\n (let* ((cumul (make-array (+ n 1) :element-type 'uint32 :initial-element 0))\n (highest (make-hash-table :size n :test #'eq)))\n (dotimes (i n)\n (setf (aref cumul (+ i 1))\n (logxor (aref cumul i) (aref s i))))\n (dotimes (i (+ n 1))\n (push i (gethash (aref cumul i) highest)))\n (when (zerop (aref cumul n))\n (return-from solve 1))\n (let ((dp (make-array (+ n 1) :element-type 'uint32 :initial-element #xffffffff)))\n (setf (aref dp 0) 0)\n (dotimes (x n)\n ;; a to z\n (unless (= #xffffffff (aref dp x))\n (dotimes (c 26)\n (let* ((mask (ash 1 c))\n (target (logxor (aref cumul x) mask))\n (nexts (gethash target highest)))\n (loop repeat 100\n for next of-type (or null uint32) in nexts\n while (and next (> next x))\n do (minf (aref dp next) (+ 1 (aref dp x))))))))\n (assert (/= #xffffffff (aref dp n)))\n (aref dp n))))\n\n(defun main ()\n (let* ((orig-s (read-line))\n (n (length orig-s))\n (s (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (let ((c (aref orig-s i)))\n (setf (aref s i) (ash 1 (- (char-code c) 97)))))\n (println (min (solve n s)\n (solve n (reverse s))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"aabxyyzz\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"byebye\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"abcdefghijklmnopqrstuvwxyz\n\"\n \"26\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"abcabcxabcx\n\"\n \"3\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nWe have a string s consisting of lowercase English letters.\nSnuke is partitioning s into some number of non-empty substrings.\nLet the subtrings obtained be s_1, s_2, ..., s_N from left to right. (Here, s = s_1 + s_2 + ... + s_N holds.)\nSnuke wants to satisfy the following condition:\n\nFor each i (1 \\leq i \\leq N), it is possible to permute the characters in s_i and obtain a palindrome.\n\nFind the minimum possible value of N when the partition satisfies the condition.\n\nConstraints\n\n1 \\leq |s| \\leq 2 \\times 10^5\n\ns consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the minimum possible value of N when the partition satisfies the condition.\n\nSample Input 1\n\naabxyyzz\n\nSample Output 1\n\n2\n\nThe solution is to partition s as aabxyyzz = aab + xyyzz.\nHere, aab can be permuted to form a palindrome aba, and xyyzz can be permuted to form a palindrome zyxyz.\n\nSample Input 2\n\nbyebye\n\nSample Output 2\n\n1\n\nbyebye can be permuted to form a palindrome byeeyb.\n\nSample Input 3\n\nabcdefghijklmnopqrstuvwxyz\n\nSample Output 3\n\n26\n\nSample Input 4\n\nabcabcxabcx\n\nSample Output 4\n\n3\n\nThe solution is to partition s as abcabcxabcx = a + b + cabcxabcx.", "sample_input": "aabxyyzz\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03570", "source_text": "Score : 700 points\n\nProblem Statement\n\nWe have a string s consisting of lowercase English letters.\nSnuke is partitioning s into some number of non-empty substrings.\nLet the subtrings obtained be s_1, s_2, ..., s_N from left to right. (Here, s = s_1 + s_2 + ... + s_N holds.)\nSnuke wants to satisfy the following condition:\n\nFor each i (1 \\leq i \\leq N), it is possible to permute the characters in s_i and obtain a palindrome.\n\nFind the minimum possible value of N when the partition satisfies the condition.\n\nConstraints\n\n1 \\leq |s| \\leq 2 \\times 10^5\n\ns consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the minimum possible value of N when the partition satisfies the condition.\n\nSample Input 1\n\naabxyyzz\n\nSample Output 1\n\n2\n\nThe solution is to partition s as aabxyyzz = aab + xyyzz.\nHere, aab can be permuted to form a palindrome aba, and xyyzz can be permuted to form a palindrome zyxyz.\n\nSample Input 2\n\nbyebye\n\nSample Output 2\n\n1\n\nbyebye can be permuted to form a palindrome byeeyb.\n\nSample Input 3\n\nabcdefghijklmnopqrstuvwxyz\n\nSample Output 3\n\n26\n\nSample Input 4\n\nabcabcxabcx\n\nSample Output 4\n\n3\n\nThe solution is to partition s as abcabcxabcx = a + b + cabcxabcx.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5334, "cpu_time_ms": 2448, "memory_kb": 64096}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s165283093", "group_id": "codeNet:p03570", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun solve (n s)\n (declare (uint31 n)\n ((simple-array uint32 (*)) s))\n (let* ((cumul (make-array (+ n 1) :element-type 'uint32 :initial-element 0))\n (highest (make-array (ash 1 26) :element-type 'int32 :initial-element -1)))\n (dotimes (i n)\n (setf (aref cumul (+ i 1))\n (logxor (aref cumul i) (aref s i))))\n (dotimes (i (+ n 1))\n (maxf (aref highest (aref cumul i)) i))\n (when (zerop (aref cumul n))\n (return-from solve 1))\n (let ((dp (make-array (+ n 1) :element-type 'uint32 :initial-element #xffffffff)))\n (setf (aref dp 0) 0)\n (dotimes (x n)\n ;; a to z\n (unless (= #xffffffff (aref dp x))\n (dotimes (c 26)\n (let* ((mask (ash 1 c))\n (target (logxor (aref cumul x) mask))\n (next (aref highest target)))\n (when (> next x)\n (minf (aref dp next) (+ 1 (aref dp x))))))))\n (assert (/= #xffffffff (aref dp n)))\n (aref dp n))))\n\n(defun main ()\n (let* ((orig-s (read-line))\n (n (length orig-s))\n (s (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (let ((c (aref orig-s i)))\n (setf (aref s i) (ash 1 (- (char-code c) 97)))))\n (println (min (solve n s)\n (solve n (reverse s))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"aabxyyzz\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"byebye\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"abcdefghijklmnopqrstuvwxyz\n\"\n \"26\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"abcabcxabcx\n\"\n \"3\n\")))\n", "language": "Lisp", "metadata": {"date": 1586958885, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03570.html", "problem_id": "p03570", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03570/input.txt", "sample_output_relpath": "derived/input_output/data/p03570/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03570/Lisp/s165283093.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s165283093", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun solve (n s)\n (declare (uint31 n)\n ((simple-array uint32 (*)) s))\n (let* ((cumul (make-array (+ n 1) :element-type 'uint32 :initial-element 0))\n (highest (make-array (ash 1 26) :element-type 'int32 :initial-element -1)))\n (dotimes (i n)\n (setf (aref cumul (+ i 1))\n (logxor (aref cumul i) (aref s i))))\n (dotimes (i (+ n 1))\n (maxf (aref highest (aref cumul i)) i))\n (when (zerop (aref cumul n))\n (return-from solve 1))\n (let ((dp (make-array (+ n 1) :element-type 'uint32 :initial-element #xffffffff)))\n (setf (aref dp 0) 0)\n (dotimes (x n)\n ;; a to z\n (unless (= #xffffffff (aref dp x))\n (dotimes (c 26)\n (let* ((mask (ash 1 c))\n (target (logxor (aref cumul x) mask))\n (next (aref highest target)))\n (when (> next x)\n (minf (aref dp next) (+ 1 (aref dp x))))))))\n (assert (/= #xffffffff (aref dp n)))\n (aref dp n))))\n\n(defun main ()\n (let* ((orig-s (read-line))\n (n (length orig-s))\n (s (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (let ((c (aref orig-s i)))\n (setf (aref s i) (ash 1 (- (char-code c) 97)))))\n (println (min (solve n s)\n (solve n (reverse s))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"aabxyyzz\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"byebye\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"abcdefghijklmnopqrstuvwxyz\n\"\n \"26\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"abcabcxabcx\n\"\n \"3\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nWe have a string s consisting of lowercase English letters.\nSnuke is partitioning s into some number of non-empty substrings.\nLet the subtrings obtained be s_1, s_2, ..., s_N from left to right. (Here, s = s_1 + s_2 + ... + s_N holds.)\nSnuke wants to satisfy the following condition:\n\nFor each i (1 \\leq i \\leq N), it is possible to permute the characters in s_i and obtain a palindrome.\n\nFind the minimum possible value of N when the partition satisfies the condition.\n\nConstraints\n\n1 \\leq |s| \\leq 2 \\times 10^5\n\ns consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the minimum possible value of N when the partition satisfies the condition.\n\nSample Input 1\n\naabxyyzz\n\nSample Output 1\n\n2\n\nThe solution is to partition s as aabxyyzz = aab + xyyzz.\nHere, aab can be permuted to form a palindrome aba, and xyyzz can be permuted to form a palindrome zyxyz.\n\nSample Input 2\n\nbyebye\n\nSample Output 2\n\n1\n\nbyebye can be permuted to form a palindrome byeeyb.\n\nSample Input 3\n\nabcdefghijklmnopqrstuvwxyz\n\nSample Output 3\n\n26\n\nSample Input 4\n\nabcabcxabcx\n\nSample Output 4\n\n3\n\nThe solution is to partition s as abcabcxabcx = a + b + cabcxabcx.", "sample_input": "aabxyyzz\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03570", "source_text": "Score : 700 points\n\nProblem Statement\n\nWe have a string s consisting of lowercase English letters.\nSnuke is partitioning s into some number of non-empty substrings.\nLet the subtrings obtained be s_1, s_2, ..., s_N from left to right. (Here, s = s_1 + s_2 + ... + s_N holds.)\nSnuke wants to satisfy the following condition:\n\nFor each i (1 \\leq i \\leq N), it is possible to permute the characters in s_i and obtain a palindrome.\n\nFind the minimum possible value of N when the partition satisfies the condition.\n\nConstraints\n\n1 \\leq |s| \\leq 2 \\times 10^5\n\ns consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the minimum possible value of N when the partition satisfies the condition.\n\nSample Input 1\n\naabxyyzz\n\nSample Output 1\n\n2\n\nThe solution is to partition s as aabxyyzz = aab + xyyzz.\nHere, aab can be permuted to form a palindrome aba, and xyyzz can be permuted to form a palindrome zyxyz.\n\nSample Input 2\n\nbyebye\n\nSample Output 2\n\n1\n\nbyebye can be permuted to form a palindrome byeeyb.\n\nSample Input 3\n\nabcdefghijklmnopqrstuvwxyz\n\nSample Output 3\n\n26\n\nSample Input 4\n\nabcabcxabcx\n\nSample Output 4\n\n3\n\nThe solution is to partition s as abcabcxabcx = a + b + cabcxabcx.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5220, "cpu_time_ms": 441, "memory_kb": 293476}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s372231029", "group_id": "codeNet:p03573", "input_text": "(let ((lst (sort (list (read) (read) (read)) #'<=)))\n\t (princ (- (+ (car lst) (car (last lst))) (cadr lst))))", "language": "Lisp", "metadata": {"date": 1508120580, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03573.html", "problem_id": "p03573", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03573/input.txt", "sample_output_relpath": "derived/input_output/data/p03573/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03573/Lisp/s372231029.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s372231029", "user_id": "u158834201"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(let ((lst (sort (list (read) (read) (read)) #'<=)))\n\t (princ (- (+ (car lst) (car (last lst))) (cadr lst))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given three integers, A, B and C.\n\nAmong them, two are the same, but the remaining one is different from the rest.\n\nFor example, when A=5,B=7,C=5, A and C are the same, but B is different.\n\nFind the one that is different from the rest among the given three integers.\n\nConstraints\n\n-100 \\leq A,B,C \\leq 100\n\nA, B and C are integers.\n\nThe input satisfies the condition in the statement.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nAmong A, B and C, print the integer that is different from the rest.\n\nSample Input 1\n\n5 7 5\n\nSample Output 1\n\n7\n\nThis is the same case as the one in the statement.\n\nSample Input 2\n\n1 1 7\n\nSample Output 2\n\n7\n\nIn this case, C is the one we seek.\n\nSample Input 3\n\n-100 100 100\n\nSample Output 3\n\n-100", "sample_input": "5 7 5\n"}, "reference_outputs": ["7\n"], "source_document_id": "p03573", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given three integers, A, B and C.\n\nAmong them, two are the same, but the remaining one is different from the rest.\n\nFor example, when A=5,B=7,C=5, A and C are the same, but B is different.\n\nFind the one that is different from the rest among the given three integers.\n\nConstraints\n\n-100 \\leq A,B,C \\leq 100\n\nA, B and C are integers.\n\nThe input satisfies the condition in the statement.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nAmong A, B and C, print the integer that is different from the rest.\n\nSample Input 1\n\n5 7 5\n\nSample Output 1\n\n7\n\nThis is the same case as the one in the statement.\n\nSample Input 2\n\n1 1 7\n\nSample Output 2\n\n7\n\nIn this case, C is the one we seek.\n\nSample Input 3\n\n-100 100 100\n\nSample Output 3\n\n-100", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 111, "cpu_time_ms": 96, "memory_kb": 10084}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s297100823", "group_id": "codeNet:p03579", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;; PAY ATTENTION TO THE STACK SIZE!\n(declaim (inline bipartite-p)\n (ftype (function * (values (or null simple-bit-vector) &optional)) bipartite-p))\n(defun bipartite-p (graph)\n \"Checks if GRAPH is bipartite and returns the vector of colorings if so,\notherwise returns NIL.\n\nGRAPH := vector of adjacency lists\"\n (declare (vector graph))\n (let* ((n (length graph))\n (visited (make-array n :element-type 'bit :initial-element 0))\n (colors (make-array n :element-type 'bit :initial-element 0)))\n (labels ((dfs (vertex color)\n (cond ((zerop (aref visited vertex))\n (setf (aref visited vertex) 1\n (aref colors vertex) color)\n (if (= color 1)\n (dolist (neighbor (aref graph vertex))\n (dfs neighbor 0))\n (dolist (neighbor (aref graph vertex))\n (dfs neighbor 1))))\n ((/= color (aref colors vertex))\n (return-from bipartite-p nil)))))\n (dotimes (i n colors)\n (when (zerop (aref visited i))\n (dfs i 1))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil)))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (let ((colors (bipartite-p graph)))\n (println\n (if colors\n (let* ((size1 (count 0 colors))\n (size2 (- n size1)))\n (- (* size1 size2) m))\n (- (ash (* n (- n 1)) -1) m))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 5\n1 2\n2 3\n3 4\n4 5\n5 6\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 5\n1 2\n2 3\n3 1\n5 4\n5 1\n\"\n \"5\n\")))\n", "language": "Lisp", "metadata": {"date": 1594865735, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03579.html", "problem_id": "p03579", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03579/input.txt", "sample_output_relpath": "derived/input_output/data/p03579/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03579/Lisp/s297100823.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s297100823", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;; PAY ATTENTION TO THE STACK SIZE!\n(declaim (inline bipartite-p)\n (ftype (function * (values (or null simple-bit-vector) &optional)) bipartite-p))\n(defun bipartite-p (graph)\n \"Checks if GRAPH is bipartite and returns the vector of colorings if so,\notherwise returns NIL.\n\nGRAPH := vector of adjacency lists\"\n (declare (vector graph))\n (let* ((n (length graph))\n (visited (make-array n :element-type 'bit :initial-element 0))\n (colors (make-array n :element-type 'bit :initial-element 0)))\n (labels ((dfs (vertex color)\n (cond ((zerop (aref visited vertex))\n (setf (aref visited vertex) 1\n (aref colors vertex) color)\n (if (= color 1)\n (dolist (neighbor (aref graph vertex))\n (dfs neighbor 0))\n (dolist (neighbor (aref graph vertex))\n (dfs neighbor 1))))\n ((/= color (aref colors vertex))\n (return-from bipartite-p nil)))))\n (dotimes (i n colors)\n (when (zerop (aref visited i))\n (dfs i 1))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil)))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (let ((colors (bipartite-p graph)))\n (println\n (if colors\n (let* ((size1 (count 0 colors))\n (size2 (- n size1)))\n (- (* size1 size2) m))\n (- (ash (* n (- n 1)) -1) m))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 5\n1 2\n2 3\n3 4\n4 5\n5 6\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 5\n1 2\n2 3\n3 1\n5 4\n5 1\n\"\n \"5\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nRng has a connected undirected graph with N vertices.\nCurrently, there are M edges in the graph, and the i-th edge connects Vertices A_i and B_i.\n\nRng will add new edges to the graph by repeating the following operation:\n\nOperation: Choose u and v (u \\neq v) such that Vertex v can be reached by traversing exactly three edges from Vertex u, and add an edge connecting Vertices u and v. It is not allowed to add an edge if there is already an edge connecting Vertices u and v.\n\nFind the maximum possible number of edges that can be added.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq A_i,B_i \\leq N\n\nThe graph has no self-loops or multiple edges.\n\nThe graph is connected.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\nA_2 B_2\n:\nA_M B_M\n\nOutput\n\nFind the maximum possible number of edges that can be added.\n\nSample Input 1\n\n6 5\n1 2\n2 3\n3 4\n4 5\n5 6\n\nSample Output 1\n\n4\n\nIf we add edges as shown below, four edges can be added, and no more.\n\nSample Input 2\n\n5 5\n1 2\n2 3\n3 1\n5 4\n5 1\n\nSample Output 2\n\n5\n\nFive edges can be added, for example, as follows:\n\nAdd an edge connecting Vertex 5 and Vertex 3.\n\nAdd an edge connecting Vertex 5 and Vertex 2.\n\nAdd an edge connecting Vertex 4 and Vertex 1.\n\nAdd an edge connecting Vertex 4 and Vertex 2.\n\nAdd an edge connecting Vertex 4 and Vertex 3.", "sample_input": "6 5\n1 2\n2 3\n3 4\n4 5\n5 6\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03579", "source_text": "Score : 500 points\n\nProblem Statement\n\nRng has a connected undirected graph with N vertices.\nCurrently, there are M edges in the graph, and the i-th edge connects Vertices A_i and B_i.\n\nRng will add new edges to the graph by repeating the following operation:\n\nOperation: Choose u and v (u \\neq v) such that Vertex v can be reached by traversing exactly three edges from Vertex u, and add an edge connecting Vertices u and v. It is not allowed to add an edge if there is already an edge connecting Vertices u and v.\n\nFind the maximum possible number of edges that can be added.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq A_i,B_i \\leq N\n\nThe graph has no self-loops or multiple edges.\n\nThe graph is connected.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\nA_2 B_2\n:\nA_M B_M\n\nOutput\n\nFind the maximum possible number of edges that can be added.\n\nSample Input 1\n\n6 5\n1 2\n2 3\n3 4\n4 5\n5 6\n\nSample Output 1\n\n4\n\nIf we add edges as shown below, four edges can be added, and no more.\n\nSample Input 2\n\n5 5\n1 2\n2 3\n3 1\n5 4\n5 1\n\nSample Output 2\n\n5\n\nFive edges can be added, for example, as follows:\n\nAdd an edge connecting Vertex 5 and Vertex 3.\n\nAdd an edge connecting Vertex 5 and Vertex 2.\n\nAdd an edge connecting Vertex 4 and Vertex 1.\n\nAdd an edge connecting Vertex 4 and Vertex 2.\n\nAdd an edge connecting Vertex 4 and Vertex 3.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6893, "cpu_time_ms": 61, "memory_kb": 32424}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s368940535", "group_id": "codeNet:p03585", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline relative-error-p))\n(defun relative-error<= (x y threshold)\n \"Returns true if the relative error between X and Y is equal to or smaller\nthan THRESHOLD: i.e. the relative errors of any numbers in the interval [X,\nY] (or [Y, X]) are equal to or smaller than THRESHOLD when the true value is in\nthe same interval.\"\n (and (not (zerop x))\n (not (zerop y))\n (<= (abs (/ (- x y) y)) threshold)\n (<= (abs (/ (- x y) x)) threshold)))\n\n;;;\n;;; ARRAY-ELEMENT-TYPE is not constant-folded on SBCL version earlier than\n;;; 1.5.0. See\n;;; https://github.com/sbcl/sbcl/commit/9f0d12e7ab961828931d01c0b2a76a5885ad35d2\n;;;\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:deftransform array-element-type ((array))\n (let ((type (sb-c::lvar-type array)))\n (flet ((element-type (type)\n (and (sb-c::array-type-p type)\n (sb-int:neq (sb-kernel::array-type-specialized-element-type type) sb-kernel:*wild-type*)\n (sb-kernel:type-specifier (sb-kernel::array-type-specialized-element-type type)))))\n (cond ((let ((type (element-type type)))\n (and type\n `',type)))\n ((sb-kernel:union-type-p type)\n (let (result)\n (loop for type in (sb-kernel:union-type-types type)\n for et = (element-type type)\n unless (and et\n (if result\n (equal result et)\n (setf result et)))\n do (sb-c::give-up-ir1-transform))\n `',result))\n ((sb-kernel:intersection-type-p type)\n (loop for type in (sb-kernel:intersection-type-types type)\n for et = (element-type type)\n when et\n return `',et\n finally (sb-c::give-up-ir1-transform)))\n (t\n (sb-c::give-up-ir1-transform)))))))\n\n;;;\n;;; Compute inversion number by merge sort\n;;;\n\n(declaim (inline %merge-count))\n(defun %merge-count (l mid r source-vec dest-vec predicate)\n (declare ((integer 0 #.array-total-size-limit) l mid r)\n (function predicate))\n (loop with count of-type (integer 0 #.most-positive-fixnum) = 0\n with i = l\n with j = mid\n for idx from l\n when (= i mid)\n do (loop for j from j below r\n for idx from idx\n do (setf (aref dest-vec idx)\n (aref source-vec j))\n finally (return-from %merge-count count))\n when (= j r)\n do (loop for i from i below mid\n for idx from idx\n do (setf (aref dest-vec idx)\n (aref source-vec i))\n finally (return-from %merge-count count))\n do (if (funcall predicate\n (aref source-vec j)\n (aref source-vec i))\n (setf (aref dest-vec idx) (aref source-vec j)\n j (1+ j)\n count (+ count (- mid i)))\n (setf (aref dest-vec idx) (aref source-vec i)\n i (1+ i)))))\n\n(defmacro with-fixnum+ (form)\n (let ((fixnum+ '(integer 0 #.most-positive-fixnum)))\n `(the ,fixnum+\n ,(reduce (lambda (f1 f2)`(,(car form)\n (the ,fixnum+ ,f1)\n (the ,fixnum+ ,f2)))\n\t (cdr form)))))\n\n(declaim (inline %calc-by-insertion-sort!))\n(defun %calc-by-insertion-sort! (vec predicate l r)\n (declare (function predicate)\n ((integer 0 #.array-total-size-limit) l r))\n (loop with inv-count of-type (integer 0 #.most-positive-fixnum) = 0\n for end from (+ l 1) below r\n do (loop for i from end above l\n while (funcall predicate (aref vec i) (aref vec (- i 1)))\n do (rotatef (aref vec (- i 1)) (aref vec i))\n (incf inv-count))\n finally (return inv-count)))\n\n;; NOTE: This function is slow on SBCL version earlier than 1.5.0 as\n;; constant-folding of ARRAY-ELEMENT-TYPE doesn't work. Use\n;; array-element-type.lisp if necessary.\n(declaim (inline calc-inversion-number!))\n(defun calc-inversion-number! (vector predicate &key (start 0) end)\n \"Calculates the inversion number of VECTOR w.r.t. the strict order\nPREDICATE. This function sorts VECTOR as a side effect.\"\n (declare (vector vector)\n (function predicate))\n (let ((end (or end (length vector))))\n (declare ((integer 0 #.array-total-size-limit) start end))\n (assert (<= start end))\n (let ((buffer (make-array end :element-type (array-element-type vector))))\n (labels\n ((recurse (l r merge-to-vec1-p)\n (declare (optimize (safety 0))\n ((integer 0 #.array-total-size-limit) l r))\n (cond ((= l r) 0)\n ((= (+ l 1) r)\n (unless merge-to-vec1-p\n (setf (aref buffer l) (aref vector l)))\n 0)\n ;; It is faster to use insertion sort. I don't adopt it\n ;; by default, however, because that makes it hard to\n ;; change the code to fit some special settings.\n ;; ((and (<= (- r l) 24) merge-to-vec1-p)\n ;; (%calc-by-insertion-sort! vec1 predicate l r))\n (t\n (let ((mid (floor (+ l r) 2)))\n (with-fixnum+\n (+ (recurse l mid (not merge-to-vec1-p))\n (recurse mid r (not merge-to-vec1-p))\n (if merge-to-vec1-p\n (%merge-count l mid r buffer vector predicate)\n (%merge-count l mid r vector buffer predicate)))))))))\n (recurse start end t)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun solve (n as bs cs)\n (declare ((simple-array int32 (*)) as bs cs)\n (uint16 n))\n (let ((lefts (make-array n :element-type 'double-float))\n (rights (make-array n :element-type 'double-float))\n (median (ceiling (floor (* n (- n 1)) 2) 2)))\n (dotimes (i n)\n (let ((y (/ (+ (aref cs i) (* 1d9 (aref as i)))\n (aref bs i))))\n (setf (aref lefts i) y)))\n (let ((ords (make-array n :element-type 'uint32)))\n (dotimes (i n) (setf (aref ords i) i))\n (setf ords (sort ords\n (lambda (i j)\n (< (aref lefts i) (aref lefts j)))))\n (sb-int:named-let bisect ((ng -1d9) (ok 1d9))\n (declare (double-float ng ok))\n (if (or (< (- ok ng) 1d-10)\n (relative-error<= ng ok 1d-10))\n ok\n (let ((mid (* 0.5d0 (+ ng ok))))\n (fill rights 0d0)\n (dotimes (i n)\n (let* ((ord (aref ords i))\n (y (/ (- (aref cs ord) (* mid (aref as ord)))\n (aref bs ord))))\n (setf (aref rights i) y)))\n (let ((invs (calc-inversion-number! rights #'<)))\n (if (>= invs median)\n (bisect ng mid)\n (bisect mid ok)))))))))\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'int32))\n (bs (make-array n :element-type 'int32))\n (cs (make-array n :element-type 'int32)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref bs i) (read-fixnum)\n (aref cs i) (read-fixnum)))\n (let ((x (solve n as bs cs))\n (y (solve n bs as cs)))\n (format t \"~D ~D~%\" x y))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1564732561, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03585.html", "problem_id": "p03585", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03585/input.txt", "sample_output_relpath": "derived/input_output/data/p03585/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03585/Lisp/s368940535.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s368940535", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1.000000000000000 1.000000000000000\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline relative-error-p))\n(defun relative-error<= (x y threshold)\n \"Returns true if the relative error between X and Y is equal to or smaller\nthan THRESHOLD: i.e. the relative errors of any numbers in the interval [X,\nY] (or [Y, X]) are equal to or smaller than THRESHOLD when the true value is in\nthe same interval.\"\n (and (not (zerop x))\n (not (zerop y))\n (<= (abs (/ (- x y) y)) threshold)\n (<= (abs (/ (- x y) x)) threshold)))\n\n;;;\n;;; ARRAY-ELEMENT-TYPE is not constant-folded on SBCL version earlier than\n;;; 1.5.0. See\n;;; https://github.com/sbcl/sbcl/commit/9f0d12e7ab961828931d01c0b2a76a5885ad35d2\n;;;\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:deftransform array-element-type ((array))\n (let ((type (sb-c::lvar-type array)))\n (flet ((element-type (type)\n (and (sb-c::array-type-p type)\n (sb-int:neq (sb-kernel::array-type-specialized-element-type type) sb-kernel:*wild-type*)\n (sb-kernel:type-specifier (sb-kernel::array-type-specialized-element-type type)))))\n (cond ((let ((type (element-type type)))\n (and type\n `',type)))\n ((sb-kernel:union-type-p type)\n (let (result)\n (loop for type in (sb-kernel:union-type-types type)\n for et = (element-type type)\n unless (and et\n (if result\n (equal result et)\n (setf result et)))\n do (sb-c::give-up-ir1-transform))\n `',result))\n ((sb-kernel:intersection-type-p type)\n (loop for type in (sb-kernel:intersection-type-types type)\n for et = (element-type type)\n when et\n return `',et\n finally (sb-c::give-up-ir1-transform)))\n (t\n (sb-c::give-up-ir1-transform)))))))\n\n;;;\n;;; Compute inversion number by merge sort\n;;;\n\n(declaim (inline %merge-count))\n(defun %merge-count (l mid r source-vec dest-vec predicate)\n (declare ((integer 0 #.array-total-size-limit) l mid r)\n (function predicate))\n (loop with count of-type (integer 0 #.most-positive-fixnum) = 0\n with i = l\n with j = mid\n for idx from l\n when (= i mid)\n do (loop for j from j below r\n for idx from idx\n do (setf (aref dest-vec idx)\n (aref source-vec j))\n finally (return-from %merge-count count))\n when (= j r)\n do (loop for i from i below mid\n for idx from idx\n do (setf (aref dest-vec idx)\n (aref source-vec i))\n finally (return-from %merge-count count))\n do (if (funcall predicate\n (aref source-vec j)\n (aref source-vec i))\n (setf (aref dest-vec idx) (aref source-vec j)\n j (1+ j)\n count (+ count (- mid i)))\n (setf (aref dest-vec idx) (aref source-vec i)\n i (1+ i)))))\n\n(defmacro with-fixnum+ (form)\n (let ((fixnum+ '(integer 0 #.most-positive-fixnum)))\n `(the ,fixnum+\n ,(reduce (lambda (f1 f2)`(,(car form)\n (the ,fixnum+ ,f1)\n (the ,fixnum+ ,f2)))\n\t (cdr form)))))\n\n(declaim (inline %calc-by-insertion-sort!))\n(defun %calc-by-insertion-sort! (vec predicate l r)\n (declare (function predicate)\n ((integer 0 #.array-total-size-limit) l r))\n (loop with inv-count of-type (integer 0 #.most-positive-fixnum) = 0\n for end from (+ l 1) below r\n do (loop for i from end above l\n while (funcall predicate (aref vec i) (aref vec (- i 1)))\n do (rotatef (aref vec (- i 1)) (aref vec i))\n (incf inv-count))\n finally (return inv-count)))\n\n;; NOTE: This function is slow on SBCL version earlier than 1.5.0 as\n;; constant-folding of ARRAY-ELEMENT-TYPE doesn't work. Use\n;; array-element-type.lisp if necessary.\n(declaim (inline calc-inversion-number!))\n(defun calc-inversion-number! (vector predicate &key (start 0) end)\n \"Calculates the inversion number of VECTOR w.r.t. the strict order\nPREDICATE. This function sorts VECTOR as a side effect.\"\n (declare (vector vector)\n (function predicate))\n (let ((end (or end (length vector))))\n (declare ((integer 0 #.array-total-size-limit) start end))\n (assert (<= start end))\n (let ((buffer (make-array end :element-type (array-element-type vector))))\n (labels\n ((recurse (l r merge-to-vec1-p)\n (declare (optimize (safety 0))\n ((integer 0 #.array-total-size-limit) l r))\n (cond ((= l r) 0)\n ((= (+ l 1) r)\n (unless merge-to-vec1-p\n (setf (aref buffer l) (aref vector l)))\n 0)\n ;; It is faster to use insertion sort. I don't adopt it\n ;; by default, however, because that makes it hard to\n ;; change the code to fit some special settings.\n ;; ((and (<= (- r l) 24) merge-to-vec1-p)\n ;; (%calc-by-insertion-sort! vec1 predicate l r))\n (t\n (let ((mid (floor (+ l r) 2)))\n (with-fixnum+\n (+ (recurse l mid (not merge-to-vec1-p))\n (recurse mid r (not merge-to-vec1-p))\n (if merge-to-vec1-p\n (%merge-count l mid r buffer vector predicate)\n (%merge-count l mid r vector buffer predicate)))))))))\n (recurse start end t)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun solve (n as bs cs)\n (declare ((simple-array int32 (*)) as bs cs)\n (uint16 n))\n (let ((lefts (make-array n :element-type 'double-float))\n (rights (make-array n :element-type 'double-float))\n (median (ceiling (floor (* n (- n 1)) 2) 2)))\n (dotimes (i n)\n (let ((y (/ (+ (aref cs i) (* 1d9 (aref as i)))\n (aref bs i))))\n (setf (aref lefts i) y)))\n (let ((ords (make-array n :element-type 'uint32)))\n (dotimes (i n) (setf (aref ords i) i))\n (setf ords (sort ords\n (lambda (i j)\n (< (aref lefts i) (aref lefts j)))))\n (sb-int:named-let bisect ((ng -1d9) (ok 1d9))\n (declare (double-float ng ok))\n (if (or (< (- ok ng) 1d-10)\n (relative-error<= ng ok 1d-10))\n ok\n (let ((mid (* 0.5d0 (+ ng ok))))\n (fill rights 0d0)\n (dotimes (i n)\n (let* ((ord (aref ords i))\n (y (/ (- (aref cs ord) (* mid (aref as ord)))\n (aref bs ord))))\n (setf (aref rights i) y)))\n (let ((invs (calc-inversion-number! rights #'<)))\n (if (>= invs median)\n (bisect ng mid)\n (bisect mid ok)))))))))\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'int32))\n (bs (make-array n :element-type 'int32))\n (cs (make-array n :element-type 'int32)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref bs i) (read-fixnum)\n (aref cs i) (read-fixnum)))\n (let ((x (solve n as bs cs))\n (y (solve n bs as cs)))\n (format t \"~D ~D~%\" x y))))\n\n#-swank (main)\n", "problem_context": "Score : 800 points\n\nProblem Statement\n\nThere are N lines in the xy-plane. The i-th line is represented by A_ix+B_iy=C_i.\nAny two lines among the N+2 lines, the above N lines plus the x-axis and y-axis, cross each other at exactly one point.\n\nFor each pair 1 \\leq i < j \\leq N, there is a car at the cross point of the i-th and j-th lines.\nEven where three or more lines intersect at a point, a car is individually placed for each pair of lines.\nThat is, there will be k(k-1)/2 cars placed at the intersection of k lines.\n\nThose cars are already very old, and can only be moved parallel to the x-axis or y-axis.\n\nTakahashi will hold an exhibition of antique cars at a place on the xy-plane.\nIn order to avoid damaging the half-broken cars too much, he will select the place of the exhibition so that the total distance covered will be minimized when all the cars are moved to the place.\nIf such a place is not uniquely determined, among the places that satisfy the condition above, the place with the minimum x-coordinate will be selected.\nIf the place is still not uniquely determined, among the places that satisfy the two conditions above, the place with the minimum y-coordinate will be selected.\n\nFind the place of the exhibition that will be selected.\n\nConstraints\n\n2 \\leq N \\leq 4 × 10^4\n\n1 \\leq |A_i|,|B_i| \\leq 10^4(1 \\leq i \\leq N)\n\n0 \\leq |C_i| \\leq 10^4(1 \\leq i \\leq N)\n\nNo two given lines are parallel.\n\nAll input values are integers.\n\nInputs\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 B_1 C_1\n:\nA_N B_N C_N\n\nOutputs\n\nPrint the x-coordinate and y-coordinate of the place of the exhibition that will be selected, in this order, with a space in between. The output will be judged as correct when the absolute or relative error is at most 10^{-9}.\n\nSample Input 1\n\n3\n1 1 1\n2 -1 2\n-1 2 2\n\nSample Output 1\n\n1.000000000000000 1.000000000000000\n\nThere is a car at each place shown by a blue circle in the figure. The place to be selected is shown by a purple circle.\n\nSample Input 2\n\n4\n1 1 2\n1 -1 0\n3 -1 -2\n1 -3 4\n\nSample Output 2\n\n-1.000000000000000 -1.000000000000000\n\nSample Input 3\n\n7\n1 7 8\n-2 4 9\n3 -8 -5\n9 2 -14\n6 7 5\n-8 -9 3\n3 8 10\n\nSample Output 3\n\n-1.722222222222222 1.325000000000000", "sample_input": "3\n1 1 1\n2 -1 2\n-1 2 2\n"}, "reference_outputs": ["1.000000000000000 1.000000000000000\n"], "source_document_id": "p03585", "source_text": "Score : 800 points\n\nProblem Statement\n\nThere are N lines in the xy-plane. The i-th line is represented by A_ix+B_iy=C_i.\nAny two lines among the N+2 lines, the above N lines plus the x-axis and y-axis, cross each other at exactly one point.\n\nFor each pair 1 \\leq i < j \\leq N, there is a car at the cross point of the i-th and j-th lines.\nEven where three or more lines intersect at a point, a car is individually placed for each pair of lines.\nThat is, there will be k(k-1)/2 cars placed at the intersection of k lines.\n\nThose cars are already very old, and can only be moved parallel to the x-axis or y-axis.\n\nTakahashi will hold an exhibition of antique cars at a place on the xy-plane.\nIn order to avoid damaging the half-broken cars too much, he will select the place of the exhibition so that the total distance covered will be minimized when all the cars are moved to the place.\nIf such a place is not uniquely determined, among the places that satisfy the condition above, the place with the minimum x-coordinate will be selected.\nIf the place is still not uniquely determined, among the places that satisfy the two conditions above, the place with the minimum y-coordinate will be selected.\n\nFind the place of the exhibition that will be selected.\n\nConstraints\n\n2 \\leq N \\leq 4 × 10^4\n\n1 \\leq |A_i|,|B_i| \\leq 10^4(1 \\leq i \\leq N)\n\n0 \\leq |C_i| \\leq 10^4(1 \\leq i \\leq N)\n\nNo two given lines are parallel.\n\nAll input values are integers.\n\nInputs\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 B_1 C_1\n:\nA_N B_N C_N\n\nOutputs\n\nPrint the x-coordinate and y-coordinate of the place of the exhibition that will be selected, in this order, with a space in between. The output will be judged as correct when the absolute or relative error is at most 10^{-9}.\n\nSample Input 1\n\n3\n1 1 1\n2 -1 2\n-1 2 2\n\nSample Output 1\n\n1.000000000000000 1.000000000000000\n\nThere is a car at each place shown by a blue circle in the figure. The place to be selected is shown by a purple circle.\n\nSample Input 2\n\n4\n1 1 2\n1 -1 0\n3 -1 -2\n1 -3 4\n\nSample Output 2\n\n-1.000000000000000 -1.000000000000000\n\nSample Input 3\n\n7\n1 7 8\n-2 4 9\n3 -8 -5\n9 2 -14\n6 7 5\n-8 -9 3\n3 8 10\n\nSample Output 3\n\n-1.722222222222222 1.325000000000000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10087, "cpu_time_ms": 949, "memory_kb": 74468}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s740287841", "group_id": "codeNet:p03587", "input_text": "(princ (count #\\1 (read-line) :test #'equal))\n", "language": "Lisp", "metadata": {"date": 1576945263, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03587.html", "problem_id": "p03587", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03587/input.txt", "sample_output_relpath": "derived/input_output/data/p03587/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03587/Lisp/s740287841.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s740287841", "user_id": "u493610446"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(princ (count #\\1 (read-line) :test #'equal))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nSnuke prepared 6 problems for a upcoming programming contest.\nFor each of those problems, Rng judged whether it can be used in the contest or not.\n\nYou are given a string S of length 6.\nIf the i-th character of s is 1, it means that the i-th problem prepared by Snuke is accepted to be used; 0 means that the problem is not accepted.\n\nHow many problems prepared by Snuke are accepted to be used in the contest?\n\nConstraints\n\nThe length of S is 6.\n\nS consists of 0 and 1.\n\nInputs\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutputs\n\nPrint the number of problems prepared by Snuke that are accepted to be used in the contest.\n\nSample Input 1\n\n111100\n\nSample Output 1\n\n4\n\nThe first, second, third and fourth problems are accepted, for a total of four.\n\nSample Input 2\n\n001001\n\nSample Output 2\n\n2\n\nSample Input 3\n\n000000\n\nSample Output 3\n\n0", "sample_input": "111100\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03587", "source_text": "Score : 100 points\n\nProblem Statement\n\nSnuke prepared 6 problems for a upcoming programming contest.\nFor each of those problems, Rng judged whether it can be used in the contest or not.\n\nYou are given a string S of length 6.\nIf the i-th character of s is 1, it means that the i-th problem prepared by Snuke is accepted to be used; 0 means that the problem is not accepted.\n\nHow many problems prepared by Snuke are accepted to be used in the contest?\n\nConstraints\n\nThe length of S is 6.\n\nS consists of 0 and 1.\n\nInputs\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutputs\n\nPrint the number of problems prepared by Snuke that are accepted to be used in the contest.\n\nSample Input 1\n\n111100\n\nSample Output 1\n\n4\n\nThe first, second, third and fourth problems are accepted, for a total of four.\n\nSample Input 2\n\n001001\n\nSample Output 2\n\n2\n\nSample Input 3\n\n000000\n\nSample Output 3\n\n0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 46, "cpu_time_ms": 20, "memory_kb": 3940}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s166437750", "group_id": "codeNet:p03597", "input_text": "(princ(-(expt(read)2)(read)))(terpri)", "language": "Lisp", "metadata": {"date": 1599545170, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03597.html", "problem_id": "p03597", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03597/input.txt", "sample_output_relpath": "derived/input_output/data/p03597/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03597/Lisp/s166437750.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s166437750", "user_id": "u425762225"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(princ(-(expt(read)2)(read)))(terpri)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe have an N \\times N square grid.\n\nWe will paint each square in the grid either black or white.\n\nIf we paint exactly A squares white, how many squares will be painted black?\n\nConstraints\n\n1 \\leq N \\leq 100\n\n0 \\leq A \\leq N^2\n\nInputs\n\nInput is given from Standard Input in the following format:\n\nN\nA\n\nOutputs\n\nPrint the number of squares that will be painted black.\n\nSample Input 1\n\n3\n4\n\nSample Output 1\n\n5\n\nThere are nine squares in a 3 \\times 3 square grid.\nFour of them will be painted white, so the remaining five squares will be painted black.\n\nSample Input 2\n\n19\n100\n\nSample Output 2\n\n261\n\nSample Input 3\n\n10\n0\n\nSample Output 3\n\n100\n\nAs zero squares will be painted white, all the squares will be painted black.", "sample_input": "3\n4\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03597", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe have an N \\times N square grid.\n\nWe will paint each square in the grid either black or white.\n\nIf we paint exactly A squares white, how many squares will be painted black?\n\nConstraints\n\n1 \\leq N \\leq 100\n\n0 \\leq A \\leq N^2\n\nInputs\n\nInput is given from Standard Input in the following format:\n\nN\nA\n\nOutputs\n\nPrint the number of squares that will be painted black.\n\nSample Input 1\n\n3\n4\n\nSample Output 1\n\n5\n\nThere are nine squares in a 3 \\times 3 square grid.\nFour of them will be painted white, so the remaining five squares will be painted black.\n\nSample Input 2\n\n19\n100\n\nSample Output 2\n\n261\n\nSample Input 3\n\n10\n0\n\nSample Output 3\n\n100\n\nAs zero squares will be painted white, all the squares will be painted black.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 37, "cpu_time_ms": 17, "memory_kb": 24020}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s490816188", "group_id": "codeNet:p03598", "input_text": "(let ((n (read)) (k (read))) (princ (loop repeat n sum (let ((x (read))) (* 2 (min x (abs (- k x))))))))\n", "language": "Lisp", "metadata": {"date": 1579986209, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03598.html", "problem_id": "p03598", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03598/input.txt", "sample_output_relpath": "derived/input_output/data/p03598/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03598/Lisp/s490816188.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s490816188", "user_id": "u493610446"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let ((n (read)) (k (read))) (princ (loop repeat n sum (let ((x (read))) (* 2 (min x (abs (- k x))))))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i).\nThus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N.\n\nIn order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B.\nThen, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i).\nThus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N.\n\nWhen activated, each type of robot will operate as follows.\n\nWhen a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.\n\nWhen a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.\n\nSnuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq K \\leq 100\n\n0 < x_i < K\n\nAll input values are integers.\n\nInputs\n\nInput is given from Standard Input in the following format:\n\nN\nK\nx_1 x_2 ... x_N\n\nOutputs\n\nPrint the minimum possible total distance covered by robots.\n\nSample Input 1\n\n1\n10\n2\n\nSample Output 1\n\n4\n\nThere are just one ball, one type-A robot and one type-B robot.\n\nIf the type-A robot is used to collect the ball, the distance from the robot to the ball is 2, and the distance from the ball to the original position of the robot is also 2, for a total distance of 4.\n\nSimilarly, if the type-B robot is used, the total distance covered will be 16.\n\nThus, the total distance covered will be minimized when the type-A robot is used. The output should be 4.\n\nSample Input 2\n\n2\n9\n3 6\n\nSample Output 2\n\n12\n\nThe total distance covered will be minimized when the first ball is collected by the type-A robot, and the second ball by the type-B robot.\n\nSample Input 3\n\n5\n20\n11 12 9 17 12\n\nSample Output 3\n\n74", "sample_input": "1\n10\n2\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03598", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i).\nThus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N.\n\nIn order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B.\nThen, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i).\nThus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N.\n\nWhen activated, each type of robot will operate as follows.\n\nWhen a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.\n\nWhen a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.\n\nSnuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq K \\leq 100\n\n0 < x_i < K\n\nAll input values are integers.\n\nInputs\n\nInput is given from Standard Input in the following format:\n\nN\nK\nx_1 x_2 ... x_N\n\nOutputs\n\nPrint the minimum possible total distance covered by robots.\n\nSample Input 1\n\n1\n10\n2\n\nSample Output 1\n\n4\n\nThere are just one ball, one type-A robot and one type-B robot.\n\nIf the type-A robot is used to collect the ball, the distance from the robot to the ball is 2, and the distance from the ball to the original position of the robot is also 2, for a total distance of 4.\n\nSimilarly, if the type-B robot is used, the total distance covered will be 16.\n\nThus, the total distance covered will be minimized when the type-A robot is used. The output should be 4.\n\nSample Input 2\n\n2\n9\n3 6\n\nSample Output 2\n\n12\n\nThe total distance covered will be minimized when the first ball is collected by the type-A robot, and the second ball by the type-B robot.\n\nSample Input 3\n\n5\n20\n11 12 9 17 12\n\nSample Output 3\n\n74", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 105, "cpu_time_ms": 19, "memory_kb": 4580}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s524813148", "group_id": "codeNet:p03599", "input_text": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n\n;;cyclone-loop\n(defun cyclone-reader (stream char)\n (declare (ignore char))\n `(loop ,@(read stream t nil t) do ,(read stream t nil t)))\n(set-macro-character #\\CYCLONE #'cyclone-reader)\n;;\n\n(let ((a (* (read) 100))\n (b (* (read) 100))\n (c (read))\n (d (read))\n (e (read))\n (f (read)))\n (declare (fixnum a) \n (fixnum b)\n (fixnum c)\n (fixnum d)\n (fixnum e)\n (fixnum f))\n 🌀 (for an to (truncate f a)\n :with max rational = -1\n :with amax fixnum = -1\n :with smax fixnum = 0\n :finally (format t \"~A ~A~%\" amax smax)) \n 🌀 (for bn to (truncate f b))\n 🌀 (for cn to (truncate f c))\n 🌀 (for dn to (truncate f d)\n :for s fixnum = (+ (* cn c) (* dn d))\n :for w fixnum = (+ (* an a) (* bn b))\n :for all fixnum = (+ w s))\n (when (and (not (zerop all))\n (> (/ s all) max)\n (<= all f)\n (<= (* s 100) (* e w)))\n (setf max (/ s all))\n (setf amax all)\n (setf smax s)))", "language": "Lisp", "metadata": {"date": 1505629300, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03599.html", "problem_id": "p03599", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03599/input.txt", "sample_output_relpath": "derived/input_output/data/p03599/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03599/Lisp/s524813148.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s524813148", "user_id": "u140665374"}, "prompt_components": {"gold_output": "110 10\n", "input_to_evaluate": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n\n;;cyclone-loop\n(defun cyclone-reader (stream char)\n (declare (ignore char))\n `(loop ,@(read stream t nil t) do ,(read stream t nil t)))\n(set-macro-character #\\CYCLONE #'cyclone-reader)\n;;\n\n(let ((a (* (read) 100))\n (b (* (read) 100))\n (c (read))\n (d (read))\n (e (read))\n (f (read)))\n (declare (fixnum a) \n (fixnum b)\n (fixnum c)\n (fixnum d)\n (fixnum e)\n (fixnum f))\n 🌀 (for an to (truncate f a)\n :with max rational = -1\n :with amax fixnum = -1\n :with smax fixnum = 0\n :finally (format t \"~A ~A~%\" amax smax)) \n 🌀 (for bn to (truncate f b))\n 🌀 (for cn to (truncate f c))\n 🌀 (for dn to (truncate f d)\n :for s fixnum = (+ (* cn c) (* dn d))\n :for w fixnum = (+ (* an a) (* bn b))\n :for all fixnum = (+ w s))\n (when (and (not (zerop all))\n (> (/ s all) max)\n (<= all f)\n (<= (* s 100) (* e w)))\n (setf max (/ s all))\n (setf amax all)\n (setf smax s)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke is making sugar water in a beaker.\nInitially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.\n\nOperation 1: Pour 100A grams of water into the beaker.\n\nOperation 2: Pour 100B grams of water into the beaker.\n\nOperation 3: Put C grams of sugar into the beaker.\n\nOperation 4: Put D grams of sugar into the beaker.\n\nIn our experimental environment, E grams of sugar can dissolve into 100 grams of water.\n\nSnuke will make sugar water with the highest possible density.\n\nThe beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker.\nFind the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it.\nIf there is more than one candidate, any of them will be accepted.\n\nWe remind you that the sugar water that contains a grams of water and b grams of sugar is \\frac{100b}{a + b} percent.\nAlso, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.\n\nConstraints\n\n1 \\leq A < B \\leq 30\n\n1 \\leq C < D \\leq 30\n\n1 \\leq E \\leq 100\n\n100A \\leq F \\leq 3 000\n\nA, B, C, D, E and F are all integers.\n\nInputs\n\nInput is given from Standard Input in the following format:\n\nA B C D E F\n\nOutputs\n\nPrint two integers separated by a space.\nThe first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it.\n\nSample Input 1\n\n1 2 10 20 15 200\n\nSample Output 1\n\n110 10\n\nIn this environment, 15 grams of sugar can dissolve into 100 grams of water, and the beaker can contain at most 200 grams of substances.\n\nWe can make 110 grams of sugar water by performing Operation 1 once and Operation 3 once.\nIt is not possible to make sugar water with higher density.\nFor example, the following sequences of operations are infeasible:\n\nIf we perform Operation 1 once and Operation 4 once, there will be undissolved sugar in the beaker.\n\nIf we perform Operation 2 once and Operation 3 three times, the mass of substances in the beaker will exceed 200 grams.\n\nSample Input 2\n\n1 2 1 2 100 1000\n\nSample Output 2\n\n200 100\n\nThere are other acceptable outputs, such as:\n\n400 200\n\nHowever, the output below is not acceptable:\n\n300 150\n\nThis is because, in order to make 300 grams of sugar water containing 150 grams of sugar, we need to pour exactly 150 grams of water into the beaker, which is impossible.\n\nSample Input 3\n\n17 19 22 26 55 2802\n\nSample Output 3\n\n2634 934", "sample_input": "1 2 10 20 15 200\n"}, "reference_outputs": ["110 10\n"], "source_document_id": "p03599", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke is making sugar water in a beaker.\nInitially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.\n\nOperation 1: Pour 100A grams of water into the beaker.\n\nOperation 2: Pour 100B grams of water into the beaker.\n\nOperation 3: Put C grams of sugar into the beaker.\n\nOperation 4: Put D grams of sugar into the beaker.\n\nIn our experimental environment, E grams of sugar can dissolve into 100 grams of water.\n\nSnuke will make sugar water with the highest possible density.\n\nThe beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker.\nFind the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it.\nIf there is more than one candidate, any of them will be accepted.\n\nWe remind you that the sugar water that contains a grams of water and b grams of sugar is \\frac{100b}{a + b} percent.\nAlso, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.\n\nConstraints\n\n1 \\leq A < B \\leq 30\n\n1 \\leq C < D \\leq 30\n\n1 \\leq E \\leq 100\n\n100A \\leq F \\leq 3 000\n\nA, B, C, D, E and F are all integers.\n\nInputs\n\nInput is given from Standard Input in the following format:\n\nA B C D E F\n\nOutputs\n\nPrint two integers separated by a space.\nThe first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it.\n\nSample Input 1\n\n1 2 10 20 15 200\n\nSample Output 1\n\n110 10\n\nIn this environment, 15 grams of sugar can dissolve into 100 grams of water, and the beaker can contain at most 200 grams of substances.\n\nWe can make 110 grams of sugar water by performing Operation 1 once and Operation 3 once.\nIt is not possible to make sugar water with higher density.\nFor example, the following sequences of operations are infeasible:\n\nIf we perform Operation 1 once and Operation 4 once, there will be undissolved sugar in the beaker.\n\nIf we perform Operation 2 once and Operation 3 three times, the mass of substances in the beaker will exceed 200 grams.\n\nSample Input 2\n\n1 2 1 2 100 1000\n\nSample Output 2\n\n200 100\n\nThere are other acceptable outputs, such as:\n\n400 200\n\nHowever, the output below is not acceptable:\n\n300 150\n\nThis is because, in order to make 300 grams of sugar water containing 150 grams of sugar, we need to pour exactly 150 grams of water into the beaker, which is impossible.\n\nSample Input 3\n\n17 19 22 26 55 2802\n\nSample Output 3\n\n2634 934", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1136, "cpu_time_ms": 3157, "memory_kb": 57704}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s514377096", "group_id": "codeNet:p03605", "input_text": "(let ((n (read)))\n (if (or (= (floor (/ n 10)) 9) (= (rem n 10) 9))\n (format t \"Yes\")\n (format t \"No\"))\n)", "language": "Lisp", "metadata": {"date": 1593817270, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03605.html", "problem_id": "p03605", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03605/input.txt", "sample_output_relpath": "derived/input_output/data/p03605/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03605/Lisp/s514377096.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s514377096", "user_id": "u136500538"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((n (read)))\n (if (or (= (floor (/ n 10)) 9) (= (rem n 10) 9))\n (format t \"Yes\")\n (format t \"No\"))\n)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIt is September 9 in Japan now.\n\nYou are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?\n\nConstraints\n\n10≤N≤99\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf 9 is contained in the decimal notation of N, print Yes; if not, print No.\n\nSample Input 1\n\n29\n\nSample Output 1\n\nYes\n\nThe one's digit of 29 is 9.\n\nSample Input 2\n\n72\n\nSample Output 2\n\nNo\n\n72 does not contain 9.\n\nSample Input 3\n\n91\n\nSample Output 3\n\nYes", "sample_input": "29\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03605", "source_text": "Score : 100 points\n\nProblem Statement\n\nIt is September 9 in Japan now.\n\nYou are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?\n\nConstraints\n\n10≤N≤99\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf 9 is contained in the decimal notation of N, print Yes; if not, print No.\n\nSample Input 1\n\n29\n\nSample Output 1\n\nYes\n\nThe one's digit of 29 is 9.\n\nSample Input 2\n\n72\n\nSample Output 2\n\nNo\n\n72 does not contain 9.\n\nSample Input 3\n\n91\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 114, "cpu_time_ms": 15, "memory_kb": 23120}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s925037454", "group_id": "codeNet:p03607", "input_text": "(let* ((n (read))\n (lst (concatenate 'list (sort (loop :repeat n :collect (read)) #'<) '(0)))\n (ans 0)\n (mem (cons 0 0)))\n (mapcar (lambda (k)\n (if (= (car mem) k)\n (incf (cdr mem))\n (progn\n (if (oddp (cdr mem))\n (incf ans))\n (setf mem (cons k 1))))) lst)\n (princ ans))", "language": "Lisp", "metadata": {"date": 1573577379, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03607.html", "problem_id": "p03607", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03607/input.txt", "sample_output_relpath": "derived/input_output/data/p03607/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03607/Lisp/s925037454.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s925037454", "user_id": "u610490393"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let* ((n (read))\n (lst (concatenate 'list (sort (loop :repeat n :collect (read)) #'<) '(0)))\n (ans 0)\n (mem (cons 0 0)))\n (mapcar (lambda (k)\n (if (= (car mem) k)\n (incf (cdr mem))\n (progn\n (if (oddp (cdr mem))\n (incf ans))\n (setf mem (cons k 1))))) lst)\n (princ ans))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are playing the following game with Joisino.\n\nInitially, you have a blank sheet of paper.\n\nJoisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.\n\nThen, you are asked a question: How many numbers are written on the sheet now?\n\nThe numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?\n\nConstraints\n\n1≤N≤100000\n\n1≤A_i≤1000000000(=10^9)\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1\n:\nA_N\n\nOutput\n\nPrint how many numbers will be written on the sheet at the end of the game.\n\nSample Input 1\n\n3\n6\n2\n6\n\nSample Output 1\n\n1\n\nThe game proceeds as follows:\n\n6 is not written on the sheet, so write 6.\n\n2 is not written on the sheet, so write 2.\n\n6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\nSample Input 2\n\n4\n2\n5\n5\n2\n\nSample Output 2\n\n0\n\nIt is possible that no number is written on the sheet in the end.\n\nSample Input 3\n\n6\n12\n22\n16\n22\n18\n12\n\nSample Output 3\n\n2", "sample_input": "3\n6\n2\n6\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03607", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are playing the following game with Joisino.\n\nInitially, you have a blank sheet of paper.\n\nJoisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.\n\nThen, you are asked a question: How many numbers are written on the sheet now?\n\nThe numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?\n\nConstraints\n\n1≤N≤100000\n\n1≤A_i≤1000000000(=10^9)\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1\n:\nA_N\n\nOutput\n\nPrint how many numbers will be written on the sheet at the end of the game.\n\nSample Input 1\n\n3\n6\n2\n6\n\nSample Output 1\n\n1\n\nThe game proceeds as follows:\n\n6 is not written on the sheet, so write 6.\n\n2 is not written on the sheet, so write 2.\n\n6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\nSample Input 2\n\n4\n2\n5\n5\n2\n\nSample Output 2\n\n0\n\nIt is possible that no number is written on the sheet in the end.\n\nSample Input 3\n\n6\n12\n22\n16\n22\n18\n12\n\nSample Output 3\n\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 385, "cpu_time_ms": 322, "memory_kb": 60008}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s566406729", "group_id": "codeNet:p03607", "input_text": "(let ((n (read))\n (a (make-hash-table)))\n (dotimes (i n)\n (let ((ai (read)))\n (setf (gethash ai a)\n (not (gethash ai a)))))\n (format t \"~A~%\" (loop for key being each hash-key of a\n using (hash-value value)\n when value count value)))\n", "language": "Lisp", "metadata": {"date": 1511628564, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03607.html", "problem_id": "p03607", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03607/input.txt", "sample_output_relpath": "derived/input_output/data/p03607/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03607/Lisp/s566406729.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s566406729", "user_id": "u275710783"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let ((n (read))\n (a (make-hash-table)))\n (dotimes (i n)\n (let ((ai (read)))\n (setf (gethash ai a)\n (not (gethash ai a)))))\n (format t \"~A~%\" (loop for key being each hash-key of a\n using (hash-value value)\n when value count value)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are playing the following game with Joisino.\n\nInitially, you have a blank sheet of paper.\n\nJoisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.\n\nThen, you are asked a question: How many numbers are written on the sheet now?\n\nThe numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?\n\nConstraints\n\n1≤N≤100000\n\n1≤A_i≤1000000000(=10^9)\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1\n:\nA_N\n\nOutput\n\nPrint how many numbers will be written on the sheet at the end of the game.\n\nSample Input 1\n\n3\n6\n2\n6\n\nSample Output 1\n\n1\n\nThe game proceeds as follows:\n\n6 is not written on the sheet, so write 6.\n\n2 is not written on the sheet, so write 2.\n\n6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\nSample Input 2\n\n4\n2\n5\n5\n2\n\nSample Output 2\n\n0\n\nIt is possible that no number is written on the sheet in the end.\n\nSample Input 3\n\n6\n12\n22\n16\n22\n18\n12\n\nSample Output 3\n\n2", "sample_input": "3\n6\n2\n6\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03607", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are playing the following game with Joisino.\n\nInitially, you have a blank sheet of paper.\n\nJoisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.\n\nThen, you are asked a question: How many numbers are written on the sheet now?\n\nThe numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?\n\nConstraints\n\n1≤N≤100000\n\n1≤A_i≤1000000000(=10^9)\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1\n:\nA_N\n\nOutput\n\nPrint how many numbers will be written on the sheet at the end of the game.\n\nSample Input 1\n\n3\n6\n2\n6\n\nSample Output 1\n\n1\n\nThe game proceeds as follows:\n\n6 is not written on the sheet, so write 6.\n\n2 is not written on the sheet, so write 2.\n\n6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\nSample Input 2\n\n4\n2\n5\n5\n2\n\nSample Output 2\n\n0\n\nIt is possible that no number is written on the sheet in the end.\n\nSample Input 3\n\n6\n12\n22\n16\n22\n18\n12\n\nSample Output 3\n\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 308, "cpu_time_ms": 421, "memory_kb": 67684}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s728125300", "group_id": "codeNet:p03607", "input_text": "(let ((lst (loop repeat (read) collect (read))))\n (do ((l (sort lst #'<) (cdr l))\n (n 1)\n (count 0))\n ((null l) (princ count))\n (if (eql (car l) (cadr l))\n\t(incf n)\n\t(and (incf count (if (oddp n) 1 0))\n\t (setf n 1)))))\n\t ", "language": "Lisp", "metadata": {"date": 1505211435, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03607.html", "problem_id": "p03607", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03607/input.txt", "sample_output_relpath": "derived/input_output/data/p03607/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03607/Lisp/s728125300.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s728125300", "user_id": "u158834201"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let ((lst (loop repeat (read) collect (read))))\n (do ((l (sort lst #'<) (cdr l))\n (n 1)\n (count 0))\n ((null l) (princ count))\n (if (eql (car l) (cadr l))\n\t(incf n)\n\t(and (incf count (if (oddp n) 1 0))\n\t (setf n 1)))))\n\t ", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are playing the following game with Joisino.\n\nInitially, you have a blank sheet of paper.\n\nJoisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.\n\nThen, you are asked a question: How many numbers are written on the sheet now?\n\nThe numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?\n\nConstraints\n\n1≤N≤100000\n\n1≤A_i≤1000000000(=10^9)\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1\n:\nA_N\n\nOutput\n\nPrint how many numbers will be written on the sheet at the end of the game.\n\nSample Input 1\n\n3\n6\n2\n6\n\nSample Output 1\n\n1\n\nThe game proceeds as follows:\n\n6 is not written on the sheet, so write 6.\n\n2 is not written on the sheet, so write 2.\n\n6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\nSample Input 2\n\n4\n2\n5\n5\n2\n\nSample Output 2\n\n0\n\nIt is possible that no number is written on the sheet in the end.\n\nSample Input 3\n\n6\n12\n22\n16\n22\n18\n12\n\nSample Output 3\n\n2", "sample_input": "3\n6\n2\n6\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03607", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are playing the following game with Joisino.\n\nInitially, you have a blank sheet of paper.\n\nJoisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.\n\nThen, you are asked a question: How many numbers are written on the sheet now?\n\nThe numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?\n\nConstraints\n\n1≤N≤100000\n\n1≤A_i≤1000000000(=10^9)\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1\n:\nA_N\n\nOutput\n\nPrint how many numbers will be written on the sheet at the end of the game.\n\nSample Input 1\n\n3\n6\n2\n6\n\nSample Output 1\n\n1\n\nThe game proceeds as follows:\n\n6 is not written on the sheet, so write 6.\n\n2 is not written on the sheet, so write 2.\n\n6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\nSample Input 2\n\n4\n2\n5\n5\n2\n\nSample Output 2\n\n0\n\nIt is possible that no number is written on the sheet in the end.\n\nSample Input 3\n\n6\n12\n22\n16\n22\n18\n12\n\nSample Output 3\n\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 249, "cpu_time_ms": 405, "memory_kb": 69732}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s269323757", "group_id": "codeNet:p03608", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))\n (declare (string string)\n ((simple-array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop for idx from offset below (length dest-vector)\n for pos1 = 0 then (1+ pos2)\n for pos2 = (position #\\space string :start pos1 :test #'char=)\n do (setf (aref dest-vector idx)\n (funcall key (parse-integer string :start pos1 :end pos2)))\n finally (return dest-vector)))\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #\\Newline))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (setf (schar ,buffer ,idx) ,terminate-char)\n (return (values ,buffer ,idx))))))\n\n(defmacro split-ints-and-bind (vars string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str (gensym \"STR\")))\n (labels ((expand (vars &optional (init-pos1 t))\n\t (if (null vars)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str :start ,pos1 :test #'char=))\n\t\t\t (,(car vars) (parse-integer ,str :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr vars) nil))))))\n `(let ((,str ,string))\n (declare (string ,str))\n\t ,@(expand vars)))))\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n(declaim (inline map-permutations!))\n(defun map-permutations! (function vector &optional (start 0) end)\n (declare (vector vector)\n (function function))\n (labels ((recurse (start end)\n (declare ((integer 0 #.most-positive-fixnum) start end))\n (if (> start end)\n (funcall function vector)\n (progn\n (recurse (1+ start) end)\n (loop for i from (1+ start) below end\n do (rotatef (aref vector start) (aref vector i))\n (recurse (1+ start) end)\n (rotatef (aref vector start) (aref vector i)))))))\n (recurse start (or end (length vector)))))\n\n(defmacro do-permutations! ((var vector &optional (start 0) end) &body body)\n `(map-permutations! (lambda (,var) ,@body) ,vector ,start ,end))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (r (read))\n (rs (make-array r :element-type 'uint8))\n (mat (make-array (list n n) :element-type 'uint32 :initial-element #xffffffff)))\n (declare (uint32 n m r))\n (split-ints-into-vector (read-line) rs :key #'1-)\n (dotimes (i n)\n (setf (aref mat i i) 0))\n (dotimes (i m)\n (split-ints-and-bind (a b cost) (buffered-read-line 20)\n (declare (uint32 a b))\n (setf (aref mat (- a 1) (- b 1)) cost\n (aref mat (- b 1) (- a 1)) cost)))\n (dotimes (k n)\n (dotimes (i n)\n (do ((j (1+ i) (1+ j)))\n ((= j n))\n (when (> (aref mat i j) (+ (aref mat i k) (aref mat k j)))\n (setf (aref mat i j) (+ (aref mat i k) (aref mat k j))\n (aref mat j i) (aref mat i j))))))\n (let ((min-cost #xffffffff))\n (do-permutations! (path rs)\n (let ((cost (loop for idx below (- r 1)\n sum (aref mat (aref path idx) (aref path (1+ idx)))\n of-type uint32)))\n (when (< cost min-cost)\n (setf min-cost cost))))\n (println min-cost))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1547702787, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03608.html", "problem_id": "p03608", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03608/input.txt", "sample_output_relpath": "derived/input_output/data/p03608/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03608/Lisp/s269323757.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s269323757", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))\n (declare (string string)\n ((simple-array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop for idx from offset below (length dest-vector)\n for pos1 = 0 then (1+ pos2)\n for pos2 = (position #\\space string :start pos1 :test #'char=)\n do (setf (aref dest-vector idx)\n (funcall key (parse-integer string :start pos1 :end pos2)))\n finally (return dest-vector)))\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #\\Newline))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (setf (schar ,buffer ,idx) ,terminate-char)\n (return (values ,buffer ,idx))))))\n\n(defmacro split-ints-and-bind (vars string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str (gensym \"STR\")))\n (labels ((expand (vars &optional (init-pos1 t))\n\t (if (null vars)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str :start ,pos1 :test #'char=))\n\t\t\t (,(car vars) (parse-integer ,str :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr vars) nil))))))\n `(let ((,str ,string))\n (declare (string ,str))\n\t ,@(expand vars)))))\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n(declaim (inline map-permutations!))\n(defun map-permutations! (function vector &optional (start 0) end)\n (declare (vector vector)\n (function function))\n (labels ((recurse (start end)\n (declare ((integer 0 #.most-positive-fixnum) start end))\n (if (> start end)\n (funcall function vector)\n (progn\n (recurse (1+ start) end)\n (loop for i from (1+ start) below end\n do (rotatef (aref vector start) (aref vector i))\n (recurse (1+ start) end)\n (rotatef (aref vector start) (aref vector i)))))))\n (recurse start (or end (length vector)))))\n\n(defmacro do-permutations! ((var vector &optional (start 0) end) &body body)\n `(map-permutations! (lambda (,var) ,@body) ,vector ,start ,end))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (r (read))\n (rs (make-array r :element-type 'uint8))\n (mat (make-array (list n n) :element-type 'uint32 :initial-element #xffffffff)))\n (declare (uint32 n m r))\n (split-ints-into-vector (read-line) rs :key #'1-)\n (dotimes (i n)\n (setf (aref mat i i) 0))\n (dotimes (i m)\n (split-ints-and-bind (a b cost) (buffered-read-line 20)\n (declare (uint32 a b))\n (setf (aref mat (- a 1) (- b 1)) cost\n (aref mat (- b 1) (- a 1)) cost)))\n (dotimes (k n)\n (dotimes (i n)\n (do ((j (1+ i) (1+ j)))\n ((= j n))\n (when (> (aref mat i j) (+ (aref mat i k) (aref mat k j)))\n (setf (aref mat i j) (+ (aref mat i k) (aref mat k j))\n (aref mat j i) (aref mat i j))))))\n (let ((min-cost #xffffffff))\n (do-permutations! (path rs)\n (let ((cost (loop for idx below (- r 1)\n sum (aref mat (aref path idx) (aref path (1+ idx)))\n of-type uint32)))\n (when (< cost min-cost)\n (setf min-cost cost))))\n (println min-cost))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are N towns in the State of Atcoder, connected by M bidirectional roads.\n\nThe i-th road connects Town A_i and B_i and has a length of C_i.\n\nJoisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order).\n\nShe will fly to the first town she visits, and fly back from the last town she visits, but for the rest of the trip she will have to travel by road.\n\nIf she visits the towns in the order that minimizes the distance traveled by road, what will that distance be?\n\nConstraints\n\n2≤N≤200\n\n1≤M≤N×(N-1)/2\n\n2≤R≤min(8,N) (min(8,N) is the smaller of 8 and N.)\n\nr_i≠r_j (i≠j)\n\n1≤A_i,B_i≤N, A_i≠B_i\n\n(A_i,B_i)≠(A_j,B_j),(A_i,B_i)≠(B_j,A_j) (i≠j)\n\n1≤C_i≤100000\n\nEvery town can be reached from every town by road.\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M R\nr_1 ... r_R\nA_1 B_1 C_1\n:\nA_M B_M C_M\n\nOutput\n\nPrint the distance traveled by road if Joisino visits the towns in the order that minimizes it.\n\nSample Input 1\n\n3 3 3\n1 2 3\n1 2 1\n2 3 1\n3 1 4\n\nSample Output 1\n\n2\n\nFor example, if she visits the towns in the order of 1, 2, 3, the distance traveled will be 2, which is the minimum possible.\n\nSample Input 2\n\n3 3 2\n1 3\n2 3 2\n1 3 6\n1 2 2\n\nSample Output 2\n\n4\n\nThe shortest distance between Towns 1 and 3 is 4. Thus, whether she visits Town 1 or 3 first, the distance traveled will be 4.\n\nSample Input 3\n\n4 6 3\n2 3 4\n1 2 4\n2 3 3\n4 3 1\n1 4 1\n4 2 2\n3 1 6\n\nSample Output 3\n\n3", "sample_input": "3 3 3\n1 2 3\n1 2 1\n2 3 1\n3 1 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03608", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are N towns in the State of Atcoder, connected by M bidirectional roads.\n\nThe i-th road connects Town A_i and B_i and has a length of C_i.\n\nJoisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order).\n\nShe will fly to the first town she visits, and fly back from the last town she visits, but for the rest of the trip she will have to travel by road.\n\nIf she visits the towns in the order that minimizes the distance traveled by road, what will that distance be?\n\nConstraints\n\n2≤N≤200\n\n1≤M≤N×(N-1)/2\n\n2≤R≤min(8,N) (min(8,N) is the smaller of 8 and N.)\n\nr_i≠r_j (i≠j)\n\n1≤A_i,B_i≤N, A_i≠B_i\n\n(A_i,B_i)≠(A_j,B_j),(A_i,B_i)≠(B_j,A_j) (i≠j)\n\n1≤C_i≤100000\n\nEvery town can be reached from every town by road.\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M R\nr_1 ... r_R\nA_1 B_1 C_1\n:\nA_M B_M C_M\n\nOutput\n\nPrint the distance traveled by road if Joisino visits the towns in the order that minimizes it.\n\nSample Input 1\n\n3 3 3\n1 2 3\n1 2 1\n2 3 1\n3 1 4\n\nSample Output 1\n\n2\n\nFor example, if she visits the towns in the order of 1, 2, 3, the distance traveled will be 2, which is the minimum possible.\n\nSample Input 2\n\n3 3 2\n1 3\n2 3 2\n1 3 6\n1 2 2\n\nSample Output 2\n\n4\n\nThe shortest distance between Towns 1 and 3 is 4. Thus, whether she visits Town 1 or 3 first, the distance traveled will be 4.\n\nSample Input 3\n\n4 6 3\n2 3 4\n1 2 4\n2 3 3\n4 3 1\n1 4 1\n4 2 2\n3 1 6\n\nSample Output 3\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4901, "cpu_time_ms": 183, "memory_kb": 26088}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s658897382", "group_id": "codeNet:p03610", "input_text": "(let ((s (concatenate 'list (read-line))))\n\n (defun f (lst)\n (if (null lst)\n nil\n (cons (car lst) (f (cddr lst)))))\n\n (format t \"~A~%\"\n (concatenate 'string (f s))))\n\n", "language": "Lisp", "metadata": {"date": 1595192695, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03610.html", "problem_id": "p03610", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03610/input.txt", "sample_output_relpath": "derived/input_output/data/p03610/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03610/Lisp/s658897382.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s658897382", "user_id": "u336541610"}, "prompt_components": {"gold_output": "acdr\n", "input_to_evaluate": "(let ((s (concatenate 'list (read-line))))\n\n (defun f (lst)\n (if (null lst)\n nil\n (cons (car lst) (f (cddr lst)))))\n\n (format t \"~A~%\"\n (concatenate 'string (f s))))\n\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.\n\nConstraints\n\nEach character in s is a lowercase English letter.\n\n1≤|s|≤10^5\n\nInput\n\nThe input is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the string obtained by concatenating all the characters in the odd-numbered positions.\n\nSample Input 1\n\natcoder\n\nSample Output 1\n\nacdr\n\nExtract the first character a, the third character c, the fifth character d and the seventh character r to obtain acdr.\n\nSample Input 2\n\naaaa\n\nSample Output 2\n\naa\n\nSample Input 3\n\nz\n\nSample Output 3\n\nz\n\nSample Input 4\n\nfukuokayamaguchi\n\nSample Output 4\n\nfkoaaauh", "sample_input": "atcoder\n"}, "reference_outputs": ["acdr\n"], "source_document_id": "p03610", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.\n\nConstraints\n\nEach character in s is a lowercase English letter.\n\n1≤|s|≤10^5\n\nInput\n\nThe input is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the string obtained by concatenating all the characters in the odd-numbered positions.\n\nSample Input 1\n\natcoder\n\nSample Output 1\n\nacdr\n\nExtract the first character a, the third character c, the fifth character d and the seventh character r to obtain acdr.\n\nSample Input 2\n\naaaa\n\nSample Output 2\n\naa\n\nSample Input 3\n\nz\n\nSample Output 3\n\nz\n\nSample Input 4\n\nfukuokayamaguchi\n\nSample Output 4\n\nfkoaaauh", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 191, "cpu_time_ms": 22, "memory_kb": 28328}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s018810679", "group_id": "codeNet:p03610", "input_text": "(let ((lst (concatenate 'list (read-line))))\n (loop :for a :from 0 :upto (1- (length lst)) :by 2 :do(princ (nth a lst))))", "language": "Lisp", "metadata": {"date": 1553207951, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03610.html", "problem_id": "p03610", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03610/input.txt", "sample_output_relpath": "derived/input_output/data/p03610/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03610/Lisp/s018810679.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s018810679", "user_id": "u610490393"}, "prompt_components": {"gold_output": "acdr\n", "input_to_evaluate": "(let ((lst (concatenate 'list (read-line))))\n (loop :for a :from 0 :upto (1- (length lst)) :by 2 :do(princ (nth a lst))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.\n\nConstraints\n\nEach character in s is a lowercase English letter.\n\n1≤|s|≤10^5\n\nInput\n\nThe input is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the string obtained by concatenating all the characters in the odd-numbered positions.\n\nSample Input 1\n\natcoder\n\nSample Output 1\n\nacdr\n\nExtract the first character a, the third character c, the fifth character d and the seventh character r to obtain acdr.\n\nSample Input 2\n\naaaa\n\nSample Output 2\n\naa\n\nSample Input 3\n\nz\n\nSample Output 3\n\nz\n\nSample Input 4\n\nfukuokayamaguchi\n\nSample Output 4\n\nfkoaaauh", "sample_input": "atcoder\n"}, "reference_outputs": ["acdr\n"], "source_document_id": "p03610", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.\n\nConstraints\n\nEach character in s is a lowercase English letter.\n\n1≤|s|≤10^5\n\nInput\n\nThe input is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the string obtained by concatenating all the characters in the odd-numbered positions.\n\nSample Input 1\n\natcoder\n\nSample Output 1\n\nacdr\n\nExtract the first character a, the third character c, the fifth character d and the seventh character r to obtain acdr.\n\nSample Input 2\n\naaaa\n\nSample Output 2\n\naa\n\nSample Input 3\n\nz\n\nSample Output 3\n\nz\n\nSample Input 4\n\nfukuokayamaguchi\n\nSample Output 4\n\nfkoaaauh", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 122, "cpu_time_ms": 2104, "memory_kb": 11360}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s256405463", "group_id": "codeNet:p03610", "input_text": "(let((s(read-line))(c 0))(loop for i across s do(if(=(mod(incf c)2)1)(format t\"~A\"i))))", "language": "Lisp", "metadata": {"date": 1534841853, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03610.html", "problem_id": "p03610", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03610/input.txt", "sample_output_relpath": "derived/input_output/data/p03610/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03610/Lisp/s256405463.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s256405463", "user_id": "u657913472"}, "prompt_components": {"gold_output": "acdr\n", "input_to_evaluate": "(let((s(read-line))(c 0))(loop for i across s do(if(=(mod(incf c)2)1)(format t\"~A\"i))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.\n\nConstraints\n\nEach character in s is a lowercase English letter.\n\n1≤|s|≤10^5\n\nInput\n\nThe input is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the string obtained by concatenating all the characters in the odd-numbered positions.\n\nSample Input 1\n\natcoder\n\nSample Output 1\n\nacdr\n\nExtract the first character a, the third character c, the fifth character d and the seventh character r to obtain acdr.\n\nSample Input 2\n\naaaa\n\nSample Output 2\n\naa\n\nSample Input 3\n\nz\n\nSample Output 3\n\nz\n\nSample Input 4\n\nfukuokayamaguchi\n\nSample Output 4\n\nfkoaaauh", "sample_input": "atcoder\n"}, "reference_outputs": ["acdr\n"], "source_document_id": "p03610", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.\n\nConstraints\n\nEach character in s is a lowercase English letter.\n\n1≤|s|≤10^5\n\nInput\n\nThe input is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the string obtained by concatenating all the characters in the odd-numbered positions.\n\nSample Input 1\n\natcoder\n\nSample Output 1\n\nacdr\n\nExtract the first character a, the third character c, the fifth character d and the seventh character r to obtain acdr.\n\nSample Input 2\n\naaaa\n\nSample Output 2\n\naa\n\nSample Input 3\n\nz\n\nSample Output 3\n\nz\n\nSample Input 4\n\nfukuokayamaguchi\n\nSample Output 4\n\nfkoaaauh", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 87, "cpu_time_ms": 52, "memory_kb": 18788}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s877071845", "group_id": "codeNet:p03611", "input_text": "(labels ((f ()\n\t (loop repeat (read)\n\t\tcollect (let ((number (read)))\n\t\t\t (list (1- number) number (1+ number)))))\n\t (g (list)\n\t (loop with flatten = (apply #'append list)\n\t for number in (remove-duplicates flatten)\n\t maximize (count number flatten))))\n (princ (g (f))))\n", "language": "Lisp", "metadata": {"date": 1504418384, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03611.html", "problem_id": "p03611", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03611/input.txt", "sample_output_relpath": "derived/input_output/data/p03611/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03611/Lisp/s877071845.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s877071845", "user_id": "u158834201"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(labels ((f ()\n\t (loop repeat (read)\n\t\tcollect (let ((number (read)))\n\t\t\t (list (1- number) number (1+ number)))))\n\t (g (list)\n\t (loop with flatten = (apply #'append list)\n\t for number in (remove-duplicates flatten)\n\t maximize (count number flatten))))\n (princ (g (f))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given an integer sequence of length N, a_1,a_2,...,a_N.\n\nFor each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing.\n\nAfter these operations, you select an integer X and count the number of i such that a_i=X.\n\nMaximize this count by making optimal choices.\n\nConstraints\n\n1≤N≤10^5\n\n0≤a_i<10^5 (1≤i≤N)\n\na_i is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\na_1 a_2 .. a_N\n\nOutput\n\nPrint the maximum possible number of i such that a_i=X.\n\nSample Input 1\n\n7\n3 1 4 1 5 9 2\n\nSample Output 1\n\n4\n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4, the maximum possible count.\n\nSample Input 2\n\n10\n0 1 2 3 4 5 6 7 8 9\n\nSample Output 2\n\n3\n\nSample Input 3\n\n1\n99999\n\nSample Output 3\n\n1", "sample_input": "7\n3 1 4 1 5 9 2\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03611", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given an integer sequence of length N, a_1,a_2,...,a_N.\n\nFor each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing.\n\nAfter these operations, you select an integer X and count the number of i such that a_i=X.\n\nMaximize this count by making optimal choices.\n\nConstraints\n\n1≤N≤10^5\n\n0≤a_i<10^5 (1≤i≤N)\n\na_i is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\na_1 a_2 .. a_N\n\nOutput\n\nPrint the maximum possible number of i such that a_i=X.\n\nSample Input 1\n\n7\n3 1 4 1 5 9 2\n\nSample Output 1\n\n4\n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4, the maximum possible count.\n\nSample Input 2\n\n10\n0 1 2 3 4 5 6 7 8 9\n\nSample Output 2\n\n3\n\nSample Input 3\n\n1\n99999\n\nSample Output 3\n\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 291, "cpu_time_ms": 208, "memory_kb": 63848}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s937879977", "group_id": "codeNet:p03617", "input_text": "(let ((q (read))\n (h (read))\n (s (read))\n (d (read))\n (n (read))\n ans)\n (setf s (min s (* 2 h) (* 4 q)))\n (cond ((> d (* 2 s)) (setf ans (* s n)))\n ((evenp n) (setf ans (* d (/ n 2))))\n (t (setf ans (+ (* d (/ (1- n) 2)) s))))\n (princ ans))\n", "language": "Lisp", "metadata": {"date": 1531798611, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03617.html", "problem_id": "p03617", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03617/input.txt", "sample_output_relpath": "derived/input_output/data/p03617/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03617/Lisp/s937879977.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s937879977", "user_id": "u994767958"}, "prompt_components": {"gold_output": "150\n", "input_to_evaluate": "(let ((q (read))\n (h (read))\n (s (read))\n (d (read))\n (n (read))\n ans)\n (setf s (min s (* 2 h) (* 4 q)))\n (cond ((> d (* 2 s)) (setf ans (* s n)))\n ((evenp n) (setf ans (* d (/ n 2))))\n (t (setf ans (+ (* d (/ (1- n) 2)) s))))\n (princ ans))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou've come to your favorite store Infinitesco to buy some ice tea.\n\nThe store sells ice tea in bottles of different volumes at different costs.\nSpecifically, a 0.25-liter bottle costs Q yen, a 0.5-liter bottle costs H yen, a 1-liter bottle costs S yen, and a 2-liter bottle costs D yen.\nThe store has an infinite supply of bottles of each type.\n\nYou want to buy exactly N liters of ice tea. How many yen do you have to spend?\n\nConstraints\n\n1 \\leq Q, H, S, D \\leq 10^8\n\n1 \\leq N \\leq 10^9\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nQ H S D\nN\n\nOutput\n\nPrint the smallest number of yen you have to spend to buy exactly N liters of ice tea.\n\nSample Input 1\n\n20 30 70 90\n3\n\nSample Output 1\n\n150\n\nBuy one 2-liter bottle and two 0.5-liter bottles. You'll get 3 liters for 90 + 30 + 30 = 150 yen.\n\nSample Input 2\n\n10000 1000 100 10\n1\n\nSample Output 2\n\n100\n\nEven though a 2-liter bottle costs just 10 yen, you need only 1 liter.\nThus, you have to buy a 1-liter bottle for 100 yen.\n\nSample Input 3\n\n10 100 1000 10000\n1\n\nSample Output 3\n\n40\n\nNow it's better to buy four 0.25-liter bottles for 10 + 10 + 10 + 10 = 40 yen.\n\nSample Input 4\n\n12345678 87654321 12345678 87654321\n123456789\n\nSample Output 4\n\n1524157763907942", "sample_input": "20 30 70 90\n3\n"}, "reference_outputs": ["150\n"], "source_document_id": "p03617", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou've come to your favorite store Infinitesco to buy some ice tea.\n\nThe store sells ice tea in bottles of different volumes at different costs.\nSpecifically, a 0.25-liter bottle costs Q yen, a 0.5-liter bottle costs H yen, a 1-liter bottle costs S yen, and a 2-liter bottle costs D yen.\nThe store has an infinite supply of bottles of each type.\n\nYou want to buy exactly N liters of ice tea. How many yen do you have to spend?\n\nConstraints\n\n1 \\leq Q, H, S, D \\leq 10^8\n\n1 \\leq N \\leq 10^9\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nQ H S D\nN\n\nOutput\n\nPrint the smallest number of yen you have to spend to buy exactly N liters of ice tea.\n\nSample Input 1\n\n20 30 70 90\n3\n\nSample Output 1\n\n150\n\nBuy one 2-liter bottle and two 0.5-liter bottles. You'll get 3 liters for 90 + 30 + 30 = 150 yen.\n\nSample Input 2\n\n10000 1000 100 10\n1\n\nSample Output 2\n\n100\n\nEven though a 2-liter bottle costs just 10 yen, you need only 1 liter.\nThus, you have to buy a 1-liter bottle for 100 yen.\n\nSample Input 3\n\n10 100 1000 10000\n1\n\nSample Output 3\n\n40\n\nNow it's better to buy four 0.25-liter bottles for 10 + 10 + 10 + 10 = 40 yen.\n\nSample Input 4\n\n12345678 87654321 12345678 87654321\n123456789\n\nSample Output 4\n\n1524157763907942", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 283, "cpu_time_ms": 152, "memory_kb": 13672}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s564082794", "group_id": "codeNet:p03617", "input_text": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n\n(let ((q (read))\n (h (read))\n (s (read))\n (d (read))\n (n (read))\n (p 0))\n (setf s (min (* 4 q) (* 2 h) s))\n (when (= (mod n 2) 1)\n (setf n (- n 1))\n (setf p 1))\n (if (< (+ (* d (/ n 2)) (* p s)) (* (+ p n) s))\n (setf a (+ (* d (/ n 2)) (* p s)))\n (setf a (* (+ p n) s)))\n (format t \"~A~%\" a))", "language": "Lisp", "metadata": {"date": 1520301562, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03617.html", "problem_id": "p03617", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03617/input.txt", "sample_output_relpath": "derived/input_output/data/p03617/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03617/Lisp/s564082794.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s564082794", "user_id": "u672956630"}, "prompt_components": {"gold_output": "150\n", "input_to_evaluate": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n\n(let ((q (read))\n (h (read))\n (s (read))\n (d (read))\n (n (read))\n (p 0))\n (setf s (min (* 4 q) (* 2 h) s))\n (when (= (mod n 2) 1)\n (setf n (- n 1))\n (setf p 1))\n (if (< (+ (* d (/ n 2)) (* p s)) (* (+ p n) s))\n (setf a (+ (* d (/ n 2)) (* p s)))\n (setf a (* (+ p n) s)))\n (format t \"~A~%\" a))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou've come to your favorite store Infinitesco to buy some ice tea.\n\nThe store sells ice tea in bottles of different volumes at different costs.\nSpecifically, a 0.25-liter bottle costs Q yen, a 0.5-liter bottle costs H yen, a 1-liter bottle costs S yen, and a 2-liter bottle costs D yen.\nThe store has an infinite supply of bottles of each type.\n\nYou want to buy exactly N liters of ice tea. How many yen do you have to spend?\n\nConstraints\n\n1 \\leq Q, H, S, D \\leq 10^8\n\n1 \\leq N \\leq 10^9\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nQ H S D\nN\n\nOutput\n\nPrint the smallest number of yen you have to spend to buy exactly N liters of ice tea.\n\nSample Input 1\n\n20 30 70 90\n3\n\nSample Output 1\n\n150\n\nBuy one 2-liter bottle and two 0.5-liter bottles. You'll get 3 liters for 90 + 30 + 30 = 150 yen.\n\nSample Input 2\n\n10000 1000 100 10\n1\n\nSample Output 2\n\n100\n\nEven though a 2-liter bottle costs just 10 yen, you need only 1 liter.\nThus, you have to buy a 1-liter bottle for 100 yen.\n\nSample Input 3\n\n10 100 1000 10000\n1\n\nSample Output 3\n\n40\n\nNow it's better to buy four 0.25-liter bottles for 10 + 10 + 10 + 10 = 40 yen.\n\nSample Input 4\n\n12345678 87654321 12345678 87654321\n123456789\n\nSample Output 4\n\n1524157763907942", "sample_input": "20 30 70 90\n3\n"}, "reference_outputs": ["150\n"], "source_document_id": "p03617", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou've come to your favorite store Infinitesco to buy some ice tea.\n\nThe store sells ice tea in bottles of different volumes at different costs.\nSpecifically, a 0.25-liter bottle costs Q yen, a 0.5-liter bottle costs H yen, a 1-liter bottle costs S yen, and a 2-liter bottle costs D yen.\nThe store has an infinite supply of bottles of each type.\n\nYou want to buy exactly N liters of ice tea. How many yen do you have to spend?\n\nConstraints\n\n1 \\leq Q, H, S, D \\leq 10^8\n\n1 \\leq N \\leq 10^9\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nQ H S D\nN\n\nOutput\n\nPrint the smallest number of yen you have to spend to buy exactly N liters of ice tea.\n\nSample Input 1\n\n20 30 70 90\n3\n\nSample Output 1\n\n150\n\nBuy one 2-liter bottle and two 0.5-liter bottles. You'll get 3 liters for 90 + 30 + 30 = 150 yen.\n\nSample Input 2\n\n10000 1000 100 10\n1\n\nSample Output 2\n\n100\n\nEven though a 2-liter bottle costs just 10 yen, you need only 1 liter.\nThus, you have to buy a 1-liter bottle for 100 yen.\n\nSample Input 3\n\n10 100 1000 10000\n1\n\nSample Output 3\n\n40\n\nNow it's better to buy four 0.25-liter bottles for 10 + 10 + 10 + 10 = 40 yen.\n\nSample Input 4\n\n12345678 87654321 12345678 87654321\n123456789\n\nSample Output 4\n\n1524157763907942", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 386, "cpu_time_ms": 22, "memory_kb": 6504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s346927677", "group_id": "codeNet:p03623", "input_text": "(let ((x (read))\n (a (read))\n (b (read)))\n\n (format t \"~A~%\"\n (if (< (abs (- x a)) (abs (- x b)))\n 'a\n 'b)))\n", "language": "Lisp", "metadata": {"date": 1595189604, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03623.html", "problem_id": "p03623", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03623/input.txt", "sample_output_relpath": "derived/input_output/data/p03623/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03623/Lisp/s346927677.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s346927677", "user_id": "u336541610"}, "prompt_components": {"gold_output": "B\n", "input_to_evaluate": "(let ((x (read))\n (a (read))\n (b (read)))\n\n (format t \"~A~%\"\n (if (< (abs (- x a)) (abs (- x b)))\n 'a\n 'b)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nSnuke lives at position x on a number line.\nOn this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.\n\nSnuke decided to get food delivery from the closer of stores A and B.\nFind out which store is closer to Snuke's residence.\n\nHere, the distance between two points s and t on a number line is represented by |s-t|.\n\nConstraints\n\n1 \\leq x \\leq 1000\n\n1 \\leq a \\leq 1000\n\n1 \\leq b \\leq 1000\n\nx, a and b are pairwise distinct.\n\nThe distances between Snuke's residence and stores A and B are different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx a b\n\nOutput\n\nIf store A is closer, print A; if store B is closer, print B.\n\nSample Input 1\n\n5 2 7\n\nSample Output 1\n\nB\n\nThe distances between Snuke's residence and stores A and B are 3 and 2, respectively.\nSince store B is closer, print B.\n\nSample Input 2\n\n1 999 1000\n\nSample Output 2\n\nA", "sample_input": "5 2 7\n"}, "reference_outputs": ["B\n"], "source_document_id": "p03623", "source_text": "Score : 100 points\n\nProblem Statement\n\nSnuke lives at position x on a number line.\nOn this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.\n\nSnuke decided to get food delivery from the closer of stores A and B.\nFind out which store is closer to Snuke's residence.\n\nHere, the distance between two points s and t on a number line is represented by |s-t|.\n\nConstraints\n\n1 \\leq x \\leq 1000\n\n1 \\leq a \\leq 1000\n\n1 \\leq b \\leq 1000\n\nx, a and b are pairwise distinct.\n\nThe distances between Snuke's residence and stores A and B are different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx a b\n\nOutput\n\nIf store A is closer, print A; if store B is closer, print B.\n\nSample Input 1\n\n5 2 7\n\nSample Output 1\n\nB\n\nThe distances between Snuke's residence and stores A and B are 3 and 2, respectively.\nSince store B is closer, print B.\n\nSample Input 2\n\n1 999 1000\n\nSample Output 2\n\nA", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 151, "cpu_time_ms": 18, "memory_kb": 23320}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s505221569", "group_id": "codeNet:p03623", "input_text": "(let* ((x (read))\n (a (abs (- (read) x)))\n (b (abs (- (read) x))))\n (if (< a b) (princ \"A\") (princ \"B\")))", "language": "Lisp", "metadata": {"date": 1557157191, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03623.html", "problem_id": "p03623", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03623/input.txt", "sample_output_relpath": "derived/input_output/data/p03623/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03623/Lisp/s505221569.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s505221569", "user_id": "u610490393"}, "prompt_components": {"gold_output": "B\n", "input_to_evaluate": "(let* ((x (read))\n (a (abs (- (read) x)))\n (b (abs (- (read) x))))\n (if (< a b) (princ \"A\") (princ \"B\")))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nSnuke lives at position x on a number line.\nOn this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.\n\nSnuke decided to get food delivery from the closer of stores A and B.\nFind out which store is closer to Snuke's residence.\n\nHere, the distance between two points s and t on a number line is represented by |s-t|.\n\nConstraints\n\n1 \\leq x \\leq 1000\n\n1 \\leq a \\leq 1000\n\n1 \\leq b \\leq 1000\n\nx, a and b are pairwise distinct.\n\nThe distances between Snuke's residence and stores A and B are different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx a b\n\nOutput\n\nIf store A is closer, print A; if store B is closer, print B.\n\nSample Input 1\n\n5 2 7\n\nSample Output 1\n\nB\n\nThe distances between Snuke's residence and stores A and B are 3 and 2, respectively.\nSince store B is closer, print B.\n\nSample Input 2\n\n1 999 1000\n\nSample Output 2\n\nA", "sample_input": "5 2 7\n"}, "reference_outputs": ["B\n"], "source_document_id": "p03623", "source_text": "Score : 100 points\n\nProblem Statement\n\nSnuke lives at position x on a number line.\nOn this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.\n\nSnuke decided to get food delivery from the closer of stores A and B.\nFind out which store is closer to Snuke's residence.\n\nHere, the distance between two points s and t on a number line is represented by |s-t|.\n\nConstraints\n\n1 \\leq x \\leq 1000\n\n1 \\leq a \\leq 1000\n\n1 \\leq b \\leq 1000\n\nx, a and b are pairwise distinct.\n\nThe distances between Snuke's residence and stores A and B are different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx a b\n\nOutput\n\nIf store A is closer, print A; if store B is closer, print B.\n\nSample Input 1\n\n5 2 7\n\nSample Output 1\n\nB\n\nThe distances between Snuke's residence and stores A and B are 3 and 2, respectively.\nSince store B is closer, print B.\n\nSample Input 2\n\n1 999 1000\n\nSample Output 2\n\nA", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 118, "cpu_time_ms": 8, "memory_kb": 3304}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s632679861", "group_id": "codeNet:p03623", "input_text": "(let ((x (read))\n (a (read))\n (b (read)))\n (format t \"~A~%\"\n (if (< (abs (- x a)) (abs (- x b)))\n \"A\" \"B\")))", "language": "Lisp", "metadata": {"date": 1513726026, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03623.html", "problem_id": "p03623", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03623/input.txt", "sample_output_relpath": "derived/input_output/data/p03623/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03623/Lisp/s632679861.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s632679861", "user_id": "u275710783"}, "prompt_components": {"gold_output": "B\n", "input_to_evaluate": "(let ((x (read))\n (a (read))\n (b (read)))\n (format t \"~A~%\"\n (if (< (abs (- x a)) (abs (- x b)))\n \"A\" \"B\")))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nSnuke lives at position x on a number line.\nOn this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.\n\nSnuke decided to get food delivery from the closer of stores A and B.\nFind out which store is closer to Snuke's residence.\n\nHere, the distance between two points s and t on a number line is represented by |s-t|.\n\nConstraints\n\n1 \\leq x \\leq 1000\n\n1 \\leq a \\leq 1000\n\n1 \\leq b \\leq 1000\n\nx, a and b are pairwise distinct.\n\nThe distances between Snuke's residence and stores A and B are different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx a b\n\nOutput\n\nIf store A is closer, print A; if store B is closer, print B.\n\nSample Input 1\n\n5 2 7\n\nSample Output 1\n\nB\n\nThe distances between Snuke's residence and stores A and B are 3 and 2, respectively.\nSince store B is closer, print B.\n\nSample Input 2\n\n1 999 1000\n\nSample Output 2\n\nA", "sample_input": "5 2 7\n"}, "reference_outputs": ["B\n"], "source_document_id": "p03623", "source_text": "Score : 100 points\n\nProblem Statement\n\nSnuke lives at position x on a number line.\nOn this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.\n\nSnuke decided to get food delivery from the closer of stores A and B.\nFind out which store is closer to Snuke's residence.\n\nHere, the distance between two points s and t on a number line is represented by |s-t|.\n\nConstraints\n\n1 \\leq x \\leq 1000\n\n1 \\leq a \\leq 1000\n\n1 \\leq b \\leq 1000\n\nx, a and b are pairwise distinct.\n\nThe distances between Snuke's residence and stores A and B are different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx a b\n\nOutput\n\nIf store A is closer, print A; if store B is closer, print B.\n\nSample Input 1\n\n5 2 7\n\nSample Output 1\n\nB\n\nThe distances between Snuke's residence and stores A and B are 3 and 2, respectively.\nSince store B is closer, print B.\n\nSample Input 2\n\n1 999 1000\n\nSample Output 2\n\nA", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 141, "cpu_time_ms": 26, "memory_kb": 4836}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s041480340", "group_id": "codeNet:p03625", "input_text": "(let* ((n (read))\n (lst (concatenate 'list (sort (loop :repeat n :collect (read)) #'<) '(0 0))))\n (defun f (ll a)\n (if (= (first ll) (second ll))\n (if a\n (* a (first ll))\n (f (cddr ll) (first ll)))\n (f (cdr ll) a)))\n (princ (f lst nil)))", "language": "Lisp", "metadata": {"date": 1573235200, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03625.html", "problem_id": "p03625", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03625/input.txt", "sample_output_relpath": "derived/input_output/data/p03625/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03625/Lisp/s041480340.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s041480340", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (read))\n (lst (concatenate 'list (sort (loop :repeat n :collect (read)) #'<) '(0 0))))\n (defun f (ll a)\n (if (= (first ll) (second ll))\n (if a\n (* a (first ll))\n (f (cddr ll) (first ll)))\n (f (cdr ll) a)))\n (princ (f lst nil)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWe have N sticks with negligible thickness.\nThe length of the i-th stick is A_i.\n\nSnuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides.\nFind the maximum possible area of the rectangle.\n\nConstraints\n\n4 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^9\n\nA_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible area of the rectangle.\nIf no rectangle can be formed, print 0.\n\nSample Input 1\n\n6\n3 1 2 4 2 1\n\nSample Output 1\n\n2\n\n1 \\times 2 rectangle can be formed.\n\nSample Input 2\n\n4\n1 2 3 4\n\nSample Output 2\n\n0\n\nNo rectangle can be formed.\n\nSample Input 3\n\n10\n3 3 3 3 4 4 4 5 5 5\n\nSample Output 3\n\n20", "sample_input": "6\n3 1 2 4 2 1\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03625", "source_text": "Score : 300 points\n\nProblem Statement\n\nWe have N sticks with negligible thickness.\nThe length of the i-th stick is A_i.\n\nSnuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides.\nFind the maximum possible area of the rectangle.\n\nConstraints\n\n4 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^9\n\nA_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible area of the rectangle.\nIf no rectangle can be formed, print 0.\n\nSample Input 1\n\n6\n3 1 2 4 2 1\n\nSample Output 1\n\n2\n\n1 \\times 2 rectangle can be formed.\n\nSample Input 2\n\n4\n1 2 3 4\n\nSample Output 2\n\n0\n\nNo rectangle can be formed.\n\nSample Input 3\n\n10\n3 3 3 3 4 4 4 5 5 5\n\nSample Output 3\n\n20", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 284, "cpu_time_ms": 427, "memory_kb": 69736}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s113980691", "group_id": "codeNet:p03625", "input_text": "(defun make-rec (N A-list)\n (let* ((candidates (remove-if-not\n (lambda (a) (>= (count a A-list) 2)) A-list))\n (sorted-candidates\n (if candidates (sort (remove-duplicates candidates :test #'=) #'>))))\n (if candidates\n (* (car sorted-candidates)\n (cadr sorted-candidates))\n 0)))\n\n(let* ((N (read))\n (A-list (loop repeat N collect (read))))\n (format t \"~A~%\" (make-rec N A-list)))", "language": "Lisp", "metadata": {"date": 1503774809, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03625.html", "problem_id": "p03625", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03625/input.txt", "sample_output_relpath": "derived/input_output/data/p03625/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03625/Lisp/s113980691.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s113980691", "user_id": "u876257701"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun make-rec (N A-list)\n (let* ((candidates (remove-if-not\n (lambda (a) (>= (count a A-list) 2)) A-list))\n (sorted-candidates\n (if candidates (sort (remove-duplicates candidates :test #'=) #'>))))\n (if candidates\n (* (car sorted-candidates)\n (cadr sorted-candidates))\n 0)))\n\n(let* ((N (read))\n (A-list (loop repeat N collect (read))))\n (format t \"~A~%\" (make-rec N A-list)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWe have N sticks with negligible thickness.\nThe length of the i-th stick is A_i.\n\nSnuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides.\nFind the maximum possible area of the rectangle.\n\nConstraints\n\n4 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^9\n\nA_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible area of the rectangle.\nIf no rectangle can be formed, print 0.\n\nSample Input 1\n\n6\n3 1 2 4 2 1\n\nSample Output 1\n\n2\n\n1 \\times 2 rectangle can be formed.\n\nSample Input 2\n\n4\n1 2 3 4\n\nSample Output 2\n\n0\n\nNo rectangle can be formed.\n\nSample Input 3\n\n10\n3 3 3 3 4 4 4 5 5 5\n\nSample Output 3\n\n20", "sample_input": "6\n3 1 2 4 2 1\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03625", "source_text": "Score : 300 points\n\nProblem Statement\n\nWe have N sticks with negligible thickness.\nThe length of the i-th stick is A_i.\n\nSnuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides.\nFind the maximum possible area of the rectangle.\n\nConstraints\n\n4 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^9\n\nA_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible area of the rectangle.\nIf no rectangle can be formed, print 0.\n\nSample Input 1\n\n6\n3 1 2 4 2 1\n\nSample Output 1\n\n2\n\n1 \\times 2 rectangle can be formed.\n\nSample Input 2\n\n4\n1 2 3 4\n\nSample Output 2\n\n0\n\nNo rectangle can be formed.\n\nSample Input 3\n\n10\n3 3 3 3 4 4 4 5 5 5\n\nSample Output 3\n\n20", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 451, "cpu_time_ms": 2105, "memory_kb": 59752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s915556143", "group_id": "codeNet:p03627", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 1))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defun ensure-list (x) (if (listp x) x (list x)))\n(defmacro nlet (name args &body body)\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args)))))\n\n(declaim (inline split-to-list))\n(defun split-to-list (str size)\n (declare (optimize (speed 3) (safety 1))\n (fixnum size)\n (string str))\n (loop for idx below size\n for pos1 = 0 then (1+ pos2)\n for pos2 = (position #\\space str :start pos1 :test #'char=)\n collect (parse-integer str :start pos1 :end pos2)))\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n(declaim (inline extract-available-bars))\n(defun extract-available-bars (list)\n (nlet recurse ((list list) (hash (make-hash-table)) res)\n (cond ((null list) res)\n ((gethash (car list) hash)\n (setf (gethash (car list) hash) nil)\n (recurse (cdr list) hash (cons (car list) res)))\n (t (setf (gethash (car list) hash) t)\n (recurse (cdr list) hash res)))))\n\n(deftype uint nil `(integer 0 ,(expt 10 9)))\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (bars (split-to-list (read-line) n))\n (available-bars (extract-available-bars bars)))\n (if (null (cdr available-bars))\n (println 0)\n (let* ((longest (reduce #'max available-bars))\n (second-longest (reduce #'max (delete longest available-bars :count 1))))\n (println (* longest second-longest))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1546017429, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03627.html", "problem_id": "p03627", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03627/input.txt", "sample_output_relpath": "derived/input_output/data/p03627/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03627/Lisp/s915556143.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s915556143", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 1))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defun ensure-list (x) (if (listp x) x (list x)))\n(defmacro nlet (name args &body body)\n (let ((args (mapcar #'ensure-list args)))\n `(labels ((,name ,(mapcar #'car args) ,@body))\n (,name ,@(mapcar #'cadr args)))))\n\n(declaim (inline split-to-list))\n(defun split-to-list (str size)\n (declare (optimize (speed 3) (safety 1))\n (fixnum size)\n (string str))\n (loop for idx below size\n for pos1 = 0 then (1+ pos2)\n for pos2 = (position #\\space str :start pos1 :test #'char=)\n collect (parse-integer str :start pos1 :end pos2)))\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n(declaim (inline extract-available-bars))\n(defun extract-available-bars (list)\n (nlet recurse ((list list) (hash (make-hash-table)) res)\n (cond ((null list) res)\n ((gethash (car list) hash)\n (setf (gethash (car list) hash) nil)\n (recurse (cdr list) hash (cons (car list) res)))\n (t (setf (gethash (car list) hash) t)\n (recurse (cdr list) hash res)))))\n\n(deftype uint nil `(integer 0 ,(expt 10 9)))\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (bars (split-to-list (read-line) n))\n (available-bars (extract-available-bars bars)))\n (if (null (cdr available-bars))\n (println 0)\n (let* ((longest (reduce #'max available-bars))\n (second-longest (reduce #'max (delete longest available-bars :count 1))))\n (println (* longest second-longest))))))\n\n#-swank(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWe have N sticks with negligible thickness.\nThe length of the i-th stick is A_i.\n\nSnuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides.\nFind the maximum possible area of the rectangle.\n\nConstraints\n\n4 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^9\n\nA_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible area of the rectangle.\nIf no rectangle can be formed, print 0.\n\nSample Input 1\n\n6\n3 1 2 4 2 1\n\nSample Output 1\n\n2\n\n1 \\times 2 rectangle can be formed.\n\nSample Input 2\n\n4\n1 2 3 4\n\nSample Output 2\n\n0\n\nNo rectangle can be formed.\n\nSample Input 3\n\n10\n3 3 3 3 4 4 4 5 5 5\n\nSample Output 3\n\n20", "sample_input": "6\n3 1 2 4 2 1\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03627", "source_text": "Score : 300 points\n\nProblem Statement\n\nWe have N sticks with negligible thickness.\nThe length of the i-th stick is A_i.\n\nSnuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides.\nFind the maximum possible area of the rectangle.\n\nConstraints\n\n4 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^9\n\nA_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the maximum possible area of the rectangle.\nIf no rectangle can be formed, print 0.\n\nSample Input 1\n\n6\n3 1 2 4 2 1\n\nSample Output 1\n\n2\n\n1 \\times 2 rectangle can be formed.\n\nSample Input 2\n\n4\n1 2 3 4\n\nSample Output 2\n\n0\n\nNo rectangle can be formed.\n\nSample Input 3\n\n10\n3 3 3 3 4 4 4 5 5 5\n\nSample Output 3\n\n20", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1954, "cpu_time_ms": 206, "memory_kb": 41572}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s988534832", "group_id": "codeNet:p03632", "input_text": "(defun read-prob ()\n (let ((lst nil))\n (dotimes (cnt 4 (nreverse lst))\n (push (read) lst)\n )))\n\n(defun solve (lst)\n (let* ((st (max (nth 0 lst) (nth 2 lst)))\n (en (min (nth 1 lst) (nth 3 lst)))\n (ans (- en st)))\n (if (< ans 0)\n 0 ans)))\n\n(format t \"~A\" (solve))", "language": "Lisp", "metadata": {"date": 1502586659, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03632.html", "problem_id": "p03632", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03632/input.txt", "sample_output_relpath": "derived/input_output/data/p03632/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03632/Lisp/s988534832.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s988534832", "user_id": "u007403111"}, "prompt_components": {"gold_output": "50\n", "input_to_evaluate": "(defun read-prob ()\n (let ((lst nil))\n (dotimes (cnt 4 (nreverse lst))\n (push (read) lst)\n )))\n\n(defun solve (lst)\n (let* ((st (max (nth 0 lst) (nth 2 lst)))\n (en (min (nth 1 lst) (nth 3 lst)))\n (ans (- en st)))\n (if (< ans 0)\n 0 ans)))\n\n(format t \"~A\" (solve))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nAlice and Bob are controlling a robot. They each have one switch that controls the robot.\n\nAlice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up.\n\nBob started holding down his button C second after the start-up, and released his button D second after the start-up.\n\nFor how many seconds both Alice and Bob were holding down their buttons?\n\nConstraints\n\n0≤A 3.\n\n8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.\n\n3 can be divided by 2 zero times.\n\nConstraints\n\n1 ≤ N ≤ 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n7\n\nSample Output 1\n\n4\n\n4 can be divided by 2 twice, which is the most number of times among 1, 2, ..., 7.\n\nSample Input 2\n\n32\n\nSample Output 2\n\n32\n\nSample Input 3\n\n1\n\nSample Output 3\n\n1\n\nSample Input 4\n\n100\n\nSample Output 4\n\n64", "sample_input": "7\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03644", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi loves numbers divisible by 2.\n\nYou are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.\n\nHere, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.\n\nFor example,\n\n6 can be divided by 2 once: 6 -> 3.\n\n8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.\n\n3 can be divided by 2 zero times.\n\nConstraints\n\n1 ≤ N ≤ 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n7\n\nSample Output 1\n\n4\n\n4 can be divided by 2 twice, which is the most number of times among 1, 2, ..., 7.\n\nSample Input 2\n\n32\n\nSample Output 2\n\n32\n\nSample Input 3\n\n1\n\nSample Output 3\n\n1\n\nSample Input 4\n\n100\n\nSample Output 4\n\n64", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 219, "cpu_time_ms": 18, "memory_kb": 6632}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s547472643", "group_id": "codeNet:p03645", "input_text": "(let* ((n (read))\n (m (read))\n (arr (make-array (list 2 (1+ n)) :element-type 'bit :initial-element 0)))\n (loop :repeat m :do (let* ((a (read))\n (b (read)))\n (cond ((= a 1) (setf (aref arr 0 b) 1))\n ((= b n) (setf (aref arr 1 a) 1)))))\n (if (loop :for k :from 0 :upto n :never (and (aref arr 0 k) (aref arr 1 k)))\n (princ \"IMPOSSIBLE\")\n (princ \"POSSIBLE\")))", "language": "Lisp", "metadata": {"date": 1573280982, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03645.html", "problem_id": "p03645", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03645/input.txt", "sample_output_relpath": "derived/input_output/data/p03645/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03645/Lisp/s547472643.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s547472643", "user_id": "u610490393"}, "prompt_components": {"gold_output": "POSSIBLE\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (arr (make-array (list 2 (1+ n)) :element-type 'bit :initial-element 0)))\n (loop :repeat m :do (let* ((a (read))\n (b (read)))\n (cond ((= a 1) (setf (aref arr 0 b) 1))\n ((= b n) (setf (aref arr 1 a) 1)))))\n (if (loop :for k :from 0 :upto n :never (and (aref arr 0 k) (aref arr 1 k)))\n (princ \"IMPOSSIBLE\")\n (princ \"POSSIBLE\")))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nIn Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.\nFor convenience, we will call them Island 1, Island 2, ..., Island N.\n\nThere are M kinds of regular boat services between these islands.\nEach service connects two islands. The i-th service connects Island a_i and Island b_i.\n\nCat Snuke is on Island 1 now, and wants to go to Island N.\nHowever, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.\n\nHelp him.\n\nConstraints\n\n3 ≤ N ≤ 200 000\n\n1 ≤ M ≤ 200 000\n\n1 ≤ a_i < b_i ≤ N\n\n(a_i, b_i) \\neq (1, N)\n\nIf i \\neq j, (a_i, b_i) \\neq (a_j, b_j).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\na_2 b_2\n:\na_M b_M\n\nOutput\n\nIf it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.\n\nSample Input 1\n\n3 2\n1 2\n2 3\n\nSample Output 1\n\nPOSSIBLE\n\nSample Input 2\n\n4 3\n1 2\n2 3\n3 4\n\nSample Output 2\n\nIMPOSSIBLE\n\nYou have to use three boat services to get to Island 4.\n\nSample Input 3\n\n100000 1\n1 99999\n\nSample Output 3\n\nIMPOSSIBLE\n\nSample Input 4\n\n5 5\n1 3\n4 5\n2 3\n2 4\n1 4\n\nSample Output 4\n\nPOSSIBLE\n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.", "sample_input": "3 2\n1 2\n2 3\n"}, "reference_outputs": ["POSSIBLE\n"], "source_document_id": "p03645", "source_text": "Score : 300 points\n\nProblem Statement\n\nIn Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.\nFor convenience, we will call them Island 1, Island 2, ..., Island N.\n\nThere are M kinds of regular boat services between these islands.\nEach service connects two islands. The i-th service connects Island a_i and Island b_i.\n\nCat Snuke is on Island 1 now, and wants to go to Island N.\nHowever, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.\n\nHelp him.\n\nConstraints\n\n3 ≤ N ≤ 200 000\n\n1 ≤ M ≤ 200 000\n\n1 ≤ a_i < b_i ≤ N\n\n(a_i, b_i) \\neq (1, N)\n\nIf i \\neq j, (a_i, b_i) \\neq (a_j, b_j).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\na_2 b_2\n:\na_M b_M\n\nOutput\n\nIf it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.\n\nSample Input 1\n\n3 2\n1 2\n2 3\n\nSample Output 1\n\nPOSSIBLE\n\nSample Input 2\n\n4 3\n1 2\n2 3\n3 4\n\nSample Output 2\n\nIMPOSSIBLE\n\nYou have to use three boat services to get to Island 4.\n\nSample Input 3\n\n100000 1\n1 99999\n\nSample Output 3\n\nIMPOSSIBLE\n\nSample Input 4\n\n5 5\n1 3\n4 5\n2 3\n2 4\n1 4\n\nSample Output 4\n\nPOSSIBLE\n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 461, "cpu_time_ms": 772, "memory_kb": 57956}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s770761954", "group_id": "codeNet:p03645", "input_text": "(let* ((n (read))\n (m (read))\n (arr (make-array (list 2 (1+ n)) :element-type 'bit :initial-element 0)))\n (loop :repeat m :do (let* ((a (read))\n (b (read)))\n (cond ((= a 1) (setf (aref arr 0 b) 1))\n ((= b n) (setf (aref arr 1 a) 1)))))\n (print arr)\n (if (loop :for k :from 0 :upto n :never (and (aref arr 0 k) (aref arr 1 k)))\n (princ \"IMPOSSIBLE\")\n (princ \"POSSIBLE\")))", "language": "Lisp", "metadata": {"date": 1573280916, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03645.html", "problem_id": "p03645", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03645/input.txt", "sample_output_relpath": "derived/input_output/data/p03645/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03645/Lisp/s770761954.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s770761954", "user_id": "u610490393"}, "prompt_components": {"gold_output": "POSSIBLE\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (arr (make-array (list 2 (1+ n)) :element-type 'bit :initial-element 0)))\n (loop :repeat m :do (let* ((a (read))\n (b (read)))\n (cond ((= a 1) (setf (aref arr 0 b) 1))\n ((= b n) (setf (aref arr 1 a) 1)))))\n (print arr)\n (if (loop :for k :from 0 :upto n :never (and (aref arr 0 k) (aref arr 1 k)))\n (princ \"IMPOSSIBLE\")\n (princ \"POSSIBLE\")))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nIn Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.\nFor convenience, we will call them Island 1, Island 2, ..., Island N.\n\nThere are M kinds of regular boat services between these islands.\nEach service connects two islands. The i-th service connects Island a_i and Island b_i.\n\nCat Snuke is on Island 1 now, and wants to go to Island N.\nHowever, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.\n\nHelp him.\n\nConstraints\n\n3 ≤ N ≤ 200 000\n\n1 ≤ M ≤ 200 000\n\n1 ≤ a_i < b_i ≤ N\n\n(a_i, b_i) \\neq (1, N)\n\nIf i \\neq j, (a_i, b_i) \\neq (a_j, b_j).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\na_2 b_2\n:\na_M b_M\n\nOutput\n\nIf it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.\n\nSample Input 1\n\n3 2\n1 2\n2 3\n\nSample Output 1\n\nPOSSIBLE\n\nSample Input 2\n\n4 3\n1 2\n2 3\n3 4\n\nSample Output 2\n\nIMPOSSIBLE\n\nYou have to use three boat services to get to Island 4.\n\nSample Input 3\n\n100000 1\n1 99999\n\nSample Output 3\n\nIMPOSSIBLE\n\nSample Input 4\n\n5 5\n1 3\n4 5\n2 3\n2 4\n1 4\n\nSample Output 4\n\nPOSSIBLE\n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.", "sample_input": "3 2\n1 2\n2 3\n"}, "reference_outputs": ["POSSIBLE\n"], "source_document_id": "p03645", "source_text": "Score : 300 points\n\nProblem Statement\n\nIn Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.\nFor convenience, we will call them Island 1, Island 2, ..., Island N.\n\nThere are M kinds of regular boat services between these islands.\nEach service connects two islands. The i-th service connects Island a_i and Island b_i.\n\nCat Snuke is on Island 1 now, and wants to go to Island N.\nHowever, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.\n\nHelp him.\n\nConstraints\n\n3 ≤ N ≤ 200 000\n\n1 ≤ M ≤ 200 000\n\n1 ≤ a_i < b_i ≤ N\n\n(a_i, b_i) \\neq (1, N)\n\nIf i \\neq j, (a_i, b_i) \\neq (a_j, b_j).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\na_2 b_2\n:\na_M b_M\n\nOutput\n\nIf it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.\n\nSample Input 1\n\n3 2\n1 2\n2 3\n\nSample Output 1\n\nPOSSIBLE\n\nSample Input 2\n\n4 3\n1 2\n2 3\n3 4\n\nSample Output 2\n\nIMPOSSIBLE\n\nYou have to use three boat services to get to Island 4.\n\nSample Input 3\n\n100000 1\n1 99999\n\nSample Output 3\n\nIMPOSSIBLE\n\nSample Input 4\n\n5 5\n1 3\n4 5\n2 3\n2 4\n1 4\n\nSample Output 4\n\nPOSSIBLE\n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 475, "cpu_time_ms": 987, "memory_kb": 72804}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s093083874", "group_id": "codeNet:p03645", "input_text": "(let* ((n (read))\n (m (read))\n (arr (make-array (list 2 (1+ n)) :element-type 'bit :initial-element 0)))\n (loop :repeat m :do (let* ((a (read))\n (b (read)))\n (cond ((= a 1) (setf (aref arr 0 b) 1))\n ((= b n) (setf (aref arr 1 a) 1)))))\n (if (loop :for k :from 0 :upto n :always (and (aref arr 0 k) (aref arr 1 k)))\n (princ \"POSSIBLE\")\n (princ \"IMPOSSIBLE\")))", "language": "Lisp", "metadata": {"date": 1573280845, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03645.html", "problem_id": "p03645", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03645/input.txt", "sample_output_relpath": "derived/input_output/data/p03645/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03645/Lisp/s093083874.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s093083874", "user_id": "u610490393"}, "prompt_components": {"gold_output": "POSSIBLE\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (arr (make-array (list 2 (1+ n)) :element-type 'bit :initial-element 0)))\n (loop :repeat m :do (let* ((a (read))\n (b (read)))\n (cond ((= a 1) (setf (aref arr 0 b) 1))\n ((= b n) (setf (aref arr 1 a) 1)))))\n (if (loop :for k :from 0 :upto n :always (and (aref arr 0 k) (aref arr 1 k)))\n (princ \"POSSIBLE\")\n (princ \"IMPOSSIBLE\")))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nIn Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.\nFor convenience, we will call them Island 1, Island 2, ..., Island N.\n\nThere are M kinds of regular boat services between these islands.\nEach service connects two islands. The i-th service connects Island a_i and Island b_i.\n\nCat Snuke is on Island 1 now, and wants to go to Island N.\nHowever, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.\n\nHelp him.\n\nConstraints\n\n3 ≤ N ≤ 200 000\n\n1 ≤ M ≤ 200 000\n\n1 ≤ a_i < b_i ≤ N\n\n(a_i, b_i) \\neq (1, N)\n\nIf i \\neq j, (a_i, b_i) \\neq (a_j, b_j).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\na_2 b_2\n:\na_M b_M\n\nOutput\n\nIf it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.\n\nSample Input 1\n\n3 2\n1 2\n2 3\n\nSample Output 1\n\nPOSSIBLE\n\nSample Input 2\n\n4 3\n1 2\n2 3\n3 4\n\nSample Output 2\n\nIMPOSSIBLE\n\nYou have to use three boat services to get to Island 4.\n\nSample Input 3\n\n100000 1\n1 99999\n\nSample Output 3\n\nIMPOSSIBLE\n\nSample Input 4\n\n5 5\n1 3\n4 5\n2 3\n2 4\n1 4\n\nSample Output 4\n\nPOSSIBLE\n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.", "sample_input": "3 2\n1 2\n2 3\n"}, "reference_outputs": ["POSSIBLE\n"], "source_document_id": "p03645", "source_text": "Score : 300 points\n\nProblem Statement\n\nIn Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.\nFor convenience, we will call them Island 1, Island 2, ..., Island N.\n\nThere are M kinds of regular boat services between these islands.\nEach service connects two islands. The i-th service connects Island a_i and Island b_i.\n\nCat Snuke is on Island 1 now, and wants to go to Island N.\nHowever, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.\n\nHelp him.\n\nConstraints\n\n3 ≤ N ≤ 200 000\n\n1 ≤ M ≤ 200 000\n\n1 ≤ a_i < b_i ≤ N\n\n(a_i, b_i) \\neq (1, N)\n\nIf i \\neq j, (a_i, b_i) \\neq (a_j, b_j).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\na_2 b_2\n:\na_M b_M\n\nOutput\n\nIf it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.\n\nSample Input 1\n\n3 2\n1 2\n2 3\n\nSample Output 1\n\nPOSSIBLE\n\nSample Input 2\n\n4 3\n1 2\n2 3\n3 4\n\nSample Output 2\n\nIMPOSSIBLE\n\nYou have to use three boat services to get to Island 4.\n\nSample Input 3\n\n100000 1\n1 99999\n\nSample Output 3\n\nIMPOSSIBLE\n\nSample Input 4\n\n5 5\n1 3\n4 5\n2 3\n2 4\n1 4\n\nSample Output 4\n\nPOSSIBLE\n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 462, "cpu_time_ms": 772, "memory_kb": 57700}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s857468290", "group_id": "codeNet:p03645", "input_text": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n(let* ((n (read))\n (m (read))\n (v1 (make-array n :initial-element nil))\n (vn (make-array n :initial-element nil)))\n (loop repeat m\n do (let ((s (read))\n (g (read)))\n (cond ((= s 1) (setf (aref v1 (1- g)) t))\n ((= g 1) (setf (aref v1 (1- s)) t))\n ((= s n) (setf (aref vn (1- g)) t))\n ((= g n) (setf (aref vn (1- s)) t)))))\n (format t \"~A~%\" (if (loop for i below n\n if (and (aref v1 i)\n (aref vn i))\n return t)\n 'POSSIBLE\n 'IMPOSSIBLE)))", "language": "Lisp", "metadata": {"date": 1504286064, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03645.html", "problem_id": "p03645", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03645/input.txt", "sample_output_relpath": "derived/input_output/data/p03645/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03645/Lisp/s857468290.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s857468290", "user_id": "u140665374"}, "prompt_components": {"gold_output": "POSSIBLE\n", "input_to_evaluate": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n(let* ((n (read))\n (m (read))\n (v1 (make-array n :initial-element nil))\n (vn (make-array n :initial-element nil)))\n (loop repeat m\n do (let ((s (read))\n (g (read)))\n (cond ((= s 1) (setf (aref v1 (1- g)) t))\n ((= g 1) (setf (aref v1 (1- s)) t))\n ((= s n) (setf (aref vn (1- g)) t))\n ((= g n) (setf (aref vn (1- s)) t)))))\n (format t \"~A~%\" (if (loop for i below n\n if (and (aref v1 i)\n (aref vn i))\n return t)\n 'POSSIBLE\n 'IMPOSSIBLE)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nIn Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.\nFor convenience, we will call them Island 1, Island 2, ..., Island N.\n\nThere are M kinds of regular boat services between these islands.\nEach service connects two islands. The i-th service connects Island a_i and Island b_i.\n\nCat Snuke is on Island 1 now, and wants to go to Island N.\nHowever, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.\n\nHelp him.\n\nConstraints\n\n3 ≤ N ≤ 200 000\n\n1 ≤ M ≤ 200 000\n\n1 ≤ a_i < b_i ≤ N\n\n(a_i, b_i) \\neq (1, N)\n\nIf i \\neq j, (a_i, b_i) \\neq (a_j, b_j).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\na_2 b_2\n:\na_M b_M\n\nOutput\n\nIf it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.\n\nSample Input 1\n\n3 2\n1 2\n2 3\n\nSample Output 1\n\nPOSSIBLE\n\nSample Input 2\n\n4 3\n1 2\n2 3\n3 4\n\nSample Output 2\n\nIMPOSSIBLE\n\nYou have to use three boat services to get to Island 4.\n\nSample Input 3\n\n100000 1\n1 99999\n\nSample Output 3\n\nIMPOSSIBLE\n\nSample Input 4\n\n5 5\n1 3\n4 5\n2 3\n2 4\n1 4\n\nSample Output 4\n\nPOSSIBLE\n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.", "sample_input": "3 2\n1 2\n2 3\n"}, "reference_outputs": ["POSSIBLE\n"], "source_document_id": "p03645", "source_text": "Score : 300 points\n\nProblem Statement\n\nIn Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.\nFor convenience, we will call them Island 1, Island 2, ..., Island N.\n\nThere are M kinds of regular boat services between these islands.\nEach service connects two islands. The i-th service connects Island a_i and Island b_i.\n\nCat Snuke is on Island 1 now, and wants to go to Island N.\nHowever, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.\n\nHelp him.\n\nConstraints\n\n3 ≤ N ≤ 200 000\n\n1 ≤ M ≤ 200 000\n\n1 ≤ a_i < b_i ≤ N\n\n(a_i, b_i) \\neq (1, N)\n\nIf i \\neq j, (a_i, b_i) \\neq (a_j, b_j).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\na_2 b_2\n:\na_M b_M\n\nOutput\n\nIf it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.\n\nSample Input 1\n\n3 2\n1 2\n2 3\n\nSample Output 1\n\nPOSSIBLE\n\nSample Input 2\n\n4 3\n1 2\n2 3\n3 4\n\nSample Output 2\n\nIMPOSSIBLE\n\nYou have to use three boat services to get to Island 4.\n\nSample Input 3\n\n100000 1\n1 99999\n\nSample Output 3\n\nIMPOSSIBLE\n\nSample Input 4\n\n5 5\n1 3\n4 5\n2 3\n2 4\n1 4\n\nSample Output 4\n\nPOSSIBLE\n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 733, "cpu_time_ms": 779, "memory_kb": 61864}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s508028812", "group_id": "codeNet:p03645", "input_text": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n(let* ((n (read))\n (m (read))\n (e (loop for i below m\n collect (cons (read) (read))))\n (n1 (remove-duplicates (mapcan (lambda (x)\n (cond ((= 1 (car x)) (list (cdr x)))\n ((= 1 (cdr x)) (list (car x)))\n (t nil)))\n e)))\n (nn (remove-duplicates (mapcan (lambda (x)\n (cond ((= n (car x)) (list (cdr x)))\n ((= n (cdr x)) (list (car x)))\n (t nil)))\n e))))\n (format t \"~A~%\" (if (find-if (lambda (x)\n (find-if (lambda (y)\n (= x y))\n nn))\n n1)\n 'POSSIBLE\n 'IMPOSSIBLE)))", "language": "Lisp", "metadata": {"date": 1504281572, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03645.html", "problem_id": "p03645", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03645/input.txt", "sample_output_relpath": "derived/input_output/data/p03645/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03645/Lisp/s508028812.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s508028812", "user_id": "u140665374"}, "prompt_components": {"gold_output": "POSSIBLE\n", "input_to_evaluate": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n(let* ((n (read))\n (m (read))\n (e (loop for i below m\n collect (cons (read) (read))))\n (n1 (remove-duplicates (mapcan (lambda (x)\n (cond ((= 1 (car x)) (list (cdr x)))\n ((= 1 (cdr x)) (list (car x)))\n (t nil)))\n e)))\n (nn (remove-duplicates (mapcan (lambda (x)\n (cond ((= n (car x)) (list (cdr x)))\n ((= n (cdr x)) (list (car x)))\n (t nil)))\n e))))\n (format t \"~A~%\" (if (find-if (lambda (x)\n (find-if (lambda (y)\n (= x y))\n nn))\n n1)\n 'POSSIBLE\n 'IMPOSSIBLE)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nIn Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.\nFor convenience, we will call them Island 1, Island 2, ..., Island N.\n\nThere are M kinds of regular boat services between these islands.\nEach service connects two islands. The i-th service connects Island a_i and Island b_i.\n\nCat Snuke is on Island 1 now, and wants to go to Island N.\nHowever, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.\n\nHelp him.\n\nConstraints\n\n3 ≤ N ≤ 200 000\n\n1 ≤ M ≤ 200 000\n\n1 ≤ a_i < b_i ≤ N\n\n(a_i, b_i) \\neq (1, N)\n\nIf i \\neq j, (a_i, b_i) \\neq (a_j, b_j).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\na_2 b_2\n:\na_M b_M\n\nOutput\n\nIf it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.\n\nSample Input 1\n\n3 2\n1 2\n2 3\n\nSample Output 1\n\nPOSSIBLE\n\nSample Input 2\n\n4 3\n1 2\n2 3\n3 4\n\nSample Output 2\n\nIMPOSSIBLE\n\nYou have to use three boat services to get to Island 4.\n\nSample Input 3\n\n100000 1\n1 99999\n\nSample Output 3\n\nIMPOSSIBLE\n\nSample Input 4\n\n5 5\n1 3\n4 5\n2 3\n2 4\n1 4\n\nSample Output 4\n\nPOSSIBLE\n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.", "sample_input": "3 2\n1 2\n2 3\n"}, "reference_outputs": ["POSSIBLE\n"], "source_document_id": "p03645", "source_text": "Score : 300 points\n\nProblem Statement\n\nIn Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.\nFor convenience, we will call them Island 1, Island 2, ..., Island N.\n\nThere are M kinds of regular boat services between these islands.\nEach service connects two islands. The i-th service connects Island a_i and Island b_i.\n\nCat Snuke is on Island 1 now, and wants to go to Island N.\nHowever, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.\n\nHelp him.\n\nConstraints\n\n3 ≤ N ≤ 200 000\n\n1 ≤ M ≤ 200 000\n\n1 ≤ a_i < b_i ≤ N\n\n(a_i, b_i) \\neq (1, N)\n\nIf i \\neq j, (a_i, b_i) \\neq (a_j, b_j).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\na_2 b_2\n:\na_M b_M\n\nOutput\n\nIf it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.\n\nSample Input 1\n\n3 2\n1 2\n2 3\n\nSample Output 1\n\nPOSSIBLE\n\nSample Input 2\n\n4 3\n1 2\n2 3\n3 4\n\nSample Output 2\n\nIMPOSSIBLE\n\nYou have to use three boat services to get to Island 4.\n\nSample Input 3\n\n100000 1\n1 99999\n\nSample Output 3\n\nIMPOSSIBLE\n\nSample Input 4\n\n5 5\n1 3\n4 5\n2 3\n2 4\n1 4\n\nSample Output 4\n\nPOSSIBLE\n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 927, "cpu_time_ms": 2105, "memory_kb": 63848}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s869835529", "group_id": "codeNet:p03645", "input_text": "(let* ((n (read))\n (m (read))\n (e (loop for i below m\n collect (cons (read) (read))))\n (n1 (mapcan (lambda (x)\n (cond ((= 1 (car x)) (list (cdr x)))\n ((= 1 (cdr x)) (list (car x)))\n (t nil)))\n e))\n (nn (mapcan (lambda (x)\n (cond ((= n (car x)) (list (cdr x)))\n ((= n (cdr x)) (list (car x)))\n (t nil)))\n e)))\n (format t \"~A~%\" (if (intersection n1 nn)\n 'POSSIBLE\n 'IMPOSSIBLE)))", "language": "Lisp", "metadata": {"date": 1504279571, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03645.html", "problem_id": "p03645", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03645/input.txt", "sample_output_relpath": "derived/input_output/data/p03645/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03645/Lisp/s869835529.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s869835529", "user_id": "u140665374"}, "prompt_components": {"gold_output": "POSSIBLE\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (e (loop for i below m\n collect (cons (read) (read))))\n (n1 (mapcan (lambda (x)\n (cond ((= 1 (car x)) (list (cdr x)))\n ((= 1 (cdr x)) (list (car x)))\n (t nil)))\n e))\n (nn (mapcan (lambda (x)\n (cond ((= n (car x)) (list (cdr x)))\n ((= n (cdr x)) (list (car x)))\n (t nil)))\n e)))\n (format t \"~A~%\" (if (intersection n1 nn)\n 'POSSIBLE\n 'IMPOSSIBLE)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nIn Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.\nFor convenience, we will call them Island 1, Island 2, ..., Island N.\n\nThere are M kinds of regular boat services between these islands.\nEach service connects two islands. The i-th service connects Island a_i and Island b_i.\n\nCat Snuke is on Island 1 now, and wants to go to Island N.\nHowever, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.\n\nHelp him.\n\nConstraints\n\n3 ≤ N ≤ 200 000\n\n1 ≤ M ≤ 200 000\n\n1 ≤ a_i < b_i ≤ N\n\n(a_i, b_i) \\neq (1, N)\n\nIf i \\neq j, (a_i, b_i) \\neq (a_j, b_j).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\na_2 b_2\n:\na_M b_M\n\nOutput\n\nIf it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.\n\nSample Input 1\n\n3 2\n1 2\n2 3\n\nSample Output 1\n\nPOSSIBLE\n\nSample Input 2\n\n4 3\n1 2\n2 3\n3 4\n\nSample Output 2\n\nIMPOSSIBLE\n\nYou have to use three boat services to get to Island 4.\n\nSample Input 3\n\n100000 1\n1 99999\n\nSample Output 3\n\nIMPOSSIBLE\n\nSample Input 4\n\n5 5\n1 3\n4 5\n2 3\n2 4\n1 4\n\nSample Output 4\n\nPOSSIBLE\n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.", "sample_input": "3 2\n1 2\n2 3\n"}, "reference_outputs": ["POSSIBLE\n"], "source_document_id": "p03645", "source_text": "Score : 300 points\n\nProblem Statement\n\nIn Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.\nFor convenience, we will call them Island 1, Island 2, ..., Island N.\n\nThere are M kinds of regular boat services between these islands.\nEach service connects two islands. The i-th service connects Island a_i and Island b_i.\n\nCat Snuke is on Island 1 now, and wants to go to Island N.\nHowever, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.\n\nHelp him.\n\nConstraints\n\n3 ≤ N ≤ 200 000\n\n1 ≤ M ≤ 200 000\n\n1 ≤ a_i < b_i ≤ N\n\n(a_i, b_i) \\neq (1, N)\n\nIf i \\neq j, (a_i, b_i) \\neq (a_j, b_j).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\na_2 b_2\n:\na_M b_M\n\nOutput\n\nIf it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.\n\nSample Input 1\n\n3 2\n1 2\n2 3\n\nSample Output 1\n\nPOSSIBLE\n\nSample Input 2\n\n4 3\n1 2\n2 3\n3 4\n\nSample Output 2\n\nIMPOSSIBLE\n\nYou have to use three boat services to get to Island 4.\n\nSample Input 3\n\n100000 1\n1 99999\n\nSample Output 3\n\nIMPOSSIBLE\n\nSample Input 4\n\n5 5\n1 3\n4 5\n2 3\n2 4\n1 4\n\nSample Output 4\n\nPOSSIBLE\n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 642, "cpu_time_ms": 2105, "memory_kb": 63812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s433949803", "group_id": "codeNet:p03652", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun feasible-p (as threshold)\n (declare ((simple-array uint16 (* *)) as)\n (uint32 threshold))\n #>threshold\n (destructuring-bind (n m) (array-dimensions as)\n (let ((indices (make-array n :element-type 'uint16 :initial-element 0))\n (marked (make-array m :element-type 'bit :initial-element 0))\n (table (make-array m :element-type 'uint16)))\n (labels ((step-index (i)\n (loop (incf (aref indices i))\n (when (>= (aref indices i) m)\n (return-from feasible-p nil))\n (when (zerop (aref marked (aref as i (aref indices i))))\n (return)))))\n (loop\n (fill table 0)\n (dotimes (i n)\n (incf (aref table (aref as i (aref indices i)))))\n (when (loop for x across table always (<= x threshold))\n (return-from feasible-p t))\n (dotimes (i n)\n (when (> (aref table (aref as i (aref indices i))) threshold)\n (setf (aref marked (aref as i (aref indices i))) 1)))\n (dotimes (i n)\n (when (> (aref table (aref as i (aref indices i))) threshold)\n (step-index i))))))))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (as (make-array (list n m) :element-type 'uint16)))\n (declare (uint16 n m))\n (dotimes (i n)\n (dotimes (j m)\n (setf (aref as i j) (- (read-fixnum) 1))))\n (sb-int:named-let bisect ((ng 0) (ok n))\n (if (<= (- ok ng) 1)\n (println ok)\n (let ((mid (ash (+ ng ok) -1)))\n (if (feasible-p as mid)\n (bisect ng mid)\n (bisect mid ok)))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1563318212, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03652.html", "problem_id": "p03652", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03652/input.txt", "sample_output_relpath": "derived/input_output/data/p03652/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03652/Lisp/s433949803.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s433949803", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun feasible-p (as threshold)\n (declare ((simple-array uint16 (* *)) as)\n (uint32 threshold))\n #>threshold\n (destructuring-bind (n m) (array-dimensions as)\n (let ((indices (make-array n :element-type 'uint16 :initial-element 0))\n (marked (make-array m :element-type 'bit :initial-element 0))\n (table (make-array m :element-type 'uint16)))\n (labels ((step-index (i)\n (loop (incf (aref indices i))\n (when (>= (aref indices i) m)\n (return-from feasible-p nil))\n (when (zerop (aref marked (aref as i (aref indices i))))\n (return)))))\n (loop\n (fill table 0)\n (dotimes (i n)\n (incf (aref table (aref as i (aref indices i)))))\n (when (loop for x across table always (<= x threshold))\n (return-from feasible-p t))\n (dotimes (i n)\n (when (> (aref table (aref as i (aref indices i))) threshold)\n (setf (aref marked (aref as i (aref indices i))) 1)))\n (dotimes (i n)\n (when (> (aref table (aref as i (aref indices i))) threshold)\n (step-index i))))))))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (as (make-array (list n m) :element-type 'uint16)))\n (declare (uint16 n m))\n (dotimes (i n)\n (dotimes (j m)\n (setf (aref as i j) (- (read-fixnum) 1))))\n (sb-int:named-let bisect ((ng 0) (ok n))\n (if (<= (- ok ng) 1)\n (println ok)\n (let ((mid (ash (+ ng ok) -1)))\n (if (feasible-p as mid)\n (bisect ng mid)\n (bisect mid ok)))))))\n\n#-swank (main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nTakahashi is hosting an sports meet.\nThere are N people who will participate. These people are conveniently numbered 1 through N.\nAlso, there are M options of sports for this event. These sports are numbered 1 through M.\nAmong these options, Takahashi will select one or more sports (possibly all) to be played in the event.\n\nTakahashi knows that Person i's j-th favorite sport is Sport A_{ij}.\nEach person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.\n\nTakahashi is worried that one of the sports will attract too many people.\nTherefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized.\nFind the minimum possible number of the participants in the sport with the largest number of participants.\n\nConstraints\n\n1 \\leq N \\leq 300\n\n1 \\leq M \\leq 300\n\nA_{i1} , A_{i2} , ... , A_{iM} is a permutation of the integers from 1 to M.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_{11} A_{12} ... A_{1M}\nA_{21} A_{22} ... A_{2M}\n:\nA_{N1} A_{N2} ... A_{NM}\n\nOutput\n\nPrint the minimum possible number of the participants in the sport with the largest number of participants.\n\nSample Input 1\n\n4 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 4 5\n2 5 4 3 1\n\nSample Output 1\n\n2\n\nAssume that Sports 1, 3 and 4 are selected to be played. In this case, Person 1 will participate in Sport 1, Person 2 in Sport 3, Person 3 in Sport 3 and Person 4 in Sport 4.\nHere, the sport with the largest number of participants is Sport 3, with two participants.\nThere is no way to reduce the number of participants in the sport with the largest number of participants to 1. Therefore, the answer is 2.\n\nSample Input 2\n\n3 3\n2 1 3\n2 1 3\n2 1 3\n\nSample Output 2\n\n3\n\nSince all the people have the same taste in sports, there will be a sport with three participants, no matter what sports are selected.\nTherefore, the answer is 3.", "sample_input": "4 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 4 5\n2 5 4 3 1\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03652", "source_text": "Score : 700 points\n\nProblem Statement\n\nTakahashi is hosting an sports meet.\nThere are N people who will participate. These people are conveniently numbered 1 through N.\nAlso, there are M options of sports for this event. These sports are numbered 1 through M.\nAmong these options, Takahashi will select one or more sports (possibly all) to be played in the event.\n\nTakahashi knows that Person i's j-th favorite sport is Sport A_{ij}.\nEach person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.\n\nTakahashi is worried that one of the sports will attract too many people.\nTherefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized.\nFind the minimum possible number of the participants in the sport with the largest number of participants.\n\nConstraints\n\n1 \\leq N \\leq 300\n\n1 \\leq M \\leq 300\n\nA_{i1} , A_{i2} , ... , A_{iM} is a permutation of the integers from 1 to M.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_{11} A_{12} ... A_{1M}\nA_{21} A_{22} ... A_{2M}\n:\nA_{N1} A_{N2} ... A_{NM}\n\nOutput\n\nPrint the minimum possible number of the participants in the sport with the largest number of participants.\n\nSample Input 1\n\n4 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 4 5\n2 5 4 3 1\n\nSample Output 1\n\n2\n\nAssume that Sports 1, 3 and 4 are selected to be played. In this case, Person 1 will participate in Sport 1, Person 2 in Sport 3, Person 3 in Sport 3 and Person 4 in Sport 4.\nHere, the sport with the largest number of participants is Sport 3, with two participants.\nThere is no way to reduce the number of participants in the sport with the largest number of participants to 1. Therefore, the answer is 2.\n\nSample Input 2\n\n3 3\n2 1 3\n2 1 3\n2 1 3\n\nSample Output 2\n\n3\n\nSince all the people have the same taste in sports, there will be a sport with three participants, no matter what sports are selected.\nTherefore, the answer is 3.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4073, "cpu_time_ms": 238, "memory_kb": 28644}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s203381176", "group_id": "codeNet:p03652", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun feasible-p (as threshold)\n (declare ((simple-array uint16 (* *)) as)\n (uint32 threshold))\n (destructuring-bind (n m) (array-dimensions as)\n (let ((indices (make-array n :element-type 'uint16 :initial-element 0))\n (table (make-array m :element-type 'uint16)))\n (loop\n (fill table 0)\n (dotimes (i n)\n (incf (aref table (aref as i (aref indices i)))))\n (let ((feasible t))\n (dotimes (i n)\n (when (> (aref table (aref as i (aref indices i))) threshold)\n (setf feasible nil)\n (incf (aref indices i))\n (when (>= (aref indices i) m)\n (return-from feasible-p nil))))\n (when feasible\n (return-from feasible-p t)))))))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (as (make-array (list n m) :element-type 'uint16)))\n (declare (uint16 n m))\n (dotimes (i n)\n (dotimes (j m)\n (setf (aref as i j) (- (read-fixnum) 1))))\n (sb-int:named-let bisect ((ng 0) (ok m))\n (if (<= (- ok ng) 1)\n (println ok)\n (let ((mid (ash (+ ng ok) -1)))\n (if (feasible-p as mid)\n (bisect ng mid)\n (bisect mid ok)))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1563315471, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03652.html", "problem_id": "p03652", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03652/input.txt", "sample_output_relpath": "derived/input_output/data/p03652/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03652/Lisp/s203381176.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s203381176", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun feasible-p (as threshold)\n (declare ((simple-array uint16 (* *)) as)\n (uint32 threshold))\n (destructuring-bind (n m) (array-dimensions as)\n (let ((indices (make-array n :element-type 'uint16 :initial-element 0))\n (table (make-array m :element-type 'uint16)))\n (loop\n (fill table 0)\n (dotimes (i n)\n (incf (aref table (aref as i (aref indices i)))))\n (let ((feasible t))\n (dotimes (i n)\n (when (> (aref table (aref as i (aref indices i))) threshold)\n (setf feasible nil)\n (incf (aref indices i))\n (when (>= (aref indices i) m)\n (return-from feasible-p nil))))\n (when feasible\n (return-from feasible-p t)))))))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (as (make-array (list n m) :element-type 'uint16)))\n (declare (uint16 n m))\n (dotimes (i n)\n (dotimes (j m)\n (setf (aref as i j) (- (read-fixnum) 1))))\n (sb-int:named-let bisect ((ng 0) (ok m))\n (if (<= (- ok ng) 1)\n (println ok)\n (let ((mid (ash (+ ng ok) -1)))\n (if (feasible-p as mid)\n (bisect ng mid)\n (bisect mid ok)))))))\n\n#-swank (main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nTakahashi is hosting an sports meet.\nThere are N people who will participate. These people are conveniently numbered 1 through N.\nAlso, there are M options of sports for this event. These sports are numbered 1 through M.\nAmong these options, Takahashi will select one or more sports (possibly all) to be played in the event.\n\nTakahashi knows that Person i's j-th favorite sport is Sport A_{ij}.\nEach person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.\n\nTakahashi is worried that one of the sports will attract too many people.\nTherefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized.\nFind the minimum possible number of the participants in the sport with the largest number of participants.\n\nConstraints\n\n1 \\leq N \\leq 300\n\n1 \\leq M \\leq 300\n\nA_{i1} , A_{i2} , ... , A_{iM} is a permutation of the integers from 1 to M.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_{11} A_{12} ... A_{1M}\nA_{21} A_{22} ... A_{2M}\n:\nA_{N1} A_{N2} ... A_{NM}\n\nOutput\n\nPrint the minimum possible number of the participants in the sport with the largest number of participants.\n\nSample Input 1\n\n4 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 4 5\n2 5 4 3 1\n\nSample Output 1\n\n2\n\nAssume that Sports 1, 3 and 4 are selected to be played. In this case, Person 1 will participate in Sport 1, Person 2 in Sport 3, Person 3 in Sport 3 and Person 4 in Sport 4.\nHere, the sport with the largest number of participants is Sport 3, with two participants.\nThere is no way to reduce the number of participants in the sport with the largest number of participants to 1. Therefore, the answer is 2.\n\nSample Input 2\n\n3 3\n2 1 3\n2 1 3\n2 1 3\n\nSample Output 2\n\n3\n\nSince all the people have the same taste in sports, there will be a sport with three participants, no matter what sports are selected.\nTherefore, the answer is 3.", "sample_input": "4 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 4 5\n2 5 4 3 1\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03652", "source_text": "Score : 700 points\n\nProblem Statement\n\nTakahashi is hosting an sports meet.\nThere are N people who will participate. These people are conveniently numbered 1 through N.\nAlso, there are M options of sports for this event. These sports are numbered 1 through M.\nAmong these options, Takahashi will select one or more sports (possibly all) to be played in the event.\n\nTakahashi knows that Person i's j-th favorite sport is Sport A_{ij}.\nEach person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.\n\nTakahashi is worried that one of the sports will attract too many people.\nTherefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized.\nFind the minimum possible number of the participants in the sport with the largest number of participants.\n\nConstraints\n\n1 \\leq N \\leq 300\n\n1 \\leq M \\leq 300\n\nA_{i1} , A_{i2} , ... , A_{iM} is a permutation of the integers from 1 to M.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_{11} A_{12} ... A_{1M}\nA_{21} A_{22} ... A_{2M}\n:\nA_{N1} A_{N2} ... A_{NM}\n\nOutput\n\nPrint the minimum possible number of the participants in the sport with the largest number of participants.\n\nSample Input 1\n\n4 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 4 5\n2 5 4 3 1\n\nSample Output 1\n\n2\n\nAssume that Sports 1, 3 and 4 are selected to be played. In this case, Person 1 will participate in Sport 1, Person 2 in Sport 3, Person 3 in Sport 3 and Person 4 in Sport 4.\nHere, the sport with the largest number of participants is Sport 3, with two participants.\nThere is no way to reduce the number of participants in the sport with the largest number of participants to 1. Therefore, the answer is 2.\n\nSample Input 2\n\n3 3\n2 1 3\n2 1 3\n2 1 3\n\nSample Output 2\n\n3\n\nSince all the people have the same taste in sports, there will be a sport with three participants, no matter what sports are selected.\nTherefore, the answer is 3.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3628, "cpu_time_ms": 231, "memory_kb": 24416}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s864149582", "group_id": "codeNet:p03657", "input_text": "(let ((a (read))\n (b (read))\n (ans \"Impossible\"))\n\n (if (zerop (rem a 3))\n (setq ans \"Possible\")\n (if (zerop (rem b 3))\n (setq ans \"Possible\")\n (if (zerop (rem (+ a b) 3))\n (setq ans \"Possible\"))\n )\n )\n (princ ans)\n)", "language": "Lisp", "metadata": {"date": 1593976316, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03657.html", "problem_id": "p03657", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03657/input.txt", "sample_output_relpath": "derived/input_output/data/p03657/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03657/Lisp/s864149582.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s864149582", "user_id": "u136500538"}, "prompt_components": {"gold_output": "Possible\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (ans \"Impossible\"))\n\n (if (zerop (rem a 3))\n (setq ans \"Possible\")\n (if (zerop (rem b 3))\n (setq ans \"Possible\")\n (if (zerop (rem (+ a b) 3))\n (setq ans \"Possible\"))\n )\n )\n (princ ans)\n)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nSnuke is giving cookies to his three goats.\n\nHe has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins).\n\nYour task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.\n\nConstraints\n\n1 \\leq A,B \\leq 100\n\nBoth A and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nIf it is possible to give cookies so that each of the three goats can have the same number of cookies, print Possible; otherwise, print Impossible.\n\nSample Input 1\n\n4 5\n\nSample Output 1\n\nPossible\n\nIf Snuke gives nine cookies, each of the three goats can have three cookies.\n\nSample Input 2\n\n1 1\n\nSample Output 2\n\nImpossible\n\nSince there are only two cookies, the three goats cannot have the same number of cookies no matter what Snuke gives to them.", "sample_input": "4 5\n"}, "reference_outputs": ["Possible\n"], "source_document_id": "p03657", "source_text": "Score : 100 points\n\nProblem Statement\n\nSnuke is giving cookies to his three goats.\n\nHe has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins).\n\nYour task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.\n\nConstraints\n\n1 \\leq A,B \\leq 100\n\nBoth A and B are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nIf it is possible to give cookies so that each of the three goats can have the same number of cookies, print Possible; otherwise, print Impossible.\n\nSample Input 1\n\n4 5\n\nSample Output 1\n\nPossible\n\nIf Snuke gives nine cookies, each of the three goats can have three cookies.\n\nSample Input 2\n\n1 1\n\nSample Output 2\n\nImpossible\n\nSince there are only two cookies, the three goats cannot have the same number of cookies no matter what Snuke gives to them.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 289, "cpu_time_ms": 17, "memory_kb": 23628}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s555080028", "group_id": "codeNet:p03658", "input_text": "(let* ((n (read))\n (k (read))\n (lst (sort (loop :repeat n :collect (read)) #'>)))\n (princ (reduce #'+ (subseq lst 0 k))))", "language": "Lisp", "metadata": {"date": 1556501186, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03658.html", "problem_id": "p03658", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03658/input.txt", "sample_output_relpath": "derived/input_output/data/p03658/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03658/Lisp/s555080028.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s555080028", "user_id": "u610490393"}, "prompt_components": {"gold_output": "12\n", "input_to_evaluate": "(let* ((n (read))\n (k (read))\n (lst (sort (loop :repeat n :collect (read)) #'>)))\n (princ (reduce #'+ (subseq lst 0 k))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nSnuke has N sticks.\nThe length of the i-th stick is l_i.\n\nSnuke is making a snake toy by joining K of the sticks together.\n\nThe length of the toy is represented by the sum of the individual sticks that compose it.\nFind the maximum possible length of the toy.\n\nConstraints\n\n1 \\leq K \\leq N \\leq 50\n\n1 \\leq l_i \\leq 50\n\nl_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nl_1 l_2 l_3 ... l_{N}\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n5 3\n1 2 3 4 5\n\nSample Output 1\n\n12\n\nYou can make a toy of length 12 by joining the sticks of lengths 3, 4 and 5, which is the maximum possible length.\n\nSample Input 2\n\n15 14\n50 26 27 21 41 7 42 35 7 5 5 36 39 1 45\n\nSample Output 2\n\n386", "sample_input": "5 3\n1 2 3 4 5\n"}, "reference_outputs": ["12\n"], "source_document_id": "p03658", "source_text": "Score : 200 points\n\nProblem Statement\n\nSnuke has N sticks.\nThe length of the i-th stick is l_i.\n\nSnuke is making a snake toy by joining K of the sticks together.\n\nThe length of the toy is represented by the sum of the individual sticks that compose it.\nFind the maximum possible length of the toy.\n\nConstraints\n\n1 \\leq K \\leq N \\leq 50\n\n1 \\leq l_i \\leq 50\n\nl_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nl_1 l_2 l_3 ... l_{N}\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n5 3\n1 2 3 4 5\n\nSample Output 1\n\n12\n\nYou can make a toy of length 12 by joining the sticks of lengths 3, 4 and 5, which is the maximum possible length.\n\nSample Input 2\n\n15 14\n50 26 27 21 41 7 42 35 7 5 5 36 39 1 45\n\nSample Output 2\n\n386", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 134, "cpu_time_ms": 60, "memory_kb": 6756}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s040856363", "group_id": "codeNet:p03658", "input_text": "(setq n(read))(setq k(read))\n(princ(apply #'+(map 'list (lambda(a)(if(<(decf k)0)0 a))(sort(loop for i from 1 to n collect(read))#'>))))", "language": "Lisp", "metadata": {"date": 1534909569, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03658.html", "problem_id": "p03658", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03658/input.txt", "sample_output_relpath": "derived/input_output/data/p03658/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03658/Lisp/s040856363.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s040856363", "user_id": "u657913472"}, "prompt_components": {"gold_output": "12\n", "input_to_evaluate": "(setq n(read))(setq k(read))\n(princ(apply #'+(map 'list (lambda(a)(if(<(decf k)0)0 a))(sort(loop for i from 1 to n collect(read))#'>))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nSnuke has N sticks.\nThe length of the i-th stick is l_i.\n\nSnuke is making a snake toy by joining K of the sticks together.\n\nThe length of the toy is represented by the sum of the individual sticks that compose it.\nFind the maximum possible length of the toy.\n\nConstraints\n\n1 \\leq K \\leq N \\leq 50\n\n1 \\leq l_i \\leq 50\n\nl_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nl_1 l_2 l_3 ... l_{N}\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n5 3\n1 2 3 4 5\n\nSample Output 1\n\n12\n\nYou can make a toy of length 12 by joining the sticks of lengths 3, 4 and 5, which is the maximum possible length.\n\nSample Input 2\n\n15 14\n50 26 27 21 41 7 42 35 7 5 5 36 39 1 45\n\nSample Output 2\n\n386", "sample_input": "5 3\n1 2 3 4 5\n"}, "reference_outputs": ["12\n"], "source_document_id": "p03658", "source_text": "Score : 200 points\n\nProblem Statement\n\nSnuke has N sticks.\nThe length of the i-th stick is l_i.\n\nSnuke is making a snake toy by joining K of the sticks together.\n\nThe length of the toy is represented by the sum of the individual sticks that compose it.\nFind the maximum possible length of the toy.\n\nConstraints\n\n1 \\leq K \\leq N \\leq 50\n\n1 \\leq l_i \\leq 50\n\nl_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nl_1 l_2 l_3 ... l_{N}\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n5 3\n1 2 3 4 5\n\nSample Output 1\n\n12\n\nYou can make a toy of length 12 by joining the sticks of lengths 3, 4 and 5, which is the maximum possible length.\n\nSample Input 2\n\n15 14\n50 26 27 21 41 7 42 35 7 5 5 36 39 1 45\n\nSample Output 2\n\n386", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 136, "cpu_time_ms": 20, "memory_kb": 4452}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s922795423", "group_id": "codeNet:p03658", "input_text": "(format t \"~A~%\" (let* ((n (read))\n (k (read))\n (l (subseq (sort (loop repeat n\n collect (read))\n #'>)\n 0 k)))\n (apply #'+ l)))", "language": "Lisp", "metadata": {"date": 1504484917, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03658.html", "problem_id": "p03658", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03658/input.txt", "sample_output_relpath": "derived/input_output/data/p03658/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03658/Lisp/s922795423.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s922795423", "user_id": "u140665374"}, "prompt_components": {"gold_output": "12\n", "input_to_evaluate": "(format t \"~A~%\" (let* ((n (read))\n (k (read))\n (l (subseq (sort (loop repeat n\n collect (read))\n #'>)\n 0 k)))\n (apply #'+ l)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nSnuke has N sticks.\nThe length of the i-th stick is l_i.\n\nSnuke is making a snake toy by joining K of the sticks together.\n\nThe length of the toy is represented by the sum of the individual sticks that compose it.\nFind the maximum possible length of the toy.\n\nConstraints\n\n1 \\leq K \\leq N \\leq 50\n\n1 \\leq l_i \\leq 50\n\nl_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nl_1 l_2 l_3 ... l_{N}\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n5 3\n1 2 3 4 5\n\nSample Output 1\n\n12\n\nYou can make a toy of length 12 by joining the sticks of lengths 3, 4 and 5, which is the maximum possible length.\n\nSample Input 2\n\n15 14\n50 26 27 21 41 7 42 35 7 5 5 36 39 1 45\n\nSample Output 2\n\n386", "sample_input": "5 3\n1 2 3 4 5\n"}, "reference_outputs": ["12\n"], "source_document_id": "p03658", "source_text": "Score : 200 points\n\nProblem Statement\n\nSnuke has N sticks.\nThe length of the i-th stick is l_i.\n\nSnuke is making a snake toy by joining K of the sticks together.\n\nThe length of the toy is represented by the sum of the individual sticks that compose it.\nFind the maximum possible length of the toy.\n\nConstraints\n\n1 \\leq K \\leq N \\leq 50\n\n1 \\leq l_i \\leq 50\n\nl_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nl_1 l_2 l_3 ... l_{N}\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n5 3\n1 2 3 4 5\n\nSample Output 1\n\n12\n\nYou can make a toy of length 12 by joining the sticks of lengths 3, 4 and 5, which is the maximum possible length.\n\nSample Input 2\n\n15 14\n50 26 27 21 41 7 42 35 7 5 5 36 39 1 45\n\nSample Output 2\n\n386", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 315, "cpu_time_ms": 140, "memory_kb": 12900}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s699071831", "group_id": "codeNet:p03659", "input_text": "(let* ((max 0)\n (a (loop repeat (read)\n sum (read) into x\n collect x\n finally (setf max x))))\n (format t \"~A~%\" (loop for n in (butlast a)\n minimize (abs (- max n n)))))", "language": "Lisp", "metadata": {"date": 1504487559, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03659.html", "problem_id": "p03659", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03659/input.txt", "sample_output_relpath": "derived/input_output/data/p03659/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03659/Lisp/s699071831.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s699071831", "user_id": "u140665374"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let* ((max 0)\n (a (loop repeat (read)\n sum (read) into x\n collect x\n finally (setf max x))))\n (format t \"~A~%\" (loop for n in (butlast a)\n minimize (abs (- max n n)))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it.\n\nThey will share these cards.\nFirst, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards.\nHere, both Snuke and Raccoon have to take at least one card.\n\nLet the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively.\nThey would like to minimize |x-y|.\nFind the minimum possible value of |x-y|.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n-10^{9} \\leq a_i \\leq 10^{9}\n\na_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_{N}\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n6\n1 2 3 4 5 6\n\nSample Output 1\n\n1\n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two cards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\nSample Input 2\n\n2\n10 -10\n\nSample Output 2\n\n20\n\nSnuke can only take one card from the top, and Raccoon can only take the remaining one card. In this case, x=10, y=-10, and thus |x-y|=20.", "sample_input": "6\n1 2 3 4 5 6\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03659", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it.\n\nThey will share these cards.\nFirst, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards.\nHere, both Snuke and Raccoon have to take at least one card.\n\nLet the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively.\nThey would like to minimize |x-y|.\nFind the minimum possible value of |x-y|.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n-10^{9} \\leq a_i \\leq 10^{9}\n\na_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_{N}\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n6\n1 2 3 4 5 6\n\nSample Output 1\n\n1\n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two cards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\nSample Input 2\n\n2\n10 -10\n\nSample Output 2\n\n20\n\nSnuke can only take one card from the top, and Raccoon can only take the remaining one card. In this case, x=10, y=-10, and thus |x-y|=20.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 245, "cpu_time_ms": 404, "memory_kb": 61796}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s952741603", "group_id": "codeNet:p03665", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (p (read))\n (dp (make-array 5200 :element-type 'uint62 :initial-element 0)))\n (setf (aref dp 0) 1)\n (dotimes (_ n)\n (let ((a (read)))\n (loop for x from 5000 downto 0\n when (> (aref dp x) 0)\n do (incf (aref dp (+ x a))\n (aref dp x)))))\n (println\n (loop for i from (if (zerop p) 0 1) below (length dp) by 2\n sum (aref dp i)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 0\n1 3\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 1\n50\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 0\n1 1 1\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"45 1\n17 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 66 25 9 89 71 41 16 53 13 61 15 85 72 62 67 42 26 36 66 4 87 59 91 4 25 26\n\"\n \"17592186044416\n\")))\n", "language": "Lisp", "metadata": {"date": 1578038728, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03665.html", "problem_id": "p03665", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03665/input.txt", "sample_output_relpath": "derived/input_output/data/p03665/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03665/Lisp/s952741603.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s952741603", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (p (read))\n (dp (make-array 5200 :element-type 'uint62 :initial-element 0)))\n (setf (aref dp 0) 1)\n (dotimes (_ n)\n (let ((a (read)))\n (loop for x from 5000 downto 0\n when (> (aref dp x) 0)\n do (incf (aref dp (+ x a))\n (aref dp x)))))\n (println\n (loop for i from (if (zerop p) 0 1) below (length dp) by 2\n sum (aref dp i)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 0\n1 3\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 1\n50\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 0\n1 1 1\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"45 1\n17 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 66 25 9 89 71 41 16 53 13 61 15 85 72 62 67 42 26 36 66 4 87 59 91 4 25 26\n\"\n \"17592186044416\n\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N bags of biscuits. The i-th bag contains A_i biscuits.\n\nTakaki will select some of these bags and eat all of the biscuits inside.\nHere, it is also possible to select all or none of the bags.\n\nHe would like to select bags so that the total number of biscuits inside is congruent to P modulo 2.\nHow many such ways to select bags there are?\n\nConstraints\n\n1 \\leq N \\leq 50\n\nP = 0 or 1\n\n1 \\leq A_i \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN P\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the number of ways to select bags so that the total number of biscuits inside is congruent to P modulo 2.\n\nSample Input 1\n\n2 0\n1 3\n\nSample Output 1\n\n2\n\nThere are two ways to select bags so that the total number of biscuits inside is congruent to 0 modulo 2:\n\nSelect neither bag. The total number of biscuits is 0.\n\nSelect both bags. The total number of biscuits is 4.\n\nSample Input 2\n\n1 1\n50\n\nSample Output 2\n\n0\n\nSample Input 3\n\n3 0\n1 1 1\n\nSample Output 3\n\n4\n\nTwo bags are distinguished even if they contain the same number of biscuits.\n\nSample Input 4\n\n45 1\n17 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 66 25 9 89 71 41 16 53 13 61 15 85 72 62 67 42 26 36 66 4 87 59 91 4 25 26\n\nSample Output 4\n\n17592186044416", "sample_input": "2 0\n1 3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03665", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N bags of biscuits. The i-th bag contains A_i biscuits.\n\nTakaki will select some of these bags and eat all of the biscuits inside.\nHere, it is also possible to select all or none of the bags.\n\nHe would like to select bags so that the total number of biscuits inside is congruent to P modulo 2.\nHow many such ways to select bags there are?\n\nConstraints\n\n1 \\leq N \\leq 50\n\nP = 0 or 1\n\n1 \\leq A_i \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN P\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the number of ways to select bags so that the total number of biscuits inside is congruent to P modulo 2.\n\nSample Input 1\n\n2 0\n1 3\n\nSample Output 1\n\n2\n\nThere are two ways to select bags so that the total number of biscuits inside is congruent to 0 modulo 2:\n\nSelect neither bag. The total number of biscuits is 0.\n\nSelect both bags. The total number of biscuits is 4.\n\nSample Input 2\n\n1 1\n50\n\nSample Output 2\n\n0\n\nSample Input 3\n\n3 0\n1 1 1\n\nSample Output 3\n\n4\n\nTwo bags are distinguished even if they contain the same number of biscuits.\n\nSample Input 4\n\n45 1\n17 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 66 25 9 89 71 41 16 53 13 61 15 85 72 62 67 42 26 36 66 4 87 59 91 4 25 26\n\nSample Output 4\n\n17592186044416", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4409, "cpu_time_ms": 316, "memory_kb": 23268}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s512659307", "group_id": "codeNet:p03671", "input_text": "(let* ((a (read))\n (b (read))\n (c (read))\n (lst (sort (copy-list (list a b c))\n #'<)))\n\n (format t \"~A~%\"\n (+ (car lst) (cadr lst))))\n\n", "language": "Lisp", "metadata": {"date": 1573362369, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03671.html", "problem_id": "p03671", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03671/input.txt", "sample_output_relpath": "derived/input_output/data/p03671/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03671/Lisp/s512659307.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s512659307", "user_id": "u336541610"}, "prompt_components": {"gold_output": "1300\n", "input_to_evaluate": "(let* ((a (read))\n (b (read))\n (c (read))\n (lst (sort (copy-list (list a b c))\n #'<)))\n\n (format t \"~A~%\"\n (+ (car lst) (cadr lst))))\n\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nSnuke is buying a bicycle.\nThe bicycle of his choice does not come with a bell, so he has to buy one separately.\n\nHe has very high awareness of safety, and decides to buy two bells, one for each hand.\n\nThe store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively.\nFind the minimum total price of two different bells.\n\nConstraints\n\n1 \\leq a,b,c \\leq 10000\n\na, b and c are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b c\n\nOutput\n\nPrint the minimum total price of two different bells.\n\nSample Input 1\n\n700 600 780\n\nSample Output 1\n\n1300\n\nBuying a 700-yen bell and a 600-yen bell costs 1300 yen.\n\nBuying a 700-yen bell and a 780-yen bell costs 1480 yen.\n\nBuying a 600-yen bell and a 780-yen bell costs 1380 yen.\n\nThe minimum among these is 1300 yen.\n\nSample Input 2\n\n10000 10000 10000\n\nSample Output 2\n\n20000\n\nBuying any two bells costs 20000 yen.", "sample_input": "700 600 780\n"}, "reference_outputs": ["1300\n"], "source_document_id": "p03671", "source_text": "Score : 100 points\n\nProblem Statement\n\nSnuke is buying a bicycle.\nThe bicycle of his choice does not come with a bell, so he has to buy one separately.\n\nHe has very high awareness of safety, and decides to buy two bells, one for each hand.\n\nThe store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively.\nFind the minimum total price of two different bells.\n\nConstraints\n\n1 \\leq a,b,c \\leq 10000\n\na, b and c are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b c\n\nOutput\n\nPrint the minimum total price of two different bells.\n\nSample Input 1\n\n700 600 780\n\nSample Output 1\n\n1300\n\nBuying a 700-yen bell and a 600-yen bell costs 1300 yen.\n\nBuying a 700-yen bell and a 780-yen bell costs 1480 yen.\n\nBuying a 600-yen bell and a 780-yen bell costs 1380 yen.\n\nThe minimum among these is 1300 yen.\n\nSample Input 2\n\n10000 10000 10000\n\nSample Output 2\n\n20000\n\nBuying any two bells costs 20000 yen.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 180, "cpu_time_ms": 126, "memory_kb": 10980}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s604443749", "group_id": "codeNet:p03672", "input_text": "(let ((str (read-line)))\n (loop for end downfrom (- (length str) 2) to 0 by 2\n if (or (string= str str\n\t\t :start1 0 :end1 (/ end 2)\n\t\t :start2 (/ end 2) :end2 end)\n\t (zerop end))\n do (princ end)))", "language": "Lisp", "metadata": {"date": 1504422101, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03672.html", "problem_id": "p03672", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03672/input.txt", "sample_output_relpath": "derived/input_output/data/p03672/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03672/Lisp/s604443749.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s604443749", "user_id": "u158834201"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(let ((str (read-line)))\n (loop for end downfrom (- (length str) 2) to 0 by 2\n if (or (string= str str\n\t\t :start1 0 :end1 (/ end 2)\n\t\t :start2 (/ end 2) :end2 end)\n\t (zerop end))\n do (princ end)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe will call a string that can be obtained by concatenating two equal strings an even string.\nFor example, xyzxyz and aaaaaa are even, while ababab and xyzxy are not.\n\nYou are given an even string S consisting of lowercase English letters.\nFind the length of the longest even string that can be obtained by deleting one or more characters from the end of S.\nIt is guaranteed that such a non-empty string exists for a given input.\n\nConstraints\n\n2 \\leq |S| \\leq 200\n\nS is an even string consisting of lowercase English letters.\n\nThere exists a non-empty even string that can be obtained by deleting one or more characters from the end of S.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the length of the longest even string that can be obtained.\n\nSample Input 1\n\nabaababaab\n\nSample Output 1\n\n6\n\nabaababaab itself is even, but we need to delete at least one character.\n\nabaababaa is not even.\n\nabaababa is not even.\n\nabaabab is not even.\n\nabaaba is even. Thus, we should print its length, 6.\n\nSample Input 2\n\nxxxx\n\nSample Output 2\n\n2\n\nxxx is not even.\n\nxx is even.\n\nSample Input 3\n\nabcabcabcabc\n\nSample Output 3\n\n6\n\nThe longest even string that can be obtained is abcabc, whose length is 6.\n\nSample Input 4\n\nakasakaakasakasakaakas\n\nSample Output 4\n\n14\n\nThe longest even string that can be obtained is akasakaakasaka, whose length is 14.", "sample_input": "abaababaab\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03672", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe will call a string that can be obtained by concatenating two equal strings an even string.\nFor example, xyzxyz and aaaaaa are even, while ababab and xyzxy are not.\n\nYou are given an even string S consisting of lowercase English letters.\nFind the length of the longest even string that can be obtained by deleting one or more characters from the end of S.\nIt is guaranteed that such a non-empty string exists for a given input.\n\nConstraints\n\n2 \\leq |S| \\leq 200\n\nS is an even string consisting of lowercase English letters.\n\nThere exists a non-empty even string that can be obtained by deleting one or more characters from the end of S.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the length of the longest even string that can be obtained.\n\nSample Input 1\n\nabaababaab\n\nSample Output 1\n\n6\n\nabaababaab itself is even, but we need to delete at least one character.\n\nabaababaa is not even.\n\nabaababa is not even.\n\nabaabab is not even.\n\nabaaba is even. Thus, we should print its length, 6.\n\nSample Input 2\n\nxxxx\n\nSample Output 2\n\n2\n\nxxx is not even.\n\nxx is even.\n\nSample Input 3\n\nabcabcabcabc\n\nSample Output 3\n\n6\n\nThe longest even string that can be obtained is abcabc, whose length is 6.\n\nSample Input 4\n\nakasakaakasakasakaakas\n\nSample Output 4\n\n14\n\nThe longest even string that can be obtained is akasakaakasaka, whose length is 14.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 216, "cpu_time_ms": 102, "memory_kb": 11748}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s684498167", "group_id": "codeNet:p03673", "input_text": "(let ((lst (loop repeat (read) collect (read)))\n current head)\n (dolist (n lst)\n (push n current)\n (rotatef current head))\n (format t \"~{~a ~}~%\" (append head (nreverse current))))", "language": "Lisp", "metadata": {"date": 1504454345, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03673.html", "problem_id": "p03673", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03673/input.txt", "sample_output_relpath": "derived/input_output/data/p03673/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03673/Lisp/s684498167.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s684498167", "user_id": "u158834201"}, "prompt_components": {"gold_output": "4 2 1 3\n", "input_to_evaluate": "(let ((lst (loop repeat (read) collect (read)))\n current head)\n (dolist (n lst)\n (push n current)\n (rotatef current head))\n (format t \"~{~a ~}~%\" (append head (nreverse current))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given an integer sequence of length n, a_1, ..., a_n.\nLet us consider performing the following n operations on an empty sequence b.\n\nThe i-th operation is as follows:\n\nAppend a_i to the end of b.\n\nReverse the order of the elements in b.\n\nFind the sequence b obtained after these n operations.\n\nConstraints\n\n1 \\leq n \\leq 2\\times 10^5\n\n0 \\leq a_i \\leq 10^9\n\nn and a_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\na_1 a_2 ... a_n\n\nOutput\n\nPrint n integers in a line with spaces in between.\nThe i-th integer should be b_i.\n\nSample Input 1\n\n4\n1 2 3 4\n\nSample Output 1\n\n4 2 1 3\n\nAfter step 1 of the first operation, b becomes: 1.\n\nAfter step 2 of the first operation, b becomes: 1.\n\nAfter step 1 of the second operation, b becomes: 1, 2.\n\nAfter step 2 of the second operation, b becomes: 2, 1.\n\nAfter step 1 of the third operation, b becomes: 2, 1, 3.\n\nAfter step 2 of the third operation, b becomes: 3, 1, 2.\n\nAfter step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n\nAfter step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is 4 2 1 3.\n\nSample Input 2\n\n3\n1 2 3\n\nSample Output 2\n\n3 1 2\n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third operation. Thus, the answer is 3 1 2.\n\nSample Input 3\n\n1\n1000000000\n\nSample Output 3\n\n1000000000\n\nSample Input 4\n\n6\n0 6 7 6 7 0\n\nSample Output 4\n\n0 6 6 0 7 7", "sample_input": "4\n1 2 3 4\n"}, "reference_outputs": ["4 2 1 3\n"], "source_document_id": "p03673", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given an integer sequence of length n, a_1, ..., a_n.\nLet us consider performing the following n operations on an empty sequence b.\n\nThe i-th operation is as follows:\n\nAppend a_i to the end of b.\n\nReverse the order of the elements in b.\n\nFind the sequence b obtained after these n operations.\n\nConstraints\n\n1 \\leq n \\leq 2\\times 10^5\n\n0 \\leq a_i \\leq 10^9\n\nn and a_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\na_1 a_2 ... a_n\n\nOutput\n\nPrint n integers in a line with spaces in between.\nThe i-th integer should be b_i.\n\nSample Input 1\n\n4\n1 2 3 4\n\nSample Output 1\n\n4 2 1 3\n\nAfter step 1 of the first operation, b becomes: 1.\n\nAfter step 2 of the first operation, b becomes: 1.\n\nAfter step 1 of the second operation, b becomes: 1, 2.\n\nAfter step 2 of the second operation, b becomes: 2, 1.\n\nAfter step 1 of the third operation, b becomes: 2, 1, 3.\n\nAfter step 2 of the third operation, b becomes: 3, 1, 2.\n\nAfter step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n\nAfter step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is 4 2 1 3.\n\nSample Input 2\n\n3\n1 2 3\n\nSample Output 2\n\n3 1 2\n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third operation. Thus, the answer is 3 1 2.\n\nSample Input 3\n\n1\n1000000000\n\nSample Output 3\n\n1000000000\n\nSample Input 4\n\n6\n0 6 7 6 7 0\n\nSample Output 4\n\n0 6 6 0 7 7", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 193, "cpu_time_ms": 900, "memory_kb": 70880}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s018896631", "group_id": "codeNet:p03675", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(defun read-fixnum+ (&optional (in *standard-input*))\n (declare (optimize (speed 3) (safety 0) (debug 0)))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let ((result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (return-from read-fixnum+ 0)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the fixnum (* result 10))))\n (return nil))))\n result)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (queue (make-queue)))\n (declare (uint31 n))\n (if (evenp n)\n (dotimes (i n)\n (if (evenp i)\n (enqueue (read-fixnum+) queue)\n (enqueue-front (read-fixnum+) queue)))\n (dotimes (i n)\n (if (oddp i)\n (enqueue (read-fixnum+) queue)\n (enqueue-front (read-fixnum+) queue))))\n (let ((i 0))\n (declare (uint31 i))\n (dolist (x (queue-list queue) (terpri))\n (write (the uint31 x))\n (incf i)\n (when (< i n)\n (write-char #\\ ))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1552519502, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03675.html", "problem_id": "p03675", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03675/input.txt", "sample_output_relpath": "derived/input_output/data/p03675/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03675/Lisp/s018896631.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s018896631", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4 2 1 3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(defun read-fixnum+ (&optional (in *standard-input*))\n (declare (optimize (speed 3) (safety 0) (debug 0)))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let ((result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (return-from read-fixnum+ 0)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the fixnum (* result 10))))\n (return nil))))\n result)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (queue (make-queue)))\n (declare (uint31 n))\n (if (evenp n)\n (dotimes (i n)\n (if (evenp i)\n (enqueue (read-fixnum+) queue)\n (enqueue-front (read-fixnum+) queue)))\n (dotimes (i n)\n (if (oddp i)\n (enqueue (read-fixnum+) queue)\n (enqueue-front (read-fixnum+) queue))))\n (let ((i 0))\n (declare (uint31 i))\n (dolist (x (queue-list queue) (terpri))\n (write (the uint31 x))\n (incf i)\n (when (< i n)\n (write-char #\\ ))))))\n\n#-swank(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given an integer sequence of length n, a_1, ..., a_n.\nLet us consider performing the following n operations on an empty sequence b.\n\nThe i-th operation is as follows:\n\nAppend a_i to the end of b.\n\nReverse the order of the elements in b.\n\nFind the sequence b obtained after these n operations.\n\nConstraints\n\n1 \\leq n \\leq 2\\times 10^5\n\n0 \\leq a_i \\leq 10^9\n\nn and a_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\na_1 a_2 ... a_n\n\nOutput\n\nPrint n integers in a line with spaces in between.\nThe i-th integer should be b_i.\n\nSample Input 1\n\n4\n1 2 3 4\n\nSample Output 1\n\n4 2 1 3\n\nAfter step 1 of the first operation, b becomes: 1.\n\nAfter step 2 of the first operation, b becomes: 1.\n\nAfter step 1 of the second operation, b becomes: 1, 2.\n\nAfter step 2 of the second operation, b becomes: 2, 1.\n\nAfter step 1 of the third operation, b becomes: 2, 1, 3.\n\nAfter step 2 of the third operation, b becomes: 3, 1, 2.\n\nAfter step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n\nAfter step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is 4 2 1 3.\n\nSample Input 2\n\n3\n1 2 3\n\nSample Output 2\n\n3 1 2\n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third operation. Thus, the answer is 3 1 2.\n\nSample Input 3\n\n1\n1000000000\n\nSample Output 3\n\n1000000000\n\nSample Input 4\n\n6\n0 6 7 6 7 0\n\nSample Output 4\n\n0 6 6 0 7 7", "sample_input": "4\n1 2 3 4\n"}, "reference_outputs": ["4 2 1 3\n"], "source_document_id": "p03675", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given an integer sequence of length n, a_1, ..., a_n.\nLet us consider performing the following n operations on an empty sequence b.\n\nThe i-th operation is as follows:\n\nAppend a_i to the end of b.\n\nReverse the order of the elements in b.\n\nFind the sequence b obtained after these n operations.\n\nConstraints\n\n1 \\leq n \\leq 2\\times 10^5\n\n0 \\leq a_i \\leq 10^9\n\nn and a_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\na_1 a_2 ... a_n\n\nOutput\n\nPrint n integers in a line with spaces in between.\nThe i-th integer should be b_i.\n\nSample Input 1\n\n4\n1 2 3 4\n\nSample Output 1\n\n4 2 1 3\n\nAfter step 1 of the first operation, b becomes: 1.\n\nAfter step 2 of the first operation, b becomes: 1.\n\nAfter step 1 of the second operation, b becomes: 1, 2.\n\nAfter step 2 of the second operation, b becomes: 2, 1.\n\nAfter step 1 of the third operation, b becomes: 2, 1, 3.\n\nAfter step 2 of the third operation, b becomes: 3, 1, 2.\n\nAfter step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n\nAfter step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is 4 2 1 3.\n\nSample Input 2\n\n3\n1 2 3\n\nSample Output 2\n\n3 1 2\n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third operation. Thus, the answer is 3 1 2.\n\nSample Input 3\n\n1\n1000000000\n\nSample Output 3\n\n1000000000\n\nSample Input 4\n\n6\n0 6 7 6 7 0\n\nSample Output 4\n\n0 6 6 0 7 7", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3160, "cpu_time_ms": 301, "memory_kb": 16996}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s589151697", "group_id": "codeNet:p03675", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n (pop (queue-list queue)))\n\n(defun empty-queue-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #.(char-code #\\Newline)))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,terminate-char))\n (return (values ,buffer ,idx))))))\n\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))\n (declare (string string)\n (function key)\n ((array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop with position = 0\n for idx from offset below (length dest-vector)\n do (setf (values (aref dest-vector idx) position)\n (parse-integer string :start position :junk-allowed t))\n (setf (aref dest-vector idx) (funcall key (aref dest-vector idx)))\n finally (return dest-vector)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n (queue (make-queue)))\n (declare (uint31 n))\n (split-ints-into-vector (buffered-read-line 2200000) as)\n (if (evenp n)\n (dotimes (i n)\n (if (evenp i)\n (enqueue (aref as i) queue)\n (enqueue-front (aref as i) queue)))\n (dotimes (i n)\n (if (oddp i)\n (enqueue (aref as i) queue)\n (enqueue-front (aref as i) queue))))\n (format t \"~{~D~^ ~}~%\" (queue-list queue))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1552518694, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03675.html", "problem_id": "p03675", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03675/input.txt", "sample_output_relpath": "derived/input_output/data/p03675/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03675/Lisp/s589151697.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s589151697", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4 2 1 3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n (pop (queue-list queue)))\n\n(defun empty-queue-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #.(char-code #\\Newline)))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,terminate-char))\n (return (values ,buffer ,idx))))))\n\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))\n (declare (string string)\n (function key)\n ((array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop with position = 0\n for idx from offset below (length dest-vector)\n do (setf (values (aref dest-vector idx) position)\n (parse-integer string :start position :junk-allowed t))\n (setf (aref dest-vector idx) (funcall key (aref dest-vector idx)))\n finally (return dest-vector)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n (queue (make-queue)))\n (declare (uint31 n))\n (split-ints-into-vector (buffered-read-line 2200000) as)\n (if (evenp n)\n (dotimes (i n)\n (if (evenp i)\n (enqueue (aref as i) queue)\n (enqueue-front (aref as i) queue)))\n (dotimes (i n)\n (if (oddp i)\n (enqueue (aref as i) queue)\n (enqueue-front (aref as i) queue))))\n (format t \"~{~D~^ ~}~%\" (queue-list queue))))\n\n#-swank(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given an integer sequence of length n, a_1, ..., a_n.\nLet us consider performing the following n operations on an empty sequence b.\n\nThe i-th operation is as follows:\n\nAppend a_i to the end of b.\n\nReverse the order of the elements in b.\n\nFind the sequence b obtained after these n operations.\n\nConstraints\n\n1 \\leq n \\leq 2\\times 10^5\n\n0 \\leq a_i \\leq 10^9\n\nn and a_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\na_1 a_2 ... a_n\n\nOutput\n\nPrint n integers in a line with spaces in between.\nThe i-th integer should be b_i.\n\nSample Input 1\n\n4\n1 2 3 4\n\nSample Output 1\n\n4 2 1 3\n\nAfter step 1 of the first operation, b becomes: 1.\n\nAfter step 2 of the first operation, b becomes: 1.\n\nAfter step 1 of the second operation, b becomes: 1, 2.\n\nAfter step 2 of the second operation, b becomes: 2, 1.\n\nAfter step 1 of the third operation, b becomes: 2, 1, 3.\n\nAfter step 2 of the third operation, b becomes: 3, 1, 2.\n\nAfter step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n\nAfter step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is 4 2 1 3.\n\nSample Input 2\n\n3\n1 2 3\n\nSample Output 2\n\n3 1 2\n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third operation. Thus, the answer is 3 1 2.\n\nSample Input 3\n\n1\n1000000000\n\nSample Output 3\n\n1000000000\n\nSample Input 4\n\n6\n0 6 7 6 7 0\n\nSample Output 4\n\n0 6 6 0 7 7", "sample_input": "4\n1 2 3 4\n"}, "reference_outputs": ["4 2 1 3\n"], "source_document_id": "p03675", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given an integer sequence of length n, a_1, ..., a_n.\nLet us consider performing the following n operations on an empty sequence b.\n\nThe i-th operation is as follows:\n\nAppend a_i to the end of b.\n\nReverse the order of the elements in b.\n\nFind the sequence b obtained after these n operations.\n\nConstraints\n\n1 \\leq n \\leq 2\\times 10^5\n\n0 \\leq a_i \\leq 10^9\n\nn and a_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\na_1 a_2 ... a_n\n\nOutput\n\nPrint n integers in a line with spaces in between.\nThe i-th integer should be b_i.\n\nSample Input 1\n\n4\n1 2 3 4\n\nSample Output 1\n\n4 2 1 3\n\nAfter step 1 of the first operation, b becomes: 1.\n\nAfter step 2 of the first operation, b becomes: 1.\n\nAfter step 1 of the second operation, b becomes: 1, 2.\n\nAfter step 2 of the second operation, b becomes: 2, 1.\n\nAfter step 1 of the third operation, b becomes: 2, 1, 3.\n\nAfter step 2 of the third operation, b becomes: 3, 1, 2.\n\nAfter step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n\nAfter step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is 4 2 1 3.\n\nSample Input 2\n\n3\n1 2 3\n\nSample Output 2\n\n3 1 2\n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third operation. Thus, the answer is 3 1 2.\n\nSample Input 3\n\n1\n1000000000\n\nSample Output 3\n\n1000000000\n\nSample Input 4\n\n6\n0 6 7 6 7 0\n\nSample Output 4\n\n0 6 6 0 7 7", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3936, "cpu_time_ms": 468, "memory_kb": 29152}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s595219776", "group_id": "codeNet:p03675", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #.(char-code #\\Newline)))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,terminate-char))\n (return (values ,buffer ,idx))))))\n\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))\n (declare (string string)\n (function key)\n ((array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop with position = 0\n for idx from offset below (length dest-vector)\n do (setf (values (aref dest-vector idx) position)\n (parse-integer string :start position :junk-allowed t))\n (setf (aref dest-vector idx) (funcall key (aref dest-vector idx)))\n finally (return dest-vector)))\n\n(defstruct (inode (:constructor %make-inode (value priority &key left right (count 1) reversed))\n (:copier nil)\n (:conc-name %inode-))\n (value 0 :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (integer 0 #.most-positive-fixnum))\n (reversed nil :type boolean)\n (left nil :type (or null inode))\n (right nil :type (or null inode)))\n\n(declaim (inline inode-count))\n(defun inode-count (inode)\n (declare ((or null inode) inode))\n (if inode\n (%inode-count inode)\n 0))\n\n(declaim (inline update-count))\n(defun update-count (inode)\n (declare (inode inode))\n (setf (%inode-count inode)\n (+ 1\n (inode-count (%inode-left inode))\n (inode-count (%inode-right inode)))))\n\n(declaim (inline force-self))\n(defun force-self (inode)\n (declare (inode inode))\n (update-count inode))\n\n(declaim (inline force-down))\n(defun force-down (inode)\n (declare ((or null inode) inode))\n (when inode ; unnecessary if it is checked before calling this function.\n (when (%inode-reversed inode)\n (setf (%inode-reversed inode) nil)\n (rotatef (%inode-left inode) (%inode-right inode))\n (let ((left (%inode-left inode)))\n (when left\n (setf (%inode-reversed left) (not (%inode-reversed left)))))\n (let ((right (%inode-right inode)))\n (when right\n (setf (%inode-reversed right) (not (%inode-reversed right))))))\n ;; Maybe only need to UPDATE-ACCUMULATOR here.\n (force-self inode)))\n\n(defun inode-split (inode index)\n \"Destructively splits the INODE into two nodes [0, INDEX) and [INDEX, N), where N\n is the number of elements of the INODE.\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless inode\n (return-from inode-split (values nil nil)))\n (force-down inode)\n (let ((implicit-key (1+ (inode-count (%inode-left inode)))))\n (if (< index implicit-key)\n (multiple-value-bind (left right)\n (inode-split (%inode-left inode) index)\n (setf (%inode-left inode) right)\n (force-self inode)\n (values left inode))\n (multiple-value-bind (left right)\n (inode-split (%inode-right inode) (- index implicit-key))\n (setf (%inode-right inode) left)\n (force-self inode)\n (values inode right)))))\n\n(defun inode-merge (left right)\n \"Destructively merges two INODEs.\"\n (cond ((null left) right)\n ((null right) left)\n (t (force-down left)\n (force-down right)\n (if (> (%inode-priority left) (%inode-priority right))\n (progn\n (setf (%inode-right left)\n (inode-merge (%inode-right left) right))\n (force-self left)\n left)\n (progn\n (setf (%inode-left right)\n (inode-merge left (%inode-left right)))\n (force-self right)\n right)))))\n\n(defun %inode-insert (inode index obj-inode)\n \"Destructively inserts OBJ-INODE into INODE at INDEX.\"\n (declare ((or null inode) inode obj-inode)\n ((integer 0 #.most-positive-fixnum) index))\n (assert (<= index (inode-count inode)))\n (multiple-value-bind (left right)\n (inode-split inode index)\n (inode-merge (inode-merge left obj-inode) right)))\n\n(declaim (inline inode-insert))\n(defun inode-insert (inode index obj)\n (%inode-insert inode index (%make-inode obj (random most-positive-fixnum))))\n\n(defun inode-map (function inode)\n (declare (function function))\n (when inode\n (force-down inode)\n (inode-map function (%inode-left inode))\n (funcall function (%inode-value inode))\n (inode-map function (%inode-right inode))))\n\n(defmacro do-inode ((var inode &optional result) &body body)\n `(block nil\n (inode-map (lambda (,var) ,@body) ,inode)\n ,result))\n\n(defun inode-delete (inode index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (assert (< index (inode-count inode)))\n (multiple-value-bind (inode1 inode2)\n (inode-split inode (1+ index))\n (multiple-value-bind (inode1 _)\n (inode-split inode1 index)\n (declare (ignore _))\n (inode-merge inode1 inode2))))\n\n(declaim (inline inode-reverse))\n(defun inode-reverse (inode l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (>= l r)\n inode\n (multiple-value-bind (inode-0-l inode-l-n)\n (inode-split inode l)\n (multiple-value-bind (inode-l-r inode-r-n)\n (inode-split inode-l-n (- r l))\n (setf (%inode-reversed inode-l-r) (not (%inode-reversed inode-l-r)))\n (inode-merge inode-0-l (inode-merge inode-l-r inode-r-n))))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n treap)\n (declare (uint31 n))\n (split-ints-into-vector (buffered-read-line 2200000) as)\n (dotimes (i n)\n (setf treap (inode-insert treap i (aref as i)))\n (setf treap (inode-reverse treap 0 (1+ i))))\n (let ((i 0))\n (declare (uint31 i))\n (do-inode (x treap (terpri))\n (write x)\n (incf i)\n (when (< i n)\n (write-char #\\ ))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1552516877, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03675.html", "problem_id": "p03675", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03675/input.txt", "sample_output_relpath": "derived/input_output/data/p03675/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03675/Lisp/s595219776.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s595219776", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4 2 1 3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #.(char-code #\\Newline)))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,terminate-char))\n (return (values ,buffer ,idx))))))\n\n(declaim (inline split-ints-into-vector))\n(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))\n (declare (string string)\n (function key)\n ((array * (*)) dest-vector)\n ((integer 0 #.most-positive-fixnum) offset))\n (loop with position = 0\n for idx from offset below (length dest-vector)\n do (setf (values (aref dest-vector idx) position)\n (parse-integer string :start position :junk-allowed t))\n (setf (aref dest-vector idx) (funcall key (aref dest-vector idx)))\n finally (return dest-vector)))\n\n(defstruct (inode (:constructor %make-inode (value priority &key left right (count 1) reversed))\n (:copier nil)\n (:conc-name %inode-))\n (value 0 :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (integer 0 #.most-positive-fixnum))\n (reversed nil :type boolean)\n (left nil :type (or null inode))\n (right nil :type (or null inode)))\n\n(declaim (inline inode-count))\n(defun inode-count (inode)\n (declare ((or null inode) inode))\n (if inode\n (%inode-count inode)\n 0))\n\n(declaim (inline update-count))\n(defun update-count (inode)\n (declare (inode inode))\n (setf (%inode-count inode)\n (+ 1\n (inode-count (%inode-left inode))\n (inode-count (%inode-right inode)))))\n\n(declaim (inline force-self))\n(defun force-self (inode)\n (declare (inode inode))\n (update-count inode))\n\n(declaim (inline force-down))\n(defun force-down (inode)\n (declare ((or null inode) inode))\n (when inode ; unnecessary if it is checked before calling this function.\n (when (%inode-reversed inode)\n (setf (%inode-reversed inode) nil)\n (rotatef (%inode-left inode) (%inode-right inode))\n (let ((left (%inode-left inode)))\n (when left\n (setf (%inode-reversed left) (not (%inode-reversed left)))))\n (let ((right (%inode-right inode)))\n (when right\n (setf (%inode-reversed right) (not (%inode-reversed right))))))\n ;; Maybe only need to UPDATE-ACCUMULATOR here.\n (force-self inode)))\n\n(defun inode-split (inode index)\n \"Destructively splits the INODE into two nodes [0, INDEX) and [INDEX, N), where N\n is the number of elements of the INODE.\"\n (declare ((integer 0 #.most-positive-fixnum) index))\n (unless inode\n (return-from inode-split (values nil nil)))\n (force-down inode)\n (let ((implicit-key (1+ (inode-count (%inode-left inode)))))\n (if (< index implicit-key)\n (multiple-value-bind (left right)\n (inode-split (%inode-left inode) index)\n (setf (%inode-left inode) right)\n (force-self inode)\n (values left inode))\n (multiple-value-bind (left right)\n (inode-split (%inode-right inode) (- index implicit-key))\n (setf (%inode-right inode) left)\n (force-self inode)\n (values inode right)))))\n\n(defun inode-merge (left right)\n \"Destructively merges two INODEs.\"\n (cond ((null left) right)\n ((null right) left)\n (t (force-down left)\n (force-down right)\n (if (> (%inode-priority left) (%inode-priority right))\n (progn\n (setf (%inode-right left)\n (inode-merge (%inode-right left) right))\n (force-self left)\n left)\n (progn\n (setf (%inode-left right)\n (inode-merge left (%inode-left right)))\n (force-self right)\n right)))))\n\n(defun %inode-insert (inode index obj-inode)\n \"Destructively inserts OBJ-INODE into INODE at INDEX.\"\n (declare ((or null inode) inode obj-inode)\n ((integer 0 #.most-positive-fixnum) index))\n (assert (<= index (inode-count inode)))\n (multiple-value-bind (left right)\n (inode-split inode index)\n (inode-merge (inode-merge left obj-inode) right)))\n\n(declaim (inline inode-insert))\n(defun inode-insert (inode index obj)\n (%inode-insert inode index (%make-inode obj (random most-positive-fixnum))))\n\n(defun inode-map (function inode)\n (declare (function function))\n (when inode\n (force-down inode)\n (inode-map function (%inode-left inode))\n (funcall function (%inode-value inode))\n (inode-map function (%inode-right inode))))\n\n(defmacro do-inode ((var inode &optional result) &body body)\n `(block nil\n (inode-map (lambda (,var) ,@body) ,inode)\n ,result))\n\n(defun inode-delete (inode index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (assert (< index (inode-count inode)))\n (multiple-value-bind (inode1 inode2)\n (inode-split inode (1+ index))\n (multiple-value-bind (inode1 _)\n (inode-split inode1 index)\n (declare (ignore _))\n (inode-merge inode1 inode2))))\n\n(declaim (inline inode-reverse))\n(defun inode-reverse (inode l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (>= l r)\n inode\n (multiple-value-bind (inode-0-l inode-l-n)\n (inode-split inode l)\n (multiple-value-bind (inode-l-r inode-r-n)\n (inode-split inode-l-n (- r l))\n (setf (%inode-reversed inode-l-r) (not (%inode-reversed inode-l-r)))\n (inode-merge inode-0-l (inode-merge inode-l-r inode-r-n))))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n treap)\n (declare (uint31 n))\n (split-ints-into-vector (buffered-read-line 2200000) as)\n (dotimes (i n)\n (setf treap (inode-insert treap i (aref as i)))\n (setf treap (inode-reverse treap 0 (1+ i))))\n (let ((i 0))\n (declare (uint31 i))\n (do-inode (x treap (terpri))\n (write x)\n (incf i)\n (when (< i n)\n (write-char #\\ ))))))\n\n#-swank(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given an integer sequence of length n, a_1, ..., a_n.\nLet us consider performing the following n operations on an empty sequence b.\n\nThe i-th operation is as follows:\n\nAppend a_i to the end of b.\n\nReverse the order of the elements in b.\n\nFind the sequence b obtained after these n operations.\n\nConstraints\n\n1 \\leq n \\leq 2\\times 10^5\n\n0 \\leq a_i \\leq 10^9\n\nn and a_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\na_1 a_2 ... a_n\n\nOutput\n\nPrint n integers in a line with spaces in between.\nThe i-th integer should be b_i.\n\nSample Input 1\n\n4\n1 2 3 4\n\nSample Output 1\n\n4 2 1 3\n\nAfter step 1 of the first operation, b becomes: 1.\n\nAfter step 2 of the first operation, b becomes: 1.\n\nAfter step 1 of the second operation, b becomes: 1, 2.\n\nAfter step 2 of the second operation, b becomes: 2, 1.\n\nAfter step 1 of the third operation, b becomes: 2, 1, 3.\n\nAfter step 2 of the third operation, b becomes: 3, 1, 2.\n\nAfter step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n\nAfter step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is 4 2 1 3.\n\nSample Input 2\n\n3\n1 2 3\n\nSample Output 2\n\n3 1 2\n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third operation. Thus, the answer is 3 1 2.\n\nSample Input 3\n\n1\n1000000000\n\nSample Output 3\n\n1000000000\n\nSample Input 4\n\n6\n0 6 7 6 7 0\n\nSample Output 4\n\n0 6 6 0 7 7", "sample_input": "4\n1 2 3 4\n"}, "reference_outputs": ["4 2 1 3\n"], "source_document_id": "p03675", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given an integer sequence of length n, a_1, ..., a_n.\nLet us consider performing the following n operations on an empty sequence b.\n\nThe i-th operation is as follows:\n\nAppend a_i to the end of b.\n\nReverse the order of the elements in b.\n\nFind the sequence b obtained after these n operations.\n\nConstraints\n\n1 \\leq n \\leq 2\\times 10^5\n\n0 \\leq a_i \\leq 10^9\n\nn and a_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\na_1 a_2 ... a_n\n\nOutput\n\nPrint n integers in a line with spaces in between.\nThe i-th integer should be b_i.\n\nSample Input 1\n\n4\n1 2 3 4\n\nSample Output 1\n\n4 2 1 3\n\nAfter step 1 of the first operation, b becomes: 1.\n\nAfter step 2 of the first operation, b becomes: 1.\n\nAfter step 1 of the second operation, b becomes: 1, 2.\n\nAfter step 2 of the second operation, b becomes: 2, 1.\n\nAfter step 1 of the third operation, b becomes: 2, 1, 3.\n\nAfter step 2 of the third operation, b becomes: 3, 1, 2.\n\nAfter step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n\nAfter step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is 4 2 1 3.\n\nSample Input 2\n\n3\n1 2 3\n\nSample Output 2\n\n3 1 2\n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third operation. Thus, the answer is 3 1 2.\n\nSample Input 3\n\n1\n1000000000\n\nSample Output 3\n\n1000000000\n\nSample Input 4\n\n6\n0 6 7 6 7 0\n\nSample Output 4\n\n0 6 6 0 7 7", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7658, "cpu_time_ms": 673, "memory_kb": 45544}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s198695299", "group_id": "codeNet:p03679", "input_text": "(let ((x (read))\n (a (read))\n (b (read))\n (ans \"dangerous\"))\n\n (if (< 0 (- a b))\n (setq ans \"delicious\")\n (if (> x (- b a))\n (setq ans \"safe\")))\n (princ ans)\n)", "language": "Lisp", "metadata": {"date": 1595695709, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03679.html", "problem_id": "p03679", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03679/input.txt", "sample_output_relpath": "derived/input_output/data/p03679/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03679/Lisp/s198695299.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s198695299", "user_id": "u136500538"}, "prompt_components": {"gold_output": "safe\n", "input_to_evaluate": "(let ((x (read))\n (a (read))\n (b (read))\n (ans \"dangerous\"))\n\n (if (< 0 (- a b))\n (setq ans \"delicious\")\n (if (> x (- b a))\n (setq ans \"safe\")))\n (princ ans)\n)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi has a strong stomach. He never gets a stomachache from eating something whose \"best-by\" date is at most X days earlier.\nHe gets a stomachache if the \"best-by\" date of the food is X+1 or more days earlier, though.\n\nOther than that, he finds the food delicious if he eats it not later than the \"best-by\" date. Otherwise, he does not find it delicious.\n\nTakahashi bought some food A days before the \"best-by\" date, and ate it B days after he bought it.\n\nWrite a program that outputs delicious if he found it delicious, safe if he did not found it delicious but did not get a stomachache either, and dangerous if he got a stomachache.\n\nConstraints\n\n1 ≤ X,A,B ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX A B\n\nOutput\n\nPrint delicious if Takahashi found the food delicious; print safe if he neither found it delicious nor got a stomachache; print dangerous if he got a stomachache.\n\nSample Input 1\n\n4 3 6\n\nSample Output 1\n\nsafe\n\nHe ate the food three days after the \"best-by\" date. It was not delicious or harmful for him.\n\nSample Input 2\n\n6 5 1\n\nSample Output 2\n\ndelicious\n\nHe ate the food by the \"best-by\" date. It was delicious for him.\n\nSample Input 3\n\n3 7 12\n\nSample Output 3\n\ndangerous\n\nHe ate the food five days after the \"best-by\" date. It was harmful for him.", "sample_input": "4 3 6\n"}, "reference_outputs": ["safe\n"], "source_document_id": "p03679", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi has a strong stomach. He never gets a stomachache from eating something whose \"best-by\" date is at most X days earlier.\nHe gets a stomachache if the \"best-by\" date of the food is X+1 or more days earlier, though.\n\nOther than that, he finds the food delicious if he eats it not later than the \"best-by\" date. Otherwise, he does not find it delicious.\n\nTakahashi bought some food A days before the \"best-by\" date, and ate it B days after he bought it.\n\nWrite a program that outputs delicious if he found it delicious, safe if he did not found it delicious but did not get a stomachache either, and dangerous if he got a stomachache.\n\nConstraints\n\n1 ≤ X,A,B ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX A B\n\nOutput\n\nPrint delicious if Takahashi found the food delicious; print safe if he neither found it delicious nor got a stomachache; print dangerous if he got a stomachache.\n\nSample Input 1\n\n4 3 6\n\nSample Output 1\n\nsafe\n\nHe ate the food three days after the \"best-by\" date. It was not delicious or harmful for him.\n\nSample Input 2\n\n6 5 1\n\nSample Output 2\n\ndelicious\n\nHe ate the food by the \"best-by\" date. It was delicious for him.\n\nSample Input 3\n\n3 7 12\n\nSample Output 3\n\ndangerous\n\nHe ate the food five days after the \"best-by\" date. It was harmful for him.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 191, "cpu_time_ms": 18, "memory_kb": 23456}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s006409077", "group_id": "codeNet:p03680", "input_text": "(let* ((n (read))\n (lst (loop repeat n\n collect (read))))\n\n (defun f (l &optional (pos 0) (cnt 0))\n (if (> cnt n)\n -1\n (if (= pos 1)\n cnt\n (f l (1- (nth pos l)) (1+ cnt)))))\n\n (format t \"~A~%\"\n (f lst)))\n", "language": "Lisp", "metadata": {"date": 1595019570, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03680.html", "problem_id": "p03680", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03680/input.txt", "sample_output_relpath": "derived/input_output/data/p03680/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03680/Lisp/s006409077.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s006409077", "user_id": "u336541610"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (read))\n (lst (loop repeat n\n collect (read))))\n\n (defun f (l &optional (pos 0) (cnt 0))\n (if (> cnt n)\n -1\n (if (= pos 1)\n cnt\n (f l (1- (nth pos l)) (1+ cnt)))))\n\n (format t \"~A~%\"\n (f lst)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi wants to gain muscle, and decides to work out at AtCoder Gym.\n\nThe exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up.\nThese buttons are numbered 1 through N.\nWhen Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i.\nWhen Button i is not lighten up, nothing will happen by pressing it.\n\nInitially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.\n\nDetermine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.\n\nConstraints\n\n2 ≤ N ≤ 10^5\n\n1 ≤ a_i ≤ N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1\na_2\n:\na_N\n\nOutput\n\nPrint -1 if it is impossible to lighten up Button 2.\nOtherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.\n\nSample Input 1\n\n3\n3\n1\n2\n\nSample Output 1\n\n2\n\nPress Button 1, then Button 3.\n\nSample Input 2\n\n4\n3\n4\n1\n2\n\nSample Output 2\n\n-1\n\nPressing Button 1 lightens up Button 3, and vice versa, so Button 2 will never be lighten up.\n\nSample Input 3\n\n5\n3\n3\n4\n2\n4\n\nSample Output 3\n\n3", "sample_input": "3\n3\n1\n2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03680", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi wants to gain muscle, and decides to work out at AtCoder Gym.\n\nThe exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up.\nThese buttons are numbered 1 through N.\nWhen Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i.\nWhen Button i is not lighten up, nothing will happen by pressing it.\n\nInitially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.\n\nDetermine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.\n\nConstraints\n\n2 ≤ N ≤ 10^5\n\n1 ≤ a_i ≤ N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1\na_2\n:\na_N\n\nOutput\n\nPrint -1 if it is impossible to lighten up Button 2.\nOtherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.\n\nSample Input 1\n\n3\n3\n1\n2\n\nSample Output 1\n\n2\n\nPress Button 1, then Button 3.\n\nSample Input 2\n\n4\n3\n4\n1\n2\n\nSample Output 2\n\n-1\n\nPressing Button 1 lightens up Button 3, and vice versa, so Button 2 will never be lighten up.\n\nSample Input 3\n\n5\n3\n3\n4\n2\n4\n\nSample Output 3\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 265, "cpu_time_ms": 2207, "memory_kb": 78420}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s661711115", "group_id": "codeNet:p03680", "input_text": "(defun solver ()\n (let ((n (read)) (temp nil)\n (ai (make-array 100000 :fill-pointer 1)))\n (loop for i from 1 to n do\n (vector-push (read) ai))\n (format t \"~A~%\" ai)\n (setf temp (aref ai 1))\n (loop for i from 1 to 100001 do\n (when (= temp 2)\n (return (format t \"~A~%\" i)))\n (setf temp (aref ai temp))\n finally (format t \"-1~%\"))))\n\n(solver)", "language": "Lisp", "metadata": {"date": 1498353839, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03680.html", "problem_id": "p03680", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03680/input.txt", "sample_output_relpath": "derived/input_output/data/p03680/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03680/Lisp/s661711115.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s661711115", "user_id": "u183015556"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun solver ()\n (let ((n (read)) (temp nil)\n (ai (make-array 100000 :fill-pointer 1)))\n (loop for i from 1 to n do\n (vector-push (read) ai))\n (format t \"~A~%\" ai)\n (setf temp (aref ai 1))\n (loop for i from 1 to 100001 do\n (when (= temp 2)\n (return (format t \"~A~%\" i)))\n (setf temp (aref ai temp))\n finally (format t \"-1~%\"))))\n\n(solver)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi wants to gain muscle, and decides to work out at AtCoder Gym.\n\nThe exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up.\nThese buttons are numbered 1 through N.\nWhen Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i.\nWhen Button i is not lighten up, nothing will happen by pressing it.\n\nInitially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.\n\nDetermine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.\n\nConstraints\n\n2 ≤ N ≤ 10^5\n\n1 ≤ a_i ≤ N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1\na_2\n:\na_N\n\nOutput\n\nPrint -1 if it is impossible to lighten up Button 2.\nOtherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.\n\nSample Input 1\n\n3\n3\n1\n2\n\nSample Output 1\n\n2\n\nPress Button 1, then Button 3.\n\nSample Input 2\n\n4\n3\n4\n1\n2\n\nSample Output 2\n\n-1\n\nPressing Button 1 lightens up Button 3, and vice versa, so Button 2 will never be lighten up.\n\nSample Input 3\n\n5\n3\n3\n4\n2\n4\n\nSample Output 3\n\n3", "sample_input": "3\n3\n1\n2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03680", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi wants to gain muscle, and decides to work out at AtCoder Gym.\n\nThe exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up.\nThese buttons are numbered 1 through N.\nWhen Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i.\nWhen Button i is not lighten up, nothing will happen by pressing it.\n\nInitially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.\n\nDetermine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.\n\nConstraints\n\n2 ≤ N ≤ 10^5\n\n1 ≤ a_i ≤ N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1\na_2\n:\na_N\n\nOutput\n\nPrint -1 if it is impossible to lighten up Button 2.\nOtherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.\n\nSample Input 1\n\n3\n3\n1\n2\n\nSample Output 1\n\n2\n\nPress Button 1, then Button 3.\n\nSample Input 2\n\n4\n3\n4\n1\n2\n\nSample Output 2\n\n-1\n\nPressing Button 1 lightens up Button 3, and vice versa, so Button 2 will never be lighten up.\n\nSample Input 3\n\n5\n3\n3\n4\n2\n4\n\nSample Output 3\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 406, "cpu_time_ms": 632, "memory_kb": 67812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s904223535", "group_id": "codeNet:p03681", "input_text": "(declaim (optimize (sped 3) (debug 0) (safety 0)))\n\n(defun fact (n)\n (let ((p 1) (r 1) (NN 1) (log2n (floor (log n 2)))\n (h 0) (shift 0) (high 1) (len 0))\n (labels ((prod (n)\n (declare (fixnum n))\n (let ((m (ash n -1)))\n (cond ((= m 0) (incf NN 2))\n ((= n 2) (* (incf NN 2) (incf NN 2)))\n (t (* (prod (- n m)) (prod m)))))))\n (loop while (/= h n) do\n (incf shift h)\n (setf h (ash n (- log2n)))\n (decf log2n)\n (setf len high)\n (setf high (if (oddp h) h (1- h)))\n (setf len (ash (- high len) -1))\n (cond ((> len 0)\n (setf p (* p (prod len)))\n (setf r (* r p)))))\n (ash r shift))))\n\n(format t \"~A~%\" (let ((n (read))\n (m (read)))\n (case (abs (- n m))\n (1 (if (> n m)\n (mod (* (expt (fact m) 2) n) 1000000007)))\n (mod (* (expt (fact n) 2) m) 1000000007) \n (0 (mod (* 2 (expt (fact n) 2)) 1000000007))\n (t 0))))", "language": "Lisp", "metadata": {"date": 1504553100, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03681.html", "problem_id": "p03681", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03681/input.txt", "sample_output_relpath": "derived/input_output/data/p03681/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03681/Lisp/s904223535.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s904223535", "user_id": "u140665374"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(declaim (optimize (sped 3) (debug 0) (safety 0)))\n\n(defun fact (n)\n (let ((p 1) (r 1) (NN 1) (log2n (floor (log n 2)))\n (h 0) (shift 0) (high 1) (len 0))\n (labels ((prod (n)\n (declare (fixnum n))\n (let ((m (ash n -1)))\n (cond ((= m 0) (incf NN 2))\n ((= n 2) (* (incf NN 2) (incf NN 2)))\n (t (* (prod (- n m)) (prod m)))))))\n (loop while (/= h n) do\n (incf shift h)\n (setf h (ash n (- log2n)))\n (decf log2n)\n (setf len high)\n (setf high (if (oddp h) h (1- h)))\n (setf len (ash (- high len) -1))\n (cond ((> len 0)\n (setf p (* p (prod len)))\n (setf r (* r p)))))\n (ash r shift))))\n\n(format t \"~A~%\" (let ((n (read))\n (m (read)))\n (case (abs (- n m))\n (1 (if (> n m)\n (mod (* (expt (fact m) 2) n) 1000000007)))\n (mod (* (expt (fact n) 2) m) 1000000007) \n (0 (mod (* 2 (expt (fact n) 2)) 1000000007))\n (t 0))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke has N dogs and M monkeys. He wants them to line up in a row.\n\nAs a Japanese saying goes, these dogs and monkeys are on bad terms. (\"ken'en no naka\", literally \"the relationship of dogs and monkeys\", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.\n\nHow many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that).\nHere, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.\n\nConstraints\n\n1 ≤ N,M ≤ 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nPrint the number of possible arrangements, modulo 10^9+7.\n\nSample Input 1\n\n2 2\n\nSample Output 1\n\n8\n\nWe will denote the dogs by A and B, and the monkeys by C and D. There are eight possible arrangements: ACBD, ADBC, BCAD, BDAC, CADB, CBDA, DACB and DBCA.\n\nSample Input 2\n\n3 2\n\nSample Output 2\n\n12\n\nSample Input 3\n\n1 8\n\nSample Output 3\n\n0\n\nSample Input 4\n\n100000 100000\n\nSample Output 4\n\n530123477", "sample_input": "2 2\n"}, "reference_outputs": ["8\n"], "source_document_id": "p03681", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke has N dogs and M monkeys. He wants them to line up in a row.\n\nAs a Japanese saying goes, these dogs and monkeys are on bad terms. (\"ken'en no naka\", literally \"the relationship of dogs and monkeys\", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.\n\nHow many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that).\nHere, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.\n\nConstraints\n\n1 ≤ N,M ≤ 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nPrint the number of possible arrangements, modulo 10^9+7.\n\nSample Input 1\n\n2 2\n\nSample Output 1\n\n8\n\nWe will denote the dogs by A and B, and the monkeys by C and D. There are eight possible arrangements: ACBD, ADBC, BCAD, BDAC, CADB, CBDA, DACB and DBCA.\n\nSample Input 2\n\n3 2\n\nSample Output 2\n\n12\n\nSample Input 3\n\n1 8\n\nSample Output 3\n\n0\n\nSample Input 4\n\n100000 100000\n\nSample Output 4\n\n530123477", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1184, "cpu_time_ms": 1302, "memory_kb": 10724}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s455690031", "group_id": "codeNet:p03681", "input_text": "(defun fact (n)\n (labels ((rec (n a)\n (if (= n 0)\n a\n (rec (1- n) (mod (* n a) 1000000007)))))\n (rec n 1)))\n\n(defun solver ()\n (let ((n (read)) (m (read))\n (big nil) (small nil) (smallfact nil))\n (if (> n m)\n (setf big n small m)\n (setf big m small n))\n (cond ((> (abs (- big small)) 1)\n (format t \"0~%\"))\n ((= big small)\n (setf smallfact (fact small))\n (format t \"~A~%\" (* smallfact smallfact 2)))\n ((setf smallfact (fact small))\n (format t \"~A~%\" (* smallfact (* smallfact (1+ small))))))))\n\n(solver)", "language": "Lisp", "metadata": {"date": 1498355775, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03681.html", "problem_id": "p03681", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03681/input.txt", "sample_output_relpath": "derived/input_output/data/p03681/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03681/Lisp/s455690031.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s455690031", "user_id": "u183015556"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(defun fact (n)\n (labels ((rec (n a)\n (if (= n 0)\n a\n (rec (1- n) (mod (* n a) 1000000007)))))\n (rec n 1)))\n\n(defun solver ()\n (let ((n (read)) (m (read))\n (big nil) (small nil) (smallfact nil))\n (if (> n m)\n (setf big n small m)\n (setf big m small n))\n (cond ((> (abs (- big small)) 1)\n (format t \"0~%\"))\n ((= big small)\n (setf smallfact (fact small))\n (format t \"~A~%\" (* smallfact smallfact 2)))\n ((setf smallfact (fact small))\n (format t \"~A~%\" (* smallfact (* smallfact (1+ small))))))))\n\n(solver)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke has N dogs and M monkeys. He wants them to line up in a row.\n\nAs a Japanese saying goes, these dogs and monkeys are on bad terms. (\"ken'en no naka\", literally \"the relationship of dogs and monkeys\", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.\n\nHow many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that).\nHere, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.\n\nConstraints\n\n1 ≤ N,M ≤ 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nPrint the number of possible arrangements, modulo 10^9+7.\n\nSample Input 1\n\n2 2\n\nSample Output 1\n\n8\n\nWe will denote the dogs by A and B, and the monkeys by C and D. There are eight possible arrangements: ACBD, ADBC, BCAD, BDAC, CADB, CBDA, DACB and DBCA.\n\nSample Input 2\n\n3 2\n\nSample Output 2\n\n12\n\nSample Input 3\n\n1 8\n\nSample Output 3\n\n0\n\nSample Input 4\n\n100000 100000\n\nSample Output 4\n\n530123477", "sample_input": "2 2\n"}, "reference_outputs": ["8\n"], "source_document_id": "p03681", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke has N dogs and M monkeys. He wants them to line up in a row.\n\nAs a Japanese saying goes, these dogs and monkeys are on bad terms. (\"ken'en no naka\", literally \"the relationship of dogs and monkeys\", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.\n\nHow many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that).\nHere, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.\n\nConstraints\n\n1 ≤ N,M ≤ 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nPrint the number of possible arrangements, modulo 10^9+7.\n\nSample Input 1\n\n2 2\n\nSample Output 1\n\n8\n\nWe will denote the dogs by A and B, and the monkeys by C and D. There are eight possible arrangements: ACBD, ADBC, BCAD, BDAC, CADB, CBDA, DACB and DBCA.\n\nSample Input 2\n\n3 2\n\nSample Output 2\n\n12\n\nSample Input 3\n\n1 8\n\nSample Output 3\n\n0\n\nSample Input 4\n\n100000 100000\n\nSample Output 4\n\n530123477", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 651, "cpu_time_ms": 138, "memory_kb": 16096}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s289034988", "group_id": "codeNet:p03684", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro split-ints-and-bind (vars string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str (gensym \"STR\")))\n (labels ((expand (vars &optional (init-pos1 t))\n\t (if (null vars)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str :start ,pos1 :test #'char=))\n\t\t\t (,(car vars) (parse-integer ,str :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr vars) nil))))))\n `(let ((,str ,string))\n (declare (string ,str))\n\t ,@(expand vars)))))\n\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #\\Newline))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (setf (schar ,buffer ,idx) ,terminate-char)\n (return (values ,buffer ,idx))))))\n\n(deftype non-negative-fixnum () '(integer 0 #.most-positive-fixnum))\n\n(defstruct (union-find\n (:constructor make-union-find\n (size &aux (parents (let ((seq (make-array size :element-type 'non-negative-fixnum)))\n (dotimes (i size seq) (setf (aref seq i) i))))\n (ranks (make-array size :element-type 'non-negative-fixnum\n :initial-element 0)))))\n (parents nil :type (simple-array non-negative-fixnum (*)))\n (ranks nil :type (simple-array non-negative-fixnum (*))))\n\n(declaim (ftype (function * (values non-negative-fixnum &optional)) uf-root))\n(defun uf-root (x uf-tree)\n \"Returns the root of X.\"\n (declare (optimize (speed 3))\n (non-negative-fixnum x))\n (let ((parents (union-find-parents uf-tree)))\n (if (= x (aref parents x))\n x\n (setf (aref parents x)\n (uf-root (aref parents x) uf-tree)))))\n\n(declaim (inline uf-unite!))\n(defun uf-unite! (x1 x2 uf-tree)\n \"Unites X1 and X2 destructively.\"\n (let ((root1 (uf-root x1 uf-tree))\n (root2 (uf-root x2 uf-tree))\n (parents (union-find-parents uf-tree))\n (ranks (union-find-ranks uf-tree)))\n (cond ((= root1 root2) nil)\n ((< (aref ranks root1) (aref ranks root2))\n (setf (aref parents root1) root2))\n ((= (aref ranks root1) (aref ranks root2))\n (setf (aref parents root2) root1)\n (incf (aref ranks root1)))\n (t (setf (aref parents root2) root1)))))\n\n(declaim (inline uf-connected-p))\n(defun uf-connected-p (x1 x2 uf-tree)\n \"Checks if X1 and X2 have the same root.\"\n (= (uf-root x1 uf-tree) (uf-root x2 uf-tree)))\n\n;; (defun bench ()\n;; (let* ((size 5000000)\n;; (tree (make-union-find size))\n;; (seed (seed-random-state 0)))\n;; (dotimes (i 5000000)\n;; (uf-unite! (random size seed) (random size seed) tree))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n ;; (x y idx)\n (table (make-array n :element-type '(cons uint32 (cons uint32 uint32)))))\n (dotimes (i n)\n (split-ints-and-bind (x y) (buffered-read-line)\n (setf (aref table i) (list x y i))))\n (let ((table-x (stable-sort (copy-seq table) #'< :key #'first))\n (table-y (stable-sort table #'< :key #'second))\n edges) ; (cost from to)\n (declare (list edges))\n (loop for j below (- n 1)\n do (destructuring-bind (x1 y1 city1) (aref table-x j)\n (destructuring-bind (x2 y2 city2) (aref table-x (+ j 1))\n (declare (uint32 x1 y1 x2 y2 city1 city2))\n (push (list (min (abs (- x2 x1)) (abs (- y2 y1)))\n city1 city2)\n edges)))\n (destructuring-bind (x1 y1 city1) (aref table-y j)\n (destructuring-bind (x2 y2 city2) (aref table-y (+ j 1))\n (declare (uint32 x1 y1 x2 y2 city1 city2))\n (push (list (min (abs (- x2 x1)) (abs (- y2 y1)))\n city1 city2)\n edges)))\n finally (setf edges (sort edges #'< :key #'first)))\n (let ((tree (make-union-find n))\n (cost-sum 0))\n (dolist (edge edges)\n (destructuring-bind (cost from to) edge\n (unless (uf-connected-p from to tree)\n (uf-unite! from to tree)\n (incf cost-sum cost))))\n (println cost-sum)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1547538507, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03684.html", "problem_id": "p03684", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03684/input.txt", "sample_output_relpath": "derived/input_output/data/p03684/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03684/Lisp/s289034988.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s289034988", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro split-ints-and-bind (vars string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str (gensym \"STR\")))\n (labels ((expand (vars &optional (init-pos1 t))\n\t (if (null vars)\n\t\t body\n\t\t `((let* ((,pos1 ,(if init-pos1 0 `(1+ ,pos2)))\n\t\t\t (,pos2 (position #\\space ,str :start ,pos1 :test #'char=))\n\t\t\t (,(car vars) (parse-integer ,str :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr vars) nil))))))\n `(let ((,str ,string))\n (declare (string ,str))\n\t ,@(expand vars)))))\n\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #\\Newline))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (setf (schar ,buffer ,idx) ,terminate-char)\n (return (values ,buffer ,idx))))))\n\n(deftype non-negative-fixnum () '(integer 0 #.most-positive-fixnum))\n\n(defstruct (union-find\n (:constructor make-union-find\n (size &aux (parents (let ((seq (make-array size :element-type 'non-negative-fixnum)))\n (dotimes (i size seq) (setf (aref seq i) i))))\n (ranks (make-array size :element-type 'non-negative-fixnum\n :initial-element 0)))))\n (parents nil :type (simple-array non-negative-fixnum (*)))\n (ranks nil :type (simple-array non-negative-fixnum (*))))\n\n(declaim (ftype (function * (values non-negative-fixnum &optional)) uf-root))\n(defun uf-root (x uf-tree)\n \"Returns the root of X.\"\n (declare (optimize (speed 3))\n (non-negative-fixnum x))\n (let ((parents (union-find-parents uf-tree)))\n (if (= x (aref parents x))\n x\n (setf (aref parents x)\n (uf-root (aref parents x) uf-tree)))))\n\n(declaim (inline uf-unite!))\n(defun uf-unite! (x1 x2 uf-tree)\n \"Unites X1 and X2 destructively.\"\n (let ((root1 (uf-root x1 uf-tree))\n (root2 (uf-root x2 uf-tree))\n (parents (union-find-parents uf-tree))\n (ranks (union-find-ranks uf-tree)))\n (cond ((= root1 root2) nil)\n ((< (aref ranks root1) (aref ranks root2))\n (setf (aref parents root1) root2))\n ((= (aref ranks root1) (aref ranks root2))\n (setf (aref parents root2) root1)\n (incf (aref ranks root1)))\n (t (setf (aref parents root2) root1)))))\n\n(declaim (inline uf-connected-p))\n(defun uf-connected-p (x1 x2 uf-tree)\n \"Checks if X1 and X2 have the same root.\"\n (= (uf-root x1 uf-tree) (uf-root x2 uf-tree)))\n\n;; (defun bench ()\n;; (let* ((size 5000000)\n;; (tree (make-union-find size))\n;; (seed (seed-random-state 0)))\n;; (dotimes (i 5000000)\n;; (uf-unite! (random size seed) (random size seed) tree))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n;; Hauptteil\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n ;; (x y idx)\n (table (make-array n :element-type '(cons uint32 (cons uint32 uint32)))))\n (dotimes (i n)\n (split-ints-and-bind (x y) (buffered-read-line)\n (setf (aref table i) (list x y i))))\n (let ((table-x (stable-sort (copy-seq table) #'< :key #'first))\n (table-y (stable-sort table #'< :key #'second))\n edges) ; (cost from to)\n (declare (list edges))\n (loop for j below (- n 1)\n do (destructuring-bind (x1 y1 city1) (aref table-x j)\n (destructuring-bind (x2 y2 city2) (aref table-x (+ j 1))\n (declare (uint32 x1 y1 x2 y2 city1 city2))\n (push (list (min (abs (- x2 x1)) (abs (- y2 y1)))\n city1 city2)\n edges)))\n (destructuring-bind (x1 y1 city1) (aref table-y j)\n (destructuring-bind (x2 y2 city2) (aref table-y (+ j 1))\n (declare (uint32 x1 y1 x2 y2 city1 city2))\n (push (list (min (abs (- x2 x1)) (abs (- y2 y1)))\n city1 city2)\n edges)))\n finally (setf edges (sort edges #'< :key #'first)))\n (let ((tree (make-union-find n))\n (cost-sum 0))\n (dolist (edge edges)\n (destructuring-bind (cost from to) edge\n (unless (uf-connected-p from to tree)\n (uf-unite! from to tree)\n (incf cost-sum cost))))\n (println cost-sum)))))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates.\n\nYou can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads.\n\nYour objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?\n\nConstraints\n\n2 ≤ N ≤ 10^5\n\n0 ≤ x_i,y_i ≤ 10^9\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\nx_2 y_2\n:\nx_N y_N\n\nOutput\n\nPrint the minimum necessary amount of money in order to build roads so that it will be possible to travel between every pair of towns by traversing roads.\n\nSample Input 1\n\n3\n1 5\n3 9\n7 8\n\nSample Output 1\n\n3\n\nBuild a road between Towns 1 and 2, and another between Towns 2 and 3. The total cost is 2+1=3 yen.\n\nSample Input 2\n\n6\n8 3\n4 9\n12 19\n18 1\n13 5\n7 6\n\nSample Output 2\n\n8", "sample_input": "3\n1 5\n3 9\n7 8\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03684", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates.\n\nYou can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads.\n\nYour objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?\n\nConstraints\n\n2 ≤ N ≤ 10^5\n\n0 ≤ x_i,y_i ≤ 10^9\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1\nx_2 y_2\n:\nx_N y_N\n\nOutput\n\nPrint the minimum necessary amount of money in order to build roads so that it will be possible to travel between every pair of towns by traversing roads.\n\nSample Input 1\n\n3\n1 5\n3 9\n7 8\n\nSample Output 1\n\n3\n\nBuild a road between Towns 1 and 2, and another between Towns 2 and 3. The total cost is 2+1=3 yen.\n\nSample Input 2\n\n6\n8 3\n4 9\n12 19\n18 1\n13 5\n7 6\n\nSample Output 2\n\n8", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5788, "cpu_time_ms": 493, "memory_kb": 47712}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s428968222", "group_id": "codeNet:p03688", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline hash-keys-to-list))\n(defun hash-keys-to-list (hash-table)\n (let ((result nil))\n (maphash (lambda (key _)\n (declare (ignore _))\n (push key result))\n hash-table)\n result))\n\n;; from alexandria\n(declaim (inline hash-table-to-alist))\n(defun hash-table-to-alist (hash-table)\n (let ((alist nil))\n (maphash (lambda (k v)\n (push (cons k v) alist))\n hash-table)\n alist))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (table (make-hash-table :size n :test 'eq)))\n (dotimes (i n)\n (let ((a (read-fixnum)))\n (if (gethash a table)\n (incf (gethash a table))\n (setf (gethash a table) 1))))\n (let ((count (hash-table-count table))\n (alist (hash-table-to-alist table)))\n (when (>= count 3)\n (write-line \"No\")\n (return-from main))\n (when (= count 1)\n (let ((k (caar alist)))\n (if (or (>= (floor n 2) k)\n (= k (- n 1)))\n (write-line \"Yes\")\n (write-line \"No\"))))\n (when (= count 2)\n (unless (< (car (first alist)) (car (second alist)))\n (rotatef (first alist) (second alist)))\n (let ((k (car (first alist)))\n (k+1 (cdr (second alist)))\n (dk (cdr (first alist))))\n (unless (= k+1 (+ k 1))\n (write-line \"No\")\n (return-from main))\n (unless (<= dk k)\n (write-line \"No\")\n (return-from main))\n (if (>= (floor (- n dk) 2)\n (- k+1 dk))\n (write-line \"Yes\")\n (write-line \"\")))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1563243027, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03688.html", "problem_id": "p03688", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03688/input.txt", "sample_output_relpath": "derived/input_output/data/p03688/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03688/Lisp/s428968222.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s428968222", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline hash-keys-to-list))\n(defun hash-keys-to-list (hash-table)\n (let ((result nil))\n (maphash (lambda (key _)\n (declare (ignore _))\n (push key result))\n hash-table)\n result))\n\n;; from alexandria\n(declaim (inline hash-table-to-alist))\n(defun hash-table-to-alist (hash-table)\n (let ((alist nil))\n (maphash (lambda (k v)\n (push (cons k v) alist))\n hash-table)\n alist))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (table (make-hash-table :size n :test 'eq)))\n (dotimes (i n)\n (let ((a (read-fixnum)))\n (if (gethash a table)\n (incf (gethash a table))\n (setf (gethash a table) 1))))\n (let ((count (hash-table-count table))\n (alist (hash-table-to-alist table)))\n (when (>= count 3)\n (write-line \"No\")\n (return-from main))\n (when (= count 1)\n (let ((k (caar alist)))\n (if (or (>= (floor n 2) k)\n (= k (- n 1)))\n (write-line \"Yes\")\n (write-line \"No\"))))\n (when (= count 2)\n (unless (< (car (first alist)) (car (second alist)))\n (rotatef (first alist) (second alist)))\n (let ((k (car (first alist)))\n (k+1 (cdr (second alist)))\n (dk (cdr (first alist))))\n (unless (= k+1 (+ k 1))\n (write-line \"No\")\n (return-from main))\n (unless (<= dk k)\n (write-line \"No\")\n (return-from main))\n (if (>= (floor (- n dk) 2)\n (- k+1 dk))\n (write-line \"Yes\")\n (write-line \"\")))))))\n\n#-swank (main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nThere are N cats.\nWe number them from 1 through N.\n\nEach of the cats wears a hat.\nCat i says: \"there are exactly a_i different colors among the N - 1 hats worn by the cats except me.\"\n\nDetermine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.\n\nConstraints\n\n2 ≤ N ≤ 10^5\n\n1 ≤ a_i ≤ N-1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint Yes if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print No otherwise.\n\nSample Input 1\n\n3\n1 2 2\n\nSample Output 1\n\nYes\n\nFor example, if cat 1, 2 and 3 wears red, blue and blue hats, respectively, it is consistent with the remarks of the cats.\n\nSample Input 2\n\n3\n1 1 2\n\nSample Output 2\n\nNo\n\nFrom the remark of cat 1, we can see that cat 2 and 3 wear hats of the same color.\nAlso, from the remark of cat 2, we can see that cat 1 and 3 wear hats of the same color.\nTherefore, cat 1 and 2 wear hats of the same color, which contradicts the remark of cat 3.\n\nSample Input 3\n\n5\n4 3 4 3 4\n\nSample Output 3\n\nNo\n\nSample Input 4\n\n3\n2 2 2\n\nSample Output 4\n\nYes\n\nSample Input 5\n\n4\n2 2 2 2\n\nSample Output 5\n\nYes\n\nSample Input 6\n\n5\n3 3 3 3 3\n\nSample Output 6\n\nNo", "sample_input": "3\n1 2 2\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03688", "source_text": "Score : 700 points\n\nProblem Statement\n\nThere are N cats.\nWe number them from 1 through N.\n\nEach of the cats wears a hat.\nCat i says: \"there are exactly a_i different colors among the N - 1 hats worn by the cats except me.\"\n\nDetermine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.\n\nConstraints\n\n2 ≤ N ≤ 10^5\n\n1 ≤ a_i ≤ N-1\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint Yes if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print No otherwise.\n\nSample Input 1\n\n3\n1 2 2\n\nSample Output 1\n\nYes\n\nFor example, if cat 1, 2 and 3 wears red, blue and blue hats, respectively, it is consistent with the remarks of the cats.\n\nSample Input 2\n\n3\n1 1 2\n\nSample Output 2\n\nNo\n\nFrom the remark of cat 1, we can see that cat 2 and 3 wear hats of the same color.\nAlso, from the remark of cat 2, we can see that cat 1 and 3 wear hats of the same color.\nTherefore, cat 1 and 2 wear hats of the same color, which contradicts the remark of cat 3.\n\nSample Input 3\n\n5\n4 3 4 3 4\n\nSample Output 3\n\nNo\n\nSample Input 4\n\n3\n2 2 2\n\nSample Output 4\n\nYes\n\nSample Input 5\n\n4\n2 2 2 2\n\nSample Output 5\n\nYes\n\nSample Input 6\n\n5\n3 3 3 3 3\n\nSample Output 6\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4027, "cpu_time_ms": 221, "memory_kb": 24548}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s362780273", "group_id": "codeNet:p03693", "input_text": "(if (= 0 (mod (+ (* (read) 100) (* (read) 10) (read)) 4))\n (princ \"YES\")\n (princ \"NO\"))", "language": "Lisp", "metadata": {"date": 1542393453, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03693.html", "problem_id": "p03693", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03693/input.txt", "sample_output_relpath": "derived/input_output/data/p03693/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03693/Lisp/s362780273.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s362780273", "user_id": "u610490393"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(if (= 0 (mod (+ (* (read) 100) (* (read) 10) (read)) 4))\n (princ \"YES\")\n (princ \"NO\"))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nAtCoDeer has three cards, one red, one green and one blue.\n\nAn integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card.\n\nWe will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer.\n\nIs this integer a multiple of 4?\n\nConstraints\n\n1 ≤ r, g, b ≤ 9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr g b\n\nOutput\n\nIf the three-digit integer is a multiple of 4, print YES (case-sensitive); otherwise, print NO.\n\nSample Input 1\n\n4 3 2\n\nSample Output 1\n\nYES\n\n432 is a multiple of 4, and thus YES should be printed.\n\nSample Input 2\n\n2 3 4\n\nSample Output 2\n\nNO\n\n234 is not a multiple of 4, and thus NO should be printed.", "sample_input": "4 3 2\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03693", "source_text": "Score : 100 points\n\nProblem Statement\n\nAtCoDeer has three cards, one red, one green and one blue.\n\nAn integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card.\n\nWe will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer.\n\nIs this integer a multiple of 4?\n\nConstraints\n\n1 ≤ r, g, b ≤ 9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr g b\n\nOutput\n\nIf the three-digit integer is a multiple of 4, print YES (case-sensitive); otherwise, print NO.\n\nSample Input 1\n\n4 3 2\n\nSample Output 1\n\nYES\n\n432 is a multiple of 4, and thus YES should be printed.\n\nSample Input 2\n\n2 3 4\n\nSample Output 2\n\nNO\n\n234 is not a multiple of 4, and thus NO should be printed.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 93, "cpu_time_ms": 5, "memory_kb": 2788}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s948614593", "group_id": "codeNet:p03695", "input_text": "(defun collector (function lst); listの各要素を数えるコレクタ 10^7くらいまで\n (if lst\n (let* ((ans '())\n (mem (cons (car lst) 1)))\n (mapcar (lambda (k)\n (if (funcall function k (car mem))\n (incf (cdr mem))\n (progn (push mem ans)\n (setf mem (cons k 1))))) (cdr lst))\n (push mem ans)\n ans)\n '()))\n\n(let* ((n (read))\n (lst (sort (loop :repeat n :collect (read)) #'<))\n (over3200 0)\n (ln (count-if (lambda (x) (<= 0 x))\n (collector #'= (mapcar (lambda (x) (if (<= 3200 x)\n (progn (incf over3200) -1)\n (floor x 400))) lst)) :key #'car)))\n (if (and (= ln 0) (not (= over3200 0)))\n (format t \"1 1\")\n (format t \"~A ~A\" ln (+ ln over3200))))\n\n", "language": "Lisp", "metadata": {"date": 1586412785, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03695.html", "problem_id": "p03695", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03695/input.txt", "sample_output_relpath": "derived/input_output/data/p03695/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03695/Lisp/s948614593.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s948614593", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2 2\n", "input_to_evaluate": "(defun collector (function lst); listの各要素を数えるコレクタ 10^7くらいまで\n (if lst\n (let* ((ans '())\n (mem (cons (car lst) 1)))\n (mapcar (lambda (k)\n (if (funcall function k (car mem))\n (incf (cdr mem))\n (progn (push mem ans)\n (setf mem (cons k 1))))) (cdr lst))\n (push mem ans)\n ans)\n '()))\n\n(let* ((n (read))\n (lst (sort (loop :repeat n :collect (read)) #'<))\n (over3200 0)\n (ln (count-if (lambda (x) (<= 0 x))\n (collector #'= (mapcar (lambda (x) (if (<= 3200 x)\n (progn (incf over3200) -1)\n (floor x 400))) lst)) :key #'car)))\n (if (and (= ln 0) (not (= over3200 0)))\n (format t \"1 1\")\n (format t \"~A ~A\" ln (+ ln over3200))))\n\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nIn AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows:\n\nRating 1-399 : gray\n\nRating 400-799 : brown\n\nRating 800-1199 : green\n\nRating 1200-1599 : cyan\n\nRating 1600-1999 : blue\n\nRating 2000-2399 : yellow\n\nRating 2400-2799 : orange\n\nRating 2800-3199 : red\n\nOther than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not.\n\nCurrently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i.\n\nFind the minimum and maximum possible numbers of different colors of the users.\n\nConstraints\n\n1 ≤ N ≤ 100\n\n1 ≤ a_i ≤ 4800\n\na_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the minimum possible number of different colors of the users, and the maximum possible number of different colors, with a space in between.\n\nSample Input 1\n\n4\n2100 2500 2700 2700\n\nSample Output 1\n\n2 2\n\nThe user with rating 2100 is \"yellow\", and the others are \"orange\". There are two different colors.\n\nSample Input 2\n\n5\n1100 1900 2800 3200 3200\n\nSample Output 2\n\n3 5\n\nThe user with rating 1100 is \"green\", the user with rating 1900 is blue and the user with rating 2800 is \"red\".\n\nIf the fourth user picks \"red\", and the fifth user picks \"blue\", there are three different colors. This is one possible scenario for the minimum number of colors.\n\nIf the fourth user picks \"purple\", and the fifth user picks \"black\", there are five different colors. This is one possible scenario for the maximum number of colors.\n\nSample Input 3\n\n20\n800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990\n\nSample Output 3\n\n1 1\n\nAll the users are \"green\", and thus there is one color.", "sample_input": "4\n2100 2500 2700 2700\n"}, "reference_outputs": ["2 2\n"], "source_document_id": "p03695", "source_text": "Score : 300 points\n\nProblem Statement\n\nIn AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows:\n\nRating 1-399 : gray\n\nRating 400-799 : brown\n\nRating 800-1199 : green\n\nRating 1200-1599 : cyan\n\nRating 1600-1999 : blue\n\nRating 2000-2399 : yellow\n\nRating 2400-2799 : orange\n\nRating 2800-3199 : red\n\nOther than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not.\n\nCurrently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i.\n\nFind the minimum and maximum possible numbers of different colors of the users.\n\nConstraints\n\n1 ≤ N ≤ 100\n\n1 ≤ a_i ≤ 4800\n\na_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the minimum possible number of different colors of the users, and the maximum possible number of different colors, with a space in between.\n\nSample Input 1\n\n4\n2100 2500 2700 2700\n\nSample Output 1\n\n2 2\n\nThe user with rating 2100 is \"yellow\", and the others are \"orange\". There are two different colors.\n\nSample Input 2\n\n5\n1100 1900 2800 3200 3200\n\nSample Output 2\n\n3 5\n\nThe user with rating 1100 is \"green\", the user with rating 1900 is blue and the user with rating 2800 is \"red\".\n\nIf the fourth user picks \"red\", and the fifth user picks \"blue\", there are three different colors. This is one possible scenario for the minimum number of colors.\n\nIf the fourth user picks \"purple\", and the fifth user picks \"black\", there are five different colors. This is one possible scenario for the maximum number of colors.\n\nSample Input 3\n\n20\n800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990\n\nSample Output 3\n\n1 1\n\nAll the users are \"green\", and thus there is one color.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 949, "cpu_time_ms": 139, "memory_kb": 16104}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s341210228", "group_id": "codeNet:p03696", "input_text": "(defun count-left (str)\n (loop for ch across (reverse str)\n with rp = 0\n with id = 0 do\n (if (eq ch #\\))\n (incf rp)\n (if (zerop rp)\n (incf id)\n (decf rp)))\n finally (return id)))\n\n(defun count-right (str)\n (loop for ch across str\n with lp = 0\n with id = 0 do\n (if (eq ch #\\()\n (incf lp)\n (if (zerop lp)\n (incf id)\n (decf lp)))\n finally (return id)))\n\n(let* ((n (read-line))\n (s (read-line)))\n (declare (ignore n))\n (dotimes (i (count-right s))\n (princ #\\())\n (princ s)\n (dotimes (i (count-left s))\n (princ #\\)))\n (terpri))\n", "language": "Lisp", "metadata": {"date": 1511737937, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03696.html", "problem_id": "p03696", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03696/input.txt", "sample_output_relpath": "derived/input_output/data/p03696/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03696/Lisp/s341210228.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s341210228", "user_id": "u275710783"}, "prompt_components": {"gold_output": "(())\n", "input_to_evaluate": "(defun count-left (str)\n (loop for ch across (reverse str)\n with rp = 0\n with id = 0 do\n (if (eq ch #\\))\n (incf rp)\n (if (zerop rp)\n (incf id)\n (decf rp)))\n finally (return id)))\n\n(defun count-right (str)\n (loop for ch across str\n with lp = 0\n with id = 0 do\n (if (eq ch #\\()\n (incf lp)\n (if (zerop lp)\n (incf id)\n (decf lp)))\n finally (return id)))\n\n(let* ((n (read-line))\n (s (read-line)))\n (declare (ignore n))\n (dotimes (i (count-right s))\n (princ #\\())\n (princ s)\n (dotimes (i (count-left s))\n (princ #\\)))\n (terpri))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYou are given a string S of length N consisting of ( and ). Your task is to insert some number of ( and ) into S to obtain a correct bracket sequence.\n\nHere, a correct bracket sequence is defined as follows:\n\n() is a correct bracket sequence.\n\nIf X is a correct bracket sequence, the concatenation of (, X and ) in this order is also a correct bracket sequence.\n\nIf X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence.\n\nEvery correct bracket sequence can be derived from the rules above.\n\nFind the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.\n\nConstraints\n\nThe length of S is N.\n\n1 ≤ N ≤ 100\n\nS consists of ( and ).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the lexicographically smallest string among the shortest correct bracket sequences that can be obtained by inserting some number of ( and ) into S.\n\nSample Input 1\n\n3\n())\n\nSample Output 1\n\n(())\n\nSample Input 2\n\n6\n)))())\n\nSample Output 2\n\n(((()))())\n\nSample Input 3\n\n8\n))))((((\n\nSample Output 3\n\n(((())))(((())))", "sample_input": "3\n())\n"}, "reference_outputs": ["(())\n"], "source_document_id": "p03696", "source_text": "Score : 400 points\n\nProblem Statement\n\nYou are given a string S of length N consisting of ( and ). Your task is to insert some number of ( and ) into S to obtain a correct bracket sequence.\n\nHere, a correct bracket sequence is defined as follows:\n\n() is a correct bracket sequence.\n\nIf X is a correct bracket sequence, the concatenation of (, X and ) in this order is also a correct bracket sequence.\n\nIf X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence.\n\nEvery correct bracket sequence can be derived from the rules above.\n\nFind the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.\n\nConstraints\n\nThe length of S is N.\n\n1 ≤ N ≤ 100\n\nS consists of ( and ).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the lexicographically smallest string among the shortest correct bracket sequences that can be obtained by inserting some number of ( and ) into S.\n\nSample Input 1\n\n3\n())\n\nSample Output 1\n\n(())\n\nSample Input 2\n\n6\n)))())\n\nSample Output 2\n\n(((()))())\n\nSample Input 3\n\n8\n))))((((\n\nSample Output 3\n\n(((())))(((())))", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 702, "cpu_time_ms": 135, "memory_kb": 15848}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s505300812", "group_id": "codeNet:p03697", "input_text": "(defun split (string &key (delimiterp #'(lambda (c) (char= c #\\Space))))\n (loop :for beg = (position-if-not delimiterp string)\n :then (position-if-not delimiterp string :start (1+ end))\n :for end = (and beg (position-if delimiterp string :start beg))\n :when beg :collect (subseq string beg end)\n :while end))\n\n(destructuring-bind (a b) (mapcar #'parse-integer (split (read-line)))\n (let ((sum (+ a b)))\n (format t \"~a~%\" (if (>= sum 10)\n \"error\"\n sum))))\n", "language": "Lisp", "metadata": {"date": 1496538175, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03697.html", "problem_id": "p03697", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03697/input.txt", "sample_output_relpath": "derived/input_output/data/p03697/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03697/Lisp/s505300812.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s505300812", "user_id": "u690263481"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(defun split (string &key (delimiterp #'(lambda (c) (char= c #\\Space))))\n (loop :for beg = (position-if-not delimiterp string)\n :then (position-if-not delimiterp string :start (1+ end))\n :for end = (and beg (position-if delimiterp string :start beg))\n :when beg :collect (subseq string beg end)\n :while end))\n\n(destructuring-bind (a b) (mapcar #'parse-integer (split (read-line)))\n (let ((sum (+ a b)))\n (format t \"~a~%\" (if (>= sum 10)\n \"error\"\n sum))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given two integers A and B as the input. Output the value of A + B.\n\nHowever, if A + B is 10 or greater, output error instead.\n\nConstraints\n\nA and B are integers.\n\n1 ≤ A, B ≤ 9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nIf A + B is 10 or greater, print the string error (case-sensitive); otherwise, print the value of A + B.\n\nSample Input 1\n\n6 3\n\nSample Output 1\n\n9\n\nSample Input 2\n\n6 4\n\nSample Output 2\n\nerror", "sample_input": "6 3\n"}, "reference_outputs": ["9\n"], "source_document_id": "p03697", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given two integers A and B as the input. Output the value of A + B.\n\nHowever, if A + B is 10 or greater, output error instead.\n\nConstraints\n\nA and B are integers.\n\n1 ≤ A, B ≤ 9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nIf A + B is 10 or greater, print the string error (case-sensitive); otherwise, print the value of A + B.\n\nSample Input 1\n\n6 3\n\nSample Output 1\n\n9\n\nSample Input 2\n\n6 4\n\nSample Output 2\n\nerror", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 536, "cpu_time_ms": 342, "memory_kb": 15972}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s908309457", "group_id": "codeNet:p03697", "input_text": "(defun solver ()\n (let ((a (read)) (b (read)))\n (if (>= (+ a b) 10)\n (format t \"error~%\")\n (format t \"~A~%\" (+ a b)))))\n\n(solver)", "language": "Lisp", "metadata": {"date": 1496538153, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03697.html", "problem_id": "p03697", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03697/input.txt", "sample_output_relpath": "derived/input_output/data/p03697/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03697/Lisp/s908309457.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s908309457", "user_id": "u183015556"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(defun solver ()\n (let ((a (read)) (b (read)))\n (if (>= (+ a b) 10)\n (format t \"error~%\")\n (format t \"~A~%\" (+ a b)))))\n\n(solver)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given two integers A and B as the input. Output the value of A + B.\n\nHowever, if A + B is 10 or greater, output error instead.\n\nConstraints\n\nA and B are integers.\n\n1 ≤ A, B ≤ 9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nIf A + B is 10 or greater, print the string error (case-sensitive); otherwise, print the value of A + B.\n\nSample Input 1\n\n6 3\n\nSample Output 1\n\n9\n\nSample Input 2\n\n6 4\n\nSample Output 2\n\nerror", "sample_input": "6 3\n"}, "reference_outputs": ["9\n"], "source_document_id": "p03697", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given two integers A and B as the input. Output the value of A + B.\n\nHowever, if A + B is 10 or greater, output error instead.\n\nConstraints\n\nA and B are integers.\n\n1 ≤ A, B ≤ 9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nIf A + B is 10 or greater, print the string error (case-sensitive); otherwise, print the value of A + B.\n\nSample Input 1\n\n6 3\n\nSample Output 1\n\n9\n\nSample Input 2\n\n6 4\n\nSample Output 2\n\nerror", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 137, "cpu_time_ms": 417, "memory_kb": 12004}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s245127885", "group_id": "codeNet:p03698", "input_text": "(format t \"~A~%\" (let ((s (read-line)))\n (if (string= s (remove-duplicates s))\n \"yes\"\n \"no\")))", "language": "Lisp", "metadata": {"date": 1504741810, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03698.html", "problem_id": "p03698", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03698/input.txt", "sample_output_relpath": "derived/input_output/data/p03698/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03698/Lisp/s245127885.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s245127885", "user_id": "u140665374"}, "prompt_components": {"gold_output": "yes\n", "input_to_evaluate": "(format t \"~A~%\" (let ((s (read-line)))\n (if (string= s (remove-duplicates s))\n \"yes\"\n \"no\")))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.\n\nConstraints\n\n2 ≤ |S| ≤ 26, where |S| denotes the length of S.\n\nS consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf all the characters in S are different, print yes (case-sensitive); otherwise, print no.\n\nSample Input 1\n\nuncopyrightable\n\nSample Output 1\n\nyes\n\nSample Input 2\n\ndifferent\n\nSample Output 2\n\nno\n\nSample Input 3\n\nno\n\nSample Output 3\n\nyes", "sample_input": "uncopyrightable\n"}, "reference_outputs": ["yes\n"], "source_document_id": "p03698", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.\n\nConstraints\n\n2 ≤ |S| ≤ 26, where |S| denotes the length of S.\n\nS consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf all the characters in S are different, print yes (case-sensitive); otherwise, print no.\n\nSample Input 1\n\nuncopyrightable\n\nSample Output 1\n\nyes\n\nSample Input 2\n\ndifferent\n\nSample Output 2\n\nno\n\nSample Input 3\n\nno\n\nSample Output 3\n\nyes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 156, "cpu_time_ms": 109, "memory_kb": 9700}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s841384952", "group_id": "codeNet:p03699", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Complement to the bitwise operations in CLHS\n;;;\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (assert (= sb-vm:n-word-bits 64)))\n\n;; KLUDGE: a variant of DPB that handles a 64-bit word efficiently\n(defmacro u64-dpb (new spec int)\n (destructuring-bind (byte s p) spec\n (assert (eql 'byte byte))\n (let ((size (gensym)) (posn (gensym)) (mask (gensym)))\n `(let* ((,size ,s)\n (,posn ,p)\n (,mask (ldb (byte ,size 0) -1)))\n (logior (the (unsigned-byte 64) (ash (logand ,new ,mask) ,posn))\n (the (unsigned-byte 64) (logand ,int (lognot (ash ,mask ,posn)))))))))\n\n(defconstant +most-positive-word+ #.(- (ash 1 64) 1))\n\n;; TODO: right shift\n(declaim (ftype (function * (values simple-bit-vector &optional)) bit-lshift))\n(defun bit-lshift (bit-vector delta &optional result-vector end)\n \"Left-shifts BIT-VECTOR by DELTA bits and fills the new bits with zero.\nThe behaviour is the same as the bit-wise operations in CLHS: The result is\ncopied to RESULT-VECTOR; if it is T, BIT-VECTOR is destructively modified; if it\nis NIL, a new bit-vector of the same length is created. If END is specified,\nthis function shifts only the range [0, END) of BIT-VECTOR and copies it to the\nrange [0, END+DELTA) of RESULT-VECTOR.\n\nNote that here `left' means the direction from a smaller index to a larger one,\ni.e. (bit-lshift #*1011000 2) |-> #*0010110\"\n (declare (optimize (speed 3))\n (simple-bit-vector bit-vector)\n ((or null (eql t) simple-bit-vector) result-vector)\n ((integer 0 #.most-positive-fixnum) delta)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (setq result-vector\n (etypecase result-vector\n (null (make-array (length bit-vector) :element-type 'bit :initial-element 0))\n ((eql t) bit-vector)\n (simple-bit-vector result-vector)))\n (setq end (or end (length bit-vector)))\n (assert (<= end (length bit-vector)))\n (setq end (min end (max 0 (- (length result-vector) delta))))\n (multiple-value-bind (d/64 d%64) (floor delta 64)\n (declare (optimize (safety 0))\n (simple-bit-vector result-vector))\n (multiple-value-bind (end/64 end%64) (floor end 64)\n ;; process the last word separately\n (unless (zerop end%64)\n (let ((word (sb-kernel:%vector-raw-bits bit-vector end/64)))\n (setf (sb-kernel:%vector-raw-bits result-vector (+ end/64 d/64))\n (u64-dpb word\n (byte (min end%64 (- 64 d%64)) d%64)\n (sb-kernel:%vector-raw-bits result-vector (+ end/64 d/64))))\n (when (> end%64 (- 64 d%64))\n (setf (ldb (byte (- end%64 (- 64 d%64)) 0)\n (sb-kernel:%vector-raw-bits result-vector (+ 1 end/64 d/64)))\n (ldb (byte (- end%64 (- 64 d%64)) (- 64 d%64)) word)))))\n ;; Body. We avoid LDB and DPB here for efficiency, though this seems to\n ;; be somewhat incomprehensible...\n (let* ((mask0 (ldb (byte 64 0) (lognot (ldb (byte d%64 0) -1))))\n (mask1-lo (ldb (byte (- 64 d%64) 0) -1))\n (mask1-hi (ldb (byte 64 0) (lognot (ash mask1-lo d%64)))))\n (declare ((unsigned-byte 64) mask0 mask1-lo mask1-hi))\n (do ((i (- end/64 1) (- i 1)))\n ((< i 0))\n (let ((word (sb-kernel:%vector-raw-bits bit-vector i))\n (i+d/64 (+ i d/64)))\n (declare ((unsigned-byte 64) word)\n ((mod #.most-positive-fixnum) i+d/64))\n (setf (sb-kernel:%vector-raw-bits result-vector i+d/64)\n (logior (the (unsigned-byte 64)\n (ash (logand word mask1-lo) d%64))\n (logand (sb-kernel:%vector-raw-bits result-vector i+d/64)\n mask1-hi)))\n (setf (sb-kernel:%vector-raw-bits result-vector (+ 1 i+d/64))\n (logior (ash word (- d%64 64))\n (logand (sb-kernel:%vector-raw-bits result-vector (+ 1 i+d/64))\n mask0))))))\n ;; zero padding\n (when (< d/64 (ceiling (length result-vector) 64))\n (setf (ldb (byte d%64 0) (sb-kernel:%vector-raw-bits result-vector d/64)) 0))\n ;; REVIEW: May we set the last word of a bit vector to zero beyond the\n ;; actual bound?\n (dotimes (i (min d/64 (ceiling (length result-vector) 64)))\n (setf (sb-kernel:%vector-raw-bits result-vector i) 0))\n result-vector)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (dp (make-array 10001 :element-type 'bit :initial-element 0)))\n (setf (aref dp 0) 1)\n (dotimes (i n)\n (let ((s (read)))\n (bit-ior dp (bit-lshift dp s) dp)))\n (println\n (loop for x below (length dp)\n maximize (if (or (zerop (aref dp x))\n (zerop (mod x 10)))\n 0\n x)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1568093193, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03699.html", "problem_id": "p03699", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03699/input.txt", "sample_output_relpath": "derived/input_output/data/p03699/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03699/Lisp/s841384952.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s841384952", "user_id": "u352600849"}, "prompt_components": {"gold_output": "25\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Complement to the bitwise operations in CLHS\n;;;\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (assert (= sb-vm:n-word-bits 64)))\n\n;; KLUDGE: a variant of DPB that handles a 64-bit word efficiently\n(defmacro u64-dpb (new spec int)\n (destructuring-bind (byte s p) spec\n (assert (eql 'byte byte))\n (let ((size (gensym)) (posn (gensym)) (mask (gensym)))\n `(let* ((,size ,s)\n (,posn ,p)\n (,mask (ldb (byte ,size 0) -1)))\n (logior (the (unsigned-byte 64) (ash (logand ,new ,mask) ,posn))\n (the (unsigned-byte 64) (logand ,int (lognot (ash ,mask ,posn)))))))))\n\n(defconstant +most-positive-word+ #.(- (ash 1 64) 1))\n\n;; TODO: right shift\n(declaim (ftype (function * (values simple-bit-vector &optional)) bit-lshift))\n(defun bit-lshift (bit-vector delta &optional result-vector end)\n \"Left-shifts BIT-VECTOR by DELTA bits and fills the new bits with zero.\nThe behaviour is the same as the bit-wise operations in CLHS: The result is\ncopied to RESULT-VECTOR; if it is T, BIT-VECTOR is destructively modified; if it\nis NIL, a new bit-vector of the same length is created. If END is specified,\nthis function shifts only the range [0, END) of BIT-VECTOR and copies it to the\nrange [0, END+DELTA) of RESULT-VECTOR.\n\nNote that here `left' means the direction from a smaller index to a larger one,\ni.e. (bit-lshift #*1011000 2) |-> #*0010110\"\n (declare (optimize (speed 3))\n (simple-bit-vector bit-vector)\n ((or null (eql t) simple-bit-vector) result-vector)\n ((integer 0 #.most-positive-fixnum) delta)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (setq result-vector\n (etypecase result-vector\n (null (make-array (length bit-vector) :element-type 'bit :initial-element 0))\n ((eql t) bit-vector)\n (simple-bit-vector result-vector)))\n (setq end (or end (length bit-vector)))\n (assert (<= end (length bit-vector)))\n (setq end (min end (max 0 (- (length result-vector) delta))))\n (multiple-value-bind (d/64 d%64) (floor delta 64)\n (declare (optimize (safety 0))\n (simple-bit-vector result-vector))\n (multiple-value-bind (end/64 end%64) (floor end 64)\n ;; process the last word separately\n (unless (zerop end%64)\n (let ((word (sb-kernel:%vector-raw-bits bit-vector end/64)))\n (setf (sb-kernel:%vector-raw-bits result-vector (+ end/64 d/64))\n (u64-dpb word\n (byte (min end%64 (- 64 d%64)) d%64)\n (sb-kernel:%vector-raw-bits result-vector (+ end/64 d/64))))\n (when (> end%64 (- 64 d%64))\n (setf (ldb (byte (- end%64 (- 64 d%64)) 0)\n (sb-kernel:%vector-raw-bits result-vector (+ 1 end/64 d/64)))\n (ldb (byte (- end%64 (- 64 d%64)) (- 64 d%64)) word)))))\n ;; Body. We avoid LDB and DPB here for efficiency, though this seems to\n ;; be somewhat incomprehensible...\n (let* ((mask0 (ldb (byte 64 0) (lognot (ldb (byte d%64 0) -1))))\n (mask1-lo (ldb (byte (- 64 d%64) 0) -1))\n (mask1-hi (ldb (byte 64 0) (lognot (ash mask1-lo d%64)))))\n (declare ((unsigned-byte 64) mask0 mask1-lo mask1-hi))\n (do ((i (- end/64 1) (- i 1)))\n ((< i 0))\n (let ((word (sb-kernel:%vector-raw-bits bit-vector i))\n (i+d/64 (+ i d/64)))\n (declare ((unsigned-byte 64) word)\n ((mod #.most-positive-fixnum) i+d/64))\n (setf (sb-kernel:%vector-raw-bits result-vector i+d/64)\n (logior (the (unsigned-byte 64)\n (ash (logand word mask1-lo) d%64))\n (logand (sb-kernel:%vector-raw-bits result-vector i+d/64)\n mask1-hi)))\n (setf (sb-kernel:%vector-raw-bits result-vector (+ 1 i+d/64))\n (logior (ash word (- d%64 64))\n (logand (sb-kernel:%vector-raw-bits result-vector (+ 1 i+d/64))\n mask0))))))\n ;; zero padding\n (when (< d/64 (ceiling (length result-vector) 64))\n (setf (ldb (byte d%64 0) (sb-kernel:%vector-raw-bits result-vector d/64)) 0))\n ;; REVIEW: May we set the last word of a bit vector to zero beyond the\n ;; actual bound?\n (dotimes (i (min d/64 (ceiling (length result-vector) 64)))\n (setf (sb-kernel:%vector-raw-bits result-vector i) 0))\n result-vector)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (dp (make-array 10001 :element-type 'bit :initial-element 0)))\n (setf (aref dp 0) 1)\n (dotimes (i n)\n (let ((s (read)))\n (bit-ior dp (bit-lshift dp s) dp)))\n (println\n (loop for x below (length dp)\n maximize (if (or (zerop (aref dp x))\n (zerop (mod x 10)))\n 0\n x)))))\n\n#-swank (main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either \"correct\" or \"incorrect\", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well.\n\nHowever, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?\n\nConstraints\n\nAll input values are integers.\n\n1 ≤ N ≤ 100\n\n1 ≤ s_i ≤ 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\ns_1\ns_2\n:\ns_N\n\nOutput\n\nPrint the maximum value that can be displayed as your grade.\n\nSample Input 1\n\n3\n5\n10\n15\n\nSample Output 1\n\n25\n\nYour grade will be 25 if the 10-point and 15-point questions are answered correctly and the 5-point question is not, and this grade will be displayed correctly. Your grade will become 30 if the 5-point question is also answered correctly, but this grade will be incorrectly displayed as 0.\n\nSample Input 2\n\n3\n10\n10\n15\n\nSample Output 2\n\n35\n\nYour grade will be 35 if all the questions are answered correctly, and this grade will be displayed correctly.\n\nSample Input 3\n\n3\n10\n20\n30\n\nSample Output 3\n\n0\n\nRegardless of whether each question is answered correctly or not, your grade will be a multiple of 10 and displayed as 0.", "sample_input": "3\n5\n10\n15\n"}, "reference_outputs": ["25\n"], "source_document_id": "p03699", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either \"correct\" or \"incorrect\", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well.\n\nHowever, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?\n\nConstraints\n\nAll input values are integers.\n\n1 ≤ N ≤ 100\n\n1 ≤ s_i ≤ 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\ns_1\ns_2\n:\ns_N\n\nOutput\n\nPrint the maximum value that can be displayed as your grade.\n\nSample Input 1\n\n3\n5\n10\n15\n\nSample Output 1\n\n25\n\nYour grade will be 25 if the 10-point and 15-point questions are answered correctly and the 5-point question is not, and this grade will be displayed correctly. Your grade will become 30 if the 5-point question is also answered correctly, but this grade will be incorrectly displayed as 0.\n\nSample Input 2\n\n3\n10\n10\n15\n\nSample Output 2\n\n35\n\nYour grade will be 35 if all the questions are answered correctly, and this grade will be displayed correctly.\n\nSample Input 3\n\n3\n10\n20\n30\n\nSample Output 3\n\n0\n\nRegardless of whether each question is answered correctly or not, your grade will be a multiple of 10 and displayed as 0.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6265, "cpu_time_ms": 311, "memory_kb": 29028}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s428238086", "group_id": "codeNet:p03703", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Calculates inversion number by merge sort\n;;;\n\n;; Introduce INIT-VECTOR for better type-propagation on SBCL\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:defknown init-vector (vector)\n vector (sb-c:flushable)\n :overwrite-fndb-silently t)\n\n (sb-c:defoptimizer (init-vector sb-c:derive-type) ((template))\n (let* ((template-type (sb-c::lvar-type template))\n (spec `(,(if (sb-kernel:array-type-complexp template-type) 'array 'simple-array)\n ,(sb-kernel:type-specifier (sb-kernel:array-type-element-type template-type))\n (*))))\n (sb-c::careful-specifier-type spec))))\n\n(defun init-vector (template)\n \"Returns a newly initialized vector of the same type as TEMPLATE vector with\nSIZE.\"\n (declare (optimize (speed 3)))\n (make-array (length template) :element-type (array-element-type template)))\n\n(declaim (inline %merge-count))\n(defun %merge-count (l mid r source-vec dest-vec predicate)\n (declare ((mod #.array-total-size-limit) l mid r)\n (function predicate))\n (loop with count of-type (integer 0 #.most-positive-fixnum) = 0\n with i = l\n with j = mid\n for idx from l\n when (= i mid)\n do (loop for j from j below r\n for idx from idx\n do (setf (aref dest-vec idx)\n (aref source-vec j))\n finally (return-from %merge-count count))\n when (= j r)\n do (loop for i from i below mid\n for idx from idx\n do (setf (aref dest-vec idx)\n (aref source-vec i))\n finally (return-from %merge-count count))\n do (if (funcall predicate\n (aref source-vec j)\n (aref source-vec i))\n (setf (aref dest-vec idx) (aref source-vec j)\n j (1+ j)\n count (+ count (- mid i)))\n (setf (aref dest-vec idx) (aref source-vec i)\n i (1+ i)))))\n\n(defmacro with-fixnum+ (form)\n (let ((fixnum+ '(integer 0 #.most-positive-fixnum)))\n `(the ,fixnum+\n ,(reduce (lambda (f1 f2)`(,(car form)\n (the ,fixnum+ ,f1)\n (the ,fixnum+ ,f2)))\n\t (cdr form)))))\n\n(declaim (inline %calc-by-bubble-sort!))\n(defun %calc-by-bubble-sort! (vec predicate l r)\n (declare (function predicate)\n ((mod #.array-total-size-limit) l r))\n (loop for end from r above l\n sum (loop with inv-count of-type (integer 0 #.most-positive-fixnum) = 0\n for i from l below (- end 1)\n do (when (funcall predicate (aref vec (+ i 1)) (aref vec i))\n (rotatef (aref vec i) (aref vec (+ i 1)))\n (incf inv-count))\n finally (return inv-count))\n of-type (integer 0 #.most-positive-fixnum)))\n\n(declaim (inline calc-inversion-number!))\n(defun calc-inversion-number! (vector predicate &key (start 0) end)\n \"Calculates the inversion number of VECTOR w.r.t. the strict order\nPREDICATE. This function sorts VECTOR as a side effect.\"\n (declare (vector vector)\n (function predicate))\n (let ((end (or end (length vector))))\n (declare ((mod #.array-total-size-limit) start end))\n (assert (<= start end))\n (let ((buffer (init-vector vector)))\n (symbol-macrolet ((vec1 vector) (vec2 buffer))\n (labels ((recurse (l r merge-to-vec1-p)\n (declare (optimize (safety 0))\n ((mod #.array-total-size-limit) l r))\n (cond ((= l r) 0)\n ((and (<= (- r l) 8) merge-to-vec1-p)\n (%calc-by-bubble-sort! vec1 predicate l r))\n (t\n (let ((mid (floor (+ l r) 2)))\n (with-fixnum+\n (+ (recurse l mid (not merge-to-vec1-p))\n (recurse mid r (not merge-to-vec1-p))\n (if merge-to-vec1-p\n (%merge-count l mid r vec2 vec1 predicate)\n (%merge-count l mid r vec1 vec2 predicate)))))))))\n (recurse start end t))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the fixnum (* result 10))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'int32))\n (cumul (make-array (1+ n) :element-type 'fixnum :initial-element 0)))\n (declare (uint31 n k))\n (dotimes (i n)\n (setf (aref as i) (- (read-fixnum) k))\n (setf (aref cumul (1+ i)) (+ (aref cumul i) (aref as i))))\n (println (- (floor (* n (+ n 1)) 2)\n (calc-inversion-number! cumul #'<)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1554446185, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03703.html", "problem_id": "p03703", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03703/input.txt", "sample_output_relpath": "derived/input_output/data/p03703/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03703/Lisp/s428238086.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s428238086", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Calculates inversion number by merge sort\n;;;\n\n;; Introduce INIT-VECTOR for better type-propagation on SBCL\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:defknown init-vector (vector)\n vector (sb-c:flushable)\n :overwrite-fndb-silently t)\n\n (sb-c:defoptimizer (init-vector sb-c:derive-type) ((template))\n (let* ((template-type (sb-c::lvar-type template))\n (spec `(,(if (sb-kernel:array-type-complexp template-type) 'array 'simple-array)\n ,(sb-kernel:type-specifier (sb-kernel:array-type-element-type template-type))\n (*))))\n (sb-c::careful-specifier-type spec))))\n\n(defun init-vector (template)\n \"Returns a newly initialized vector of the same type as TEMPLATE vector with\nSIZE.\"\n (declare (optimize (speed 3)))\n (make-array (length template) :element-type (array-element-type template)))\n\n(declaim (inline %merge-count))\n(defun %merge-count (l mid r source-vec dest-vec predicate)\n (declare ((mod #.array-total-size-limit) l mid r)\n (function predicate))\n (loop with count of-type (integer 0 #.most-positive-fixnum) = 0\n with i = l\n with j = mid\n for idx from l\n when (= i mid)\n do (loop for j from j below r\n for idx from idx\n do (setf (aref dest-vec idx)\n (aref source-vec j))\n finally (return-from %merge-count count))\n when (= j r)\n do (loop for i from i below mid\n for idx from idx\n do (setf (aref dest-vec idx)\n (aref source-vec i))\n finally (return-from %merge-count count))\n do (if (funcall predicate\n (aref source-vec j)\n (aref source-vec i))\n (setf (aref dest-vec idx) (aref source-vec j)\n j (1+ j)\n count (+ count (- mid i)))\n (setf (aref dest-vec idx) (aref source-vec i)\n i (1+ i)))))\n\n(defmacro with-fixnum+ (form)\n (let ((fixnum+ '(integer 0 #.most-positive-fixnum)))\n `(the ,fixnum+\n ,(reduce (lambda (f1 f2)`(,(car form)\n (the ,fixnum+ ,f1)\n (the ,fixnum+ ,f2)))\n\t (cdr form)))))\n\n(declaim (inline %calc-by-bubble-sort!))\n(defun %calc-by-bubble-sort! (vec predicate l r)\n (declare (function predicate)\n ((mod #.array-total-size-limit) l r))\n (loop for end from r above l\n sum (loop with inv-count of-type (integer 0 #.most-positive-fixnum) = 0\n for i from l below (- end 1)\n do (when (funcall predicate (aref vec (+ i 1)) (aref vec i))\n (rotatef (aref vec i) (aref vec (+ i 1)))\n (incf inv-count))\n finally (return inv-count))\n of-type (integer 0 #.most-positive-fixnum)))\n\n(declaim (inline calc-inversion-number!))\n(defun calc-inversion-number! (vector predicate &key (start 0) end)\n \"Calculates the inversion number of VECTOR w.r.t. the strict order\nPREDICATE. This function sorts VECTOR as a side effect.\"\n (declare (vector vector)\n (function predicate))\n (let ((end (or end (length vector))))\n (declare ((mod #.array-total-size-limit) start end))\n (assert (<= start end))\n (let ((buffer (init-vector vector)))\n (symbol-macrolet ((vec1 vector) (vec2 buffer))\n (labels ((recurse (l r merge-to-vec1-p)\n (declare (optimize (safety 0))\n ((mod #.array-total-size-limit) l r))\n (cond ((= l r) 0)\n ((and (<= (- r l) 8) merge-to-vec1-p)\n (%calc-by-bubble-sort! vec1 predicate l r))\n (t\n (let ((mid (floor (+ l r) 2)))\n (with-fixnum+\n (+ (recurse l mid (not merge-to-vec1-p))\n (recurse mid r (not merge-to-vec1-p))\n (if merge-to-vec1-p\n (%merge-count l mid r vec2 vec1 predicate)\n (%merge-count l mid r vec1 vec2 predicate)))))))))\n (recurse start end t))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the fixnum (* result 10))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'int32))\n (cumul (make-array (1+ n) :element-type 'fixnum :initial-element 0)))\n (declare (uint31 n k))\n (dotimes (i n)\n (setf (aref as i) (- (read-fixnum) k))\n (setf (aref cumul (1+ i)) (+ (aref cumul i) (aref as i))))\n (println (- (floor (* n (+ n 1)) 2)\n (calc-inversion-number! cumul #'<)))))\n\n#-swank(main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nYou are given an integer sequence of length N, a = {a_1, a_2, …, a_N}, and an integer K.\n\na has N(N+1)/2 non-empty contiguous subsequences, {a_l, a_{l+1}, …, a_r} (1 ≤ l ≤ r ≤ N). Among them, how many have an arithmetic mean that is greater than or equal to K?\n\nConstraints\n\nAll input values are integers.\n\n1 ≤ N ≤ 2 \\times 10^5\n\n1 ≤ K ≤ 10^9\n\n1 ≤ a_i ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\na_1\na_2\n:\na_N\n\nOutput\n\nPrint the number of the non-empty contiguous subsequences with an arithmetic mean that is greater than or equal to K.\n\nSample Input 1\n\n3 6\n7\n5\n7\n\nSample Output 1\n\n5\n\nAll the non-empty contiguous subsequences of a are listed below:\n\n{a_1} = {7}\n\n{a_1, a_2} = {7, 5}\n\n{a_1, a_2, a_3} = {7, 5, 7}\n\n{a_2} = {5}\n\n{a_2, a_3} = {5, 7}\n\n{a_3} = {7}\n\nTheir means are 7, 6, 19/3, 5, 6 and 7, respectively, and five among them are 6 or greater. Note that {a_1} and {a_3} are indistinguishable by the values of their elements, but we count them individually.\n\nSample Input 2\n\n1 2\n1\n\nSample Output 2\n\n0\n\nSample Input 3\n\n7 26\n10\n20\n30\n40\n30\n20\n10\n\nSample Output 3\n\n13", "sample_input": "3 6\n7\n5\n7\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03703", "source_text": "Score : 600 points\n\nProblem Statement\n\nYou are given an integer sequence of length N, a = {a_1, a_2, …, a_N}, and an integer K.\n\na has N(N+1)/2 non-empty contiguous subsequences, {a_l, a_{l+1}, …, a_r} (1 ≤ l ≤ r ≤ N). Among them, how many have an arithmetic mean that is greater than or equal to K?\n\nConstraints\n\nAll input values are integers.\n\n1 ≤ N ≤ 2 \\times 10^5\n\n1 ≤ K ≤ 10^9\n\n1 ≤ a_i ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\na_1\na_2\n:\na_N\n\nOutput\n\nPrint the number of the non-empty contiguous subsequences with an arithmetic mean that is greater than or equal to K.\n\nSample Input 1\n\n3 6\n7\n5\n7\n\nSample Output 1\n\n5\n\nAll the non-empty contiguous subsequences of a are listed below:\n\n{a_1} = {7}\n\n{a_1, a_2} = {7, 5}\n\n{a_1, a_2, a_3} = {7, 5, 7}\n\n{a_2} = {5}\n\n{a_2, a_3} = {5, 7}\n\n{a_3} = {7}\n\nTheir means are 7, 6, 19/3, 5, 6 and 7, respectively, and five among them are 6 or greater. Note that {a_1} and {a_3} are indistinguishable by the values of their elements, but we count them individually.\n\nSample Input 2\n\n1 2\n1\n\nSample Output 2\n\n0\n\nSample Input 3\n\n7 26\n10\n20\n30\n40\n30\n20\n10\n\nSample Output 3\n\n13", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7073, "cpu_time_ms": 299, "memory_kb": 37352}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s661860355", "group_id": "codeNet:p03703", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n\n(defconstant +op-identity+ 0)\n\n(declaim (inline op))\n(defun op (x y)\n (+ x y))\n\n(declaim (inline treap-order))\n(defun treap-order (x y)\n (< x y))\n\n;; Treap with explicit key\n(defstruct (treap (:constructor make-treap (key priority value accumulator &key left right))\n (:copier nil)\n (:conc-name %treap-))\n (key 0 :type fixnum)\n (value nil :type fixnum)\n (accumulator nil :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (left nil :type (or null treap))\n (right nil :type (or null treap)))\n\n(declaim (inline treap-accumulator))\n(defun treap-accumulator (treap)\n (declare ((or null treap) treap))\n (if (null treap)\n +op-identity+\n (%treap-accumulator treap)))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (treap)\n (declare (treap treap))\n (setf (%treap-accumulator treap)\n (if (%treap-left treap)\n (if (%treap-right treap)\n (op (op (%treap-accumulator (%treap-left treap))\n (%treap-value treap))\n (%treap-accumulator (%treap-right treap)))\n (op (%treap-accumulator (%treap-left treap))\n (%treap-value treap)))\n (if (%treap-right treap)\n (op (%treap-value treap)\n (%treap-accumulator (%treap-right treap)))\n (%treap-value treap)))))\n\n(declaim (inline force-self))\n(defun force-self (treap)\n (declare (treap treap))\n (update-accumulator treap))\n\n(declaim (ftype (function * (values (or null treap) (or null treap) &optional)) treap-split))\n(defun treap-split (key treap)\n \"Destructively splits the TREAP with reference to KEY and returns two treaps,\nthe smaller sub-treap (< KEY) and the larger one (>= KEY).\"\n (declare #.OPT\n ((or null treap) treap))\n (cond ((null treap)\n (values nil nil))\n ((funcall #'treap-order (%treap-key treap) key)\n (multiple-value-bind (left right)\n (treap-split key (%treap-right treap))\n (setf (%treap-right treap) left)\n (force-self treap)\n (values treap right)))\n (t\n (multiple-value-bind (left right)\n (treap-split key (%treap-left treap))\n (setf (%treap-left treap) right)\n (force-self treap)\n (values left treap)))))\n\n(declaim (inline treap-insert))\n(defun treap-insert (key value treap)\n \"Destructively inserts KEY into TREAP and returns the result treap. You cannot\nrely on the side effect. Use the returned value.\n\nThe behavior is undefined when duplicated keys are inserted.\"\n (declare ((or null treap) treap))\n (labels ((recur (node treap)\n (declare (treap node))\n (cond ((null treap) node)\n ((> (%treap-priority node) (%treap-priority treap))\n (setf (values (%treap-left node) (%treap-right node))\n (treap-split (%treap-key node) treap))\n (force-self node)\n node)\n (t\n (if (funcall #'treap-order (%treap-key node) (%treap-key treap))\n (setf (%treap-left treap)\n (recur node (%treap-left treap)))\n (setf (%treap-right treap)\n (recur node (%treap-right treap))))\n (force-self treap)\n treap))))\n (recur (make-treap key (random most-positive-fixnum) value value) treap)))\n\n(declaim (inline treap-ensure-key))\n(defun treap-ensure-key (key value treap &key if-exists)\n \"IF-EXISTS := nil | function\n\nEnsures that TREAP contains KEY and assigns VALUE to it if IF-EXISTS is null. If\nIF-EXISTS is function and TREAP contains KEY, TREAP-ENSURE-KEY updates the value\nby the function instead of overwriting it with VALUE.\"\n (declare ((or null treap) treap))\n (labels ((find-and-update (treap)\n ;; Updates value and returns T if KEY exists\n (cond ((null treap) nil)\n ((funcall #'treap-order key (%treap-key treap))\n (when (find-and-update (%treap-left treap))\n (force-self treap)\n t))\n ((funcall #'treap-order (%treap-key treap) key)\n (when (find-and-update (%treap-right treap))\n (force-self treap)\n t))\n (t (setf (%treap-value treap)\n (if if-exists\n (funcall if-exists (%treap-value treap))\n value))\n (force-self treap)\n t))))\n (if (find-and-update treap)\n treap\n (treap-insert key value treap))))\n\n(defun treap-merge (left right)\n \"Destructively merges two treaps. Assumes that all keys of LEFT are smaller\n (or larger, depending on the order) than those of RIGHT.\"\n (declare #.OPT\n ((or null treap) left right))\n (cond ((null left) right)\n ((null right) left)\n ((> (%treap-priority left) (%treap-priority right))\n (setf (%treap-right left)\n (treap-merge (%treap-right left) right))\n (force-self left)\n left)\n (t\n (setf (%treap-left right)\n (treap-merge left (%treap-left right)))\n (force-self right)\n right)))\n\n;; FIXME: might be problematic when two priorities collide.\n(declaim (inline treap-query))\n(defun treap-query (treap &key left right)\n \"Queries the sum of the half-open interval specified by the keys: [LEFT,\nRIGHT). If LEFT (RIGHT) is not given, it is assumed to be -inf (+inf).\"\n (if (null left)\n (if (null right)\n (treap-accumulator treap)\n (multiple-value-bind (treap-0-r treap-r-n)\n (treap-split right treap)\n (prog1 (treap-accumulator treap-0-r)\n (treap-merge treap-0-r treap-r-n))))\n (if (null right)\n (multiple-value-bind (treap-0-l treap-l-n)\n (treap-split left treap)\n (prog1 (treap-accumulator treap-l-n)\n (treap-merge treap-0-l treap-l-n)))\n (progn\n (assert (not (funcall #'treap-order right left)))\n (multiple-value-bind (treap-0-l treap-l-n)\n (treap-split left treap)\n (multiple-value-bind (treap-l-r treap-r-n)\n (treap-split right treap-l-n)\n (prog1 (treap-accumulator treap-l-r)\n (treap-merge treap-0-l (treap-merge treap-l-r treap-r-n)))))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the fixnum (* result 10))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'int32))\n (cumul (make-array (1+ n) :element-type 'fixnum :initial-element 0))\n treap)\n (declare (uint31 n k))\n (dotimes (i n)\n (setf (aref as i) (- (read-fixnum) k))\n (setf (aref cumul (1+ i)) (+ (aref cumul i) (aref as i))))\n (println\n (loop for i to n\n sum (treap-query treap :right (1+ (aref cumul i)))\n of-type fixnum\n do (setf treap (treap-ensure-key (aref cumul i) 1 treap :if-exists #'1+))))))\n\n#-swank(main)\n\n", "language": "Lisp", "metadata": {"date": 1554374674, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03703.html", "problem_id": "p03703", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03703/input.txt", "sample_output_relpath": "derived/input_output/data/p03703/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03703/Lisp/s661860355.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s661860355", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n\n(defconstant +op-identity+ 0)\n\n(declaim (inline op))\n(defun op (x y)\n (+ x y))\n\n(declaim (inline treap-order))\n(defun treap-order (x y)\n (< x y))\n\n;; Treap with explicit key\n(defstruct (treap (:constructor make-treap (key priority value accumulator &key left right))\n (:copier nil)\n (:conc-name %treap-))\n (key 0 :type fixnum)\n (value nil :type fixnum)\n (accumulator nil :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (left nil :type (or null treap))\n (right nil :type (or null treap)))\n\n(declaim (inline treap-accumulator))\n(defun treap-accumulator (treap)\n (declare ((or null treap) treap))\n (if (null treap)\n +op-identity+\n (%treap-accumulator treap)))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (treap)\n (declare (treap treap))\n (setf (%treap-accumulator treap)\n (if (%treap-left treap)\n (if (%treap-right treap)\n (op (op (%treap-accumulator (%treap-left treap))\n (%treap-value treap))\n (%treap-accumulator (%treap-right treap)))\n (op (%treap-accumulator (%treap-left treap))\n (%treap-value treap)))\n (if (%treap-right treap)\n (op (%treap-value treap)\n (%treap-accumulator (%treap-right treap)))\n (%treap-value treap)))))\n\n(declaim (inline force-self))\n(defun force-self (treap)\n (declare (treap treap))\n (update-accumulator treap))\n\n(declaim (ftype (function * (values (or null treap) (or null treap) &optional)) treap-split))\n(defun treap-split (key treap)\n \"Destructively splits the TREAP with reference to KEY and returns two treaps,\nthe smaller sub-treap (< KEY) and the larger one (>= KEY).\"\n (declare #.OPT\n ((or null treap) treap))\n (cond ((null treap)\n (values nil nil))\n ((funcall #'treap-order (%treap-key treap) key)\n (multiple-value-bind (left right)\n (treap-split key (%treap-right treap))\n (setf (%treap-right treap) left)\n (force-self treap)\n (values treap right)))\n (t\n (multiple-value-bind (left right)\n (treap-split key (%treap-left treap))\n (setf (%treap-left treap) right)\n (force-self treap)\n (values left treap)))))\n\n(declaim (inline treap-insert))\n(defun treap-insert (key value treap)\n \"Destructively inserts KEY into TREAP and returns the result treap. You cannot\nrely on the side effect. Use the returned value.\n\nThe behavior is undefined when duplicated keys are inserted.\"\n (declare ((or null treap) treap))\n (labels ((recur (node treap)\n (declare (treap node))\n (cond ((null treap) node)\n ((> (%treap-priority node) (%treap-priority treap))\n (setf (values (%treap-left node) (%treap-right node))\n (treap-split (%treap-key node) treap))\n (force-self node)\n node)\n (t\n (if (funcall #'treap-order (%treap-key node) (%treap-key treap))\n (setf (%treap-left treap)\n (recur node (%treap-left treap)))\n (setf (%treap-right treap)\n (recur node (%treap-right treap))))\n (force-self treap)\n treap))))\n (recur (make-treap key (random most-positive-fixnum) value value) treap)))\n\n(declaim (inline treap-ensure-key))\n(defun treap-ensure-key (key value treap &key if-exists)\n \"IF-EXISTS := nil | function\n\nEnsures that TREAP contains KEY and assigns VALUE to it if IF-EXISTS is null. If\nIF-EXISTS is function and TREAP contains KEY, TREAP-ENSURE-KEY updates the value\nby the function instead of overwriting it with VALUE.\"\n (declare ((or null treap) treap))\n (labels ((find-and-update (treap)\n ;; Updates value and returns T if KEY exists\n (cond ((null treap) nil)\n ((funcall #'treap-order key (%treap-key treap))\n (when (find-and-update (%treap-left treap))\n (force-self treap)\n t))\n ((funcall #'treap-order (%treap-key treap) key)\n (when (find-and-update (%treap-right treap))\n (force-self treap)\n t))\n (t (setf (%treap-value treap)\n (if if-exists\n (funcall if-exists (%treap-value treap))\n value))\n (force-self treap)\n t))))\n (if (find-and-update treap)\n treap\n (treap-insert key value treap))))\n\n(defun treap-merge (left right)\n \"Destructively merges two treaps. Assumes that all keys of LEFT are smaller\n (or larger, depending on the order) than those of RIGHT.\"\n (declare #.OPT\n ((or null treap) left right))\n (cond ((null left) right)\n ((null right) left)\n ((> (%treap-priority left) (%treap-priority right))\n (setf (%treap-right left)\n (treap-merge (%treap-right left) right))\n (force-self left)\n left)\n (t\n (setf (%treap-left right)\n (treap-merge left (%treap-left right)))\n (force-self right)\n right)))\n\n;; FIXME: might be problematic when two priorities collide.\n(declaim (inline treap-query))\n(defun treap-query (treap &key left right)\n \"Queries the sum of the half-open interval specified by the keys: [LEFT,\nRIGHT). If LEFT (RIGHT) is not given, it is assumed to be -inf (+inf).\"\n (if (null left)\n (if (null right)\n (treap-accumulator treap)\n (multiple-value-bind (treap-0-r treap-r-n)\n (treap-split right treap)\n (prog1 (treap-accumulator treap-0-r)\n (treap-merge treap-0-r treap-r-n))))\n (if (null right)\n (multiple-value-bind (treap-0-l treap-l-n)\n (treap-split left treap)\n (prog1 (treap-accumulator treap-l-n)\n (treap-merge treap-0-l treap-l-n)))\n (progn\n (assert (not (funcall #'treap-order right left)))\n (multiple-value-bind (treap-0-l treap-l-n)\n (treap-split left treap)\n (multiple-value-bind (treap-l-r treap-r-n)\n (treap-split right treap-l-n)\n (prog1 (treap-accumulator treap-l-r)\n (treap-merge treap-0-l (treap-merge treap-l-r treap-r-n)))))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the fixnum (* result 10))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'int32))\n (cumul (make-array (1+ n) :element-type 'fixnum :initial-element 0))\n treap)\n (declare (uint31 n k))\n (dotimes (i n)\n (setf (aref as i) (- (read-fixnum) k))\n (setf (aref cumul (1+ i)) (+ (aref cumul i) (aref as i))))\n (println\n (loop for i to n\n sum (treap-query treap :right (1+ (aref cumul i)))\n of-type fixnum\n do (setf treap (treap-ensure-key (aref cumul i) 1 treap :if-exists #'1+))))))\n\n#-swank(main)\n\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nYou are given an integer sequence of length N, a = {a_1, a_2, …, a_N}, and an integer K.\n\na has N(N+1)/2 non-empty contiguous subsequences, {a_l, a_{l+1}, …, a_r} (1 ≤ l ≤ r ≤ N). Among them, how many have an arithmetic mean that is greater than or equal to K?\n\nConstraints\n\nAll input values are integers.\n\n1 ≤ N ≤ 2 \\times 10^5\n\n1 ≤ K ≤ 10^9\n\n1 ≤ a_i ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\na_1\na_2\n:\na_N\n\nOutput\n\nPrint the number of the non-empty contiguous subsequences with an arithmetic mean that is greater than or equal to K.\n\nSample Input 1\n\n3 6\n7\n5\n7\n\nSample Output 1\n\n5\n\nAll the non-empty contiguous subsequences of a are listed below:\n\n{a_1} = {7}\n\n{a_1, a_2} = {7, 5}\n\n{a_1, a_2, a_3} = {7, 5, 7}\n\n{a_2} = {5}\n\n{a_2, a_3} = {5, 7}\n\n{a_3} = {7}\n\nTheir means are 7, 6, 19/3, 5, 6 and 7, respectively, and five among them are 6 or greater. Note that {a_1} and {a_3} are indistinguishable by the values of their elements, but we count them individually.\n\nSample Input 2\n\n1 2\n1\n\nSample Output 2\n\n0\n\nSample Input 3\n\n7 26\n10\n20\n30\n40\n30\n20\n10\n\nSample Output 3\n\n13", "sample_input": "3 6\n7\n5\n7\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03703", "source_text": "Score : 600 points\n\nProblem Statement\n\nYou are given an integer sequence of length N, a = {a_1, a_2, …, a_N}, and an integer K.\n\na has N(N+1)/2 non-empty contiguous subsequences, {a_l, a_{l+1}, …, a_r} (1 ≤ l ≤ r ≤ N). Among them, how many have an arithmetic mean that is greater than or equal to K?\n\nConstraints\n\nAll input values are integers.\n\n1 ≤ N ≤ 2 \\times 10^5\n\n1 ≤ K ≤ 10^9\n\n1 ≤ a_i ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\na_1\na_2\n:\na_N\n\nOutput\n\nPrint the number of the non-empty contiguous subsequences with an arithmetic mean that is greater than or equal to K.\n\nSample Input 1\n\n3 6\n7\n5\n7\n\nSample Output 1\n\n5\n\nAll the non-empty contiguous subsequences of a are listed below:\n\n{a_1} = {7}\n\n{a_1, a_2} = {7, 5}\n\n{a_1, a_2, a_3} = {7, 5, 7}\n\n{a_2} = {5}\n\n{a_2, a_3} = {5, 7}\n\n{a_3} = {7}\n\nTheir means are 7, 6, 19/3, 5, 6 and 7, respectively, and five among them are 6 or greater. Note that {a_1} and {a_3} are indistinguishable by the values of their elements, but we count them individually.\n\nSample Input 2\n\n1 2\n1\n\nSample Output 2\n\n0\n\nSample Input 3\n\n7 26\n10\n20\n30\n40\n30\n20\n10\n\nSample Output 3\n\n13", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9463, "cpu_time_ms": 400, "memory_kb": 43624}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s759968069", "group_id": "codeNet:p03703", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n\n(defconstant +op-identity+ 0)\n(declaim (inline op))\n(defun op (x y)\n (+ x y))\n\n;; Treap with explicit key\n(defstruct (treap (:constructor make-treap (key priority value accumulator &key left right))\n (:copier nil)\n (:conc-name %treap-))\n (key 0 :type fixnum)\n (value nil :type fixnum)\n (accumulator nil :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (left nil :type (or null treap))\n (right nil :type (or null treap)))\n\n(declaim (inline treap-accumulator))\n(defun treap-accumulator (treap)\n (declare ((or null treap) treap))\n (if (null treap)\n +op-identity+\n (%treap-accumulator treap)))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (treap)\n (declare (treap treap))\n (setf (%treap-accumulator treap)\n (if (%treap-left treap)\n (if (%treap-right treap)\n (op (op (%treap-accumulator (%treap-left treap))\n (%treap-value treap))\n (%treap-accumulator (%treap-right treap)))\n (op (%treap-accumulator (%treap-left treap))\n (%treap-value treap)))\n (if (%treap-right treap)\n (op (%treap-value treap)\n (%treap-accumulator (%treap-right treap)))\n (%treap-value treap)))))\n\n(declaim (inline force-self))\n(defun force-self (treap)\n (declare (treap treap))\n (update-accumulator treap))\n\n(declaim (ftype (function * (values (or null treap) (or null treap) &optional)) treap-split))\n(defun treap-split (key treap &key (test #'<))\n \"Destructively splits the TREAP with reference to KEY and returns two treaps,\nthe smaller sub-treap (< KEY) and the larger one (>= KEY).\"\n (declare (function test)\n ((or null treap) treap))\n (cond ((null treap)\n (values nil nil))\n ((funcall test (%treap-key treap) key)\n (multiple-value-bind (left right)\n (treap-split key (%treap-right treap) :test test)\n (setf (%treap-right treap) left)\n (force-self treap)\n (values treap right)))\n (t\n (multiple-value-bind (left right)\n (treap-split key (%treap-left treap) :test test)\n (setf (%treap-left treap) right)\n (force-self treap)\n (values left treap)))))\n\n(declaim (inline treap-insert))\n(defun treap-insert (key value treap &key (test #'<))\n \"Destructively inserts KEY into TREAP and returns the result treap. You cannot\nrely on the side effect. Use the returned value.\n\nThe behavior is undefined when duplicated keys are inserted.\"\n (declare ((or null treap) treap)\n (function test))\n (labels ((recur (node treap)\n (declare (treap node))\n (cond ((null treap) node)\n ((> (%treap-priority node) (%treap-priority treap))\n (setf (values (%treap-left node) (%treap-right node))\n (treap-split (%treap-key node) treap :test test))\n (force-self node)\n node)\n (t\n (if (funcall test (%treap-key node) (%treap-key treap))\n (setf (%treap-left treap)\n (recur node (%treap-left treap)))\n (setf (%treap-right treap)\n (recur node (%treap-right treap))))\n (force-self treap)\n treap))))\n (recur (make-treap key (random most-positive-fixnum) value value) treap)))\n\n(declaim (inline treap-ensure-key))\n(defun treap-ensure-key (key value treap &key (test #'<) if-exists)\n \"IF-EXISTS := nil | function\n\nEnsures that TREAP contains KEY and assigns VALUE to it If IF-EXISTS is null. If\nIF-EXISTS is function and TREAP contains KEY, TREAP-ENSURE-KEY updates the value\nby the function instead of overwriting it with VALUE.\"\n (declare (function test)\n ((or null treap) treap))\n (labels ((find-and-update (treap)\n ;; Updates value and returns T if KEY exists\n (cond ((null treap) nil)\n ((funcall test key (%treap-key treap))\n (when (find-and-update (%treap-left treap))\n (force-self treap)\n t))\n ((funcall test (%treap-key treap) key)\n (when (find-and-update (%treap-right treap))\n (force-self treap)\n t))\n (t (setf (%treap-value treap)\n (if if-exists\n (funcall if-exists (%treap-value treap))\n value))\n (force-self treap)\n t))))\n (if (find-and-update treap)\n treap\n (treap-insert key value treap :test test))))\n\n(defun treap-merge (left right)\n \"Destructively merges two treaps. Assumes that all keys of LEFT are smaller\n (or larger, depending on the order) than those of RIGHT.\"\n (declare ((or null treap) left right))\n (cond ((null left) right)\n ((null right) left)\n ((> (%treap-priority left) (%treap-priority right))\n (setf (%treap-right left)\n (treap-merge (%treap-right left) right))\n (force-self left)\n left)\n (t\n (setf (%treap-left right)\n (treap-merge left (%treap-left right)))\n (force-self right)\n right)))\n\n;; FIXME: might be problematic when two priorities collide.\n(declaim (inline treap-query))\n(defun treap-query (treap &key left right (test #'<))\n \"Queries the sum of the half-open interval specified by the keys: [LEFT,\nRIGHT). If LEFT (RIGHT) is not given, it is assumed to be -inf (+inf).\"\n (if (null left)\n (if (null right)\n (treap-accumulator treap)\n (multiple-value-bind (treap-0-r treap-r-n)\n (treap-split right treap :test test)\n (prog1 (treap-accumulator treap-0-r)\n (treap-merge treap-0-r treap-r-n))))\n (if (null right)\n (multiple-value-bind (treap-0-l treap-l-n)\n (treap-split left treap :test test)\n (prog1 (treap-accumulator treap-l-n)\n (treap-merge treap-0-l treap-l-n)))\n (progn\n (assert (not (funcall test right left)))\n (multiple-value-bind (treap-0-l treap-l-n)\n (treap-split left treap :test test)\n (multiple-value-bind (treap-l-r treap-r-n)\n (treap-split right treap-l-n :test test)\n (prog1 (treap-accumulator treap-l-r)\n (treap-merge treap-0-l (treap-merge treap-l-r treap-r-n)))))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the fixnum (* result 10))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'int32))\n (cumul (make-array (1+ n) :element-type 'fixnum :initial-element 0))\n treap)\n (declare (uint31 n k))\n (dotimes (i n)\n (setf (aref as i) (- (read-fixnum) k))\n (setf (aref cumul (1+ i)) (+ (aref cumul i) (aref as i))))\n (println\n (loop for i to n\n sum (treap-query treap :right (1+ (aref cumul i)))\n of-type fixnum\n do (setf treap (treap-ensure-key (aref cumul i) 1 treap :if-exists #'1+))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1554373958, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03703.html", "problem_id": "p03703", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03703/input.txt", "sample_output_relpath": "derived/input_output/data/p03703/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03703/Lisp/s759968069.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s759968069", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n\n(defconstant +op-identity+ 0)\n(declaim (inline op))\n(defun op (x y)\n (+ x y))\n\n;; Treap with explicit key\n(defstruct (treap (:constructor make-treap (key priority value accumulator &key left right))\n (:copier nil)\n (:conc-name %treap-))\n (key 0 :type fixnum)\n (value nil :type fixnum)\n (accumulator nil :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (left nil :type (or null treap))\n (right nil :type (or null treap)))\n\n(declaim (inline treap-accumulator))\n(defun treap-accumulator (treap)\n (declare ((or null treap) treap))\n (if (null treap)\n +op-identity+\n (%treap-accumulator treap)))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (treap)\n (declare (treap treap))\n (setf (%treap-accumulator treap)\n (if (%treap-left treap)\n (if (%treap-right treap)\n (op (op (%treap-accumulator (%treap-left treap))\n (%treap-value treap))\n (%treap-accumulator (%treap-right treap)))\n (op (%treap-accumulator (%treap-left treap))\n (%treap-value treap)))\n (if (%treap-right treap)\n (op (%treap-value treap)\n (%treap-accumulator (%treap-right treap)))\n (%treap-value treap)))))\n\n(declaim (inline force-self))\n(defun force-self (treap)\n (declare (treap treap))\n (update-accumulator treap))\n\n(declaim (ftype (function * (values (or null treap) (or null treap) &optional)) treap-split))\n(defun treap-split (key treap &key (test #'<))\n \"Destructively splits the TREAP with reference to KEY and returns two treaps,\nthe smaller sub-treap (< KEY) and the larger one (>= KEY).\"\n (declare (function test)\n ((or null treap) treap))\n (cond ((null treap)\n (values nil nil))\n ((funcall test (%treap-key treap) key)\n (multiple-value-bind (left right)\n (treap-split key (%treap-right treap) :test test)\n (setf (%treap-right treap) left)\n (force-self treap)\n (values treap right)))\n (t\n (multiple-value-bind (left right)\n (treap-split key (%treap-left treap) :test test)\n (setf (%treap-left treap) right)\n (force-self treap)\n (values left treap)))))\n\n(declaim (inline treap-insert))\n(defun treap-insert (key value treap &key (test #'<))\n \"Destructively inserts KEY into TREAP and returns the result treap. You cannot\nrely on the side effect. Use the returned value.\n\nThe behavior is undefined when duplicated keys are inserted.\"\n (declare ((or null treap) treap)\n (function test))\n (labels ((recur (node treap)\n (declare (treap node))\n (cond ((null treap) node)\n ((> (%treap-priority node) (%treap-priority treap))\n (setf (values (%treap-left node) (%treap-right node))\n (treap-split (%treap-key node) treap :test test))\n (force-self node)\n node)\n (t\n (if (funcall test (%treap-key node) (%treap-key treap))\n (setf (%treap-left treap)\n (recur node (%treap-left treap)))\n (setf (%treap-right treap)\n (recur node (%treap-right treap))))\n (force-self treap)\n treap))))\n (recur (make-treap key (random most-positive-fixnum) value value) treap)))\n\n(declaim (inline treap-ensure-key))\n(defun treap-ensure-key (key value treap &key (test #'<) if-exists)\n \"IF-EXISTS := nil | function\n\nEnsures that TREAP contains KEY and assigns VALUE to it If IF-EXISTS is null. If\nIF-EXISTS is function and TREAP contains KEY, TREAP-ENSURE-KEY updates the value\nby the function instead of overwriting it with VALUE.\"\n (declare (function test)\n ((or null treap) treap))\n (labels ((find-and-update (treap)\n ;; Updates value and returns T if KEY exists\n (cond ((null treap) nil)\n ((funcall test key (%treap-key treap))\n (when (find-and-update (%treap-left treap))\n (force-self treap)\n t))\n ((funcall test (%treap-key treap) key)\n (when (find-and-update (%treap-right treap))\n (force-self treap)\n t))\n (t (setf (%treap-value treap)\n (if if-exists\n (funcall if-exists (%treap-value treap))\n value))\n (force-self treap)\n t))))\n (if (find-and-update treap)\n treap\n (treap-insert key value treap :test test))))\n\n(defun treap-merge (left right)\n \"Destructively merges two treaps. Assumes that all keys of LEFT are smaller\n (or larger, depending on the order) than those of RIGHT.\"\n (declare ((or null treap) left right))\n (cond ((null left) right)\n ((null right) left)\n ((> (%treap-priority left) (%treap-priority right))\n (setf (%treap-right left)\n (treap-merge (%treap-right left) right))\n (force-self left)\n left)\n (t\n (setf (%treap-left right)\n (treap-merge left (%treap-left right)))\n (force-self right)\n right)))\n\n;; FIXME: might be problematic when two priorities collide.\n(declaim (inline treap-query))\n(defun treap-query (treap &key left right (test #'<))\n \"Queries the sum of the half-open interval specified by the keys: [LEFT,\nRIGHT). If LEFT (RIGHT) is not given, it is assumed to be -inf (+inf).\"\n (if (null left)\n (if (null right)\n (treap-accumulator treap)\n (multiple-value-bind (treap-0-r treap-r-n)\n (treap-split right treap :test test)\n (prog1 (treap-accumulator treap-0-r)\n (treap-merge treap-0-r treap-r-n))))\n (if (null right)\n (multiple-value-bind (treap-0-l treap-l-n)\n (treap-split left treap :test test)\n (prog1 (treap-accumulator treap-l-n)\n (treap-merge treap-0-l treap-l-n)))\n (progn\n (assert (not (funcall test right left)))\n (multiple-value-bind (treap-0-l treap-l-n)\n (treap-split left treap :test test)\n (multiple-value-bind (treap-l-r treap-r-n)\n (treap-split right treap-l-n :test test)\n (prog1 (treap-accumulator treap-l-r)\n (treap-merge treap-0-l (treap-merge treap-l-r treap-r-n)))))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the fixnum (* result 10))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'int32))\n (cumul (make-array (1+ n) :element-type 'fixnum :initial-element 0))\n treap)\n (declare (uint31 n k))\n (dotimes (i n)\n (setf (aref as i) (- (read-fixnum) k))\n (setf (aref cumul (1+ i)) (+ (aref cumul i) (aref as i))))\n (println\n (loop for i to n\n sum (treap-query treap :right (1+ (aref cumul i)))\n of-type fixnum\n do (setf treap (treap-ensure-key (aref cumul i) 1 treap :if-exists #'1+))))))\n\n#-swank(main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nYou are given an integer sequence of length N, a = {a_1, a_2, …, a_N}, and an integer K.\n\na has N(N+1)/2 non-empty contiguous subsequences, {a_l, a_{l+1}, …, a_r} (1 ≤ l ≤ r ≤ N). Among them, how many have an arithmetic mean that is greater than or equal to K?\n\nConstraints\n\nAll input values are integers.\n\n1 ≤ N ≤ 2 \\times 10^5\n\n1 ≤ K ≤ 10^9\n\n1 ≤ a_i ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\na_1\na_2\n:\na_N\n\nOutput\n\nPrint the number of the non-empty contiguous subsequences with an arithmetic mean that is greater than or equal to K.\n\nSample Input 1\n\n3 6\n7\n5\n7\n\nSample Output 1\n\n5\n\nAll the non-empty contiguous subsequences of a are listed below:\n\n{a_1} = {7}\n\n{a_1, a_2} = {7, 5}\n\n{a_1, a_2, a_3} = {7, 5, 7}\n\n{a_2} = {5}\n\n{a_2, a_3} = {5, 7}\n\n{a_3} = {7}\n\nTheir means are 7, 6, 19/3, 5, 6 and 7, respectively, and five among them are 6 or greater. Note that {a_1} and {a_3} are indistinguishable by the values of their elements, but we count them individually.\n\nSample Input 2\n\n1 2\n1\n\nSample Output 2\n\n0\n\nSample Input 3\n\n7 26\n10\n20\n30\n40\n30\n20\n10\n\nSample Output 3\n\n13", "sample_input": "3 6\n7\n5\n7\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03703", "source_text": "Score : 600 points\n\nProblem Statement\n\nYou are given an integer sequence of length N, a = {a_1, a_2, …, a_N}, and an integer K.\n\na has N(N+1)/2 non-empty contiguous subsequences, {a_l, a_{l+1}, …, a_r} (1 ≤ l ≤ r ≤ N). Among them, how many have an arithmetic mean that is greater than or equal to K?\n\nConstraints\n\nAll input values are integers.\n\n1 ≤ N ≤ 2 \\times 10^5\n\n1 ≤ K ≤ 10^9\n\n1 ≤ a_i ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\na_1\na_2\n:\na_N\n\nOutput\n\nPrint the number of the non-empty contiguous subsequences with an arithmetic mean that is greater than or equal to K.\n\nSample Input 1\n\n3 6\n7\n5\n7\n\nSample Output 1\n\n5\n\nAll the non-empty contiguous subsequences of a are listed below:\n\n{a_1} = {7}\n\n{a_1, a_2} = {7, 5}\n\n{a_1, a_2, a_3} = {7, 5, 7}\n\n{a_2} = {5}\n\n{a_2, a_3} = {5, 7}\n\n{a_3} = {7}\n\nTheir means are 7, 6, 19/3, 5, 6 and 7, respectively, and five among them are 6 or greater. Note that {a_1} and {a_3} are indistinguishable by the values of their elements, but we count them individually.\n\nSample Input 2\n\n1 2\n1\n\nSample Output 2\n\n0\n\nSample Input 3\n\n7 26\n10\n20\n30\n40\n30\n20\n10\n\nSample Output 3\n\n13", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9537, "cpu_time_ms": 550, "memory_kb": 49768}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s589187393", "group_id": "codeNet:p03703", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; 1D BIT\n(defmacro define-bitree (name &key (operator '#'+) (identity 0) sum-type (order '#'>))\n \"OPERATOR := binary operator (on a commutative monoid)\nIDENTITY := object (identity element of the monoid)\nORDER := nil | strict comparison operator on the monoid\nSUM-TYPE := nil | type specifier\n\nDefines no structure; BIT is just a vector. Defines the three function:\n-UPDATE!, -SUM and COERCE-TO-!. In addition this macro defines\nthe bisection function -BISECT-LEFT if ORDER is specified. (Note that the\nlast function works only when the sequence of sums (VECTOR[0],\nVECTOR[0]+VECTOR[1], ...) is monotonous.)\n\nSUM-TYPE is used only for the type declaration: each sum\nVECTOR[i]+VECTOR[i+1]...+VECTOR[i+k] is declared to be this type. (The\nelement-type of vector itself doesn't need to be SUM-TYPE.)\"\n (let* ((name (string name))\n (fname-update (intern (format nil \"~A-UPDATE!\" name)))\n (fname-sum (intern (format nil \"~A-SUM\" name)))\n (fname-coerce (intern (format nil \"COERCE-TO-~A!\" name)))\n (fname-bisect (intern (format nil \"~A-BISECT-LEFT\" name))))\n `(progn\n (declaim (inline ,fname-update))\n (defun ,fname-update (bitree index delta)\n \"Destructively increments the vector: vector[INDEX] = vector[INDEX] +\nDELTA\"\n (let ((len (length bitree)))\n (do ((i index (logior i (+ i 1))))\n ((>= i len) bitree)\n (declare ((integer 0 #.most-positive-fixnum) i))\n (setf (aref bitree i)\n (funcall ,operator (aref bitree i) delta)))))\n\n (declaim (inline ,fname-sum))\n (defun ,fname-sum (bitree end)\n \"Returns the sum of prefix: vector[0] + ... + vector[END-1].\"\n (declare ((integer 0 #.most-positive-fixnum) end))\n (let ((res ,identity))\n ,@(when sum-type `((declare (type ,sum-type res))))\n (do ((i (- end 1) (- (logand i (+ i 1)) 1)))\n ((< i 0) res)\n (declare ((integer -1 #.most-positive-fixnum) i))\n (setf res (funcall ,operator res (aref bitree i))))))\n\n (declaim (inline ,fname-coerce))\n (defun ,fname-coerce (vector)\n \"Destructively constructs BIT from VECTOR.\"\n (loop with len = (length vector)\n for i below len\n for dest-i = (logior i (+ i 1))\n when (< dest-i len)\n do (setf (aref vector dest-i)\n (funcall ,operator (aref vector dest-i) (aref vector i)))\n finally (return vector)))\n\n ,@(when order\n `((declaim (inline ,fname-bisect))\n (defun ,fname-bisect (bitree value)\n \"Returns the smallest index that fulfills VECTOR[0]+ ... +\nVECTOR[index-1] >= VALUE. Returns the length of VECTOR if VECTOR[0]+\n... +VECTOR[END-1] > VALUE.\"\n (declare (vector bitree))\n (if (not (funcall ,order value ,identity))\n 0\n (let ((len (length bitree))\n (index+1 0)\n (cumul ,identity))\n (declare ((integer 0 #.most-positive-fixnum) index+1)\n ,@(when sum-type\n `((type ,sum-type cumul))))\n (do ((delta (ash 1 (- (integer-length len) 1))\n (ash delta -1)))\n ((zerop delta) index+1)\n (declare ((integer 0 #.most-positive-fixnum) delta))\n (let ((next-index (+ index+1 delta -1)))\n (when (< next-index len)\n (let ((next-cumul (funcall ,operator cumul (aref bitree next-index))))\n ,@(when sum-type\n `((declare (type ,sum-type next-cumul))))\n (when (funcall ,order value next-cumul)\n (setf cumul next-cumul)\n (incf index+1 delta))))))))))))))\n\n(define-bitree bitree\n :operator #'+\n :identity 0\n :sum-type fixnum)\n\n(declaim (inline make-reverse-lookup-table))\n(defun make-reverse-lookup-table (vector &key (test #'eql))\n \"Assigns each value of the (sorted) VECTOR of length n to the integers 0, ...,\nn-1.\"\n (let ((table (make-hash-table :test test :size (length vector))))\n (dotimes (i (length vector) table)\n (setf (gethash (aref vector i) table) i))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the fixnum (* result 10))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'int32))\n (cumul (make-array (1+ n) :element-type 'fixnum :initial-element 0))\n (bitree (make-array (1+ n) :element-type 'fixnum :initial-element 0)))\n (declare (uint31 n k))\n (dotimes (i n)\n (setf (aref as i) (- (read-fixnum) k))\n (setf (aref cumul (1+ i)) (+ (aref cumul i) (aref as i))))\n (let ((table (make-reverse-lookup-table (sort (copy-seq cumul) #'<))))\n (println\n (loop for i to n\n sum (bitree-sum bitree (1+ (the uint31 (gethash (aref cumul i) table))))\n of-type fixnum\n do (bitree-update! bitree (gethash (aref cumul i) table) 1))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1554353740, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03703.html", "problem_id": "p03703", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03703/input.txt", "sample_output_relpath": "derived/input_output/data/p03703/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03703/Lisp/s589187393.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s589187393", "user_id": "u352600849"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;; 1D BIT\n(defmacro define-bitree (name &key (operator '#'+) (identity 0) sum-type (order '#'>))\n \"OPERATOR := binary operator (on a commutative monoid)\nIDENTITY := object (identity element of the monoid)\nORDER := nil | strict comparison operator on the monoid\nSUM-TYPE := nil | type specifier\n\nDefines no structure; BIT is just a vector. Defines the three function:\n-UPDATE!, -SUM and COERCE-TO-!. In addition this macro defines\nthe bisection function -BISECT-LEFT if ORDER is specified. (Note that the\nlast function works only when the sequence of sums (VECTOR[0],\nVECTOR[0]+VECTOR[1], ...) is monotonous.)\n\nSUM-TYPE is used only for the type declaration: each sum\nVECTOR[i]+VECTOR[i+1]...+VECTOR[i+k] is declared to be this type. (The\nelement-type of vector itself doesn't need to be SUM-TYPE.)\"\n (let* ((name (string name))\n (fname-update (intern (format nil \"~A-UPDATE!\" name)))\n (fname-sum (intern (format nil \"~A-SUM\" name)))\n (fname-coerce (intern (format nil \"COERCE-TO-~A!\" name)))\n (fname-bisect (intern (format nil \"~A-BISECT-LEFT\" name))))\n `(progn\n (declaim (inline ,fname-update))\n (defun ,fname-update (bitree index delta)\n \"Destructively increments the vector: vector[INDEX] = vector[INDEX] +\nDELTA\"\n (let ((len (length bitree)))\n (do ((i index (logior i (+ i 1))))\n ((>= i len) bitree)\n (declare ((integer 0 #.most-positive-fixnum) i))\n (setf (aref bitree i)\n (funcall ,operator (aref bitree i) delta)))))\n\n (declaim (inline ,fname-sum))\n (defun ,fname-sum (bitree end)\n \"Returns the sum of prefix: vector[0] + ... + vector[END-1].\"\n (declare ((integer 0 #.most-positive-fixnum) end))\n (let ((res ,identity))\n ,@(when sum-type `((declare (type ,sum-type res))))\n (do ((i (- end 1) (- (logand i (+ i 1)) 1)))\n ((< i 0) res)\n (declare ((integer -1 #.most-positive-fixnum) i))\n (setf res (funcall ,operator res (aref bitree i))))))\n\n (declaim (inline ,fname-coerce))\n (defun ,fname-coerce (vector)\n \"Destructively constructs BIT from VECTOR.\"\n (loop with len = (length vector)\n for i below len\n for dest-i = (logior i (+ i 1))\n when (< dest-i len)\n do (setf (aref vector dest-i)\n (funcall ,operator (aref vector dest-i) (aref vector i)))\n finally (return vector)))\n\n ,@(when order\n `((declaim (inline ,fname-bisect))\n (defun ,fname-bisect (bitree value)\n \"Returns the smallest index that fulfills VECTOR[0]+ ... +\nVECTOR[index-1] >= VALUE. Returns the length of VECTOR if VECTOR[0]+\n... +VECTOR[END-1] > VALUE.\"\n (declare (vector bitree))\n (if (not (funcall ,order value ,identity))\n 0\n (let ((len (length bitree))\n (index+1 0)\n (cumul ,identity))\n (declare ((integer 0 #.most-positive-fixnum) index+1)\n ,@(when sum-type\n `((type ,sum-type cumul))))\n (do ((delta (ash 1 (- (integer-length len) 1))\n (ash delta -1)))\n ((zerop delta) index+1)\n (declare ((integer 0 #.most-positive-fixnum) delta))\n (let ((next-index (+ index+1 delta -1)))\n (when (< next-index len)\n (let ((next-cumul (funcall ,operator cumul (aref bitree next-index))))\n ,@(when sum-type\n `((declare (type ,sum-type next-cumul))))\n (when (funcall ,order value next-cumul)\n (setf cumul next-cumul)\n (incf index+1 delta))))))))))))))\n\n(define-bitree bitree\n :operator #'+\n :identity 0\n :sum-type fixnum)\n\n(declaim (inline make-reverse-lookup-table))\n(defun make-reverse-lookup-table (vector &key (test #'eql))\n \"Assigns each value of the (sorted) VECTOR of length n to the integers 0, ...,\nn-1.\"\n (let ((table (make-hash-table :test test :size (length vector))))\n (dotimes (i (length vector) table)\n (setf (gethash (aref vector i) table) i))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the fixnum (* result 10))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'int32))\n (cumul (make-array (1+ n) :element-type 'fixnum :initial-element 0))\n (bitree (make-array (1+ n) :element-type 'fixnum :initial-element 0)))\n (declare (uint31 n k))\n (dotimes (i n)\n (setf (aref as i) (- (read-fixnum) k))\n (setf (aref cumul (1+ i)) (+ (aref cumul i) (aref as i))))\n (let ((table (make-reverse-lookup-table (sort (copy-seq cumul) #'<))))\n (println\n (loop for i to n\n sum (bitree-sum bitree (1+ (the uint31 (gethash (aref cumul i) table))))\n of-type fixnum\n do (bitree-update! bitree (gethash (aref cumul i) table) 1))))))\n\n#-swank(main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nYou are given an integer sequence of length N, a = {a_1, a_2, …, a_N}, and an integer K.\n\na has N(N+1)/2 non-empty contiguous subsequences, {a_l, a_{l+1}, …, a_r} (1 ≤ l ≤ r ≤ N). Among them, how many have an arithmetic mean that is greater than or equal to K?\n\nConstraints\n\nAll input values are integers.\n\n1 ≤ N ≤ 2 \\times 10^5\n\n1 ≤ K ≤ 10^9\n\n1 ≤ a_i ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\na_1\na_2\n:\na_N\n\nOutput\n\nPrint the number of the non-empty contiguous subsequences with an arithmetic mean that is greater than or equal to K.\n\nSample Input 1\n\n3 6\n7\n5\n7\n\nSample Output 1\n\n5\n\nAll the non-empty contiguous subsequences of a are listed below:\n\n{a_1} = {7}\n\n{a_1, a_2} = {7, 5}\n\n{a_1, a_2, a_3} = {7, 5, 7}\n\n{a_2} = {5}\n\n{a_2, a_3} = {5, 7}\n\n{a_3} = {7}\n\nTheir means are 7, 6, 19/3, 5, 6 and 7, respectively, and five among them are 6 or greater. Note that {a_1} and {a_3} are indistinguishable by the values of their elements, but we count them individually.\n\nSample Input 2\n\n1 2\n1\n\nSample Output 2\n\n0\n\nSample Input 3\n\n7 26\n10\n20\n30\n40\n30\n20\n10\n\nSample Output 3\n\n13", "sample_input": "3 6\n7\n5\n7\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03703", "source_text": "Score : 600 points\n\nProblem Statement\n\nYou are given an integer sequence of length N, a = {a_1, a_2, …, a_N}, and an integer K.\n\na has N(N+1)/2 non-empty contiguous subsequences, {a_l, a_{l+1}, …, a_r} (1 ≤ l ≤ r ≤ N). Among them, how many have an arithmetic mean that is greater than or equal to K?\n\nConstraints\n\nAll input values are integers.\n\n1 ≤ N ≤ 2 \\times 10^5\n\n1 ≤ K ≤ 10^9\n\n1 ≤ a_i ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\na_1\na_2\n:\na_N\n\nOutput\n\nPrint the number of the non-empty contiguous subsequences with an arithmetic mean that is greater than or equal to K.\n\nSample Input 1\n\n3 6\n7\n5\n7\n\nSample Output 1\n\n5\n\nAll the non-empty contiguous subsequences of a are listed below:\n\n{a_1} = {7}\n\n{a_1, a_2} = {7, 5}\n\n{a_1, a_2, a_3} = {7, 5, 7}\n\n{a_2} = {5}\n\n{a_2, a_3} = {5, 7}\n\n{a_3} = {7}\n\nTheir means are 7, 6, 19/3, 5, 6 and 7, respectively, and five among them are 6 or greater. Note that {a_1} and {a_3} are indistinguishable by the values of their elements, but we count them individually.\n\nSample Input 2\n\n1 2\n1\n\nSample Output 2\n\n0\n\nSample Input 3\n\n7 26\n10\n20\n30\n40\n30\n20\n10\n\nSample Output 3\n\n13", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7451, "cpu_time_ms": 366, "memory_kb": 35304}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s817722221", "group_id": "codeNet:p03707", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(declaim (inline read-schar))\n(defun read-schar (&optional (stream *standard-input*))\n (declare #-swank (sb-kernel:ansi-stream stream)\n (inline read-byte))\n #+swank (read-char stream nil #\\Newline) ; on SLIME\n #-swank (code-char (read-byte stream nil #.(char-code #\\Newline))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (q (read))\n (plan (make-array (list n m) :element-type 'bit :initial-element 0))\n (dp (make-array (list (+ n 1) (+ m 1)) :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (dotimes (j m (read-schar))\n (when (char= #\\1 (read-schar))\n (setf (aref plan i j) 1))))\n (loop\n for i from 1 to n\n do (loop\n for j from 1 to m\n for alpha = (cond ((and (= (aref plan (- i 1) (- j 1)) 1)\n (or (= i 1) (= 0 (aref plan (- i 2) (- j 1))))\n (or (= j 1) (= 0 (aref plan (- i 1) (- j 2)))))\n 1)\n ((and (= (aref plan (- i 1) (- j 1)) 1)\n (and (> i 1) (= 1 (aref plan (- i 2) (- j 1))))\n (and (> j 1) (= 1 (aref plan (- i 1) (- j 2)))))\n -1)\n (t 0))\n do (setf (aref dp i j)\n (+ (aref dp (- i 1) j)\n (aref dp i (- j 1))\n (- (aref dp (- i 1) (- j 1)))\n alpha))))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (i q)\n (let ((y1 (- (read-fixnum) 1))\n (x1 (- (read-fixnum) 1))\n (y2 (read-fixnum))\n (x2 (read-fixnum)))\n (println (- (aref dp y2 x2) (aref dp y1 x1)))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 4 4\n1101\n0110\n1101\n1 1 3 4\n1 1 3 1\n2 2 3 4\n1 2 2 4\n\"\n \"3\n2\n2\n2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 5 6\n11010\n01110\n10101\n11101\n01010\n1 1 5 5\n1 2 4 5\n2 3 3 4\n3 3 3 3\n3 1 3 5\n1 1 3 4\n\"\n \"3\n2\n1\n1\n3\n2\n\")))\n", "language": "Lisp", "metadata": {"date": 1589458224, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03707.html", "problem_id": "p03707", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03707/input.txt", "sample_output_relpath": "derived/input_output/data/p03707/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03707/Lisp/s817722221.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s817722221", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n2\n2\n2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(declaim (inline read-schar))\n(defun read-schar (&optional (stream *standard-input*))\n (declare #-swank (sb-kernel:ansi-stream stream)\n (inline read-byte))\n #+swank (read-char stream nil #\\Newline) ; on SLIME\n #-swank (code-char (read-byte stream nil #.(char-code #\\Newline))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (q (read))\n (plan (make-array (list n m) :element-type 'bit :initial-element 0))\n (dp (make-array (list (+ n 1) (+ m 1)) :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (dotimes (j m (read-schar))\n (when (char= #\\1 (read-schar))\n (setf (aref plan i j) 1))))\n (loop\n for i from 1 to n\n do (loop\n for j from 1 to m\n for alpha = (cond ((and (= (aref plan (- i 1) (- j 1)) 1)\n (or (= i 1) (= 0 (aref plan (- i 2) (- j 1))))\n (or (= j 1) (= 0 (aref plan (- i 1) (- j 2)))))\n 1)\n ((and (= (aref plan (- i 1) (- j 1)) 1)\n (and (> i 1) (= 1 (aref plan (- i 2) (- j 1))))\n (and (> j 1) (= 1 (aref plan (- i 1) (- j 2)))))\n -1)\n (t 0))\n do (setf (aref dp i j)\n (+ (aref dp (- i 1) j)\n (aref dp i (- j 1))\n (- (aref dp (- i 1) (- j 1)))\n alpha))))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (i q)\n (let ((y1 (- (read-fixnum) 1))\n (x1 (- (read-fixnum) 1))\n (y2 (read-fixnum))\n (x2 (read-fixnum)))\n (println (- (aref dp y2 x2) (aref dp y1 x1)))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 4 4\n1101\n0110\n1101\n1 1 3 4\n1 1 3 1\n2 2 3 4\n1 2 2 4\n\"\n \"3\n2\n2\n2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 5 6\n11010\n01110\n10101\n11101\n01010\n1 1 5 5\n1 2 4 5\n2 3 3 4\n3 3 3 3\n3 1 3 5\n1 1 3 4\n\"\n \"3\n2\n1\n1\n3\n2\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nNuske has a grid with N rows and M columns of squares. The rows are numbered 1 through N from top to bottom, and the columns are numbered 1 through M from left to right.\nEach square in the grid is painted in either blue or white. If S_{i,j} is 1, the square at the i-th row and j-th column is blue; if S_{i,j} is 0, the square is white.\nFor every pair of two blue square a and b, there is at most one path that starts from a, repeatedly proceeds to an adjacent (side by side) blue square and finally reaches b, without traversing the same square more than once.\n\nPhantom Thnook, Nuske's eternal rival, gives Q queries to Nuske. The i-th query consists of four integers x_{i,1}, y_{i,1}, x_{i,2} and y_{i,2} and asks him the following: when the rectangular region of the grid bounded by (and including) the x_{i,1}-th row, x_{i,2}-th row, y_{i,1}-th column and y_{i,2}-th column is cut out, how many connected components consisting of blue squares there are in the region?\n\nProcess all the queries.\n\nConstraints\n\n1 ≤ N,M ≤ 2000\n\n1 ≤ Q ≤ 200000\n\nS_{i,j} is either 0 or 1.\n\nS_{i,j} satisfies the condition explained in the statement.\n\n1 ≤ x_{i,1} ≤ x_{i,2} ≤ N(1 ≤ i ≤ Q)\n\n1 ≤ y_{i,1} ≤ y_{i,2} ≤ M(1 ≤ i ≤ Q)\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN M Q\nS_{1,1}..S_{1,M}\n:\nS_{N,1}..S_{N,M}\nx_{1,1} y_{i,1} x_{i,2} y_{i,2}\n:\nx_{Q,1} y_{Q,1} x_{Q,2} y_{Q,2}\n\nOutput\n\nFor each query, print the number of the connected components consisting of blue squares in the region.\n\nSample Input 1\n\n3 4 4\n1101\n0110\n1101\n1 1 3 4\n1 1 3 1\n2 2 3 4\n1 2 2 4\n\nSample Output 1\n\n3\n2\n2\n2\n\nIn the first query, the whole grid is specified. There are three components consisting of blue squares, and thus 3 should be printed.\n\nIn the second query, the region within the red frame is specified. There are two components consisting of blue squares, and thus 2 should be printed.\nNote that squares that belong to the same component in the original grid may belong to different components.\n\nSample Input 2\n\n5 5 6\n11010\n01110\n10101\n11101\n01010\n1 1 5 5\n1 2 4 5\n2 3 3 4\n3 3 3 3\n3 1 3 5\n1 1 3 4\n\nSample Output 2\n\n3\n2\n1\n1\n3\n2", "sample_input": "3 4 4\n1101\n0110\n1101\n1 1 3 4\n1 1 3 1\n2 2 3 4\n1 2 2 4\n"}, "reference_outputs": ["3\n2\n2\n2\n"], "source_document_id": "p03707", "source_text": "Score : 700 points\n\nProblem Statement\n\nNuske has a grid with N rows and M columns of squares. The rows are numbered 1 through N from top to bottom, and the columns are numbered 1 through M from left to right.\nEach square in the grid is painted in either blue or white. If S_{i,j} is 1, the square at the i-th row and j-th column is blue; if S_{i,j} is 0, the square is white.\nFor every pair of two blue square a and b, there is at most one path that starts from a, repeatedly proceeds to an adjacent (side by side) blue square and finally reaches b, without traversing the same square more than once.\n\nPhantom Thnook, Nuske's eternal rival, gives Q queries to Nuske. The i-th query consists of four integers x_{i,1}, y_{i,1}, x_{i,2} and y_{i,2} and asks him the following: when the rectangular region of the grid bounded by (and including) the x_{i,1}-th row, x_{i,2}-th row, y_{i,1}-th column and y_{i,2}-th column is cut out, how many connected components consisting of blue squares there are in the region?\n\nProcess all the queries.\n\nConstraints\n\n1 ≤ N,M ≤ 2000\n\n1 ≤ Q ≤ 200000\n\nS_{i,j} is either 0 or 1.\n\nS_{i,j} satisfies the condition explained in the statement.\n\n1 ≤ x_{i,1} ≤ x_{i,2} ≤ N(1 ≤ i ≤ Q)\n\n1 ≤ y_{i,1} ≤ y_{i,2} ≤ M(1 ≤ i ≤ Q)\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN M Q\nS_{1,1}..S_{1,M}\n:\nS_{N,1}..S_{N,M}\nx_{1,1} y_{i,1} x_{i,2} y_{i,2}\n:\nx_{Q,1} y_{Q,1} x_{Q,2} y_{Q,2}\n\nOutput\n\nFor each query, print the number of the connected components consisting of blue squares in the region.\n\nSample Input 1\n\n3 4 4\n1101\n0110\n1101\n1 1 3 4\n1 1 3 1\n2 2 3 4\n1 2 2 4\n\nSample Output 1\n\n3\n2\n2\n2\n\nIn the first query, the whole grid is specified. There are three components consisting of blue squares, and thus 3 should be printed.\n\nIn the second query, the region within the red frame is specified. There are two components consisting of blue squares, and thus 2 should be printed.\nNote that squares that belong to the same component in the original grid may belong to different components.\n\nSample Input 2\n\n5 5 6\n11010\n01110\n10101\n11101\n01010\n1 1 5 5\n1 2 4 5\n2 3 3 4\n3 3 3 3\n3 1 3 5\n1 1 3 4\n\nSample Output 2\n\n3\n2\n1\n1\n3\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6625, "cpu_time_ms": 288, "memory_kb": 44536}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s452388115", "group_id": "codeNet:p03711", "input_text": "(let ((x (read))\n (y (read))\n (lst1 '(1 3 5 7 8 10 12))\n (lst2 '(4 6 9 11))\n (lst3 '(2)))\n\n (format t \"~A~%\"\n (cond ((and (member x lst1) (member y lst1)) \"Yes\")\n ((and (member x lst2) (member y lst2)) \"Yes\")\n ((and (member x lst3) (member y lst3)) \"Yes\")\n (t \"No\"))))\n", "language": "Lisp", "metadata": {"date": 1572927080, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03711.html", "problem_id": "p03711", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03711/input.txt", "sample_output_relpath": "derived/input_output/data/p03711/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03711/Lisp/s452388115.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s452388115", "user_id": "u336541610"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((x (read))\n (y (read))\n (lst1 '(1 3 5 7 8 10 12))\n (lst2 '(4 6 9 11))\n (lst3 '(2)))\n\n (format t \"~A~%\"\n (cond ((and (member x lst1) (member y lst1)) \"Yes\")\n ((and (member x lst2) (member y lst2)) \"Yes\")\n ((and (member x lst3) (member y lst3)) \"Yes\")\n (t \"No\"))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nBased on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below.\nGiven two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.\n\nConstraints\n\nx and y are integers.\n\n1 ≤ x < y ≤ 12\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx y\n\nOutput\n\nIf x and y belong to the same group, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\nYes\n\nSample Input 2\n\n2 4\n\nSample Output 2\n\nNo", "sample_input": "1 3\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03711", "source_text": "Score : 100 points\n\nProblem Statement\n\nBased on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below.\nGiven two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.\n\nConstraints\n\nx and y are integers.\n\n1 ≤ x < y ≤ 12\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx y\n\nOutput\n\nIf x and y belong to the same group, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\nYes\n\nSample Input 2\n\n2 4\n\nSample Output 2\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 344, "cpu_time_ms": 34, "memory_kb": 7268}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s667363562", "group_id": "codeNet:p03711", "input_text": "(defmacro defsolver (name vars &body body)\n `(defun ,name ()\n (let (,@(mapcar #'list\n\t\t vars\n\t\t (mapcar (constantly '(read))\n\t\t\t vars)))\n ,@body)))\n\n(defun check (x y)\n (let* ((g1 '(1 3 5 7 8 10 12))\n\t (g2 '(4 6 9 11))\n\t (h1 (member x g1 :test #'equal))\n\t (h2 (member y g1 :test #'equal))\n\t (h3 (member x g2 :test #'equal))\n\t (h4 (member y g2 :test #'equal)))\n (or (and h1 h2) (and h3 h4))))\n\n(defsolver prob-a (x y)\n (format t \"~:[No~;Yes~]\"\n\t (check x y)))\n\n(prob-a)", "language": "Lisp", "metadata": {"date": 1495331146, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03711.html", "problem_id": "p03711", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03711/input.txt", "sample_output_relpath": "derived/input_output/data/p03711/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03711/Lisp/s667363562.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s667363562", "user_id": "u100932207"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defmacro defsolver (name vars &body body)\n `(defun ,name ()\n (let (,@(mapcar #'list\n\t\t vars\n\t\t (mapcar (constantly '(read))\n\t\t\t vars)))\n ,@body)))\n\n(defun check (x y)\n (let* ((g1 '(1 3 5 7 8 10 12))\n\t (g2 '(4 6 9 11))\n\t (h1 (member x g1 :test #'equal))\n\t (h2 (member y g1 :test #'equal))\n\t (h3 (member x g2 :test #'equal))\n\t (h4 (member y g2 :test #'equal)))\n (or (and h1 h2) (and h3 h4))))\n\n(defsolver prob-a (x y)\n (format t \"~:[No~;Yes~]\"\n\t (check x y)))\n\n(prob-a)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nBased on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below.\nGiven two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.\n\nConstraints\n\nx and y are integers.\n\n1 ≤ x < y ≤ 12\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx y\n\nOutput\n\nIf x and y belong to the same group, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\nYes\n\nSample Input 2\n\n2 4\n\nSample Output 2\n\nNo", "sample_input": "1 3\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03711", "source_text": "Score : 100 points\n\nProblem Statement\n\nBased on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below.\nGiven two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.\n\nConstraints\n\nx and y are integers.\n\n1 ≤ x < y ≤ 12\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx y\n\nOutput\n\nIf x and y belong to the same group, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\nYes\n\nSample Input 2\n\n2 4\n\nSample Output 2\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 494, "cpu_time_ms": 23, "memory_kb": 6504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s849674083", "group_id": "codeNet:p03711", "input_text": "(defmacro defsolver (name vars &body body)\n `(defun ,name ()\n (let (,@(mapcar #'list\n\t\t vars\n\t\t (mapcar (constantly '(read))\n\t\t\t vars)))\n ,@body)))\n\n(defun check (x y)\n (let* ((g1 '(1 3 5 7 8 10 12))\n\t (g2 '(4 6 9 11))\n\t (h1 (member x g1 :test #'equal))\n\t (h2 (member y g1 :test #'equal))\n\t (h3 (member x g2 :test #'equal))\n\t (h4 (member y g2 :test #'equal)))\n (format t \"~a ~a ~a ~a~%\" h1 h2 h3 h4)\n (or (and h1 h2) (and h3 h4))))\n\n(defsolver prob-a (x y)\n (format t \"~:[No~;Yes~]~a\"\n\t (or (= x y) (check x y))))\n\n(prob-a)", "language": "Lisp", "metadata": {"date": 1495330439, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03711.html", "problem_id": "p03711", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03711/input.txt", "sample_output_relpath": "derived/input_output/data/p03711/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03711/Lisp/s849674083.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s849674083", "user_id": "u100932207"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defmacro defsolver (name vars &body body)\n `(defun ,name ()\n (let (,@(mapcar #'list\n\t\t vars\n\t\t (mapcar (constantly '(read))\n\t\t\t vars)))\n ,@body)))\n\n(defun check (x y)\n (let* ((g1 '(1 3 5 7 8 10 12))\n\t (g2 '(4 6 9 11))\n\t (h1 (member x g1 :test #'equal))\n\t (h2 (member y g1 :test #'equal))\n\t (h3 (member x g2 :test #'equal))\n\t (h4 (member y g2 :test #'equal)))\n (format t \"~a ~a ~a ~a~%\" h1 h2 h3 h4)\n (or (and h1 h2) (and h3 h4))))\n\n(defsolver prob-a (x y)\n (format t \"~:[No~;Yes~]~a\"\n\t (or (= x y) (check x y))))\n\n(prob-a)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nBased on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below.\nGiven two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.\n\nConstraints\n\nx and y are integers.\n\n1 ≤ x < y ≤ 12\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx y\n\nOutput\n\nIf x and y belong to the same group, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\nYes\n\nSample Input 2\n\n2 4\n\nSample Output 2\n\nNo", "sample_input": "1 3\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03711", "source_text": "Score : 100 points\n\nProblem Statement\n\nBased on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below.\nGiven two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.\n\nConstraints\n\nx and y are integers.\n\n1 ≤ x < y ≤ 12\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx y\n\nOutput\n\nIf x and y belong to the same group, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\nYes\n\nSample Input 2\n\n2 4\n\nSample Output 2\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 552, "cpu_time_ms": 354, "memory_kb": 17892}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s164285265", "group_id": "codeNet:p03712", "input_text": "(let ((a (read))\n (b (+ 2(read))))\n (format t \"~A~%\" (concatenate 'string (loop :repeat b collect #\\#)))\n (loop :repeat a do(format t \"#~A#~%\" (read-line)))\n (format t \"~A~%\" (concatenate 'string (loop :repeat b collect #\\#))))", "language": "Lisp", "metadata": {"date": 1542327806, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03712.html", "problem_id": "p03712", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03712/input.txt", "sample_output_relpath": "derived/input_output/data/p03712/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03712/Lisp/s164285265.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s164285265", "user_id": "u610490393"}, "prompt_components": {"gold_output": "#####\n#abc#\n#arc#\n#####\n", "input_to_evaluate": "(let ((a (read))\n (b (+ 2(read))))\n (format t \"~A~%\" (concatenate 'string (loop :repeat b collect #\\#)))\n (loop :repeat a do(format t \"#~A#~%\" (read-line)))\n (format t \"~A~%\" (concatenate 'string (loop :repeat b collect #\\#))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given a image with a height of H pixels and a width of W pixels.\nEach pixel is represented by a lowercase English letter.\nThe pixel at the i-th row from the top and j-th column from the left is a_{ij}.\n\nPut a box around this image and output the result. The box should consist of # and have a thickness of 1.\n\nConstraints\n\n1 ≤ H, W ≤ 100\n\na_{ij} is a lowercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\na_{11} ... a_{1W}\n:\na_{H1} ... a_{HW}\n\nOutput\n\nPrint the image surrounded by a box that consists of # and has a thickness of 1.\n\nSample Input 1\n\n2 3\nabc\narc\n\nSample Output 1\n\n#####\n#abc#\n#arc#\n#####\n\nSample Input 2\n\n1 1\nz\n\nSample Output 2\n\n###\n#z#\n###", "sample_input": "2 3\nabc\narc\n"}, "reference_outputs": ["#####\n#abc#\n#arc#\n#####\n"], "source_document_id": "p03712", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given a image with a height of H pixels and a width of W pixels.\nEach pixel is represented by a lowercase English letter.\nThe pixel at the i-th row from the top and j-th column from the left is a_{ij}.\n\nPut a box around this image and output the result. The box should consist of # and have a thickness of 1.\n\nConstraints\n\n1 ≤ H, W ≤ 100\n\na_{ij} is a lowercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\na_{11} ... a_{1W}\n:\na_{H1} ... a_{HW}\n\nOutput\n\nPrint the image surrounded by a box that consists of # and has a thickness of 1.\n\nSample Input 1\n\n2 3\nabc\narc\n\nSample Output 1\n\n#####\n#abc#\n#arc#\n#####\n\nSample Input 2\n\n1 1\nz\n\nSample Output 2\n\n###\n#z#\n###", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 235, "cpu_time_ms": 218, "memory_kb": 16096}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s331529790", "group_id": "codeNet:p03712", "input_text": "(defun solver ()\n (let ((H (read)) (W (read))\n (array (make-array 101)))\n (loop for i from 1 to H do\n (setf (svref array i) (read)))\n (loop for i from 1 to (+ W 2) do\n (format t \"#\"))\n (format t \"~%\")\n (loop for i from 1 to H do\n (format t \"#~(~A~)#~%\" (svref array i)))\n (loop for i from 1 to (+ W 2) do\n (format t \"#\"))\n (format t \"~%\")))\n\n(solver)", "language": "Lisp", "metadata": {"date": 1495329672, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03712.html", "problem_id": "p03712", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03712/input.txt", "sample_output_relpath": "derived/input_output/data/p03712/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03712/Lisp/s331529790.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s331529790", "user_id": "u183015556"}, "prompt_components": {"gold_output": "#####\n#abc#\n#arc#\n#####\n", "input_to_evaluate": "(defun solver ()\n (let ((H (read)) (W (read))\n (array (make-array 101)))\n (loop for i from 1 to H do\n (setf (svref array i) (read)))\n (loop for i from 1 to (+ W 2) do\n (format t \"#\"))\n (format t \"~%\")\n (loop for i from 1 to H do\n (format t \"#~(~A~)#~%\" (svref array i)))\n (loop for i from 1 to (+ W 2) do\n (format t \"#\"))\n (format t \"~%\")))\n\n(solver)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given a image with a height of H pixels and a width of W pixels.\nEach pixel is represented by a lowercase English letter.\nThe pixel at the i-th row from the top and j-th column from the left is a_{ij}.\n\nPut a box around this image and output the result. The box should consist of # and have a thickness of 1.\n\nConstraints\n\n1 ≤ H, W ≤ 100\n\na_{ij} is a lowercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\na_{11} ... a_{1W}\n:\na_{H1} ... a_{HW}\n\nOutput\n\nPrint the image surrounded by a box that consists of # and has a thickness of 1.\n\nSample Input 1\n\n2 3\nabc\narc\n\nSample Output 1\n\n#####\n#abc#\n#arc#\n#####\n\nSample Input 2\n\n1 1\nz\n\nSample Output 2\n\n###\n#z#\n###", "sample_input": "2 3\nabc\narc\n"}, "reference_outputs": ["#####\n#abc#\n#arc#\n#####\n"], "source_document_id": "p03712", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given a image with a height of H pixels and a width of W pixels.\nEach pixel is represented by a lowercase English letter.\nThe pixel at the i-th row from the top and j-th column from the left is a_{ij}.\n\nPut a box around this image and output the result. The box should consist of # and have a thickness of 1.\n\nConstraints\n\n1 ≤ H, W ≤ 100\n\na_{ij} is a lowercase English letter.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\na_{11} ... a_{1W}\n:\na_{H1} ... a_{HW}\n\nOutput\n\nPrint the image surrounded by a box that consists of # and has a thickness of 1.\n\nSample Input 1\n\n2 3\nabc\narc\n\nSample Output 1\n\n#####\n#abc#\n#arc#\n#####\n\nSample Input 2\n\n1 1\nz\n\nSample Output 2\n\n###\n#z#\n###", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 412, "cpu_time_ms": 577, "memory_kb": 16480}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s526779340", "group_id": "codeNet:p03713", "input_text": "#|\n------------------------------------\n| Utils |\n------------------------------------\n|#\n\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n(defconstant +mod+ 1000000007)\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n(defmacro read-numbers-to-list (size)\n `(loop repeat ,size collect (read)))\n\n(defmacro read-numbers-to-array (size)\n (let ((i (gensym))\n (arr (gensym)))\n `(let ((,arr (make-array ,size\n :element-type 'fixnum)))\n (declare ((array fixnum 1) ,arr))\n (loop for ,i of-type fixnum below ,size do\n (setf (aref ,arr ,i) (read))\n finally\n (return ,arr)))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(declaim (inline unwrap))\n(defun unwrap (list)\n (the string\n (format nil \"~{~a~^ ~}\" list)))\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(defmacro maxf (place cand)\n `(setf ,place (max ,place ,cand)))\n\n(defmacro minf (place cand)\n `(setf ,place (min ,place ,cand)))\n\n\n(defmacro alambda (parms &body body)\n `(labels ((self ,parms ,@body))\n #'self))\n\n(defun iota (count &optional (start 0) (step 1))\n (loop for i from 0 below count collect (+ start (* i step))))\n\n\n#|\n------------------------------------\n| Body |\n------------------------------------\n|#\n\n\n\n(defun calc-vertical-horizontal-divide (x y)\n (reduce #'min\n (mapcar (lambda (w)\n (let ((sa (* w y))\n (sb (* (- x w) (floor y 2)))\n (sc (* (- x w) (ceiling y 2)))\n (sd (* (floor (- x w) 2) y))\n (se (* (ceiling (- x w) 2) y)))\n (min (- (max sa sb sc)\n (min sa sb sc))\n (- (max sa sd se)\n (min sa sd se)))))\n (iota (1- x) 1))))\n\n(defun solve (h w)\n (declare (fixnum h w))\n (min (calc-vertical-horizontal-divide h w)\n (calc-vertical-horizontal-divide w h)))\n\n(defun main ()\n (declare #.OPT)\n (let ((h (read))\n (w (read)))\n (declare (fixnum h w))\n (princ (solve h w))\n (fresh-line)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1600324366, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03713.html", "problem_id": "p03713", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03713/input.txt", "sample_output_relpath": "derived/input_output/data/p03713/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03713/Lisp/s526779340.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s526779340", "user_id": "u425762225"}, "prompt_components": {"gold_output": "0\n", "input_to_evaluate": "#|\n------------------------------------\n| Utils |\n------------------------------------\n|#\n\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n(defconstant +mod+ 1000000007)\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n(defmacro read-numbers-to-list (size)\n `(loop repeat ,size collect (read)))\n\n(defmacro read-numbers-to-array (size)\n (let ((i (gensym))\n (arr (gensym)))\n `(let ((,arr (make-array ,size\n :element-type 'fixnum)))\n (declare ((array fixnum 1) ,arr))\n (loop for ,i of-type fixnum below ,size do\n (setf (aref ,arr ,i) (read))\n finally\n (return ,arr)))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(declaim (inline unwrap))\n(defun unwrap (list)\n (the string\n (format nil \"~{~a~^ ~}\" list)))\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(defmacro maxf (place cand)\n `(setf ,place (max ,place ,cand)))\n\n(defmacro minf (place cand)\n `(setf ,place (min ,place ,cand)))\n\n\n(defmacro alambda (parms &body body)\n `(labels ((self ,parms ,@body))\n #'self))\n\n(defun iota (count &optional (start 0) (step 1))\n (loop for i from 0 below count collect (+ start (* i step))))\n\n\n#|\n------------------------------------\n| Body |\n------------------------------------\n|#\n\n\n\n(defun calc-vertical-horizontal-divide (x y)\n (reduce #'min\n (mapcar (lambda (w)\n (let ((sa (* w y))\n (sb (* (- x w) (floor y 2)))\n (sc (* (- x w) (ceiling y 2)))\n (sd (* (floor (- x w) 2) y))\n (se (* (ceiling (- x w) 2) y)))\n (min (- (max sa sb sc)\n (min sa sb sc))\n (- (max sa sd se)\n (min sa sd se)))))\n (iota (1- x) 1))))\n\n(defun solve (h w)\n (declare (fixnum h w))\n (min (calc-vertical-horizontal-divide h w)\n (calc-vertical-horizontal-divide w h)))\n\n(defun main ()\n (declare #.OPT)\n (let ((h (read))\n (w (read)))\n (declare (fixnum h w))\n (princ (solve h w))\n (fresh-line)))\n\n#-swank (main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere is a bar of chocolate with a height of H blocks and a width of W blocks.\nSnuke is dividing this bar into exactly three pieces.\nHe can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.\n\nSnuke is trying to divide the bar as evenly as possible.\nMore specifically, he is trying to minimize S_{max} - S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece.\nFind the minimum possible value of S_{max} - S_{min}.\n\nConstraints\n\n2 ≤ H, W ≤ 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\n\nOutput\n\nPrint the minimum possible value of S_{max} - S_{min}.\n\nSample Input 1\n\n3 5\n\nSample Output 1\n\n0\n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\nSample Input 2\n\n4 5\n\nSample Output 2\n\n2\n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\nSample Input 3\n\n5 5\n\nSample Output 3\n\n4\n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\nSample Input 4\n\n100000 2\n\nSample Output 4\n\n1\n\nSample Input 5\n\n100000 100000\n\nSample Output 5\n\n50000", "sample_input": "3 5\n"}, "reference_outputs": ["0\n"], "source_document_id": "p03713", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere is a bar of chocolate with a height of H blocks and a width of W blocks.\nSnuke is dividing this bar into exactly three pieces.\nHe can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.\n\nSnuke is trying to divide the bar as evenly as possible.\nMore specifically, he is trying to minimize S_{max} - S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece.\nFind the minimum possible value of S_{max} - S_{min}.\n\nConstraints\n\n2 ≤ H, W ≤ 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\n\nOutput\n\nPrint the minimum possible value of S_{max} - S_{min}.\n\nSample Input 1\n\n3 5\n\nSample Output 1\n\n0\n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\nSample Input 2\n\n4 5\n\nSample Output 2\n\n2\n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\nSample Input 3\n\n5 5\n\nSample Output 3\n\n4\n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\nSample Input 4\n\n100000 2\n\nSample Output 4\n\n1\n\nSample Input 5\n\n100000 100000\n\nSample Output 5\n\n50000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4411, "cpu_time_ms": 58, "memory_kb": 32192}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s720376801", "group_id": "codeNet:p03717", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (right-to-lefts (make-array 301 :element-type 'list :initial-element nil))\n (dp (make-array (list (+ n 2) (+ n 2) (+ n 2))\n :element-type 'uint31\n :initial-element 0)))\n (declare (uint16 n m))\n (dotimes (i m)\n (let ((l (read))\n (r (read))\n (x (read)))\n (push (cons l x) (aref right-to-lefts r))))\n #>right-to-lefts\n (setf (aref dp 1 0 0) 1\n (aref dp 0 1 0) 1\n (aref dp 0 0 1) 1)\n (dotimes (i (+ n 1))\n (dotimes (j (+ n 1))\n (dotimes (k (+ n 1))\n (let ((min i)\n (mid j)\n (max k))\n (when (< max mid) (rotatef max mid))\n (when (< mid min) (rotatef mid min))\n (when (< max mid) (rotatef max mid))\n (loop for (l . x) of-type (uint16 . uint16) in (aref right-to-lefts max)\n when (and (< min l) (= x 3))\n do (setf (aref dp i j k) 0)\n when (and (< mid l) (= x 2))\n do (setf (aref dp i j k) 0)\n when (and (>= min l) (= x 2))\n do (setf (aref dp i j k) 0)\n when (and (>= mid l) (= x 1))\n do (setf (aref dp i j k) 0))\n (incfmod (aref dp (+ max 1) j k) (aref dp i j k))\n (incfmod (aref dp i (+ max 1) k) (aref dp i j k))\n (incfmod (aref dp i j (+ max 1)) (aref dp i j k))))))\n (let ((res 0))\n (declare (uint31 res))\n (dotimes (i n)\n (dotimes (j n)\n (incfmod res (aref dp n i j))\n (incfmod res (aref dp i n j))\n (incfmod res (aref dp i j n))))\n (println res))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 1\n1 3 3\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 2\n1 3 1\n2 4 2\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 3\n1 1 1\n1 1 2\n1 1 3\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8 10\n2 6 2\n5 5 1\n3 5 2\n4 7 3\n4 4 1\n2 3 1\n7 7 1\n1 5 2\n1 7 3\n3 4 2\n\"\n \"108\n\")))\n", "language": "Lisp", "metadata": {"date": 1585808265, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03717.html", "problem_id": "p03717", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03717/input.txt", "sample_output_relpath": "derived/input_output/data/p03717/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03717/Lisp/s720376801.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s720376801", "user_id": "u352600849"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n #+sbcl\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (locally (declare (muffle-conditions warning))\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (right-to-lefts (make-array 301 :element-type 'list :initial-element nil))\n (dp (make-array (list (+ n 2) (+ n 2) (+ n 2))\n :element-type 'uint31\n :initial-element 0)))\n (declare (uint16 n m))\n (dotimes (i m)\n (let ((l (read))\n (r (read))\n (x (read)))\n (push (cons l x) (aref right-to-lefts r))))\n #>right-to-lefts\n (setf (aref dp 1 0 0) 1\n (aref dp 0 1 0) 1\n (aref dp 0 0 1) 1)\n (dotimes (i (+ n 1))\n (dotimes (j (+ n 1))\n (dotimes (k (+ n 1))\n (let ((min i)\n (mid j)\n (max k))\n (when (< max mid) (rotatef max mid))\n (when (< mid min) (rotatef mid min))\n (when (< max mid) (rotatef max mid))\n (loop for (l . x) of-type (uint16 . uint16) in (aref right-to-lefts max)\n when (and (< min l) (= x 3))\n do (setf (aref dp i j k) 0)\n when (and (< mid l) (= x 2))\n do (setf (aref dp i j k) 0)\n when (and (>= min l) (= x 2))\n do (setf (aref dp i j k) 0)\n when (and (>= mid l) (= x 1))\n do (setf (aref dp i j k) 0))\n (incfmod (aref dp (+ max 1) j k) (aref dp i j k))\n (incfmod (aref dp i (+ max 1) k) (aref dp i j k))\n (incfmod (aref dp i j (+ max 1)) (aref dp i j k))))))\n (let ((res 0))\n (declare (uint31 res))\n (dotimes (i n)\n (dotimes (j n)\n (incfmod res (aref dp n i j))\n (incfmod res (aref dp i n j))\n (incfmod res (aref dp i j n))))\n (println res))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 1\n1 3 3\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 2\n1 3 1\n2 4 2\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 3\n1 1 1\n1 1 2\n1 1 3\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8 10\n2 6 2\n5 5 1\n3 5 2\n4 7 3\n4 4 1\n2 3 1\n7 7 1\n1 5 2\n1 7 3\n3 4 2\n\"\n \"108\n\")))\n", "problem_context": "Score : 800 points\n\nProblem Statement\n\nThere are N squares arranged in a row.\nThe squares are numbered 1, 2, ..., N, from left to right.\n\nSnuke is painting each square in red, green or blue.\nAccording to his aesthetic sense, the following M conditions must all be satisfied.\nThe i-th condition is:\n\nThere are exactly x_i different colors among squares l_i, l_i + 1, ..., r_i.\n\nIn how many ways can the squares be painted to satisfy all the conditions?\nFind the count modulo 10^9+7.\n\nConstraints\n\n1 ≤ N ≤ 300\n\n1 ≤ M ≤ 300\n\n1 ≤ l_i ≤ r_i ≤ N\n\n1 ≤ x_i ≤ 3\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nl_1 r_1 x_1\nl_2 r_2 x_2\n:\nl_M r_M x_M\n\nOutput\n\nPrint the number of ways to paint the squares to satisfy all the conditions, modulo 10^9+7.\n\nSample Input 1\n\n3 1\n1 3 3\n\nSample Output 1\n\n6\n\nThe six ways are:\n\nRGB\n\nRBG\n\nGRB\n\nGBR\n\nBRG\n\nBGR\n\nwhere R, G and B correspond to red, green and blue squares, respectively.\n\nSample Input 2\n\n4 2\n1 3 1\n2 4 2\n\nSample Output 2\n\n6\n\nThe six ways are:\n\nRRRG\n\nRRRB\n\nGGGR\n\nGGGB\n\nBBBR\n\nBBBG\n\nSample Input 3\n\n1 3\n1 1 1\n1 1 2\n1 1 3\n\nSample Output 3\n\n0\n\nThere are zero ways.\n\nSample Input 4\n\n8 10\n2 6 2\n5 5 1\n3 5 2\n4 7 3\n4 4 1\n2 3 1\n7 7 1\n1 5 2\n1 7 3\n3 4 2\n\nSample Output 4\n\n108", "sample_input": "3 1\n1 3 3\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03717", "source_text": "Score : 800 points\n\nProblem Statement\n\nThere are N squares arranged in a row.\nThe squares are numbered 1, 2, ..., N, from left to right.\n\nSnuke is painting each square in red, green or blue.\nAccording to his aesthetic sense, the following M conditions must all be satisfied.\nThe i-th condition is:\n\nThere are exactly x_i different colors among squares l_i, l_i + 1, ..., r_i.\n\nIn how many ways can the squares be painted to satisfy all the conditions?\nFind the count modulo 10^9+7.\n\nConstraints\n\n1 ≤ N ≤ 300\n\n1 ≤ M ≤ 300\n\n1 ≤ l_i ≤ r_i ≤ N\n\n1 ≤ x_i ≤ 3\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nl_1 r_1 x_1\nl_2 r_2 x_2\n:\nl_M r_M x_M\n\nOutput\n\nPrint the number of ways to paint the squares to satisfy all the conditions, modulo 10^9+7.\n\nSample Input 1\n\n3 1\n1 3 3\n\nSample Output 1\n\n6\n\nThe six ways are:\n\nRGB\n\nRBG\n\nGRB\n\nGBR\n\nBRG\n\nBGR\n\nwhere R, G and B correspond to red, green and blue squares, respectively.\n\nSample Input 2\n\n4 2\n1 3 1\n2 4 2\n\nSample Output 2\n\n6\n\nThe six ways are:\n\nRRRG\n\nRRRB\n\nGGGR\n\nGGGB\n\nBBBR\n\nBBBG\n\nSample Input 3\n\n1 3\n1 1 1\n1 1 2\n1 1 3\n\nSample Output 3\n\n0\n\nThere are zero ways.\n\nSample Input 4\n\n8 10\n2 6 2\n5 5 1\n3 5 2\n4 7 3\n4 4 1\n2 3 1\n7 7 1\n1 5 2\n1 7 3\n3 4 2\n\nSample Output 4\n\n108", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6669, "cpu_time_ms": 1972, "memory_kb": 131560}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s897007122", "group_id": "codeNet:p03718", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Ford-Fulkerson\n;;;\n(defstruct (edge (:constructor %make-edge))\n (to nil :type fixnum)\n (capacity 0 :type fixnum)\n (flow 0 :type fixnum)\n (reversed nil :type (or null edge)))\n\n(defun push-edge (from-idx to-idx capacity graph &key bidirectional)\n \"FROM-IDX, TO-IDX := index of vertex\nGRAPH := vector of list of all the edges that goes from the vertex\"\n (declare #.OPT ((simple-array list (*)) graph))\n (let* ((dep (%make-edge :to to-idx :capacity capacity))\n (ret (%make-edge :to from-idx\n :capacity (if bidirectional capacity 0)\n :reversed dep)))\n (setf (edge-reversed dep) ret)\n (push dep (aref graph from-idx))\n (push ret (aref graph to-idx))))\n\n(defun %find-flow (src-idx dest-idx graph max-flow checked)\n \"DFS\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) src-idx dest-idx max-flow)\n (simple-bit-vector checked)\n ((simple-array list (*)) graph))\n (setf (aref checked src-idx) 1)\n (if (= src-idx dest-idx)\n max-flow\n (dolist (edge (aref graph src-idx) 0)\n (when (and (zerop (aref checked (edge-to edge)))\n (< (edge-flow edge) (edge-capacity edge)))\n (let ((flow (%find-flow (edge-to edge)\n dest-idx\n graph\n (min max-flow (- (edge-capacity edge) (edge-flow edge)))\n checked)))\n (declare ((integer 0 #.most-positive-fixnum) flow))\n (unless (zerop flow)\n (incf (edge-flow edge) flow)\n (incf (edge-capacity (edge-reversed edge)) flow)\n (return flow)))))))\n\n(defun max-flow (src-idx dest-idx graph)\n (declare #.OPT ((simple-array list (*)) graph))\n (let ((checked (make-array (length graph) :element-type 'bit :initial-element 0)))\n (loop for incr-flow of-type (integer 0 #.most-positive-fixnum)\n = (%find-flow src-idx dest-idx graph most-positive-fixnum checked)\n do (fill checked 0)\n until (zerop incr-flow)\n sum incr-flow of-type (integer 0 #.most-positive-fixnum))))\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #.(char-code #\\Newline)))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,terminate-char))\n (return (values ,buffer ,idx))))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defconstant +inf+ #xffffffff)\n(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (graph (make-array (+ h w 2) :element-type 'list :initial-element nil))\n (start-index (+ h w))\n (goal-index (+ h w 1)))\n (declare (uint7 h w))\n (dotimes (i h)\n (let ((line (buffered-read-line 100)))\n (dotimes (j w)\n (case (aref line j)\n (#\\o (push-edge i (+ j h) 1 graph :bidirectional t))\n (#\\S\n (push-edge start-index i +inf+ graph)\n (push-edge start-index (+ j h) +inf+ graph))\n (#\\T\n (push-edge i goal-index +inf+ graph)\n (push-edge (+ j h) goal-index +inf+ graph))))))\n (let ((res (max-flow start-index goal-index graph)))\n (if (>= res +inf+)\n (println -1)\n (println res)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1552136433, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03718.html", "problem_id": "p03718", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03718/input.txt", "sample_output_relpath": "derived/input_output/data/p03718/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03718/Lisp/s897007122.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s897007122", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Ford-Fulkerson\n;;;\n(defstruct (edge (:constructor %make-edge))\n (to nil :type fixnum)\n (capacity 0 :type fixnum)\n (flow 0 :type fixnum)\n (reversed nil :type (or null edge)))\n\n(defun push-edge (from-idx to-idx capacity graph &key bidirectional)\n \"FROM-IDX, TO-IDX := index of vertex\nGRAPH := vector of list of all the edges that goes from the vertex\"\n (declare #.OPT ((simple-array list (*)) graph))\n (let* ((dep (%make-edge :to to-idx :capacity capacity))\n (ret (%make-edge :to from-idx\n :capacity (if bidirectional capacity 0)\n :reversed dep)))\n (setf (edge-reversed dep) ret)\n (push dep (aref graph from-idx))\n (push ret (aref graph to-idx))))\n\n(defun %find-flow (src-idx dest-idx graph max-flow checked)\n \"DFS\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) src-idx dest-idx max-flow)\n (simple-bit-vector checked)\n ((simple-array list (*)) graph))\n (setf (aref checked src-idx) 1)\n (if (= src-idx dest-idx)\n max-flow\n (dolist (edge (aref graph src-idx) 0)\n (when (and (zerop (aref checked (edge-to edge)))\n (< (edge-flow edge) (edge-capacity edge)))\n (let ((flow (%find-flow (edge-to edge)\n dest-idx\n graph\n (min max-flow (- (edge-capacity edge) (edge-flow edge)))\n checked)))\n (declare ((integer 0 #.most-positive-fixnum) flow))\n (unless (zerop flow)\n (incf (edge-flow edge) flow)\n (incf (edge-capacity (edge-reversed edge)) flow)\n (return flow)))))))\n\n(defun max-flow (src-idx dest-idx graph)\n (declare #.OPT ((simple-array list (*)) graph))\n (let ((checked (make-array (length graph) :element-type 'bit :initial-element 0)))\n (loop for incr-flow of-type (integer 0 #.most-positive-fixnum)\n = (%find-flow src-idx dest-idx graph most-positive-fixnum checked)\n do (fill checked 0)\n until (zerop incr-flow)\n sum incr-flow of-type (integer 0 #.most-positive-fixnum))))\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\\Space))\n \"Note that the returned string will be reused.\"\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let ((,buffer (load-time-value (make-string ,buffer-size\n :element-type 'base-char))))\n (declare (simple-base-string ,buffer))\n (loop for ,character of-type base-char =\n #-swank (code-char (read-byte ,in nil #.(char-code #\\Newline)))\n #+swank (read-char ,in nil #\\Newline)\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,terminate-char))\n (return (values ,buffer ,idx))))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defconstant +inf+ #xffffffff)\n(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (graph (make-array (+ h w 2) :element-type 'list :initial-element nil))\n (start-index (+ h w))\n (goal-index (+ h w 1)))\n (declare (uint7 h w))\n (dotimes (i h)\n (let ((line (buffered-read-line 100)))\n (dotimes (j w)\n (case (aref line j)\n (#\\o (push-edge i (+ j h) 1 graph :bidirectional t))\n (#\\S\n (push-edge start-index i +inf+ graph)\n (push-edge start-index (+ j h) +inf+ graph))\n (#\\T\n (push-edge i goal-index +inf+ graph)\n (push-edge (+ j h) goal-index +inf+ graph))))))\n (let ((res (max-flow start-index goal-index graph)))\n (if (>= res +inf+)\n (println -1)\n (println res)))))\n\n#-swank(main)\n", "problem_context": "Score : 800 points\n\nProblem Statement\n\nThere is a pond with a rectangular shape.\nThe pond is divided into a grid with H rows and W columns of squares.\nWe will denote the square at the i-th row from the top and j-th column from the left by (i,\\ j).\n\nSome of the squares in the pond contains a lotus leaf floating on the water.\nOn one of those leaves, S, there is a frog trying to get to another leaf T.\nThe state of square (i,\\ j) is given to you by a character a_{ij}, as follows:\n\n. : A square without a leaf.\n\no : A square with a leaf floating on the water.\n\nS : A square with the leaf S.\n\nT : A square with the leaf T.\n\nThe frog will repeatedly perform the following action to get to the leaf T: \"jump to a leaf that is in the same row or the same column as the leaf where the frog is currently located.\"\n\nSnuke is trying to remove some of the leaves, other than S and T, so that the frog cannot get to the leaf T.\nDetermine whether this objective is achievable. If it is achievable, find the minimum necessary number of leaves to remove.\n\nConstraints\n\n2 ≤ H, W ≤ 100\n\na_{ij} is ., o, S or T.\n\nThere is exactly one S among a_{ij}.\n\nThere is exactly one T among a_{ij}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\na_{11} ... a_{1W}\n:\na_{H1} ... a_{HW}\n\nOutput\n\nIf the objective is achievable, print the minimum necessary number of leaves to remove.\nOtherwise, print -1 instead.\n\nSample Input 1\n\n3 3\nS.o\n.o.\no.T\n\nSample Output 1\n\n2\n\nRemove the upper-right and lower-left leaves.\n\nSample Input 2\n\n3 4\nS...\n.oo.\n...T\n\nSample Output 2\n\n0\n\nSample Input 3\n\n4 3\n.S.\n.o.\n.o.\n.T.\n\nSample Output 3\n\n-1\n\nSample Input 4\n\n10 10\n.o...o..o.\n....o.....\n....oo.oo.\n..oooo..o.\n....oo....\n..o..o....\no..o....So\no....T....\n....o.....\n........oo\n\nSample Output 4\n\n5", "sample_input": "3 3\nS.o\n.o.\no.T\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03718", "source_text": "Score : 800 points\n\nProblem Statement\n\nThere is a pond with a rectangular shape.\nThe pond is divided into a grid with H rows and W columns of squares.\nWe will denote the square at the i-th row from the top and j-th column from the left by (i,\\ j).\n\nSome of the squares in the pond contains a lotus leaf floating on the water.\nOn one of those leaves, S, there is a frog trying to get to another leaf T.\nThe state of square (i,\\ j) is given to you by a character a_{ij}, as follows:\n\n. : A square without a leaf.\n\no : A square with a leaf floating on the water.\n\nS : A square with the leaf S.\n\nT : A square with the leaf T.\n\nThe frog will repeatedly perform the following action to get to the leaf T: \"jump to a leaf that is in the same row or the same column as the leaf where the frog is currently located.\"\n\nSnuke is trying to remove some of the leaves, other than S and T, so that the frog cannot get to the leaf T.\nDetermine whether this objective is achievable. If it is achievable, find the minimum necessary number of leaves to remove.\n\nConstraints\n\n2 ≤ H, W ≤ 100\n\na_{ij} is ., o, S or T.\n\nThere is exactly one S among a_{ij}.\n\nThere is exactly one T among a_{ij}.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\na_{11} ... a_{1W}\n:\na_{H1} ... a_{HW}\n\nOutput\n\nIf the objective is achievable, print the minimum necessary number of leaves to remove.\nOtherwise, print -1 instead.\n\nSample Input 1\n\n3 3\nS.o\n.o.\no.T\n\nSample Output 1\n\n2\n\nRemove the upper-right and lower-left leaves.\n\nSample Input 2\n\n3 4\nS...\n.oo.\n...T\n\nSample Output 2\n\n0\n\nSample Input 3\n\n4 3\n.S.\n.o.\n.o.\n.T.\n\nSample Output 3\n\n-1\n\nSample Input 4\n\n10 10\n.o...o..o.\n....o.....\n....oo.oo.\n..oooo..o.\n....oo....\n..o..o....\no..o....So\no....T....\n....o.....\n........oo\n\nSample Output 4\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4862, "cpu_time_ms": 93, "memory_kb": 14952}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s051267459", "group_id": "codeNet:p03719", "input_text": "(princ(if(or(>(setq a(read))(setq b(read)))(> a(setq c(read)))(> c b))\"Yes\"\"No\"))", "language": "Lisp", "metadata": {"date": 1528290269, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03719.html", "problem_id": "p03719", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03719/input.txt", "sample_output_relpath": "derived/input_output/data/p03719/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03719/Lisp/s051267459.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s051267459", "user_id": "u657913472"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(princ(if(or(>(setq a(read))(setq b(read)))(> a(setq c(read)))(> c b))\"Yes\"\"No\"))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given three integers A, B and C.\nDetermine whether C is not less than A and not greater than B.\n\nConstraints\n\n-100≤A,B,C≤100\n\nA, B and C are all integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf the condition is satisfied, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 3 2\n\nSample Output 1\n\nYes\n\nC=2 is not less than A=1 and not greater than B=3, and thus the output should be Yes.\n\nSample Input 2\n\n6 5 4\n\nSample Output 2\n\nNo\n\nC=4 is less than A=6, and thus the output should be No.\n\nSample Input 3\n\n2 2 2\n\nSample Output 3\n\nYes", "sample_input": "1 3 2\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03719", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given three integers A, B and C.\nDetermine whether C is not less than A and not greater than B.\n\nConstraints\n\n-100≤A,B,C≤100\n\nA, B and C are all integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf the condition is satisfied, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 3 2\n\nSample Output 1\n\nYes\n\nC=2 is not less than A=1 and not greater than B=3, and thus the output should be Yes.\n\nSample Input 2\n\n6 5 4\n\nSample Output 2\n\nNo\n\nC=4 is less than A=6, and thus the output should be No.\n\nSample Input 3\n\n2 2 2\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 81, "cpu_time_ms": 23, "memory_kb": 4324}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s508953969", "group_id": "codeNet:p03719", "input_text": "(defun main (a b c)\n (if (and (<= a c) (<= c b))\n t\n nil))\n\n(let ((a (read)) (b (read)) (c (read)))\n (if (main a b c)\n (princ \"Yes\")\n (princ \"No\")))", "language": "Lisp", "metadata": {"date": 1508887112, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03719.html", "problem_id": "p03719", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03719/input.txt", "sample_output_relpath": "derived/input_output/data/p03719/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03719/Lisp/s508953969.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s508953969", "user_id": "u361243145"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun main (a b c)\n (if (and (<= a c) (<= c b))\n t\n nil))\n\n(let ((a (read)) (b (read)) (c (read)))\n (if (main a b c)\n (princ \"Yes\")\n (princ \"No\")))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given three integers A, B and C.\nDetermine whether C is not less than A and not greater than B.\n\nConstraints\n\n-100≤A,B,C≤100\n\nA, B and C are all integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf the condition is satisfied, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 3 2\n\nSample Output 1\n\nYes\n\nC=2 is not less than A=1 and not greater than B=3, and thus the output should be Yes.\n\nSample Input 2\n\n6 5 4\n\nSample Output 2\n\nNo\n\nC=4 is less than A=6, and thus the output should be No.\n\nSample Input 3\n\n2 2 2\n\nSample Output 3\n\nYes", "sample_input": "1 3 2\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03719", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given three integers A, B and C.\nDetermine whether C is not less than A and not greater than B.\n\nConstraints\n\n-100≤A,B,C≤100\n\nA, B and C are all integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf the condition is satisfied, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 3 2\n\nSample Output 1\n\nYes\n\nC=2 is not less than A=1 and not greater than B=3, and thus the output should be Yes.\n\nSample Input 2\n\n6 5 4\n\nSample Output 2\n\nNo\n\nC=4 is less than A=6, and thus the output should be No.\n\nSample Input 3\n\n2 2 2\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 174, "cpu_time_ms": 100, "memory_kb": 10212}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s183663501", "group_id": "codeNet:p03719", "input_text": "(defun read-list-from-string (str)\n (read-from-string (concatenate 'string \"(\" str \")\")))\n\n(defun read-num-from-string (str)\n (parse-integer str))\n\n(defun read-list ()\n (read-list-from-string (read-line)))\n\n(defun read-num ()\n (read-num-from-string (read-line)))\n\n(defun solve ()\n (let ((list (read-list)))\n (if (and (<= (nth 0 list) (nth 2 list))\n\t (<= (nth 2 list) (nth 1 list)))\n\t(princ \"Yes\")\n\t(princ \"No\"))))\n\n(solve)", "language": "Lisp", "metadata": {"date": 1494724651, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03719.html", "problem_id": "p03719", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03719/input.txt", "sample_output_relpath": "derived/input_output/data/p03719/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03719/Lisp/s183663501.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s183663501", "user_id": "u237110174"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun read-list-from-string (str)\n (read-from-string (concatenate 'string \"(\" str \")\")))\n\n(defun read-num-from-string (str)\n (parse-integer str))\n\n(defun read-list ()\n (read-list-from-string (read-line)))\n\n(defun read-num ()\n (read-num-from-string (read-line)))\n\n(defun solve ()\n (let ((list (read-list)))\n (if (and (<= (nth 0 list) (nth 2 list))\n\t (<= (nth 2 list) (nth 1 list)))\n\t(princ \"Yes\")\n\t(princ \"No\"))))\n\n(solve)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given three integers A, B and C.\nDetermine whether C is not less than A and not greater than B.\n\nConstraints\n\n-100≤A,B,C≤100\n\nA, B and C are all integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf the condition is satisfied, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 3 2\n\nSample Output 1\n\nYes\n\nC=2 is not less than A=1 and not greater than B=3, and thus the output should be Yes.\n\nSample Input 2\n\n6 5 4\n\nSample Output 2\n\nNo\n\nC=4 is less than A=6, and thus the output should be No.\n\nSample Input 3\n\n2 2 2\n\nSample Output 3\n\nYes", "sample_input": "1 3 2\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03719", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given three integers A, B and C.\nDetermine whether C is not less than A and not greater than B.\n\nConstraints\n\n-100≤A,B,C≤100\n\nA, B and C are all integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf the condition is satisfied, print Yes; otherwise, print No.\n\nSample Input 1\n\n1 3 2\n\nSample Output 1\n\nYes\n\nC=2 is not less than A=1 and not greater than B=3, and thus the output should be Yes.\n\nSample Input 2\n\n6 5 4\n\nSample Output 2\n\nNo\n\nC=4 is less than A=6, and thus the output should be No.\n\nSample Input 3\n\n2 2 2\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 434, "cpu_time_ms": 114, "memory_kb": 11880}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s557236751", "group_id": "codeNet:p03720", "input_text": "(defun inc (x)\n (1+ x))\n\n(defun solve(n a b)\n (dotimes (i n)\n (format t \"~A~%\" (+ (count (1+ i) a) (count (1+ i) b))))) \n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (a (make-array m))\n (b (make-array m)))\n (progn\n (dotimes (i m)\n (setf (aref a i) (read))\n (setf (aref b i) (read)))\n (solve n a b))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1593099293, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03720.html", "problem_id": "p03720", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03720/input.txt", "sample_output_relpath": "derived/input_output/data/p03720/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03720/Lisp/s557236751.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s557236751", "user_id": "u425762225"}, "prompt_components": {"gold_output": "2\n2\n1\n1\n", "input_to_evaluate": "(defun inc (x)\n (1+ x))\n\n(defun solve(n a b)\n (dotimes (i n)\n (format t \"~A~%\" (+ (count (1+ i) a) (count (1+ i) b))))) \n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (a (make-array m))\n (b (make-array m)))\n (progn\n (dotimes (i m)\n (setf (aref a i) (read))\n (setf (aref b i) (read)))\n (solve n a b))))\n\n(main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N cities and M roads.\nThe i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally.\nThere may be more than one road that connects the same pair of two cities.\nFor each city, how many roads are connected to the city?\n\nConstraints\n\n2≤N,M≤50\n\n1≤a_i,b_i≤N\n\na_i ≠ b_i\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\n:\na_M b_M\n\nOutput\n\nPrint the answer in N lines.\nIn the i-th line (1≤i≤N), print the number of roads connected to city i.\n\nSample Input 1\n\n4 3\n1 2\n2 3\n1 4\n\nSample Output 1\n\n2\n2\n1\n1\n\nCity 1 is connected to the 1-st and 3-rd roads.\n\nCity 2 is connected to the 1-st and 2-nd roads.\n\nCity 3 is connected to the 2-nd road.\n\nCity 4 is connected to the 3-rd road.\n\nSample Input 2\n\n2 5\n1 2\n2 1\n1 2\n2 1\n1 2\n\nSample Output 2\n\n5\n5\n\nSample Input 3\n\n8 8\n1 2\n3 4\n1 5\n2 8\n3 7\n5 2\n4 1\n6 8\n\nSample Output 3\n\n3\n3\n2\n2\n2\n1\n1\n2", "sample_input": "4 3\n1 2\n2 3\n1 4\n"}, "reference_outputs": ["2\n2\n1\n1\n"], "source_document_id": "p03720", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N cities and M roads.\nThe i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally.\nThere may be more than one road that connects the same pair of two cities.\nFor each city, how many roads are connected to the city?\n\nConstraints\n\n2≤N,M≤50\n\n1≤a_i,b_i≤N\n\na_i ≠ b_i\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\n:\na_M b_M\n\nOutput\n\nPrint the answer in N lines.\nIn the i-th line (1≤i≤N), print the number of roads connected to city i.\n\nSample Input 1\n\n4 3\n1 2\n2 3\n1 4\n\nSample Output 1\n\n2\n2\n1\n1\n\nCity 1 is connected to the 1-st and 3-rd roads.\n\nCity 2 is connected to the 1-st and 2-nd roads.\n\nCity 3 is connected to the 2-nd road.\n\nCity 4 is connected to the 3-rd road.\n\nSample Input 2\n\n2 5\n1 2\n2 1\n1 2\n2 1\n1 2\n\nSample Output 2\n\n5\n5\n\nSample Input 3\n\n8 8\n1 2\n3 4\n1 5\n2 8\n3 7\n5 2\n4 1\n6 8\n\nSample Output 3\n\n3\n3\n2\n2\n2\n1\n1\n2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 373, "cpu_time_ms": 17, "memory_kb": 24400}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s377398368", "group_id": "codeNet:p03721", "input_text": "(let* ((n (read))\n (k (read))\n (ans (make-array (list n))))\n\n (loop for i below n do\n (setf (aref ans i) (list (read) (read)))\n )\n (setf ans (sort ans #'< :key #'car))\n\n (loop for i below n do\n (if (> k (second (aref ans i)))\n (decf k (second (aref ans i)))\n (progn\n (decf k (second (aref ans i)))\n (princ (car (aref ans i)))\n (return)\n )\n )\n )\n)", "language": "Lisp", "metadata": {"date": 1595885599, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03721.html", "problem_id": "p03721", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03721/input.txt", "sample_output_relpath": "derived/input_output/data/p03721/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03721/Lisp/s377398368.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s377398368", "user_id": "u136500538"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let* ((n (read))\n (k (read))\n (ans (make-array (list n))))\n\n (loop for i below n do\n (setf (aref ans i) (list (read) (read)))\n )\n (setf ans (sort ans #'< :key #'car))\n\n (loop for i below n do\n (if (> k (second (aref ans i)))\n (decf k (second (aref ans i)))\n (progn\n (decf k (second (aref ans i)))\n (princ (car (aref ans i)))\n (return)\n )\n )\n )\n)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere is an empty array.\nThe following N operations will be performed to insert integers into the array.\nIn the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array.\nFind the K-th smallest integer in the array after the N operations.\nFor example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.\n\nConstraints\n\n1≤N≤10^5\n\n1≤a_i,b_i≤10^5\n\n1≤K≤b_1…+…b_n\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\na_1 b_1\n:\na_N b_N\n\nOutput\n\nPrint the K-th smallest integer in the array after the N operations.\n\nSample Input 1\n\n3 4\n1 1\n2 2\n3 3\n\nSample Output 1\n\n3\n\nThe resulting array is the same as the one in the problem statement.\n\nSample Input 2\n\n10 500000\n1 100000\n1 100000\n1 100000\n1 100000\n1 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n\nSample Output 2\n\n1", "sample_input": "3 4\n1 1\n2 2\n3 3\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03721", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere is an empty array.\nThe following N operations will be performed to insert integers into the array.\nIn the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array.\nFind the K-th smallest integer in the array after the N operations.\nFor example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.\n\nConstraints\n\n1≤N≤10^5\n\n1≤a_i,b_i≤10^5\n\n1≤K≤b_1…+…b_n\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\na_1 b_1\n:\na_N b_N\n\nOutput\n\nPrint the K-th smallest integer in the array after the N operations.\n\nSample Input 1\n\n3 4\n1 1\n2 2\n3 3\n\nSample Output 1\n\n3\n\nThe resulting array is the same as the one in the problem statement.\n\nSample Input 2\n\n10 500000\n1 100000\n1 100000\n1 100000\n1 100000\n1 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n\nSample Output 2\n\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 466, "cpu_time_ms": 247, "memory_kb": 80816}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s210199298", "group_id": "codeNet:p03724", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (degs (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (incf (aref degs a))\n (incf (aref degs b))))\n (write-line (if (loop for x across degs\n always (evenp x))\n \"YES\"\n \"NO\"))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 4\n1 2\n2 4\n1 3\n3 4\n\"\n \"YES\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 5\n1 2\n3 5\n5 1\n3 4\n2 3\n\"\n \"NO\n\")))\n", "language": "Lisp", "metadata": {"date": 1589546031, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03724.html", "problem_id": "p03724", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03724/input.txt", "sample_output_relpath": "derived/input_output/data/p03724/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03724/Lisp/s210199298.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s210199298", "user_id": "u352600849"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (degs (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (incf (aref degs a))\n (incf (aref degs b))))\n (write-line (if (loop for x across degs\n always (evenp x))\n \"YES\"\n \"NO\"))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 4\n1 2\n2 4\n1 3\n3 4\n\"\n \"YES\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 5\n1 2\n3 5\n5 1\n3 4\n2 3\n\"\n \"NO\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nTakahashi is not good at problems about trees in programming contests, and Aoki is helping him practice.\n\nFirst, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge.\n\nThen, Aoki gave him M queries. The i-th of them is as follows:\n\nIncrement the number written at each edge along the path connecting vertices a_i and b_i, by one.\n\nAfter Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number.\nHowever, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries.\n\nDetermine whether there exists a tree that has the property mentioned by Takahashi.\n\nConstraints\n\n2 ≤ N ≤ 10^5\n\n1 ≤ M ≤ 10^5\n\n1 ≤ a_i,b_i ≤ N\n\na_i ≠ b_i\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\n:\na_M b_M\n\nOutput\n\nPrint YES if there exists a tree that has the property mentioned by Takahashi; print NO otherwise.\n\nSample Input 1\n\n4 4\n1 2\n2 4\n1 3\n3 4\n\nSample Output 1\n\nYES\n\nFor example, Takahashi's graph has the property mentioned by him if it has the following edges: 1-2, 1-3 and 1-4.\nIn this case, the number written at every edge will become 2.\n\nSample Input 2\n\n5 5\n1 2\n3 5\n5 1\n3 4\n2 3\n\nSample Output 2\n\nNO", "sample_input": "4 4\n1 2\n2 4\n1 3\n3 4\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03724", "source_text": "Score : 500 points\n\nProblem Statement\n\nTakahashi is not good at problems about trees in programming contests, and Aoki is helping him practice.\n\nFirst, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge.\n\nThen, Aoki gave him M queries. The i-th of them is as follows:\n\nIncrement the number written at each edge along the path connecting vertices a_i and b_i, by one.\n\nAfter Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number.\nHowever, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries.\n\nDetermine whether there exists a tree that has the property mentioned by Takahashi.\n\nConstraints\n\n2 ≤ N ≤ 10^5\n\n1 ≤ M ≤ 10^5\n\n1 ≤ a_i,b_i ≤ N\n\na_i ≠ b_i\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\n:\na_M b_M\n\nOutput\n\nPrint YES if there exists a tree that has the property mentioned by Takahashi; print NO otherwise.\n\nSample Input 1\n\n4 4\n1 2\n2 4\n1 3\n3 4\n\nSample Output 1\n\nYES\n\nFor example, Takahashi's graph has the property mentioned by him if it has the following edges: 1-2, 1-3 and 1-4.\nIn this case, the number written at every edge will become 2.\n\nSample Input 2\n\n5 5\n1 2\n3 5\n5 1\n3 4\n2 3\n\nSample Output 2\n\nNO", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5089, "cpu_time_ms": 284, "memory_kb": 24808}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s013291502", "group_id": "codeNet:p03726", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Queue with singly linked list\n;;;\n\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type list))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Removes and returns the element at the front of QUEUE. Returns NIL if QUEUE\nis empty.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline queue-peek))\n(defun queue-peek (queue)\n (car (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n;; 次数が1になった頂点を0に、その隣の頂点を1に塗って、隣接頂点の次数を1下げる?\n(defun main ()\n (let* ((n (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (degs (make-array n :element-type 'int32 :initial-element 0))\n (colors (make-array n :element-type 'int32 :initial-element -1)))\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (incf (aref degs a))\n (incf (aref degs b))\n (push a (aref graph b))\n (push b (aref graph a))))\n #>degs\n (labels ((yes () (write-line \"First\") (return-from main)))\n (let ((que0 (make-queue))\n (que1 (make-queue)))\n (loop for i below n\n when (= (aref degs i) 1)\n do (enqueue i que1)\n (decf (aref degs i))\n (setf (aref colors i) 1))\n (loop (when (and (queue-empty-p que0)\n (queue-empty-p que1))\n (return))\n (loop until (queue-empty-p que1)\n for v = (dequeue que1)\n do (dbg v degs colors)\n (assert (zerop (aref degs v)))\n (dolist (neighbor (aref graph v))\n (when (zerop (aref degs neighbor))\n (yes))\n (unless (zerop (aref degs neighbor))\n (setf (aref degs neighbor) 0\n (aref colors neighbor) 0)\n (enqueue neighbor que0))))\n #>que0\n (loop until (queue-empty-p que0)\n for v = (dequeue que0)\n do (dbg v degs colors)\n (dolist (neighbor (aref graph v))\n (unless (zerop (aref degs neighbor))\n (decf (aref degs neighbor))\n (when (= 1 (aref degs neighbor))\n (setf (aref colors neighbor) 1)\n (decf (aref degs neighbor))\n (enqueue neighbor que1)))))))\n (write-line \"Second\"))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2\n2 3\n\"\n \"First\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 2\n2 3\n2 4\n\"\n \"First\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n1 2\n2 3\n3 4\n2 5\n5 6\n\"\n \"Second\n\")))\n", "language": "Lisp", "metadata": {"date": 1589551109, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03726.html", "problem_id": "p03726", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03726/input.txt", "sample_output_relpath": "derived/input_output/data/p03726/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03726/Lisp/s013291502.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s013291502", "user_id": "u352600849"}, "prompt_components": {"gold_output": "First\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Queue with singly linked list\n;;;\n\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type list))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Removes and returns the element at the front of QUEUE. Returns NIL if QUEUE\nis empty.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline queue-peek))\n(defun queue-peek (queue)\n (car (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(in-package :cl-user)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n;; 次数が1になった頂点を0に、その隣の頂点を1に塗って、隣接頂点の次数を1下げる?\n(defun main ()\n (let* ((n (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (degs (make-array n :element-type 'int32 :initial-element 0))\n (colors (make-array n :element-type 'int32 :initial-element -1)))\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (incf (aref degs a))\n (incf (aref degs b))\n (push a (aref graph b))\n (push b (aref graph a))))\n #>degs\n (labels ((yes () (write-line \"First\") (return-from main)))\n (let ((que0 (make-queue))\n (que1 (make-queue)))\n (loop for i below n\n when (= (aref degs i) 1)\n do (enqueue i que1)\n (decf (aref degs i))\n (setf (aref colors i) 1))\n (loop (when (and (queue-empty-p que0)\n (queue-empty-p que1))\n (return))\n (loop until (queue-empty-p que1)\n for v = (dequeue que1)\n do (dbg v degs colors)\n (assert (zerop (aref degs v)))\n (dolist (neighbor (aref graph v))\n (when (zerop (aref degs neighbor))\n (yes))\n (unless (zerop (aref degs neighbor))\n (setf (aref degs neighbor) 0\n (aref colors neighbor) 0)\n (enqueue neighbor que0))))\n #>que0\n (loop until (queue-empty-p que0)\n for v = (dequeue que0)\n do (dbg v degs colors)\n (dolist (neighbor (aref graph v))\n (unless (zerop (aref degs neighbor))\n (decf (aref degs neighbor))\n (when (= 1 (aref degs neighbor))\n (setf (aref colors neighbor) 1)\n (decf (aref degs neighbor))\n (enqueue neighbor que1)))))))\n (write-line \"Second\"))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2\n2 3\n\"\n \"First\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 2\n2 3\n2 4\n\"\n \"First\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n1 2\n2 3\n3 4\n2 5\n5 6\n\"\n \"Second\n\")))\n", "problem_context": "Score : 900 points\n\nProblem Statement\n\nThere is a tree with N vertices numbered 1 through N.\nThe i-th of the N-1 edges connects vertices a_i and b_i.\n\nInitially, each vertex is uncolored.\n\nTakahashi and Aoki is playing a game by painting the vertices. In this game, they alternately perform the following operation, starting from Takahashi:\n\nSelect a vertex that is not painted yet.\n\nIf it is Takahashi who is performing this operation, paint the vertex white; paint it black if it is Aoki.\n\nThen, after all the vertices are colored, the following procedure takes place:\n\nRepaint every white vertex that is adjacent to a black vertex, in black.\n\nNote that all such white vertices are repainted simultaneously, not one at a time.\n\nIf there are still one or more white vertices remaining, Takahashi wins; if all the vertices are now black, Aoki wins.\nDetermine the winner of the game, assuming that both persons play optimally.\n\nConstraints\n\n2 ≤ N ≤ 10^5\n\n1 ≤ a_i,b_i ≤ N\n\na_i ≠ b_i\n\nThe input graph is a tree.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 b_1\n:\na_{N-1} b_{N-1}\n\nOutput\n\nPrint First if Takahashi wins; print Second if Aoki wins.\n\nSample Input 1\n\n3\n1 2\n2 3\n\nSample Output 1\n\nFirst\n\nBelow is a possible progress of the game:\n\nFirst, Takahashi paint vertex 2 white.\n\nThen, Aoki paint vertex 1 black.\n\nLastly, Takahashi paint vertex 3 white.\n\nIn this case, the colors of vertices 1, 2 and 3 after the final procedure are black, black and white, resulting in Takahashi's victory.\n\nSample Input 2\n\n4\n1 2\n2 3\n2 4\n\nSample Output 2\n\nFirst\n\nSample Input 3\n\n6\n1 2\n2 3\n3 4\n2 5\n5 6\n\nSample Output 3\n\nSecond", "sample_input": "3\n1 2\n2 3\n"}, "reference_outputs": ["First\n"], "source_document_id": "p03726", "source_text": "Score : 900 points\n\nProblem Statement\n\nThere is a tree with N vertices numbered 1 through N.\nThe i-th of the N-1 edges connects vertices a_i and b_i.\n\nInitially, each vertex is uncolored.\n\nTakahashi and Aoki is playing a game by painting the vertices. In this game, they alternately perform the following operation, starting from Takahashi:\n\nSelect a vertex that is not painted yet.\n\nIf it is Takahashi who is performing this operation, paint the vertex white; paint it black if it is Aoki.\n\nThen, after all the vertices are colored, the following procedure takes place:\n\nRepaint every white vertex that is adjacent to a black vertex, in black.\n\nNote that all such white vertices are repainted simultaneously, not one at a time.\n\nIf there are still one or more white vertices remaining, Takahashi wins; if all the vertices are now black, Aoki wins.\nDetermine the winner of the game, assuming that both persons play optimally.\n\nConstraints\n\n2 ≤ N ≤ 10^5\n\n1 ≤ a_i,b_i ≤ N\n\na_i ≠ b_i\n\nThe input graph is a tree.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 b_1\n:\na_{N-1} b_{N-1}\n\nOutput\n\nPrint First if Takahashi wins; print Second if Aoki wins.\n\nSample Input 1\n\n3\n1 2\n2 3\n\nSample Output 1\n\nFirst\n\nBelow is a possible progress of the game:\n\nFirst, Takahashi paint vertex 2 white.\n\nThen, Aoki paint vertex 1 black.\n\nLastly, Takahashi paint vertex 3 white.\n\nIn this case, the colors of vertices 1, 2 and 3 after the final procedure are black, black and white, resulting in Takahashi's victory.\n\nSample Input 2\n\n4\n1 2\n2 3\n2 4\n\nSample Output 2\n\nFirst\n\nSample Input 3\n\n6\n1 2\n2 3\n3 4\n2 5\n5 6\n\nSample Output 3\n\nSecond", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8153, "cpu_time_ms": 150, "memory_kb": 26600}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s960485718", "group_id": "codeNet:p03729", "input_text": "(let ((a (read))\n\t(b (read))\n\t(c (read))\n\t(ans \"YES\"))\n\t\n\t(if (char= (char (string a) (- (length (string a)) 1)) (char (string b) 0))\n\t\t(if (not (char= (char (string b) (- (length (string b)) 1)) (char (string c) 0)))\n\t\t\t(setq ans \"NO\")\n\t\t)\n\t\t(setq ans \"NO\")\n\t)\n\t(format t \"~A~%\" ans)\n)", "language": "Lisp", "metadata": {"date": 1599518757, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03729.html", "problem_id": "p03729", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03729/input.txt", "sample_output_relpath": "derived/input_output/data/p03729/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03729/Lisp/s960485718.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s960485718", "user_id": "u136500538"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(let ((a (read))\n\t(b (read))\n\t(c (read))\n\t(ans \"YES\"))\n\t\n\t(if (char= (char (string a) (- (length (string a)) 1)) (char (string b) 0))\n\t\t(if (not (char= (char (string b) (- (length (string b)) 1)) (char (string c) 0)))\n\t\t\t(setq ans \"NO\")\n\t\t)\n\t\t(setq ans \"NO\")\n\t)\n\t(format t \"~A~%\" ans)\n)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given three strings A, B and C. Check whether they form a word chain.\n\nMore formally, determine whether both of the following are true:\n\nThe last character in A and the initial character in B are the same.\n\nThe last character in B and the initial character in C are the same.\n\nIf both are true, print YES. Otherwise, print NO.\n\nConstraints\n\nA, B and C are all composed of lowercase English letters (a - z).\n\n1 ≤ |A|, |B|, |C| ≤ 10, where |A|, |B| and |C| are the lengths of A, B and C, respectively.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint YES or NO.\n\nSample Input 1\n\nrng gorilla apple\n\nSample Output 1\n\nYES\n\nThey form a word chain.\n\nSample Input 2\n\nyakiniku unagi sushi\n\nSample Output 2\n\nNO\n\nA and B form a word chain, but B and C do not.\n\nSample Input 3\n\na a a\n\nSample Output 3\n\nYES\n\nSample Input 4\n\naaaaaaaaab aaaaaaaaaa aaaaaaaaab\n\nSample Output 4\n\nNO", "sample_input": "rng gorilla apple\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03729", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given three strings A, B and C. Check whether they form a word chain.\n\nMore formally, determine whether both of the following are true:\n\nThe last character in A and the initial character in B are the same.\n\nThe last character in B and the initial character in C are the same.\n\nIf both are true, print YES. Otherwise, print NO.\n\nConstraints\n\nA, B and C are all composed of lowercase English letters (a - z).\n\n1 ≤ |A|, |B|, |C| ≤ 10, where |A|, |B| and |C| are the lengths of A, B and C, respectively.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint YES or NO.\n\nSample Input 1\n\nrng gorilla apple\n\nSample Output 1\n\nYES\n\nThey form a word chain.\n\nSample Input 2\n\nyakiniku unagi sushi\n\nSample Output 2\n\nNO\n\nA and B form a word chain, but B and C do not.\n\nSample Input 3\n\na a a\n\nSample Output 3\n\nYES\n\nSample Input 4\n\naaaaaaaaab aaaaaaaaaa aaaaaaaaab\n\nSample Output 4\n\nNO", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 286, "cpu_time_ms": 16, "memory_kb": 23668}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s289118484", "group_id": "codeNet:p03729", "input_text": "(let ((a (read))\n\t(b (read))\n\t(c (read))\n\t(ans \"Yes\"))\n\t\n\t(if (char= (char (string a) (- (length (string a)) 1)) (char (string b) 0))\n\t\t(if (not (char= (char (string b) (- (length (string b)) 1)) (char (string c) 0)))\n\t\t\t(setq ans \"No\")\n\t\t)\n\t\t(setq ans \"No\")\n\t)\n\t(format t \"~A~%\" ans)\n)", "language": "Lisp", "metadata": {"date": 1599518692, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03729.html", "problem_id": "p03729", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03729/input.txt", "sample_output_relpath": "derived/input_output/data/p03729/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03729/Lisp/s289118484.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s289118484", "user_id": "u136500538"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(let ((a (read))\n\t(b (read))\n\t(c (read))\n\t(ans \"Yes\"))\n\t\n\t(if (char= (char (string a) (- (length (string a)) 1)) (char (string b) 0))\n\t\t(if (not (char= (char (string b) (- (length (string b)) 1)) (char (string c) 0)))\n\t\t\t(setq ans \"No\")\n\t\t)\n\t\t(setq ans \"No\")\n\t)\n\t(format t \"~A~%\" ans)\n)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given three strings A, B and C. Check whether they form a word chain.\n\nMore formally, determine whether both of the following are true:\n\nThe last character in A and the initial character in B are the same.\n\nThe last character in B and the initial character in C are the same.\n\nIf both are true, print YES. Otherwise, print NO.\n\nConstraints\n\nA, B and C are all composed of lowercase English letters (a - z).\n\n1 ≤ |A|, |B|, |C| ≤ 10, where |A|, |B| and |C| are the lengths of A, B and C, respectively.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint YES or NO.\n\nSample Input 1\n\nrng gorilla apple\n\nSample Output 1\n\nYES\n\nThey form a word chain.\n\nSample Input 2\n\nyakiniku unagi sushi\n\nSample Output 2\n\nNO\n\nA and B form a word chain, but B and C do not.\n\nSample Input 3\n\na a a\n\nSample Output 3\n\nYES\n\nSample Input 4\n\naaaaaaaaab aaaaaaaaaa aaaaaaaaab\n\nSample Output 4\n\nNO", "sample_input": "rng gorilla apple\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03729", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given three strings A, B and C. Check whether they form a word chain.\n\nMore formally, determine whether both of the following are true:\n\nThe last character in A and the initial character in B are the same.\n\nThe last character in B and the initial character in C are the same.\n\nIf both are true, print YES. Otherwise, print NO.\n\nConstraints\n\nA, B and C are all composed of lowercase English letters (a - z).\n\n1 ≤ |A|, |B|, |C| ≤ 10, where |A|, |B| and |C| are the lengths of A, B and C, respectively.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint YES or NO.\n\nSample Input 1\n\nrng gorilla apple\n\nSample Output 1\n\nYES\n\nThey form a word chain.\n\nSample Input 2\n\nyakiniku unagi sushi\n\nSample Output 2\n\nNO\n\nA and B form a word chain, but B and C do not.\n\nSample Input 3\n\na a a\n\nSample Output 3\n\nYES\n\nSample Input 4\n\naaaaaaaaab aaaaaaaaaa aaaaaaaaab\n\nSample Output 4\n\nNO", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 286, "cpu_time_ms": 17, "memory_kb": 23540}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s711971933", "group_id": "codeNet:p03729", "input_text": "(let ((a (read))\n (b (read))\n (c (read)))\n\n (defun get-f (x)\n (car (concatenate 'list (symbol-name x))))\n\n (defun get-b (y)\n (car (reverse (concatenate 'list (symbol-name y)))))\n\n\n (format t \"~A~%\"\n (if (and (char= (get-b a) (get-f b)) (char= (get-b b) (get-f c)))\n 'yes\n 'no)))\n", "language": "Lisp", "metadata": {"date": 1594844602, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03729.html", "problem_id": "p03729", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03729/input.txt", "sample_output_relpath": "derived/input_output/data/p03729/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03729/Lisp/s711971933.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s711971933", "user_id": "u336541610"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (c (read)))\n\n (defun get-f (x)\n (car (concatenate 'list (symbol-name x))))\n\n (defun get-b (y)\n (car (reverse (concatenate 'list (symbol-name y)))))\n\n\n (format t \"~A~%\"\n (if (and (char= (get-b a) (get-f b)) (char= (get-b b) (get-f c)))\n 'yes\n 'no)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given three strings A, B and C. Check whether they form a word chain.\n\nMore formally, determine whether both of the following are true:\n\nThe last character in A and the initial character in B are the same.\n\nThe last character in B and the initial character in C are the same.\n\nIf both are true, print YES. Otherwise, print NO.\n\nConstraints\n\nA, B and C are all composed of lowercase English letters (a - z).\n\n1 ≤ |A|, |B|, |C| ≤ 10, where |A|, |B| and |C| are the lengths of A, B and C, respectively.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint YES or NO.\n\nSample Input 1\n\nrng gorilla apple\n\nSample Output 1\n\nYES\n\nThey form a word chain.\n\nSample Input 2\n\nyakiniku unagi sushi\n\nSample Output 2\n\nNO\n\nA and B form a word chain, but B and C do not.\n\nSample Input 3\n\na a a\n\nSample Output 3\n\nYES\n\nSample Input 4\n\naaaaaaaaab aaaaaaaaaa aaaaaaaaab\n\nSample Output 4\n\nNO", "sample_input": "rng gorilla apple\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03729", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given three strings A, B and C. Check whether they form a word chain.\n\nMore formally, determine whether both of the following are true:\n\nThe last character in A and the initial character in B are the same.\n\nThe last character in B and the initial character in C are the same.\n\nIf both are true, print YES. Otherwise, print NO.\n\nConstraints\n\nA, B and C are all composed of lowercase English letters (a - z).\n\n1 ≤ |A|, |B|, |C| ≤ 10, where |A|, |B| and |C| are the lengths of A, B and C, respectively.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint YES or NO.\n\nSample Input 1\n\nrng gorilla apple\n\nSample Output 1\n\nYES\n\nThey form a word chain.\n\nSample Input 2\n\nyakiniku unagi sushi\n\nSample Output 2\n\nNO\n\nA and B form a word chain, but B and C do not.\n\nSample Input 3\n\na a a\n\nSample Output 3\n\nYES\n\nSample Input 4\n\naaaaaaaaab aaaaaaaaaa aaaaaaaaab\n\nSample Output 4\n\nNO", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 329, "cpu_time_ms": 18, "memory_kb": 23524}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s477878194", "group_id": "codeNet:p03729", "input_text": "(setq a(concatenate 'list(string(read))))\n(setq b(concatenate 'list(string(read))))\n(setq c(concatenate 'list(string(read))))\n(princ(if(and(char=(nth(1-(length a))a)(first b))(char=(nth(1-(length b))b)(first c)))\"YES\"\"NO\"))", "language": "Lisp", "metadata": {"date": 1528286651, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03729.html", "problem_id": "p03729", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03729/input.txt", "sample_output_relpath": "derived/input_output/data/p03729/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03729/Lisp/s477878194.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s477878194", "user_id": "u657913472"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(setq a(concatenate 'list(string(read))))\n(setq b(concatenate 'list(string(read))))\n(setq c(concatenate 'list(string(read))))\n(princ(if(and(char=(nth(1-(length a))a)(first b))(char=(nth(1-(length b))b)(first c)))\"YES\"\"NO\"))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given three strings A, B and C. Check whether they form a word chain.\n\nMore formally, determine whether both of the following are true:\n\nThe last character in A and the initial character in B are the same.\n\nThe last character in B and the initial character in C are the same.\n\nIf both are true, print YES. Otherwise, print NO.\n\nConstraints\n\nA, B and C are all composed of lowercase English letters (a - z).\n\n1 ≤ |A|, |B|, |C| ≤ 10, where |A|, |B| and |C| are the lengths of A, B and C, respectively.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint YES or NO.\n\nSample Input 1\n\nrng gorilla apple\n\nSample Output 1\n\nYES\n\nThey form a word chain.\n\nSample Input 2\n\nyakiniku unagi sushi\n\nSample Output 2\n\nNO\n\nA and B form a word chain, but B and C do not.\n\nSample Input 3\n\na a a\n\nSample Output 3\n\nYES\n\nSample Input 4\n\naaaaaaaaab aaaaaaaaaa aaaaaaaaab\n\nSample Output 4\n\nNO", "sample_input": "rng gorilla apple\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03729", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given three strings A, B and C. Check whether they form a word chain.\n\nMore formally, determine whether both of the following are true:\n\nThe last character in A and the initial character in B are the same.\n\nThe last character in B and the initial character in C are the same.\n\nIf both are true, print YES. Otherwise, print NO.\n\nConstraints\n\nA, B and C are all composed of lowercase English letters (a - z).\n\n1 ≤ |A|, |B|, |C| ≤ 10, where |A|, |B| and |C| are the lengths of A, B and C, respectively.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint YES or NO.\n\nSample Input 1\n\nrng gorilla apple\n\nSample Output 1\n\nYES\n\nThey form a word chain.\n\nSample Input 2\n\nyakiniku unagi sushi\n\nSample Output 2\n\nNO\n\nA and B form a word chain, but B and C do not.\n\nSample Input 3\n\na a a\n\nSample Output 3\n\nYES\n\nSample Input 4\n\naaaaaaaaab aaaaaaaaaa aaaaaaaaab\n\nSample Output 4\n\nNO", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 223, "cpu_time_ms": 25, "memory_kb": 4712}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s218078114", "group_id": "codeNet:p03730", "input_text": "(let((a(read))(b(read))(c(read)))(princ(if(>(loop for i from 1 to b count(=(mod(* i a)b)c))0)\"YES\"\"NO\")))", "language": "Lisp", "metadata": {"date": 1534990490, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03730.html", "problem_id": "p03730", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03730/input.txt", "sample_output_relpath": "derived/input_output/data/p03730/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03730/Lisp/s218078114.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s218078114", "user_id": "u657913472"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(let((a(read))(b(read))(c(read)))(princ(if(>(loop for i from 1 to b count(=(mod(* i a)b)c))0)\"YES\"\"NO\")))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe ask you to select some number of positive integers, and calculate the sum of them.\n\nIt is allowed to select as many integers as you like, and as large integers as you wish.\nYou have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer.\n\nYour objective is to make the sum congruent to C modulo B.\nDetermine whether this is possible.\n\nIf the objective is achievable, print YES. Otherwise, print NO.\n\nConstraints\n\n1 ≤ A ≤ 100\n\n1 ≤ B ≤ 100\n\n0 ≤ C < B\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint YES or NO.\n\nSample Input 1\n\n7 5 1\n\nSample Output 1\n\nYES\n\nFor example, if you select 7 and 14, the sum 21 is congruent to 1 modulo 5.\n\nSample Input 2\n\n2 2 1\n\nSample Output 2\n\nNO\n\nThe sum of even numbers, no matter how many, is never odd.\n\nSample Input 3\n\n1 100 97\n\nSample Output 3\n\nYES\n\nYou can select 97, since you may select multiples of 1, that is, all integers.\n\nSample Input 4\n\n40 98 58\n\nSample Output 4\n\nYES\n\nSample Input 5\n\n77 42 36\n\nSample Output 5\n\nNO", "sample_input": "7 5 1\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03730", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe ask you to select some number of positive integers, and calculate the sum of them.\n\nIt is allowed to select as many integers as you like, and as large integers as you wish.\nYou have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer.\n\nYour objective is to make the sum congruent to C modulo B.\nDetermine whether this is possible.\n\nIf the objective is achievable, print YES. Otherwise, print NO.\n\nConstraints\n\n1 ≤ A ≤ 100\n\n1 ≤ B ≤ 100\n\n0 ≤ C < B\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint YES or NO.\n\nSample Input 1\n\n7 5 1\n\nSample Output 1\n\nYES\n\nFor example, if you select 7 and 14, the sum 21 is congruent to 1 modulo 5.\n\nSample Input 2\n\n2 2 1\n\nSample Output 2\n\nNO\n\nThe sum of even numbers, no matter how many, is never odd.\n\nSample Input 3\n\n1 100 97\n\nSample Output 3\n\nYES\n\nYou can select 97, since you may select multiples of 1, that is, all integers.\n\nSample Input 4\n\n40 98 58\n\nSample Output 4\n\nYES\n\nSample Input 5\n\n77 42 36\n\nSample Output 5\n\nNO", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 105, "cpu_time_ms": 29, "memory_kb": 4964}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s906064606", "group_id": "codeNet:p03736", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun %concat-name (&rest args)\n (if (cdr args)\n (format nil \"~A-~A\"\n (car args)\n (apply #'%concat-name (cdr args)))\n (car args)))\n\n (defun %concat+name+ (&rest args)\n (format nil \"+~A+\" (apply #'%concat-name args))))\n\n(defmacro define-cons-pack (name &rest slot-descriptions)\n (assert slot-descriptions () \"~A has no slots.\" name)\n (labels ((extract-62bit-slots (list)\n (let ((position 0))\n (loop for (slot-name slot-size) in list\n while (<= (+ position slot-size) 62)\n collect (list slot-name slot-size position)\n do (incf position slot-size)))))\n (let* ((packer-name (intern (%concat-name \"PACK\" name)))\n (unpacker-macro-name (intern (%concat-name \"WITH-UNPACKING\" name)))\n (new-value (gensym \"NEW-VALUE\"))\n (tmp1 (gensym))\n (tmp2 (gensym))\n (tmp (gensym))\n (car-slots (extract-62bit-slots slot-descriptions))\n (car-revslots (reverse car-slots))\n (cdr-slots (extract-62bit-slots (nthcdr (length car-slots) slot-descriptions)))\n (cdr-revslots (reverse cdr-slots))\n (slots (append car-slots cdr-slots)))\n (assert (= (+ (length car-slots) (length cdr-slots))\n (length slot-descriptions))\n () \"Size restriction iviolated: each cell <= 62 bit, total size <= 124 bit\")\n (unless (> (length cdr-slots) 0)\n (error \"Whole size is too small. Use DEFINE-INTEGER-PACK instead.\"))\n (let ((car-width (+ (second (first car-revslots))\n (third (first car-revslots))))\n (cdr-width (+ (second (first cdr-revslots))\n (third (first cdr-revslots)))))\n `(progn\n (deftype ,name () '(cons (unsigned-byte ,car-width) (unsigned-byte ,cdr-width)))\n ;; define most positive integer for every slot as constant\n ,@(loop for (slot-name slot-size _) in slots\n collect `(defconstant ,(intern (%concat+name+ \"MAX\" name slot-name))\n (- (ash 1 ,slot-size) 1)))\n ;; setter and getter\n ,@(loop for slot in car-slots\n for (slot-name slot-size slot-position) = slot\n for accessor-name = (intern (%concat-name name slot-name))\n append `((declaim (inline ,accessor-name (setf ,accessor-name)))\n (defun ,accessor-name (,name)\n (declare (type ,name ,name))\n (ldb (byte ,slot-size ,slot-position)\n (the (unsigned-byte ,car-width) (car ,name))))\n (defun (setf ,accessor-name) (,new-value ,name)\n (declare (type ,name ,name))\n (setf (ldb (byte ,slot-size ,slot-position)\n (the (unsigned-byte ,car-width) (car ,name)))\n ,new-value))))\n ,@(loop for slot in cdr-slots\n for (slot-name slot-size slot-position) = slot\n for accessor-name = (intern (%concat-name name slot-name))\n append `((declaim (inline ,accessor-name (setf ,accessor-name)))\n (defun ,accessor-name (,name)\n (declare (type ,name ,name))\n (ldb (byte ,slot-size ,slot-position)\n (the (unsigned-byte ,cdr-width) (cdr ,name))))\n (defun (setf ,accessor-name) (,new-value ,name)\n (declare (type ,name ,name))\n (setf (ldb (byte ,slot-size ,slot-position)\n (the (unsigned-byte ,cdr-width) (cdr ,name)))\n ,new-value))))\n ;; constructor\n (declaim (inline ,packer-name))\n (defun ,packer-name ,(loop for slot in slots collect (car slot))\n (declare ,@(loop for (slot-name slot-size slot-position) in slots\n collect `(type (unsigned-byte ,slot-size) ,slot-name)))\n (let ((,tmp1 ,(caar car-revslots))\n (,tmp2 ,(caar cdr-revslots)))\n (declare (type (unsigned-byte ,car-width) ,tmp1)\n (type (unsigned-byte ,cdr-width) ,tmp2))\n ,@(loop for (slot-name slot-size _) in (rest car-revslots)\n collect `(setq ,tmp1 (logxor ,slot-name\n (the (unsigned-byte ,car-width)\n (ash ,tmp1 ,slot-size)))))\n ,@(loop for (slot-name slot-size _) in (rest cdr-revslots)\n collect `(setq ,tmp2 (logxor ,slot-name\n (the (unsigned-byte ,cdr-width)\n (ash ,tmp2 ,slot-size)))))\n (cons ,tmp1 ,tmp2)))\n ;; destructuring-bind-style macro\n (defmacro ,unpacker-macro-name (vars ,name &body body)\n (check-type vars list)\n (assert (= (length vars) ,(length slots)))\n `(let* ((,',tmp ,,name)\n (,',tmp1 (car ,',tmp))\n (,',tmp2 (cdr ,',tmp)))\n (declare (type (unsigned-byte ,,car-width) ,',tmp1)\n (type (unsigned-byte ,,cdr-width) ,',tmp2))\n (let* ,(loop for var in vars\n for rest on ',car-slots\n for (slot-name slot-size _) = (car rest)\n collect `(,var\n (prog1 (the (unsigned-byte ,slot-size)\n (ldb (byte ,slot-size 0) ,',tmp1))\n ,@(when (cdr rest)\n `((setq ,',tmp1 (ash ,',tmp1 ,(- slot-size))))))))\n (let* ,(loop for var in (nthcdr ,(length car-slots) vars)\n for rest on ',cdr-slots\n for (slot-name slot-size _) = (car rest)\n collect `(,var\n (prog1 (the (unsigned-byte ,slot-size)\n (ldb (byte ,slot-size 0) ,',tmp2))\n ,@(when (cdr rest)\n `((setq ,',tmp2 (ash ,',tmp2 ,(- slot-size))))))))\n ,@body)))))))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 22 31 32 40 62 63 64)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;; Treap with implicit key for updating and querying interval.\n(define-cons-pack node (value- 40) (delta- 22) (value+ 40) (delta+ 22))\n\n(sb-int:defconstant-eqx +op-identity+\n (pack-node +max-node-value-+ +max-node-delta-+\n +max-node-value++ +max-node-delta++)\n #'equal)\n\n(declaim (inline op))\n(defun op (a b)\n (with-unpacking-node (a-value- a-delta- a-value+ a-delta+) a\n (with-unpacking-node (b-value- b-delta- b-value+ b-delta+) b\n (if (<= (- a-value- a-delta-) (- b-value- b-delta-))\n (if (<= (+ a-value+ a-delta+) (+ b-value+ b-delta+))\n (pack-node a-value- a-delta- a-value+ a-delta+)\n (pack-node a-value- a-delta- b-value+ b-delta+))\n (if (<= (+ a-value+ a-delta+) (+ b-value+ b-delta+))\n (pack-node b-value- b-delta- a-value+ a-delta+)\n (pack-node b-value- b-delta- b-value+ b-delta+))))))\n\n(defconstant +updater-identity+ 0)\n\n(declaim (inline updater-op))\n(defun updater-op (a b)\n \"Is the operator to compute and update LAZY value. A is the current LAZY value\nand B is operand.\"\n (declare (uint40 a b))\n (+ a b))\n\n(declaim (inline modifier-op))\n(defun modifier-op (a b size)\n \"Is the operator to update ACCUMULATOR (and VALUE) based on LAZY value. A is\nthe current ACCUMULATOR value and B is the LAZY value. SIZE is the length of the\nspecified interval.\"\n (declare (ignorable size))\n (with-unpacking-node (a-value- a-delta- a-value+ a-delta+) a\n (pack-node (min +max-node-value-+ (+ a-value- b))\n a-delta-\n (min +max-node-value++ (+ a-value+ b))\n a-delta+)))\n\n(defstruct (itreap (:constructor %make-itreap (value priority &key left right (count 1) (accumulator value) (lazy +updater-identity+)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +op-identity+ :type node)\n (accumulator +op-identity+ :type node)\n (lazy +updater-identity+ :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (integer 0 #.most-positive-fixnum)) ; size of (sub)treap\n (left nil :type (or null itreap))\n (right nil :type (or null itreap)))\n\n(declaim (inline itreap-count))\n(defun itreap-count (itreap)\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-count itreap)\n 0))\n\n(declaim (inline itreap-accumulator))\n(defun itreap-accumulator (itreap)\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-accumulator itreap)\n +op-identity+))\n\n(declaim (inline update-count))\n(defun update-count (itreap)\n (declare (itreap itreap))\n (setf (%itreap-count itreap)\n (+ 1\n (itreap-count (%itreap-left itreap))\n (itreap-count (%itreap-right itreap)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (itreap)\n (declare (itreap itreap))\n (setf (%itreap-accumulator itreap)\n (if (%itreap-left itreap)\n (if (%itreap-right itreap)\n (let ((mid (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap))))\n (declare (dynamic-extent mid))\n (op mid (%itreap-accumulator (%itreap-right itreap))))\n (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap)))\n (if (%itreap-right itreap)\n (op (%itreap-value itreap)\n (%itreap-accumulator (%itreap-right itreap)))\n (%itreap-value itreap)))))\n\n(declaim (inline force-self))\n(defun force-self (itreap)\n (declare (itreap itreap))\n (update-count itreap)\n (update-accumulator itreap))\n\n(declaim (inline force-down))\n(defun force-down (itreap)\n (declare (itreap itreap))\n (unless (eql +updater-identity+ (%itreap-lazy itreap))\n (when (%itreap-left itreap)\n (setf (%itreap-lazy (%itreap-left itreap))\n (updater-op (%itreap-lazy (%itreap-left itreap))\n (%itreap-lazy itreap)))\n (setf (%itreap-accumulator (%itreap-left itreap))\n (modifier-op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-lazy itreap)\n (%itreap-count (%itreap-left itreap)))))\n (when (%itreap-right itreap)\n (setf (%itreap-lazy (%itreap-right itreap))\n (updater-op (%itreap-lazy (%itreap-right itreap))\n (%itreap-lazy itreap)))\n (setf (%itreap-accumulator (%itreap-right itreap))\n (modifier-op (%itreap-accumulator (%itreap-right itreap))\n (%itreap-lazy itreap)\n (%itreap-count (%itreap-right itreap)))))\n (setf (%itreap-value itreap)\n (modifier-op (%itreap-value itreap)\n (%itreap-lazy itreap)\n 1))\n (setf (%itreap-lazy itreap) +updater-identity+)))\n\n(defun itreap-split (itreap index)\n \"Destructively splits the ITREAP into two nodes [0, INDEX) and [INDEX, N), where N\n is the number of elements of the ITREAP.\"\n (declare #.OPT ((integer 0 #.most-positive-fixnum) index))\n (unless (<= index (itreap-count itreap))\n (error 'invalid-itreap-index-error :index index :itreap itreap))\n (labels ((recur (itreap ikey)\n (unless itreap\n (return-from itreap-split (values nil nil)))\n (force-down itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= ikey left-count)\n (multiple-value-bind (left right)\n (itreap-split (%itreap-left itreap) ikey)\n (setf (%itreap-left itreap) right)\n (force-self itreap)\n (values left itreap))\n (multiple-value-bind (left right)\n (itreap-split (%itreap-right itreap) (- ikey left-count 1))\n (setf (%itreap-right itreap) left)\n (force-self itreap)\n (values itreap right))))))\n (recur itreap index)))\n\n(defun itreap-merge (left right)\n \"Destructively merges two ITREAPs.\"\n (declare #.OPT ((or null itreap) left right))\n (cond ((null left) (when right (force-down right) (force-self right)) right)\n ((null right) (when left (force-down left) (force-self left)) left)\n (t (force-down left)\n (force-down right)\n (if (> (%itreap-priority left) (%itreap-priority right))\n (progn\n (setf (%itreap-right left)\n (itreap-merge (%itreap-right left) right))\n (force-self left)\n left)\n (progn\n (setf (%itreap-left right)\n (itreap-merge left (%itreap-left right)))\n (force-self right)\n right)))))\n\n(define-condition invalid-itreap-index-error (type-error)\n ((itreap :initarg :itreap :reader invalid-itreap-index-error-itreap)\n (index :initarg :index :reader invalid-itreap-index-error-index))\n (:report\n (lambda (condition stream)\n (let ((index (invalid-itreap-index-error-index condition)))\n (if (consp index)\n (format stream \"Invalid range [~W, ~W) for itreap ~W.\"\n (car index)\n (cdr index)\n (invalid-itreap-index-error-itreap condition))\n (format stream \"Invalid index ~W for itreap ~W.\"\n index\n (invalid-itreap-index-error-itreap condition)))))))\n\n(defun %heapify (top)\n \"Properly swaps the priorities of the node and its two children.\"\n (declare #.OPT)\n (when top\n (let ((high-priority-node top))\n (when (and (%itreap-left top)\n (> (%itreap-priority (%itreap-left top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-left top)))\n (when (and (%itreap-right top)\n (> (%itreap-priority (%itreap-right top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-right top)))\n (unless (eql high-priority-node top)\n (rotatef (%itreap-priority high-priority-node)\n (%itreap-priority top))\n (%heapify high-priority-node)))))\n\n(defun make-itreap (size)\n \"Makes a treap of SIZE in O(SIZE) time.\"\n (declare #.OPT)\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-itreap (cons (dpb mid (byte 22 40) +inf+)\n (dpb mid (byte 22 40) +inf+))\n (random most-positive-fixnum))))\n (setf (%itreap-left node) (build l mid))\n (setf (%itreap-right node) (build (+ mid 1) r))\n (%heapify node)\n (force-self node)\n node))))\n (build 0 size)))\n\n(defun (setf itreap-ref) (new-value itreap index)\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index index))\n (labels ((%set (itreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (force-down itreap)\n (prog1\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (cond ((< index left-count)\n (%set (%itreap-left itreap) index))\n ((> index left-count)\n (%set (%itreap-right itreap) (- index left-count 1)))\n (t (setf (%itreap-value itreap) new-value))))\n (force-self itreap))))\n (%set itreap index)\n new-value))\n\n(defun itreap-map (function itreap)\n \"Successively applies FUNCTION to ITREAP[0], ..., ITREAP[SIZE-1].\"\n (declare #.OPT (function function))\n (when itreap\n (force-down itreap)\n (itreap-map function (%itreap-left itreap))\n (funcall function (%itreap-value itreap))\n (itreap-map function (%itreap-right itreap))\n (force-self itreap)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n;; (defun itreap-pprint (itreap)\n;; (write-char #\\<)\n;; (itreap-map (lambda (x) (princ (caar x)) (write-char #\\ )) itreap)\n;; (write-char #\\>)\n;; (terpri))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (q (read))\n (a (- (read) 1))\n (b (- (read) 1))\n (xs (make-array q :element-type 'uint32))\n (itreap (make-itreap n)))\n (declare (uint32 n q a b))\n (dotimes (i q) (setf (aref xs i) (- (read-fixnum) 1)))\n (locally (declare (notinline pack-node))\n (setf (itreap-ref itreap a)\n (let ((value (abs (- (aref xs 0) b))))\n (pack-node value a value a))\n (itreap-ref itreap b)\n (let ((value (abs (- (aref xs 0) a))))\n (pack-node value b value b))))\n ;; #>itreap\n (do ((i 1 (+ i 1)))\n ((>= i q))\n (multiple-value-bind (itreap-l itreap-r) (itreap-split itreap (aref xs i))\n (let* ((left-query (itreap-accumulator itreap-l))\n (right-query (itreap-accumulator itreap-r))\n (value- (node-value- left-query))\n (delta- (node-delta- left-query))\n (value+ (node-value+ right-query))\n (delta+ (node-delta+ right-query))\n (new-value (min +inf+\n (+ (- value- delta-) (aref xs i))\n (- (+ value+ delta+) (aref xs i)))))\n (declare (uint40 value- value+ new-value)\n (uint22 delta- delta+))\n (setf itreap (itreap-merge itreap-l itreap-r))\n (setf (%itreap-lazy itreap) (abs (- (aref xs (- i 1)) (aref xs i))))\n (force-down itreap)\n (force-self itreap)\n (setf (itreap-ref itreap (aref xs (- i 1)))\n (pack-node new-value (aref xs (- i 1))\n new-value (aref xs (- i 1)))))))\n (let ((res most-positive-fixnum))\n (declare (uint62 res))\n (itreap-map (lambda (x) (setq res (min res (node-value- x)))) itreap)\n (println res))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1562972510, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03736.html", "problem_id": "p03736", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03736/input.txt", "sample_output_relpath": "derived/input_output/data/p03736/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03736/Lisp/s906064606.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s906064606", "user_id": "u352600849"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun %concat-name (&rest args)\n (if (cdr args)\n (format nil \"~A-~A\"\n (car args)\n (apply #'%concat-name (cdr args)))\n (car args)))\n\n (defun %concat+name+ (&rest args)\n (format nil \"+~A+\" (apply #'%concat-name args))))\n\n(defmacro define-cons-pack (name &rest slot-descriptions)\n (assert slot-descriptions () \"~A has no slots.\" name)\n (labels ((extract-62bit-slots (list)\n (let ((position 0))\n (loop for (slot-name slot-size) in list\n while (<= (+ position slot-size) 62)\n collect (list slot-name slot-size position)\n do (incf position slot-size)))))\n (let* ((packer-name (intern (%concat-name \"PACK\" name)))\n (unpacker-macro-name (intern (%concat-name \"WITH-UNPACKING\" name)))\n (new-value (gensym \"NEW-VALUE\"))\n (tmp1 (gensym))\n (tmp2 (gensym))\n (tmp (gensym))\n (car-slots (extract-62bit-slots slot-descriptions))\n (car-revslots (reverse car-slots))\n (cdr-slots (extract-62bit-slots (nthcdr (length car-slots) slot-descriptions)))\n (cdr-revslots (reverse cdr-slots))\n (slots (append car-slots cdr-slots)))\n (assert (= (+ (length car-slots) (length cdr-slots))\n (length slot-descriptions))\n () \"Size restriction iviolated: each cell <= 62 bit, total size <= 124 bit\")\n (unless (> (length cdr-slots) 0)\n (error \"Whole size is too small. Use DEFINE-INTEGER-PACK instead.\"))\n (let ((car-width (+ (second (first car-revslots))\n (third (first car-revslots))))\n (cdr-width (+ (second (first cdr-revslots))\n (third (first cdr-revslots)))))\n `(progn\n (deftype ,name () '(cons (unsigned-byte ,car-width) (unsigned-byte ,cdr-width)))\n ;; define most positive integer for every slot as constant\n ,@(loop for (slot-name slot-size _) in slots\n collect `(defconstant ,(intern (%concat+name+ \"MAX\" name slot-name))\n (- (ash 1 ,slot-size) 1)))\n ;; setter and getter\n ,@(loop for slot in car-slots\n for (slot-name slot-size slot-position) = slot\n for accessor-name = (intern (%concat-name name slot-name))\n append `((declaim (inline ,accessor-name (setf ,accessor-name)))\n (defun ,accessor-name (,name)\n (declare (type ,name ,name))\n (ldb (byte ,slot-size ,slot-position)\n (the (unsigned-byte ,car-width) (car ,name))))\n (defun (setf ,accessor-name) (,new-value ,name)\n (declare (type ,name ,name))\n (setf (ldb (byte ,slot-size ,slot-position)\n (the (unsigned-byte ,car-width) (car ,name)))\n ,new-value))))\n ,@(loop for slot in cdr-slots\n for (slot-name slot-size slot-position) = slot\n for accessor-name = (intern (%concat-name name slot-name))\n append `((declaim (inline ,accessor-name (setf ,accessor-name)))\n (defun ,accessor-name (,name)\n (declare (type ,name ,name))\n (ldb (byte ,slot-size ,slot-position)\n (the (unsigned-byte ,cdr-width) (cdr ,name))))\n (defun (setf ,accessor-name) (,new-value ,name)\n (declare (type ,name ,name))\n (setf (ldb (byte ,slot-size ,slot-position)\n (the (unsigned-byte ,cdr-width) (cdr ,name)))\n ,new-value))))\n ;; constructor\n (declaim (inline ,packer-name))\n (defun ,packer-name ,(loop for slot in slots collect (car slot))\n (declare ,@(loop for (slot-name slot-size slot-position) in slots\n collect `(type (unsigned-byte ,slot-size) ,slot-name)))\n (let ((,tmp1 ,(caar car-revslots))\n (,tmp2 ,(caar cdr-revslots)))\n (declare (type (unsigned-byte ,car-width) ,tmp1)\n (type (unsigned-byte ,cdr-width) ,tmp2))\n ,@(loop for (slot-name slot-size _) in (rest car-revslots)\n collect `(setq ,tmp1 (logxor ,slot-name\n (the (unsigned-byte ,car-width)\n (ash ,tmp1 ,slot-size)))))\n ,@(loop for (slot-name slot-size _) in (rest cdr-revslots)\n collect `(setq ,tmp2 (logxor ,slot-name\n (the (unsigned-byte ,cdr-width)\n (ash ,tmp2 ,slot-size)))))\n (cons ,tmp1 ,tmp2)))\n ;; destructuring-bind-style macro\n (defmacro ,unpacker-macro-name (vars ,name &body body)\n (check-type vars list)\n (assert (= (length vars) ,(length slots)))\n `(let* ((,',tmp ,,name)\n (,',tmp1 (car ,',tmp))\n (,',tmp2 (cdr ,',tmp)))\n (declare (type (unsigned-byte ,,car-width) ,',tmp1)\n (type (unsigned-byte ,,cdr-width) ,',tmp2))\n (let* ,(loop for var in vars\n for rest on ',car-slots\n for (slot-name slot-size _) = (car rest)\n collect `(,var\n (prog1 (the (unsigned-byte ,slot-size)\n (ldb (byte ,slot-size 0) ,',tmp1))\n ,@(when (cdr rest)\n `((setq ,',tmp1 (ash ,',tmp1 ,(- slot-size))))))))\n (let* ,(loop for var in (nthcdr ,(length car-slots) vars)\n for rest on ',cdr-slots\n for (slot-name slot-size _) = (car rest)\n collect `(,var\n (prog1 (the (unsigned-byte ,slot-size)\n (ldb (byte ,slot-size 0) ,',tmp2))\n ,@(when (cdr rest)\n `((setq ,',tmp2 (ash ,',tmp2 ,(- slot-size))))))))\n ,@body)))))))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 22 31 32 40 62 63 64)\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;; Treap with implicit key for updating and querying interval.\n(define-cons-pack node (value- 40) (delta- 22) (value+ 40) (delta+ 22))\n\n(sb-int:defconstant-eqx +op-identity+\n (pack-node +max-node-value-+ +max-node-delta-+\n +max-node-value++ +max-node-delta++)\n #'equal)\n\n(declaim (inline op))\n(defun op (a b)\n (with-unpacking-node (a-value- a-delta- a-value+ a-delta+) a\n (with-unpacking-node (b-value- b-delta- b-value+ b-delta+) b\n (if (<= (- a-value- a-delta-) (- b-value- b-delta-))\n (if (<= (+ a-value+ a-delta+) (+ b-value+ b-delta+))\n (pack-node a-value- a-delta- a-value+ a-delta+)\n (pack-node a-value- a-delta- b-value+ b-delta+))\n (if (<= (+ a-value+ a-delta+) (+ b-value+ b-delta+))\n (pack-node b-value- b-delta- a-value+ a-delta+)\n (pack-node b-value- b-delta- b-value+ b-delta+))))))\n\n(defconstant +updater-identity+ 0)\n\n(declaim (inline updater-op))\n(defun updater-op (a b)\n \"Is the operator to compute and update LAZY value. A is the current LAZY value\nand B is operand.\"\n (declare (uint40 a b))\n (+ a b))\n\n(declaim (inline modifier-op))\n(defun modifier-op (a b size)\n \"Is the operator to update ACCUMULATOR (and VALUE) based on LAZY value. A is\nthe current ACCUMULATOR value and B is the LAZY value. SIZE is the length of the\nspecified interval.\"\n (declare (ignorable size))\n (with-unpacking-node (a-value- a-delta- a-value+ a-delta+) a\n (pack-node (min +max-node-value-+ (+ a-value- b))\n a-delta-\n (min +max-node-value++ (+ a-value+ b))\n a-delta+)))\n\n(defstruct (itreap (:constructor %make-itreap (value priority &key left right (count 1) (accumulator value) (lazy +updater-identity+)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +op-identity+ :type node)\n (accumulator +op-identity+ :type node)\n (lazy +updater-identity+ :type fixnum)\n (priority 0 :type (integer 0 #.most-positive-fixnum))\n (count 1 :type (integer 0 #.most-positive-fixnum)) ; size of (sub)treap\n (left nil :type (or null itreap))\n (right nil :type (or null itreap)))\n\n(declaim (inline itreap-count))\n(defun itreap-count (itreap)\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-count itreap)\n 0))\n\n(declaim (inline itreap-accumulator))\n(defun itreap-accumulator (itreap)\n (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-accumulator itreap)\n +op-identity+))\n\n(declaim (inline update-count))\n(defun update-count (itreap)\n (declare (itreap itreap))\n (setf (%itreap-count itreap)\n (+ 1\n (itreap-count (%itreap-left itreap))\n (itreap-count (%itreap-right itreap)))))\n\n(declaim (inline update-accumulator))\n(defun update-accumulator (itreap)\n (declare (itreap itreap))\n (setf (%itreap-accumulator itreap)\n (if (%itreap-left itreap)\n (if (%itreap-right itreap)\n (let ((mid (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap))))\n (declare (dynamic-extent mid))\n (op mid (%itreap-accumulator (%itreap-right itreap))))\n (op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-value itreap)))\n (if (%itreap-right itreap)\n (op (%itreap-value itreap)\n (%itreap-accumulator (%itreap-right itreap)))\n (%itreap-value itreap)))))\n\n(declaim (inline force-self))\n(defun force-self (itreap)\n (declare (itreap itreap))\n (update-count itreap)\n (update-accumulator itreap))\n\n(declaim (inline force-down))\n(defun force-down (itreap)\n (declare (itreap itreap))\n (unless (eql +updater-identity+ (%itreap-lazy itreap))\n (when (%itreap-left itreap)\n (setf (%itreap-lazy (%itreap-left itreap))\n (updater-op (%itreap-lazy (%itreap-left itreap))\n (%itreap-lazy itreap)))\n (setf (%itreap-accumulator (%itreap-left itreap))\n (modifier-op (%itreap-accumulator (%itreap-left itreap))\n (%itreap-lazy itreap)\n (%itreap-count (%itreap-left itreap)))))\n (when (%itreap-right itreap)\n (setf (%itreap-lazy (%itreap-right itreap))\n (updater-op (%itreap-lazy (%itreap-right itreap))\n (%itreap-lazy itreap)))\n (setf (%itreap-accumulator (%itreap-right itreap))\n (modifier-op (%itreap-accumulator (%itreap-right itreap))\n (%itreap-lazy itreap)\n (%itreap-count (%itreap-right itreap)))))\n (setf (%itreap-value itreap)\n (modifier-op (%itreap-value itreap)\n (%itreap-lazy itreap)\n 1))\n (setf (%itreap-lazy itreap) +updater-identity+)))\n\n(defun itreap-split (itreap index)\n \"Destructively splits the ITREAP into two nodes [0, INDEX) and [INDEX, N), where N\n is the number of elements of the ITREAP.\"\n (declare #.OPT ((integer 0 #.most-positive-fixnum) index))\n (unless (<= index (itreap-count itreap))\n (error 'invalid-itreap-index-error :index index :itreap itreap))\n (labels ((recur (itreap ikey)\n (unless itreap\n (return-from itreap-split (values nil nil)))\n (force-down itreap)\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (if (<= ikey left-count)\n (multiple-value-bind (left right)\n (itreap-split (%itreap-left itreap) ikey)\n (setf (%itreap-left itreap) right)\n (force-self itreap)\n (values left itreap))\n (multiple-value-bind (left right)\n (itreap-split (%itreap-right itreap) (- ikey left-count 1))\n (setf (%itreap-right itreap) left)\n (force-self itreap)\n (values itreap right))))))\n (recur itreap index)))\n\n(defun itreap-merge (left right)\n \"Destructively merges two ITREAPs.\"\n (declare #.OPT ((or null itreap) left right))\n (cond ((null left) (when right (force-down right) (force-self right)) right)\n ((null right) (when left (force-down left) (force-self left)) left)\n (t (force-down left)\n (force-down right)\n (if (> (%itreap-priority left) (%itreap-priority right))\n (progn\n (setf (%itreap-right left)\n (itreap-merge (%itreap-right left) right))\n (force-self left)\n left)\n (progn\n (setf (%itreap-left right)\n (itreap-merge left (%itreap-left right)))\n (force-self right)\n right)))))\n\n(define-condition invalid-itreap-index-error (type-error)\n ((itreap :initarg :itreap :reader invalid-itreap-index-error-itreap)\n (index :initarg :index :reader invalid-itreap-index-error-index))\n (:report\n (lambda (condition stream)\n (let ((index (invalid-itreap-index-error-index condition)))\n (if (consp index)\n (format stream \"Invalid range [~W, ~W) for itreap ~W.\"\n (car index)\n (cdr index)\n (invalid-itreap-index-error-itreap condition))\n (format stream \"Invalid index ~W for itreap ~W.\"\n index\n (invalid-itreap-index-error-itreap condition)))))))\n\n(defun %heapify (top)\n \"Properly swaps the priorities of the node and its two children.\"\n (declare #.OPT)\n (when top\n (let ((high-priority-node top))\n (when (and (%itreap-left top)\n (> (%itreap-priority (%itreap-left top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-left top)))\n (when (and (%itreap-right top)\n (> (%itreap-priority (%itreap-right top))\n (%itreap-priority high-priority-node)))\n (setq high-priority-node (%itreap-right top)))\n (unless (eql high-priority-node top)\n (rotatef (%itreap-priority high-priority-node)\n (%itreap-priority top))\n (%heapify high-priority-node)))))\n\n(defun make-itreap (size)\n \"Makes a treap of SIZE in O(SIZE) time.\"\n (declare #.OPT)\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= l r)\n nil\n (let* ((mid (ash (+ l r) -1))\n (node (%make-itreap (cons (dpb mid (byte 22 40) +inf+)\n (dpb mid (byte 22 40) +inf+))\n (random most-positive-fixnum))))\n (setf (%itreap-left node) (build l mid))\n (setf (%itreap-right node) (build (+ mid 1) r))\n (%heapify node)\n (force-self node)\n node))))\n (build 0 size)))\n\n(defun (setf itreap-ref) (new-value itreap index)\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) index))\n (unless (< index (itreap-count itreap))\n (error 'invalid-itreap-index-error :itreap itreap :index index))\n (labels ((%set (itreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (force-down itreap)\n (prog1\n (let ((left-count (itreap-count (%itreap-left itreap))))\n (cond ((< index left-count)\n (%set (%itreap-left itreap) index))\n ((> index left-count)\n (%set (%itreap-right itreap) (- index left-count 1)))\n (t (setf (%itreap-value itreap) new-value))))\n (force-self itreap))))\n (%set itreap index)\n new-value))\n\n(defun itreap-map (function itreap)\n \"Successively applies FUNCTION to ITREAP[0], ..., ITREAP[SIZE-1].\"\n (declare #.OPT (function function))\n (when itreap\n (force-down itreap)\n (itreap-map function (%itreap-left itreap))\n (funcall function (%itreap-value itreap))\n (itreap-map function (%itreap-right itreap))\n (force-self itreap)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n;; (defun itreap-pprint (itreap)\n;; (write-char #\\<)\n;; (itreap-map (lambda (x) (princ (caar x)) (write-char #\\ )) itreap)\n;; (write-char #\\>)\n;; (terpri))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (q (read))\n (a (- (read) 1))\n (b (- (read) 1))\n (xs (make-array q :element-type 'uint32))\n (itreap (make-itreap n)))\n (declare (uint32 n q a b))\n (dotimes (i q) (setf (aref xs i) (- (read-fixnum) 1)))\n (locally (declare (notinline pack-node))\n (setf (itreap-ref itreap a)\n (let ((value (abs (- (aref xs 0) b))))\n (pack-node value a value a))\n (itreap-ref itreap b)\n (let ((value (abs (- (aref xs 0) a))))\n (pack-node value b value b))))\n ;; #>itreap\n (do ((i 1 (+ i 1)))\n ((>= i q))\n (multiple-value-bind (itreap-l itreap-r) (itreap-split itreap (aref xs i))\n (let* ((left-query (itreap-accumulator itreap-l))\n (right-query (itreap-accumulator itreap-r))\n (value- (node-value- left-query))\n (delta- (node-delta- left-query))\n (value+ (node-value+ right-query))\n (delta+ (node-delta+ right-query))\n (new-value (min +inf+\n (+ (- value- delta-) (aref xs i))\n (- (+ value+ delta+) (aref xs i)))))\n (declare (uint40 value- value+ new-value)\n (uint22 delta- delta+))\n (setf itreap (itreap-merge itreap-l itreap-r))\n (setf (%itreap-lazy itreap) (abs (- (aref xs (- i 1)) (aref xs i))))\n (force-down itreap)\n (force-self itreap)\n (setf (itreap-ref itreap (aref xs (- i 1)))\n (pack-node new-value (aref xs (- i 1))\n new-value (aref xs (- i 1)))))))\n (let ((res most-positive-fixnum))\n (declare (uint62 res))\n (itreap-map (lambda (x) (setq res (min res (node-value- x)))) itreap)\n (println res))))\n\n#-swank(main)\n", "problem_context": "Score : 900 points\n\nProblem Statement\n\nThere are N squares in a row. The squares are numbered 1, 2, ..., N from left to right.\n\nYou have two pieces, initially placed on square A and B, respectively.\nYou will be asked to process Q queries of the following kind, in the order received:\n\nGiven an integer x_i, move one of the two pieces of your choice to square x_i.\n\nHere, it takes you one second to move a piece one square.\nThat is, the time it takes to move a piece from square X to Y is |X-Y| seconds.\n\nYour objective is to process all the queries in the shortest possible time.\n\nYou may only move the pieces in response to queries, and you may not move both pieces at the same time.\nAlso, it is not allowed to rearrange the order in which queries are given.\nIt is, however, allowed to have both pieces in the same square at the same time.\n\nConstraints\n\n1 ≤ N, Q ≤ 200,000\n\n1 ≤ A, B ≤ N\n\n1 ≤ x_i ≤ N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q A B\nx_1 x_2 ... x_Q\n\nOutput\n\nLet the shortest possible time to process all the queries be X seconds. Print X.\n\nSample Input 1\n\n8 3 1 8\n3 5 1\n\nSample Output 1\n\n7\n\nAll the queries can be processed in seven seconds, by:\n\nmoving the piece at square 1 to 3\n\nmoving the piece at square 8 to 5\n\nmoving the piece at square 3 to 1\n\nSample Input 2\n\n9 2 1 9\n5 1\n\nSample Output 2\n\n4\n\nThe piece at square 9 should be moved first.\n\nSample Input 3\n\n9 2 1 9\n5 9\n\nSample Output 3\n\n4\n\nThe piece at square 1 should be moved first.\n\nSample Input 4\n\n11 16 8 1\n1 1 5 1 11 4 5 2 5 3 3 3 5 5 6 7\n\nSample Output 4\n\n21", "sample_input": "8 3 1 8\n3 5 1\n"}, "reference_outputs": ["7\n"], "source_document_id": "p03736", "source_text": "Score : 900 points\n\nProblem Statement\n\nThere are N squares in a row. The squares are numbered 1, 2, ..., N from left to right.\n\nYou have two pieces, initially placed on square A and B, respectively.\nYou will be asked to process Q queries of the following kind, in the order received:\n\nGiven an integer x_i, move one of the two pieces of your choice to square x_i.\n\nHere, it takes you one second to move a piece one square.\nThat is, the time it takes to move a piece from square X to Y is |X-Y| seconds.\n\nYour objective is to process all the queries in the shortest possible time.\n\nYou may only move the pieces in response to queries, and you may not move both pieces at the same time.\nAlso, it is not allowed to rearrange the order in which queries are given.\nIt is, however, allowed to have both pieces in the same square at the same time.\n\nConstraints\n\n1 ≤ N, Q ≤ 200,000\n\n1 ≤ A, B ≤ N\n\n1 ≤ x_i ≤ N\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q A B\nx_1 x_2 ... x_Q\n\nOutput\n\nLet the shortest possible time to process all the queries be X seconds. Print X.\n\nSample Input 1\n\n8 3 1 8\n3 5 1\n\nSample Output 1\n\n7\n\nAll the queries can be processed in seven seconds, by:\n\nmoving the piece at square 1 to 3\n\nmoving the piece at square 8 to 5\n\nmoving the piece at square 3 to 1\n\nSample Input 2\n\n9 2 1 9\n5 1\n\nSample Output 2\n\n4\n\nThe piece at square 9 should be moved first.\n\nSample Input 3\n\n9 2 1 9\n5 9\n\nSample Output 3\n\n4\n\nThe piece at square 1 should be moved first.\n\nSample Input 4\n\n11 16 8 1\n1 1 5 1 11 4 5 2 5 3 3 3 5 5 6 7\n\nSample Output 4\n\n21", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 21378, "cpu_time_ms": 959, "memory_kb": 81640}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s999916906", "group_id": "codeNet:p03739", "input_text": "(defun solver ()\n (let* ((n (read))\n (numv (make-array n :fill-pointer 0))\n (sum 0) (presum 0) (count 0))\n (loop repeat n\n do (vector-push (read) numv))\n (loop for x across numv\n do (incf sum x)\n (loop\n (cond ((and (zerop sum) (plusp presum))\n (decf sum) (incf count))\n ((and (zerop sum) (minusp presum))\n (incf sum) (incf count))\n ((and (plusp sum) (plusp presum))\n (decf sum) (incf count))\n ((and (plusp sum) (minusp presum))\n (return))\n ((and (minusp sum) (plusp presum))\n (return))\n ((and (minusp sum) (minusp presum))\n (incf sum) (incf count))\n (t (return))))\n (setf presum sum))\n (format t \"~A~%\" count)))\n\n(solver)", "language": "Lisp", "metadata": {"date": 1493271355, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03739.html", "problem_id": "p03739", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03739/input.txt", "sample_output_relpath": "derived/input_output/data/p03739/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03739/Lisp/s999916906.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s999916906", "user_id": "u183015556"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun solver ()\n (let* ((n (read))\n (numv (make-array n :fill-pointer 0))\n (sum 0) (presum 0) (count 0))\n (loop repeat n\n do (vector-push (read) numv))\n (loop for x across numv\n do (incf sum x)\n (loop\n (cond ((and (zerop sum) (plusp presum))\n (decf sum) (incf count))\n ((and (zerop sum) (minusp presum))\n (incf sum) (incf count))\n ((and (plusp sum) (plusp presum))\n (decf sum) (incf count))\n ((and (plusp sum) (minusp presum))\n (return))\n ((and (minusp sum) (plusp presum))\n (return))\n ((and (minusp sum) (minusp presum))\n (incf sum) (incf count))\n (t (return))))\n (setf presum sum))\n (format t \"~A~%\" count)))\n\n(solver)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given an integer sequence of length N. The i-th term in the sequence is a_i.\nIn one operation, you can select a term and either increment or decrement it by one.\n\nAt least how many operations are necessary to satisfy the following conditions?\n\nFor every i (1≤i≤n), the sum of the terms from the 1-st through i-th term is not zero.\n\nFor every i (1≤i≤n-1), the sign of the sum of the terms from the 1-st through i-th term, is different from the sign of the sum of the terms from the 1-st through (i+1)-th term.\n\nConstraints\n\n2 ≤ n ≤ 10^5\n\n|a_i| ≤ 10^9\n\nEach a_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\na_1 a_2 ... a_n\n\nOutput\n\nPrint the minimum necessary count of operations.\n\nSample Input 1\n\n4\n1 -3 1 0\n\nSample Output 1\n\n4\n\nFor example, the given sequence can be transformed into 1, -2, 2, -2 by four operations. The sums of the first one, two, three and four terms are 1, -1, 1 and -1, respectively, which satisfy the conditions.\n\nSample Input 2\n\n5\n3 -6 4 -5 7\n\nSample Output 2\n\n0\n\nThe given sequence already satisfies the conditions.\n\nSample Input 3\n\n6\n-1 4 3 2 -5 4\n\nSample Output 3\n\n8", "sample_input": "4\n1 -3 1 0\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03739", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given an integer sequence of length N. The i-th term in the sequence is a_i.\nIn one operation, you can select a term and either increment or decrement it by one.\n\nAt least how many operations are necessary to satisfy the following conditions?\n\nFor every i (1≤i≤n), the sum of the terms from the 1-st through i-th term is not zero.\n\nFor every i (1≤i≤n-1), the sign of the sum of the terms from the 1-st through i-th term, is different from the sign of the sum of the terms from the 1-st through (i+1)-th term.\n\nConstraints\n\n2 ≤ n ≤ 10^5\n\n|a_i| ≤ 10^9\n\nEach a_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\na_1 a_2 ... a_n\n\nOutput\n\nPrint the minimum necessary count of operations.\n\nSample Input 1\n\n4\n1 -3 1 0\n\nSample Output 1\n\n4\n\nFor example, the given sequence can be transformed into 1, -2, 2, -2 by four operations. The sums of the first one, two, three and four terms are 1, -1, 1 and -1, respectively, which satisfy the conditions.\n\nSample Input 2\n\n5\n3 -6 4 -5 7\n\nSample Output 2\n\n0\n\nThe given sequence already satisfies the conditions.\n\nSample Input 3\n\n6\n-1 4 3 2 -5 4\n\nSample Output 3\n\n8", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 904, "cpu_time_ms": 2105, "memory_kb": 57704}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s342870670", "group_id": "codeNet:p03742", "input_text": "(princ(if(<(abs(-(read)(read))2)\"Brown\"\"Alice\")", "language": "Lisp", "metadata": {"date": 1539258255, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03742.html", "problem_id": "p03742", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03742/input.txt", "sample_output_relpath": "derived/input_output/data/p03742/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03742/Lisp/s342870670.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s342870670", "user_id": "u657913472"}, "prompt_components": {"gold_output": "Brown\n", "input_to_evaluate": "(princ(if(<(abs(-(read)(read))2)\"Brown\"\"Alice\")", "problem_context": "Score : 500 points\n\nProblem Statement\n\nAlice and Brown loves games. Today, they will play the following game.\n\nIn this game, there are two piles initially consisting of X and Y stones, respectively.\nAlice and Bob alternately perform the following operation, starting from Alice:\n\nTake 2i stones from one of the piles. Then, throw away i of them, and put the remaining i in the other pile. Here, the integer i (1≤i) can be freely chosen as long as there is a sufficient number of stones in the pile.\n\nThe player who becomes unable to perform the operation, loses the game.\n\nGiven X and Y, determine the winner of the game, assuming that both players play optimally.\n\nConstraints\n\n0 ≤ X, Y ≤ 10^{18}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nPrint the winner: either Alice or Brown.\n\nSample Input 1\n\n2 1\n\nSample Output 1\n\nBrown\n\nAlice can do nothing but taking two stones from the pile containing two stones. As a result, the piles consist of zero and two stones, respectively. Then, Brown will take the two stones, and the piles will consist of one and zero stones, respectively. Alice will be unable to perform the operation anymore, which means Brown's victory.\n\nSample Input 2\n\n5 0\n\nSample Output 2\n\nAlice\n\nSample Input 3\n\n0 0\n\nSample Output 3\n\nBrown\n\nSample Input 4\n\n4 8\n\nSample Output 4\n\nAlice", "sample_input": "2 1\n"}, "reference_outputs": ["Brown\n"], "source_document_id": "p03742", "source_text": "Score : 500 points\n\nProblem Statement\n\nAlice and Brown loves games. Today, they will play the following game.\n\nIn this game, there are two piles initially consisting of X and Y stones, respectively.\nAlice and Bob alternately perform the following operation, starting from Alice:\n\nTake 2i stones from one of the piles. Then, throw away i of them, and put the remaining i in the other pile. Here, the integer i (1≤i) can be freely chosen as long as there is a sufficient number of stones in the pile.\n\nThe player who becomes unable to perform the operation, loses the game.\n\nGiven X and Y, determine the winner of the game, assuming that both players play optimally.\n\nConstraints\n\n0 ≤ X, Y ≤ 10^{18}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nPrint the winner: either Alice or Brown.\n\nSample Input 1\n\n2 1\n\nSample Output 1\n\nBrown\n\nAlice can do nothing but taking two stones from the pile containing two stones. As a result, the piles consist of zero and two stones, respectively. Then, Brown will take the two stones, and the piles will consist of one and zero stones, respectively. Alice will be unable to perform the operation anymore, which means Brown's victory.\n\nSample Input 2\n\n5 0\n\nSample Output 2\n\nAlice\n\nSample Input 3\n\n0 0\n\nSample Output 3\n\nBrown\n\nSample Input 4\n\n4 8\n\nSample Output 4\n\nAlice", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 47, "cpu_time_ms": 82, "memory_kb": 8928}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s528079561", "group_id": "codeNet:p03746", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"64MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n;; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (table (make-array n :element-type 'bit :initial-element 0)))\n (declare (uint32 n m))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (labels ((recur (v)\n (declare (uint32 v))\n (setf (aref table v) 1)\n (dolist (neighbor (aref graph v) (list v))\n (when (zerop (aref table neighbor))\n (return (cons v (recur neighbor)))))))\n (let* ((path1 (recur 0))\n (path2 (recur 0))\n (res (append (nreverse (cdr path1)) path2)))\n (println (length res))\n (with-buffered-stdout\n (loop with init = t\n for v in res\n do (if init\n (setq init nil)\n (write-char #\\ ))\n (write (+ v 1))))))))\n\n#-swank (main)\n\n", "language": "Lisp", "metadata": {"date": 1563225992, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03746.html", "problem_id": "p03746", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03746/input.txt", "sample_output_relpath": "derived/input_output/data/p03746/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03746/Lisp/s528079561.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s528079561", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n2 3 1 4\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"64MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n;; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (table (make-array n :element-type 'bit :initial-element 0)))\n (declare (uint32 n m))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (labels ((recur (v)\n (declare (uint32 v))\n (setf (aref table v) 1)\n (dolist (neighbor (aref graph v) (list v))\n (when (zerop (aref table neighbor))\n (return (cons v (recur neighbor)))))))\n (let* ((path1 (recur 0))\n (path2 (recur 0))\n (res (append (nreverse (cdr path1)) path2)))\n (println (length res))\n (with-buffered-stdout\n (loop with init = t\n for v in res\n do (if init\n (setq init nil)\n (write-char #\\ ))\n (write (+ v 1))))))))\n\n#-swank (main)\n\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nYou are given a connected undirected simple graph, which has N vertices and M edges.\nThe vertices are numbered 1 through N, and the edges are numbered 1 through M.\nEdge i connects vertices A_i and B_i.\nYour task is to find a path that satisfies the following conditions:\n\nThe path traverses two or more vertices.\n\nThe path does not traverse the same vertex more than once.\n\nA vertex directly connected to at least one of the endpoints of the path, is always contained in the path.\n\nIt can be proved that such a path always exists.\nAlso, if there are more than one solution, any of them will be accepted.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq A_i < B_i \\leq N\n\nThe given graph is connected and simple (that is, for every pair of vertices, there is at most one edge that directly connects them).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\nA_2 B_2\n:\nA_M B_M\n\nOutput\n\nFind one path that satisfies the conditions, and print it in the following format.\nIn the first line, print the count of the vertices contained in the path.\nIn the second line, print a space-separated list of the indices of the vertices, in order of appearance in the path.\n\nSample Input 1\n\n5 6\n1 3\n1 4\n2 3\n1 5\n3 5\n2 4\n\nSample Output 1\n\n4\n2 3 1 4\n\nThere are two vertices directly connected to vertex 2: vertices 3 and 4.\nThere are also two vertices directly connected to vertex 4: vertices 1 and 2.\nHence, the path 2 → 3 → 1 → 4 satisfies the conditions.\n\nSample Input 2\n\n7 8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n3 5\n2 6\n\nSample Output 2\n\n7\n1 2 3 4 5 6 7", "sample_input": "5 6\n1 3\n1 4\n2 3\n1 5\n3 5\n2 4\n"}, "reference_outputs": ["4\n2 3 1 4\n"], "source_document_id": "p03746", "source_text": "Score : 500 points\n\nProblem Statement\n\nYou are given a connected undirected simple graph, which has N vertices and M edges.\nThe vertices are numbered 1 through N, and the edges are numbered 1 through M.\nEdge i connects vertices A_i and B_i.\nYour task is to find a path that satisfies the following conditions:\n\nThe path traverses two or more vertices.\n\nThe path does not traverse the same vertex more than once.\n\nA vertex directly connected to at least one of the endpoints of the path, is always contained in the path.\n\nIt can be proved that such a path always exists.\nAlso, if there are more than one solution, any of them will be accepted.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n1 \\leq A_i < B_i \\leq N\n\nThe given graph is connected and simple (that is, for every pair of vertices, there is at most one edge that directly connects them).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\nA_2 B_2\n:\nA_M B_M\n\nOutput\n\nFind one path that satisfies the conditions, and print it in the following format.\nIn the first line, print the count of the vertices contained in the path.\nIn the second line, print a space-separated list of the indices of the vertices, in order of appearance in the path.\n\nSample Input 1\n\n5 6\n1 3\n1 4\n2 3\n1 5\n3 5\n2 4\n\nSample Output 1\n\n4\n2 3 1 4\n\nThere are two vertices directly connected to vertex 2: vertices 3 and 4.\nThere are also two vertices directly connected to vertex 4: vertices 1 and 2.\nHence, the path 2 → 3 → 1 → 4 satisfies the conditions.\n\nSample Input 2\n\n7 8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n3 5\n2 6\n\nSample Output 2\n\n7\n1 2 3 4 5 6 7", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4291, "cpu_time_ms": 130, "memory_kb": 30268}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s261332438", "group_id": "codeNet:p03747", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(declaim (inline count-collision))\n(defun count-collision (anticlock clock l time)\n (if (< (* 2 time) (mod (- anticlock clock) l))\n 0\n (let ((remain (- (* 2 time) (mod (- anticlock clock) l))))\n (+ 1 (floor remain l)))))\n\n(defun main ()\n (declare #.OPT (inline sort))\n (let* ((n (read))\n (l (read))\n (time (read))\n (inits (make-array n :element-type 'uint32))\n (dirs (make-array n :element-type 'bit)))\n (declare (uint32 n l time))\n (dotimes (i n) (setf (aref inits i) (read-fixnum)\n (aref dirs i) (mod (read-fixnum) 2)))\n (let* ((count0 (loop for i below n\n unless (= (aref dirs 0) (aref dirs i))\n sum (if (zerop (aref dirs 0))\n (count-collision (aref inits 0) (aref inits i) l time)\n (count-collision (aref inits i) (aref inits 0) l time))\n of-type uint32))\n (end-index (mod (if (zerop (aref dirs 0))\n (- count0)\n count0)\n n))\n (ends (make-array n :element-type 'uint32))\n (end0 (mod (+ (aref inits 0)\n (if (zerop (aref dirs 0))\n (- time)\n time))\n l)))\n (dotimes (i n)\n (setf (aref ends i)\n (mod (+ (aref inits i)\n (if (zerop (aref dirs i))\n (- time)\n time))\n l)))\n (setf ends (sort ends #'<))\n (let ((end0-pos (position end0 ends))\n (res (make-array n :element-type 'uint32)))\n (cond ((and (= (aref ends end0-pos) (aref ends (mod (+ end0-pos 1) n)))\n (= 1 (aref dirs 0)))\n (setf end0-pos (mod (+ end0-pos 1) n)))\n ((and (= (aref ends end0-pos) (aref ends (mod (- end0-pos 1) n)))\n (= 0 (aref dirs 0)))\n (setf end0-pos (mod (- end0-pos 1) n))))\n (let ((actual-index (mod (- end0-pos end-index) n)))\n (loop for i below n\n do (setf (aref res i)\n (aref ends (mod (+ actual-index i) n))))\n (map () #'println res))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1558653913, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03747.html", "problem_id": "p03747", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03747/input.txt", "sample_output_relpath": "derived/input_output/data/p03747/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03747/Lisp/s261332438.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s261332438", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n3\n0\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(declaim (inline count-collision))\n(defun count-collision (anticlock clock l time)\n (if (< (* 2 time) (mod (- anticlock clock) l))\n 0\n (let ((remain (- (* 2 time) (mod (- anticlock clock) l))))\n (+ 1 (floor remain l)))))\n\n(defun main ()\n (declare #.OPT (inline sort))\n (let* ((n (read))\n (l (read))\n (time (read))\n (inits (make-array n :element-type 'uint32))\n (dirs (make-array n :element-type 'bit)))\n (declare (uint32 n l time))\n (dotimes (i n) (setf (aref inits i) (read-fixnum)\n (aref dirs i) (mod (read-fixnum) 2)))\n (let* ((count0 (loop for i below n\n unless (= (aref dirs 0) (aref dirs i))\n sum (if (zerop (aref dirs 0))\n (count-collision (aref inits 0) (aref inits i) l time)\n (count-collision (aref inits i) (aref inits 0) l time))\n of-type uint32))\n (end-index (mod (if (zerop (aref dirs 0))\n (- count0)\n count0)\n n))\n (ends (make-array n :element-type 'uint32))\n (end0 (mod (+ (aref inits 0)\n (if (zerop (aref dirs 0))\n (- time)\n time))\n l)))\n (dotimes (i n)\n (setf (aref ends i)\n (mod (+ (aref inits i)\n (if (zerop (aref dirs i))\n (- time)\n time))\n l)))\n (setf ends (sort ends #'<))\n (let ((end0-pos (position end0 ends))\n (res (make-array n :element-type 'uint32)))\n (cond ((and (= (aref ends end0-pos) (aref ends (mod (+ end0-pos 1) n)))\n (= 1 (aref dirs 0)))\n (setf end0-pos (mod (+ end0-pos 1) n)))\n ((and (= (aref ends end0-pos) (aref ends (mod (- end0-pos 1) n)))\n (= 0 (aref dirs 0)))\n (setf end0-pos (mod (- end0-pos 1) n))))\n (let ((actual-index (mod (- end0-pos end-index) n)))\n (loop for i below n\n do (setf (aref res i)\n (aref ends (mod (+ actual-index i) n))))\n (map () #'println res))))))\n\n#-swank(main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nThere is a circle with a circumference of L.\nEach point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point.\nOn this circumference, there are N ants.\nThese ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i.\n\nThe N ants have just started walking.\nFor each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2.\nEvery ant walks at a constant speed of 1 per second.\nSometimes, two ants bump into each other.\nEach of these two ants will then turn around and start walking in the opposite direction.\n\nFor each ant, find its position after T seconds.\n\nConstraints\n\nAll input values are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq L \\leq 10^9\n\n1 \\leq T \\leq 10^9\n\n0 \\leq X_1 < X_2 < ... < X_N \\leq L - 1\n\n1 \\leq W_i \\leq 2\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN L T\nX_1 W_1\nX_2 W_2\n:\nX_N W_N\n\nOutput\n\nPrint N lines.\nThe i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive.\n\nSample Input 1\n\n3 8 3\n0 1\n3 2\n6 1\n\nSample Output 1\n\n1\n3\n0\n\n1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at coordinate 1.5.\n1 second after that, ant 1 and 3 bump into each other at coordinate 0.5.\n0.5 seconds after that, that is, 3 seconds after the ants start walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.\n\nSample Input 2\n\n4 20 9\n7 2\n9 1\n12 1\n18 1\n\nSample Output 2\n\n7\n18\n18\n1", "sample_input": "3 8 3\n0 1\n3 2\n6 1\n"}, "reference_outputs": ["1\n3\n0\n"], "source_document_id": "p03747", "source_text": "Score : 700 points\n\nProblem Statement\n\nThere is a circle with a circumference of L.\nEach point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point.\nOn this circumference, there are N ants.\nThese ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i.\n\nThe N ants have just started walking.\nFor each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2.\nEvery ant walks at a constant speed of 1 per second.\nSometimes, two ants bump into each other.\nEach of these two ants will then turn around and start walking in the opposite direction.\n\nFor each ant, find its position after T seconds.\n\nConstraints\n\nAll input values are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq L \\leq 10^9\n\n1 \\leq T \\leq 10^9\n\n0 \\leq X_1 < X_2 < ... < X_N \\leq L - 1\n\n1 \\leq W_i \\leq 2\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN L T\nX_1 W_1\nX_2 W_2\n:\nX_N W_N\n\nOutput\n\nPrint N lines.\nThe i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive.\n\nSample Input 1\n\n3 8 3\n0 1\n3 2\n6 1\n\nSample Output 1\n\n1\n3\n0\n\n1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at coordinate 1.5.\n1 second after that, ant 1 and 3 bump into each other at coordinate 0.5.\n0.5 seconds after that, that is, 3 seconds after the ants start walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.\n\nSample Input 2\n\n4 20 9\n7 2\n9 1\n12 1\n18 1\n\nSample Output 2\n\n7\n18\n18\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4705, "cpu_time_ms": 467, "memory_kb": 41704}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s902378783", "group_id": "codeNet:p03753", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/println-matrix\n (:use :cl)\n (:export #:println-matrix))\n(in-package :cp/println-matrix)\n\n(declaim (inline println-matrix))\n(defun println-matrix (array &key (separator #\\ ) (key #'identity) (writer #'write) (row-start 0) row-end (col-start 0) col-end)\n \"Prints a 2-dimensional array.\"\n (declare ((array * (* *)) array)\n ((integer 0 #.most-positive-fixnum) row-start col-start))\n (let ((row-end (or row-end (array-dimension array 0)))\n (col-end (or col-end (array-dimension array 1))))\n (declare ((integer 0 #.most-positive-fixnum) row-end col-end))\n (loop for i from row-start below row-end\n do (loop for j from col-start below col-end\n unless (= j col-start)\n do (princ separator)\n do (funcall writer (funcall key (aref array i j))))\n (terpri))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/println-matrix :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun test (n m &rest as)\n (let ((matrix (make-array (list n 7) :element-type 'base-char :initial-element #\\.)))\n (dotimes (i (* n 7))\n (when (member (mod i m) as)\n (setf (row-major-aref matrix i) #\\#)))\n (println-matrix matrix :separator \"\" :writer #'write-char)))\n\n(defun solve-small (n m as)\n (declare (uint31 n m)\n ((simple-array uint31 (*)) as))\n (let ((plan (make-array (list n 7) :element-type 'bit :initial-element 0))\n (res 0))\n (declare (uint62 res))\n (loop for a across as\n do (loop for i from a below (* n 7) by m\n do (setf (row-major-aref plan i) 1)))\n (dotimes (i n)\n (dotimes (j 7)\n (when (zerop (aref plan i j))\n (sb-int:named-let dfs ((i i) (j j))\n (labels ((visit (y x)\n (when (and (<= 0 y (- n 1))\n (<= 0 x 6))\n (dfs y x))))\n (when (zerop (aref plan i j))\n (setf (aref plan i j) 1)\n (visit (- i 1) j)\n (visit (+ i 1) j)\n (visit i (- j 1))\n (visit i (+ j 1)))))\n (incf res))))\n res))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (q (read))\n (as (make-array q :element-type 'uint31 :initial-element 0)))\n (dotimes (i q)\n (setf (aref as i) (read-fixnum)))\n (println\n (cond\n ((zerop (mod m 7))\n (let* ((period (floor m 7))\n (term1 (solve-small period m as))\n (term2 (solve-small (* 2 period) m as))\n (coef (- term2 term1))\n (intercept (- term1 coef)))\n (multiple-value-bind (quot rem) (floor n period)\n (dbg coef intercept)\n (+ intercept (* quot coef)\n (- (solve-small (+ period rem) m as) term1)))))\n ((<= n 10000)\n (solve1 n m as))\n (t (error \"Huh?\"))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"4\n\"\n (run \"7 7 3\n1 3 5\n\" nil)))\n (it.bese.fiveam:is\n (equal \"10\n\"\n (run \"10 14 8\n5 6 7 8 9 10 11 12\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1598330678, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03753.html", "problem_id": "p03753", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03753/input.txt", "sample_output_relpath": "derived/input_output/data/p03753/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03753/Lisp/s902378783.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s902378783", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defconstant +mod+ 1000000007)\n\n(defmacro dbg (&rest forms)\n #+swank (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n;; BEGIN_INSERTED_CONTENTS\n(defpackage :cp/println-matrix\n (:use :cl)\n (:export #:println-matrix))\n(in-package :cp/println-matrix)\n\n(declaim (inline println-matrix))\n(defun println-matrix (array &key (separator #\\ ) (key #'identity) (writer #'write) (row-start 0) row-end (col-start 0) col-end)\n \"Prints a 2-dimensional array.\"\n (declare ((array * (* *)) array)\n ((integer 0 #.most-positive-fixnum) row-start col-start))\n (let ((row-end (or row-end (array-dimension array 0)))\n (col-end (or col-end (array-dimension array 1))))\n (declare ((integer 0 #.most-positive-fixnum) row-end col-end))\n (loop for i from row-start below row-end\n do (loop for j from col-start below col-end\n unless (= j col-start)\n do (princ separator)\n do (funcall writer (funcall key (aref array i j))))\n (terpri))))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/println-matrix :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun test (n m &rest as)\n (let ((matrix (make-array (list n 7) :element-type 'base-char :initial-element #\\.)))\n (dotimes (i (* n 7))\n (when (member (mod i m) as)\n (setf (row-major-aref matrix i) #\\#)))\n (println-matrix matrix :separator \"\" :writer #'write-char)))\n\n(defun solve-small (n m as)\n (declare (uint31 n m)\n ((simple-array uint31 (*)) as))\n (let ((plan (make-array (list n 7) :element-type 'bit :initial-element 0))\n (res 0))\n (declare (uint62 res))\n (loop for a across as\n do (loop for i from a below (* n 7) by m\n do (setf (row-major-aref plan i) 1)))\n (dotimes (i n)\n (dotimes (j 7)\n (when (zerop (aref plan i j))\n (sb-int:named-let dfs ((i i) (j j))\n (labels ((visit (y x)\n (when (and (<= 0 y (- n 1))\n (<= 0 x 6))\n (dfs y x))))\n (when (zerop (aref plan i j))\n (setf (aref plan i j) 1)\n (visit (- i 1) j)\n (visit (+ i 1) j)\n (visit i (- j 1))\n (visit i (+ j 1)))))\n (incf res))))\n res))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (q (read))\n (as (make-array q :element-type 'uint31 :initial-element 0)))\n (dotimes (i q)\n (setf (aref as i) (read-fixnum)))\n (println\n (cond\n ((zerop (mod m 7))\n (let* ((period (floor m 7))\n (term1 (solve-small period m as))\n (term2 (solve-small (* 2 period) m as))\n (coef (- term2 term1))\n (intercept (- term1 coef)))\n (multiple-value-bind (quot rem) (floor n period)\n (dbg coef intercept)\n (+ intercept (* quot coef)\n (- (solve-small (+ period rem) m as) term1)))))\n ((<= n 10000)\n (solve1 n m as))\n (t (error \"Huh?\"))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n #+os-windows (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)\n #+os-unix (run-program \"xsel\" '(\"-b\" \"-o\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let* ((*standard-output* (or out (make-string-output-stream)))\n (res (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n (if out res (get-output-stream-string *standard-output*))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"4\n\"\n (run \"7 7 3\n1 3 5\n\" nil)))\n (it.bese.fiveam:is\n (equal \"10\n\"\n (run \"10 14 8\n5 6 7 8 9 10 11 12\n\" nil))))\n", "problem_context": "Max Score: 500 Points\n\nProblem Statement\n\nWe have a grid with n rows and 7 columns. We call it a calendar. The cell at i-th row and j-th column is denoted (i, j).\n\nInitially, each cell at (i, j) contains the integer 7i + j - 8, and each cell is white.\n\nSnuke likes painting, so he decided integer m, and did q operations with a calendar.\n\n・In i-th operation, he paint black on the cell in which an integer is written such remainder of dividing by m is a_i.\n\nPlease count the number of connected white parts.\n\nNote that if two adjacent cells are white, the cells belong to the same connected part.\n\nInput Format\n\nThe input format is following:\n\nn m q\na_1 a_2 ... a_q\n\nOutput Format\n\nPrint the number of connected part in one line.\n\nConstraints\n\nn ≤ 10^{12}\n\n7n is divisible by m.\n\n1 ≤ q ≤ m ≤ 10^5\n\n0 ≤ a_1 < a_2 < ... < a_q < m\n\nScoring\n\nSubtask 1 [100 points]\n\nn ≤ 100000.\n\nSubtask 2 [90 points]\n\nm is divisible by 7.\n\na_{i + 1} - a_i = 1.\n\nSubtask 3 [200 points]\n\nm is divisible by 7.\n\nSubtask 4 [110 points]\n\nThere are no additional constraints.\n\nSample Input 1\n\n7 7 3\n1 3 5\n\nSample Output 1\n\n4\n\nThe calendar looks like this:\n\nSample Input 2\n\n10 14 8\n5 6 7 8 9 10 11 12\n\nSample Output 2\n\n10\n\nThe calendar looks like this:", "sample_input": "7 7 3\n1 3 5\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03753", "source_text": "Max Score: 500 Points\n\nProblem Statement\n\nWe have a grid with n rows and 7 columns. We call it a calendar. The cell at i-th row and j-th column is denoted (i, j).\n\nInitially, each cell at (i, j) contains the integer 7i + j - 8, and each cell is white.\n\nSnuke likes painting, so he decided integer m, and did q operations with a calendar.\n\n・In i-th operation, he paint black on the cell in which an integer is written such remainder of dividing by m is a_i.\n\nPlease count the number of connected white parts.\n\nNote that if two adjacent cells are white, the cells belong to the same connected part.\n\nInput Format\n\nThe input format is following:\n\nn m q\na_1 a_2 ... a_q\n\nOutput Format\n\nPrint the number of connected part in one line.\n\nConstraints\n\nn ≤ 10^{12}\n\n7n is divisible by m.\n\n1 ≤ q ≤ m ≤ 10^5\n\n0 ≤ a_1 < a_2 < ... < a_q < m\n\nScoring\n\nSubtask 1 [100 points]\n\nn ≤ 100000.\n\nSubtask 2 [90 points]\n\nm is divisible by 7.\n\na_{i + 1} - a_i = 1.\n\nSubtask 3 [200 points]\n\nm is divisible by 7.\n\nSubtask 4 [110 points]\n\nThere are no additional constraints.\n\nSample Input 1\n\n7 7 3\n1 3 5\n\nSample Output 1\n\n4\n\nThe calendar looks like this:\n\nSample Input 2\n\n10 14 8\n5 6 7 8 9 10 11 12\n\nSample Output 2\n\n10\n\nThe calendar looks like this:", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6470, "cpu_time_ms": 35, "memory_kb": 27540}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s469949370", "group_id": "codeNet:p03759", "input_text": "(let ((a (read))\n (b (read))\n (c (read)))\n\n (format t \"~A~%\"\n (if (= (- b a) (- c b))\n 'yes\n 'no)))\n", "language": "Lisp", "metadata": {"date": 1572743336, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03759.html", "problem_id": "p03759", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03759/input.txt", "sample_output_relpath": "derived/input_output/data/p03759/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03759/Lisp/s469949370.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s469949370", "user_id": "u336541610"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (c (read)))\n\n (format t \"~A~%\"\n (if (= (- b a) (- c b))\n 'yes\n 'no)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThree poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right.\nWe will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, b-a = c-b.\n\nDetermine whether the arrangement of the poles is beautiful.\n\nConstraints\n\n1 \\leq a,b,c \\leq 100\n\na, b and c are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b c\n\nOutput\n\nPrint YES if the arrangement of the poles is beautiful; print NO otherwise.\n\nSample Input 1\n\n2 4 6\n\nSample Output 1\n\nYES\n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\nSample Input 2\n\n2 5 6\n\nSample Output 2\n\nNO\n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\nSample Input 3\n\n3 2 1\n\nSample Output 3\n\nYES\n\nSince 1-2 = 2-3, this arrangement of poles is beautiful.", "sample_input": "2 4 6\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03759", "source_text": "Score : 100 points\n\nProblem Statement\n\nThree poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right.\nWe will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, b-a = c-b.\n\nDetermine whether the arrangement of the poles is beautiful.\n\nConstraints\n\n1 \\leq a,b,c \\leq 100\n\na, b and c are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b c\n\nOutput\n\nPrint YES if the arrangement of the poles is beautiful; print NO otherwise.\n\nSample Input 1\n\n2 4 6\n\nSample Output 1\n\nYES\n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\nSample Input 2\n\n2 5 6\n\nSample Output 2\n\nNO\n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\nSample Input 3\n\n3 2 1\n\nSample Output 3\n\nYES\n\nSince 1-2 = 2-3, this arrangement of poles is beautiful.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 142, "cpu_time_ms": 120, "memory_kb": 11104}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s676802441", "group_id": "codeNet:p03759", "input_text": "(defun solver ()\n (let ((a (read)) (b (read)) (c (read)))\n (if (= (- b a) (- c b))\n (format t \"YES~%\")\n (format t \"NO~%\"))))\n\n(solver)", "language": "Lisp", "metadata": {"date": 1495325251, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03759.html", "problem_id": "p03759", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03759/input.txt", "sample_output_relpath": "derived/input_output/data/p03759/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03759/Lisp/s676802441.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s676802441", "user_id": "u183015556"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(defun solver ()\n (let ((a (read)) (b (read)) (c (read)))\n (if (= (- b a) (- c b))\n (format t \"YES~%\")\n (format t \"NO~%\"))))\n\n(solver)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThree poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right.\nWe will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, b-a = c-b.\n\nDetermine whether the arrangement of the poles is beautiful.\n\nConstraints\n\n1 \\leq a,b,c \\leq 100\n\na, b and c are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b c\n\nOutput\n\nPrint YES if the arrangement of the poles is beautiful; print NO otherwise.\n\nSample Input 1\n\n2 4 6\n\nSample Output 1\n\nYES\n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\nSample Input 2\n\n2 5 6\n\nSample Output 2\n\nNO\n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\nSample Input 3\n\n3 2 1\n\nSample Output 3\n\nYES\n\nSince 1-2 = 2-3, this arrangement of poles is beautiful.", "sample_input": "2 4 6\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03759", "source_text": "Score : 100 points\n\nProblem Statement\n\nThree poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right.\nWe will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, b-a = c-b.\n\nDetermine whether the arrangement of the poles is beautiful.\n\nConstraints\n\n1 \\leq a,b,c \\leq 100\n\na, b and c are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b c\n\nOutput\n\nPrint YES if the arrangement of the poles is beautiful; print NO otherwise.\n\nSample Input 1\n\n2 4 6\n\nSample Output 1\n\nYES\n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\nSample Input 2\n\n2 5 6\n\nSample Output 2\n\nNO\n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\nSample Input 3\n\n3 2 1\n\nSample Output 3\n\nYES\n\nSince 1-2 = 2-3, this arrangement of poles is beautiful.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 146, "cpu_time_ms": 97, "memory_kb": 10984}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s163655019", "group_id": "codeNet:p03760", "input_text": "(format t \"~{~A~}~%\" (loop for odds across (read-line)\n for evens across (concatenate 'string (read-line) \" \")\n append (list odds evens)))", "language": "Lisp", "metadata": {"date": 1504577287, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03760.html", "problem_id": "p03760", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03760/input.txt", "sample_output_relpath": "derived/input_output/data/p03760/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03760/Lisp/s163655019.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s163655019", "user_id": "u140665374"}, "prompt_components": {"gold_output": "xaybzc\n", "input_to_evaluate": "(format t \"~{~A~}~%\" (loop for odds across (read-line)\n for evens across (concatenate 'string (read-line) \" \")\n append (list odds evens)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nSnuke signed up for a new website which holds programming competitions.\nHe worried that he might forget his password, and he took notes of it.\nSince directly recording his password would cause him trouble if stolen,\nhe took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions.\n\nYou are given two strings O and E. O contains the characters at the odd-numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order.\nRestore the original password.\n\nConstraints\n\nO and E consists of lowercase English letters (a - z).\n\n1 \\leq |O|,|E| \\leq 50\n\n|O| - |E| is either 0 or 1.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nO\nE\n\nOutput\n\nPrint the original password.\n\nSample Input 1\n\nxyz\nabc\n\nSample Output 1\n\nxaybzc\n\nThe original password is xaybzc. Extracting the characters at the odd-numbered positions results in xyz, and extracting the characters at the even-numbered positions results in abc.\n\nSample Input 2\n\natcoderbeginnercontest\natcoderregularcontest\n\nSample Output 2\n\naattccooddeerrbreeggiunlnaerrccoonntteesstt", "sample_input": "xyz\nabc\n"}, "reference_outputs": ["xaybzc\n"], "source_document_id": "p03760", "source_text": "Score : 200 points\n\nProblem Statement\n\nSnuke signed up for a new website which holds programming competitions.\nHe worried that he might forget his password, and he took notes of it.\nSince directly recording his password would cause him trouble if stolen,\nhe took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions.\n\nYou are given two strings O and E. O contains the characters at the odd-numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order.\nRestore the original password.\n\nConstraints\n\nO and E consists of lowercase English letters (a - z).\n\n1 \\leq |O|,|E| \\leq 50\n\n|O| - |E| is either 0 or 1.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nO\nE\n\nOutput\n\nPrint the original password.\n\nSample Input 1\n\nxyz\nabc\n\nSample Output 1\n\nxaybzc\n\nThe original password is xaybzc. Extracting the characters at the odd-numbered positions results in xyz, and extracting the characters at the even-numbered positions results in abc.\n\nSample Input 2\n\natcoderbeginnercontest\natcoderregularcontest\n\nSample Output 2\n\naattccooddeerrbreeggiunlnaerrccoonntteesstt", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 182, "cpu_time_ms": 32, "memory_kb": 5220}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s470682842", "group_id": "codeNet:p03761", "input_text": "(let* ((si (loop repeat (read)\n collect (coerce (read-line) 'list)))\n (a (make-array 26 :initial-element 50)))\n (mapc (lambda (s)\n (let ((b (make-array 26 :initial-element 0))) \n (mapc (lambda (c)\n (incf (aref b (- (char-code c) 97))))\n s)\n (loop for y across b\n for i from 0\n when (> (aref a i) y)\n do (setf (aref a i) y))))\n si)\n (loop for x across a\n for i from 97\n do (loop repeat x\n do (princ (code-char i))))\n (fresh-line))", "language": "Lisp", "metadata": {"date": 1504576540, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03761.html", "problem_id": "p03761", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03761/input.txt", "sample_output_relpath": "derived/input_output/data/p03761/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03761/Lisp/s470682842.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s470682842", "user_id": "u140665374"}, "prompt_components": {"gold_output": "aac\n", "input_to_evaluate": "(let* ((si (loop repeat (read)\n collect (coerce (read-line) 'list)))\n (a (make-array 26 :initial-element 50)))\n (mapc (lambda (s)\n (let ((b (make-array 26 :initial-element 0))) \n (mapc (lambda (c)\n (incf (aref b (- (char-code c) 97))))\n s)\n (loop for y across b\n for i from 0\n when (> (aref a i) y)\n do (setf (aref a i) y))))\n si)\n (loop for x across a\n for i from 97\n do (loop repeat x\n do (princ (code-char i))))\n (fresh-line))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke loves \"paper cutting\": he cuts out characters from a newspaper headline and rearranges them to form another string.\n\nHe will receive a headline which contains one of the strings S_1,...,S_n tomorrow.\nHe is excited and already thinking of what string he will create.\nSince he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains.\n\nFind the longest string that can be created regardless of which string among S_1,...,S_n the headline contains.\nIf there are multiple such strings, find the lexicographically smallest one among them.\n\nConstraints\n\n1 \\leq n \\leq 50\n\n1 \\leq |S_i| \\leq 50 for every i = 1, ..., n.\n\nS_i consists of lowercase English letters (a - z) for every i = 1, ..., n.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\nS_1\n...\nS_n\n\nOutput\n\nPrint the lexicographically smallest string among the longest strings that satisfy the condition.\nIf the answer is an empty string, print an empty line.\n\nSample Input 1\n\n3\ncbaa\ndaacc\nacacac\n\nSample Output 1\n\naac\n\nThe strings that can be created from each of cbaa, daacc and acacac, are aa, aac, aca, caa and so forth.\nAmong them, aac, aca and caa are the longest, and the lexicographically smallest of these three is aac.\n\nSample Input 2\n\n3\na\naa\nb\n\nSample Output 2\n\nThe answer is an empty string.", "sample_input": "3\ncbaa\ndaacc\nacacac\n"}, "reference_outputs": ["aac\n"], "source_document_id": "p03761", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke loves \"paper cutting\": he cuts out characters from a newspaper headline and rearranges them to form another string.\n\nHe will receive a headline which contains one of the strings S_1,...,S_n tomorrow.\nHe is excited and already thinking of what string he will create.\nSince he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains.\n\nFind the longest string that can be created regardless of which string among S_1,...,S_n the headline contains.\nIf there are multiple such strings, find the lexicographically smallest one among them.\n\nConstraints\n\n1 \\leq n \\leq 50\n\n1 \\leq |S_i| \\leq 50 for every i = 1, ..., n.\n\nS_i consists of lowercase English letters (a - z) for every i = 1, ..., n.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\nS_1\n...\nS_n\n\nOutput\n\nPrint the lexicographically smallest string among the longest strings that satisfy the condition.\nIf the answer is an empty string, print an empty line.\n\nSample Input 1\n\n3\ncbaa\ndaacc\nacacac\n\nSample Output 1\n\naac\n\nThe strings that can be created from each of cbaa, daacc and acacac, are aa, aac, aca, caa and so forth.\nAmong them, aac, aca and caa are the longest, and the lexicographically smallest of these three is aac.\n\nSample Input 2\n\n3\na\naa\nb\n\nSample Output 2\n\nThe answer is an empty string.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 592, "cpu_time_ms": 177, "memory_kb": 19680}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s691022446", "group_id": "codeNet:p03762", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (xs (make-array n :element-type 'int32))\n (ys (make-array m :element-type 'int32)))\n (declare ((integer 0 100000) n m))\n (dotimes (j n) (setf (aref xs j) (read-fixnum)))\n (dotimes (i m) (setf (aref ys i) (read-fixnum)))\n (println\n (mod\n (* (loop with res of-type uint32 = 0\n for i from 1 to (- m 1)\n do (setf res (mod (+ res (* i\n (- m i)\n (- (aref ys i) (aref ys (- i 1)))))\n +mod+))\n finally (return res))\n (loop with res of-type uint32 = 0\n for j from 1 to (- n 1)\n do (setf res (mod (+ res (* j\n (- n j)\n (- (aref xs j) (aref xs (- j 1)))))\n +mod+))\n finally (return res)))\n +mod+))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1557457055, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03762.html", "problem_id": "p03762", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03762/input.txt", "sample_output_relpath": "derived/input_output/data/p03762/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03762/Lisp/s691022446.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s691022446", "user_id": "u352600849"}, "prompt_components": {"gold_output": "60\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n ;; (return-from read-fixnum 0)\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (xs (make-array n :element-type 'int32))\n (ys (make-array m :element-type 'int32)))\n (declare ((integer 0 100000) n m))\n (dotimes (j n) (setf (aref xs j) (read-fixnum)))\n (dotimes (i m) (setf (aref ys i) (read-fixnum)))\n (println\n (mod\n (* (loop with res of-type uint32 = 0\n for i from 1 to (- m 1)\n do (setf res (mod (+ res (* i\n (- m i)\n (- (aref ys i) (aref ys (- i 1)))))\n +mod+))\n finally (return res))\n (loop with res of-type uint32 = 0\n for j from 1 to (- n 1)\n do (setf res (mod (+ res (* j\n (- n j)\n (- (aref xs j) (aref xs (- j 1)))))\n +mod+))\n finally (return res)))\n +mod+))))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nOn a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis.\nAmong the lines parallel to the x axis, the i-th from the bottom is represented by y = y_i.\nSimilarly, among the lines parallel to the y axis, the i-th from the left is represented by x = x_i.\n\nFor every rectangle that is formed by these lines, find its area, and print the total area modulo 10^9+7.\n\nThat is, for every quadruple (i,j,k,l) satisfying 1\\leq i < j\\leq n and 1\\leq k < l\\leq m, find the area of the rectangle formed by the lines x=x_i, x=x_j, y=y_k and y=y_l, and print the sum of these areas modulo 10^9+7.\n\nConstraints\n\n2 \\leq n,m \\leq 10^5\n\n-10^9 \\leq x_1 < ... < x_n \\leq 10^9\n\n-10^9 \\leq y_1 < ... < y_m \\leq 10^9\n\nx_i and y_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn m\nx_1 x_2 ... x_n\ny_1 y_2 ... y_m\n\nOutput\n\nPrint the total area of the rectangles, modulo 10^9+7.\n\nSample Input 1\n\n3 3\n1 3 4\n1 3 6\n\nSample Output 1\n\n60\n\nThe following figure illustrates this input:\n\nThe total area of the nine rectangles A, B, ..., I shown in the following figure, is 60.\n\nSample Input 2\n\n6 5\n-790013317 -192321079 95834122 418379342 586260100 802780784\n-253230108 193944314 363756450 712662868 735867677\n\nSample Output 2\n\n835067060", "sample_input": "3 3\n1 3 4\n1 3 6\n"}, "reference_outputs": ["60\n"], "source_document_id": "p03762", "source_text": "Score : 500 points\n\nProblem Statement\n\nOn a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis.\nAmong the lines parallel to the x axis, the i-th from the bottom is represented by y = y_i.\nSimilarly, among the lines parallel to the y axis, the i-th from the left is represented by x = x_i.\n\nFor every rectangle that is formed by these lines, find its area, and print the total area modulo 10^9+7.\n\nThat is, for every quadruple (i,j,k,l) satisfying 1\\leq i < j\\leq n and 1\\leq k < l\\leq m, find the area of the rectangle formed by the lines x=x_i, x=x_j, y=y_k and y=y_l, and print the sum of these areas modulo 10^9+7.\n\nConstraints\n\n2 \\leq n,m \\leq 10^5\n\n-10^9 \\leq x_1 < ... < x_n \\leq 10^9\n\n-10^9 \\leq y_1 < ... < y_m \\leq 10^9\n\nx_i and y_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn m\nx_1 x_2 ... x_n\ny_1 y_2 ... y_m\n\nOutput\n\nPrint the total area of the rectangles, modulo 10^9+7.\n\nSample Input 1\n\n3 3\n1 3 4\n1 3 6\n\nSample Output 1\n\n60\n\nThe following figure illustrates this input:\n\nThe total area of the nine rectangles A, B, ..., I shown in the following figure, is 60.\n\nSample Input 2\n\n6 5\n-790013317 -192321079 95834122 418379342 586260100 802780784\n-253230108 193944314 363756450 712662868 735867677\n\nSample Output 2\n\n835067060", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3359, "cpu_time_ms": 250, "memory_kb": 25700}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s267065454", "group_id": "codeNet:p03765", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;; Should we do this with UNWIND-PROTECT?\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((ss (read-line))\n (tt (read-line))\n (slen (length ss))\n (tlen (length tt))\n (cumuls (make-array (+ 1 slen) :element-type 'uint32 :initial-element 0))\n (cumult (make-array (+ 1 tlen) :element-type 'uint32 :initial-element 0))\n (q (read)))\n (declare (simple-string ss tt)\n (uint32 q))\n (dotimes (i slen)\n (setf (aref cumuls (+ i 1))\n (+ (aref cumuls i) (if (char= #\\A (aref ss i)) 1 2))))\n (dotimes (i tlen)\n (setf (aref cumult (+ i 1))\n (+ (aref cumult i) (if (char= #\\A (aref tt i)) 1 2))))\n (with-buffered-stdout\n (dotimes (i q)\n (let ((a (- (read-fixnum) 1))\n (b (read-fixnum))\n (c (- (read-fixnum) 1))\n (d (read-fixnum)))\n (if (= (mod (- (aref cumuls b) (aref cumuls a)) 3)\n (mod (- (aref cumult d) (aref cumult c)) 3))\n (write-line \"YES\")\n (write-line \"NO\")))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1566762246, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03765.html", "problem_id": "p03765", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03765/input.txt", "sample_output_relpath": "derived/input_output/data/p03765/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03765/Lisp/s267065454.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s267065454", "user_id": "u352600849"}, "prompt_components": {"gold_output": "YES\nNO\nYES\nNO\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;; Should we do this with UNWIND-PROTECT?\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((ss (read-line))\n (tt (read-line))\n (slen (length ss))\n (tlen (length tt))\n (cumuls (make-array (+ 1 slen) :element-type 'uint32 :initial-element 0))\n (cumult (make-array (+ 1 tlen) :element-type 'uint32 :initial-element 0))\n (q (read)))\n (declare (simple-string ss tt)\n (uint32 q))\n (dotimes (i slen)\n (setf (aref cumuls (+ i 1))\n (+ (aref cumuls i) (if (char= #\\A (aref ss i)) 1 2))))\n (dotimes (i tlen)\n (setf (aref cumult (+ i 1))\n (+ (aref cumult i) (if (char= #\\A (aref tt i)) 1 2))))\n (with-buffered-stdout\n (dotimes (i q)\n (let ((a (- (read-fixnum) 1))\n (b (read-fixnum))\n (c (- (read-fixnum) 1))\n (d (read-fixnum)))\n (if (= (mod (- (aref cumuls b) (aref cumuls a)) 3)\n (mod (- (aref cumult d) (aref cumult c)) 3))\n (write-line \"YES\")\n (write-line \"NO\")))))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nLet us consider the following operations on a string consisting of A and B:\n\nSelect a character in a string. If it is A, replace it with BB. If it is B, replace with AA.\n\nSelect a substring that is equal to either AAA or BBB, and delete it from the string.\n\nFor example, if the first operation is performed on ABA and the first character is selected, the string becomes BBBA.\nIf the second operation is performed on BBBAAAA and the fourth through sixth characters are selected, the string becomes BBBA.\n\nThese operations can be performed any number of times, in any order.\n\nYou are given two string S and T, and q queries a_i, b_i, c_i, d_i.\nFor each query, determine whether S_{a_i} S_{{a_i}+1} ... S_{b_i}, a substring of S, can be made into T_{c_i} T_{{c_i}+1} ... T_{d_i}, a substring of T.\n\nConstraints\n\n1 \\leq |S|, |T| \\leq 10^5\n\nS and T consist of letters A and B.\n\n1 \\leq q \\leq 10^5\n\n1 \\leq a_i \\leq b_i \\leq |S|\n\n1 \\leq c_i \\leq d_i \\leq |T|\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\nq\na_1 b_1 c_1 d_1\n...\na_q b_q c_q d_q\n\nOutput\n\nPrint q lines. The i-th line should contain the response to the i-th query. If S_{a_i} S_{{a_i}+1} ... S_{b_i} can be made into T_{c_i} T_{{c_i}+1} ... T_{d_i}, print YES. Otherwise, print NO.\n\nSample Input 1\n\nBBBAAAABA\nBBBBA\n4\n7 9 2 5\n7 9 1 4\n1 7 2 5\n1 7 2 4\n\nSample Output 1\n\nYES\nNO\nYES\nNO\n\nThe first query asks whether the string ABA can be made into BBBA.\nAs explained in the problem statement, it can be done by the first operation.\n\nThe second query asks whether ABA can be made into BBBB, and the fourth query asks whether BBBAAAA can be made into BBB.\nNeither is possible.\n\nThe third query asks whether the string BBBAAAA can be made into BBBA.\nAs explained in the problem statement, it can be done by the second operation.\n\nSample Input 2\n\nAAAAABBBBAAABBBBAAAA\nBBBBAAABBBBBBAAAAABB\n10\n2 15 2 13\n2 13 6 16\n1 13 2 20\n4 20 3 20\n1 18 9 19\n2 14 1 11\n3 20 3 15\n6 16 1 17\n4 18 8 20\n7 20 3 14\n\nSample Output 2\n\nYES\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO", "sample_input": "BBBAAAABA\nBBBBA\n4\n7 9 2 5\n7 9 1 4\n1 7 2 5\n1 7 2 4\n"}, "reference_outputs": ["YES\nNO\nYES\nNO\n"], "source_document_id": "p03765", "source_text": "Score : 600 points\n\nProblem Statement\n\nLet us consider the following operations on a string consisting of A and B:\n\nSelect a character in a string. If it is A, replace it with BB. If it is B, replace with AA.\n\nSelect a substring that is equal to either AAA or BBB, and delete it from the string.\n\nFor example, if the first operation is performed on ABA and the first character is selected, the string becomes BBBA.\nIf the second operation is performed on BBBAAAA and the fourth through sixth characters are selected, the string becomes BBBA.\n\nThese operations can be performed any number of times, in any order.\n\nYou are given two string S and T, and q queries a_i, b_i, c_i, d_i.\nFor each query, determine whether S_{a_i} S_{{a_i}+1} ... S_{b_i}, a substring of S, can be made into T_{c_i} T_{{c_i}+1} ... T_{d_i}, a substring of T.\n\nConstraints\n\n1 \\leq |S|, |T| \\leq 10^5\n\nS and T consist of letters A and B.\n\n1 \\leq q \\leq 10^5\n\n1 \\leq a_i \\leq b_i \\leq |S|\n\n1 \\leq c_i \\leq d_i \\leq |T|\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nT\nq\na_1 b_1 c_1 d_1\n...\na_q b_q c_q d_q\n\nOutput\n\nPrint q lines. The i-th line should contain the response to the i-th query. If S_{a_i} S_{{a_i}+1} ... S_{b_i} can be made into T_{c_i} T_{{c_i}+1} ... T_{d_i}, print YES. Otherwise, print NO.\n\nSample Input 1\n\nBBBAAAABA\nBBBBA\n4\n7 9 2 5\n7 9 1 4\n1 7 2 5\n1 7 2 4\n\nSample Output 1\n\nYES\nNO\nYES\nNO\n\nThe first query asks whether the string ABA can be made into BBBA.\nAs explained in the problem statement, it can be done by the first operation.\n\nThe second query asks whether ABA can be made into BBBB, and the fourth query asks whether BBBAAAA can be made into BBB.\nNeither is possible.\n\nThe third query asks whether the string BBBAAAA can be made into BBBA.\nAs explained in the problem statement, it can be done by the second operation.\n\nSample Input 2\n\nAAAAABBBBAAABBBBAAAA\nBBBBAAABBBBBBAAAAABB\n10\n2 15 2 13\n2 13 6 16\n1 13 2 20\n4 20 3 20\n1 18 9 19\n2 14 1 11\n3 20 3 15\n6 16 1 17\n4 18 8 20\n7 20 3 14\n\nSample Output 2\n\nYES\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3915, "cpu_time_ms": 136, "memory_kb": 19176}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s801911688", "group_id": "codeNet:p03767", "input_text": "(defun input (n)\n (let ((A (make-array n)))\n (loop for i below n do (setf (aref A i) (read)))\n A))\n(defun solve (n A)\n (loop for i from n below (* 2 n) sum (aref A i)))\n(let* ((n (read))\n (A (input (* 3 n))))\n (sort A #'>)\n (princ (solve n A)))", "language": "Lisp", "metadata": {"date": 1522870011, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03767.html", "problem_id": "p03767", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03767/input.txt", "sample_output_relpath": "derived/input_output/data/p03767/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03767/Lisp/s801911688.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s801911688", "user_id": "u672956630"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(defun input (n)\n (let ((A (make-array n)))\n (loop for i below n do (setf (aref A i) (read)))\n A))\n(defun solve (n A)\n (loop for i from n below (* 2 n) sum (aref A i)))\n(let* ((n (read))\n (A (input (* 3 n))))\n (sort A #'>)\n (princ (solve n A)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are 3N participants in AtCoder Group Contest.\nThe strength of the i-th participant is represented by an integer a_i.\nThey will form N teams, each consisting of three participants.\nNo participant may belong to multiple teams.\n\nThe strength of a team is defined as the second largest strength among its members.\nFor example, a team of participants of strength 1, 5, 2 has a strength 2, and a team of three participants of strength 3, 2, 3 has a strength 3.\n\nFind the maximum possible sum of the strengths of N teams.\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n1 ≤ a_i ≤ 10^{9}\n\na_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_{3N}\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n2\n5 2 8 5 1 5\n\nSample Output 1\n\n10\n\nThe following is one formation of teams that maximizes the sum of the strengths of teams:\n\nTeam 1: consists of the first, fourth and fifth participants.\n\nTeam 2: consists of the second, third and sixth participants.\n\nSample Input 2\n\n10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n\nSample Output 2\n\n10000000000\n\nThe sum of the strengths can be quite large.", "sample_input": "2\n5 2 8 5 1 5\n"}, "reference_outputs": ["10\n"], "source_document_id": "p03767", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are 3N participants in AtCoder Group Contest.\nThe strength of the i-th participant is represented by an integer a_i.\nThey will form N teams, each consisting of three participants.\nNo participant may belong to multiple teams.\n\nThe strength of a team is defined as the second largest strength among its members.\nFor example, a team of participants of strength 1, 5, 2 has a strength 2, and a team of three participants of strength 3, 2, 3 has a strength 3.\n\nFind the maximum possible sum of the strengths of N teams.\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n1 ≤ a_i ≤ 10^{9}\n\na_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_{3N}\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n2\n5 2 8 5 1 5\n\nSample Output 1\n\n10\n\nThe following is one formation of teams that maximizes the sum of the strengths of teams:\n\nTeam 1: consists of the first, fourth and fifth participants.\n\nTeam 2: consists of the second, third and sixth participants.\n\nSample Input 2\n\n10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n\nSample Output 2\n\n10000000000\n\nThe sum of the strengths can be quite large.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 260, "cpu_time_ms": 905, "memory_kb": 59848}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s405533506", "group_id": "codeNet:p03767", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun script-p ()\n (eql sb-sys:*stdin* *standard-input*)))\n\n(macrolet ((optimize (pred)\n\t (if pred\n\t\t `(declaim (optimize (speed 3) (debug 0) (safety 0)))\n\t\t `(declaim (optimize (speed 0) (debug 3) (safety 3))))))\n (optimize #. (script-p)))\n\n(defun xclip ()\n (with-output-to-string (s)\n (sb-ext:run-program \"/usr/bin/xclip\" '(\"-o\") :output s)))\n\n(defun test ()\n (with-input-from-string (*standard-input* (xclip))\n (main)))\n\n(defun main ()\n (let* ((n (read))\n\t (as (sort (loop :repeat (* 3 n)\n\t\t :collect (read))\n\t\t #'>)))\n (format t \"~a~%\"\n\t (loop :repeat n\n\t :for x :in (cdr as) :by #'cddr\n\t :sum x))))\n\n(when (script-p) (main))\n", "language": "Lisp", "metadata": {"date": 1491250890, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03767.html", "problem_id": "p03767", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03767/input.txt", "sample_output_relpath": "derived/input_output/data/p03767/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03767/Lisp/s405533506.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s405533506", "user_id": "u693548378"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun script-p ()\n (eql sb-sys:*stdin* *standard-input*)))\n\n(macrolet ((optimize (pred)\n\t (if pred\n\t\t `(declaim (optimize (speed 3) (debug 0) (safety 0)))\n\t\t `(declaim (optimize (speed 0) (debug 3) (safety 3))))))\n (optimize #. (script-p)))\n\n(defun xclip ()\n (with-output-to-string (s)\n (sb-ext:run-program \"/usr/bin/xclip\" '(\"-o\") :output s)))\n\n(defun test ()\n (with-input-from-string (*standard-input* (xclip))\n (main)))\n\n(defun main ()\n (let* ((n (read))\n\t (as (sort (loop :repeat (* 3 n)\n\t\t :collect (read))\n\t\t #'>)))\n (format t \"~a~%\"\n\t (loop :repeat n\n\t :for x :in (cdr as) :by #'cddr\n\t :sum x))))\n\n(when (script-p) (main))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are 3N participants in AtCoder Group Contest.\nThe strength of the i-th participant is represented by an integer a_i.\nThey will form N teams, each consisting of three participants.\nNo participant may belong to multiple teams.\n\nThe strength of a team is defined as the second largest strength among its members.\nFor example, a team of participants of strength 1, 5, 2 has a strength 2, and a team of three participants of strength 3, 2, 3 has a strength 3.\n\nFind the maximum possible sum of the strengths of N teams.\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n1 ≤ a_i ≤ 10^{9}\n\na_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_{3N}\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n2\n5 2 8 5 1 5\n\nSample Output 1\n\n10\n\nThe following is one formation of teams that maximizes the sum of the strengths of teams:\n\nTeam 1: consists of the first, fourth and fifth participants.\n\nTeam 2: consists of the second, third and sixth participants.\n\nSample Input 2\n\n10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n\nSample Output 2\n\n10000000000\n\nThe sum of the strengths can be quite large.", "sample_input": "2\n5 2 8 5 1 5\n"}, "reference_outputs": ["10\n"], "source_document_id": "p03767", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are 3N participants in AtCoder Group Contest.\nThe strength of the i-th participant is represented by an integer a_i.\nThey will form N teams, each consisting of three participants.\nNo participant may belong to multiple teams.\n\nThe strength of a team is defined as the second largest strength among its members.\nFor example, a team of participants of strength 1, 5, 2 has a strength 2, and a team of three participants of strength 3, 2, 3 has a strength 3.\n\nFind the maximum possible sum of the strengths of N teams.\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n1 ≤ a_i ≤ 10^{9}\n\na_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_{3N}\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n2\n5 2 8 5 1 5\n\nSample Output 1\n\n10\n\nThe following is one formation of teams that maximizes the sum of the strengths of teams:\n\nTeam 1: consists of the first, fourth and fifth participants.\n\nTeam 2: consists of the second, third and sixth participants.\n\nSample Input 2\n\n10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n\nSample Output 2\n\n10000000000\n\nThe sum of the strengths can be quite large.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 731, "cpu_time_ms": 925, "memory_kb": 63972}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s743210976", "group_id": "codeNet:p03768", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (colors (make-array n :element-type 'int32 :initial-element -1))\n (dp (make-array n :element-type 'int32 :initial-element 0)))\n (declare (uint32 n m))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (let ((q (read)))\n ;; reverse ordering\n (sb-int:named-let recur ((count 0))\n (unless (= q count)\n (let ((v (- (read-fixnum) 1))\n (d (read-fixnum))\n (c (read-fixnum)))\n (recur (+ count 1))\n (sb-int:named-let dfs ((v v) (depth d))\n ;; if not colored, color it\n (when (= -1 (aref colors v))\n (setf (aref colors v) c))\n ;; search neighbors if the current depth is larger than the\n ;; maximal old depth.\n (when (> depth (aref dp v))\n (setf (aref dp v) depth)\n (dolist (neighbor (aref graph v))\n (dfs neighbor (- depth 1)))))))))\n (with-buffered-stdout\n (dotimes (i n)\n (println (max 0 (aref colors i)))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1563219227, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03768.html", "problem_id": "p03768", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03768/input.txt", "sample_output_relpath": "derived/input_output/data/p03768/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03768/Lisp/s743210976.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s743210976", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n2\n2\n2\n2\n1\n0\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (colors (make-array n :element-type 'int32 :initial-element -1))\n (dp (make-array n :element-type 'int32 :initial-element 0)))\n (declare (uint32 n m))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (let ((q (read)))\n ;; reverse ordering\n (sb-int:named-let recur ((count 0))\n (unless (= q count)\n (let ((v (- (read-fixnum) 1))\n (d (read-fixnum))\n (c (read-fixnum)))\n (recur (+ count 1))\n (sb-int:named-let dfs ((v v) (depth d))\n ;; if not colored, color it\n (when (= -1 (aref colors v))\n (setf (aref colors v) c))\n ;; search neighbors if the current depth is larger than the\n ;; maximal old depth.\n (when (> depth (aref dp v))\n (setf (aref dp v) depth)\n (dolist (neighbor (aref graph v))\n (dfs neighbor (- depth 1)))))))))\n (with-buffered-stdout\n (dotimes (i n)\n (println (max 0 (aref colors i)))))))\n\n#-swank (main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nSquid loves painting vertices in graphs.\n\nThere is a simple undirected graph consisting of N vertices numbered 1 through N, and M edges.\nInitially, all the vertices are painted in color 0. The i-th edge bidirectionally connects two vertices a_i and b_i. The length of every edge is 1.\n\nSquid performed Q operations on this graph. In the i-th operation, he repaints all the vertices within a distance of d_i from vertex v_i, in color c_i.\n\nFind the color of each vertex after the Q operations.\n\nConstraints\n\n1 ≤ N,M,Q ≤ 10^5\n\n1 ≤ a_i,b_i,v_i ≤ N\n\na_i ≠ b_i\n\n0 ≤ d_i ≤ 10\n\n1 ≤ c_i ≤10^5\n\nd_i and c_i are all integers.\n\nThere are no self-loops or multiple edges in the given graph.\n\nPartial Score\n\n200 points will be awarded for passing the testset satisfying 1 ≤ N,M,Q ≤ 2{,}000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\n:\na_{M} b_{M}\nQ\nv_1 d_1 c_1\n:\nv_{Q} d_{Q} c_{Q}\n\nOutput\n\nPrint the answer in N lines.\nIn the i-th line, print the color of vertex i after the Q operations.\n\nSample Input 1\n\n7 7\n1 2\n1 3\n1 4\n4 5\n5 6\n5 7\n2 3\n2\n6 1 1\n1 2 2\n\nSample Output 1\n\n2\n2\n2\n2\n2\n1\n0\n\nInitially, each vertex is painted in color 0.\nIn the first operation, vertices 5 and 6 are repainted in color 1.\nIn the second operation, vertices 1, 2, 3, 4 and 5 are repainted in color 2.\n\nSample Input 2\n\n14 10\n1 4\n5 7\n7 11\n4 10\n14 7\n14 3\n6 14\n8 11\n5 13\n8 3\n8\n8 6 2\n9 7 85\n6 9 3\n6 7 5\n10 3 1\n12 9 4\n9 6 6\n8 2 3\n\nSample Output 2\n\n1\n0\n3\n1\n5\n5\n3\n3\n6\n1\n3\n4\n5\n3\n\nThe given graph may not be connected.", "sample_input": "7 7\n1 2\n1 3\n1 4\n4 5\n5 6\n5 7\n2 3\n2\n6 1 1\n1 2 2\n"}, "reference_outputs": ["2\n2\n2\n2\n2\n1\n0\n"], "source_document_id": "p03768", "source_text": "Score : 700 points\n\nProblem Statement\n\nSquid loves painting vertices in graphs.\n\nThere is a simple undirected graph consisting of N vertices numbered 1 through N, and M edges.\nInitially, all the vertices are painted in color 0. The i-th edge bidirectionally connects two vertices a_i and b_i. The length of every edge is 1.\n\nSquid performed Q operations on this graph. In the i-th operation, he repaints all the vertices within a distance of d_i from vertex v_i, in color c_i.\n\nFind the color of each vertex after the Q operations.\n\nConstraints\n\n1 ≤ N,M,Q ≤ 10^5\n\n1 ≤ a_i,b_i,v_i ≤ N\n\na_i ≠ b_i\n\n0 ≤ d_i ≤ 10\n\n1 ≤ c_i ≤10^5\n\nd_i and c_i are all integers.\n\nThere are no self-loops or multiple edges in the given graph.\n\nPartial Score\n\n200 points will be awarded for passing the testset satisfying 1 ≤ N,M,Q ≤ 2{,}000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\n:\na_{M} b_{M}\nQ\nv_1 d_1 c_1\n:\nv_{Q} d_{Q} c_{Q}\n\nOutput\n\nPrint the answer in N lines.\nIn the i-th line, print the color of vertex i after the Q operations.\n\nSample Input 1\n\n7 7\n1 2\n1 3\n1 4\n4 5\n5 6\n5 7\n2 3\n2\n6 1 1\n1 2 2\n\nSample Output 1\n\n2\n2\n2\n2\n2\n1\n0\n\nInitially, each vertex is painted in color 0.\nIn the first operation, vertices 5 and 6 are repainted in color 1.\nIn the second operation, vertices 1, 2, 3, 4 and 5 are repainted in color 2.\n\nSample Input 2\n\n14 10\n1 4\n5 7\n7 11\n4 10\n14 7\n14 3\n6 14\n8 11\n5 13\n8 3\n8\n8 6 2\n9 7 85\n6 9 3\n6 7 5\n10 3 1\n12 9 4\n9 6 6\n8 2 3\n\nSample Output 2\n\n1\n0\n3\n1\n5\n5\n3\n3\n6\n1\n3\n4\n5\n3\n\nThe given graph may not be connected.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4088, "cpu_time_ms": 354, "memory_kb": 41184}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s190281917", "group_id": "codeNet:p03768", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun script-p ()\n (eql sb-sys:*stdin* *standard-input*)))\n\n;;; helper\n(defmacro defvars (&rest vars)\n `(progn ,@(mapcar #'(lambda (x) `(defvar ,x)) vars)))\n\n(macrolet ((optimize (pred)\n\t (if pred\n\t\t `(declaim (optimize (speed 3) (debug 0) (safety 0)))\n\t\t `(declaim (optimize (speed 0) (debug 3) (safety 3))))))\n (optimize #. (script-p)))\n\n(defun xclip ()\n (with-output-to-string (s)\n (sb-ext:run-program \"/usr/bin/xclip\" '(\"-sel\" \"clip\" \"-o\") :output s)))\n\n(defun test ()\n (with-input-from-string (*standard-input* (xclip))\n (main)))\n\n(defmacro show (name)\n (if (script-p)\n nil\n `(format t ,(concatenate 'string (format nil \"~a\" name) \" is ~a~%\")\n\t ,name)))\n\n;;; code starts here\n(defparameter dmax 10)\n\n(defstruct v color ns mark)\n\n(defvars n m vs l dp init colors)\n\n;; table[v][d]\n;; v: vertex\n;; d: distace\n;; value: -1 invalid\n;; | 0 not colored\n;; | n otherwise\n\n(defun rundp (v d)\n (cond ((> d dmax) 0)\n\t((plusp (aref dp v d)) (aref dp v d))\n\t(t (setf (aref dp v d)\n\t\t (max (aref init v d)\n\t\t (loop for x in (aref vs v)\n\t\t\t maximize (rundp x (1+ d))))))))\n\n(defun main ()\n (setf n (read))\n (setf m (read))\n (setf vs (make-array n :initial-element nil))\n\n (loop for i from 0 below n\n do (push i (aref vs i)))\n\n (loop repeat m\n for a = (1- (read))\n for b = (1- (read))\n do (push b (aref vs a))\n do (push a (aref vs b)))\n\n (show vs)\n\n (setf l (read))\n (setf dp (make-array (list n (1+ dmax)) :initial-element -1))\n (setf init (make-array (list n (1+ dmax)) :initial-element -1))\n (setf colors (make-array (1+ l)))\n\n (loop repeat l\n for i from 1 ;; 1!\n for v = (1- (read))\n for d = (read)\n for c = (read)\n do (setf (aref init v d) i\n\t (aref colors i) c))\n\n (show init)\n (show colors)\n \n (loop for v from 0 below n\n do (format t \"~a~%\" (aref colors (rundp v 0)))))\n\n(when (script-p) (main))\n", "language": "Lisp", "metadata": {"date": 1491493759, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03768.html", "problem_id": "p03768", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03768/input.txt", "sample_output_relpath": "derived/input_output/data/p03768/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03768/Lisp/s190281917.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s190281917", "user_id": "u693548378"}, "prompt_components": {"gold_output": "2\n2\n2\n2\n2\n1\n0\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun script-p ()\n (eql sb-sys:*stdin* *standard-input*)))\n\n;;; helper\n(defmacro defvars (&rest vars)\n `(progn ,@(mapcar #'(lambda (x) `(defvar ,x)) vars)))\n\n(macrolet ((optimize (pred)\n\t (if pred\n\t\t `(declaim (optimize (speed 3) (debug 0) (safety 0)))\n\t\t `(declaim (optimize (speed 0) (debug 3) (safety 3))))))\n (optimize #. (script-p)))\n\n(defun xclip ()\n (with-output-to-string (s)\n (sb-ext:run-program \"/usr/bin/xclip\" '(\"-sel\" \"clip\" \"-o\") :output s)))\n\n(defun test ()\n (with-input-from-string (*standard-input* (xclip))\n (main)))\n\n(defmacro show (name)\n (if (script-p)\n nil\n `(format t ,(concatenate 'string (format nil \"~a\" name) \" is ~a~%\")\n\t ,name)))\n\n;;; code starts here\n(defparameter dmax 10)\n\n(defstruct v color ns mark)\n\n(defvars n m vs l dp init colors)\n\n;; table[v][d]\n;; v: vertex\n;; d: distace\n;; value: -1 invalid\n;; | 0 not colored\n;; | n otherwise\n\n(defun rundp (v d)\n (cond ((> d dmax) 0)\n\t((plusp (aref dp v d)) (aref dp v d))\n\t(t (setf (aref dp v d)\n\t\t (max (aref init v d)\n\t\t (loop for x in (aref vs v)\n\t\t\t maximize (rundp x (1+ d))))))))\n\n(defun main ()\n (setf n (read))\n (setf m (read))\n (setf vs (make-array n :initial-element nil))\n\n (loop for i from 0 below n\n do (push i (aref vs i)))\n\n (loop repeat m\n for a = (1- (read))\n for b = (1- (read))\n do (push b (aref vs a))\n do (push a (aref vs b)))\n\n (show vs)\n\n (setf l (read))\n (setf dp (make-array (list n (1+ dmax)) :initial-element -1))\n (setf init (make-array (list n (1+ dmax)) :initial-element -1))\n (setf colors (make-array (1+ l)))\n\n (loop repeat l\n for i from 1 ;; 1!\n for v = (1- (read))\n for d = (read)\n for c = (read)\n do (setf (aref init v d) i\n\t (aref colors i) c))\n\n (show init)\n (show colors)\n \n (loop for v from 0 below n\n do (format t \"~a~%\" (aref colors (rundp v 0)))))\n\n(when (script-p) (main))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nSquid loves painting vertices in graphs.\n\nThere is a simple undirected graph consisting of N vertices numbered 1 through N, and M edges.\nInitially, all the vertices are painted in color 0. The i-th edge bidirectionally connects two vertices a_i and b_i. The length of every edge is 1.\n\nSquid performed Q operations on this graph. In the i-th operation, he repaints all the vertices within a distance of d_i from vertex v_i, in color c_i.\n\nFind the color of each vertex after the Q operations.\n\nConstraints\n\n1 ≤ N,M,Q ≤ 10^5\n\n1 ≤ a_i,b_i,v_i ≤ N\n\na_i ≠ b_i\n\n0 ≤ d_i ≤ 10\n\n1 ≤ c_i ≤10^5\n\nd_i and c_i are all integers.\n\nThere are no self-loops or multiple edges in the given graph.\n\nPartial Score\n\n200 points will be awarded for passing the testset satisfying 1 ≤ N,M,Q ≤ 2{,}000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\n:\na_{M} b_{M}\nQ\nv_1 d_1 c_1\n:\nv_{Q} d_{Q} c_{Q}\n\nOutput\n\nPrint the answer in N lines.\nIn the i-th line, print the color of vertex i after the Q operations.\n\nSample Input 1\n\n7 7\n1 2\n1 3\n1 4\n4 5\n5 6\n5 7\n2 3\n2\n6 1 1\n1 2 2\n\nSample Output 1\n\n2\n2\n2\n2\n2\n1\n0\n\nInitially, each vertex is painted in color 0.\nIn the first operation, vertices 5 and 6 are repainted in color 1.\nIn the second operation, vertices 1, 2, 3, 4 and 5 are repainted in color 2.\n\nSample Input 2\n\n14 10\n1 4\n5 7\n7 11\n4 10\n14 7\n14 3\n6 14\n8 11\n5 13\n8 3\n8\n8 6 2\n9 7 85\n6 9 3\n6 7 5\n10 3 1\n12 9 4\n9 6 6\n8 2 3\n\nSample Output 2\n\n1\n0\n3\n1\n5\n5\n3\n3\n6\n1\n3\n4\n5\n3\n\nThe given graph may not be connected.", "sample_input": "7 7\n1 2\n1 3\n1 4\n4 5\n5 6\n5 7\n2 3\n2\n6 1 1\n1 2 2\n"}, "reference_outputs": ["2\n2\n2\n2\n2\n1\n0\n"], "source_document_id": "p03768", "source_text": "Score : 700 points\n\nProblem Statement\n\nSquid loves painting vertices in graphs.\n\nThere is a simple undirected graph consisting of N vertices numbered 1 through N, and M edges.\nInitially, all the vertices are painted in color 0. The i-th edge bidirectionally connects two vertices a_i and b_i. The length of every edge is 1.\n\nSquid performed Q operations on this graph. In the i-th operation, he repaints all the vertices within a distance of d_i from vertex v_i, in color c_i.\n\nFind the color of each vertex after the Q operations.\n\nConstraints\n\n1 ≤ N,M,Q ≤ 10^5\n\n1 ≤ a_i,b_i,v_i ≤ N\n\na_i ≠ b_i\n\n0 ≤ d_i ≤ 10\n\n1 ≤ c_i ≤10^5\n\nd_i and c_i are all integers.\n\nThere are no self-loops or multiple edges in the given graph.\n\nPartial Score\n\n200 points will be awarded for passing the testset satisfying 1 ≤ N,M,Q ≤ 2{,}000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\na_1 b_1\n:\na_{M} b_{M}\nQ\nv_1 d_1 c_1\n:\nv_{Q} d_{Q} c_{Q}\n\nOutput\n\nPrint the answer in N lines.\nIn the i-th line, print the color of vertex i after the Q operations.\n\nSample Input 1\n\n7 7\n1 2\n1 3\n1 4\n4 5\n5 6\n5 7\n2 3\n2\n6 1 1\n1 2 2\n\nSample Output 1\n\n2\n2\n2\n2\n2\n1\n0\n\nInitially, each vertex is painted in color 0.\nIn the first operation, vertices 5 and 6 are repainted in color 1.\nIn the second operation, vertices 1, 2, 3, 4 and 5 are repainted in color 2.\n\nSample Input 2\n\n14 10\n1 4\n5 7\n7 11\n4 10\n14 7\n14 3\n6 14\n8 11\n5 13\n8 3\n8\n8 6 2\n9 7 85\n6 9 3\n6 7 5\n10 3 1\n12 9 4\n9 6 6\n8 2 3\n\nSample Output 2\n\n1\n0\n3\n1\n5\n5\n3\n3\n6\n1\n3\n4\n5\n3\n\nThe given graph may not be connected.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1975, "cpu_time_ms": 2107, "memory_kb": 82884}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s894836997", "group_id": "codeNet:p03773", "input_text": "(format t \"~A~%\"\n (mod (+ (read) (read)) 24))\n", "language": "Lisp", "metadata": {"date": 1594776232, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03773.html", "problem_id": "p03773", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03773/input.txt", "sample_output_relpath": "derived/input_output/data/p03773/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03773/Lisp/s894836997.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s894836997", "user_id": "u336541610"}, "prompt_components": {"gold_output": "21\n", "input_to_evaluate": "(format t \"~A~%\"\n (mod (+ (read) (read)) 24))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nDolphin loves programming contests. Today, he will take part in a contest in AtCoder.\n\nIn this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as \"21 o'clock\".\n\nThe current time is A o'clock, and a contest will begin in exactly B hours.\nWhen will the contest begin? Answer in 24-hour time.\n\nConstraints\n\n0 \\leq A,B \\leq 23\n\nA and B are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the hour of the starting time of the contest in 24-hour time.\n\nSample Input 1\n\n9 12\n\nSample Output 1\n\n21\n\nIn this input, the current time is 9 o'clock, and 12 hours later it will be 21 o'clock in 24-hour time.\n\nSample Input 2\n\n19 0\n\nSample Output 2\n\n19\n\nThe contest has just started.\n\nSample Input 3\n\n23 2\n\nSample Output 3\n\n1\n\nThe contest will begin at 1 o'clock the next day.", "sample_input": "9 12\n"}, "reference_outputs": ["21\n"], "source_document_id": "p03773", "source_text": "Score : 100 points\n\nProblem Statement\n\nDolphin loves programming contests. Today, he will take part in a contest in AtCoder.\n\nIn this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as \"21 o'clock\".\n\nThe current time is A o'clock, and a contest will begin in exactly B hours.\nWhen will the contest begin? Answer in 24-hour time.\n\nConstraints\n\n0 \\leq A,B \\leq 23\n\nA and B are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the hour of the starting time of the contest in 24-hour time.\n\nSample Input 1\n\n9 12\n\nSample Output 1\n\n21\n\nIn this input, the current time is 9 o'clock, and 12 hours later it will be 21 o'clock in 24-hour time.\n\nSample Input 2\n\n19 0\n\nSample Output 2\n\n19\n\nThe contest has just started.\n\nSample Input 3\n\n23 2\n\nSample Output 3\n\n1\n\nThe contest will begin at 1 o'clock the next day.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 53, "cpu_time_ms": 18, "memory_kb": 24116}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s596012116", "group_id": "codeNet:p03773", "input_text": "(let ((a (read)) (b (read)))\n (princ (mod (+ a b) 24)))\n", "language": "Lisp", "metadata": {"date": 1490764656, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03773.html", "problem_id": "p03773", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03773/input.txt", "sample_output_relpath": "derived/input_output/data/p03773/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03773/Lisp/s596012116.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s596012116", "user_id": "u231540466"}, "prompt_components": {"gold_output": "21\n", "input_to_evaluate": "(let ((a (read)) (b (read)))\n (princ (mod (+ a b) 24)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nDolphin loves programming contests. Today, he will take part in a contest in AtCoder.\n\nIn this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as \"21 o'clock\".\n\nThe current time is A o'clock, and a contest will begin in exactly B hours.\nWhen will the contest begin? Answer in 24-hour time.\n\nConstraints\n\n0 \\leq A,B \\leq 23\n\nA and B are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the hour of the starting time of the contest in 24-hour time.\n\nSample Input 1\n\n9 12\n\nSample Output 1\n\n21\n\nIn this input, the current time is 9 o'clock, and 12 hours later it will be 21 o'clock in 24-hour time.\n\nSample Input 2\n\n19 0\n\nSample Output 2\n\n19\n\nThe contest has just started.\n\nSample Input 3\n\n23 2\n\nSample Output 3\n\n1\n\nThe contest will begin at 1 o'clock the next day.", "sample_input": "9 12\n"}, "reference_outputs": ["21\n"], "source_document_id": "p03773", "source_text": "Score : 100 points\n\nProblem Statement\n\nDolphin loves programming contests. Today, he will take part in a contest in AtCoder.\n\nIn this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as \"21 o'clock\".\n\nThe current time is A o'clock, and a contest will begin in exactly B hours.\nWhen will the contest begin? Answer in 24-hour time.\n\nConstraints\n\n0 \\leq A,B \\leq 23\n\nA and B are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the hour of the starting time of the contest in 24-hour time.\n\nSample Input 1\n\n9 12\n\nSample Output 1\n\n21\n\nIn this input, the current time is 9 o'clock, and 12 hours later it will be 21 o'clock in 24-hour time.\n\nSample Input 2\n\n19 0\n\nSample Output 2\n\n19\n\nThe contest has just started.\n\nSample Input 3\n\n23 2\n\nSample Output 3\n\n1\n\nThe contest will begin at 1 o'clock the next day.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 61, "cpu_time_ms": 12, "memory_kb": 3560}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s017943694", "group_id": "codeNet:p03773", "input_text": "(defun split-with (string &key (delimiterp #'(lambda (c) (char= c #\\Space))))\n (loop :for beg = (position-if-not delimiterp string)\n :then (position-if-not delimiterp string :start (1+ end))\n :for end = (and beg (position-if delimiterp string :start beg))\n :when beg :collect (subseq string beg end)\n :while end))\n\n(let* ((lst (split-with (read-line)))\n (a (parse-integer (car lst)))\n (b (parse-integer (car (cdr lst)))))\n (format t \"~d~%\" (mod (+ a b) 24)))\n", "language": "Lisp", "metadata": {"date": 1490576703, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03773.html", "problem_id": "p03773", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03773/input.txt", "sample_output_relpath": "derived/input_output/data/p03773/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03773/Lisp/s017943694.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s017943694", "user_id": "u690263481"}, "prompt_components": {"gold_output": "21\n", "input_to_evaluate": "(defun split-with (string &key (delimiterp #'(lambda (c) (char= c #\\Space))))\n (loop :for beg = (position-if-not delimiterp string)\n :then (position-if-not delimiterp string :start (1+ end))\n :for end = (and beg (position-if delimiterp string :start beg))\n :when beg :collect (subseq string beg end)\n :while end))\n\n(let* ((lst (split-with (read-line)))\n (a (parse-integer (car lst)))\n (b (parse-integer (car (cdr lst)))))\n (format t \"~d~%\" (mod (+ a b) 24)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nDolphin loves programming contests. Today, he will take part in a contest in AtCoder.\n\nIn this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as \"21 o'clock\".\n\nThe current time is A o'clock, and a contest will begin in exactly B hours.\nWhen will the contest begin? Answer in 24-hour time.\n\nConstraints\n\n0 \\leq A,B \\leq 23\n\nA and B are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the hour of the starting time of the contest in 24-hour time.\n\nSample Input 1\n\n9 12\n\nSample Output 1\n\n21\n\nIn this input, the current time is 9 o'clock, and 12 hours later it will be 21 o'clock in 24-hour time.\n\nSample Input 2\n\n19 0\n\nSample Output 2\n\n19\n\nThe contest has just started.\n\nSample Input 3\n\n23 2\n\nSample Output 3\n\n1\n\nThe contest will begin at 1 o'clock the next day.", "sample_input": "9 12\n"}, "reference_outputs": ["21\n"], "source_document_id": "p03773", "source_text": "Score : 100 points\n\nProblem Statement\n\nDolphin loves programming contests. Today, he will take part in a contest in AtCoder.\n\nIn this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as \"21 o'clock\".\n\nThe current time is A o'clock, and a contest will begin in exactly B hours.\nWhen will the contest begin? Answer in 24-hour time.\n\nConstraints\n\n0 \\leq A,B \\leq 23\n\nA and B are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the hour of the starting time of the contest in 24-hour time.\n\nSample Input 1\n\n9 12\n\nSample Output 1\n\n21\n\nIn this input, the current time is 9 o'clock, and 12 hours later it will be 21 o'clock in 24-hour time.\n\nSample Input 2\n\n19 0\n\nSample Output 2\n\n19\n\nThe contest has just started.\n\nSample Input 3\n\n23 2\n\nSample Output 3\n\n1\n\nThe contest will begin at 1 o'clock the next day.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 501, "cpu_time_ms": 40, "memory_kb": 9316}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s043321623", "group_id": "codeNet:p03774", "input_text": "(let* ((n (read))\n (m (read))\n (stu (loop :for k :from 1 :upto n :collect (list (read) (read))))\n (ckpt (loop :for k :from 1 :upto m :collect (list k (read) (read)))))\n (defun dist (a b)\n (+ (abs (- (first a) (first b))) (abs (- (second a) (second b)))))\n (defun f (k)\n (let* ((ans 1))\n (loop :for x :from 1 :upto m :do(if (> (dist k (cdr (nth (1- ans) ckpt))) (dist k (cdr (nth (1- x) ckpt)))) (setf ans x)))\n ans))\n )", "language": "Lisp", "metadata": {"date": 1567743489, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03774.html", "problem_id": "p03774", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03774/input.txt", "sample_output_relpath": "derived/input_output/data/p03774/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03774/Lisp/s043321623.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s043321623", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2\n1\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (stu (loop :for k :from 1 :upto n :collect (list (read) (read))))\n (ckpt (loop :for k :from 1 :upto m :collect (list k (read) (read)))))\n (defun dist (a b)\n (+ (abs (- (first a) (first b))) (abs (- (second a) (second b)))))\n (defun f (k)\n (let* ((ans 1))\n (loop :for x :from 1 :upto m :do(if (> (dist k (cdr (nth (1- ans) ckpt))) (dist k (cdr (nth (1- x) ckpt)))) (setf ans x)))\n ans))\n )", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N students and M checkpoints on the xy-plane.\n\nThe coordinates of the i-th student (1 \\leq i \\leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \\leq j \\leq M) is (c_j,d_j).\n\nWhen the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.\n\nThe Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.\n\nHere, |x| denotes the absolute value of x.\n\nIf there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.\n\nWhich checkpoint will each student go to?\n\nConstraints\n\n1 \\leq N,M \\leq 50\n\n-10^8 \\leq a_i,b_i,c_j,d_j \\leq 10^8\n\nAll input values are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN M\na_1 b_1\n:\na_N b_N\nc_1 d_1\n:\nc_M d_M\n\nOutput\n\nPrint N lines.\n\nThe i-th line (1 \\leq i \\leq N) should contain the index of the checkpoint for the i-th student to go.\n\nSample Input 1\n\n2 2\n2 0\n0 0\n-1 0\n1 0\n\nSample Output 1\n\n2\n1\n\nThe Manhattan distance between the first student and each checkpoint is:\n\nFor checkpoint 1: |2-(-1)|+|0-0|=3\n\nFor checkpoint 2: |2-1|+|0-0|=1\n\nThe nearest checkpoint is checkpoint 2. Thus, the first line in the output should contain 2.\n\nThe Manhattan distance between the second student and each checkpoint is:\n\nFor checkpoint 1: |0-(-1)|+|0-0|=1\n\nFor checkpoint 2: |0-1|+|0-0|=1\n\nWhen there are multiple nearest checkpoints, the student will go to the checkpoint with the smallest index. Thus, the second line in the output should contain 1.\n\nSample Input 2\n\n3 4\n10 10\n-10 -10\n3 3\n1 2\n2 3\n3 5\n3 5\n\nSample Output 2\n\n3\n1\n2\n\nThere can be multiple checkpoints at the same coordinates.\n\nSample Input 3\n\n5 5\n-100000000 -100000000\n-100000000 100000000\n100000000 -100000000\n100000000 100000000\n0 0\n0 0\n100000000 100000000\n100000000 -100000000\n-100000000 100000000\n-100000000 -100000000\n\nSample Output 3\n\n5\n4\n3\n2\n1", "sample_input": "2 2\n2 0\n0 0\n-1 0\n1 0\n"}, "reference_outputs": ["2\n1\n"], "source_document_id": "p03774", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N students and M checkpoints on the xy-plane.\n\nThe coordinates of the i-th student (1 \\leq i \\leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \\leq j \\leq M) is (c_j,d_j).\n\nWhen the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.\n\nThe Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.\n\nHere, |x| denotes the absolute value of x.\n\nIf there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.\n\nWhich checkpoint will each student go to?\n\nConstraints\n\n1 \\leq N,M \\leq 50\n\n-10^8 \\leq a_i,b_i,c_j,d_j \\leq 10^8\n\nAll input values are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN M\na_1 b_1\n:\na_N b_N\nc_1 d_1\n:\nc_M d_M\n\nOutput\n\nPrint N lines.\n\nThe i-th line (1 \\leq i \\leq N) should contain the index of the checkpoint for the i-th student to go.\n\nSample Input 1\n\n2 2\n2 0\n0 0\n-1 0\n1 0\n\nSample Output 1\n\n2\n1\n\nThe Manhattan distance between the first student and each checkpoint is:\n\nFor checkpoint 1: |2-(-1)|+|0-0|=3\n\nFor checkpoint 2: |2-1|+|0-0|=1\n\nThe nearest checkpoint is checkpoint 2. Thus, the first line in the output should contain 2.\n\nThe Manhattan distance between the second student and each checkpoint is:\n\nFor checkpoint 1: |0-(-1)|+|0-0|=1\n\nFor checkpoint 2: |0-1|+|0-0|=1\n\nWhen there are multiple nearest checkpoints, the student will go to the checkpoint with the smallest index. Thus, the second line in the output should contain 1.\n\nSample Input 2\n\n3 4\n10 10\n-10 -10\n3 3\n1 2\n2 3\n3 5\n3 5\n\nSample Output 2\n\n3\n1\n2\n\nThere can be multiple checkpoints at the same coordinates.\n\nSample Input 3\n\n5 5\n-100000000 -100000000\n-100000000 100000000\n100000000 -100000000\n100000000 100000000\n0 0\n0 0\n100000000 100000000\n100000000 -100000000\n-100000000 100000000\n-100000000 -100000000\n\nSample Output 3\n\n5\n4\n3\n2\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 456, "cpu_time_ms": 127, "memory_kb": 13280}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s597050272", "group_id": "codeNet:p03775", "input_text": "(let ((n (read))\n (ans 0)\n (a 0)\n (b 0))\n (loop for i from 1 while (<= (* i i) n) do\n (if (zerop (rem n i))\n (progn\n (setq a i)\n (setq b (/ n i))\n (if (= ans 0)\n (setq ans (max (length (princ-to-string a)) (length (princ-to-string b))))\n (if (> ans (max (length (princ-to-string a)) (length (princ-to-string b))))\n (setq ans (max (length (princ-to-string a)) (length (princ-to-string b))))\n )\n )\n (if (not (= (* i i) n))\n (progn\n (setq a i)\n (setq b (/ n i))\n (if (> ans (max (length (princ-to-string a)) (length (princ-to-string b))))\n (setq ans (max (length (princ-to-string a)) (length (princ-to-string b))))\n )\n )\n )\n )\n )\n )\n (princ ans)\n)", "language": "Lisp", "metadata": {"date": 1594389935, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03775.html", "problem_id": "p03775", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03775/input.txt", "sample_output_relpath": "derived/input_output/data/p03775/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03775/Lisp/s597050272.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s597050272", "user_id": "u136500538"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((n (read))\n (ans 0)\n (a 0)\n (b 0))\n (loop for i from 1 while (<= (* i i) n) do\n (if (zerop (rem n i))\n (progn\n (setq a i)\n (setq b (/ n i))\n (if (= ans 0)\n (setq ans (max (length (princ-to-string a)) (length (princ-to-string b))))\n (if (> ans (max (length (princ-to-string a)) (length (princ-to-string b))))\n (setq ans (max (length (princ-to-string a)) (length (princ-to-string b))))\n )\n )\n (if (not (= (* i i) n))\n (progn\n (setq a i)\n (setq b (/ n i))\n (if (> ans (max (length (princ-to-string a)) (length (princ-to-string b))))\n (setq ans (max (length (princ-to-string a)) (length (princ-to-string b))))\n )\n )\n )\n )\n )\n )\n (princ ans)\n)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given an integer N.\n\nFor two positive integers A and B, we will define F(A,B) as the larger of the following: the number of digits in the decimal notation of A, and the number of digits in the decimal notation of B.\n\nFor example, F(3,11) = 2 since 3 has one digit and 11 has two digits.\n\nFind the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \\times B.\n\nConstraints\n\n1 \\leq N \\leq 10^{10}\n\nN is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \\times B.\n\nSample Input 1\n\n10000\n\nSample Output 1\n\n3\n\nF(A,B) has a minimum value of 3 at (A,B)=(100,100).\n\nSample Input 2\n\n1000003\n\nSample Output 2\n\n7\n\nThere are two pairs (A,B) that satisfy the condition: (1,1000003) and (1000003,1). For these pairs, F(1,1000003)=F(1000003,1)=7.\n\nSample Input 3\n\n9876543210\n\nSample Output 3\n\n6", "sample_input": "10000\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03775", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given an integer N.\n\nFor two positive integers A and B, we will define F(A,B) as the larger of the following: the number of digits in the decimal notation of A, and the number of digits in the decimal notation of B.\n\nFor example, F(3,11) = 2 since 3 has one digit and 11 has two digits.\n\nFind the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \\times B.\n\nConstraints\n\n1 \\leq N \\leq 10^{10}\n\nN is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \\times B.\n\nSample Input 1\n\n10000\n\nSample Output 1\n\n3\n\nF(A,B) has a minimum value of 3 at (A,B)=(100,100).\n\nSample Input 2\n\n1000003\n\nSample Output 2\n\n7\n\nThere are two pairs (A,B) that satisfy the condition: (1,1000003) and (1000003,1). For these pairs, F(1,1000003)=F(1000003,1)=7.\n\nSample Input 3\n\n9876543210\n\nSample Output 3\n\n6", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 941, "cpu_time_ms": 19, "memory_kb": 24628}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s701392836", "group_id": "codeNet:p03776", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Compute binomial coefficient by direct bignum arithmetic\n;;;\n;;; This code ist almost the same as that of alexandria.\n;;;\n\n(declaim (inline %multiply-range))\n(defun %multiply-range (i j)\n (labels ((bisect (j k)\n (declare (type (integer 1 #.most-positive-fixnum) j k)\n (values integer))\n (if (< (- k j) 8)\n (multiply-range j k)\n (let ((middle (+ j (truncate (- k j) 2))))\n (* (bisect j middle)\n (bisect (+ middle 1) k)))))\n (multiply-range (j k)\n (declare (type (integer 1 #.most-positive-fixnum) j k))\n (do ((f k (* f m))\n (m (1- k) (1- m)))\n ((< m j) f)\n (declare (type (integer 0 (#.most-positive-fixnum)) m)\n (type unsigned-byte f)))))\n (bisect i j)))\n\n(declaim (inline factorial))\n(defun factorial (n)\n (%multiply-range 1 n))\n\n(defun binomial-coefficient (n k)\n (declare #.OPT\n ((integer 0 (#.most-positive-fixnum)) n k))\n (assert (>= n k))\n (if (or (zerop k) (= n k))\n 1\n (let ((n-k (- n k)))\n (when (< k n-k)\n (rotatef k n-k))\n (if (= 1 n-k)\n n\n (floor (%multiply-range (+ k 1) n)\n\t (%multiply-range 1 n-k))))))\n\n(defun multiset-coefficient (n k)\n (binomial-coefficient (+ n k -1) k))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (a (read))\n (b (read))\n (vs (sort (make-array n :element-type 'uint62 :initial-contents (the list (loop repeat n collect (read)))) #'>))\n (max-score (loop for end from a to b maximize (/ (loop for i below end sum (aref vs i) of-type uint62) end)))\n (prevs (make-array n :element-type 'uint32 :initial-element 1)))\n (declare (uint8 n a b))\n (println (float max-score 1d0))\n (loop for i from 1 below n\n do (if (= (aref vs i) (aref vs (- i 1)))\n (setf (aref prevs i) (+ (aref prevs (- i 1)) 1))\n 1))\n (let ((chunks (copy-seq prevs))\n (i (- n 1)))\n (declare ((simple-array uint32 (*)) chunks))\n (loop (when (<= i 0)\n (return))\n (loop for j from i downto 0\n until (= 1 (aref chunks j))\n do (setf (aref chunks j) (aref chunks i))\n finally (setf (aref chunks j) (aref chunks i))\n (setf i (- j 1))))\n (println\n (loop for end from a to b\n for score = (/ (loop for i below end sum (aref vs i) of-type uint62) end)\n when (= score max-score)\n sum (binomial-coefficient (aref chunks (- end 1)) (aref prevs (- end 1)))\n of-type uint62)))))\n\n#-swank(main)\n\n", "language": "Lisp", "metadata": {"date": 1560055415, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03776.html", "problem_id": "p03776", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03776/input.txt", "sample_output_relpath": "derived/input_output/data/p03776/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03776/Lisp/s701392836.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s701392836", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4.500000\n1\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Compute binomial coefficient by direct bignum arithmetic\n;;;\n;;; This code ist almost the same as that of alexandria.\n;;;\n\n(declaim (inline %multiply-range))\n(defun %multiply-range (i j)\n (labels ((bisect (j k)\n (declare (type (integer 1 #.most-positive-fixnum) j k)\n (values integer))\n (if (< (- k j) 8)\n (multiply-range j k)\n (let ((middle (+ j (truncate (- k j) 2))))\n (* (bisect j middle)\n (bisect (+ middle 1) k)))))\n (multiply-range (j k)\n (declare (type (integer 1 #.most-positive-fixnum) j k))\n (do ((f k (* f m))\n (m (1- k) (1- m)))\n ((< m j) f)\n (declare (type (integer 0 (#.most-positive-fixnum)) m)\n (type unsigned-byte f)))))\n (bisect i j)))\n\n(declaim (inline factorial))\n(defun factorial (n)\n (%multiply-range 1 n))\n\n(defun binomial-coefficient (n k)\n (declare #.OPT\n ((integer 0 (#.most-positive-fixnum)) n k))\n (assert (>= n k))\n (if (or (zerop k) (= n k))\n 1\n (let ((n-k (- n k)))\n (when (< k n-k)\n (rotatef k n-k))\n (if (= 1 n-k)\n n\n (floor (%multiply-range (+ k 1) n)\n\t (%multiply-range 1 n-k))))))\n\n(defun multiset-coefficient (n k)\n (binomial-coefficient (+ n k -1) k))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (a (read))\n (b (read))\n (vs (sort (make-array n :element-type 'uint62 :initial-contents (the list (loop repeat n collect (read)))) #'>))\n (max-score (loop for end from a to b maximize (/ (loop for i below end sum (aref vs i) of-type uint62) end)))\n (prevs (make-array n :element-type 'uint32 :initial-element 1)))\n (declare (uint8 n a b))\n (println (float max-score 1d0))\n (loop for i from 1 below n\n do (if (= (aref vs i) (aref vs (- i 1)))\n (setf (aref prevs i) (+ (aref prevs (- i 1)) 1))\n 1))\n (let ((chunks (copy-seq prevs))\n (i (- n 1)))\n (declare ((simple-array uint32 (*)) chunks))\n (loop (when (<= i 0)\n (return))\n (loop for j from i downto 0\n until (= 1 (aref chunks j))\n do (setf (aref chunks j) (aref chunks i))\n finally (setf (aref chunks j) (aref chunks i))\n (setf i (- j 1))))\n (println\n (loop for end from a to b\n for score = (/ (loop for i below end sum (aref vs i) of-type uint62) end)\n when (= score max-score)\n sum (binomial-coefficient (aref chunks (- end 1)) (aref prevs (- end 1)))\n of-type uint62)))))\n\n#-swank(main)\n\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYou are given N items.\n\nThe value of the i-th item (1 \\leq i \\leq N) is v_i.\n\nYour have to select at least A and at most B of these items.\n\nUnder this condition, find the maximum possible arithmetic mean of the values of selected items.\n\nAdditionally, find the number of ways to select items so that the mean of the values of selected items is maximized.\n\nConstraints\n\n1 \\leq N \\leq 50\n\n1 \\leq A,B \\leq N\n\n1 \\leq v_i \\leq 10^{15}\n\nEach v_i is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN A B\nv_1\nv_2\n...\nv_N\n\nOutput\n\nPrint two lines.\n\nThe first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.\n\nThe second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.\n\nSample Input 1\n\n5 2 2\n1 2 3 4 5\n\nSample Output 1\n\n4.500000\n1\n\nThe mean of the values of selected items will be maximized when selecting the fourth and fifth items. Hence, the first line of the output should contain 4.5.\n\nThere is no other way to select items so that the mean of the values will be 4.5, and thus the second line of the output should contain 1.\n\nSample Input 2\n\n4 2 3\n10 20 10 10\n\nSample Output 2\n\n15.000000\n3\n\nThere can be multiple ways to select items so that the mean of the values will be maximized.\n\nSample Input 3\n\n5 1 5\n1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996\n\nSample Output 3\n\n1000000000000000.000000\n1", "sample_input": "5 2 2\n1 2 3 4 5\n"}, "reference_outputs": ["4.500000\n1\n"], "source_document_id": "p03776", "source_text": "Score : 400 points\n\nProblem Statement\n\nYou are given N items.\n\nThe value of the i-th item (1 \\leq i \\leq N) is v_i.\n\nYour have to select at least A and at most B of these items.\n\nUnder this condition, find the maximum possible arithmetic mean of the values of selected items.\n\nAdditionally, find the number of ways to select items so that the mean of the values of selected items is maximized.\n\nConstraints\n\n1 \\leq N \\leq 50\n\n1 \\leq A,B \\leq N\n\n1 \\leq v_i \\leq 10^{15}\n\nEach v_i is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN A B\nv_1\nv_2\n...\nv_N\n\nOutput\n\nPrint two lines.\n\nThe first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.\n\nThe second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.\n\nSample Input 1\n\n5 2 2\n1 2 3 4 5\n\nSample Output 1\n\n4.500000\n1\n\nThe mean of the values of selected items will be maximized when selecting the fourth and fifth items. Hence, the first line of the output should contain 4.5.\n\nThere is no other way to select items so that the mean of the values will be 4.5, and thus the second line of the output should contain 1.\n\nSample Input 2\n\n4 2 3\n10 20 10 10\n\nSample Output 2\n\n15.000000\n3\n\nThere can be multiple ways to select items so that the mean of the values will be maximized.\n\nSample Input 3\n\n5 1 5\n1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996\n\nSample Output 3\n\n1000000000000000.000000\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4078, "cpu_time_ms": 267, "memory_kb": 33248}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s734897760", "group_id": "codeNet:p03776", "input_text": "(defun input (n)\n (let ((a (make-array n)))\n (loop for i below n do (setf (aref a i) (read)))\n a))\n\n(defparameter *fact-array* (make-array 60))\n(setf (aref *fact-array* 0) 1)\n(setf (aref *fact-array* 1) 1)\n(defun fact (n)\n (let ((x (aref *fact-array* n)))\n (if (> x 0)\n x\n (progn (setf (aref *fact-array* n) (* n (fact (1- n))))\n (aref *fact-array* n)))))\n(defun ncr (n r) (/ (fact n) (fact r) (fact (- n r))))\n\n(defun solve (a b v)\n (let ((ave (/ (loop for i below a sum (aref v i)) a))\n (num (count (aref v (1- a)) v))\n (tmp (loop for i from (1- a) downto 0 unless (= (aref v i) (aref v (1- a))) return (- a i 1))))\n (cons (float ave)\n (if (= (aref v 0) (aref v (1- a)))\n (loop for i from a to b when (<= i num) sum (ncr num i))\n (ncr num tmp)))))\n\n(let* ((n (read))\n (a (read))\n (b (read))\n (v (sort (input n) #'>))\n (e (solve a b v)))\n (format t \"~,6F~%~A~%\" (car e) (cdr e)))", "language": "Lisp", "metadata": {"date": 1524970572, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03776.html", "problem_id": "p03776", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03776/input.txt", "sample_output_relpath": "derived/input_output/data/p03776/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03776/Lisp/s734897760.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s734897760", "user_id": "u672956630"}, "prompt_components": {"gold_output": "4.500000\n1\n", "input_to_evaluate": "(defun input (n)\n (let ((a (make-array n)))\n (loop for i below n do (setf (aref a i) (read)))\n a))\n\n(defparameter *fact-array* (make-array 60))\n(setf (aref *fact-array* 0) 1)\n(setf (aref *fact-array* 1) 1)\n(defun fact (n)\n (let ((x (aref *fact-array* n)))\n (if (> x 0)\n x\n (progn (setf (aref *fact-array* n) (* n (fact (1- n))))\n (aref *fact-array* n)))))\n(defun ncr (n r) (/ (fact n) (fact r) (fact (- n r))))\n\n(defun solve (a b v)\n (let ((ave (/ (loop for i below a sum (aref v i)) a))\n (num (count (aref v (1- a)) v))\n (tmp (loop for i from (1- a) downto 0 unless (= (aref v i) (aref v (1- a))) return (- a i 1))))\n (cons (float ave)\n (if (= (aref v 0) (aref v (1- a)))\n (loop for i from a to b when (<= i num) sum (ncr num i))\n (ncr num tmp)))))\n\n(let* ((n (read))\n (a (read))\n (b (read))\n (v (sort (input n) #'>))\n (e (solve a b v)))\n (format t \"~,6F~%~A~%\" (car e) (cdr e)))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYou are given N items.\n\nThe value of the i-th item (1 \\leq i \\leq N) is v_i.\n\nYour have to select at least A and at most B of these items.\n\nUnder this condition, find the maximum possible arithmetic mean of the values of selected items.\n\nAdditionally, find the number of ways to select items so that the mean of the values of selected items is maximized.\n\nConstraints\n\n1 \\leq N \\leq 50\n\n1 \\leq A,B \\leq N\n\n1 \\leq v_i \\leq 10^{15}\n\nEach v_i is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN A B\nv_1\nv_2\n...\nv_N\n\nOutput\n\nPrint two lines.\n\nThe first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.\n\nThe second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.\n\nSample Input 1\n\n5 2 2\n1 2 3 4 5\n\nSample Output 1\n\n4.500000\n1\n\nThe mean of the values of selected items will be maximized when selecting the fourth and fifth items. Hence, the first line of the output should contain 4.5.\n\nThere is no other way to select items so that the mean of the values will be 4.5, and thus the second line of the output should contain 1.\n\nSample Input 2\n\n4 2 3\n10 20 10 10\n\nSample Output 2\n\n15.000000\n3\n\nThere can be multiple ways to select items so that the mean of the values will be maximized.\n\nSample Input 3\n\n5 1 5\n1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996\n\nSample Output 3\n\n1000000000000000.000000\n1", "sample_input": "5 2 2\n1 2 3 4 5\n"}, "reference_outputs": ["4.500000\n1\n"], "source_document_id": "p03776", "source_text": "Score : 400 points\n\nProblem Statement\n\nYou are given N items.\n\nThe value of the i-th item (1 \\leq i \\leq N) is v_i.\n\nYour have to select at least A and at most B of these items.\n\nUnder this condition, find the maximum possible arithmetic mean of the values of selected items.\n\nAdditionally, find the number of ways to select items so that the mean of the values of selected items is maximized.\n\nConstraints\n\n1 \\leq N \\leq 50\n\n1 \\leq A,B \\leq N\n\n1 \\leq v_i \\leq 10^{15}\n\nEach v_i is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN A B\nv_1\nv_2\n...\nv_N\n\nOutput\n\nPrint two lines.\n\nThe first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.\n\nThe second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.\n\nSample Input 1\n\n5 2 2\n1 2 3 4 5\n\nSample Output 1\n\n4.500000\n1\n\nThe mean of the values of selected items will be maximized when selecting the fourth and fifth items. Hence, the first line of the output should contain 4.5.\n\nThere is no other way to select items so that the mean of the values will be 4.5, and thus the second line of the output should contain 1.\n\nSample Input 2\n\n4 2 3\n10 20 10 10\n\nSample Output 2\n\n15.000000\n3\n\nThere can be multiple ways to select items so that the mean of the values will be maximized.\n\nSample Input 3\n\n5 1 5\n1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996\n\nSample Output 3\n\n1000000000000000.000000\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 987, "cpu_time_ms": 176, "memory_kb": 18788}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s608408255", "group_id": "codeNet:p03777", "input_text": "(let* ((a (read-char))\n (x (read-char))\n (b (read-char)))\n (if (char= a b) (princ \"H\") (princ \"D\")))", "language": "Lisp", "metadata": {"date": 1559847544, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03777.html", "problem_id": "p03777", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03777/input.txt", "sample_output_relpath": "derived/input_output/data/p03777/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03777/Lisp/s608408255.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s608408255", "user_id": "u610490393"}, "prompt_components": {"gold_output": "H\n", "input_to_evaluate": "(let* ((a (read-char))\n (x (read-char))\n (b (read-char)))\n (if (char= a b) (princ \"H\") (princ \"D\")))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTwo deer, AtCoDeer and TopCoDeer, are playing a game called Honest or Dishonest.\nIn this game, an honest player always tells the truth, and an dishonest player always tell lies.\nYou are given two characters a and b as the input. Each of them is either H or D, and carries the following information:\n\nIf a=H, AtCoDeer is honest; if a=D, AtCoDeer is dishonest.\nIf b=H, AtCoDeer is saying that TopCoDeer is honest; if b=D, AtCoDeer is saying that TopCoDeer is dishonest.\n\nGiven this information, determine whether TopCoDeer is honest.\n\nConstraints\n\na=H or a=D.\n\nb=H or b=D.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf TopCoDeer is honest, print H. If he is dishonest, print D.\n\nSample Input 1\n\nH H\n\nSample Output 1\n\nH\n\nIn this input, AtCoDeer is honest. Hence, as he says, TopCoDeer is honest.\n\nSample Input 2\n\nD H\n\nSample Output 2\n\nD\n\nIn this input, AtCoDeer is dishonest. Hence, contrary to what he says, TopCoDeer is dishonest.\n\nSample Input 3\n\nD D\n\nSample Output 3\n\nH", "sample_input": "H H\n"}, "reference_outputs": ["H\n"], "source_document_id": "p03777", "source_text": "Score : 100 points\n\nProblem Statement\n\nTwo deer, AtCoDeer and TopCoDeer, are playing a game called Honest or Dishonest.\nIn this game, an honest player always tells the truth, and an dishonest player always tell lies.\nYou are given two characters a and b as the input. Each of them is either H or D, and carries the following information:\n\nIf a=H, AtCoDeer is honest; if a=D, AtCoDeer is dishonest.\nIf b=H, AtCoDeer is saying that TopCoDeer is honest; if b=D, AtCoDeer is saying that TopCoDeer is dishonest.\n\nGiven this information, determine whether TopCoDeer is honest.\n\nConstraints\n\na=H or a=D.\n\nb=H or b=D.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf TopCoDeer is honest, print H. If he is dishonest, print D.\n\nSample Input 1\n\nH H\n\nSample Output 1\n\nH\n\nIn this input, AtCoDeer is honest. Hence, as he says, TopCoDeer is honest.\n\nSample Input 2\n\nD H\n\nSample Output 2\n\nD\n\nIn this input, AtCoDeer is dishonest. Hence, contrary to what he says, TopCoDeer is dishonest.\n\nSample Input 3\n\nD D\n\nSample Output 3\n\nH", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 113, "cpu_time_ms": 92, "memory_kb": 8036}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s718498917", "group_id": "codeNet:p03780", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod- (&rest args)\n (reduce (lambda (x y) (mod (- x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod- (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (- ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'uint31))\n (dp (make-array (list (+ n 1) (+ k 1)) :element-type 'uint31))\n (dp2 (make-array (list n (+ k 1)) :element-type 'uint31))\n (powers (make-array 5000 :element-type 'uint31 :initial-element 1)))\n (declare (uint16 n k))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i (- (length powers) 1))\n (setf (aref powers (+ i 1))\n (mod (ash (aref powers i) 1) +mod+)))\n (dotimes (x (+ n 1))\n (dotimes (y (+ k 1))\n (setf (aref dp x y)\n (if (zerop x)\n (if (zerop y) 1 0)\n (mod+ (aref dp (- x 1) y)\n (aref dp (- x 1) (max 0 (- y (aref as (- x 1))))))))))\n (dotimes (i n)\n (dotimes (y (+ k 1))\n (setf (aref dp2 i y)\n (if (zerop y)\n (aref powers (- n 1))\n (mod- (aref dp n y)\n (aref dp2 i (max 0 (- y (aref as i)))))))))\n (println\n (loop for i below n\n count (= (aref dp n k)\n (mod (ash (aref dp2 i k) 1) +mod+))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 6\n1 4 3\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 400\n3 1 4 1 5\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 20\n10 4 3 10 25 2\n\"\n \"3\n\")))\n", "language": "Lisp", "metadata": {"date": 1579936577, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03780.html", "problem_id": "p03780", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03780/input.txt", "sample_output_relpath": "derived/input_output/data/p03780/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03780/Lisp/s718498917.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s718498917", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; FIXME: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one.\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod- (&rest args)\n (reduce (lambda (x y) (mod (- x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod- (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (- ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'uint31))\n (dp (make-array (list (+ n 1) (+ k 1)) :element-type 'uint31))\n (dp2 (make-array (list n (+ k 1)) :element-type 'uint31))\n (powers (make-array 5000 :element-type 'uint31 :initial-element 1)))\n (declare (uint16 n k))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i (- (length powers) 1))\n (setf (aref powers (+ i 1))\n (mod (ash (aref powers i) 1) +mod+)))\n (dotimes (x (+ n 1))\n (dotimes (y (+ k 1))\n (setf (aref dp x y)\n (if (zerop x)\n (if (zerop y) 1 0)\n (mod+ (aref dp (- x 1) y)\n (aref dp (- x 1) (max 0 (- y (aref as (- x 1))))))))))\n (dotimes (i n)\n (dotimes (y (+ k 1))\n (setf (aref dp2 i y)\n (if (zerop y)\n (aref powers (- n 1))\n (mod- (aref dp n y)\n (aref dp2 i (max 0 (- y (aref as i)))))))))\n (println\n (loop for i below n\n count (= (aref dp n k)\n (mod (ash (aref dp2 i k) 1) +mod+))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 6\n1 4 3\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 400\n3 1 4 1 5\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 20\n10 4 3 10 25 2\n\"\n \"3\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nAtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i.\nBecause he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.\n\nThen, for each card i, he judges whether it is unnecessary or not, as follows:\n\nIf, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.\n\nOtherwise, card i is NOT unnecessary.\n\nFind the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.\n\nConstraints\n\nAll input values are integers.\n\n1≤N≤5000\n\n1≤K≤5000\n\n1≤a_i≤10^9 (1≤i≤N)\n\nPartial Score\n\n300 points will be awarded for passing the test set satisfying N,K≤400.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN K\na_1 a_2 ... a_N\n\nOutput\n\nPrint the number of the unnecessary cards.\n\nSample Input 1\n\n3 6\n1 4 3\n\nSample Output 1\n\n1\n\nThere are two good sets: {2,3} and {1,2,3}.\n\nCard 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is also good. Thus, card 1 is unnecessary.\n\nFor card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is NOT unnecessary.\n\nNeither is card 3 for a similar reason, hence the answer is 1.\n\nSample Input 2\n\n5 400\n3 1 4 1 5\n\nSample Output 2\n\n5\n\nIn this case, there is no good set. Therefore, all the cards are unnecessary.\n\nSample Input 3\n\n6 20\n10 4 3 10 25 2\n\nSample Output 3\n\n3", "sample_input": "3 6\n1 4 3\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03780", "source_text": "Score : 600 points\n\nProblem Statement\n\nAtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i.\nBecause he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.\n\nThen, for each card i, he judges whether it is unnecessary or not, as follows:\n\nIf, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.\n\nOtherwise, card i is NOT unnecessary.\n\nFind the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.\n\nConstraints\n\nAll input values are integers.\n\n1≤N≤5000\n\n1≤K≤5000\n\n1≤a_i≤10^9 (1≤i≤N)\n\nPartial Score\n\n300 points will be awarded for passing the test set satisfying N,K≤400.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN K\na_1 a_2 ... a_N\n\nOutput\n\nPrint the number of the unnecessary cards.\n\nSample Input 1\n\n3 6\n1 4 3\n\nSample Output 1\n\n1\n\nThere are two good sets: {2,3} and {1,2,3}.\n\nCard 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is also good. Thus, card 1 is unnecessary.\n\nFor card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is NOT unnecessary.\n\nNeither is card 3 for a similar reason, hence the answer is 1.\n\nSample Input 2\n\n5 400\n3 1 4 1 5\n\nSample Output 2\n\n5\n\nIn this case, there is no good set. Therefore, all the cards are unnecessary.\n\nSample Input 3\n\n6 20\n10 4 3 10 25 2\n\nSample Output 3\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7364, "cpu_time_ms": 1180, "memory_kb": 221924}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s227313196", "group_id": "codeNet:p03781", "input_text": "(defun atari (X)\n (floor (1- (sqrt (1+ (* 8 X)))) 2) )\n\n(defun solve (X &optional (Y (1- (atari X))))\n (if (<= X (/ (* Y (1+ Y)) 2)) Y\n (solve X (1+ Y)) ))\n\n(princ (solve(read)))", "language": "Lisp", "metadata": {"date": 1584733142, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03781.html", "problem_id": "p03781", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03781/input.txt", "sample_output_relpath": "derived/input_output/data/p03781/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03781/Lisp/s227313196.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s227313196", "user_id": "u334552723"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun atari (X)\n (floor (1- (sqrt (1+ (* 8 X)))) 2) )\n\n(defun solve (X &optional (Y (1- (atari X))))\n (if (<= X (/ (* Y (1+ Y)) 2)) Y\n (solve X (1+ Y)) ))\n\n(princ (solve(read)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0.\nDuring the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right.\nThat is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i.\nThe kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible.\nFind the earliest possible time to reach coordinate X.\n\nConstraints\n\nX is an integer.\n\n1≤X≤10^9\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the earliest possible time for the kangaroo to reach coordinate X.\n\nSample Input 1\n\n6\n\nSample Output 1\n\n3\n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times, which is the earliest possible time.\n\nSample Input 2\n\n2\n\nSample Output 2\n\n2\n\nHe can reach his nest at time 2 by staying at his position during the first second, and jumping to the right at the next second.\n\nSample Input 3\n\n11\n\nSample Output 3\n\n5", "sample_input": "6\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03781", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0.\nDuring the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right.\nThat is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i.\nThe kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible.\nFind the earliest possible time to reach coordinate X.\n\nConstraints\n\nX is an integer.\n\n1≤X≤10^9\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the earliest possible time for the kangaroo to reach coordinate X.\n\nSample Input 1\n\n6\n\nSample Output 1\n\n3\n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times, which is the earliest possible time.\n\nSample Input 2\n\n2\n\nSample Output 2\n\n2\n\nHe can reach his nest at time 2 by staying at his position during the first second, and jumping to the right at the next second.\n\nSample Input 3\n\n11\n\nSample Output 3\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 183, "cpu_time_ms": 21, "memory_kb": 6504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s884497668", "group_id": "codeNet:p03785", "input_text": "(locally (declare (optimize (speed 3) (safety 0)))\n (defun split-with (string &key (delimiterp #'(lambda (c) (char= c #\\Space))))\n (loop :for beg = (position-if-not delimiterp string)\n :then (position-if-not delimiterp string :start (1+ end))\n :for end = (and beg (position-if delimiterp string :start beg))\n :when beg :collect (subseq string beg end)\n :while end))\n \n (defun count-bus (n c k t-list) \n (declare (ignore n))\n (declare (integer c k))\n (let ((t0 (aref t-list 0))\n (ptr 0)\n (count 0))\n (loop\n :while (< ptr (- n 1))\n :do (loop\n :for i :downfrom (if (< (length t-list) c)\n (- (length t-list) 1)\n (- c 1))\n :when (<= (aref t-list (+ i ptr)) (+ t0 k))\n :do (progn (incf count)\n (setf ptr (+ i ptr 1))\n (unless (zerop (length t-list))\n (setf t0 (aref t-list ptr)))\n (loop-finish))))\n count))\n \n (let* ((fl (split-with (read-line t nil nil)))\n (n (parse-integer (car fl)))\n (c (parse-integer (cadr fl)))\n (k (parse-integer (caddr fl)))\n (t-list (coerce (sort (loop :for x = (read-line t nil nil)\n :repeat n\n :while x\n :collect (parse-integer x))\n #'<)\n 'vector)))\n (format t \"~d~%\" (count-bus n c k t-list))))\n", "language": "Lisp", "metadata": {"date": 1489371633, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03785.html", "problem_id": "p03785", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03785/input.txt", "sample_output_relpath": "derived/input_output/data/p03785/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03785/Lisp/s884497668.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s884497668", "user_id": "u690263481"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(locally (declare (optimize (speed 3) (safety 0)))\n (defun split-with (string &key (delimiterp #'(lambda (c) (char= c #\\Space))))\n (loop :for beg = (position-if-not delimiterp string)\n :then (position-if-not delimiterp string :start (1+ end))\n :for end = (and beg (position-if delimiterp string :start beg))\n :when beg :collect (subseq string beg end)\n :while end))\n \n (defun count-bus (n c k t-list) \n (declare (ignore n))\n (declare (integer c k))\n (let ((t0 (aref t-list 0))\n (ptr 0)\n (count 0))\n (loop\n :while (< ptr (- n 1))\n :do (loop\n :for i :downfrom (if (< (length t-list) c)\n (- (length t-list) 1)\n (- c 1))\n :when (<= (aref t-list (+ i ptr)) (+ t0 k))\n :do (progn (incf count)\n (setf ptr (+ i ptr 1))\n (unless (zerop (length t-list))\n (setf t0 (aref t-list ptr)))\n (loop-finish))))\n count))\n \n (let* ((fl (split-with (read-line t nil nil)))\n (n (parse-integer (car fl)))\n (c (parse-integer (cadr fl)))\n (k (parse-integer (caddr fl)))\n (t-list (coerce (sort (loop :for x = (read-line t nil nil)\n :repeat n\n :while x\n :collect (parse-integer x))\n #'<)\n 'vector)))\n (format t \"~d~%\" (count-bus n c k t-list))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nEvery day, N passengers arrive at Takahashi Airport.\nThe i-th passenger arrives at time T_i.\n\nEvery passenger arrived at Takahashi airport travels to the city by bus. Each bus can accommodate up to C passengers.\nNaturally, a passenger cannot take a bus that departs earlier than the airplane arrives at the airport.\nAlso, a passenger will get angry if he/she is still unable to take a bus K units of time after the arrival of the airplane.\nFor that reason, it is necessary to arrange buses so that the i-th passenger can take a bus departing at time between T_i and T_i + K (inclusive).\n\nWhen setting the departure times for buses under this condition, find the minimum required number of buses.\nHere, the departure time for each bus does not need to be an integer, and there may be multiple buses that depart at the same time.\n\nConstraints\n\n2 \\leq N \\leq 100000\n\n1 \\leq C \\leq 10^9\n\n1 \\leq K \\leq 10^9\n\n1 \\leq T_i \\leq 10^9\n\nC, K and T_i are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN C K\nT_1\nT_2\n:\nT_N\n\nOutput\n\nPrint the minimum required number of buses.\n\nSample Input 1\n\n5 3 5\n1\n2\n3\n6\n12\n\nSample Output 1\n\n3\n\nFor example, the following three buses are enough:\n\nA bus departing at time 4.5, that carries the passengers arriving at time 2 and 3.\n\nA bus departing at time 6, that carries the passengers arriving at time 1 and 6.\n\nA bus departing at time 12, that carries the passenger arriving at time 12.\n\nSample Input 2\n\n6 3 3\n7\n6\n2\n8\n10\n6\n\nSample Output 2\n\n3", "sample_input": "5 3 5\n1\n2\n3\n6\n12\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03785", "source_text": "Score : 300 points\n\nProblem Statement\n\nEvery day, N passengers arrive at Takahashi Airport.\nThe i-th passenger arrives at time T_i.\n\nEvery passenger arrived at Takahashi airport travels to the city by bus. Each bus can accommodate up to C passengers.\nNaturally, a passenger cannot take a bus that departs earlier than the airplane arrives at the airport.\nAlso, a passenger will get angry if he/she is still unable to take a bus K units of time after the arrival of the airplane.\nFor that reason, it is necessary to arrange buses so that the i-th passenger can take a bus departing at time between T_i and T_i + K (inclusive).\n\nWhen setting the departure times for buses under this condition, find the minimum required number of buses.\nHere, the departure time for each bus does not need to be an integer, and there may be multiple buses that depart at the same time.\n\nConstraints\n\n2 \\leq N \\leq 100000\n\n1 \\leq C \\leq 10^9\n\n1 \\leq K \\leq 10^9\n\n1 \\leq T_i \\leq 10^9\n\nC, K and T_i are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN C K\nT_1\nT_2\n:\nT_N\n\nOutput\n\nPrint the minimum required number of buses.\n\nSample Input 1\n\n5 3 5\n1\n2\n3\n6\n12\n\nSample Output 1\n\n3\n\nFor example, the following three buses are enough:\n\nA bus departing at time 4.5, that carries the passengers arriving at time 2 and 3.\n\nA bus departing at time 6, that carries the passengers arriving at time 1 and 6.\n\nA bus departing at time 12, that carries the passenger arriving at time 12.\n\nSample Input 2\n\n6 3 3\n7\n6\n2\n8\n10\n6\n\nSample Output 2\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1616, "cpu_time_ms": 2104, "memory_kb": 43496}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s017694279", "group_id": "codeNet:p03786", "input_text": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n(defvar n (read))\n(defvar a (make-array n))\n(loop for i from 0 below n\n do (setf (aref a i) (read)))\n(sort a #'>)\n(defun solve ()\n (loop for i from 1 below n\n for able = 0\n do (loop for j from (1- n) downto 0\n initially (setq able (aref a i))\n unless (= j i)\n if (> (aref a j) (* able 2))\n do (return-from solve i)\n else do (setq able (+ able (aref a j)))\n finally (setq able 0)))\n n)\n(format t \"~A~%\" (solve))", "language": "Lisp", "metadata": {"date": 1522195655, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03786.html", "problem_id": "p03786", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03786/input.txt", "sample_output_relpath": "derived/input_output/data/p03786/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03786/Lisp/s017694279.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s017694279", "user_id": "u672956630"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n(defvar n (read))\n(defvar a (make-array n))\n(loop for i from 0 below n\n do (setf (aref a i) (read)))\n(sort a #'>)\n(defun solve ()\n (loop for i from 1 below n\n for able = 0\n do (loop for j from (1- n) downto 0\n initially (setq able (aref a i))\n unless (= j i)\n if (> (aref a j) (* able 2))\n do (return-from solve i)\n else do (setq able (+ able (aref a j)))\n finally (setq able 0)))\n n)\n(format t \"~A~%\" (solve))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nSnuke found N strange creatures.\nEach creature has a fixed color and size. The color and size of the i-th creature are represented by i and A_i, respectively.\n\nEvery creature can absorb another creature whose size is at most twice the size of itself.\nWhen a creature of size A and color B absorbs another creature of size C and color D (C \\leq 2 \\times A), they will merge into one creature of size A+C and color B.\nHere, depending on the sizes of two creatures, it is possible that both of them can absorb the other.\n\nSnuke has been watching these creatures merge over and over and ultimately become one creature.\nFind the number of the possible colors of this creature.\n\nConstraints\n\n2 \\leq N \\leq 100000\n\n1 \\leq A_i \\leq 10^9\n\nA_i is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nA_1 A_2 … A_N\n\nOutput\n\nPrint the number of the possible colors of the last remaining creature after the N creatures repeatedly merge and ultimately become one creature.\n\nSample Input 1\n\n3\n3 1 4\n\nSample Output 1\n\n2\n\nThe possible colors of the last remaining creature are colors 1 and 3.\nFor example, when the creature of color 3 absorbs the creature of color 2, then the creature of color 1 absorbs the creature of color 3, the color of the last remaining creature will be color 1.\n\nSample Input 2\n\n5\n1 1 1 1 1\n\nSample Output 2\n\n5\n\nThere may be multiple creatures of the same size.\n\nSample Input 3\n\n6\n40 1 30 2 7 20\n\nSample Output 3\n\n4", "sample_input": "3\n3 1 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03786", "source_text": "Score : 400 points\n\nProblem Statement\n\nSnuke found N strange creatures.\nEach creature has a fixed color and size. The color and size of the i-th creature are represented by i and A_i, respectively.\n\nEvery creature can absorb another creature whose size is at most twice the size of itself.\nWhen a creature of size A and color B absorbs another creature of size C and color D (C \\leq 2 \\times A), they will merge into one creature of size A+C and color B.\nHere, depending on the sizes of two creatures, it is possible that both of them can absorb the other.\n\nSnuke has been watching these creatures merge over and over and ultimately become one creature.\nFind the number of the possible colors of this creature.\n\nConstraints\n\n2 \\leq N \\leq 100000\n\n1 \\leq A_i \\leq 10^9\n\nA_i is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nA_1 A_2 … A_N\n\nOutput\n\nPrint the number of the possible colors of the last remaining creature after the N creatures repeatedly merge and ultimately become one creature.\n\nSample Input 1\n\n3\n3 1 4\n\nSample Output 1\n\n2\n\nThe possible colors of the last remaining creature are colors 1 and 3.\nFor example, when the creature of color 3 absorbs the creature of color 2, then the creature of color 1 absorbs the creature of color 3, the color of the last remaining creature will be color 1.\n\nSample Input 2\n\n5\n1 1 1 1 1\n\nSample Output 2\n\n5\n\nThere may be multiple creatures of the same size.\n\nSample Input 3\n\n6\n40 1 30 2 7 20\n\nSample Output 3\n\n4", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 579, "cpu_time_ms": 2105, "memory_kb": 57704}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s785697654", "group_id": "codeNet:p03792", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n feasible\n (plan (make-array (list n n) :element-type 'bit :initial-element 0))\n (rows (make-array n :element-type 'uint32 :initial-element 0))\n (cols (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (let ((line (read-line)))\n (dotimes (j n)\n (when (char= #\\# (aref line j))\n (setf (aref plan i j) 1)\n (setq feasible t)\n (incf (aref rows i))\n (incf (aref cols j))))))\n (unless feasible\n (println -1)\n (return-from main))\n (println\n (+ (- n (count n cols))\n (loop for row below n\n minimize (+ (loop for j below n\n count (zerop (aref plan row j)))\n (if (loop for i below n\n always (zerop (aref plan i row)))\n 1\n 0)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n#.\n.#\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n..\n..\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n##\n##\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n.#.\n###\n.#.\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n...\n.#.\n...\n\"\n \"5\n\")))\n", "language": "Lisp", "metadata": {"date": 1583396059, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03792.html", "problem_id": "p03792", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03792/input.txt", "sample_output_relpath": "derived/input_output/data/p03792/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03792/Lisp/s785697654.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s785697654", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n feasible\n (plan (make-array (list n n) :element-type 'bit :initial-element 0))\n (rows (make-array n :element-type 'uint32 :initial-element 0))\n (cols (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (let ((line (read-line)))\n (dotimes (j n)\n (when (char= #\\# (aref line j))\n (setf (aref plan i j) 1)\n (setq feasible t)\n (incf (aref rows i))\n (incf (aref cols j))))))\n (unless feasible\n (println -1)\n (return-from main))\n (println\n (+ (- n (count n cols))\n (loop for row below n\n minimize (+ (loop for j below n\n count (zerop (aref plan row j)))\n (if (loop for i below n\n always (zerop (aref plan i row)))\n 1\n 0)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n#.\n.#\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n..\n..\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n##\n##\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n.#.\n###\n.#.\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n...\n.#.\n...\n\"\n \"5\n\")))\n", "problem_context": "Score : 1300 points\n\nProblem Statement\n\nThere is a square-shaped grid with N vertical rows and N horizontal columns.\nWe will denote the square at the i-th row from the top and the j-th column from the left as (i,\\ j).\n\nInitially, each square is either white or black.\nThe initial color of the grid is given to you as characters a_{ij}, arranged in a square shape.\nIf the square (i,\\ j) is white, a_{ij} is .. If it is black, a_{ij} is #.\n\nYou are developing a robot that repaints the grid.\nIt can repeatedly perform the following operation:\n\nSelect two integers i, j (1 ≤ i,\\ j ≤ N). Memorize the colors of the squares (i,\\ 1), (i,\\ 2), ..., (i,\\ N) as c_1, c_2, ..., c_N, respectively. Then, repaint the squares (1,\\ j), (2,\\ j), ..., (N,\\ j) with the colors c_1, c_2, ..., c_N, respectively.\n\nYour objective is to turn all the squares black.\nDetermine whether it is possible, and find the minimum necessary number of operations to achieve it if the answer is positive.\n\nConstraints\n\n2 ≤ N ≤ 500\n\na_{ij} is either . or #.\n\nPartial Score\n\nIn a test set worth 300 points, N ≤ 3.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\na_{11}...a_{1N}\n:\na_{N1}...a_{NN}\n\nOutput\n\nIf it is possible to turn all the squares black, print the minimum necessary number of operations to achieve the objective.\nIf it is impossible, print -1 instead.\n\nSample Input 1\n\n2\n#.\n.#\n\nSample Output 1\n\n3\n\nFor example, perform the operation as follows:\n\nSelect i = 1, j = 2.\n\nSelect i = 1, j = 1.\n\nSelect i = 1, j = 2.\n\nThe transition of the colors of the squares is shown in the figure below:\n\nSample Input 2\n\n2\n..\n..\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n2\n##\n##\n\nSample Output 3\n\n0\n\nSample Input 4\n\n3\n.#.\n###\n.#.\n\nSample Output 4\n\n2\n\nSample Input 5\n\n3\n...\n.#.\n...\n\nSample Output 5\n\n5", "sample_input": "2\n#.\n.#\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03792", "source_text": "Score : 1300 points\n\nProblem Statement\n\nThere is a square-shaped grid with N vertical rows and N horizontal columns.\nWe will denote the square at the i-th row from the top and the j-th column from the left as (i,\\ j).\n\nInitially, each square is either white or black.\nThe initial color of the grid is given to you as characters a_{ij}, arranged in a square shape.\nIf the square (i,\\ j) is white, a_{ij} is .. If it is black, a_{ij} is #.\n\nYou are developing a robot that repaints the grid.\nIt can repeatedly perform the following operation:\n\nSelect two integers i, j (1 ≤ i,\\ j ≤ N). Memorize the colors of the squares (i,\\ 1), (i,\\ 2), ..., (i,\\ N) as c_1, c_2, ..., c_N, respectively. Then, repaint the squares (1,\\ j), (2,\\ j), ..., (N,\\ j) with the colors c_1, c_2, ..., c_N, respectively.\n\nYour objective is to turn all the squares black.\nDetermine whether it is possible, and find the minimum necessary number of operations to achieve it if the answer is positive.\n\nConstraints\n\n2 ≤ N ≤ 500\n\na_{ij} is either . or #.\n\nPartial Score\n\nIn a test set worth 300 points, N ≤ 3.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\na_{11}...a_{1N}\n:\na_{N1}...a_{NN}\n\nOutput\n\nIf it is possible to turn all the squares black, print the minimum necessary number of operations to achieve the objective.\nIf it is impossible, print -1 instead.\n\nSample Input 1\n\n2\n#.\n.#\n\nSample Output 1\n\n3\n\nFor example, perform the operation as follows:\n\nSelect i = 1, j = 2.\n\nSelect i = 1, j = 1.\n\nSelect i = 1, j = 2.\n\nThe transition of the colors of the squares is shown in the figure below:\n\nSample Input 2\n\n2\n..\n..\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n2\n##\n##\n\nSample Output 3\n\n0\n\nSample Input 4\n\n3\n.#.\n###\n.#.\n\nSample Output 4\n\n2\n\nSample Input 5\n\n3\n...\n.#.\n...\n\nSample Output 5\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4942, "cpu_time_ms": 97, "memory_kb": 18920}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s257939942", "group_id": "codeNet:p03792", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (diagonal 0)\n (safe 0)\n (plan (make-array (list n n) :element-type 'bit :initial-element 0))\n (rows (make-array n :element-type 'uint32 :initial-element 0))\n (cols (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (let ((line (read-line)))\n (dotimes (j n)\n (when (char= #\\# (aref line j))\n (setf (aref plan i j) 1)\n (if (= i j)\n (incf diagonal)\n (incf safe))\n (incf (aref rows i))\n (incf (aref cols j))))))\n (when (= 0 diagonal safe)\n (println -1)\n (return-from main))\n (when (find n rows)\n (println (- n (count n cols)))\n (return-from main))\n (when (find n cols)\n (println (- n (count n rows)))\n (return-from main))\n (let ((base (if (zerop safe)\n #xffffffff\n (+ 1 (min (reduce #'max rows :key (lambda (x) (- n x)))\n (reduce #'max cols :key (lambda (x) (- n x))))))))\n #>base\n (dotimes (i n)\n (dotimes (j n)\n (when (= 1 (aref plan i j))\n (minf base (- n (aref rows j)))\n (minf base (- n (aref cols i)))\n (when (= i j)\n (minf base\n (+ 1 (min (loop for row below n\n when (= 1 (aref plan row i))\n minimize (- n (aref rows row)))\n (loop for col below n\n when (= 1 (aref plan j col))\n minimize (- n (aref cols col))))))))))\n (assert (< base #xffffffff))\n (println (+ base n)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n#.\n.#\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n..\n..\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n##\n##\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n.#.\n###\n.#.\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n...\n.#.\n...\n\"\n \"5\n\")))\n", "language": "Lisp", "metadata": {"date": 1583386112, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03792.html", "problem_id": "p03792", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03792/input.txt", "sample_output_relpath": "derived/input_output/data/p03792/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03792/Lisp/s257939942.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s257939942", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (diagonal 0)\n (safe 0)\n (plan (make-array (list n n) :element-type 'bit :initial-element 0))\n (rows (make-array n :element-type 'uint32 :initial-element 0))\n (cols (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (let ((line (read-line)))\n (dotimes (j n)\n (when (char= #\\# (aref line j))\n (setf (aref plan i j) 1)\n (if (= i j)\n (incf diagonal)\n (incf safe))\n (incf (aref rows i))\n (incf (aref cols j))))))\n (when (= 0 diagonal safe)\n (println -1)\n (return-from main))\n (when (find n rows)\n (println (- n (count n cols)))\n (return-from main))\n (when (find n cols)\n (println (- n (count n rows)))\n (return-from main))\n (let ((base (if (zerop safe)\n #xffffffff\n (+ 1 (min (reduce #'max rows :key (lambda (x) (- n x)))\n (reduce #'max cols :key (lambda (x) (- n x))))))))\n #>base\n (dotimes (i n)\n (dotimes (j n)\n (when (= 1 (aref plan i j))\n (minf base (- n (aref rows j)))\n (minf base (- n (aref cols i)))\n (when (= i j)\n (minf base\n (+ 1 (min (loop for row below n\n when (= 1 (aref plan row i))\n minimize (- n (aref rows row)))\n (loop for col below n\n when (= 1 (aref plan j col))\n minimize (- n (aref cols col))))))))))\n (assert (< base #xffffffff))\n (println (+ base n)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n#.\n.#\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n..\n..\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n##\n##\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n.#.\n###\n.#.\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n...\n.#.\n...\n\"\n \"5\n\")))\n", "problem_context": "Score : 1300 points\n\nProblem Statement\n\nThere is a square-shaped grid with N vertical rows and N horizontal columns.\nWe will denote the square at the i-th row from the top and the j-th column from the left as (i,\\ j).\n\nInitially, each square is either white or black.\nThe initial color of the grid is given to you as characters a_{ij}, arranged in a square shape.\nIf the square (i,\\ j) is white, a_{ij} is .. If it is black, a_{ij} is #.\n\nYou are developing a robot that repaints the grid.\nIt can repeatedly perform the following operation:\n\nSelect two integers i, j (1 ≤ i,\\ j ≤ N). Memorize the colors of the squares (i,\\ 1), (i,\\ 2), ..., (i,\\ N) as c_1, c_2, ..., c_N, respectively. Then, repaint the squares (1,\\ j), (2,\\ j), ..., (N,\\ j) with the colors c_1, c_2, ..., c_N, respectively.\n\nYour objective is to turn all the squares black.\nDetermine whether it is possible, and find the minimum necessary number of operations to achieve it if the answer is positive.\n\nConstraints\n\n2 ≤ N ≤ 500\n\na_{ij} is either . or #.\n\nPartial Score\n\nIn a test set worth 300 points, N ≤ 3.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\na_{11}...a_{1N}\n:\na_{N1}...a_{NN}\n\nOutput\n\nIf it is possible to turn all the squares black, print the minimum necessary number of operations to achieve the objective.\nIf it is impossible, print -1 instead.\n\nSample Input 1\n\n2\n#.\n.#\n\nSample Output 1\n\n3\n\nFor example, perform the operation as follows:\n\nSelect i = 1, j = 2.\n\nSelect i = 1, j = 1.\n\nSelect i = 1, j = 2.\n\nThe transition of the colors of the squares is shown in the figure below:\n\nSample Input 2\n\n2\n..\n..\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n2\n##\n##\n\nSample Output 3\n\n0\n\nSample Input 4\n\n3\n.#.\n###\n.#.\n\nSample Output 4\n\n2\n\nSample Input 5\n\n3\n...\n.#.\n...\n\nSample Output 5\n\n5", "sample_input": "2\n#.\n.#\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03792", "source_text": "Score : 1300 points\n\nProblem Statement\n\nThere is a square-shaped grid with N vertical rows and N horizontal columns.\nWe will denote the square at the i-th row from the top and the j-th column from the left as (i,\\ j).\n\nInitially, each square is either white or black.\nThe initial color of the grid is given to you as characters a_{ij}, arranged in a square shape.\nIf the square (i,\\ j) is white, a_{ij} is .. If it is black, a_{ij} is #.\n\nYou are developing a robot that repaints the grid.\nIt can repeatedly perform the following operation:\n\nSelect two integers i, j (1 ≤ i,\\ j ≤ N). Memorize the colors of the squares (i,\\ 1), (i,\\ 2), ..., (i,\\ N) as c_1, c_2, ..., c_N, respectively. Then, repaint the squares (1,\\ j), (2,\\ j), ..., (N,\\ j) with the colors c_1, c_2, ..., c_N, respectively.\n\nYour objective is to turn all the squares black.\nDetermine whether it is possible, and find the minimum necessary number of operations to achieve it if the answer is positive.\n\nConstraints\n\n2 ≤ N ≤ 500\n\na_{ij} is either . or #.\n\nPartial Score\n\nIn a test set worth 300 points, N ≤ 3.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\na_{11}...a_{1N}\n:\na_{N1}...a_{NN}\n\nOutput\n\nIf it is possible to turn all the squares black, print the minimum necessary number of operations to achieve the objective.\nIf it is impossible, print -1 instead.\n\nSample Input 1\n\n2\n#.\n.#\n\nSample Output 1\n\n3\n\nFor example, perform the operation as follows:\n\nSelect i = 1, j = 2.\n\nSelect i = 1, j = 1.\n\nSelect i = 1, j = 2.\n\nThe transition of the colors of the squares is shown in the figure below:\n\nSample Input 2\n\n2\n..\n..\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n2\n##\n##\n\nSample Output 3\n\n0\n\nSample Input 4\n\n3\n.#.\n###\n.#.\n\nSample Output 4\n\n2\n\nSample Input 5\n\n3\n...\n.#.\n...\n\nSample Output 5\n\n5", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5725, "cpu_time_ms": 234, "memory_kb": 30184}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s258829341", "group_id": "codeNet:p03795", "input_text": "(princ(-(*(setq a(read))800)(*(floor a 15)200)))", "language": "Lisp", "metadata": {"date": 1528281335, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03795.html", "problem_id": "p03795", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03795/input.txt", "sample_output_relpath": "derived/input_output/data/p03795/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03795/Lisp/s258829341.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s258829341", "user_id": "u657913472"}, "prompt_components": {"gold_output": "15800\n", "input_to_evaluate": "(princ(-(*(setq a(read))800)(*(floor a 15)200)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nSnuke has a favorite restaurant.\n\nThe price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer.\n\nSo far, Snuke has ordered N meals at the restaurant.\nLet the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen.\nFind x-y.\n\nConstraints\n\n1 ≤ N ≤ 100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n20\n\nSample Output 1\n\n15800\n\nSo far, Snuke has paid 16000 yen, and the restaurant has paid back 200 yen. Thus, the answer is 15800.\n\nSample Input 2\n\n60\n\nSample Output 2\n\n47200\n\nSnuke has paid 48000 yen for 60 meals, and the restaurant has paid back 800 yen.", "sample_input": "20\n"}, "reference_outputs": ["15800\n"], "source_document_id": "p03795", "source_text": "Score : 100 points\n\nProblem Statement\n\nSnuke has a favorite restaurant.\n\nThe price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer.\n\nSo far, Snuke has ordered N meals at the restaurant.\nLet the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen.\nFind x-y.\n\nConstraints\n\n1 ≤ N ≤ 100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n20\n\nSample Output 1\n\n15800\n\nSo far, Snuke has paid 16000 yen, and the restaurant has paid back 200 yen. Thus, the answer is 15800.\n\nSample Input 2\n\n60\n\nSample Output 2\n\n47200\n\nSnuke has paid 48000 yen for 60 meals, and the restaurant has paid back 800 yen.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 48, "cpu_time_ms": 74, "memory_kb": 8164}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s016354555", "group_id": "codeNet:p03795", "input_text": "(defun main ()\n(setq n (read))\n(format t \"~A~%\" (- (* n 800) (* 200 (floor (/ n 15)))))\n)\n(main)", "language": "Lisp", "metadata": {"date": 1489184568, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03795.html", "problem_id": "p03795", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03795/input.txt", "sample_output_relpath": "derived/input_output/data/p03795/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03795/Lisp/s016354555.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s016354555", "user_id": "u610490393"}, "prompt_components": {"gold_output": "15800\n", "input_to_evaluate": "(defun main ()\n(setq n (read))\n(format t \"~A~%\" (- (* n 800) (* 200 (floor (/ n 15)))))\n)\n(main)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nSnuke has a favorite restaurant.\n\nThe price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer.\n\nSo far, Snuke has ordered N meals at the restaurant.\nLet the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen.\nFind x-y.\n\nConstraints\n\n1 ≤ N ≤ 100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n20\n\nSample Output 1\n\n15800\n\nSo far, Snuke has paid 16000 yen, and the restaurant has paid back 200 yen. Thus, the answer is 15800.\n\nSample Input 2\n\n60\n\nSample Output 2\n\n47200\n\nSnuke has paid 48000 yen for 60 meals, and the restaurant has paid back 800 yen.", "sample_input": "20\n"}, "reference_outputs": ["15800\n"], "source_document_id": "p03795", "source_text": "Score : 100 points\n\nProblem Statement\n\nSnuke has a favorite restaurant.\n\nThe price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer.\n\nSo far, Snuke has ordered N meals at the restaurant.\nLet the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen.\nFind x-y.\n\nConstraints\n\n1 ≤ N ≤ 100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n20\n\nSample Output 1\n\n15800\n\nSo far, Snuke has paid 16000 yen, and the restaurant has paid back 200 yen. Thus, the answer is 15800.\n\nSample Input 2\n\n60\n\nSample Output 2\n\n47200\n\nSnuke has paid 48000 yen for 60 meals, and the restaurant has paid back 800 yen.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 96, "cpu_time_ms": 178, "memory_kb": 14436}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s295626727", "group_id": "codeNet:p03795", "input_text": "(let ((n (parse-integer (read-line))))\n (format t \"~A~%\"\n (- (* n 800) (* 200 (floor (/ n 15))))))", "language": "Lisp", "metadata": {"date": 1487470063, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03795.html", "problem_id": "p03795", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03795/input.txt", "sample_output_relpath": "derived/input_output/data/p03795/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03795/Lisp/s295626727.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s295626727", "user_id": "u275710783"}, "prompt_components": {"gold_output": "15800\n", "input_to_evaluate": "(let ((n (parse-integer (read-line))))\n (format t \"~A~%\"\n (- (* n 800) (* 200 (floor (/ n 15))))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nSnuke has a favorite restaurant.\n\nThe price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer.\n\nSo far, Snuke has ordered N meals at the restaurant.\nLet the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen.\nFind x-y.\n\nConstraints\n\n1 ≤ N ≤ 100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n20\n\nSample Output 1\n\n15800\n\nSo far, Snuke has paid 16000 yen, and the restaurant has paid back 200 yen. Thus, the answer is 15800.\n\nSample Input 2\n\n60\n\nSample Output 2\n\n47200\n\nSnuke has paid 48000 yen for 60 meals, and the restaurant has paid back 800 yen.", "sample_input": "20\n"}, "reference_outputs": ["15800\n"], "source_document_id": "p03795", "source_text": "Score : 100 points\n\nProblem Statement\n\nSnuke has a favorite restaurant.\n\nThe price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer.\n\nSo far, Snuke has ordered N meals at the restaurant.\nLet the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen.\nFind x-y.\n\nConstraints\n\n1 ≤ N ≤ 100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n20\n\nSample Output 1\n\n15800\n\nSo far, Snuke has paid 16000 yen, and the restaurant has paid back 200 yen. Thus, the answer is 15800.\n\nSample Input 2\n\n60\n\nSample Output 2\n\n47200\n\nSnuke has paid 48000 yen for 60 meals, and the restaurant has paid back 800 yen.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 108, "cpu_time_ms": 676, "memory_kb": 13668}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s500882737", "group_id": "codeNet:p03796", "input_text": "(let ((n (read))\n (s 1))\n\n (loop for i from 1 to n\n do (setq s (mod (* s i) (+ (expt 10 9) 7))))\n\n (format t \"~A~%\" s))\n", "language": "Lisp", "metadata": {"date": 1572735937, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03796.html", "problem_id": "p03796", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03796/input.txt", "sample_output_relpath": "derived/input_output/data/p03796/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03796/Lisp/s500882737.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s500882737", "user_id": "u336541610"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(let ((n (read))\n (s 1))\n\n (loop for i from 1 to n\n do (setq s (mod (* s i) (+ (expt 10 9) 7))))\n\n (format t \"~A~%\" s))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nSnuke loves working out. He is now exercising N times.\n\nBefore he starts exercising, his power is 1. After he exercises for the i-th time, his power gets multiplied by i.\n\nFind Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.\n\nConstraints\n\n1 ≤ N ≤ 10^{5}\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer modulo 10^{9}+7.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\nAfter Snuke exercises for the first time, his power gets multiplied by 1 and becomes 1.\n\nAfter Snuke exercises for the second time, his power gets multiplied by 2 and becomes 2.\n\nAfter Snuke exercises for the third time, his power gets multiplied by 3 and becomes 6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n3628800\n\nSample Input 3\n\n100000\n\nSample Output 3\n\n457992974\n\nPrint the answer modulo 10^{9}+7.", "sample_input": "3\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03796", "source_text": "Score : 200 points\n\nProblem Statement\n\nSnuke loves working out. He is now exercising N times.\n\nBefore he starts exercising, his power is 1. After he exercises for the i-th time, his power gets multiplied by i.\n\nFind Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.\n\nConstraints\n\n1 ≤ N ≤ 10^{5}\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer modulo 10^{9}+7.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\nAfter Snuke exercises for the first time, his power gets multiplied by 1 and becomes 1.\n\nAfter Snuke exercises for the second time, his power gets multiplied by 2 and becomes 2.\n\nAfter Snuke exercises for the third time, his power gets multiplied by 3 and becomes 6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n3628800\n\nSample Input 3\n\n100000\n\nSample Output 3\n\n457992974\n\nPrint the answer modulo 10^{9}+7.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 134, "cpu_time_ms": 140, "memory_kb": 13280}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s632298271", "group_id": "codeNet:p03796", "input_text": "(setq s 1)\n(dotimes(i(read))(setq s(mod(* s(1+ i))1000000007)))\n(princ s)", "language": "Lisp", "metadata": {"date": 1535374740, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03796.html", "problem_id": "p03796", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03796/input.txt", "sample_output_relpath": "derived/input_output/data/p03796/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03796/Lisp/s632298271.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s632298271", "user_id": "u657913472"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(setq s 1)\n(dotimes(i(read))(setq s(mod(* s(1+ i))1000000007)))\n(princ s)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nSnuke loves working out. He is now exercising N times.\n\nBefore he starts exercising, his power is 1. After he exercises for the i-th time, his power gets multiplied by i.\n\nFind Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.\n\nConstraints\n\n1 ≤ N ≤ 10^{5}\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer modulo 10^{9}+7.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\nAfter Snuke exercises for the first time, his power gets multiplied by 1 and becomes 1.\n\nAfter Snuke exercises for the second time, his power gets multiplied by 2 and becomes 2.\n\nAfter Snuke exercises for the third time, his power gets multiplied by 3 and becomes 6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n3628800\n\nSample Input 3\n\n100000\n\nSample Output 3\n\n457992974\n\nPrint the answer modulo 10^{9}+7.", "sample_input": "3\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03796", "source_text": "Score : 200 points\n\nProblem Statement\n\nSnuke loves working out. He is now exercising N times.\n\nBefore he starts exercising, his power is 1. After he exercises for the i-th time, his power gets multiplied by i.\n\nFind Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.\n\nConstraints\n\n1 ≤ N ≤ 10^{5}\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer modulo 10^{9}+7.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\nAfter Snuke exercises for the first time, his power gets multiplied by 1 and becomes 1.\n\nAfter Snuke exercises for the second time, his power gets multiplied by 2 and becomes 2.\n\nAfter Snuke exercises for the third time, his power gets multiplied by 3 and becomes 6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n3628800\n\nSample Input 3\n\n100000\n\nSample Output 3\n\n457992974\n\nPrint the answer modulo 10^{9}+7.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 73, "cpu_time_ms": 139, "memory_kb": 12648}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s322423602", "group_id": "codeNet:p03797", "input_text": "(defun split (str delim)\n (let ((res (make-array 1 :element-type 'string\n :fill-pointer 0\n :adjustable t)))\n (loop for i from 0 below (length str)\n with start = 0\n when (eq (char str i) delim)\n do (vector-push-extend (subseq str start i) res)\n (setf start (1+ i))\n finally (let ((tail (subseq str start)))\n (when tail\n (vector-push-extend tail res))))\n res))\n\n(let* ((line (map 'vector #'parse-integer (split (read-line) #\\Space)))\n (n (aref line 0))\n (m (truncate (aref line 1) 2))\n (res 0)\n (nmin (min n m)))\n (incf res nmin)\n (decf n nmin)\n (decf m nmin)\n (incf res (truncate m 2))\n (format t \"~A~%\" res))", "language": "Lisp", "metadata": {"date": 1487471050, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03797.html", "problem_id": "p03797", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03797/input.txt", "sample_output_relpath": "derived/input_output/data/p03797/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03797/Lisp/s322423602.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s322423602", "user_id": "u275710783"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun split (str delim)\n (let ((res (make-array 1 :element-type 'string\n :fill-pointer 0\n :adjustable t)))\n (loop for i from 0 below (length str)\n with start = 0\n when (eq (char str i) delim)\n do (vector-push-extend (subseq str start i) res)\n (setf start (1+ i))\n finally (let ((tail (subseq str start)))\n (when tail\n (vector-push-extend tail res))))\n res))\n\n(let* ((line (map 'vector #'parse-integer (split (read-line) #\\Space)))\n (n (aref line 0))\n (m (truncate (aref line 1) 2))\n (res 0)\n (nmin (min n m)))\n (incf res nmin)\n (decf n nmin)\n (decf m nmin)\n (incf res (truncate m 2))\n (format t \"~A~%\" res))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke loves puzzles.\n\nToday, he is working on a puzzle using S- and c-shaped pieces.\nIn this puzzle, you can combine two c-shaped pieces into one S-shaped piece, as shown in the figure below:\n\nSnuke decided to create as many Scc groups as possible by putting together one S-shaped piece and two c-shaped pieces.\n\nFind the maximum number of Scc groups that can be created when Snuke has N S-shaped pieces and M c-shaped pieces.\n\nConstraints\n\n1 ≤ N,M ≤ 10^{12}\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n1 6\n\nSample Output 1\n\n2\n\nTwo Scc groups can be created as follows:\n\nCombine two c-shaped pieces into one S-shaped piece\n\nCreate two Scc groups, each from one S-shaped piece and two c-shaped pieces\n\nSample Input 2\n\n12345 678901\n\nSample Output 2\n\n175897", "sample_input": "1 6\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03797", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke loves puzzles.\n\nToday, he is working on a puzzle using S- and c-shaped pieces.\nIn this puzzle, you can combine two c-shaped pieces into one S-shaped piece, as shown in the figure below:\n\nSnuke decided to create as many Scc groups as possible by putting together one S-shaped piece and two c-shaped pieces.\n\nFind the maximum number of Scc groups that can be created when Snuke has N S-shaped pieces and M c-shaped pieces.\n\nConstraints\n\n1 ≤ N,M ≤ 10^{12}\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n1 6\n\nSample Output 1\n\n2\n\nTwo Scc groups can be created as follows:\n\nCombine two c-shaped pieces into one S-shaped piece\n\nCreate two Scc groups, each from one S-shaped piece and two c-shaped pieces\n\nSample Input 2\n\n12345 678901\n\nSample Output 2\n\n175897", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 784, "cpu_time_ms": 614, "memory_kb": 17128}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s393780987", "group_id": "codeNet:p03800", "input_text": "(defun calc (A1 AN S)\n (loop for si in S\n with a = A1\n and b = AN\n collect (if a #\\S #\\W)\n do \n (shiftf b a (eq (eq a b) si))\n finally (unless (eq A1 a) (return nil)) ))\n\n(defun solve (l)\n (concatenate 'string\n (or (calc t t l)\n (calc t nil l)\n (calc nil t l)\n (calc nil nil l)\n \"-1\")))\n(read)\n(princ (solve \n (mapcar (lambda (x) (eq x #\\o)) \n (concatenate 'list\n (read-line)) )))", "language": "Lisp", "metadata": {"date": 1585238274, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03800.html", "problem_id": "p03800", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03800/input.txt", "sample_output_relpath": "derived/input_output/data/p03800/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03800/Lisp/s393780987.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s393780987", "user_id": "u334552723"}, "prompt_components": {"gold_output": "SSSWWS\n", "input_to_evaluate": "(defun calc (A1 AN S)\n (loop for si in S\n with a = A1\n and b = AN\n collect (if a #\\S #\\W)\n do \n (shiftf b a (eq (eq a b) si))\n finally (unless (eq A1 a) (return nil)) ))\n\n(defun solve (l)\n (concatenate 'string\n (or (calc t t l)\n (calc t nil l)\n (calc nil t l)\n (calc nil nil l)\n \"-1\")))\n(read)\n(princ (solve \n (mapcar (lambda (x) (eq x #\\o)) \n (concatenate 'list\n (read-line)) )))", "problem_context": "Score : 500 points\n\nProblem Statement\n\nSnuke, who loves animals, built a zoo.\n\nThere are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle.\nThe animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1.\n\nThere are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies.\n\nSnuke cannot tell the difference between these two species, and asked each animal the following question: \"Are your neighbors of the same species?\" The animal numbered i answered s_i. Here, if s_i is o, the animal said that the two neighboring animals are of the same species, and if s_i is x, the animal said that the two neighboring animals are of different species.\n\nMore formally, a sheep answered o if the two neighboring animals are both sheep or both wolves, and answered x otherwise.\nSimilarly, a wolf answered x if the two neighboring animals are both sheep or both wolves, and answered o otherwise.\n\nSnuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print -1.\n\nConstraints\n\n3 ≤ N ≤ 10^{5}\n\ns is a string of length N consisting of o and x.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\ns\n\nOutput\n\nIf there does not exist an valid assignment that is consistent with s, print -1.\nOtherwise, print an string t in the following format. The output is considered correct if the assignment described by t is consistent with s.\n\nt is a string of length N consisting of S and W.\n\nIf t_i is S, it indicates that the animal numbered i is a sheep. If t_i is W, it indicates that the animal numbered i is a wolf.\n\nSample Input 1\n\n6\nooxoox\n\nSample Output 1\n\nSSSWWS\n\nFor example, if the animals numbered 1, 2, 3, 4, 5 and 6 are respectively a sheep, sheep, sheep, wolf, wolf, and sheep, it is consistent with their responses. Besides, there is another valid assignment of species: a wolf, sheep, wolf, sheep, wolf and wolf.\n\nLet us remind you: if the neiboring animals are of the same species, a sheep answers o and a wolf answers x. If the neiboring animals are of different species, a sheep answers x and a wolf answers o.\n\nSample Input 2\n\n3\noox\n\nSample Output 2\n\n-1\n\nPrint -1 if there is no valid assignment of species.\n\nSample Input 3\n\n10\noxooxoxoox\n\nSample Output 3\n\nSSWWSSSWWS", "sample_input": "6\nooxoox\n"}, "reference_outputs": ["SSSWWS\n"], "source_document_id": "p03800", "source_text": "Score : 500 points\n\nProblem Statement\n\nSnuke, who loves animals, built a zoo.\n\nThere are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle.\nThe animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1.\n\nThere are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies.\n\nSnuke cannot tell the difference between these two species, and asked each animal the following question: \"Are your neighbors of the same species?\" The animal numbered i answered s_i. Here, if s_i is o, the animal said that the two neighboring animals are of the same species, and if s_i is x, the animal said that the two neighboring animals are of different species.\n\nMore formally, a sheep answered o if the two neighboring animals are both sheep or both wolves, and answered x otherwise.\nSimilarly, a wolf answered x if the two neighboring animals are both sheep or both wolves, and answered o otherwise.\n\nSnuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print -1.\n\nConstraints\n\n3 ≤ N ≤ 10^{5}\n\ns is a string of length N consisting of o and x.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\ns\n\nOutput\n\nIf there does not exist an valid assignment that is consistent with s, print -1.\nOtherwise, print an string t in the following format. The output is considered correct if the assignment described by t is consistent with s.\n\nt is a string of length N consisting of S and W.\n\nIf t_i is S, it indicates that the animal numbered i is a sheep. If t_i is W, it indicates that the animal numbered i is a wolf.\n\nSample Input 1\n\n6\nooxoox\n\nSample Output 1\n\nSSSWWS\n\nFor example, if the animals numbered 1, 2, 3, 4, 5 and 6 are respectively a sheep, sheep, sheep, wolf, wolf, and sheep, it is consistent with their responses. Besides, there is another valid assignment of species: a wolf, sheep, wolf, sheep, wolf and wolf.\n\nLet us remind you: if the neiboring animals are of the same species, a sheep answers o and a wolf answers x. If the neiboring animals are of different species, a sheep answers x and a wolf answers o.\n\nSample Input 2\n\n3\noox\n\nSample Output 2\n\n-1\n\nPrint -1 if there is no valid assignment of species.\n\nSample Input 3\n\n10\noxooxoxoox\n\nSample Output 3\n\nSSWWSSSWWS", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 561, "cpu_time_ms": 29, "memory_kb": 14692}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s240239725", "group_id": "codeNet:p03803", "input_text": "(let((a #1=(mod(+(read)11)13))(b #1#))(princ(cond((< a b)\"Bob\")((> a b)\"Alice\")(t\"Draw\"))))", "language": "Lisp", "metadata": {"date": 1528278421, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03803.html", "problem_id": "p03803", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03803/input.txt", "sample_output_relpath": "derived/input_output/data/p03803/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03803/Lisp/s240239725.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s240239725", "user_id": "u657913472"}, "prompt_components": {"gold_output": "Alice\n", "input_to_evaluate": "(let((a #1=(mod(+(read)11)13))(b #1#))(princ(cond((< a b)\"Bob\")((> a b)\"Alice\")(t\"Draw\"))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nAlice and Bob are playing One Card Poker.\n\nOne Card Poker is a two-player game using playing cards.\n\nEach card in this game shows an integer between 1 and 13, inclusive.\n\nThe strength of a card is determined by the number written on it, as follows:\n\nWeak 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < 10 < 11 < 12 < 13 < 1 Strong\n\nOne Card Poker is played as follows:\n\nEach player picks one card from the deck. The chosen card becomes the player's hand.\n\nThe players reveal their hands to each other. The player with the stronger card wins the game.\n\nIf their cards are equally strong, the game is drawn.\n\nYou are watching Alice and Bob playing the game, and can see their hands.\n\nThe number written on Alice's card is A, and the number written on Bob's card is B.\n\nWrite a program to determine the outcome of the game.\n\nConstraints\n\n1≦A≦13\n\n1≦B≦13\n\nA and B are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint Alice if Alice will win. Print Bob if Bob will win. Print Draw if the game will be drawn.\n\nSample Input 1\n\n8 6\n\nSample Output 1\n\nAlice\n\n8 is written on Alice's card, and 6 is written on Bob's card.\nAlice has the stronger card, and thus the output should be Alice.\n\nSample Input 2\n\n1 1\n\nSample Output 2\n\nDraw\n\nSince their cards have the same number, the game will be drawn.\n\nSample Input 3\n\n13 1\n\nSample Output 3\n\nBob", "sample_input": "8 6\n"}, "reference_outputs": ["Alice\n"], "source_document_id": "p03803", "source_text": "Score : 100 points\n\nProblem Statement\n\nAlice and Bob are playing One Card Poker.\n\nOne Card Poker is a two-player game using playing cards.\n\nEach card in this game shows an integer between 1 and 13, inclusive.\n\nThe strength of a card is determined by the number written on it, as follows:\n\nWeak 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < 10 < 11 < 12 < 13 < 1 Strong\n\nOne Card Poker is played as follows:\n\nEach player picks one card from the deck. The chosen card becomes the player's hand.\n\nThe players reveal their hands to each other. The player with the stronger card wins the game.\n\nIf their cards are equally strong, the game is drawn.\n\nYou are watching Alice and Bob playing the game, and can see their hands.\n\nThe number written on Alice's card is A, and the number written on Bob's card is B.\n\nWrite a program to determine the outcome of the game.\n\nConstraints\n\n1≦A≦13\n\n1≦B≦13\n\nA and B are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint Alice if Alice will win. Print Bob if Bob will win. Print Draw if the game will be drawn.\n\nSample Input 1\n\n8 6\n\nSample Output 1\n\nAlice\n\n8 is written on Alice's card, and 6 is written on Bob's card.\nAlice has the stronger card, and thus the output should be Alice.\n\nSample Input 2\n\n1 1\n\nSample Output 2\n\nDraw\n\nSince their cards have the same number, the game will be drawn.\n\nSample Input 3\n\n13 1\n\nSample Output 3\n\nBob", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 91, "cpu_time_ms": 123, "memory_kb": 12648}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s550643325", "group_id": "codeNet:p03803", "input_text": "(defun split (str delim)\n (let ((res (make-array 1 :element-type 'string\n :fill-pointer 0\n :adjustable t)))\n (loop for i from 0 below (length str)\n with start = 0\n when (eq (char str i) delim)\n do (vector-push-extend (subseq str start i) res)\n (setf start (1+ i))\n finally (let ((tail (subseq str start)))\n (when tail\n (vector-push-extend tail res))))\n res))\n\n(let* ((l (map 'vector 'parse-integer (split (read-line) #\\ )))\n (a (aref l 0))\n (b (aref l 1)))\n (when (= a 1) (setf a 14))\n (when (= b 1) (setf b 14))\n (if (= a b)\n (format t \"Draw~%\")\n (if (> a b)\n (format t \"Alice~%\")\n (format t \"Bob~%\"))))", "language": "Lisp", "metadata": {"date": 1486866946, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03803.html", "problem_id": "p03803", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03803/input.txt", "sample_output_relpath": "derived/input_output/data/p03803/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03803/Lisp/s550643325.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s550643325", "user_id": "u275710783"}, "prompt_components": {"gold_output": "Alice\n", "input_to_evaluate": "(defun split (str delim)\n (let ((res (make-array 1 :element-type 'string\n :fill-pointer 0\n :adjustable t)))\n (loop for i from 0 below (length str)\n with start = 0\n when (eq (char str i) delim)\n do (vector-push-extend (subseq str start i) res)\n (setf start (1+ i))\n finally (let ((tail (subseq str start)))\n (when tail\n (vector-push-extend tail res))))\n res))\n\n(let* ((l (map 'vector 'parse-integer (split (read-line) #\\ )))\n (a (aref l 0))\n (b (aref l 1)))\n (when (= a 1) (setf a 14))\n (when (= b 1) (setf b 14))\n (if (= a b)\n (format t \"Draw~%\")\n (if (> a b)\n (format t \"Alice~%\")\n (format t \"Bob~%\"))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nAlice and Bob are playing One Card Poker.\n\nOne Card Poker is a two-player game using playing cards.\n\nEach card in this game shows an integer between 1 and 13, inclusive.\n\nThe strength of a card is determined by the number written on it, as follows:\n\nWeak 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < 10 < 11 < 12 < 13 < 1 Strong\n\nOne Card Poker is played as follows:\n\nEach player picks one card from the deck. The chosen card becomes the player's hand.\n\nThe players reveal their hands to each other. The player with the stronger card wins the game.\n\nIf their cards are equally strong, the game is drawn.\n\nYou are watching Alice and Bob playing the game, and can see their hands.\n\nThe number written on Alice's card is A, and the number written on Bob's card is B.\n\nWrite a program to determine the outcome of the game.\n\nConstraints\n\n1≦A≦13\n\n1≦B≦13\n\nA and B are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint Alice if Alice will win. Print Bob if Bob will win. Print Draw if the game will be drawn.\n\nSample Input 1\n\n8 6\n\nSample Output 1\n\nAlice\n\n8 is written on Alice's card, and 6 is written on Bob's card.\nAlice has the stronger card, and thus the output should be Alice.\n\nSample Input 2\n\n1 1\n\nSample Output 2\n\nDraw\n\nSince their cards have the same number, the game will be drawn.\n\nSample Input 3\n\n13 1\n\nSample Output 3\n\nBob", "sample_input": "8 6\n"}, "reference_outputs": ["Alice\n"], "source_document_id": "p03803", "source_text": "Score : 100 points\n\nProblem Statement\n\nAlice and Bob are playing One Card Poker.\n\nOne Card Poker is a two-player game using playing cards.\n\nEach card in this game shows an integer between 1 and 13, inclusive.\n\nThe strength of a card is determined by the number written on it, as follows:\n\nWeak 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < 10 < 11 < 12 < 13 < 1 Strong\n\nOne Card Poker is played as follows:\n\nEach player picks one card from the deck. The chosen card becomes the player's hand.\n\nThe players reveal their hands to each other. The player with the stronger card wins the game.\n\nIf their cards are equally strong, the game is drawn.\n\nYou are watching Alice and Bob playing the game, and can see their hands.\n\nThe number written on Alice's card is A, and the number written on Bob's card is B.\n\nWrite a program to determine the outcome of the game.\n\nConstraints\n\n1≦A≦13\n\n1≦B≦13\n\nA and B are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint Alice if Alice will win. Print Bob if Bob will win. Print Draw if the game will be drawn.\n\nSample Input 1\n\n8 6\n\nSample Output 1\n\nAlice\n\n8 is written on Alice's card, and 6 is written on Bob's card.\nAlice has the stronger card, and thus the output should be Alice.\n\nSample Input 2\n\n1 1\n\nSample Output 2\n\nDraw\n\nSince their cards have the same number, the game will be drawn.\n\nSample Input 3\n\n13 1\n\nSample Output 3\n\nBob", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 794, "cpu_time_ms": 549, "memory_kb": 16484}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s438023865", "group_id": "codeNet:p03804", "input_text": "(defun list-slice (lst x1 x2 y1 y2)\n (mapcar (lambda (k) (subseq k x1 x2)) (subseq lst y1 y2)))\n(let* ((n (read))\n (m (read))\n (lst-a (loop :repeat n :collect (concatenate 'list (read-line))))\n (lst-b (loop :repeat m :collect (concatenate 'list (read-line)))))\n (if (loop :for x :from 0 :upto (- n m)\n :never(loop :for y :from 0 :upto (- n m) :never (equal lst-b (list-slice lst-a x (+ x m) y (+ y m)))))\n (format t \"Yes~%\")\n (format t \"No~%\")))", "language": "Lisp", "metadata": {"date": 1572690561, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03804.html", "problem_id": "p03804", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03804/input.txt", "sample_output_relpath": "derived/input_output/data/p03804/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03804/Lisp/s438023865.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s438023865", "user_id": "u610490393"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun list-slice (lst x1 x2 y1 y2)\n (mapcar (lambda (k) (subseq k x1 x2)) (subseq lst y1 y2)))\n(let* ((n (read))\n (m (read))\n (lst-a (loop :repeat n :collect (concatenate 'list (read-line))))\n (lst-b (loop :repeat m :collect (concatenate 'list (read-line)))))\n (if (loop :for x :from 0 :upto (- n m)\n :never(loop :for y :from 0 :upto (- n m) :never (equal lst-b (list-slice lst-a x (+ x m) y (+ y m)))))\n (format t \"Yes~%\")\n (format t \"No~%\")))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.\n\nA pixel is the smallest element of an image, and in this problem it is a square of size 1×1.\n\nAlso, the given images are binary images, and the color of each pixel is either white or black.\n\nIn the input, every pixel is represented by a character: . corresponds to a white pixel, and # corresponds to a black pixel.\n\nThe image A is given as N strings A_1,...,A_N.\n\nThe j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1≦i,j≦N).\n\nSimilarly, the template image B is given as M strings B_1,...,B_M.\n\nThe j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1≦i,j≦M).\n\nDetermine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.\n\nConstraints\n\n1≦M≦N≦50\n\nA_i is a string of length N consisting of # and ..\n\nB_i is a string of length M consisting of # and ..\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN M\nA_1\nA_2\n:\nA_N\nB_1\nB_2\n:\nB_M\n\nOutput\n\nPrint Yes if the template image B is contained in the image A. Print No otherwise.\n\nSample Input 1\n\n3 2\n#.#\n.#.\n#.#\n#.\n.#\n\nSample Output 1\n\nYes\n\nThe template image B is identical to the upper-left 2 × 2 subimage and the lower-right 2 × 2 subimage of A. Thus, the output should be Yes.\n\nSample Input 2\n\n4 1\n....\n....\n....\n....\n#\n\nSample Output 2\n\nNo\n\nThe template image B, composed of a black pixel, is not contained in the image A composed of white pixels.", "sample_input": "3 2\n#.#\n.#.\n#.#\n#.\n.#\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03804", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.\n\nA pixel is the smallest element of an image, and in this problem it is a square of size 1×1.\n\nAlso, the given images are binary images, and the color of each pixel is either white or black.\n\nIn the input, every pixel is represented by a character: . corresponds to a white pixel, and # corresponds to a black pixel.\n\nThe image A is given as N strings A_1,...,A_N.\n\nThe j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1≦i,j≦N).\n\nSimilarly, the template image B is given as M strings B_1,...,B_M.\n\nThe j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1≦i,j≦M).\n\nDetermine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.\n\nConstraints\n\n1≦M≦N≦50\n\nA_i is a string of length N consisting of # and ..\n\nB_i is a string of length M consisting of # and ..\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN M\nA_1\nA_2\n:\nA_N\nB_1\nB_2\n:\nB_M\n\nOutput\n\nPrint Yes if the template image B is contained in the image A. Print No otherwise.\n\nSample Input 1\n\n3 2\n#.#\n.#.\n#.#\n#.\n.#\n\nSample Output 1\n\nYes\n\nThe template image B is identical to the upper-left 2 × 2 subimage and the lower-right 2 × 2 subimage of A. Thus, the output should be Yes.\n\nSample Input 2\n\n4 1\n....\n....\n....\n....\n#\n\nSample Output 2\n\nNo\n\nThe template image B, composed of a black pixel, is not contained in the image A composed of white pixels.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 486, "cpu_time_ms": 166, "memory_kb": 15844}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s462452468", "group_id": "codeNet:p03805", "input_text": "(defun dfs (graph v n visited)\n (let ((all-visited-p t))\n (dotimes (i n)\n (if (null (aref visited i))\n (setf all-visited-p nil)))\n (if all-visited-p\n 1\n (let ((res 0))\n (dotimes (i n)\n (if (and (aref graph v i)\n (null (aref visited i)))\n (setf (aref visited i) t\n res (+ res (dfs graph i n visited))\n (aref visited i) nil)))\n res))))\n\n(let* ((n (read))\n (m (read))\n (graph (make-array `(,n ,n) :initial-element nil))\n (visited (make-array n :initial-element nil)))\n (dotimes (i m)\n (let ((a (1- (read)))\n (b (1- (read))))\n (setf (aref graph a b) t\n (aref graph b a) t)))\n (setf (aref visited 0) t)\n (format t \"~A~%\" (dfs graph 0 n visited)))\n", "language": "Lisp", "metadata": {"date": 1525918417, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03805.html", "problem_id": "p03805", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03805/input.txt", "sample_output_relpath": "derived/input_output/data/p03805/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03805/Lisp/s462452468.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s462452468", "user_id": "u275710783"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun dfs (graph v n visited)\n (let ((all-visited-p t))\n (dotimes (i n)\n (if (null (aref visited i))\n (setf all-visited-p nil)))\n (if all-visited-p\n 1\n (let ((res 0))\n (dotimes (i n)\n (if (and (aref graph v i)\n (null (aref visited i)))\n (setf (aref visited i) t\n res (+ res (dfs graph i n visited))\n (aref visited i) nil)))\n res))))\n\n(let* ((n (read))\n (m (read))\n (graph (make-array `(,n ,n) :initial-element nil))\n (visited (make-array n :initial-element nil)))\n (dotimes (i m)\n (let ((a (1- (read)))\n (b (1- (read))))\n (setf (aref graph a b) t\n (aref graph b a) t)))\n (setf (aref visited 0) t)\n (format t \"~A~%\" (dfs graph 0 n visited)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges.\n\nHere, a self-loop is an edge where a_i = b_i (1≤i≤M), and double edges are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint32))\n (graph (make-array n :element-type 'list :initial-element nil))\n (dp (make-array n :element-type 'fixnum)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (labels ((dfs (v parent)\n (if (and (null (cdr (aref graph v)))\n (= parent (car (aref graph v))))\n (setf (aref dp v) (aref as v))\n (let ((sum 0)\n (max 0))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (let ((value (dfs child v)))\n (incf sum value)\n (maxf max value))))\n (let ((res (- (* (aref as v) 2) sum)))\n (dbg res sum max v dp)\n (unless (and (<= 0 res)\n (<= 0\n (- (aref as v) res)\n (if (>= max (- sum max))\n (- sum max)\n (ash sum -1))))\n (write-line \"NO\")\n (return-from main))\n (setf (aref dp v) res))))))\n (if (= n 2)\n (write-line (if (= (aref as 0) (aref as 1))\n \"YES\"\n \"NO\"))\n (dotimes (v n)\n (when (cdr (aref graph v))\n (dfs v -1)\n (write-line\n (if (zerop (aref dp v))\n \"YES\"\n \"NO\"))\n (return-from main)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n1 2 1 1 2\n2 4\n5 2\n3 2\n1 3\n\"\n \"YES\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2 1\n1 2\n2 3\n\"\n \"NO\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n3 2 2 2 2 2\n1 2\n2 3\n1 4\n1 5\n4 6\n\"\n \"YES\n\")))\n", "language": "Lisp", "metadata": {"date": 1585469237, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03809.html", "problem_id": "p03809", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03809/input.txt", "sample_output_relpath": "derived/input_output/data/p03809/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03809/Lisp/s249965642.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s249965642", "user_id": "u352600849"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint32))\n (graph (make-array n :element-type 'list :initial-element nil))\n (dp (make-array n :element-type 'fixnum)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (labels ((dfs (v parent)\n (if (and (null (cdr (aref graph v)))\n (= parent (car (aref graph v))))\n (setf (aref dp v) (aref as v))\n (let ((sum 0)\n (max 0))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (let ((value (dfs child v)))\n (incf sum value)\n (maxf max value))))\n (let ((res (- (* (aref as v) 2) sum)))\n (dbg res sum max v dp)\n (unless (and (<= 0 res)\n (<= 0\n (- (aref as v) res)\n (if (>= max (- sum max))\n (- sum max)\n (ash sum -1))))\n (write-line \"NO\")\n (return-from main))\n (setf (aref dp v) res))))))\n (if (= n 2)\n (write-line (if (= (aref as 0) (aref as 1))\n \"YES\"\n \"NO\"))\n (dotimes (v n)\n (when (cdr (aref graph v))\n (dfs v -1)\n (write-line\n (if (zerop (aref dp v))\n \"YES\"\n \"NO\"))\n (return-from main)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n1 2 1 1 2\n2 4\n5 2\n3 2\n1 3\n\"\n \"YES\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2 1\n1 2\n2 3\n\"\n \"NO\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n3 2 2 2 2 2\n1 2\n2 3\n1 4\n1 5\n4 6\n\"\n \"YES\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nThere is a tree with N vertices, numbered 1 through N.\nThe i-th of the N-1 edges connects vertices a_i and b_i.\n\nCurrently, there are A_i stones placed on vertex i.\nDetermine whether it is possible to remove all the stones from the vertices by repeatedly performing the following operation:\n\nSelect a pair of different leaves. Then, remove exactly one stone from every vertex on the path between those two vertices.\nHere, a leaf is a vertex of the tree whose degree is 1, and the selected leaves themselves are also considered as vertices on the path connecting them.\n\nNote that the operation cannot be performed if there is a vertex with no stone on the path.\n\nConstraints\n\n2 ≦ N ≦ 10^5\n\n1 ≦ a_i,b_i ≦ N\n\n0 ≦ A_i ≦ 10^9\n\nThe given graph is a tree.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nA_1 A_2 … A_N\na_1 b_1\n:\na_{N-1} b_{N-1}\n\nOutput\n\nIf it is possible to remove all the stones from the vertices, print YES. Otherwise, print NO.\n\nSample Input 1\n\n5\n1 2 1 1 2\n2 4\n5 2\n3 2\n1 3\n\nSample Output 1\n\nYES\n\nAll the stones can be removed, as follows:\n\nSelect vertices 4 and 5. Then, there is one stone remaining on each vertex except 4.\n\nSelect vertices 1 and 5. Then, there is no stone on any vertex.\n\nSample Input 2\n\n3\n1 2 1\n1 2\n2 3\n\nSample Output 2\n\nNO\n\nSample Input 3\n\n6\n3 2 2 2 2 2\n1 2\n2 3\n1 4\n1 5\n4 6\n\nSample Output 3\n\nYES", "sample_input": "5\n1 2 1 1 2\n2 4\n5 2\n3 2\n1 3\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03809", "source_text": "Score : 700 points\n\nProblem Statement\n\nThere is a tree with N vertices, numbered 1 through N.\nThe i-th of the N-1 edges connects vertices a_i and b_i.\n\nCurrently, there are A_i stones placed on vertex i.\nDetermine whether it is possible to remove all the stones from the vertices by repeatedly performing the following operation:\n\nSelect a pair of different leaves. Then, remove exactly one stone from every vertex on the path between those two vertices.\nHere, a leaf is a vertex of the tree whose degree is 1, and the selected leaves themselves are also considered as vertices on the path connecting them.\n\nNote that the operation cannot be performed if there is a vertex with no stone on the path.\n\nConstraints\n\n2 ≦ N ≦ 10^5\n\n1 ≦ a_i,b_i ≦ N\n\n0 ≦ A_i ≦ 10^9\n\nThe given graph is a tree.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nA_1 A_2 … A_N\na_1 b_1\n:\na_{N-1} b_{N-1}\n\nOutput\n\nIf it is possible to remove all the stones from the vertices, print YES. Otherwise, print NO.\n\nSample Input 1\n\n5\n1 2 1 1 2\n2 4\n5 2\n3 2\n1 3\n\nSample Output 1\n\nYES\n\nAll the stones can be removed, as follows:\n\nSelect vertices 4 and 5. Then, there is one stone remaining on each vertex except 4.\n\nSelect vertices 1 and 5. Then, there is no stone on any vertex.\n\nSample Input 2\n\n3\n1 2 1\n1 2\n2 3\n\nSample Output 2\n\nNO\n\nSample Input 3\n\n6\n3 2 2 2 2 2\n1 2\n2 3\n1 4\n1 5\n4 6\n\nSample Output 3\n\nYES", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7379, "cpu_time_ms": 159, "memory_kb": 42040}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s970352651", "group_id": "codeNet:p03809", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint32))\n (graph (make-array n :element-type 'list :initial-element nil))\n (dp (make-array n :element-type 'fixnum)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (labels ((dfs (v parent)\n (if (and (null (cdr (aref graph v)))\n (= parent (car (aref graph v))))\n (setf (aref dp v) (aref as v))\n (let ((sum 0)\n (max 0))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (let ((value (dfs child v)))\n (incf sum value)\n (maxf max value))))\n (let ((res (- (* (aref as v) 2) sum)))\n (dbg res sum max v dp)\n (unless (and (<= 0 res)\n (<= 0\n (- (aref as v) res)\n (if (>= max (- sum max))\n (- sum max)\n (ash sum -1))))\n (write-line \"NO\")\n (return-from main))\n (setf (aref dp v) res))))))\n (dotimes (v n)\n (when (cdr (aref graph v))\n (dfs v -1)\n (write-line\n (if (zerop (aref dp v))\n (error \"Huh?\")\n \"NO\"))\n (return-from main))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n1 2 1 1 2\n2 4\n5 2\n3 2\n1 3\n\"\n \"YES\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2 1\n1 2\n2 3\n\"\n \"NO\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n3 2 2 2 2 2\n1 2\n2 3\n1 4\n1 5\n4 6\n\"\n \"YES\n\")))\n", "language": "Lisp", "metadata": {"date": 1585468819, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03809.html", "problem_id": "p03809", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03809/input.txt", "sample_output_relpath": "derived/input_output/data/p03809/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03809/Lisp/s970352651.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s970352651", "user_id": "u352600849"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (as (make-array n :element-type 'uint32))\n (graph (make-array n :element-type 'list :initial-element nil))\n (dp (make-array n :element-type 'fixnum)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (labels ((dfs (v parent)\n (if (and (null (cdr (aref graph v)))\n (= parent (car (aref graph v))))\n (setf (aref dp v) (aref as v))\n (let ((sum 0)\n (max 0))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (let ((value (dfs child v)))\n (incf sum value)\n (maxf max value))))\n (let ((res (- (* (aref as v) 2) sum)))\n (dbg res sum max v dp)\n (unless (and (<= 0 res)\n (<= 0\n (- (aref as v) res)\n (if (>= max (- sum max))\n (- sum max)\n (ash sum -1))))\n (write-line \"NO\")\n (return-from main))\n (setf (aref dp v) res))))))\n (dotimes (v n)\n (when (cdr (aref graph v))\n (dfs v -1)\n (write-line\n (if (zerop (aref dp v))\n (error \"Huh?\")\n \"NO\"))\n (return-from main))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n1 2 1 1 2\n2 4\n5 2\n3 2\n1 3\n\"\n \"YES\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2 1\n1 2\n2 3\n\"\n \"NO\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n3 2 2 2 2 2\n1 2\n2 3\n1 4\n1 5\n4 6\n\"\n \"YES\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nThere is a tree with N vertices, numbered 1 through N.\nThe i-th of the N-1 edges connects vertices a_i and b_i.\n\nCurrently, there are A_i stones placed on vertex i.\nDetermine whether it is possible to remove all the stones from the vertices by repeatedly performing the following operation:\n\nSelect a pair of different leaves. Then, remove exactly one stone from every vertex on the path between those two vertices.\nHere, a leaf is a vertex of the tree whose degree is 1, and the selected leaves themselves are also considered as vertices on the path connecting them.\n\nNote that the operation cannot be performed if there is a vertex with no stone on the path.\n\nConstraints\n\n2 ≦ N ≦ 10^5\n\n1 ≦ a_i,b_i ≦ N\n\n0 ≦ A_i ≦ 10^9\n\nThe given graph is a tree.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nA_1 A_2 … A_N\na_1 b_1\n:\na_{N-1} b_{N-1}\n\nOutput\n\nIf it is possible to remove all the stones from the vertices, print YES. Otherwise, print NO.\n\nSample Input 1\n\n5\n1 2 1 1 2\n2 4\n5 2\n3 2\n1 3\n\nSample Output 1\n\nYES\n\nAll the stones can be removed, as follows:\n\nSelect vertices 4 and 5. Then, there is one stone remaining on each vertex except 4.\n\nSelect vertices 1 and 5. Then, there is no stone on any vertex.\n\nSample Input 2\n\n3\n1 2 1\n1 2\n2 3\n\nSample Output 2\n\nNO\n\nSample Input 3\n\n6\n3 2 2 2 2 2\n1 2\n2 3\n1 4\n1 5\n4 6\n\nSample Output 3\n\nYES", "sample_input": "5\n1 2 1 1 2\n2 4\n5 2\n3 2\n1 3\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03809", "source_text": "Score : 700 points\n\nProblem Statement\n\nThere is a tree with N vertices, numbered 1 through N.\nThe i-th of the N-1 edges connects vertices a_i and b_i.\n\nCurrently, there are A_i stones placed on vertex i.\nDetermine whether it is possible to remove all the stones from the vertices by repeatedly performing the following operation:\n\nSelect a pair of different leaves. Then, remove exactly one stone from every vertex on the path between those two vertices.\nHere, a leaf is a vertex of the tree whose degree is 1, and the selected leaves themselves are also considered as vertices on the path connecting them.\n\nNote that the operation cannot be performed if there is a vertex with no stone on the path.\n\nConstraints\n\n2 ≦ N ≦ 10^5\n\n1 ≦ a_i,b_i ≦ N\n\n0 ≦ A_i ≦ 10^9\n\nThe given graph is a tree.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nA_1 A_2 … A_N\na_1 b_1\n:\na_{N-1} b_{N-1}\n\nOutput\n\nIf it is possible to remove all the stones from the vertices, print YES. Otherwise, print NO.\n\nSample Input 1\n\n5\n1 2 1 1 2\n2 4\n5 2\n3 2\n1 3\n\nSample Output 1\n\nYES\n\nAll the stones can be removed, as follows:\n\nSelect vertices 4 and 5. Then, there is one stone remaining on each vertex except 4.\n\nSelect vertices 1 and 5. Then, there is no stone on any vertex.\n\nSample Input 2\n\n3\n1 2 1\n1 2\n2 3\n\nSample Output 2\n\nNO\n\nSample Input 3\n\n6\n3 2 2 2 2 2\n1 2\n2 3\n1 4\n1 5\n4 6\n\nSample Output 3\n\nYES", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7218, "cpu_time_ms": 492, "memory_kb": 56344}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s503746523", "group_id": "codeNet:p03813", "input_text": "(print (if (< (read) 1200) 'ABC 'ARC))", "language": "Lisp", "metadata": {"date": 1560319783, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03813.html", "problem_id": "p03813", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03813/input.txt", "sample_output_relpath": "derived/input_output/data/p03813/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03813/Lisp/s503746523.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s503746523", "user_id": "u820942903"}, "prompt_components": {"gold_output": "ABC\n", "input_to_evaluate": "(print (if (< (read) 1200) 'ABC 'ARC))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nSmeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise.\n\nYou are given Smeke's current rating, x. Print ABC if Smeke will participate in ABC, and print ARC otherwise.\n\nConstraints\n\n1 ≦ x ≦ 3{,}000\n\nx is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n1000\n\nSample Output 1\n\nABC\n\nSmeke's current rating is less than 1200, thus the output should be ABC.\n\nSample Input 2\n\n2000\n\nSample Output 2\n\nARC\n\nSmeke's current rating is not less than 1200, thus the output should be ARC.", "sample_input": "1000\n"}, "reference_outputs": ["ABC\n"], "source_document_id": "p03813", "source_text": "Score : 100 points\n\nProblem Statement\n\nSmeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise.\n\nYou are given Smeke's current rating, x. Print ABC if Smeke will participate in ABC, and print ARC otherwise.\n\nConstraints\n\n1 ≦ x ≦ 3{,}000\n\nx is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n1000\n\nSample Output 1\n\nABC\n\nSmeke's current rating is less than 1200, thus the output should be ABC.\n\nSample Input 2\n\n2000\n\nSample Output 2\n\nARC\n\nSmeke's current rating is not less than 1200, thus the output should be ARC.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 38, "cpu_time_ms": 5, "memory_kb": 2792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s545455282", "group_id": "codeNet:p03815", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((x (read)))\n (multiple-value-bind (quot rem) (floor x 11)\n (println\n (+ (* 2 quot)\n (cond ((zerop rem) 0)\n ((<= rem 6) 1)\n (t 2)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"149696127901\n\"\n \"27217477801\n\")))\n", "language": "Lisp", "metadata": {"date": 1578207438, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03815.html", "problem_id": "p03815", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03815/input.txt", "sample_output_relpath": "derived/input_output/data/p03815/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03815/Lisp/s545455282.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s545455282", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((x (read)))\n (multiple-value-bind (quot rem) (floor x 11)\n (println\n (+ (* 2 quot)\n (cond ((zerop rem) 0)\n ((<= rem 6) 1)\n (t 2)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"149696127901\n\"\n \"27217477801\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.\n\nSnuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:\n\nOperation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward.\n\nFor example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure.\nIf the die is rotated toward the right as shown in the figure, the side showing 3 will face upward.\nBesides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back.\n\nFind the minimum number of operation Snuke needs to perform in order to score at least x points in total.\n\nConstraints\n\n1 ≦ x ≦ 10^{15}\n\nx is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n7\n\nSample Output 1\n\n2\n\nSample Input 2\n\n149696127901\n\nSample Output 2\n\n27217477801", "sample_input": "7\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03815", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.\n\nSnuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:\n\nOperation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward.\n\nFor example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure.\nIf the die is rotated toward the right as shown in the figure, the side showing 3 will face upward.\nBesides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back.\n\nFind the minimum number of operation Snuke needs to perform in order to score at least x points in total.\n\nConstraints\n\n1 ≦ x ≦ 10^{15}\n\nx is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n7\n\nSample Output 1\n\n2\n\nSample Input 2\n\n149696127901\n\nSample Output 2\n\n27217477801", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3878, "cpu_time_ms": 150, "memory_kb": 16100}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s818769656", "group_id": "codeNet:p03815", "input_text": "(format t \"~A~%\" (multiple-value-bind (a b)\n (truncate (read) 11)\n (+ (* a 2) (ceiling b 6))))", "language": "Lisp", "metadata": {"date": 1504727374, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03815.html", "problem_id": "p03815", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03815/input.txt", "sample_output_relpath": "derived/input_output/data/p03815/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03815/Lisp/s818769656.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s818769656", "user_id": "u140665374"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(format t \"~A~%\" (multiple-value-bind (a b)\n (truncate (read) 11)\n (+ (* a 2) (ceiling b 6))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.\n\nSnuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:\n\nOperation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward.\n\nFor example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure.\nIf the die is rotated toward the right as shown in the figure, the side showing 3 will face upward.\nBesides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back.\n\nFind the minimum number of operation Snuke needs to perform in order to score at least x points in total.\n\nConstraints\n\n1 ≦ x ≦ 10^{15}\n\nx is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n7\n\nSample Output 1\n\n2\n\nSample Input 2\n\n149696127901\n\nSample Output 2\n\n27217477801", "sample_input": "7\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03815", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.\n\nSnuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:\n\nOperation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward.\n\nFor example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure.\nIf the die is rotated toward the right as shown in the figure, the side showing 3 will face upward.\nBesides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back.\n\nFind the minimum number of operation Snuke needs to perform in order to score at least x points in total.\n\nConstraints\n\n1 ≦ x ≦ 10^{15}\n\nx is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n7\n\nSample Output 1\n\n2\n\nSample Input 2\n\n149696127901\n\nSample Output 2\n\n27217477801", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 130, "cpu_time_ms": 121, "memory_kb": 12004}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s140316704", "group_id": "codeNet:p03815", "input_text": "(format t \"~A~%\" (let ((n (read)))\n (if (or (< 6 (mod n 11))\n (= 0 (mod n 11)))\n (* (ceiling (/ n 11)) 2)\n (1- (* (ceiling (/ n 11)) 2)))))", "language": "Lisp", "metadata": {"date": 1504726403, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03815.html", "problem_id": "p03815", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03815/input.txt", "sample_output_relpath": "derived/input_output/data/p03815/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03815/Lisp/s140316704.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s140316704", "user_id": "u140665374"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(format t \"~A~%\" (let ((n (read)))\n (if (or (< 6 (mod n 11))\n (= 0 (mod n 11)))\n (* (ceiling (/ n 11)) 2)\n (1- (* (ceiling (/ n 11)) 2)))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.\n\nSnuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:\n\nOperation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward.\n\nFor example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure.\nIf the die is rotated toward the right as shown in the figure, the side showing 3 will face upward.\nBesides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back.\n\nFind the minimum number of operation Snuke needs to perform in order to score at least x points in total.\n\nConstraints\n\n1 ≦ x ≦ 10^{15}\n\nx is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n7\n\nSample Output 1\n\n2\n\nSample Input 2\n\n149696127901\n\nSample Output 2\n\n27217477801", "sample_input": "7\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03815", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.\n\nSnuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:\n\nOperation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward.\n\nFor example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure.\nIf the die is rotated toward the right as shown in the figure, the side showing 3 will face upward.\nBesides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back.\n\nFind the minimum number of operation Snuke needs to perform in order to score at least x points in total.\n\nConstraints\n\n1 ≦ x ≦ 10^{15}\n\nx is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n7\n\nSample Output 1\n\n2\n\nSample Input 2\n\n149696127901\n\nSample Output 2\n\n27217477801", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 227, "cpu_time_ms": 19, "memory_kb": 6504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s958358758", "group_id": "codeNet:p03817", "input_text": "(let ((x (read))\n (ans 0))\n (setq ans (* (floor (/ x 11)) 2))\n (setq x (rem x 11))\n (if (>= x 7)\n (incf ans 2)\n (if (not (= x 0))\n (incf ans)\n )\n )\n (princ ans)\n)", "language": "Lisp", "metadata": {"date": 1595897471, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03817.html", "problem_id": "p03817", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03817/input.txt", "sample_output_relpath": "derived/input_output/data/p03817/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03817/Lisp/s958358758.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s958358758", "user_id": "u136500538"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((x (read))\n (ans 0))\n (setq ans (* (floor (/ x 11)) 2))\n (setq x (rem x 11))\n (if (>= x 7)\n (incf ans 2)\n (if (not (= x 0))\n (incf ans)\n )\n )\n (princ ans)\n)", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.\n\nSnuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:\n\nOperation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward.\n\nFor example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure.\nIf the die is rotated toward the right as shown in the figure, the side showing 3 will face upward.\nBesides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back.\n\nFind the minimum number of operation Snuke needs to perform in order to score at least x points in total.\n\nConstraints\n\n1 ≦ x ≦ 10^{15}\n\nx is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n7\n\nSample Output 1\n\n2\n\nSample Input 2\n\n149696127901\n\nSample Output 2\n\n27217477801", "sample_input": "7\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03817", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.\n\nSnuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:\n\nOperation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward.\n\nFor example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure.\nIf the die is rotated toward the right as shown in the figure, the side showing 3 will face upward.\nBesides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back.\n\nFind the minimum number of operation Snuke needs to perform in order to score at least x points in total.\n\nConstraints\n\n1 ≦ x ≦ 10^{15}\n\nx is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n7\n\nSample Output 1\n\n2\n\nSample Input 2\n\n149696127901\n\nSample Output 2\n\n27217477801", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 212, "cpu_time_ms": 18, "memory_kb": 24412}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s941904895", "group_id": "codeNet:p03817", "input_text": "(let ((n (read)))\n (format t \"~A~%\" (+ (* 2 (floor (/ n 11))) (cond ((= (mod n 11) 0) 0)\n ((< 6 (mod n 11)) 2)\n (t 1)))))\n", "language": "Lisp", "metadata": {"date": 1527698817, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03817.html", "problem_id": "p03817", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03817/input.txt", "sample_output_relpath": "derived/input_output/data/p03817/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03817/Lisp/s941904895.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s941904895", "user_id": "u994767958"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((n (read)))\n (format t \"~A~%\" (+ (* 2 (floor (/ n 11))) (cond ((= (mod n 11) 0) 0)\n ((< 6 (mod n 11)) 2)\n (t 1)))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.\n\nSnuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:\n\nOperation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward.\n\nFor example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure.\nIf the die is rotated toward the right as shown in the figure, the side showing 3 will face upward.\nBesides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back.\n\nFind the minimum number of operation Snuke needs to perform in order to score at least x points in total.\n\nConstraints\n\n1 ≦ x ≦ 10^{15}\n\nx is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n7\n\nSample Output 1\n\n2\n\nSample Input 2\n\n149696127901\n\nSample Output 2\n\n27217477801", "sample_input": "7\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03817", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.\n\nSnuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:\n\nOperation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward.\n\nFor example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure.\nIf the die is rotated toward the right as shown in the figure, the side showing 3 will face upward.\nBesides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back.\n\nFind the minimum number of operation Snuke needs to perform in order to score at least x points in total.\n\nConstraints\n\n1 ≦ x ≦ 10^{15}\n\nx is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n7\n\nSample Output 1\n\n2\n\nSample Input 2\n\n149696127901\n\nSample Output 2\n\n27217477801", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 223, "cpu_time_ms": 55, "memory_kb": 8932}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s297076272", "group_id": "codeNet:p03817", "input_text": "(let ((n (read)))\n (format t \"~A~%\" (+ (* 2 (floor (/ n 11))) (cond ((= (mod n 11) 0) 0)\n ((< 5 (mod n 11)) 2)\n (t 1)))))\n", "language": "Lisp", "metadata": {"date": 1527698377, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03817.html", "problem_id": "p03817", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03817/input.txt", "sample_output_relpath": "derived/input_output/data/p03817/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03817/Lisp/s297076272.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s297076272", "user_id": "u994767958"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((n (read)))\n (format t \"~A~%\" (+ (* 2 (floor (/ n 11))) (cond ((= (mod n 11) 0) 0)\n ((< 5 (mod n 11)) 2)\n (t 1)))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.\n\nSnuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:\n\nOperation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward.\n\nFor example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure.\nIf the die is rotated toward the right as shown in the figure, the side showing 3 will face upward.\nBesides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back.\n\nFind the minimum number of operation Snuke needs to perform in order to score at least x points in total.\n\nConstraints\n\n1 ≦ x ≦ 10^{15}\n\nx is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n7\n\nSample Output 1\n\n2\n\nSample Input 2\n\n149696127901\n\nSample Output 2\n\n27217477801", "sample_input": "7\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03817", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.\n\nSnuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:\n\nOperation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward.\n\nFor example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure.\nIf the die is rotated toward the right as shown in the figure, the side showing 3 will face upward.\nBesides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back.\n\nFind the minimum number of operation Snuke needs to perform in order to score at least x points in total.\n\nConstraints\n\n1 ≦ x ≦ 10^{15}\n\nx is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n7\n\nSample Output 1\n\n2\n\nSample Input 2\n\n149696127901\n\nSample Output 2\n\n27217477801", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 223, "cpu_time_ms": 172, "memory_kb": 15976}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s451685192", "group_id": "codeNet:p03822", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"64MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n;; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;; ;\n;;; Memoization macro\n;;; \n\n;; TODO: detailed documentation\n\n;; Usage example:\n;; (with-cache (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-cache (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c d) ...)) ; => C is ignored.\n;; (with-cache (:array (10 10) :initial-element -1 :element-type 'fixnum :debug t)\n;; (defun foo (x y) ...)) ; executes with trace of foo\n\n;; FIXME: *RECURSION-DEPTH* should be included within the macro.\n(declaim (type (integer 0 #.most-positive-fixnum) *recursion-depth*))\n(defparameter *recursion-depth* 0)\n\n(defmacro with-cache (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (debug (prog1 (getf rest-attribs :debug) (remf rest-attribs :debug)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array (list ,@dimensions) ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((debug (name args obj)\n (let ((value (gensym)))\n (if debug\n `(progn\n (format t \"~A~A: (~A ~{~A~^ ~}) =>~%\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',name\n (list ,@args))\n (let ((,value (let ((*recursion-depth* (1+ *recursion-depth*)))\n ,obj)))\n (format t \"~A~A: (~A ~{~A~^ ~}) => ~A~%\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',name\n (list ,@args)\n ,value)\n ,value))\n obj)))\n (make-cache-check-form (cache-type name args)\n (debug name\n args\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dimensions-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value))))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name))))\n (extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car form))) body)))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n ,@(extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(make-cache-check-form cache-type name args))))))\n ((nlet sb-int:named-let)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (,(car def-form) ,name ,bindings\n ,@(extract-declarations body)\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(make-cache-check-form cache-type name args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n ,@(extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(make-cache-check-form cache-type name args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (graph (make-array n :element-type 'list :initial-element nil)))\n (loop for i from 1 below n\n do (let ((a (- (read-fixnum) 1)))\n (push i (aref graph a))))\n (println\n (with-cache (:array (n) :element-type 'uint32 :initial-element #xffffffff)\n (sb-int:named-let recur ((v 0))\n (setf (aref graph v)\n (sort (aref graph v) #'> :key #'recur))\n (loop for i of-type uint32 from 0\n for child in (aref graph v)\n maximize (+ i 1 (recur child))))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1563083065, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03822.html", "problem_id": "p03822", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03822/input.txt", "sample_output_relpath": "derived/input_output/data/p03822/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03822/Lisp/s451685192.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s451685192", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"64MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n;; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;; ;\n;;; Memoization macro\n;;; \n\n;; TODO: detailed documentation\n\n;; Usage example:\n;; (with-cache (:hash-table :test #'equal :key #'cons)\n;; (defun ...))\n;; (with-cache (:array (10 10 * 10) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c d) ...)) ; => C is ignored.\n;; (with-cache (:array (10 10) :initial-element -1 :element-type 'fixnum :debug t)\n;; (defun foo (x y) ...)) ; executes with trace of foo\n\n;; FIXME: *RECURSION-DEPTH* should be included within the macro.\n(declaim (type (integer 0 #.most-positive-fixnum) *recursion-depth*))\n(defparameter *recursion-depth* 0)\n\n(defmacro with-cache (cache-attribs def-form)\n (let* ((cache-attribs (if (atom cache-attribs) (list cache-attribs) cache-attribs))\n (cache-type (first cache-attribs))\n (dimensions-with-* (when (eql cache-type :array) (second cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\n (rest-attribs (ecase cache-type\n (:hash-table (cdr cache-attribs))\n (:array (cddr cache-attribs))))\n (key (prog1 (getf rest-attribs :key) (remf rest-attribs :key)))\n (debug (prog1 (getf rest-attribs :debug) (remf rest-attribs :debug)))\n (cache-form (case cache-type\n (:hash-table `(make-hash-table ,@rest-attribs))\n (:array `(make-array (list ,@dimensions) ,@rest-attribs))))\n (initial-element (when (eql cache-type :array)\n (assert (member :initial-element rest-attribs))\n (getf rest-attribs :initial-element))))\n (let ((cache (gensym))\n (value (gensym))\n\t (present-p (gensym))\n (name-alias (gensym))\n\t (args-lst (gensym))\n (indices (loop repeat rank collect (gensym))))\n (labels ((debug (name args obj)\n (let ((value (gensym)))\n (if debug\n `(progn\n (format t \"~A~A: (~A ~{~A~^ ~}) =>~%\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',name\n (list ,@args))\n (let ((,value (let ((*recursion-depth* (1+ *recursion-depth*)))\n ,obj)))\n (format t \"~A~A: (~A ~{~A~^ ~}) => ~A~%\"\n (make-string *recursion-depth*\n :element-type 'base-char\n :initial-element #\\ )\n *recursion-depth*\n ',name\n (list ,@args)\n ,value)\n ,value))\n obj)))\n (make-cache-check-form (cache-type name args)\n (debug name\n args\n (case cache-type\n (:hash-table\n `(let ((,args-lst (funcall ,(or key #'list) ,@args)))\n (multiple-value-bind (,value ,present-p)\n (gethash ,args-lst ,cache)\n (if ,present-p\n ,value\n (setf (gethash ,args-lst ,cache)\n (,name-alias ,@args))))))\n (:array\n (let ((memoized-args (loop for dimension in dimensions-with-*\n for arg in args\n unless (eql dimension '*)\n collect arg)))\n (if key\n `(multiple-value-bind ,indices\n (funcall ,key ,@memoized-args)\n (let ((,value (aref ,cache ,@indices)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@indices)\n (,name-alias ,@args))\n ,value)))\n `(let ((,value (aref ,cache ,@memoized-args)))\n (if (eql ,initial-element ,value)\n (setf (aref ,cache ,@memoized-args)\n (,name-alias ,@args))\n ,value))))))))\n (make-reset-form (cache-type)\n (case cache-type\n (:hash-table `(setf ,cache (make-hash-table ,@rest-attribs)))\n (:array `(prog1 nil\n (fill (array-storage-vector ,cache) ,initial-element)))))\n (make-reset-name (name)\n (intern (format nil \"RESET-~A\" (symbol-name name))))\n (extract-declarations (body)\n (remove-if-not (lambda (form) (eql 'declare (car form))) body)))\n (ecase (car def-form)\n ((defun)\n (destructuring-bind (_ name args &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (defun ,(make-reset-name name) () ,(make-reset-form cache-type))\n (defun ,name ,args\n ,@(extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(make-cache-check-form cache-type name args))))))\n ((nlet sb-int:named-let)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (,(car def-form) ,name ,bindings\n ,@(extract-declarations body)\n ,(let ((args (mapcar (lambda (x) (if (atom x) x (car x))) bindings)))\n `(labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(make-cache-check-form cache-type name args)))))))\n ((labels flet)\n (destructuring-bind (_ definitions &body labels-body) def-form\n (declare (ignore _))\n (destructuring-bind (name args &body body) (car definitions)\n `(let ((,cache ,cache-form))\n (,(car def-form)\n ((,(make-reset-name name) () ,(make-reset-form cache-type))\n (,name ,args\n ,@(extract-declarations body)\n (labels ((,name-alias ,args ,@body))\n (declare (inline ,name-alias))\n ,(make-cache-check-form cache-type name args)))\n ,@(cdr definitions))\n (declare (ignorable #',(make-reset-name name)))\n ,@labels-body))))))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (graph (make-array n :element-type 'list :initial-element nil)))\n (loop for i from 1 below n\n do (let ((a (- (read-fixnum) 1)))\n (push i (aref graph a))))\n (println\n (with-cache (:array (n) :element-type 'uint32 :initial-element #xffffffff)\n (sb-int:named-let recur ((v 0))\n (setf (aref graph v)\n (sort (aref graph v) #'> :key #'recur))\n (loop for i of-type uint32 from 0\n for child in (aref graph v)\n maximize (+ i 1 (recur child))))))))\n\n#-swank (main)\n", "problem_context": "Score : 800 points\n\nProblem Statement\n\nN contestants participated in a competition. The total of N-1 matches were played in a knockout tournament.\nFor some reasons, the tournament may not be \"fair\" for all the contestants.\nThat is, the number of the matches that must be played in order to win the championship may be different for each contestant. The structure of the tournament is formally described at the end of this statement.\n\nAfter each match, there were always one winner and one loser. The last contestant standing was declared the champion.\n\nFigure: an example of a tournament\n\nFor convenience, the contestants were numbered 1 through N. The contestant numbered 1 was the champion, and the contestant numbered i(2 ≦ i ≦ N) was defeated in a match against the contestant numbered a_i.\n\nWe will define the depth of the tournament as the maximum number of the matches that must be played in order to win the championship over all the contestants.\n\nFind the minimum possible depth of the tournament.\n\nThe formal description of the structure of the tournament is as follows. In the i-th match, one of the following played against each other:\n\nTwo predetermined contestants\n\nOne predetermined contestant and the winner of the j-th match, where j(j (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((x (read))\n (y (read)))\n (println\n (cond ((<= 0 x y)\n (- y x))\n ((<= 0 y x)\n (+ x y 1))\n ((<= x y 0)\n (- y x))\n ((<= y x 0)\n (min (+ 1 (abs x) (abs y))\n (+ 2 (- (abs y) (abs x)))))\n ((and (<= x 0 y)\n (<= (abs x) (abs y)))\n (+ 1 (- (abs y) (abs x))))\n ((and (<= x 0 y)\n (<= (abs y) (abs x)))\n (+ 1 (- (abs x) (abs y))))\n ((and (<= y 0 x)\n (<= (abs x) (abs y)))\n (+ 1 (- (abs y) (abs x))))\n ((and (<= y 0 x)\n (<= (abs y) (abs x)))\n (+ 1 (- (abs x) (abs y))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 20\n\"\n \"10\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 -10\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"-10 -20\n\"\n \"12\n\")))\n", "language": "Lisp", "metadata": {"date": 1578127835, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03838.html", "problem_id": "p03838", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03838/input.txt", "sample_output_relpath": "derived/input_output/data/p03838/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03838/Lisp/s158146540.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s158146540", "user_id": "u352600849"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((x (read))\n (y (read)))\n (println\n (cond ((<= 0 x y)\n (- y x))\n ((<= 0 y x)\n (+ x y 1))\n ((<= x y 0)\n (- y x))\n ((<= y x 0)\n (min (+ 1 (abs x) (abs y))\n (+ 2 (- (abs y) (abs x)))))\n ((and (<= x 0 y)\n (<= (abs x) (abs y)))\n (+ 1 (- (abs y) (abs x))))\n ((and (<= x 0 y)\n (<= (abs y) (abs x)))\n (+ 1 (- (abs x) (abs y))))\n ((and (<= y 0 x)\n (<= (abs x) (abs y)))\n (+ 1 (- (abs y) (abs x))))\n ((and (<= y 0 x)\n (<= (abs y) (abs x)))\n (+ 1 (- (abs x) (abs y))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n ;; (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 20\n\"\n \"10\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 -10\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"-10 -20\n\"\n \"12\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke has a calculator. It has a display and two buttons.\n\nInitially, the display shows an integer x.\nSnuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:\n\nButton A: When pressed, the value on the display is incremented by 1.\n\nButton B: When pressed, the sign of the value on the display is reversed.\n\nFind the minimum number of times Snuke needs to press the buttons to achieve his objective.\nIt can be shown that the objective is always achievable regardless of the values of the integers x and y.\n\nConstraints\n\nx and y are integers.\n\n|x|, |y| ≤ 10^9\n\nx and y are different.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx y\n\nOutput\n\nPrint the minimum number of times Snuke needs to press the buttons to achieve his objective.\n\nSample Input 1\n\n10 20\n\nSample Output 1\n\n10\n\nPress button A ten times.\n\nSample Input 2\n\n10 -10\n\nSample Output 2\n\n1\n\nPress button B once.\n\nSample Input 3\n\n-10 -20\n\nSample Output 3\n\n12\n\nPress the buttons as follows:\n\nPress button B once.\n\nPress button A ten times.\n\nPress button B once.", "sample_input": "10 20\n"}, "reference_outputs": ["10\n"], "source_document_id": "p03838", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke has a calculator. It has a display and two buttons.\n\nInitially, the display shows an integer x.\nSnuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:\n\nButton A: When pressed, the value on the display is incremented by 1.\n\nButton B: When pressed, the sign of the value on the display is reversed.\n\nFind the minimum number of times Snuke needs to press the buttons to achieve his objective.\nIt can be shown that the objective is always achievable regardless of the values of the integers x and y.\n\nConstraints\n\nx and y are integers.\n\n|x|, |y| ≤ 10^9\n\nx and y are different.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx y\n\nOutput\n\nPrint the minimum number of times Snuke needs to press the buttons to achieve his objective.\n\nSample Input 1\n\n10 20\n\nSample Output 1\n\n10\n\nPress button A ten times.\n\nSample Input 2\n\n10 -10\n\nSample Output 2\n\n1\n\nPress button B once.\n\nSample Input 3\n\n-10 -20\n\nSample Output 3\n\n12\n\nPress the buttons as follows:\n\nPress button B once.\n\nPress button A ten times.\n\nPress button B once.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4468, "cpu_time_ms": 171, "memory_kb": 19684}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s317389463", "group_id": "codeNet:p03838", "input_text": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n(let ((x (read))\n (y (read)))\n (format t \"~A~%\" (+ (abs (- (abs y) (abs x)))\n (if (< y x)\n (if (> (* x y) 0) 2 1)\n (if (and (< x 0) (> y 0)) 1 0)))))", "language": "Lisp", "metadata": {"date": 1521684349, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03838.html", "problem_id": "p03838", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03838/input.txt", "sample_output_relpath": "derived/input_output/data/p03838/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03838/Lisp/s317389463.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s317389463", "user_id": "u672956630"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n(let ((x (read))\n (y (read)))\n (format t \"~A~%\" (+ (abs (- (abs y) (abs x)))\n (if (< y x)\n (if (> (* x y) 0) 2 1)\n (if (and (< x 0) (> y 0)) 1 0)))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke has a calculator. It has a display and two buttons.\n\nInitially, the display shows an integer x.\nSnuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:\n\nButton A: When pressed, the value on the display is incremented by 1.\n\nButton B: When pressed, the sign of the value on the display is reversed.\n\nFind the minimum number of times Snuke needs to press the buttons to achieve his objective.\nIt can be shown that the objective is always achievable regardless of the values of the integers x and y.\n\nConstraints\n\nx and y are integers.\n\n|x|, |y| ≤ 10^9\n\nx and y are different.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx y\n\nOutput\n\nPrint the minimum number of times Snuke needs to press the buttons to achieve his objective.\n\nSample Input 1\n\n10 20\n\nSample Output 1\n\n10\n\nPress button A ten times.\n\nSample Input 2\n\n10 -10\n\nSample Output 2\n\n1\n\nPress button B once.\n\nSample Input 3\n\n-10 -20\n\nSample Output 3\n\n12\n\nPress the buttons as follows:\n\nPress button B once.\n\nPress button A ten times.\n\nPress button B once.", "sample_input": "10 20\n"}, "reference_outputs": ["10\n"], "source_document_id": "p03838", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke has a calculator. It has a display and two buttons.\n\nInitially, the display shows an integer x.\nSnuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:\n\nButton A: When pressed, the value on the display is incremented by 1.\n\nButton B: When pressed, the sign of the value on the display is reversed.\n\nFind the minimum number of times Snuke needs to press the buttons to achieve his objective.\nIt can be shown that the objective is always achievable regardless of the values of the integers x and y.\n\nConstraints\n\nx and y are integers.\n\n|x|, |y| ≤ 10^9\n\nx and y are different.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx y\n\nOutput\n\nPrint the minimum number of times Snuke needs to press the buttons to achieve his objective.\n\nSample Input 1\n\n10 20\n\nSample Output 1\n\n10\n\nPress button A ten times.\n\nSample Input 2\n\n10 -10\n\nSample Output 2\n\n1\n\nPress button B once.\n\nSample Input 3\n\n-10 -20\n\nSample Output 3\n\n12\n\nPress the buttons as follows:\n\nPress button B once.\n\nPress button A ten times.\n\nPress button B once.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 274, "cpu_time_ms": 120, "memory_kb": 12136}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s759578315", "group_id": "codeNet:p03840", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((ai (read))\n (ao (read))\n (at (read))\n (aj (read))\n (al (read))\n (as (read))\n (az (read)))\n (println (max (+ ao\n (* 2 (ash ai -1))\n (* 2 (ash aj -1))\n (* 2 (ash al -1)))\n (if (and (> ai 0) (> aj 0) (> al 0))\n 0\n (+ ao\n (* 2 (ash (- ai 1) -1))\n (* 2 (ash (- aj 1) -1))\n (* 2 (ash (- al 1) -1))\n 3))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 1 1 0 0 0 0\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"0 0 10 0 0 0 0\n\"\n \"0\n\")))\n", "language": "Lisp", "metadata": {"date": 1585313702, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03840.html", "problem_id": "p03840", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03840/input.txt", "sample_output_relpath": "derived/input_output/data/p03840/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03840/Lisp/s759578315.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s759578315", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((ai (read))\n (ao (read))\n (at (read))\n (aj (read))\n (al (read))\n (as (read))\n (az (read)))\n (println (max (+ ao\n (* 2 (ash ai -1))\n (* 2 (ash aj -1))\n (* 2 (ash al -1)))\n (if (and (> ai 0) (> aj 0) (> al 0))\n 0\n (+ ao\n (* 2 (ash (- ai 1) -1))\n (* 2 (ash (- aj 1) -1))\n (* 2 (ash (- al 1) -1))\n 3))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 1 1 0 0 0 0\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"0 0 10 0 0 0 0\n\"\n \"0\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nA tetromino is a figure formed by joining four squares edge to edge.\nWe will refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and Z-tetrominos, respectively:\n\nSnuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and Z-tetrominos in his possession are a_I, a_O, a_T, a_J, a_L, a_S and a_Z, respectively.\nSnuke will join K of his tetrominos to form a rectangle that is two squares tall and 2K squares wide.\nHere, the following rules must be followed:\n\nWhen placing each tetromino, rotation is allowed, but reflection is not.\n\nEach square in the rectangle must be covered by exactly one tetromino.\n\nNo part of each tetromino may be outside the rectangle.\n\nSnuke wants to form as large a rectangle as possible.\nFind the maximum possible value of K.\n\nConstraints\n\n0≤a_I,a_O,a_T,a_J,a_L,a_S,a_Z≤10^9\n\na_I+a_O+a_T+a_J+a_L+a_S+a_Z≥1\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na_I a_O a_T a_J a_L a_S a_Z\n\nOutput\n\nPrint the maximum possible value of K. If no rectangle can be formed, print 0.\n\nSample Input 1\n\n2 1 1 0 0 0 0\n\nSample Output 1\n\n3\n\nOne possible way to form the largest rectangle is shown in the following figure:\n\nSample Input 2\n\n0 0 10 0 0 0 0\n\nSample Output 2\n\n0\n\nNo rectangle can be formed.", "sample_input": "2 1 1 0 0 0 0\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03840", "source_text": "Score : 600 points\n\nProblem Statement\n\nA tetromino is a figure formed by joining four squares edge to edge.\nWe will refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and Z-tetrominos, respectively:\n\nSnuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and Z-tetrominos in his possession are a_I, a_O, a_T, a_J, a_L, a_S and a_Z, respectively.\nSnuke will join K of his tetrominos to form a rectangle that is two squares tall and 2K squares wide.\nHere, the following rules must be followed:\n\nWhen placing each tetromino, rotation is allowed, but reflection is not.\n\nEach square in the rectangle must be covered by exactly one tetromino.\n\nNo part of each tetromino may be outside the rectangle.\n\nSnuke wants to form as large a rectangle as possible.\nFind the maximum possible value of K.\n\nConstraints\n\n0≤a_I,a_O,a_T,a_J,a_L,a_S,a_Z≤10^9\n\na_I+a_O+a_T+a_J+a_L+a_S+a_Z≥1\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na_I a_O a_T a_J a_L a_S a_Z\n\nOutput\n\nPrint the maximum possible value of K. If no rectangle can be formed, print 0.\n\nSample Input 1\n\n2 1 1 0 0 0 0\n\nSample Output 1\n\n3\n\nOne possible way to form the largest rectangle is shown in the following figure:\n\nSample Input 2\n\n0 0 10 0 0 0 0\n\nSample Output 2\n\n0\n\nNo rectangle can be formed.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4125, "cpu_time_ms": 201, "memory_kb": 20072}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s540197099", "group_id": "codeNet:p03840", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-condition fin () ())\n\n(defun main ()\n (let* ((ai (read))\n (ao (read))\n (at (read))\n (aj (read))\n (al (read))\n (as (read))\n (az (read))\n (res 0))\n (declare (ignore at as az))\n (incf res (* ao 2))\n (when (or (zerop ai) (zerop aj) (zerop al))\n (incf res (* 2 aj))\n (incf res (* 2 al))\n (incf res (* 2 ai))\n (println (floor res 2))\n (return-from main))\n (if (oddp ai)\n (progn (incf res (* 2 (- ai 1)))\n (setf ai 1))\n (progn (incf res (* 2 (- ai 2)))\n (setf ai 2)))\n (if (oddp aj)\n (progn (incf res (* 2 (- aj 1)))\n (setf aj 1))\n (progn (incf res (* 2 (- aj 2)))\n (setf aj 2)))\n (if (oddp al)\n (progn (incf res (* 2 (- al 1)))\n (setf al 1))\n (progn (incf res (* 2 (- al 2)))\n (setf al 2)))\n (cond ((and (= ai 2) (= aj 2) (= al 2))\n (incf res 12))\n ((and (= ai 2) (= aj 2) (= al 1))\n (incf res 8))\n ((and (= ai 2) (= aj 1) (= al 2))\n (incf res 8))\n ((and (= ai 2) (= aj 1) (= al 1))\n (incf res 6))\n ((and (= ai 1) (= aj 2) (= al 2))\n (incf res 8))\n ((and (= ai 1) (= aj 2) (= al 1))\n (incf res 6))\n ((and (= ai 1) (= aj 1) (= al 2))\n (incf res 6))\n ((and (= ai 1) (= aj 1) (= al 1))\n (incf res 6)))\n (println (floor res 2))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 1 1 0 0 0 0\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"0 0 10 0 0 0 0\n\"\n \"0\n\")))\n", "language": "Lisp", "metadata": {"date": 1570063940, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03840.html", "problem_id": "p03840", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03840/input.txt", "sample_output_relpath": "derived/input_output/data/p03840/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03840/Lisp/s540197099.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s540197099", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-condition fin () ())\n\n(defun main ()\n (let* ((ai (read))\n (ao (read))\n (at (read))\n (aj (read))\n (al (read))\n (as (read))\n (az (read))\n (res 0))\n (declare (ignore at as az))\n (incf res (* ao 2))\n (when (or (zerop ai) (zerop aj) (zerop al))\n (incf res (* 2 aj))\n (incf res (* 2 al))\n (incf res (* 2 ai))\n (println (floor res 2))\n (return-from main))\n (if (oddp ai)\n (progn (incf res (* 2 (- ai 1)))\n (setf ai 1))\n (progn (incf res (* 2 (- ai 2)))\n (setf ai 2)))\n (if (oddp aj)\n (progn (incf res (* 2 (- aj 1)))\n (setf aj 1))\n (progn (incf res (* 2 (- aj 2)))\n (setf aj 2)))\n (if (oddp al)\n (progn (incf res (* 2 (- al 1)))\n (setf al 1))\n (progn (incf res (* 2 (- al 2)))\n (setf al 2)))\n (cond ((and (= ai 2) (= aj 2) (= al 2))\n (incf res 12))\n ((and (= ai 2) (= aj 2) (= al 1))\n (incf res 8))\n ((and (= ai 2) (= aj 1) (= al 2))\n (incf res 8))\n ((and (= ai 2) (= aj 1) (= al 1))\n (incf res 6))\n ((and (= ai 1) (= aj 2) (= al 2))\n (incf res 8))\n ((and (= ai 1) (= aj 2) (= al 1))\n (incf res 6))\n ((and (= ai 1) (= aj 1) (= al 2))\n (incf res 6))\n ((and (= ai 1) (= aj 1) (= al 1))\n (incf res 6)))\n (println (floor res 2))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 1 1 0 0 0 0\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"0 0 10 0 0 0 0\n\"\n \"0\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nA tetromino is a figure formed by joining four squares edge to edge.\nWe will refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and Z-tetrominos, respectively:\n\nSnuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and Z-tetrominos in his possession are a_I, a_O, a_T, a_J, a_L, a_S and a_Z, respectively.\nSnuke will join K of his tetrominos to form a rectangle that is two squares tall and 2K squares wide.\nHere, the following rules must be followed:\n\nWhen placing each tetromino, rotation is allowed, but reflection is not.\n\nEach square in the rectangle must be covered by exactly one tetromino.\n\nNo part of each tetromino may be outside the rectangle.\n\nSnuke wants to form as large a rectangle as possible.\nFind the maximum possible value of K.\n\nConstraints\n\n0≤a_I,a_O,a_T,a_J,a_L,a_S,a_Z≤10^9\n\na_I+a_O+a_T+a_J+a_L+a_S+a_Z≥1\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na_I a_O a_T a_J a_L a_S a_Z\n\nOutput\n\nPrint the maximum possible value of K. If no rectangle can be formed, print 0.\n\nSample Input 1\n\n2 1 1 0 0 0 0\n\nSample Output 1\n\n3\n\nOne possible way to form the largest rectangle is shown in the following figure:\n\nSample Input 2\n\n0 0 10 0 0 0 0\n\nSample Output 2\n\n0\n\nNo rectangle can be formed.", "sample_input": "2 1 1 0 0 0 0\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03840", "source_text": "Score : 600 points\n\nProblem Statement\n\nA tetromino is a figure formed by joining four squares edge to edge.\nWe will refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and Z-tetrominos, respectively:\n\nSnuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and Z-tetrominos in his possession are a_I, a_O, a_T, a_J, a_L, a_S and a_Z, respectively.\nSnuke will join K of his tetrominos to form a rectangle that is two squares tall and 2K squares wide.\nHere, the following rules must be followed:\n\nWhen placing each tetromino, rotation is allowed, but reflection is not.\n\nEach square in the rectangle must be covered by exactly one tetromino.\n\nNo part of each tetromino may be outside the rectangle.\n\nSnuke wants to form as large a rectangle as possible.\nFind the maximum possible value of K.\n\nConstraints\n\n0≤a_I,a_O,a_T,a_J,a_L,a_S,a_Z≤10^9\n\na_I+a_O+a_T+a_J+a_L+a_S+a_Z≥1\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na_I a_O a_T a_J a_L a_S a_Z\n\nOutput\n\nPrint the maximum possible value of K. If no rectangle can be formed, print 0.\n\nSample Input 1\n\n2 1 1 0 0 0 0\n\nSample Output 1\n\n3\n\nOne possible way to form the largest rectangle is shown in the following figure:\n\nSample Input 2\n\n0 0 10 0 0 0 0\n\nSample Output 2\n\n0\n\nNo rectangle can be formed.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4960, "cpu_time_ms": 217, "memory_kb": 20196}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s646826706", "group_id": "codeNet:p03841", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline println-sequence))\n(defun println-sequence (sequence &key (out *standard-output*) (key #'identity))\n (let ((init t))\n (sequence:dosequence (x sequence)\n (if init\n (setq init nil)\n (write-char #\\ out))\n (princ (funcall key x) out))\n (terpri out)))\n\n;;;\n;;; Binary heap\n;;;\n\n(define-condition heap-empty-error (error)\n ((heap :initarg :heap :reader heap-empty-error-heap))\n (:report\n (lambda (condition stream)\n (format stream \"Attempted to pop empty heap ~W\" (heap-empty-error-heap condition)))))\n\n(defmacro define-binary-heap (name &key (order '#'>) (element-type 'fixnum))\n \"Defines a binary heap specialized for the given order and the element\ntype. This macro defines a structure of the name NAME and relevant functions:\nMAKE-, -PUSH, -POP, -REINITIALIZE, -EMPTY-P,\n-COUNT, and -PEEK.\"\n (check-type name symbol)\n (let* ((string-name (string name))\n (fname-push (intern (format nil \"~A-PUSH\" string-name)))\n (fname-pop (intern (format nil \"~A-POP\" string-name)))\n (fname-reinitialize (intern (format nil \"~A-REINITIALIZE\" string-name)))\n (fname-empty-p (intern (format nil \"~A-EMPTY-P\" string-name)))\n (fname-count (intern (format nil \"~A-COUNT\" string-name)))\n (fname-peek (intern (format nil \"~A-PEEK\" string-name)))\n (fname-make (intern (format nil \"MAKE-~A\" string-name)))\n (acc-position (intern (format nil \"~A-POSITION\" string-name)))\n (acc-data (intern (format nil \"~A-DATA\" string-name))))\n `(progn\n (locally\n ;; prevent style warnings\n (declare #+sbcl (muffle-conditions style-warning))\n (defstruct (,name\n (:constructor ,fname-make\n (size\n &aux (data ,(if (eql element-type '*)\n `(make-array (1+ size))\n `(make-array (1+ size) :element-type ',element-type))))))\n (data #() :type (simple-array ,element-type (*)))\n (position 1 :type (integer 1 #.most-positive-fixnum))))\n\n (declaim #+sbcl (sb-ext:maybe-inline ,fname-push))\n (defun ,fname-push (obj heap)\n \"Adds OBJ to the end of HEAP.\"\n (declare (optimize (speed 3))\n (type ,name heap))\n (symbol-macrolet ((position (,acc-position heap)))\n (when (>= position (length (,acc-data heap)))\n (setf (,acc-data heap)\n (adjust-array (,acc-data heap)\n (min (- array-total-size-limit 1)\n (* position 2)))))\n (let ((data (,acc-data heap)))\n (declare ((simple-array ,element-type (*)) data))\n (labels ((update (pos)\n (declare (optimize (speed 3) (safety 0)))\n (unless (= pos 1)\n (let ((parent-pos (ash pos -1)))\n (when (funcall ,order (aref data pos) (aref data parent-pos))\n (rotatef (aref data pos) (aref data parent-pos))\n (update parent-pos))))))\n (setf (aref data position) obj)\n (update position)\n (incf position)\n heap))))\n\n (declaim #+sbcl (sb-ext:maybe-inline ,fname-pop))\n (defun ,fname-pop (heap)\n \"Removes and returns the element at the top of HEAP.\"\n (declare (optimize (speed 3))\n (type ,name heap))\n (symbol-macrolet ((position (,acc-position heap)))\n (let ((data (,acc-data heap)))\n (declare ((simple-array ,element-type (*)) data))\n (labels ((update (pos)\n (declare (optimize (speed 3) (safety 0))\n ((integer 1 #.most-positive-fixnum) pos))\n (let* ((child-pos1 (+ pos pos))\n (child-pos2 (1+ child-pos1)))\n (when (<= child-pos1 position)\n (if (<= child-pos2 position)\n (if (funcall ,order (aref data child-pos1) (aref data child-pos2))\n (unless (funcall ,order (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))\n (update child-pos1))\n (unless (funcall ,order (aref data pos) (aref data child-pos2))\n (rotatef (aref data pos) (aref data child-pos2))\n (update child-pos2)))\n (unless (funcall ,order (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))))))))\n (when (= position 1)\n (error 'heap-empty-error :heap heap))\n (prog1 (aref data 1)\n (decf position)\n (setf (aref data 1) (aref data position))\n (update 1))))))\n\n (declaim (inline ,fname-reinitialize))\n (defun ,fname-reinitialize (heap)\n \"Makes HEAP empty.\"\n (setf (,acc-position heap) 1)\n heap)\n\n (declaim (inline ,fname-empty-p))\n (defun ,fname-empty-p (heap)\n \"Returns true iff HEAP is empty.\"\n (= 1 (,acc-position heap)))\n\n (declaim (inline ,fname-count))\n (defun ,fname-count (heap)\n \"Returns the current number of the elements in HEAP.\"\n (- (,acc-position heap) 1))\n\n (declaim (inline ,fname-peek))\n (defun ,fname-peek (heap)\n \"Returns the topmost element of HEAP.\"\n (if (= 1 (,acc-position heap))\n (error 'heap-empty-error :heap heap)\n (aref (,acc-data heap) 1))))))\n\n(define-binary-heap heap\n :order #'<\n :element-type fixnum)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n ;; number . position\n (nodes (make-array n :element-type 'list))\n (as (make-array (* n n) :element-type 'uint32))\n (reserved (make-array (* n n) :element-type 'bit :initial-element 0))\n (que (make-heap (* n n))))\n (dotimes (i n)\n (let ((x (- (read) 1)))\n (setf (aref nodes i) (cons (+ i 1) x)\n (aref reserved x) 1)))\n (setq nodes (sort nodes #'< :key #'cdr))\n (loop for i below (* n n)\n when (zerop (aref reserved i))\n do (heap-push i que))\n (let (rest)\n (loop for (num . pos) across nodes\n do (setf (aref as pos) num)\n (loop repeat (- num 1)\n for i = (heap-pop que)\n do (when (> i pos)\n (write-line \"No\")\n (return-from main))\n (setf (aref as i) num))\n (loop repeat (- n num)\n do (push num rest)))\n (dolist (num rest)\n (setf (aref as (heap-pop que)) num)))\n (write-line \"Yes\")\n (println-sequence as)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 5 9\n\"\n \"Yes\n1 1 1 2 2 2 3 3 3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n4 1\n\"\n \"No\n\")))\n", "language": "Lisp", "metadata": {"date": 1585316065, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03841.html", "problem_id": "p03841", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03841/input.txt", "sample_output_relpath": "derived/input_output/data/p03841/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03841/Lisp/s646826706.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s646826706", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n1 1 1 2 2 2 3 3 3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline println-sequence))\n(defun println-sequence (sequence &key (out *standard-output*) (key #'identity))\n (let ((init t))\n (sequence:dosequence (x sequence)\n (if init\n (setq init nil)\n (write-char #\\ out))\n (princ (funcall key x) out))\n (terpri out)))\n\n;;;\n;;; Binary heap\n;;;\n\n(define-condition heap-empty-error (error)\n ((heap :initarg :heap :reader heap-empty-error-heap))\n (:report\n (lambda (condition stream)\n (format stream \"Attempted to pop empty heap ~W\" (heap-empty-error-heap condition)))))\n\n(defmacro define-binary-heap (name &key (order '#'>) (element-type 'fixnum))\n \"Defines a binary heap specialized for the given order and the element\ntype. This macro defines a structure of the name NAME and relevant functions:\nMAKE-, -PUSH, -POP, -REINITIALIZE, -EMPTY-P,\n-COUNT, and -PEEK.\"\n (check-type name symbol)\n (let* ((string-name (string name))\n (fname-push (intern (format nil \"~A-PUSH\" string-name)))\n (fname-pop (intern (format nil \"~A-POP\" string-name)))\n (fname-reinitialize (intern (format nil \"~A-REINITIALIZE\" string-name)))\n (fname-empty-p (intern (format nil \"~A-EMPTY-P\" string-name)))\n (fname-count (intern (format nil \"~A-COUNT\" string-name)))\n (fname-peek (intern (format nil \"~A-PEEK\" string-name)))\n (fname-make (intern (format nil \"MAKE-~A\" string-name)))\n (acc-position (intern (format nil \"~A-POSITION\" string-name)))\n (acc-data (intern (format nil \"~A-DATA\" string-name))))\n `(progn\n (locally\n ;; prevent style warnings\n (declare #+sbcl (muffle-conditions style-warning))\n (defstruct (,name\n (:constructor ,fname-make\n (size\n &aux (data ,(if (eql element-type '*)\n `(make-array (1+ size))\n `(make-array (1+ size) :element-type ',element-type))))))\n (data #() :type (simple-array ,element-type (*)))\n (position 1 :type (integer 1 #.most-positive-fixnum))))\n\n (declaim #+sbcl (sb-ext:maybe-inline ,fname-push))\n (defun ,fname-push (obj heap)\n \"Adds OBJ to the end of HEAP.\"\n (declare (optimize (speed 3))\n (type ,name heap))\n (symbol-macrolet ((position (,acc-position heap)))\n (when (>= position (length (,acc-data heap)))\n (setf (,acc-data heap)\n (adjust-array (,acc-data heap)\n (min (- array-total-size-limit 1)\n (* position 2)))))\n (let ((data (,acc-data heap)))\n (declare ((simple-array ,element-type (*)) data))\n (labels ((update (pos)\n (declare (optimize (speed 3) (safety 0)))\n (unless (= pos 1)\n (let ((parent-pos (ash pos -1)))\n (when (funcall ,order (aref data pos) (aref data parent-pos))\n (rotatef (aref data pos) (aref data parent-pos))\n (update parent-pos))))))\n (setf (aref data position) obj)\n (update position)\n (incf position)\n heap))))\n\n (declaim #+sbcl (sb-ext:maybe-inline ,fname-pop))\n (defun ,fname-pop (heap)\n \"Removes and returns the element at the top of HEAP.\"\n (declare (optimize (speed 3))\n (type ,name heap))\n (symbol-macrolet ((position (,acc-position heap)))\n (let ((data (,acc-data heap)))\n (declare ((simple-array ,element-type (*)) data))\n (labels ((update (pos)\n (declare (optimize (speed 3) (safety 0))\n ((integer 1 #.most-positive-fixnum) pos))\n (let* ((child-pos1 (+ pos pos))\n (child-pos2 (1+ child-pos1)))\n (when (<= child-pos1 position)\n (if (<= child-pos2 position)\n (if (funcall ,order (aref data child-pos1) (aref data child-pos2))\n (unless (funcall ,order (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))\n (update child-pos1))\n (unless (funcall ,order (aref data pos) (aref data child-pos2))\n (rotatef (aref data pos) (aref data child-pos2))\n (update child-pos2)))\n (unless (funcall ,order (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))))))))\n (when (= position 1)\n (error 'heap-empty-error :heap heap))\n (prog1 (aref data 1)\n (decf position)\n (setf (aref data 1) (aref data position))\n (update 1))))))\n\n (declaim (inline ,fname-reinitialize))\n (defun ,fname-reinitialize (heap)\n \"Makes HEAP empty.\"\n (setf (,acc-position heap) 1)\n heap)\n\n (declaim (inline ,fname-empty-p))\n (defun ,fname-empty-p (heap)\n \"Returns true iff HEAP is empty.\"\n (= 1 (,acc-position heap)))\n\n (declaim (inline ,fname-count))\n (defun ,fname-count (heap)\n \"Returns the current number of the elements in HEAP.\"\n (- (,acc-position heap) 1))\n\n (declaim (inline ,fname-peek))\n (defun ,fname-peek (heap)\n \"Returns the topmost element of HEAP.\"\n (if (= 1 (,acc-position heap))\n (error 'heap-empty-error :heap heap)\n (aref (,acc-data heap) 1))))))\n\n(define-binary-heap heap\n :order #'<\n :element-type fixnum)\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n ;; number . position\n (nodes (make-array n :element-type 'list))\n (as (make-array (* n n) :element-type 'uint32))\n (reserved (make-array (* n n) :element-type 'bit :initial-element 0))\n (que (make-heap (* n n))))\n (dotimes (i n)\n (let ((x (- (read) 1)))\n (setf (aref nodes i) (cons (+ i 1) x)\n (aref reserved x) 1)))\n (setq nodes (sort nodes #'< :key #'cdr))\n (loop for i below (* n n)\n when (zerop (aref reserved i))\n do (heap-push i que))\n (let (rest)\n (loop for (num . pos) across nodes\n do (setf (aref as pos) num)\n (loop repeat (- num 1)\n for i = (heap-pop que)\n do (when (> i pos)\n (write-line \"No\")\n (return-from main))\n (setf (aref as i) num))\n (loop repeat (- n num)\n do (push num rest)))\n (dolist (num rest)\n (setf (aref as (heap-pop que)) num)))\n (write-line \"Yes\")\n (println-sequence as)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 5 9\n\"\n \"Yes\n1 1 1 2 2 2 3 3 3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n4 1\n\"\n \"No\n\")))\n", "problem_context": "Score : 800 points\n\nProblem Statement\n\nYou are given an integer sequence x of length N.\nDetermine if there exists an integer sequence a that satisfies all of the following conditions, and if it exists, construct an instance of a.\n\na is N^2 in length, containing N copies of each of the integers 1, 2, ..., N.\n\nFor each 1 ≤ i ≤ N, the i-th occurrence of the integer i from the left in a is the x_i-th element of a from the left.\n\nConstraints\n\n1 ≤ N ≤ 500\n\n1 ≤ x_i ≤ N^2\n\nAll x_i are distinct.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nx_1 x_2 ... x_N\n\nOutput\n\nIf there does not exist an integer sequence a that satisfies all the conditions, print No.\nIf there does exist such an sequence a, print Yes in the first line, then print an instance of a in the second line, with spaces inbetween.\n\nSample Input 1\n\n3\n1 5 9\n\nSample Output 1\n\nYes\n1 1 1 2 2 2 3 3 3\n\nFor example, the second occurrence of the integer 2 from the left in a in the output is the fifth element of a from the left.\nSimilarly, the condition is satisfied for the integers 1 and 3.\n\nSample Input 2\n\n2\n4 1\n\nSample Output 2\n\nNo", "sample_input": "3\n1 5 9\n"}, "reference_outputs": ["Yes\n1 1 1 2 2 2 3 3 3\n"], "source_document_id": "p03841", "source_text": "Score : 800 points\n\nProblem Statement\n\nYou are given an integer sequence x of length N.\nDetermine if there exists an integer sequence a that satisfies all of the following conditions, and if it exists, construct an instance of a.\n\na is N^2 in length, containing N copies of each of the integers 1, 2, ..., N.\n\nFor each 1 ≤ i ≤ N, the i-th occurrence of the integer i from the left in a is the x_i-th element of a from the left.\n\nConstraints\n\n1 ≤ N ≤ 500\n\n1 ≤ x_i ≤ N^2\n\nAll x_i are distinct.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nx_1 x_2 ... x_N\n\nOutput\n\nIf there does not exist an integer sequence a that satisfies all the conditions, print No.\nIf there does exist such an sequence a, print Yes in the first line, then print an instance of a in the second line, with spaces inbetween.\n\nSample Input 1\n\n3\n1 5 9\n\nSample Output 1\n\nYes\n1 1 1 2 2 2 3 3 3\n\nFor example, the second occurrence of the integer 2 from the left in a in the output is the fifth element of a from the left.\nSimilarly, the condition is satisfied for the integers 1 and 3.\n\nSample Input 2\n\n2\n4 1\n\nSample Output 2\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10692, "cpu_time_ms": 300, "memory_kb": 34408}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s308148776", "group_id": "codeNet:p03845", "input_text": "(let* ((n (read))\n (lst (loop :repeat n :collect (read)))\n (m (read))\n (lst-a (loop :repeat m :collect (cons (read) (read)))))\n (mapcar (lambda (cs)\n (let* ((j (copy-list lst)))\n (setf (nth (1- (car cs)) j) (cdr cs))\n (print (reduce #'+ j)))) lst-a))", "language": "Lisp", "metadata": {"date": 1560439462, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03845.html", "problem_id": "p03845", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03845/input.txt", "sample_output_relpath": "derived/input_output/data/p03845/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03845/Lisp/s308148776.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s308148776", "user_id": "u610490393"}, "prompt_components": {"gold_output": "6\n9\n", "input_to_evaluate": "(let* ((n (read))\n (lst (loop :repeat n :collect (read)))\n (m (read))\n (lst-a (loop :repeat m :collect (cons (read) (read)))))\n (mapcar (lambda (cs)\n (let* ((j (copy-list lst)))\n (setf (nth (1- (car cs)) j) (cdr cs))\n (print (reduce #'+ j)))) lst-a))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nJoisino is about to compete in the final round of a certain programming competition.\nIn this contest, there are N problems, numbered 1 through N.\nJoisino knows that it takes her T_i seconds to solve problem i(1≦i≦N).\n\nAlso, there are M kinds of drinks offered to the contestants, numbered 1 through M.\nIf Joisino takes drink i(1≦i≦M), her brain will be stimulated and the time it takes for her to solve problem P_i will become X_i seconds.\nIt does not affect the time to solve the other problems.\n\nA contestant is allowed to take exactly one of the drinks before the start of the contest.\nFor each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink.\nHere, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems.\nYour task is to write a program to calculate it instead of her.\n\nConstraints\n\nAll input values are integers.\n\n1≦N≦100\n\n1≦T_i≦10^5\n\n1≦M≦100\n\n1≦P_i≦N\n\n1≦X_i≦10^5\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nT_1 T_2 ... T_N\nM\nP_1 X_1\nP_2 X_2\n:\nP_M X_M\n\nOutput\n\nFor each drink, calculate how many seconds it takes Joisino to solve all the problems if she takes that drink, and print the results, one per line.\n\nSample Input 1\n\n3\n2 1 4\n2\n1 1\n2 3\n\nSample Output 1\n\n6\n9\n\nIf Joisino takes drink 1, the time it takes her to solve each problem will be 1, 1 and 4 seconds, respectively, totaling 6 seconds.\n\nIf Joisino takes drink 2, the time it takes her to solve each problem will be 2, 3 and 4 seconds, respectively, totaling 9 seconds.\n\nSample Input 2\n\n5\n7 2 3 8 5\n3\n4 2\n1 7\n4 13\n\nSample Output 2\n\n19\n25\n30", "sample_input": "3\n2 1 4\n2\n1 1\n2 3\n"}, "reference_outputs": ["6\n9\n"], "source_document_id": "p03845", "source_text": "Score : 200 points\n\nProblem Statement\n\nJoisino is about to compete in the final round of a certain programming competition.\nIn this contest, there are N problems, numbered 1 through N.\nJoisino knows that it takes her T_i seconds to solve problem i(1≦i≦N).\n\nAlso, there are M kinds of drinks offered to the contestants, numbered 1 through M.\nIf Joisino takes drink i(1≦i≦M), her brain will be stimulated and the time it takes for her to solve problem P_i will become X_i seconds.\nIt does not affect the time to solve the other problems.\n\nA contestant is allowed to take exactly one of the drinks before the start of the contest.\nFor each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink.\nHere, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems.\nYour task is to write a program to calculate it instead of her.\n\nConstraints\n\nAll input values are integers.\n\n1≦N≦100\n\n1≦T_i≦10^5\n\n1≦M≦100\n\n1≦P_i≦N\n\n1≦X_i≦10^5\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nT_1 T_2 ... T_N\nM\nP_1 X_1\nP_2 X_2\n:\nP_M X_M\n\nOutput\n\nFor each drink, calculate how many seconds it takes Joisino to solve all the problems if she takes that drink, and print the results, one per line.\n\nSample Input 1\n\n3\n2 1 4\n2\n1 1\n2 3\n\nSample Output 1\n\n6\n9\n\nIf Joisino takes drink 1, the time it takes her to solve each problem will be 1, 1 and 4 seconds, respectively, totaling 6 seconds.\n\nIf Joisino takes drink 2, the time it takes her to solve each problem will be 2, 3 and 4 seconds, respectively, totaling 9 seconds.\n\nSample Input 2\n\n5\n7 2 3 8 5\n3\n4 2\n1 7\n4 13\n\nSample Output 2\n\n19\n25\n30", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 306, "cpu_time_ms": 32, "memory_kb": 7264}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s693748492", "group_id": "codeNet:p03845", "input_text": "(declaim (inline sum-seq))\n(defun sum-vec (vec)\n (loop for x across vec summing x))\n\n(defparameter solve-times\n (concatenate 'vector (loop for i from 1 to (read)\n collect (read))))\n\n(defparameter total-time\n (sum-vec solve-times))\n\n(defparameter drinks\n (loop for i from 1 to (read)\n collect (cons (read) (read))))\n\n(loop for drink in drinks\n do (progn (prin1 (+ (cdr drink)\n (- (aref solve-times (1- (car drink))))\n total-time))\n (terpri)))\n", "language": "Lisp", "metadata": {"date": 1483826799, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03845.html", "problem_id": "p03845", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03845/input.txt", "sample_output_relpath": "derived/input_output/data/p03845/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03845/Lisp/s693748492.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s693748492", "user_id": "u328322317"}, "prompt_components": {"gold_output": "6\n9\n", "input_to_evaluate": "(declaim (inline sum-seq))\n(defun sum-vec (vec)\n (loop for x across vec summing x))\n\n(defparameter solve-times\n (concatenate 'vector (loop for i from 1 to (read)\n collect (read))))\n\n(defparameter total-time\n (sum-vec solve-times))\n\n(defparameter drinks\n (loop for i from 1 to (read)\n collect (cons (read) (read))))\n\n(loop for drink in drinks\n do (progn (prin1 (+ (cdr drink)\n (- (aref solve-times (1- (car drink))))\n total-time))\n (terpri)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nJoisino is about to compete in the final round of a certain programming competition.\nIn this contest, there are N problems, numbered 1 through N.\nJoisino knows that it takes her T_i seconds to solve problem i(1≦i≦N).\n\nAlso, there are M kinds of drinks offered to the contestants, numbered 1 through M.\nIf Joisino takes drink i(1≦i≦M), her brain will be stimulated and the time it takes for her to solve problem P_i will become X_i seconds.\nIt does not affect the time to solve the other problems.\n\nA contestant is allowed to take exactly one of the drinks before the start of the contest.\nFor each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink.\nHere, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems.\nYour task is to write a program to calculate it instead of her.\n\nConstraints\n\nAll input values are integers.\n\n1≦N≦100\n\n1≦T_i≦10^5\n\n1≦M≦100\n\n1≦P_i≦N\n\n1≦X_i≦10^5\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nT_1 T_2 ... T_N\nM\nP_1 X_1\nP_2 X_2\n:\nP_M X_M\n\nOutput\n\nFor each drink, calculate how many seconds it takes Joisino to solve all the problems if she takes that drink, and print the results, one per line.\n\nSample Input 1\n\n3\n2 1 4\n2\n1 1\n2 3\n\nSample Output 1\n\n6\n9\n\nIf Joisino takes drink 1, the time it takes her to solve each problem will be 1, 1 and 4 seconds, respectively, totaling 6 seconds.\n\nIf Joisino takes drink 2, the time it takes her to solve each problem will be 2, 3 and 4 seconds, respectively, totaling 9 seconds.\n\nSample Input 2\n\n5\n7 2 3 8 5\n3\n4 2\n1 7\n4 13\n\nSample Output 2\n\n19\n25\n30", "sample_input": "3\n2 1 4\n2\n1 1\n2 3\n"}, "reference_outputs": ["6\n9\n"], "source_document_id": "p03845", "source_text": "Score : 200 points\n\nProblem Statement\n\nJoisino is about to compete in the final round of a certain programming competition.\nIn this contest, there are N problems, numbered 1 through N.\nJoisino knows that it takes her T_i seconds to solve problem i(1≦i≦N).\n\nAlso, there are M kinds of drinks offered to the contestants, numbered 1 through M.\nIf Joisino takes drink i(1≦i≦M), her brain will be stimulated and the time it takes for her to solve problem P_i will become X_i seconds.\nIt does not affect the time to solve the other problems.\n\nA contestant is allowed to take exactly one of the drinks before the start of the contest.\nFor each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink.\nHere, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems.\nYour task is to write a program to calculate it instead of her.\n\nConstraints\n\nAll input values are integers.\n\n1≦N≦100\n\n1≦T_i≦10^5\n\n1≦M≦100\n\n1≦P_i≦N\n\n1≦X_i≦10^5\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nT_1 T_2 ... T_N\nM\nP_1 X_1\nP_2 X_2\n:\nP_M X_M\n\nOutput\n\nFor each drink, calculate how many seconds it takes Joisino to solve all the problems if she takes that drink, and print the results, one per line.\n\nSample Input 1\n\n3\n2 1 4\n2\n1 1\n2 3\n\nSample Output 1\n\n6\n9\n\nIf Joisino takes drink 1, the time it takes her to solve each problem will be 1, 1 and 4 seconds, respectively, totaling 6 seconds.\n\nIf Joisino takes drink 2, the time it takes her to solve each problem will be 2, 3 and 4 seconds, respectively, totaling 9 seconds.\n\nSample Input 2\n\n5\n7 2 3 8 5\n3\n4 2\n1 7\n4 13\n\nSample Output 2\n\n19\n25\n30", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 535, "cpu_time_ms": 48, "memory_kb": 4452}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s626998912", "group_id": "codeNet:p03853", "input_text": "(loop repeat (read)\n with w = (read)\n for i = (read-line)\n do (format t \"~A~%~A~%\" i i))", "language": "Lisp", "metadata": {"date": 1505323497, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03853.html", "problem_id": "p03853", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03853/input.txt", "sample_output_relpath": "derived/input_output/data/p03853/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03853/Lisp/s626998912.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s626998912", "user_id": "u140665374"}, "prompt_components": {"gold_output": "*.\n*.\n.*\n.*\n", "input_to_evaluate": "(loop repeat (read)\n with w = (read)\n for i = (read-line)\n do (format t \"~A~%~A~%\" i i))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either . or *. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.\n\nExtend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).\n\nConstraints\n\n1≦H, W≦100\n\nC_{i,j} is either . or *.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nH W\nC_{1,1}...C_{1,W}\n:\nC_{H,1}...C_{H,W}\n\nOutput\n\nPrint the extended image.\n\nSample Input 1\n\n2 2\n*.\n.*\n\nSample Output 1\n\n*.\n*.\n.*\n.*\n\nSample Input 2\n\n1 4\n***.\n\nSample Output 2\n\n***.\n***.\n\nSample Input 3\n\n9 20\n.....***....***.....\n....*...*..*...*....\n...*.....**.....*...\n...*.....*......*...\n....*.....*....*....\n.....**..*...**.....\n.......*..*.*.......\n........**.*........\n.........**.........\n\nSample Output 3\n\n.....***....***.....\n.....***....***.....\n....*...*..*...*....\n....*...*..*...*....\n...*.....**.....*...\n...*.....**.....*...\n...*.....*......*...\n...*.....*......*...\n....*.....*....*....\n....*.....*....*....\n.....**..*...**.....\n.....**..*...**.....\n.......*..*.*.......\n.......*..*.*.......\n........**.*........\n........**.*........\n.........**.........\n.........**.........", "sample_input": "2 2\n*.\n.*\n"}, "reference_outputs": ["*.\n*.\n.*\n.*\n"], "source_document_id": "p03853", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either . or *. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.\n\nExtend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).\n\nConstraints\n\n1≦H, W≦100\n\nC_{i,j} is either . or *.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nH W\nC_{1,1}...C_{1,W}\n:\nC_{H,1}...C_{H,W}\n\nOutput\n\nPrint the extended image.\n\nSample Input 1\n\n2 2\n*.\n.*\n\nSample Output 1\n\n*.\n*.\n.*\n.*\n\nSample Input 2\n\n1 4\n***.\n\nSample Output 2\n\n***.\n***.\n\nSample Input 3\n\n9 20\n.....***....***.....\n....*...*..*...*....\n...*.....**.....*...\n...*.....*......*...\n....*.....*....*....\n.....**..*...**.....\n.......*..*.*.......\n........**.*........\n.........**.........\n\nSample Output 3\n\n.....***....***.....\n.....***....***.....\n....*...*..*...*....\n....*...*..*...*....\n...*.....**.....*...\n...*.....**.....*...\n...*.....*......*...\n...*.....*......*...\n....*.....*....*....\n....*.....*....*....\n.....**..*...**.....\n.....**..*...**.....\n.......*..*.*.......\n.......*..*.*.......\n........**.*........\n........**.*........\n.........**.........\n.........**.........", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 103, "cpu_time_ms": 168, "memory_kb": 12256}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s925229960", "group_id": "codeNet:p03857", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; Should we do this with UNWIND-PROTECT?\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Disjoint set by Union-Find algorithm\n;;;\n\n(defstruct (disjoint-set\n (:constructor make-disjoint-set\n (size &aux (data (make-array size :element-type '(signed-byte 32) :initial-element -1))))\n (:conc-name ds-))\n (data nil :type (simple-array (signed-byte 32) (*))))\n\n(declaim (ftype (function * (values (mod #.array-total-size-limit) &optional)) ds-root))\n(defun ds-root (x disjoint-set)\n \"Returns the root of X.\"\n (declare (optimize (speed 3) (safety 0))\n ((mod #.array-total-size-limit) x))\n (let ((data (ds-data disjoint-set)))\n (if (< (aref data x) 0)\n x\n (setf (aref data x)\n (ds-root (aref data x) disjoint-set)))))\n\n(declaim (inline ds-unite!))\n(defun ds-unite! (x1 x2 disjoint-set)\n \"Destructively unites X1 and X2 and returns true iff X1 and X2 become\nconnected for the first time.\"\n (let ((root1 (ds-root x1 disjoint-set))\n (root2 (ds-root x2 disjoint-set)))\n (unless (= root1 root2)\n (let ((data (ds-data disjoint-set)))\n ;; ensure the size of root1 >= the size of root2\n (when (> (aref data root1) (aref data root2))\n (rotatef root1 root2))\n (incf (aref data root1) (aref data root2))\n (setf (aref data root2) root1)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (l (read))\n (road-network (make-disjoint-set n))\n (rail-network (make-disjoint-set n))\n (table (make-hash-table :test #'equal :size n))\n (cities (make-array n :element-type 'cons)))\n (declare (uint32 n k l))\n (dotimes (_ k)\n (let ((p (- (read-fixnum) 1))\n (q (- (read-fixnum) 1)))\n (ds-unite! p q road-network)))\n (dotimes (_ l)\n (let ((r (- (read-fixnum) 1))\n (s (- (read-fixnum) 1)))\n (ds-unite! r s rail-network)))\n (dotimes (i n)\n (let* ((root1 (ds-root i road-network))\n (root2 (ds-root i rail-network))\n (pair (cons root1 root2)))\n (if (gethash pair table)\n (incf (the uint32 (gethash pair table)))\n (setf (gethash pair table) 1))\n (setf (aref cities i) pair)))\n (with-buffered-stdout\n (dotimes (i n)\n (unless (zerop i) (write-char #\\ ))\n (write (gethash (aref cities i) table)))\n (terpri))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1566441071, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03857.html", "problem_id": "p03857", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03857/input.txt", "sample_output_relpath": "derived/input_output/data/p03857/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03857/Lisp/s925229960.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s925229960", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1 2 2 1\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; Should we do this with UNWIND-PROTECT?\n(defmacro with-buffered-stdout (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to\n*STANDARD-OUTPUT* after BODY has been done (without error). Note that only\nBASE-CHAR is allowed.\"\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n;;;\n;;; Disjoint set by Union-Find algorithm\n;;;\n\n(defstruct (disjoint-set\n (:constructor make-disjoint-set\n (size &aux (data (make-array size :element-type '(signed-byte 32) :initial-element -1))))\n (:conc-name ds-))\n (data nil :type (simple-array (signed-byte 32) (*))))\n\n(declaim (ftype (function * (values (mod #.array-total-size-limit) &optional)) ds-root))\n(defun ds-root (x disjoint-set)\n \"Returns the root of X.\"\n (declare (optimize (speed 3) (safety 0))\n ((mod #.array-total-size-limit) x))\n (let ((data (ds-data disjoint-set)))\n (if (< (aref data x) 0)\n x\n (setf (aref data x)\n (ds-root (aref data x) disjoint-set)))))\n\n(declaim (inline ds-unite!))\n(defun ds-unite! (x1 x2 disjoint-set)\n \"Destructively unites X1 and X2 and returns true iff X1 and X2 become\nconnected for the first time.\"\n (let ((root1 (ds-root x1 disjoint-set))\n (root2 (ds-root x2 disjoint-set)))\n (unless (= root1 root2)\n (let ((data (ds-data disjoint-set)))\n ;; ensure the size of root1 >= the size of root2\n (when (> (aref data root1) (aref data root2))\n (rotatef root1 root2))\n (incf (aref data root1) (aref data root2))\n (setf (aref data root2) root1)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (l (read))\n (road-network (make-disjoint-set n))\n (rail-network (make-disjoint-set n))\n (table (make-hash-table :test #'equal :size n))\n (cities (make-array n :element-type 'cons)))\n (declare (uint32 n k l))\n (dotimes (_ k)\n (let ((p (- (read-fixnum) 1))\n (q (- (read-fixnum) 1)))\n (ds-unite! p q road-network)))\n (dotimes (_ l)\n (let ((r (- (read-fixnum) 1))\n (s (- (read-fixnum) 1)))\n (ds-unite! r s rail-network)))\n (dotimes (i n)\n (let* ((root1 (ds-root i road-network))\n (root2 (ds-root i rail-network))\n (pair (cons root1 root2)))\n (if (gethash pair table)\n (incf (the uint32 (gethash pair table)))\n (setf (gethash pair table) 1))\n (setf (aref cities i) pair)))\n (with-buffered-stdout\n (dotimes (i n)\n (unless (zerop i) (write-char #\\ ))\n (write (gethash (aref cities i) table)))\n (terpri))))\n\n#-swank (main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are N cities. There are also K roads and L railways, extending between the cities.\nThe i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities.\nNo two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.\n\nWe will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads.\nWe will also define connectivity by railways similarly.\n\nFor each city, find the number of the cities connected to that city by both roads and railways.\n\nConstraints\n\n2 ≦ N ≦ 2*10^5\n\n1 ≦ K, L≦ 10^5\n\n1 ≦ p_i, q_i, r_i, s_i ≦ N\n\np_i < q_i\n\nr_i < s_i\n\nWhen i ≠ j, (p_i, q_i) ≠ (p_j, q_j)\n\nWhen i ≠ j, (r_i, s_i) ≠ (r_j, s_j)\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN K L\np_1 q_1\n:\np_K q_K\nr_1 s_1\n:\nr_L s_L\n\nOutput\n\nPrint N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.\n\nSample Input 1\n\n4 3 1\n1 2\n2 3\n3 4\n2 3\n\nSample Output 1\n\n1 2 2 1\n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers for the cities are 1, 2, 2 and 1, respectively.\n\nSample Input 2\n\n4 2 2\n1 2\n2 3\n1 4\n2 3\n\nSample Output 2\n\n1 2 2 1\n\nSample Input 3\n\n7 4 4\n1 2\n2 3\n2 5\n6 7\n3 5\n4 5\n3 4\n6 7\n\nSample Output 3\n\n1 1 2 1 2 2 2", "sample_input": "4 3 1\n1 2\n2 3\n3 4\n2 3\n"}, "reference_outputs": ["1 2 2 1\n"], "source_document_id": "p03857", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are N cities. There are also K roads and L railways, extending between the cities.\nThe i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities.\nNo two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.\n\nWe will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads.\nWe will also define connectivity by railways similarly.\n\nFor each city, find the number of the cities connected to that city by both roads and railways.\n\nConstraints\n\n2 ≦ N ≦ 2*10^5\n\n1 ≦ K, L≦ 10^5\n\n1 ≦ p_i, q_i, r_i, s_i ≦ N\n\np_i < q_i\n\nr_i < s_i\n\nWhen i ≠ j, (p_i, q_i) ≠ (p_j, q_j)\n\nWhen i ≠ j, (r_i, s_i) ≠ (r_j, s_j)\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN K L\np_1 q_1\n:\np_K q_K\nr_1 s_1\n:\nr_L s_L\n\nOutput\n\nPrint N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.\n\nSample Input 1\n\n4 3 1\n1 2\n2 3\n3 4\n2 3\n\nSample Output 1\n\n1 2 2 1\n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers for the cities are 1, 2, 2 and 1, respectively.\n\nSample Input 2\n\n4 2 2\n1 2\n2 3\n1 4\n2 3\n\nSample Output 2\n\n1 2 2 1\n\nSample Input 3\n\n7 4 4\n1 2\n2 3\n2 5\n6 7\n3 5\n4 5\n3 4\n6 7\n\nSample Output 3\n\n1 1 2 1 2 2 2", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5186, "cpu_time_ms": 333, "memory_kb": 33764}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s275415792", "group_id": "codeNet:p03861", "input_text": "(defun main (a b x)\n (let ((min-divisor (+ (truncate a x) 1))\n (max-divisor (+ (truncate b x) 1)))\n (- max-divisor min-divisor)))\n\n(format t \"~A~%\" (main (read) (read) (read)))\n", "language": "Lisp", "metadata": {"date": 1580065875, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03861.html", "problem_id": "p03861", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03861/input.txt", "sample_output_relpath": "derived/input_output/data/p03861/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03861/Lisp/s275415792.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s275415792", "user_id": "u237057875"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun main (a b x)\n (let ((min-divisor (+ (truncate a x) 1))\n (max-divisor (+ (truncate b x) 1)))\n (- max-divisor min-divisor)))\n\n(format t \"~A~%\" (main (read) (read) (read)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given nonnegative integers a and b (a ≤ b), and a positive integer x.\nAmong the integers between a and b, inclusive, how many are divisible by x?\n\nConstraints\n\n0 ≤ a ≤ b ≤ 10^{18}\n\n1 ≤ x ≤ 10^{18}\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b x\n\nOutput\n\nPrint the number of the integers between a and b, inclusive, that are divisible by x.\n\nSample Input 1\n\n4 8 2\n\nSample Output 1\n\n3\n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2: 4, 6 and 8.\n\nSample Input 2\n\n0 5 1\n\nSample Output 2\n\n6\n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0, 1, 2, 3, 4 and 5.\n\nSample Input 3\n\n9 9 2\n\nSample Output 3\n\n0\n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\nSample Input 4\n\n1 1000000000000000000 3\n\nSample Output 4\n\n333333333333333333\n\nWatch out for integer overflows.", "sample_input": "4 8 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03861", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given nonnegative integers a and b (a ≤ b), and a positive integer x.\nAmong the integers between a and b, inclusive, how many are divisible by x?\n\nConstraints\n\n0 ≤ a ≤ b ≤ 10^{18}\n\n1 ≤ x ≤ 10^{18}\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b x\n\nOutput\n\nPrint the number of the integers between a and b, inclusive, that are divisible by x.\n\nSample Input 1\n\n4 8 2\n\nSample Output 1\n\n3\n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2: 4, 6 and 8.\n\nSample Input 2\n\n0 5 1\n\nSample Output 2\n\n6\n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0, 1, 2, 3, 4 and 5.\n\nSample Input 3\n\n9 9 2\n\nSample Output 3\n\n0\n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\nSample Input 4\n\n1 1000000000000000000 3\n\nSample Output 4\n\n333333333333333333\n\nWatch out for integer overflows.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 188, "cpu_time_ms": 9, "memory_kb": 3432}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s094608866", "group_id": "codeNet:p03861", "input_text": "(let* ((lst (list (read) (read) (read)))\n (ans (ceiling (- (nth 1 lst) (nth 0 lst)) (nth 2 lst))))\n (if (= 0 (mod (nth 0 lst) (nth 2 lst)))\n (princ (1+ ans))\n (princ ans)))", "language": "Lisp", "metadata": {"date": 1554129110, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03861.html", "problem_id": "p03861", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03861/input.txt", "sample_output_relpath": "derived/input_output/data/p03861/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03861/Lisp/s094608866.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s094608866", "user_id": "u610490393"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let* ((lst (list (read) (read) (read)))\n (ans (ceiling (- (nth 1 lst) (nth 0 lst)) (nth 2 lst))))\n (if (= 0 (mod (nth 0 lst) (nth 2 lst)))\n (princ (1+ ans))\n (princ ans)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given nonnegative integers a and b (a ≤ b), and a positive integer x.\nAmong the integers between a and b, inclusive, how many are divisible by x?\n\nConstraints\n\n0 ≤ a ≤ b ≤ 10^{18}\n\n1 ≤ x ≤ 10^{18}\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b x\n\nOutput\n\nPrint the number of the integers between a and b, inclusive, that are divisible by x.\n\nSample Input 1\n\n4 8 2\n\nSample Output 1\n\n3\n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2: 4, 6 and 8.\n\nSample Input 2\n\n0 5 1\n\nSample Output 2\n\n6\n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0, 1, 2, 3, 4 and 5.\n\nSample Input 3\n\n9 9 2\n\nSample Output 3\n\n0\n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\nSample Input 4\n\n1 1000000000000000000 3\n\nSample Output 4\n\n333333333333333333\n\nWatch out for integer overflows.", "sample_input": "4 8 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03861", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given nonnegative integers a and b (a ≤ b), and a positive integer x.\nAmong the integers between a and b, inclusive, how many are divisible by x?\n\nConstraints\n\n0 ≤ a ≤ b ≤ 10^{18}\n\n1 ≤ x ≤ 10^{18}\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b x\n\nOutput\n\nPrint the number of the integers between a and b, inclusive, that are divisible by x.\n\nSample Input 1\n\n4 8 2\n\nSample Output 1\n\n3\n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2: 4, 6 and 8.\n\nSample Input 2\n\n0 5 1\n\nSample Output 2\n\n6\n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0, 1, 2, 3, 4 and 5.\n\nSample Input 3\n\n9 9 2\n\nSample Output 3\n\n0\n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\nSample Input 4\n\n1 1000000000000000000 3\n\nSample Output 4\n\n333333333333333333\n\nWatch out for integer overflows.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 188, "cpu_time_ms": 134, "memory_kb": 13156}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s905958267", "group_id": "codeNet:p03861", "input_text": "(let ((a (read))\n (b (read))\n (c (read)))\n (princ (+ (if (= 0 (mod a c)) 1 0) (- (/ b c) (/ a c)))))", "language": "Lisp", "metadata": {"date": 1550072555, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03861.html", "problem_id": "p03861", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03861/input.txt", "sample_output_relpath": "derived/input_output/data/p03861/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03861/Lisp/s905958267.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s905958267", "user_id": "u994767958"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (c (read)))\n (princ (+ (if (= 0 (mod a c)) 1 0) (- (/ b c) (/ a c)))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given nonnegative integers a and b (a ≤ b), and a positive integer x.\nAmong the integers between a and b, inclusive, how many are divisible by x?\n\nConstraints\n\n0 ≤ a ≤ b ≤ 10^{18}\n\n1 ≤ x ≤ 10^{18}\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b x\n\nOutput\n\nPrint the number of the integers between a and b, inclusive, that are divisible by x.\n\nSample Input 1\n\n4 8 2\n\nSample Output 1\n\n3\n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2: 4, 6 and 8.\n\nSample Input 2\n\n0 5 1\n\nSample Output 2\n\n6\n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0, 1, 2, 3, 4 and 5.\n\nSample Input 3\n\n9 9 2\n\nSample Output 3\n\n0\n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\nSample Input 4\n\n1 1000000000000000000 3\n\nSample Output 4\n\n333333333333333333\n\nWatch out for integer overflows.", "sample_input": "4 8 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03861", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given nonnegative integers a and b (a ≤ b), and a positive integer x.\nAmong the integers between a and b, inclusive, how many are divisible by x?\n\nConstraints\n\n0 ≤ a ≤ b ≤ 10^{18}\n\n1 ≤ x ≤ 10^{18}\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b x\n\nOutput\n\nPrint the number of the integers between a and b, inclusive, that are divisible by x.\n\nSample Input 1\n\n4 8 2\n\nSample Output 1\n\n3\n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2: 4, 6 and 8.\n\nSample Input 2\n\n0 5 1\n\nSample Output 2\n\n6\n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0, 1, 2, 3, 4 and 5.\n\nSample Input 3\n\n9 9 2\n\nSample Output 3\n\n0\n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\nSample Input 4\n\n1 1000000000000000000 3\n\nSample Output 4\n\n333333333333333333\n\nWatch out for integer overflows.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 114, "cpu_time_ms": 125, "memory_kb": 12136}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s712679214", "group_id": "codeNet:p03866", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; unfinished.\n\n(declaim (inline find-argopt))\n(defun find-argopt (sequence predicate &key (start 0) end (key #'identity))\n \"Returns an index x that satisfies (NOT (FUNCALL PREDICATE SEQUENCE[y]\nSEQUENCE[x])) (i.e. SEQUENCE[x] >= SEQUENCE[y]) for all the indices y and\nreturns SEQUENCE[x] as the second value.\"\n (declare ((or null (integer 0 #.most-positive-fixnum)) end)\n ((integer 0 #.most-positive-fixnum) start)\n (function predicate)\n (sequence sequence))\n (labels ((invalid-range-error ()\n (error \"Can't find optimal value in null interval [~A, ~A) on ~A\" start end sequence)))\n (etypecase sequence\n (list\n (let ((sequence (nthcdr start sequence))\n (end (or end most-positive-fixnum)))\n (when (or (null sequence)\n (>= start end))\n (invalid-range-error))\n (let ((opt-element (car sequence))\n (opt-index start)\n (pos start))\n (dolist (x sequence)\n (when (>= pos end)\n (return-from find-argopt (values opt-index opt-element)))\n (unless (funcall predicate (funcall key opt-element) (funcall key x))\n (setq opt-element x\n opt-index pos))\n (incf pos))\n (values opt-index opt-element))))\n (vector\n (let ((end (or end (length sequence))))\n (when (or (>= start end)\n (>= start (length sequence)))\n (invalid-range-error))\n (let ((opt-element (aref sequence start))\n (opt-index start))\n (loop for i from start below end\n for x = (aref sequence i)\n do (unless (funcall predicate (funcall key opt-element) (funcall key x))\n (setq opt-element x\n opt-index i)))\n (values opt-index opt-element)))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defconstant +eps+ 1d-10)\n\n(defun main ()\n (declare #.OPT)\n (let* ((init-x (float (read) 1d0))\n (init-y (float (read) 1d0))\n (goal-x (float (read) 1d0))\n (goal-y (float (read) 1d0))\n (n (read))\n (xs (make-array (+ n 2) :element-type 'double-float))\n (ys (make-array (+ n 2) :element-type 'double-float))\n (rs (make-array (+ n 2) :element-type 'double-float :initial-element 0d0))\n (init n)\n (goal (+ 1 n))\n (q (loop for i below (+ n 2) collect i))\n (dists (make-array (+ n 2) :element-type 'double-float :initial-element most-positive-double-float)))\n (declare ((simple-array double-float (*)) dists)\n (list q)\n (uint16 n))\n (dotimes (i n)\n (setf (aref xs i) (float (read-fixnum) 1d0)\n (aref ys i) (float (read-fixnum) 1d0)\n (aref rs i) (float (read-fixnum) 1d0)))\n (setf (aref xs init) init-x\n (aref ys init) init-y\n (aref xs goal) goal-x\n (aref ys goal) goal-y\n (aref dists init) 0d0)\n (loop until (null q)\n for i = (find-argopt q #'< :key (lambda (v) (aref dists v)))\n for v = (nth i q)\n for x0 = (aref xs v)\n for y0 = (aref ys v)\n for r0 = (aref rs v)\n do (setf q (delete v q :count 1))\n (dotimes (next (+ n 2))\n (let* ((x1 (aref xs next))\n (y1 (aref ys next))\n (r1 (aref rs next))\n (delta (max 0d0 (- (sqrt (+ (expt (- x0 x1) 2)\n (expt (- y0 y1) 2)))\n r0 r1))))\n (when (< (+ (aref dists v) delta +eps+)\n (aref dists next))\n (setf (aref dists next)\n (+ (aref dists v) delta))))))\n (println (aref dists goal))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1566550936, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03866.html", "problem_id": "p03866", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03866/input.txt", "sample_output_relpath": "derived/input_output/data/p03866/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03866/Lisp/s712679214.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s712679214", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3.6568542495\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; unfinished.\n\n(declaim (inline find-argopt))\n(defun find-argopt (sequence predicate &key (start 0) end (key #'identity))\n \"Returns an index x that satisfies (NOT (FUNCALL PREDICATE SEQUENCE[y]\nSEQUENCE[x])) (i.e. SEQUENCE[x] >= SEQUENCE[y]) for all the indices y and\nreturns SEQUENCE[x] as the second value.\"\n (declare ((or null (integer 0 #.most-positive-fixnum)) end)\n ((integer 0 #.most-positive-fixnum) start)\n (function predicate)\n (sequence sequence))\n (labels ((invalid-range-error ()\n (error \"Can't find optimal value in null interval [~A, ~A) on ~A\" start end sequence)))\n (etypecase sequence\n (list\n (let ((sequence (nthcdr start sequence))\n (end (or end most-positive-fixnum)))\n (when (or (null sequence)\n (>= start end))\n (invalid-range-error))\n (let ((opt-element (car sequence))\n (opt-index start)\n (pos start))\n (dolist (x sequence)\n (when (>= pos end)\n (return-from find-argopt (values opt-index opt-element)))\n (unless (funcall predicate (funcall key opt-element) (funcall key x))\n (setq opt-element x\n opt-index pos))\n (incf pos))\n (values opt-index opt-element))))\n (vector\n (let ((end (or end (length sequence))))\n (when (or (>= start end)\n (>= start (length sequence)))\n (invalid-range-error))\n (let ((opt-element (aref sequence start))\n (opt-index start))\n (loop for i from start below end\n for x = (aref sequence i)\n do (unless (funcall predicate (funcall key opt-element) (funcall key x))\n (setq opt-element x\n opt-index i)))\n (values opt-index opt-element)))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defconstant +eps+ 1d-10)\n\n(defun main ()\n (declare #.OPT)\n (let* ((init-x (float (read) 1d0))\n (init-y (float (read) 1d0))\n (goal-x (float (read) 1d0))\n (goal-y (float (read) 1d0))\n (n (read))\n (xs (make-array (+ n 2) :element-type 'double-float))\n (ys (make-array (+ n 2) :element-type 'double-float))\n (rs (make-array (+ n 2) :element-type 'double-float :initial-element 0d0))\n (init n)\n (goal (+ 1 n))\n (q (loop for i below (+ n 2) collect i))\n (dists (make-array (+ n 2) :element-type 'double-float :initial-element most-positive-double-float)))\n (declare ((simple-array double-float (*)) dists)\n (list q)\n (uint16 n))\n (dotimes (i n)\n (setf (aref xs i) (float (read-fixnum) 1d0)\n (aref ys i) (float (read-fixnum) 1d0)\n (aref rs i) (float (read-fixnum) 1d0)))\n (setf (aref xs init) init-x\n (aref ys init) init-y\n (aref xs goal) goal-x\n (aref ys goal) goal-y\n (aref dists init) 0d0)\n (loop until (null q)\n for i = (find-argopt q #'< :key (lambda (v) (aref dists v)))\n for v = (nth i q)\n for x0 = (aref xs v)\n for y0 = (aref ys v)\n for r0 = (aref rs v)\n do (setf q (delete v q :count 1))\n (dotimes (next (+ n 2))\n (let* ((x1 (aref xs next))\n (y1 (aref ys next))\n (r1 (aref rs next))\n (delta (max 0d0 (- (sqrt (+ (expt (- x0 x1) 2)\n (expt (- y0 y1) 2)))\n r0 r1))))\n (when (< (+ (aref dists v) delta +eps+)\n (aref dists next))\n (setf (aref dists next)\n (+ (aref dists v) delta))))))\n (println (aref dists goal))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nOn the xy-plane, Snuke is going to travel from the point (x_s, y_s) to the point (x_t, y_t).\nHe can move in arbitrary directions with speed 1.\nHere, we will consider him as a point without size.\n\nThere are N circular barriers deployed on the plane.\nThe center and the radius of the i-th barrier are (x_i, y_i) and r_i, respectively.\nThe barriers may overlap or contain each other.\n\nA point on the plane is exposed to cosmic rays if the point is not within any of the barriers.\n\nSnuke wants to avoid exposure to cosmic rays as much as possible during the travel.\nFind the minimum possible duration of time he is exposed to cosmic rays during the travel.\n\nConstraints\n\nAll input values are integers.\n\n-10^9 ≤ x_s, y_s, x_t, y_t ≤ 10^9\n\n(x_s, y_s) ≠ (x_t, y_t)\n\n1≤N≤1,000\n\n-10^9 ≤ x_i, y_i ≤ 10^9\n\n1 ≤ r_i ≤ 10^9\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx_s y_s x_t y_t\nN\nx_1 y_1 r_1\nx_2 y_2 r_2\n:\nx_N y_N r_N\n\nOutput\n\nPrint the minimum possible duration of time Snuke is exposed to cosmic rays during the travel.\nThe output is considered correct if the absolute or relative error is at most 10^{-9}.\n\nSample Input 1\n\n-2 -2 2 2\n1\n0 0 1\n\nSample Output 1\n\n3.6568542495\n\nAn optimal route is as follows:\n\nSample Input 2\n\n-2 0 2 0\n2\n-1 0 2\n1 0 2\n\nSample Output 2\n\n0.0000000000\n\nAn optimal route is as follows:\n\nSample Input 3\n\n4 -2 -2 4\n3\n0 0 2\n4 0 1\n0 4 1\n\nSample Output 3\n\n4.0000000000\n\nAn optimal route is as follows:", "sample_input": "-2 -2 2 2\n1\n0 0 1\n"}, "reference_outputs": ["3.6568542495\n"], "source_document_id": "p03866", "source_text": "Score : 600 points\n\nProblem Statement\n\nOn the xy-plane, Snuke is going to travel from the point (x_s, y_s) to the point (x_t, y_t).\nHe can move in arbitrary directions with speed 1.\nHere, we will consider him as a point without size.\n\nThere are N circular barriers deployed on the plane.\nThe center and the radius of the i-th barrier are (x_i, y_i) and r_i, respectively.\nThe barriers may overlap or contain each other.\n\nA point on the plane is exposed to cosmic rays if the point is not within any of the barriers.\n\nSnuke wants to avoid exposure to cosmic rays as much as possible during the travel.\nFind the minimum possible duration of time he is exposed to cosmic rays during the travel.\n\nConstraints\n\nAll input values are integers.\n\n-10^9 ≤ x_s, y_s, x_t, y_t ≤ 10^9\n\n(x_s, y_s) ≠ (x_t, y_t)\n\n1≤N≤1,000\n\n-10^9 ≤ x_i, y_i ≤ 10^9\n\n1 ≤ r_i ≤ 10^9\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx_s y_s x_t y_t\nN\nx_1 y_1 r_1\nx_2 y_2 r_2\n:\nx_N y_N r_N\n\nOutput\n\nPrint the minimum possible duration of time Snuke is exposed to cosmic rays during the travel.\nThe output is considered correct if the absolute or relative error is at most 10^{-9}.\n\nSample Input 1\n\n-2 -2 2 2\n1\n0 0 1\n\nSample Output 1\n\n3.6568542495\n\nAn optimal route is as follows:\n\nSample Input 2\n\n-2 0 2 0\n2\n-1 0 2\n1 0 2\n\nSample Output 2\n\n0.0000000000\n\nAn optimal route is as follows:\n\nSample Input 3\n\n4 -2 -2 4\n3\n0 0 2\n4 0 1\n0 4 1\n\nSample Output 3\n\n4.0000000000\n\nAn optimal route is as follows:", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6210, "cpu_time_ms": 96, "memory_kb": 16872}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s378464172", "group_id": "codeNet:p03866", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; unfinished.\n\n(declaim (inline find-argopt))\n(defun find-argopt (sequence predicate &key (start 0) end (key #'identity))\n \"Returns an index x that satisfies (NOT (FUNCALL PREDICATE SEQUENCE[y]\nSEQUENCE[x])) (i.e. SEQUENCE[x] >= SEQUENCE[y]) for all the indices y and\nreturns SEQUENCE[x] as the second value.\"\n (declare ((or null (integer 0 #.most-positive-fixnum)) end)\n ((integer 0 #.most-positive-fixnum) start)\n (function predicate)\n (sequence sequence))\n (etypecase sequence\n (list\n (let ((end (or end most-positive-fixnum))\n (optimum (funcall key (car sequence)))\n (index 0)\n (pos 0))\n (dolist (x sequence (values index optimum))\n (when (>= pos end)\n (return (values index optimum)))\n (when (>= pos start)\n (unless (funcall predicate optimum (funcall key x))\n (setq optimum (funcall key x)\n index pos)))\n (incf pos))))\n (vector\n (let ((end (or end (length sequence))))\n (unless (<= start end)\n (error \"Can't find optimal value in null interval [~A, ~A)\" start end))\n (let ((optimum (funcall key (aref sequence 0)))\n (index 0))\n (dotimes (i (length sequence) (values index optimum))\n (unless (funcall predicate optimum (funcall key (aref sequence i)))\n (setq optimum (aref sequence i)\n index i))))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defconstant +eps+ 1d-10)\n\n(defun main ()\n (declare #.OPT)\n (let* ((init-x (float (read) 1d0))\n (init-y (float (read) 1d0))\n (goal-x (float (read) 1d0))\n (goal-y (float (read) 1d0))\n (n (read))\n (xs (make-array (+ n 2) :element-type 'double-float))\n (ys (make-array (+ n 2) :element-type 'double-float))\n (rs (make-array (+ n 2) :element-type 'double-float :initial-element 0d0))\n (init n)\n (goal (+ 1 n))\n (q (loop for i below (+ n 2) collect i))\n (dists (make-array (+ n 2) :element-type 'double-float :initial-element most-positive-double-float)))\n (declare ((simple-array double-float (*)) dists)\n (list q)\n (uint16 n))\n (dotimes (i n)\n (setf (aref xs i) (float (read-fixnum) 1d0)\n (aref ys i) (float (read-fixnum) 1d0)\n (aref rs i) (float (read-fixnum) 1d0)))\n (setf (aref xs init) init-x\n (aref ys init) init-y\n (aref xs goal) goal-x\n (aref ys goal) goal-y\n (aref dists init) 0d0)\n (loop until (null q)\n for i = (find-argopt q #'< :key (lambda (v) (aref dists v)))\n for v = (nth i q)\n for x0 = (aref xs v)\n for y0 = (aref ys v)\n for r0 = (aref rs v)\n do (setf q (delete v q :count 1))\n (dotimes (next (+ n 2))\n (let* ((x1 (aref xs next))\n (y1 (aref ys next))\n (r1 (aref rs next))\n (delta (max 0d0 (- (sqrt (+ (expt (- x0 x1) 2)\n (expt (- y0 y1) 2)))\n r0 r1))))\n (when (< (+ (aref dists v) delta +eps+)\n (aref dists next))\n (setf (aref dists next)\n (+ (aref dists v) delta))))))\n (println (aref dists goal))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1566549518, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03866.html", "problem_id": "p03866", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03866/input.txt", "sample_output_relpath": "derived/input_output/data/p03866/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03866/Lisp/s378464172.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s378464172", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3.6568542495\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; unfinished.\n\n(declaim (inline find-argopt))\n(defun find-argopt (sequence predicate &key (start 0) end (key #'identity))\n \"Returns an index x that satisfies (NOT (FUNCALL PREDICATE SEQUENCE[y]\nSEQUENCE[x])) (i.e. SEQUENCE[x] >= SEQUENCE[y]) for all the indices y and\nreturns SEQUENCE[x] as the second value.\"\n (declare ((or null (integer 0 #.most-positive-fixnum)) end)\n ((integer 0 #.most-positive-fixnum) start)\n (function predicate)\n (sequence sequence))\n (etypecase sequence\n (list\n (let ((end (or end most-positive-fixnum))\n (optimum (funcall key (car sequence)))\n (index 0)\n (pos 0))\n (dolist (x sequence (values index optimum))\n (when (>= pos end)\n (return (values index optimum)))\n (when (>= pos start)\n (unless (funcall predicate optimum (funcall key x))\n (setq optimum (funcall key x)\n index pos)))\n (incf pos))))\n (vector\n (let ((end (or end (length sequence))))\n (unless (<= start end)\n (error \"Can't find optimal value in null interval [~A, ~A)\" start end))\n (let ((optimum (funcall key (aref sequence 0)))\n (index 0))\n (dotimes (i (length sequence) (values index optimum))\n (unless (funcall predicate optimum (funcall key (aref sequence i)))\n (setq optimum (aref sequence i)\n index i))))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defconstant +eps+ 1d-10)\n\n(defun main ()\n (declare #.OPT)\n (let* ((init-x (float (read) 1d0))\n (init-y (float (read) 1d0))\n (goal-x (float (read) 1d0))\n (goal-y (float (read) 1d0))\n (n (read))\n (xs (make-array (+ n 2) :element-type 'double-float))\n (ys (make-array (+ n 2) :element-type 'double-float))\n (rs (make-array (+ n 2) :element-type 'double-float :initial-element 0d0))\n (init n)\n (goal (+ 1 n))\n (q (loop for i below (+ n 2) collect i))\n (dists (make-array (+ n 2) :element-type 'double-float :initial-element most-positive-double-float)))\n (declare ((simple-array double-float (*)) dists)\n (list q)\n (uint16 n))\n (dotimes (i n)\n (setf (aref xs i) (float (read-fixnum) 1d0)\n (aref ys i) (float (read-fixnum) 1d0)\n (aref rs i) (float (read-fixnum) 1d0)))\n (setf (aref xs init) init-x\n (aref ys init) init-y\n (aref xs goal) goal-x\n (aref ys goal) goal-y\n (aref dists init) 0d0)\n (loop until (null q)\n for i = (find-argopt q #'< :key (lambda (v) (aref dists v)))\n for v = (nth i q)\n for x0 = (aref xs v)\n for y0 = (aref ys v)\n for r0 = (aref rs v)\n do (setf q (delete v q :count 1))\n (dotimes (next (+ n 2))\n (let* ((x1 (aref xs next))\n (y1 (aref ys next))\n (r1 (aref rs next))\n (delta (max 0d0 (- (sqrt (+ (expt (- x0 x1) 2)\n (expt (- y0 y1) 2)))\n r0 r1))))\n (when (< (+ (aref dists v) delta +eps+)\n (aref dists next))\n (setf (aref dists next)\n (+ (aref dists v) delta))))))\n (println (aref dists goal))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nOn the xy-plane, Snuke is going to travel from the point (x_s, y_s) to the point (x_t, y_t).\nHe can move in arbitrary directions with speed 1.\nHere, we will consider him as a point without size.\n\nThere are N circular barriers deployed on the plane.\nThe center and the radius of the i-th barrier are (x_i, y_i) and r_i, respectively.\nThe barriers may overlap or contain each other.\n\nA point on the plane is exposed to cosmic rays if the point is not within any of the barriers.\n\nSnuke wants to avoid exposure to cosmic rays as much as possible during the travel.\nFind the minimum possible duration of time he is exposed to cosmic rays during the travel.\n\nConstraints\n\nAll input values are integers.\n\n-10^9 ≤ x_s, y_s, x_t, y_t ≤ 10^9\n\n(x_s, y_s) ≠ (x_t, y_t)\n\n1≤N≤1,000\n\n-10^9 ≤ x_i, y_i ≤ 10^9\n\n1 ≤ r_i ≤ 10^9\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx_s y_s x_t y_t\nN\nx_1 y_1 r_1\nx_2 y_2 r_2\n:\nx_N y_N r_N\n\nOutput\n\nPrint the minimum possible duration of time Snuke is exposed to cosmic rays during the travel.\nThe output is considered correct if the absolute or relative error is at most 10^{-9}.\n\nSample Input 1\n\n-2 -2 2 2\n1\n0 0 1\n\nSample Output 1\n\n3.6568542495\n\nAn optimal route is as follows:\n\nSample Input 2\n\n-2 0 2 0\n2\n-1 0 2\n1 0 2\n\nSample Output 2\n\n0.0000000000\n\nAn optimal route is as follows:\n\nSample Input 3\n\n4 -2 -2 4\n3\n0 0 2\n4 0 1\n0 4 1\n\nSample Output 3\n\n4.0000000000\n\nAn optimal route is as follows:", "sample_input": "-2 -2 2 2\n1\n0 0 1\n"}, "reference_outputs": ["3.6568542495\n"], "source_document_id": "p03866", "source_text": "Score : 600 points\n\nProblem Statement\n\nOn the xy-plane, Snuke is going to travel from the point (x_s, y_s) to the point (x_t, y_t).\nHe can move in arbitrary directions with speed 1.\nHere, we will consider him as a point without size.\n\nThere are N circular barriers deployed on the plane.\nThe center and the radius of the i-th barrier are (x_i, y_i) and r_i, respectively.\nThe barriers may overlap or contain each other.\n\nA point on the plane is exposed to cosmic rays if the point is not within any of the barriers.\n\nSnuke wants to avoid exposure to cosmic rays as much as possible during the travel.\nFind the minimum possible duration of time he is exposed to cosmic rays during the travel.\n\nConstraints\n\nAll input values are integers.\n\n-10^9 ≤ x_s, y_s, x_t, y_t ≤ 10^9\n\n(x_s, y_s) ≠ (x_t, y_t)\n\n1≤N≤1,000\n\n-10^9 ≤ x_i, y_i ≤ 10^9\n\n1 ≤ r_i ≤ 10^9\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx_s y_s x_t y_t\nN\nx_1 y_1 r_1\nx_2 y_2 r_2\n:\nx_N y_N r_N\n\nOutput\n\nPrint the minimum possible duration of time Snuke is exposed to cosmic rays during the travel.\nThe output is considered correct if the absolute or relative error is at most 10^{-9}.\n\nSample Input 1\n\n-2 -2 2 2\n1\n0 0 1\n\nSample Output 1\n\n3.6568542495\n\nAn optimal route is as follows:\n\nSample Input 2\n\n-2 0 2 0\n2\n-1 0 2\n1 0 2\n\nSample Output 2\n\n0.0000000000\n\nAn optimal route is as follows:\n\nSample Input 3\n\n4 -2 -2 4\n3\n0 0 2\n4 0 1\n0 4 1\n\nSample Output 3\n\n4.0000000000\n\nAn optimal route is as follows:", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5749, "cpu_time_ms": 256, "memory_kb": 27108}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s681615007", "group_id": "codeNet:p03866", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; unfinished.\n\n(declaim (inline find-argopt))\n(defun find-argopt (sequence predicate &key (start 0) end (key #'identity))\n \"Returns an index x that satisfies (NOT (FUNCALL PREDICATE SEQUENCE[y]\nSEQUENCE[x])) (i.e. SEQUENCE[x] >= SEQUENCE[y]) for all the indices y and\nreturns SEQUENCE[x] as the second value.\"\n (declare ((or null (integer 0 #.most-positive-fixnum)) end)\n ((integer 0 #.most-positive-fixnum) start)\n (function predicate)\n (sequence sequence))\n (etypecase sequence\n (list\n (let ((end (or end most-positive-fixnum))\n (optimum (funcall key (car sequence)))\n (index 0)\n (pos 0))\n (dolist (x sequence (values index optimum))\n (when (>= pos end)\n (return (values index optimum)))\n (when (>= pos start)\n (unless (funcall predicate optimum (funcall key x))\n (setq optimum (funcall key x)\n index pos)))\n (incf pos))))\n (vector\n (let ((end (or end (length sequence))))\n (unless (<= start end)\n (error \"Can't find optimal value in null interval [~A, ~A)\" start end))\n (let ((optimum (funcall key (aref sequence 0)))\n (index 0))\n (dotimes (i (length sequence) (values index optimum))\n (unless (funcall predicate optimum (funcall key (aref sequence i)))\n (setq optimum (aref sequence i)\n index i))))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defconstant +eps+ 1d-10)\n\n(defun main ()\n (let* ((init-x (float (read) 1d0))\n (init-y (float (read) 1d0))\n (goal-x (float (read) 1d0))\n (goal-y (float (read) 1d0))\n (n (read))\n (xs (make-array (+ n 2) :element-type 'double-float))\n (ys (make-array (+ n 2) :element-type 'double-float))\n (rs (make-array (+ n 2) :element-type 'double-float :initial-element 0d0))\n (init n)\n (goal (+ 1 n))\n (q (loop for i below (+ n 2) collect i))\n (dists (make-array (+ n 2) :element-type 'double-float :initial-element most-positive-double-float)))\n (declare ((simple-array double-float (*)) dists)\n (list q)\n (uint16 n))\n (dotimes (i n)\n (setf (aref xs i) (float (read-fixnum) 1d0)\n (aref ys i) (float (read-fixnum) 1d0)\n (aref rs i) (float (read-fixnum) 1d0)))\n (setf (aref xs init) init-x\n (aref ys init) init-y\n (aref xs goal) goal-x\n (aref ys goal) goal-y\n (aref dists init) 0d0)\n (loop until (null q)\n for i = (find-argopt q #'< :key (lambda (v) (aref dists v)))\n for v = (nth i q)\n for x0 = (aref xs v)\n for y0 = (aref ys v)\n for r0 = (aref rs v)\n do (setf q (delete v q :count 1))\n (dotimes (next (+ n 2))\n (let* ((x1 (aref xs next))\n (y1 (aref ys next))\n (r1 (aref rs next))\n (delta (max 0d0 (- (sqrt (+ (expt (- x0 x1) 2)\n (expt (- y0 y1) 2)))\n r0 r1))))\n (when (< (+ (aref dists v) delta +eps+)\n (aref dists next))\n (setf (aref dists next)\n (+ (aref dists v) delta))))))\n (println (aref dists goal))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1566549454, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03866.html", "problem_id": "p03866", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03866/input.txt", "sample_output_relpath": "derived/input_output/data/p03866/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03866/Lisp/s681615007.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s681615007", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3.6568542495\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; unfinished.\n\n(declaim (inline find-argopt))\n(defun find-argopt (sequence predicate &key (start 0) end (key #'identity))\n \"Returns an index x that satisfies (NOT (FUNCALL PREDICATE SEQUENCE[y]\nSEQUENCE[x])) (i.e. SEQUENCE[x] >= SEQUENCE[y]) for all the indices y and\nreturns SEQUENCE[x] as the second value.\"\n (declare ((or null (integer 0 #.most-positive-fixnum)) end)\n ((integer 0 #.most-positive-fixnum) start)\n (function predicate)\n (sequence sequence))\n (etypecase sequence\n (list\n (let ((end (or end most-positive-fixnum))\n (optimum (funcall key (car sequence)))\n (index 0)\n (pos 0))\n (dolist (x sequence (values index optimum))\n (when (>= pos end)\n (return (values index optimum)))\n (when (>= pos start)\n (unless (funcall predicate optimum (funcall key x))\n (setq optimum (funcall key x)\n index pos)))\n (incf pos))))\n (vector\n (let ((end (or end (length sequence))))\n (unless (<= start end)\n (error \"Can't find optimal value in null interval [~A, ~A)\" start end))\n (let ((optimum (funcall key (aref sequence 0)))\n (index 0))\n (dotimes (i (length sequence) (values index optimum))\n (unless (funcall predicate optimum (funcall key (aref sequence i)))\n (setq optimum (aref sequence i)\n index i))))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defconstant +eps+ 1d-10)\n\n(defun main ()\n (let* ((init-x (float (read) 1d0))\n (init-y (float (read) 1d0))\n (goal-x (float (read) 1d0))\n (goal-y (float (read) 1d0))\n (n (read))\n (xs (make-array (+ n 2) :element-type 'double-float))\n (ys (make-array (+ n 2) :element-type 'double-float))\n (rs (make-array (+ n 2) :element-type 'double-float :initial-element 0d0))\n (init n)\n (goal (+ 1 n))\n (q (loop for i below (+ n 2) collect i))\n (dists (make-array (+ n 2) :element-type 'double-float :initial-element most-positive-double-float)))\n (declare ((simple-array double-float (*)) dists)\n (list q)\n (uint16 n))\n (dotimes (i n)\n (setf (aref xs i) (float (read-fixnum) 1d0)\n (aref ys i) (float (read-fixnum) 1d0)\n (aref rs i) (float (read-fixnum) 1d0)))\n (setf (aref xs init) init-x\n (aref ys init) init-y\n (aref xs goal) goal-x\n (aref ys goal) goal-y\n (aref dists init) 0d0)\n (loop until (null q)\n for i = (find-argopt q #'< :key (lambda (v) (aref dists v)))\n for v = (nth i q)\n for x0 = (aref xs v)\n for y0 = (aref ys v)\n for r0 = (aref rs v)\n do (setf q (delete v q :count 1))\n (dotimes (next (+ n 2))\n (let* ((x1 (aref xs next))\n (y1 (aref ys next))\n (r1 (aref rs next))\n (delta (max 0d0 (- (sqrt (+ (expt (- x0 x1) 2)\n (expt (- y0 y1) 2)))\n r0 r1))))\n (when (< (+ (aref dists v) delta +eps+)\n (aref dists next))\n (setf (aref dists next)\n (+ (aref dists v) delta))))))\n (println (aref dists goal))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nOn the xy-plane, Snuke is going to travel from the point (x_s, y_s) to the point (x_t, y_t).\nHe can move in arbitrary directions with speed 1.\nHere, we will consider him as a point without size.\n\nThere are N circular barriers deployed on the plane.\nThe center and the radius of the i-th barrier are (x_i, y_i) and r_i, respectively.\nThe barriers may overlap or contain each other.\n\nA point on the plane is exposed to cosmic rays if the point is not within any of the barriers.\n\nSnuke wants to avoid exposure to cosmic rays as much as possible during the travel.\nFind the minimum possible duration of time he is exposed to cosmic rays during the travel.\n\nConstraints\n\nAll input values are integers.\n\n-10^9 ≤ x_s, y_s, x_t, y_t ≤ 10^9\n\n(x_s, y_s) ≠ (x_t, y_t)\n\n1≤N≤1,000\n\n-10^9 ≤ x_i, y_i ≤ 10^9\n\n1 ≤ r_i ≤ 10^9\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx_s y_s x_t y_t\nN\nx_1 y_1 r_1\nx_2 y_2 r_2\n:\nx_N y_N r_N\n\nOutput\n\nPrint the minimum possible duration of time Snuke is exposed to cosmic rays during the travel.\nThe output is considered correct if the absolute or relative error is at most 10^{-9}.\n\nSample Input 1\n\n-2 -2 2 2\n1\n0 0 1\n\nSample Output 1\n\n3.6568542495\n\nAn optimal route is as follows:\n\nSample Input 2\n\n-2 0 2 0\n2\n-1 0 2\n1 0 2\n\nSample Output 2\n\n0.0000000000\n\nAn optimal route is as follows:\n\nSample Input 3\n\n4 -2 -2 4\n3\n0 0 2\n4 0 1\n0 4 1\n\nSample Output 3\n\n4.0000000000\n\nAn optimal route is as follows:", "sample_input": "-2 -2 2 2\n1\n0 0 1\n"}, "reference_outputs": ["3.6568542495\n"], "source_document_id": "p03866", "source_text": "Score : 600 points\n\nProblem Statement\n\nOn the xy-plane, Snuke is going to travel from the point (x_s, y_s) to the point (x_t, y_t).\nHe can move in arbitrary directions with speed 1.\nHere, we will consider him as a point without size.\n\nThere are N circular barriers deployed on the plane.\nThe center and the radius of the i-th barrier are (x_i, y_i) and r_i, respectively.\nThe barriers may overlap or contain each other.\n\nA point on the plane is exposed to cosmic rays if the point is not within any of the barriers.\n\nSnuke wants to avoid exposure to cosmic rays as much as possible during the travel.\nFind the minimum possible duration of time he is exposed to cosmic rays during the travel.\n\nConstraints\n\nAll input values are integers.\n\n-10^9 ≤ x_s, y_s, x_t, y_t ≤ 10^9\n\n(x_s, y_s) ≠ (x_t, y_t)\n\n1≤N≤1,000\n\n-10^9 ≤ x_i, y_i ≤ 10^9\n\n1 ≤ r_i ≤ 10^9\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx_s y_s x_t y_t\nN\nx_1 y_1 r_1\nx_2 y_2 r_2\n:\nx_N y_N r_N\n\nOutput\n\nPrint the minimum possible duration of time Snuke is exposed to cosmic rays during the travel.\nThe output is considered correct if the absolute or relative error is at most 10^{-9}.\n\nSample Input 1\n\n-2 -2 2 2\n1\n0 0 1\n\nSample Output 1\n\n3.6568542495\n\nAn optimal route is as follows:\n\nSample Input 2\n\n-2 0 2 0\n2\n-1 0 2\n1 0 2\n\nSample Output 2\n\n0.0000000000\n\nAn optimal route is as follows:\n\nSample Input 3\n\n4 -2 -2 4\n3\n0 0 2\n4 0 1\n0 4 1\n\nSample Output 3\n\n4.0000000000\n\nAn optimal route is as follows:", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5713, "cpu_time_ms": 103, "memory_kb": 17252}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s784482229", "group_id": "codeNet:p03866", "input_text": "(declaim (optimize (speed 3) (safety 0) (debug 0))\n\t (inline sqr dist))\n\n(defun sqr (x) (* x x))\n\n(defun dist (m n)\n (destructuring-bind (x1 y1 r1) m\n (destructuring-bind (x2 y2 r2) n\n (max 0 (- (sqrt (coerce (+ (sqr (- x1 x2)) (sqr (- y1 y2)))\n\t\t\t 'double-float)) r1 r2)))))\n\n(defun main ()\n (let ((nodes `((,(read) ,(read) 0) (,(read) ,(read) 0)))\n\t(n (read)))\n (dotimes (_ n) (push `(,(read) ,(read) ,(read)) nodes))\n (setf nodes (nreverse nodes))\n\n (let* ((s (+ n 2))\n\t (table (make-array (list s s) :initial-element 0)))\n (loop for i from 0\n\t for x in nodes\n\t do (loop for j from 0\n\t for y in nodes\n\t unless (= i j)\n\t do (setf (aref table i j) (dist y x))))\n (dotimes (k s)\n\t(dotimes (i s)\n\t (dotimes (j s)\n\t (let ((cand (+ (aref table i k)\n\t\t\t (aref table k j))))\n\t (when (> (aref table i j) cand)\n\t\t(setf (aref table i j)\n\t\t cand))))))\n (format t \"~,10f~%\" (aref table 0 1)))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1480964711, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03866.html", "problem_id": "p03866", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03866/input.txt", "sample_output_relpath": "derived/input_output/data/p03866/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03866/Lisp/s784482229.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s784482229", "user_id": "u693548378"}, "prompt_components": {"gold_output": "3.6568542495\n", "input_to_evaluate": "(declaim (optimize (speed 3) (safety 0) (debug 0))\n\t (inline sqr dist))\n\n(defun sqr (x) (* x x))\n\n(defun dist (m n)\n (destructuring-bind (x1 y1 r1) m\n (destructuring-bind (x2 y2 r2) n\n (max 0 (- (sqrt (coerce (+ (sqr (- x1 x2)) (sqr (- y1 y2)))\n\t\t\t 'double-float)) r1 r2)))))\n\n(defun main ()\n (let ((nodes `((,(read) ,(read) 0) (,(read) ,(read) 0)))\n\t(n (read)))\n (dotimes (_ n) (push `(,(read) ,(read) ,(read)) nodes))\n (setf nodes (nreverse nodes))\n\n (let* ((s (+ n 2))\n\t (table (make-array (list s s) :initial-element 0)))\n (loop for i from 0\n\t for x in nodes\n\t do (loop for j from 0\n\t for y in nodes\n\t unless (= i j)\n\t do (setf (aref table i j) (dist y x))))\n (dotimes (k s)\n\t(dotimes (i s)\n\t (dotimes (j s)\n\t (let ((cand (+ (aref table i k)\n\t\t\t (aref table k j))))\n\t (when (> (aref table i j) cand)\n\t\t(setf (aref table i j)\n\t\t cand))))))\n (format t \"~,10f~%\" (aref table 0 1)))))\n\n(main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nOn the xy-plane, Snuke is going to travel from the point (x_s, y_s) to the point (x_t, y_t).\nHe can move in arbitrary directions with speed 1.\nHere, we will consider him as a point without size.\n\nThere are N circular barriers deployed on the plane.\nThe center and the radius of the i-th barrier are (x_i, y_i) and r_i, respectively.\nThe barriers may overlap or contain each other.\n\nA point on the plane is exposed to cosmic rays if the point is not within any of the barriers.\n\nSnuke wants to avoid exposure to cosmic rays as much as possible during the travel.\nFind the minimum possible duration of time he is exposed to cosmic rays during the travel.\n\nConstraints\n\nAll input values are integers.\n\n-10^9 ≤ x_s, y_s, x_t, y_t ≤ 10^9\n\n(x_s, y_s) ≠ (x_t, y_t)\n\n1≤N≤1,000\n\n-10^9 ≤ x_i, y_i ≤ 10^9\n\n1 ≤ r_i ≤ 10^9\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx_s y_s x_t y_t\nN\nx_1 y_1 r_1\nx_2 y_2 r_2\n:\nx_N y_N r_N\n\nOutput\n\nPrint the minimum possible duration of time Snuke is exposed to cosmic rays during the travel.\nThe output is considered correct if the absolute or relative error is at most 10^{-9}.\n\nSample Input 1\n\n-2 -2 2 2\n1\n0 0 1\n\nSample Output 1\n\n3.6568542495\n\nAn optimal route is as follows:\n\nSample Input 2\n\n-2 0 2 0\n2\n-1 0 2\n1 0 2\n\nSample Output 2\n\n0.0000000000\n\nAn optimal route is as follows:\n\nSample Input 3\n\n4 -2 -2 4\n3\n0 0 2\n4 0 1\n0 4 1\n\nSample Output 3\n\n4.0000000000\n\nAn optimal route is as follows:", "sample_input": "-2 -2 2 2\n1\n0 0 1\n"}, "reference_outputs": ["3.6568542495\n"], "source_document_id": "p03866", "source_text": "Score : 600 points\n\nProblem Statement\n\nOn the xy-plane, Snuke is going to travel from the point (x_s, y_s) to the point (x_t, y_t).\nHe can move in arbitrary directions with speed 1.\nHere, we will consider him as a point without size.\n\nThere are N circular barriers deployed on the plane.\nThe center and the radius of the i-th barrier are (x_i, y_i) and r_i, respectively.\nThe barriers may overlap or contain each other.\n\nA point on the plane is exposed to cosmic rays if the point is not within any of the barriers.\n\nSnuke wants to avoid exposure to cosmic rays as much as possible during the travel.\nFind the minimum possible duration of time he is exposed to cosmic rays during the travel.\n\nConstraints\n\nAll input values are integers.\n\n-10^9 ≤ x_s, y_s, x_t, y_t ≤ 10^9\n\n(x_s, y_s) ≠ (x_t, y_t)\n\n1≤N≤1,000\n\n-10^9 ≤ x_i, y_i ≤ 10^9\n\n1 ≤ r_i ≤ 10^9\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nx_s y_s x_t y_t\nN\nx_1 y_1 r_1\nx_2 y_2 r_2\n:\nx_N y_N r_N\n\nOutput\n\nPrint the minimum possible duration of time Snuke is exposed to cosmic rays during the travel.\nThe output is considered correct if the absolute or relative error is at most 10^{-9}.\n\nSample Input 1\n\n-2 -2 2 2\n1\n0 0 1\n\nSample Output 1\n\n3.6568542495\n\nAn optimal route is as follows:\n\nSample Input 2\n\n-2 0 2 0\n2\n-1 0 2\n1 0 2\n\nSample Output 2\n\n0.0000000000\n\nAn optimal route is as follows:\n\nSample Input 3\n\n4 -2 -2 4\n3\n0 0 2\n4 0 1\n0 4 1\n\nSample Output 3\n\n4.0000000000\n\nAn optimal route is as follows:", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 968, "cpu_time_ms": 2117, "memory_kb": 115536}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s206361005", "group_id": "codeNet:p03878", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Quicksort\n;;;\n\n;; Note: Not randomized; the worst case time complexity is O(n^2).\n\n(declaim (inline %median3))\n(defun %median3 (x y z order)\n (if (funcall order x y)\n (if (funcall order y z)\n y\n (if (funcall order z x)\n x\n z))\n (if (funcall order z y)\n y\n (if (funcall order x z)\n x\n z))))\n\n(declaim (inline quicksort!))\n(defun quicksort! (vector order &key (start 0) end)\n \"Destructively sorts VECTOR w.r.t. ORDER\"\n (declare (vector vector))\n (unless end\n (setq end (length vector)))\n (assert (<= 0 start end))\n (labels\n ((recur (left right)\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3 (aref vector l)\n (aref vector (ash (+ l r) -1))\n (aref vector r)\n order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall order (aref vector l) pivot)\n do (incf l 1))\n (loop while (funcall order pivot (aref vector r))\n do (decf r 1))\n (when (>= l r)\n (return))\n (rotatef (aref vector l) (aref vector r))\n (incf l 1)\n (decf r 1))\n (recur left (- l 1))\n (recur (+ r 1) right)))))\n (recur start (- end 1))\n vector))\n\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(declaim (inline pophash))\n(defun pophash (hash-table)\n (maphash (lambda (key _)\n (declare (ignore _))\n (remhash key hash-table)\n (return-from pophash key))\n hash-table))\n\n(declaim (inline uint32<))\n(defun uint32< (x y)\n (< (the uint32 x) (the uint32 y)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n (bs (make-array n :element-type 'uint31))\n (res 1))\n (declare (uint31 n res))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i n)\n (setf (aref bs i) (read-fixnum)))\n (quicksort! as #'<)\n (quicksort! bs #'<)\n (let ((anum 0)\n (bnum 0))\n (declare (uint31 anum bnum))\n (sb-int:named-let recur ((apos 0) (bpos 0))\n (declare (uint31 apos bpos))\n (cond ((and (= apos n) (= bpos n)))\n ((= apos n)\n (mulfmod res anum)\n (decf anum)\n (recur apos (+ 1 bpos)))\n ((= bpos n)\n (mulfmod res bnum)\n (decf bnum)\n (recur (+ 1 apos) bpos))\n ((uint32< (aref as apos) (aref bs bpos))\n (if (zerop bnum)\n (incf anum)\n (progn (mulfmod res bnum)\n (decf bnum)))\n (recur (+ 1 apos) bpos))\n (t\n (if (zerop anum)\n (incf bnum)\n (progn (mulfmod res anum)\n (decf anum)))\n (recur apos (+ 1 bpos))))))\n (println res)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n0\n10\n20\n30\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n3\n10\n8\n7\n12\n5\n\"\n \"1\n\")))\n", "language": "Lisp", "metadata": {"date": 1572142639, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03878.html", "problem_id": "p03878", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03878/input.txt", "sample_output_relpath": "derived/input_output/data/p03878/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03878/Lisp/s206361005.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s206361005", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Quicksort\n;;;\n\n;; Note: Not randomized; the worst case time complexity is O(n^2).\n\n(declaim (inline %median3))\n(defun %median3 (x y z order)\n (if (funcall order x y)\n (if (funcall order y z)\n y\n (if (funcall order z x)\n x\n z))\n (if (funcall order z y)\n y\n (if (funcall order x z)\n x\n z))))\n\n(declaim (inline quicksort!))\n(defun quicksort! (vector order &key (start 0) end)\n \"Destructively sorts VECTOR w.r.t. ORDER\"\n (declare (vector vector))\n (unless end\n (setq end (length vector)))\n (assert (<= 0 start end))\n (labels\n ((recur (left right)\n (when (< left right)\n (let* ((l left)\n (r right)\n (pivot (%median3 (aref vector l)\n (aref vector (ash (+ l r) -1))\n (aref vector r)\n order)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (funcall order (aref vector l) pivot)\n do (incf l 1))\n (loop while (funcall order pivot (aref vector r))\n do (decf r 1))\n (when (>= l r)\n (return))\n (rotatef (aref vector l) (aref vector r))\n (incf l 1)\n (decf r 1))\n (recur left (- l 1))\n (recur (+ r 1) right)))))\n (recur start (- end 1))\n vector))\n\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(declaim (inline pophash))\n(defun pophash (hash-table)\n (maphash (lambda (key _)\n (declare (ignore _))\n (remhash key hash-table)\n (return-from pophash key))\n hash-table))\n\n(declaim (inline uint32<))\n(defun uint32< (x y)\n (< (the uint32 x) (the uint32 y)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint31))\n (bs (make-array n :element-type 'uint31))\n (res 1))\n (declare (uint31 n res))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i n)\n (setf (aref bs i) (read-fixnum)))\n (quicksort! as #'<)\n (quicksort! bs #'<)\n (let ((anum 0)\n (bnum 0))\n (declare (uint31 anum bnum))\n (sb-int:named-let recur ((apos 0) (bpos 0))\n (declare (uint31 apos bpos))\n (cond ((and (= apos n) (= bpos n)))\n ((= apos n)\n (mulfmod res anum)\n (decf anum)\n (recur apos (+ 1 bpos)))\n ((= bpos n)\n (mulfmod res bnum)\n (decf bnum)\n (recur (+ 1 apos) bpos))\n ((uint32< (aref as apos) (aref bs bpos))\n (if (zerop bnum)\n (incf anum)\n (progn (mulfmod res bnum)\n (decf bnum)))\n (recur (+ 1 apos) bpos))\n (t\n (if (zerop anum)\n (incf bnum)\n (progn (mulfmod res anum)\n (decf anum)))\n (recur apos (+ 1 bpos))))))\n (println res)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n0\n10\n20\n30\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n3\n10\n8\n7\n12\n5\n\"\n \"1\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\n#nck {\nwidth: 30px;\nheight: auto;\n}\n\nThere are N computers and N sockets in a one-dimensional world.\nThe coordinate of the i-th computer is a_i, and the coordinate of the i-th socket is b_i.\nIt is guaranteed that these 2N coordinates are pairwise distinct.\n\nSnuke wants to connect each computer to a socket using a cable.\nEach socket can be connected to only one computer.\n\nIn how many ways can he minimize the total length of the cables?\nCompute the answer modulo 10^9+7.\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n0 ≤ a_i, b_i ≤ 10^9\n\nThe coordinates are integers.\n\nThe coordinates are pairwise distinct.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\na_1\n:\na_N\nb_1\n:\nb_N\n\nOutput\n\nPrint the number of ways to minimize the total length of the cables, modulo 10^9+7.\n\nSample Input 1\n\n2\n0\n10\n20\n30\n\nSample Output 1\n\n2\n\nThere are two optimal connections: 0-20, 10-30 and 0-30, 10-20.\nIn both connections the total length of the cables is 40.\n\nSample Input 2\n\n3\n3\n10\n8\n7\n12\n5\n\nSample Output 2\n\n1", "sample_input": "2\n0\n10\n20\n30\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03878", "source_text": "Score : 500 points\n\nProblem Statement\n\n#nck {\nwidth: 30px;\nheight: auto;\n}\n\nThere are N computers and N sockets in a one-dimensional world.\nThe coordinate of the i-th computer is a_i, and the coordinate of the i-th socket is b_i.\nIt is guaranteed that these 2N coordinates are pairwise distinct.\n\nSnuke wants to connect each computer to a socket using a cable.\nEach socket can be connected to only one computer.\n\nIn how many ways can he minimize the total length of the cables?\nCompute the answer modulo 10^9+7.\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n0 ≤ a_i, b_i ≤ 10^9\n\nThe coordinates are integers.\n\nThe coordinates are pairwise distinct.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\na_1\n:\na_N\nb_1\n:\nb_N\n\nOutput\n\nPrint the number of ways to minimize the total length of the cables, modulo 10^9+7.\n\nSample Input 1\n\n2\n0\n10\n20\n30\n\nSample Output 1\n\n2\n\nThere are two optimal connections: 0-20, 10-30 and 0-30, 10-20.\nIn both connections the total length of the cables is 40.\n\nSample Input 2\n\n3\n3\n10\n8\n7\n12\n5\n\nSample Output 2\n\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8640, "cpu_time_ms": 177, "memory_kb": 25960}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s805489892", "group_id": "codeNet:p03878", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(declaim (inline pophash))\n(defun pophash (hash-table)\n (maphash (lambda (key _)\n (declare (ignore _))\n (remhash key hash-table)\n (return-from pophash key))\n hash-table))\n\n(declaim (inline hash-table-empty-p))\n(defun hash-table-empty-p (hash-table)\n (zerop (hash-table-count hash-table)))\n \n(declaim (inline uint32<))\n(defun uint32< (x y)\n (< (the uint32 x) (the uint32 y)))\n \n(defun main ()\n (declare #.OPT\n (inline sb-impl::stable-sort-list))\n (let* ((n (read))\n (as (loop repeat n collect (read-fixnum)))\n (bs (loop repeat n collect (read-fixnum)))\n (res 1))\n (declare (uint31 n res))\n (setq as (sb-impl::stable-sort-list as #'uint32< #'identity)\n bs (sb-impl::stable-sort-list bs #'uint32< #'identity))\n (let ((set-a (make-array n :fill-pointer 0 :element-type 'uint31))\n (set-b (make-array n :fill-pointer 0 :element-type 'uint31)))\n (sb-int:named-let recur ((as as) (bs bs))\n (cond ((and (null as) (null bs)))\n ((null as)\n (mulfmod res (the uint31 (length set-a)))\n (vector-pop set-a)\n (recur as (cdr bs)))\n ((null bs)\n (mulfmod res (the uint31 (length set-b)))\n (vector-pop set-b)\n (recur (cdr as) bs))\n ((uint32< (car as) (car bs))\n (if (zerop (length set-b))\n (vector-push (car as) set-a)\n (progn (mulfmod res (the uint31 (length set-b)))\n (vector-pop set-b)))\n (recur (cdr as) bs))\n (t\n (if (zerop (length set-a))\n (vector-push (car bs) set-b)\n (progn (mulfmod res (the uint31 (length set-a)))\n (vector-pop set-a)))\n (recur as (cdr bs))))))\n (println res)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n0\n10\n20\n30\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n3\n10\n8\n7\n12\n5\n\"\n \"1\n\")))\n", "language": "Lisp", "metadata": {"date": 1572120354, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03878.html", "problem_id": "p03878", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03878/input.txt", "sample_output_relpath": "derived/input_output/data/p03878/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03878/Lisp/s805489892.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s805489892", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(declaim (inline pophash))\n(defun pophash (hash-table)\n (maphash (lambda (key _)\n (declare (ignore _))\n (remhash key hash-table)\n (return-from pophash key))\n hash-table))\n\n(declaim (inline hash-table-empty-p))\n(defun hash-table-empty-p (hash-table)\n (zerop (hash-table-count hash-table)))\n \n(declaim (inline uint32<))\n(defun uint32< (x y)\n (< (the uint32 x) (the uint32 y)))\n \n(defun main ()\n (declare #.OPT\n (inline sb-impl::stable-sort-list))\n (let* ((n (read))\n (as (loop repeat n collect (read-fixnum)))\n (bs (loop repeat n collect (read-fixnum)))\n (res 1))\n (declare (uint31 n res))\n (setq as (sb-impl::stable-sort-list as #'uint32< #'identity)\n bs (sb-impl::stable-sort-list bs #'uint32< #'identity))\n (let ((set-a (make-array n :fill-pointer 0 :element-type 'uint31))\n (set-b (make-array n :fill-pointer 0 :element-type 'uint31)))\n (sb-int:named-let recur ((as as) (bs bs))\n (cond ((and (null as) (null bs)))\n ((null as)\n (mulfmod res (the uint31 (length set-a)))\n (vector-pop set-a)\n (recur as (cdr bs)))\n ((null bs)\n (mulfmod res (the uint31 (length set-b)))\n (vector-pop set-b)\n (recur (cdr as) bs))\n ((uint32< (car as) (car bs))\n (if (zerop (length set-b))\n (vector-push (car as) set-a)\n (progn (mulfmod res (the uint31 (length set-b)))\n (vector-pop set-b)))\n (recur (cdr as) bs))\n (t\n (if (zerop (length set-a))\n (vector-push (car bs) set-b)\n (progn (mulfmod res (the uint31 (length set-a)))\n (vector-pop set-a)))\n (recur as (cdr bs))))))\n (println res)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n0\n10\n20\n30\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n3\n10\n8\n7\n12\n5\n\"\n \"1\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\n#nck {\nwidth: 30px;\nheight: auto;\n}\n\nThere are N computers and N sockets in a one-dimensional world.\nThe coordinate of the i-th computer is a_i, and the coordinate of the i-th socket is b_i.\nIt is guaranteed that these 2N coordinates are pairwise distinct.\n\nSnuke wants to connect each computer to a socket using a cable.\nEach socket can be connected to only one computer.\n\nIn how many ways can he minimize the total length of the cables?\nCompute the answer modulo 10^9+7.\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n0 ≤ a_i, b_i ≤ 10^9\n\nThe coordinates are integers.\n\nThe coordinates are pairwise distinct.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\na_1\n:\na_N\nb_1\n:\nb_N\n\nOutput\n\nPrint the number of ways to minimize the total length of the cables, modulo 10^9+7.\n\nSample Input 1\n\n2\n0\n10\n20\n30\n\nSample Output 1\n\n2\n\nThere are two optimal connections: 0-20, 10-30 and 0-30, 10-20.\nIn both connections the total length of the cables is 40.\n\nSample Input 2\n\n3\n3\n10\n8\n7\n12\n5\n\nSample Output 2\n\n1", "sample_input": "2\n0\n10\n20\n30\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03878", "source_text": "Score : 500 points\n\nProblem Statement\n\n#nck {\nwidth: 30px;\nheight: auto;\n}\n\nThere are N computers and N sockets in a one-dimensional world.\nThe coordinate of the i-th computer is a_i, and the coordinate of the i-th socket is b_i.\nIt is guaranteed that these 2N coordinates are pairwise distinct.\n\nSnuke wants to connect each computer to a socket using a cable.\nEach socket can be connected to only one computer.\n\nIn how many ways can he minimize the total length of the cables?\nCompute the answer modulo 10^9+7.\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n0 ≤ a_i, b_i ≤ 10^9\n\nThe coordinates are integers.\n\nThe coordinates are pairwise distinct.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\na_1\n:\na_N\nb_1\n:\nb_N\n\nOutput\n\nPrint the number of ways to minimize the total length of the cables, modulo 10^9+7.\n\nSample Input 1\n\n2\n0\n10\n20\n30\n\nSample Output 1\n\n2\n\nThere are two optimal connections: 0-20, 10-30 and 0-30, 10-20.\nIn both connections the total length of the cables is 40.\n\nSample Input 2\n\n3\n3\n10\n8\n7\n12\n5\n\nSample Output 2\n\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7402, "cpu_time_ms": 430, "memory_kb": 35172}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s491566440", "group_id": "codeNet:p03878", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\n\n;; TODO: non-global handling\n\n(defconstant +binom-size+ 510000)\n(defconstant +binom-mod+ #.(+ (expt 10 9) 7))\n\n(declaim ((simple-array (unsigned-byte 32) (*)) *fact* *fact-inv* *inv*))\n(defparameter *fact* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of factorials\")\n(defparameter *fact-inv* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of inverses of factorials\")\n(defparameter *inv* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of inverses of non-negative integers\")\n\n(defun initialize-binom ()\n (declare (optimize (speed 3) (safety 0)))\n (setf (aref *fact* 0) 1\n (aref *fact* 1) 1\n (aref *fact-inv* 0) 1\n (aref *fact-inv* 1) 1\n (aref *inv* 1) 1)\n (loop for i from 2 below +binom-size+\n do (setf (aref *fact* i) (mod (* i (aref *fact* (- i 1))) +binom-mod+)\n (aref *inv* i) (- +binom-mod+\n (mod (* (aref *inv* (rem +binom-mod+ i))\n (floor +binom-mod+ i))\n +binom-mod+))\n (aref *fact-inv* i) (mod (* (aref *inv* i)\n (aref *fact-inv* (- i 1)))\n +binom-mod+))))\n\n(initialize-binom)\n\n(declaim (inline binom))\n(defun binom (n k)\n \"Returns nCk.\"\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (mod (* (aref *fact* n)\n (mod (* (aref *fact-inv* k) (aref *fact-inv* (- n k))) +binom-mod+))\n +binom-mod+)))\n\n(declaim (inline perm))\n(defun perm (n k)\n \"Returns nPk.\"\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (mod (* (aref *fact* n) (aref *fact-inv* (- n k))) +binom-mod+)))\n\n;; TODO: compiler macro or source-transform\n(declaim (inline multinomial))\n(defun multinomial (&rest ks)\n \"Returns the multinomial coefficient K!/k_1!k_2!...k_n! for K = k_1 + k_2 +\n... + k_n. K must be equal to or smaller than\nMOST-POSITIVE-FIXNUM. (multinomial) returns 1.\"\n (let ((sum 0)\n (result 1))\n (declare ((integer 0 #.most-positive-fixnum) result sum))\n (dolist (k ks)\n (incf sum k)\n (setq result\n (mod (* result (aref *fact-inv* k)) +binom-mod+)))\n (mod (* result (aref *fact* sum)) +binom-mod+)))\n\n(declaim (inline catalan))\n(defun catalan (n)\n \"Returns the N-th Catalan number.\"\n (declare ((integer 0 #.most-positive-fixnum) n))\n (mod (* (aref *fact* (* 2 n))\n (mod (* (aref *fact-inv* (+ n 1))\n (aref *fact-inv* n))\n +binom-mod+))\n +binom-mod+))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(declaim (inline pophash))\n(defun pophash (hash-table)\n (maphash (lambda (key _)\n (declare (ignore _))\n (remhash key hash-table)\n (return-from pophash key))\n hash-table))\n\n(declaim (inline hash-table-empty-p))\n(defun hash-table-empty-p (hash-table)\n (zerop (hash-table-count hash-table)))\n \n(declaim (inline uint32<))\n(defun uint32< (x y)\n (< (the uint32 x) (the uint32 y)))\n \n(defun main ()\n (declare (inline sort))\n (let* ((n (read))\n (as (loop repeat n collect (read-fixnum)))\n (bs (loop repeat n collect (read-fixnum)))\n (res 1))\n (declare (uint31 n res))\n (setf as (sort as #'uint32<)\n bs (sort bs #'uint32<))\n (let ((table-a (make-hash-table :test #'eq))\n (table-b (make-hash-table :test #'eq)))\n (sb-int:named-let recur ((as as) (bs bs))\n (cond ((and (null as) (null bs)))\n ((null as)\n (mulfmod res (the uint31 (hash-table-count table-a)))\n (pophash table-a)\n (recur as (cdr bs)))\n ((null bs)\n (mulfmod res (the uint31 (hash-table-count table-b)))\n (pophash table-b)\n (recur (cdr as) bs))\n ((uint32< (car as) (car bs))\n (if (hash-table-empty-p table-b)\n (setf (gethash (car as) table-a) t)\n (progn (mulfmod res (the uint31 (hash-table-count table-b)))\n (pophash table-b)))\n (recur (cdr as) bs))\n (t\n (if (hash-table-empty-p table-a)\n (setf (gethash (car bs) table-b) t)\n (progn (mulfmod res (the uint31 (hash-table-count table-a)))\n (pophash table-a)))\n (recur as (cdr bs))))))\n (println res)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n0\n10\n20\n30\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n3\n10\n8\n7\n12\n5\n\"\n \"1\n\")))\n", "language": "Lisp", "metadata": {"date": 1572119550, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03878.html", "problem_id": "p03878", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03878/input.txt", "sample_output_relpath": "derived/input_output/data/p03878/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03878/Lisp/s491566440.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s491566440", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defmacro define-mod-operations (divisor)\n `(progn\n (defun mod* (&rest args)\n (reduce (lambda (x y) (mod (* x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod* (&rest args)\n (if (null args)\n 1\n (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))\n\n (defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))\n\n (sb-c:define-source-transform mod+ (&rest args)\n (if (null args)\n 0\n (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))\n\n (define-modify-macro incfmod (delta)\n (lambda (x y) (mod (+ x y) ,divisor)))\n\n (define-modify-macro decfmod (delta)\n (lambda (x y) (mod (- x y) ,divisor)))\n\n (define-modify-macro mulfmod (multiplier)\n (lambda (x y) (mod (* x y) ,divisor)))))\n\n;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\n\n;; TODO: non-global handling\n\n(defconstant +binom-size+ 510000)\n(defconstant +binom-mod+ #.(+ (expt 10 9) 7))\n\n(declaim ((simple-array (unsigned-byte 32) (*)) *fact* *fact-inv* *inv*))\n(defparameter *fact* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of factorials\")\n(defparameter *fact-inv* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of inverses of factorials\")\n(defparameter *inv* (make-array +binom-size+ :element-type '(unsigned-byte 32))\n \"table of inverses of non-negative integers\")\n\n(defun initialize-binom ()\n (declare (optimize (speed 3) (safety 0)))\n (setf (aref *fact* 0) 1\n (aref *fact* 1) 1\n (aref *fact-inv* 0) 1\n (aref *fact-inv* 1) 1\n (aref *inv* 1) 1)\n (loop for i from 2 below +binom-size+\n do (setf (aref *fact* i) (mod (* i (aref *fact* (- i 1))) +binom-mod+)\n (aref *inv* i) (- +binom-mod+\n (mod (* (aref *inv* (rem +binom-mod+ i))\n (floor +binom-mod+ i))\n +binom-mod+))\n (aref *fact-inv* i) (mod (* (aref *inv* i)\n (aref *fact-inv* (- i 1)))\n +binom-mod+))))\n\n(initialize-binom)\n\n(declaim (inline binom))\n(defun binom (n k)\n \"Returns nCk.\"\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (mod (* (aref *fact* n)\n (mod (* (aref *fact-inv* k) (aref *fact-inv* (- n k))) +binom-mod+))\n +binom-mod+)))\n\n(declaim (inline perm))\n(defun perm (n k)\n \"Returns nPk.\"\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (mod (* (aref *fact* n) (aref *fact-inv* (- n k))) +binom-mod+)))\n\n;; TODO: compiler macro or source-transform\n(declaim (inline multinomial))\n(defun multinomial (&rest ks)\n \"Returns the multinomial coefficient K!/k_1!k_2!...k_n! for K = k_1 + k_2 +\n... + k_n. K must be equal to or smaller than\nMOST-POSITIVE-FIXNUM. (multinomial) returns 1.\"\n (let ((sum 0)\n (result 1))\n (declare ((integer 0 #.most-positive-fixnum) result sum))\n (dolist (k ks)\n (incf sum k)\n (setq result\n (mod (* result (aref *fact-inv* k)) +binom-mod+)))\n (mod (* result (aref *fact* sum)) +binom-mod+)))\n\n(declaim (inline catalan))\n(defun catalan (n)\n \"Returns the N-th Catalan number.\"\n (declare ((integer 0 #.most-positive-fixnum) n))\n (mod (* (aref *fact* (* 2 n))\n (mod (* (aref *fact-inv* (+ n 1))\n (aref *fact-inv* n))\n +binom-mod+))\n +binom-mod+))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n\n(declaim (inline pophash))\n(defun pophash (hash-table)\n (maphash (lambda (key _)\n (declare (ignore _))\n (remhash key hash-table)\n (return-from pophash key))\n hash-table))\n\n(declaim (inline hash-table-empty-p))\n(defun hash-table-empty-p (hash-table)\n (zerop (hash-table-count hash-table)))\n \n(declaim (inline uint32<))\n(defun uint32< (x y)\n (< (the uint32 x) (the uint32 y)))\n \n(defun main ()\n (declare (inline sort))\n (let* ((n (read))\n (as (loop repeat n collect (read-fixnum)))\n (bs (loop repeat n collect (read-fixnum)))\n (res 1))\n (declare (uint31 n res))\n (setf as (sort as #'uint32<)\n bs (sort bs #'uint32<))\n (let ((table-a (make-hash-table :test #'eq))\n (table-b (make-hash-table :test #'eq)))\n (sb-int:named-let recur ((as as) (bs bs))\n (cond ((and (null as) (null bs)))\n ((null as)\n (mulfmod res (the uint31 (hash-table-count table-a)))\n (pophash table-a)\n (recur as (cdr bs)))\n ((null bs)\n (mulfmod res (the uint31 (hash-table-count table-b)))\n (pophash table-b)\n (recur (cdr as) bs))\n ((uint32< (car as) (car bs))\n (if (hash-table-empty-p table-b)\n (setf (gethash (car as) table-a) t)\n (progn (mulfmod res (the uint31 (hash-table-count table-b)))\n (pophash table-b)))\n (recur (cdr as) bs))\n (t\n (if (hash-table-empty-p table-a)\n (setf (gethash (car bs) table-b) t)\n (progn (mulfmod res (the uint31 (hash-table-count table-a)))\n (pophash table-a)))\n (recur as (cdr bs))))))\n (println res)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/msys64/usr/bin/cat.exe\" '(\"/dev/clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n0\n10\n20\n30\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n3\n10\n8\n7\n12\n5\n\"\n \"1\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\n#nck {\nwidth: 30px;\nheight: auto;\n}\n\nThere are N computers and N sockets in a one-dimensional world.\nThe coordinate of the i-th computer is a_i, and the coordinate of the i-th socket is b_i.\nIt is guaranteed that these 2N coordinates are pairwise distinct.\n\nSnuke wants to connect each computer to a socket using a cable.\nEach socket can be connected to only one computer.\n\nIn how many ways can he minimize the total length of the cables?\nCompute the answer modulo 10^9+7.\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n0 ≤ a_i, b_i ≤ 10^9\n\nThe coordinates are integers.\n\nThe coordinates are pairwise distinct.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\na_1\n:\na_N\nb_1\n:\nb_N\n\nOutput\n\nPrint the number of ways to minimize the total length of the cables, modulo 10^9+7.\n\nSample Input 1\n\n2\n0\n10\n20\n30\n\nSample Output 1\n\n2\n\nThere are two optimal connections: 0-20, 10-30 and 0-30, 10-20.\nIn both connections the total length of the cables is 40.\n\nSample Input 2\n\n3\n3\n10\n8\n7\n12\n5\n\nSample Output 2\n\n1", "sample_input": "2\n0\n10\n20\n30\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03878", "source_text": "Score : 500 points\n\nProblem Statement\n\n#nck {\nwidth: 30px;\nheight: auto;\n}\n\nThere are N computers and N sockets in a one-dimensional world.\nThe coordinate of the i-th computer is a_i, and the coordinate of the i-th socket is b_i.\nIt is guaranteed that these 2N coordinates are pairwise distinct.\n\nSnuke wants to connect each computer to a socket using a cable.\nEach socket can be connected to only one computer.\n\nIn how many ways can he minimize the total length of the cables?\nCompute the answer modulo 10^9+7.\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n0 ≤ a_i, b_i ≤ 10^9\n\nThe coordinates are integers.\n\nThe coordinates are pairwise distinct.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\na_1\n:\na_N\nb_1\n:\nb_N\n\nOutput\n\nPrint the number of ways to minimize the total length of the cables, modulo 10^9+7.\n\nSample Input 1\n\n2\n0\n10\n20\n30\n\nSample Output 1\n\n2\n\nThere are two optimal connections: 0-20, 10-30 and 0-30, 10-20.\nIn both connections the total length of the cables is 40.\n\nSample Input 2\n\n3\n3\n10\n8\n7\n12\n5\n\nSample Output 2\n\n1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9975, "cpu_time_ms": 2105, "memory_kb": 68836}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s330508626", "group_id": "codeNet:p03943", "input_text": "(let* ((l (sort (read-from-string\n (concatenate 'string \"(\" (read-line) \")\"))#'<=))\n (a (first l))\n (b (second l))\n (c (third l)))\n (if (= c (+ a b))\n (princ \"Yes\")\n (princ \"No\")))", "language": "Lisp", "metadata": {"date": 1593101969, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03943.html", "problem_id": "p03943", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03943/input.txt", "sample_output_relpath": "derived/input_output/data/p03943/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03943/Lisp/s330508626.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s330508626", "user_id": "u425762225"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let* ((l (sort (read-from-string\n (concatenate 'string \"(\" (read-line) \")\"))#'<=))\n (a (first l))\n (b (second l))\n (c (third l)))\n (if (= c (+ a b))\n (princ \"Yes\")\n (princ \"No\")))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTwo students of AtCoder Kindergarten are fighting over candy packs.\n\nThere are three candy packs, each of which contains a, b, and c candies, respectively.\n\nTeacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.\n\nNote that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.\n\nConstraints\n\n1 ≦ a, b, c ≦ 100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b c\n\nOutput\n\nIf it is possible to distribute the packs so that each student gets the same number of candies, print Yes. Otherwise, print No.\n\nSample Input 1\n\n10 30 20\n\nSample Output 1\n\nYes\n\nGive the pack with 30 candies to one student, and give the two packs with 10 and 20 candies to the other. Then, each gets 30 candies.\n\nSample Input 2\n\n30 30 100\n\nSample Output 2\n\nNo\n\nIn this case, the student who gets the pack with 100 candies always has more candies than the other.\n\nNote that every pack must be given to one of them.\n\nSample Input 3\n\n56 25 31\n\nSample Output 3\n\nYes", "sample_input": "10 30 20\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03943", "source_text": "Score : 100 points\n\nProblem Statement\n\nTwo students of AtCoder Kindergarten are fighting over candy packs.\n\nThere are three candy packs, each of which contains a, b, and c candies, respectively.\n\nTeacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.\n\nNote that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.\n\nConstraints\n\n1 ≦ a, b, c ≦ 100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b c\n\nOutput\n\nIf it is possible to distribute the packs so that each student gets the same number of candies, print Yes. Otherwise, print No.\n\nSample Input 1\n\n10 30 20\n\nSample Output 1\n\nYes\n\nGive the pack with 30 candies to one student, and give the two packs with 10 and 20 candies to the other. Then, each gets 30 candies.\n\nSample Input 2\n\n30 30 100\n\nSample Output 2\n\nNo\n\nIn this case, the student who gets the pack with 100 candies always has more candies than the other.\n\nNote that every pack must be given to one of them.\n\nSample Input 3\n\n56 25 31\n\nSample Output 3\n\nYes", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 232, "cpu_time_ms": 20, "memory_kb": 24180}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s602772207", "group_id": "codeNet:p03952", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline println-sequence))\n(defun println-sequence (sequence &key (out *standard-output*) (key #'identity))\n (let ((init t))\n (sequence:dosequence (x sequence)\n (if init\n (setq init nil)\n (write-char #\\ out))\n (princ (funcall key x) out))\n (terpri out)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (x (read)))\n (when (or (= x 1) (= x (- (* 2 n) 1)))\n (write-line \"No\")\n (return-from main))\n (write-line \"Yes\")\n (let ((res (make-array (- (* 2 n) 1) :element-type 'uint32))\n (table (make-hash-table :test #'eq)))\n (loop for i from 1 to (- (* 2 n) 1)\n do (setf (gethash i table) t))\n (labels ((%set (i value)\n (setf (aref res i) value)\n (remhash value table)))\n (if (= x 2)\n (progn (%set (- n 2) (- x 1))\n (%set (- n 1) x)\n (%set n (+ x 1))\n (when (> n 2)\n (%set (+ n 1) (+ x 2))))\n (progn (%set (- n 2) (- x 1))\n (%set (- n 1) x)\n (%set n (+ x 1))\n (when (> n 2)\n (%set (+ n 1) (- x 2)))))\n (loop for i below (- n 2)\n for key being each hash-key of table\n do (%set i key))\n (loop for i from (+ n 2) below (- (* 2 n) 1)\n for key being each hash-key of table\n do (%set i key))\n (println-sequence res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 4\n\"\n \"Yes\n1\n6\n3\n7\n4\n5\n2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 1\n\"\n \"No\n\")))\n", "language": "Lisp", "metadata": {"date": 1585189640, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03952.html", "problem_id": "p03952", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03952/input.txt", "sample_output_relpath": "derived/input_output/data/p03952/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03952/Lisp/s602772207.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s602772207", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n1\n6\n3\n7\n4\n5\n2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (inline println-sequence))\n(defun println-sequence (sequence &key (out *standard-output*) (key #'identity))\n (let ((init t))\n (sequence:dosequence (x sequence)\n (if init\n (setq init nil)\n (write-char #\\ out))\n (princ (funcall key x) out))\n (terpri out)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (x (read)))\n (when (or (= x 1) (= x (- (* 2 n) 1)))\n (write-line \"No\")\n (return-from main))\n (write-line \"Yes\")\n (let ((res (make-array (- (* 2 n) 1) :element-type 'uint32))\n (table (make-hash-table :test #'eq)))\n (loop for i from 1 to (- (* 2 n) 1)\n do (setf (gethash i table) t))\n (labels ((%set (i value)\n (setf (aref res i) value)\n (remhash value table)))\n (if (= x 2)\n (progn (%set (- n 2) (- x 1))\n (%set (- n 1) x)\n (%set n (+ x 1))\n (when (> n 2)\n (%set (+ n 1) (+ x 2))))\n (progn (%set (- n 2) (- x 1))\n (%set (- n 1) x)\n (%set n (+ x 1))\n (when (> n 2)\n (%set (+ n 1) (- x 2)))))\n (loop for i below (- n 2)\n for key being each hash-key of table\n do (%set i key))\n (loop for i from (+ n 2) below (- (* 2 n) 1)\n for key being each hash-key of table\n do (%set i key))\n (println-sequence res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 4\n\"\n \"Yes\n1\n6\n3\n7\n4\n5\n2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 1\n\"\n \"No\n\")))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have a pyramid with N steps, built with blocks.\nThe steps are numbered 1 through N from top to bottom.\nFor each 1≤i≤N, step i consists of 2i-1 blocks aligned horizontally.\nThe pyramid is built so that the blocks at the centers of the steps are aligned vertically.\n\nA pyramid with N=4 steps\n\nSnuke wrote a permutation of (1, 2, ..., 2N-1) into the blocks of step N.\nThen, he wrote integers into all remaining blocks, under the following rule:\n\nThe integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.\n\nWriting integers into the blocks\n\nAfterwards, he erased all integers written into the blocks.\nNow, he only remembers that the integer written into the block of step 1 was x.\n\nConstruct a permutation of (1, 2, ..., 2N-1) that could have been written into the blocks of step N, or declare that Snuke's memory is incorrect and such a permutation does not exist.\n\nConstraints\n\n2≤N≤10^5\n\n1≤x≤2N-1\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN x\n\nOutput\n\nIf no permutation of (1, 2, ..., 2N-1) could have been written into the blocks of step N, print No.\n\nOtherwise, print Yes in the first line, then print 2N-1 lines in addition.\n\nThe i-th of these 2N-1 lines should contain the i-th element of a possible permutation.\n\nSample Input 1\n\n4 4\n\nSample Output 1\n\nYes\n1\n6\n3\n7\n4\n5\n2\n\nThis case corresponds to the figure in the problem statement.\n\nSample Input 2\n\n2 1\n\nSample Output 2\n\nNo\n\nNo matter what permutation was written into the blocks of step N, the integer written into the block of step 1 would be 2.", "sample_input": "4 4\n"}, "reference_outputs": ["Yes\n1\n6\n3\n7\n4\n5\n2\n"], "source_document_id": "p03952", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have a pyramid with N steps, built with blocks.\nThe steps are numbered 1 through N from top to bottom.\nFor each 1≤i≤N, step i consists of 2i-1 blocks aligned horizontally.\nThe pyramid is built so that the blocks at the centers of the steps are aligned vertically.\n\nA pyramid with N=4 steps\n\nSnuke wrote a permutation of (1, 2, ..., 2N-1) into the blocks of step N.\nThen, he wrote integers into all remaining blocks, under the following rule:\n\nThe integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.\n\nWriting integers into the blocks\n\nAfterwards, he erased all integers written into the blocks.\nNow, he only remembers that the integer written into the block of step 1 was x.\n\nConstruct a permutation of (1, 2, ..., 2N-1) that could have been written into the blocks of step N, or declare that Snuke's memory is incorrect and such a permutation does not exist.\n\nConstraints\n\n2≤N≤10^5\n\n1≤x≤2N-1\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN x\n\nOutput\n\nIf no permutation of (1, 2, ..., 2N-1) could have been written into the blocks of step N, print No.\n\nOtherwise, print Yes in the first line, then print 2N-1 lines in addition.\n\nThe i-th of these 2N-1 lines should contain the i-th element of a possible permutation.\n\nSample Input 1\n\n4 4\n\nSample Output 1\n\nYes\n1\n6\n3\n7\n4\n5\n2\n\nThis case corresponds to the figure in the problem statement.\n\nSample Input 2\n\n2 1\n\nSample Output 2\n\nNo\n\nNo matter what permutation was written into the blocks of step N, the integer written into the block of step 1 would be 2.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5008, "cpu_time_ms": 235, "memory_kb": 32484}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s055514318", "group_id": "codeNet:p03952", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n(defun main ()\n (declare #.OPT\n (inline set-difference))\n (let* ((n (read))\n (x (read))\n (end (- (* 2 n) 1))\n (seq (loop for i from 1 to end collect i))\n (res (make-array end :element-type 'uint32))\n (out (make-string-output-stream :element-type 'base-char)))\n (declare (uint32 n x))\n (cond ((or (= x 1) (= x end))\n (println \"No\"))\n ((= n 2)\n (format t \"Yes~%1~%2~%3~%\"))\n (t\n (let ((fixed (if (> x 2)\n (list (- x 2) x (+ x 1) (- x 1))\n (list (+ x 2) x (- x 1) (+ x 1)))))\n (setf (aref res (- n 2)) (elt fixed 0)\n (aref res (- n 1)) (elt fixed 1)\n (aref res n) (elt fixed 2)\n (aref res (+ n 1)) (elt fixed 3))\n (setf seq (set-difference seq fixed\n :test (lambda (x y)\n (declare (uint32 x y))\n (= x y))))\n (loop for i from 0 below (- n 2)\n for a = (pop seq)\n do (setf (aref res i) a))\n (loop for i from (+ n 2) below end\n for a = (pop seq)\n do (setf (aref res i) a))\n (println \"Yes\")\n (loop for a across res\n do (println a out)\n finally (write-string (get-output-stream-string out))))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1551602318, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03952.html", "problem_id": "p03952", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03952/input.txt", "sample_output_relpath": "derived/input_output/data/p03952/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03952/Lisp/s055514318.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s055514318", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n1\n6\n3\n7\n4\n5\n2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n(defun main ()\n (declare #.OPT\n (inline set-difference))\n (let* ((n (read))\n (x (read))\n (end (- (* 2 n) 1))\n (seq (loop for i from 1 to end collect i))\n (res (make-array end :element-type 'uint32))\n (out (make-string-output-stream :element-type 'base-char)))\n (declare (uint32 n x))\n (cond ((or (= x 1) (= x end))\n (println \"No\"))\n ((= n 2)\n (format t \"Yes~%1~%2~%3~%\"))\n (t\n (let ((fixed (if (> x 2)\n (list (- x 2) x (+ x 1) (- x 1))\n (list (+ x 2) x (- x 1) (+ x 1)))))\n (setf (aref res (- n 2)) (elt fixed 0)\n (aref res (- n 1)) (elt fixed 1)\n (aref res n) (elt fixed 2)\n (aref res (+ n 1)) (elt fixed 3))\n (setf seq (set-difference seq fixed\n :test (lambda (x y)\n (declare (uint32 x y))\n (= x y))))\n (loop for i from 0 below (- n 2)\n for a = (pop seq)\n do (setf (aref res i) a))\n (loop for i from (+ n 2) below end\n for a = (pop seq)\n do (setf (aref res i) a))\n (println \"Yes\")\n (loop for a across res\n do (println a out)\n finally (write-string (get-output-stream-string out))))))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have a pyramid with N steps, built with blocks.\nThe steps are numbered 1 through N from top to bottom.\nFor each 1≤i≤N, step i consists of 2i-1 blocks aligned horizontally.\nThe pyramid is built so that the blocks at the centers of the steps are aligned vertically.\n\nA pyramid with N=4 steps\n\nSnuke wrote a permutation of (1, 2, ..., 2N-1) into the blocks of step N.\nThen, he wrote integers into all remaining blocks, under the following rule:\n\nThe integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.\n\nWriting integers into the blocks\n\nAfterwards, he erased all integers written into the blocks.\nNow, he only remembers that the integer written into the block of step 1 was x.\n\nConstruct a permutation of (1, 2, ..., 2N-1) that could have been written into the blocks of step N, or declare that Snuke's memory is incorrect and such a permutation does not exist.\n\nConstraints\n\n2≤N≤10^5\n\n1≤x≤2N-1\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN x\n\nOutput\n\nIf no permutation of (1, 2, ..., 2N-1) could have been written into the blocks of step N, print No.\n\nOtherwise, print Yes in the first line, then print 2N-1 lines in addition.\n\nThe i-th of these 2N-1 lines should contain the i-th element of a possible permutation.\n\nSample Input 1\n\n4 4\n\nSample Output 1\n\nYes\n1\n6\n3\n7\n4\n5\n2\n\nThis case corresponds to the figure in the problem statement.\n\nSample Input 2\n\n2 1\n\nSample Output 2\n\nNo\n\nNo matter what permutation was written into the blocks of step N, the integer written into the block of step 1 would be 2.", "sample_input": "4 4\n"}, "reference_outputs": ["Yes\n1\n6\n3\n7\n4\n5\n2\n"], "source_document_id": "p03952", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have a pyramid with N steps, built with blocks.\nThe steps are numbered 1 through N from top to bottom.\nFor each 1≤i≤N, step i consists of 2i-1 blocks aligned horizontally.\nThe pyramid is built so that the blocks at the centers of the steps are aligned vertically.\n\nA pyramid with N=4 steps\n\nSnuke wrote a permutation of (1, 2, ..., 2N-1) into the blocks of step N.\nThen, he wrote integers into all remaining blocks, under the following rule:\n\nThe integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.\n\nWriting integers into the blocks\n\nAfterwards, he erased all integers written into the blocks.\nNow, he only remembers that the integer written into the block of step 1 was x.\n\nConstruct a permutation of (1, 2, ..., 2N-1) that could have been written into the blocks of step N, or declare that Snuke's memory is incorrect and such a permutation does not exist.\n\nConstraints\n\n2≤N≤10^5\n\n1≤x≤2N-1\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN x\n\nOutput\n\nIf no permutation of (1, 2, ..., 2N-1) could have been written into the blocks of step N, print No.\n\nOtherwise, print Yes in the first line, then print 2N-1 lines in addition.\n\nThe i-th of these 2N-1 lines should contain the i-th element of a possible permutation.\n\nSample Input 1\n\n4 4\n\nSample Output 1\n\nYes\n1\n6\n3\n7\n4\n5\n2\n\nThis case corresponds to the figure in the problem statement.\n\nSample Input 2\n\n2 1\n\nSample Output 2\n\nNo\n\nNo matter what permutation was written into the blocks of step N, the integer written into the block of step 1 would be 2.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2444, "cpu_time_ms": 204, "memory_kb": 28392}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s576217306", "group_id": "codeNet:p03952", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (x (read))\n (end (- (* 2 n) 1))\n (seq (loop for i from 1 to end collect i))\n (res (make-array end :element-type 'uint32)))\n (declare (uint32 n x))\n (cond ((or (= x 1) (= x end))\n (println \"No\"))\n ((= n 2)\n (format t \"Yes~%1~%2~%3~%\"))\n (t\n (let ((fixed (if (> x 2)\n (list (- x 2) x (+ x 1) (- x 1))\n (list (+ x 2) x (- x 1) (+ x 1)))))\n (setf (aref res (- n 2)) (elt fixed 0)\n (aref res (- n 1)) (elt fixed 1)\n (aref res n) (elt fixed 2)\n (aref res (+ n 1)) (elt fixed 3))\n (setf seq (set-difference seq fixed))\n (loop for i from 0 below (- n 2)\n for a = (pop seq)\n do (setf (aref res i) a))\n (loop for i from (+ n 2) below end\n for a = (pop seq)\n do (setf (aref res i) a))\n (println \"Yes\")\n (loop for a across res\n do (println a)))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1551601602, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03952.html", "problem_id": "p03952", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03952/input.txt", "sample_output_relpath": "derived/input_output/data/p03952/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03952/Lisp/s576217306.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s576217306", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n1\n6\n3\n7\n4\n5\n2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (x (read))\n (end (- (* 2 n) 1))\n (seq (loop for i from 1 to end collect i))\n (res (make-array end :element-type 'uint32)))\n (declare (uint32 n x))\n (cond ((or (= x 1) (= x end))\n (println \"No\"))\n ((= n 2)\n (format t \"Yes~%1~%2~%3~%\"))\n (t\n (let ((fixed (if (> x 2)\n (list (- x 2) x (+ x 1) (- x 1))\n (list (+ x 2) x (- x 1) (+ x 1)))))\n (setf (aref res (- n 2)) (elt fixed 0)\n (aref res (- n 1)) (elt fixed 1)\n (aref res n) (elt fixed 2)\n (aref res (+ n 1)) (elt fixed 3))\n (setf seq (set-difference seq fixed))\n (loop for i from 0 below (- n 2)\n for a = (pop seq)\n do (setf (aref res i) a))\n (loop for i from (+ n 2) below end\n for a = (pop seq)\n do (setf (aref res i) a))\n (println \"Yes\")\n (loop for a across res\n do (println a)))))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have a pyramid with N steps, built with blocks.\nThe steps are numbered 1 through N from top to bottom.\nFor each 1≤i≤N, step i consists of 2i-1 blocks aligned horizontally.\nThe pyramid is built so that the blocks at the centers of the steps are aligned vertically.\n\nA pyramid with N=4 steps\n\nSnuke wrote a permutation of (1, 2, ..., 2N-1) into the blocks of step N.\nThen, he wrote integers into all remaining blocks, under the following rule:\n\nThe integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.\n\nWriting integers into the blocks\n\nAfterwards, he erased all integers written into the blocks.\nNow, he only remembers that the integer written into the block of step 1 was x.\n\nConstruct a permutation of (1, 2, ..., 2N-1) that could have been written into the blocks of step N, or declare that Snuke's memory is incorrect and such a permutation does not exist.\n\nConstraints\n\n2≤N≤10^5\n\n1≤x≤2N-1\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN x\n\nOutput\n\nIf no permutation of (1, 2, ..., 2N-1) could have been written into the blocks of step N, print No.\n\nOtherwise, print Yes in the first line, then print 2N-1 lines in addition.\n\nThe i-th of these 2N-1 lines should contain the i-th element of a possible permutation.\n\nSample Input 1\n\n4 4\n\nSample Output 1\n\nYes\n1\n6\n3\n7\n4\n5\n2\n\nThis case corresponds to the figure in the problem statement.\n\nSample Input 2\n\n2 1\n\nSample Output 2\n\nNo\n\nNo matter what permutation was written into the blocks of step N, the integer written into the block of step 1 would be 2.", "sample_input": "4 4\n"}, "reference_outputs": ["Yes\n1\n6\n3\n7\n4\n5\n2\n"], "source_document_id": "p03952", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have a pyramid with N steps, built with blocks.\nThe steps are numbered 1 through N from top to bottom.\nFor each 1≤i≤N, step i consists of 2i-1 blocks aligned horizontally.\nThe pyramid is built so that the blocks at the centers of the steps are aligned vertically.\n\nA pyramid with N=4 steps\n\nSnuke wrote a permutation of (1, 2, ..., 2N-1) into the blocks of step N.\nThen, he wrote integers into all remaining blocks, under the following rule:\n\nThe integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.\n\nWriting integers into the blocks\n\nAfterwards, he erased all integers written into the blocks.\nNow, he only remembers that the integer written into the block of step 1 was x.\n\nConstruct a permutation of (1, 2, ..., 2N-1) that could have been written into the blocks of step N, or declare that Snuke's memory is incorrect and such a permutation does not exist.\n\nConstraints\n\n2≤N≤10^5\n\n1≤x≤2N-1\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN x\n\nOutput\n\nIf no permutation of (1, 2, ..., 2N-1) could have been written into the blocks of step N, print No.\n\nOtherwise, print Yes in the first line, then print 2N-1 lines in addition.\n\nThe i-th of these 2N-1 lines should contain the i-th element of a possible permutation.\n\nSample Input 1\n\n4 4\n\nSample Output 1\n\nYes\n1\n6\n3\n7\n4\n5\n2\n\nThis case corresponds to the figure in the problem statement.\n\nSample Input 2\n\n2 1\n\nSample Output 2\n\nNo\n\nNo matter what permutation was written into the blocks of step N, the integer written into the block of step 1 would be 2.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2079, "cpu_time_ms": 538, "memory_kb": 18148}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s525515882", "group_id": "codeNet:p03952", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n(defun main ()\n (let* ((n (read))\n (x (read))\n (end (- (* 2 n) 1))\n (seq (loop for i from 1 to end collect i))\n (res (make-array end :element-type 'uint32)))\n (declare (uint32 n x))\n (cond ((or (= x 1) (= x end))\n (println \"No\"))\n ((= n 2)\n (format t \"Yes~%1~%2~%3~%\"))\n (t\n (let ((fixed (if (> x 2)\n (list (- x 2) x (+ x 1) (- x 1))\n (list (+ x 2) x (- x 1) (+ x 1)))))\n (setf (aref res (- n 2)) (elt fixed 0)\n (aref res (- n 1)) (elt fixed 1)\n (aref res n) (elt fixed 2)\n (aref res (+ n 1)) (elt fixed 3))\n (setf seq (set-difference seq fixed))\n (loop for i from 0 below (- n 2)\n for a = (pop seq)\n do (setf (aref res i) a))\n (loop for i from (+ n 2) below end\n for a = (pop seq)\n do (setf (aref res i) a))\n (println \"Yes\")\n (loop for a across res\n do (println a)))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1551601500, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03952.html", "problem_id": "p03952", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03952/input.txt", "sample_output_relpath": "derived/input_output/data/p03952/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03952/Lisp/s525515882.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s525515882", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Yes\n1\n6\n3\n7\n4\n5\n2\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n(defun main ()\n (let* ((n (read))\n (x (read))\n (end (- (* 2 n) 1))\n (seq (loop for i from 1 to end collect i))\n (res (make-array end :element-type 'uint32)))\n (declare (uint32 n x))\n (cond ((or (= x 1) (= x end))\n (println \"No\"))\n ((= n 2)\n (format t \"Yes~%1~%2~%3~%\"))\n (t\n (let ((fixed (if (> x 2)\n (list (- x 2) x (+ x 1) (- x 1))\n (list (+ x 2) x (- x 1) (+ x 1)))))\n (setf (aref res (- n 2)) (elt fixed 0)\n (aref res (- n 1)) (elt fixed 1)\n (aref res n) (elt fixed 2)\n (aref res (+ n 1)) (elt fixed 3))\n (setf seq (set-difference seq fixed))\n (loop for i from 0 below (- n 2)\n for a = (pop seq)\n do (setf (aref res i) a))\n (loop for i from (+ n 2) below end\n for a = (pop seq)\n do (setf (aref res i) a))\n (println \"Yes\")\n (loop for a across res\n do (println a)))))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have a pyramid with N steps, built with blocks.\nThe steps are numbered 1 through N from top to bottom.\nFor each 1≤i≤N, step i consists of 2i-1 blocks aligned horizontally.\nThe pyramid is built so that the blocks at the centers of the steps are aligned vertically.\n\nA pyramid with N=4 steps\n\nSnuke wrote a permutation of (1, 2, ..., 2N-1) into the blocks of step N.\nThen, he wrote integers into all remaining blocks, under the following rule:\n\nThe integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.\n\nWriting integers into the blocks\n\nAfterwards, he erased all integers written into the blocks.\nNow, he only remembers that the integer written into the block of step 1 was x.\n\nConstruct a permutation of (1, 2, ..., 2N-1) that could have been written into the blocks of step N, or declare that Snuke's memory is incorrect and such a permutation does not exist.\n\nConstraints\n\n2≤N≤10^5\n\n1≤x≤2N-1\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN x\n\nOutput\n\nIf no permutation of (1, 2, ..., 2N-1) could have been written into the blocks of step N, print No.\n\nOtherwise, print Yes in the first line, then print 2N-1 lines in addition.\n\nThe i-th of these 2N-1 lines should contain the i-th element of a possible permutation.\n\nSample Input 1\n\n4 4\n\nSample Output 1\n\nYes\n1\n6\n3\n7\n4\n5\n2\n\nThis case corresponds to the figure in the problem statement.\n\nSample Input 2\n\n2 1\n\nSample Output 2\n\nNo\n\nNo matter what permutation was written into the blocks of step N, the integer written into the block of step 1 would be 2.", "sample_input": "4 4\n"}, "reference_outputs": ["Yes\n1\n6\n3\n7\n4\n5\n2\n"], "source_document_id": "p03952", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have a pyramid with N steps, built with blocks.\nThe steps are numbered 1 through N from top to bottom.\nFor each 1≤i≤N, step i consists of 2i-1 blocks aligned horizontally.\nThe pyramid is built so that the blocks at the centers of the steps are aligned vertically.\n\nA pyramid with N=4 steps\n\nSnuke wrote a permutation of (1, 2, ..., 2N-1) into the blocks of step N.\nThen, he wrote integers into all remaining blocks, under the following rule:\n\nThe integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.\n\nWriting integers into the blocks\n\nAfterwards, he erased all integers written into the blocks.\nNow, he only remembers that the integer written into the block of step 1 was x.\n\nConstruct a permutation of (1, 2, ..., 2N-1) that could have been written into the blocks of step N, or declare that Snuke's memory is incorrect and such a permutation does not exist.\n\nConstraints\n\n2≤N≤10^5\n\n1≤x≤2N-1\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN x\n\nOutput\n\nIf no permutation of (1, 2, ..., 2N-1) could have been written into the blocks of step N, print No.\n\nOtherwise, print Yes in the first line, then print 2N-1 lines in addition.\n\nThe i-th of these 2N-1 lines should contain the i-th element of a possible permutation.\n\nSample Input 1\n\n4 4\n\nSample Output 1\n\nYes\n1\n6\n3\n7\n4\n5\n2\n\nThis case corresponds to the figure in the problem statement.\n\nSample Input 2\n\n2 1\n\nSample Output 2\n\nNo\n\nNo matter what permutation was written into the blocks of step N, the integer written into the block of step 1 would be 2.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2061, "cpu_time_ms": 549, "memory_kb": 21988}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s518266808", "group_id": "codeNet:p03953", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Calculate a^n on any monoids in O(log(n)) time\n;;;\n\n(declaim (inline power))\n(defun power (base exponent op identity)\n \"OP := binary operation (comprising a monoid)\nIDENTITY := identity element w.r.t. OP\"\n (declare ((integer 0) exponent))\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) p))\n (cond ((zerop p) identity)\n ((evenp p) (recur (funcall op x x) (ash p -1)))\n (t (nth-value 0 (funcall op x (recur x (- p 1)))))))\n (recur-big (x p)\n (declare ((integer 0) p))\n (cond ((zerop p) identity)\n ((evenp p) (recur-big (funcall op x x) (ash p -1)))\n (t (nth-value 0 (funcall op x (recur-big x (- p 1))))))))\n (typecase exponent\n (fixnum (recur base exponent))\n (otherwise (recur-big base exponent)))))\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline perm*)\n (ftype (function * (values (simple-array uint31 (*)) &optional)) perm*))\n(defun perm* (perm1 perm2)\n \"Composes two permutations.\"\n (declare ((simple-array uint31 (*)) perm1 perm2))\n (let* ((n (length perm1))\n (result (make-array n :element-type 'uint31)))\n (dotimes (i n)\n (setf (aref result i) (aref perm2 (aref perm1 i))))\n result))\n\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (xs (make-array n :element-type 'fixnum))\n (deltas (make-array n :element-type 'fixnum))\n (iden (make-array n :element-type 'uint31))\n (perm (make-array n :element-type 'uint31)))\n (declare (uint31 n)\n ((simple-array uint31 (*)) iden perm))\n (dotimes (i n)\n (setf (aref xs i) (read-fixnum)\n (aref perm i) i\n (aref iden i) i)\n (when (> i 0)\n (setf (aref deltas i)\n (- (aref xs i) (aref xs (- i 1))))))\n (let* ((m (read))\n (k (read)))\n (declare (uint62 m k))\n (dotimes (_ m)\n (let ((a (- (read-fixnum) 1)))\n (rotatef (aref perm a) (aref perm (+ a 1)))))\n (let ((perm-k (power perm k #'perm* iden))\n (res (make-array n :element-type 'fixnum)))\n (loop for i from 0 below n\n do (setf (aref res i)\n (if (zerop i)\n (aref xs i)\n (+ (aref res (- i 1))\n (aref deltas (aref perm-k i))))))\n (map () #'println res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"100000~%\")\n (dotimes (_ 100000)\n (println (- (random 2000000000) 1000000000) out))\n (format out \"100000 1000000000000000000~%\")\n (dotimes (_ 100000)\n (println (+ 2 (random 99998)) out))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n-1 0 2\n1 1\n2\n\"\n \"-1.0\n1.0\n2.0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 -1 1\n2 2\n2 2\n\"\n \"1.0\n-1.0\n1.0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n0 1 3 6 10\n3 10\n2 3 4\n\"\n \"0.0\n3.0\n7.0\n8.0\n10.0\n\")))\n", "language": "Lisp", "metadata": {"date": 1581568608, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03953.html", "problem_id": "p03953", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03953/input.txt", "sample_output_relpath": "derived/input_output/data/p03953/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03953/Lisp/s518266808.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s518266808", "user_id": "u352600849"}, "prompt_components": {"gold_output": "-1.0\n1.0\n2.0\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;;;\n;;; Calculate a^n on any monoids in O(log(n)) time\n;;;\n\n(declaim (inline power))\n(defun power (base exponent op identity)\n \"OP := binary operation (comprising a monoid)\nIDENTITY := identity element w.r.t. OP\"\n (declare ((integer 0) exponent))\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) p))\n (cond ((zerop p) identity)\n ((evenp p) (recur (funcall op x x) (ash p -1)))\n (t (nth-value 0 (funcall op x (recur x (- p 1)))))))\n (recur-big (x p)\n (declare ((integer 0) p))\n (cond ((zerop p) identity)\n ((evenp p) (recur-big (funcall op x x) (ash p -1)))\n (t (nth-value 0 (funcall op x (recur-big x (- p 1))))))))\n (typecase exponent\n (fixnum (recur base exponent))\n (otherwise (recur-big base exponent)))))\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline perm*)\n (ftype (function * (values (simple-array uint31 (*)) &optional)) perm*))\n(defun perm* (perm1 perm2)\n \"Composes two permutations.\"\n (declare ((simple-array uint31 (*)) perm1 perm2))\n (let* ((n (length perm1))\n (result (make-array n :element-type 'uint31)))\n (dotimes (i n)\n (setf (aref result i) (aref perm2 (aref perm1 i))))\n result))\n\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (xs (make-array n :element-type 'fixnum))\n (deltas (make-array n :element-type 'fixnum))\n (iden (make-array n :element-type 'uint31))\n (perm (make-array n :element-type 'uint31)))\n (declare (uint31 n)\n ((simple-array uint31 (*)) iden perm))\n (dotimes (i n)\n (setf (aref xs i) (read-fixnum)\n (aref perm i) i\n (aref iden i) i)\n (when (> i 0)\n (setf (aref deltas i)\n (- (aref xs i) (aref xs (- i 1))))))\n (let* ((m (read))\n (k (read)))\n (declare (uint62 m k))\n (dotimes (_ m)\n (let ((a (- (read-fixnum) 1)))\n (rotatef (aref perm a) (aref perm (+ a 1)))))\n (let ((perm-k (power perm k #'perm* iden))\n (res (make-array n :element-type 'fixnum)))\n (loop for i from 0 below n\n do (setf (aref res i)\n (if (zerop i)\n (aref xs i)\n (+ (aref res (- i 1))\n (aref deltas (aref perm-k i))))))\n (map () #'println res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"100000~%\")\n (dotimes (_ 100000)\n (println (- (random 2000000000) 1000000000) out))\n (format out \"100000 1000000000000000000~%\")\n (dotimes (_ 100000)\n (println (+ 2 (random 99998)) out))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n-1 0 2\n1 1\n2\n\"\n \"-1.0\n1.0\n2.0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 -1 1\n2 2\n2 2\n\"\n \"1.0\n-1.0\n1.0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n0 1 3 6 10\n3 10\n2 3 4\n\"\n \"0.0\n3.0\n7.0\n8.0\n10.0\n\")))\n", "problem_context": "Score : 800 points\n\nProblem Statement\n\nThere are N rabbits on a number line.\nThe rabbits are conveniently numbered 1 through N.\nThe coordinate of the initial position of rabbit i is x_i.\n\nThe rabbits will now take exercise on the number line, by performing sets described below.\nA set consists of M jumps. The j-th jump of a set is performed by rabbit a_j (2≤a_j≤N-1).\nFor this jump, either rabbit a_j-1 or rabbit a_j+1 is chosen with equal probability (let the chosen rabbit be rabbit x), then rabbit a_j will jump to the symmetric point of its current position with respect to rabbit x.\n\nThe rabbits will perform K sets in succession.\nFor each rabbit, find the expected value of the coordinate of its eventual position after K sets are performed.\n\nConstraints\n\n3≤N≤10^5\n\nx_i is an integer.\n\n|x_i|≤10^9\n\n1≤M≤10^5\n\n2≤a_j≤N-1\n\n1≤K≤10^{18}\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nx_1 x_2 ... x_N\nM K\na_1 a_2 ... a_M\n\nOutput\n\nPrint N lines.\nThe i-th line should contain the expected value of the coordinate of the eventual position of rabbit i after K sets are performed.\nThe output is considered correct if the absolute or relative error is at most 10^{-9}.\n\nSample Input 1\n\n3\n-1 0 2\n1 1\n2\n\nSample Output 1\n\n-1.0\n1.0\n2.0\n\nRabbit 2 will perform the jump.\nIf rabbit 1 is chosen, the coordinate of the destination will be -2.\nIf rabbit 3 is chosen, the coordinate of the destination will be 4.\nThus, the expected value of the coordinate of the eventual position of rabbit 2 is 0.5×(-2)+0.5×4=1.0.\n\nSample Input 2\n\n3\n1 -1 1\n2 2\n2 2\n\nSample Output 2\n\n1.0\n-1.0\n1.0\n\nx_i may not be distinct.\n\nSample Input 3\n\n5\n0 1 3 6 10\n3 10\n2 3 4\n\nSample Output 3\n\n0.0\n3.0\n7.0\n8.0\n10.0", "sample_input": "3\n-1 0 2\n1 1\n2\n"}, "reference_outputs": ["-1.0\n1.0\n2.0\n"], "source_document_id": "p03953", "source_text": "Score : 800 points\n\nProblem Statement\n\nThere are N rabbits on a number line.\nThe rabbits are conveniently numbered 1 through N.\nThe coordinate of the initial position of rabbit i is x_i.\n\nThe rabbits will now take exercise on the number line, by performing sets described below.\nA set consists of M jumps. The j-th jump of a set is performed by rabbit a_j (2≤a_j≤N-1).\nFor this jump, either rabbit a_j-1 or rabbit a_j+1 is chosen with equal probability (let the chosen rabbit be rabbit x), then rabbit a_j will jump to the symmetric point of its current position with respect to rabbit x.\n\nThe rabbits will perform K sets in succession.\nFor each rabbit, find the expected value of the coordinate of its eventual position after K sets are performed.\n\nConstraints\n\n3≤N≤10^5\n\nx_i is an integer.\n\n|x_i|≤10^9\n\n1≤M≤10^5\n\n2≤a_j≤N-1\n\n1≤K≤10^{18}\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nx_1 x_2 ... x_N\nM K\na_1 a_2 ... a_M\n\nOutput\n\nPrint N lines.\nThe i-th line should contain the expected value of the coordinate of the eventual position of rabbit i after K sets are performed.\nThe output is considered correct if the absolute or relative error is at most 10^{-9}.\n\nSample Input 1\n\n3\n-1 0 2\n1 1\n2\n\nSample Output 1\n\n-1.0\n1.0\n2.0\n\nRabbit 2 will perform the jump.\nIf rabbit 1 is chosen, the coordinate of the destination will be -2.\nIf rabbit 3 is chosen, the coordinate of the destination will be 4.\nThus, the expected value of the coordinate of the eventual position of rabbit 2 is 0.5×(-2)+0.5×4=1.0.\n\nSample Input 2\n\n3\n1 -1 1\n2 2\n2 2\n\nSample Output 2\n\n1.0\n-1.0\n1.0\n\nx_i may not be distinct.\n\nSample Input 3\n\n5\n0 1 3 6 10\n3 10\n2 3 4\n\nSample Output 3\n\n0.0\n3.0\n7.0\n8.0\n10.0", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7477, "cpu_time_ms": 412, "memory_kb": 56808}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s303962913", "group_id": "codeNet:p03958", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defconstant +mod+ 1000000007)\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n;;; Utils\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n(declaim (inline fast-sort))\n(defmethod fast-sort ((sequence list) &key (test #'<))\n (declare (inline sort)\n (inline sb-impl::stable-sort-list))\n (sort sequence (lambda (x y)\n (funcall test x y))))\n\n(declaim (inline quick-sort))\n(defmethod quick-sort ((sequence array))\n (labels ((swap (arr x y)\n (rotatef (aref arr x)\n (aref arr y)))\n (qsort-sub (arr left right)\n (let ((l left)\n (r right)\n (pivot (aref arr (+ left\n (random (- right left))))))\n (loop while (<= l r) do\n (loop while (< (aref arr l) pivot) do\n (incf l))\n (loop while (> (aref arr r) pivot) do\n (decf r))\n (when (<= l r)\n (swap arr l r)\n (incf l)\n (decf r)))\n (when (< left r)\n (qsort-sub arr left r))\n (when (< l right)\n (qsort-sub arr l right)))))\n (qsort-sub sequence 0 (1- (length sequence)))\n sequence))\n\n\n(defmacro read-numbers-to-list (size)\n `(loop repeat ,size collect (read)))\n\n\n\n(defmacro read-numbers-to-array (size)\n `(make-array ,size :initial-contents (loop repeat ,size collect (read))))\n\n(defmacro read-numbers-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size))))\n (dotimes (,r ,row-size)\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (read))))\n ,board)))\n\n\n(defun princ-for-each-line (list)\n (format t \"~{~a~&~}\" list))\n\n(defun unwrap (list)\n (format nil \"~{~a~^ ~}\" list))\n\n\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n\n\n\n;;; Body\n\n\n(declaim (ftype (function (uint16 uint16 list) uint16)))\n(defun solve (a)\n (declare (list a))\n (the fixnum\n (if (null (rest a))\n (1- (first a))\n (max\n 0\n (- (1- (first a))\n (reduce #'+ (subseq a 1)))))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((k (read))\n (total (read))\n (a (fast-sort (read-numbers-to-list total)\n :test #'>)))\n (declare (uint16 k)\n (uint16 total)\n (list a))\n (format t \"~a~&\" (solve a))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1599336836, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03958.html", "problem_id": "p03958", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03958/input.txt", "sample_output_relpath": "derived/input_output/data/p03958/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03958/Lisp/s303962913.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s303962913", "user_id": "u425762225"}, "prompt_components": {"gold_output": "0\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n(defconstant +mod+ 1000000007)\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n;;; Utils\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n(declaim (inline fast-sort))\n(defmethod fast-sort ((sequence list) &key (test #'<))\n (declare (inline sort)\n (inline sb-impl::stable-sort-list))\n (sort sequence (lambda (x y)\n (funcall test x y))))\n\n(declaim (inline quick-sort))\n(defmethod quick-sort ((sequence array))\n (labels ((swap (arr x y)\n (rotatef (aref arr x)\n (aref arr y)))\n (qsort-sub (arr left right)\n (let ((l left)\n (r right)\n (pivot (aref arr (+ left\n (random (- right left))))))\n (loop while (<= l r) do\n (loop while (< (aref arr l) pivot) do\n (incf l))\n (loop while (> (aref arr r) pivot) do\n (decf r))\n (when (<= l r)\n (swap arr l r)\n (incf l)\n (decf r)))\n (when (< left r)\n (qsort-sub arr left r))\n (when (< l right)\n (qsort-sub arr l right)))))\n (qsort-sub sequence 0 (1- (length sequence)))\n sequence))\n\n\n(defmacro read-numbers-to-list (size)\n `(loop repeat ,size collect (read)))\n\n\n\n(defmacro read-numbers-to-array (size)\n `(make-array ,size :initial-contents (loop repeat ,size collect (read))))\n\n(defmacro read-numbers-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size))))\n (dotimes (,r ,row-size)\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (read))))\n ,board)))\n\n\n(defun princ-for-each-line (list)\n (format t \"~{~a~&~}\" list))\n\n(defun unwrap (list)\n (format nil \"~{~a~^ ~}\" list))\n\n\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n\n\n\n;;; Body\n\n\n(declaim (ftype (function (uint16 uint16 list) uint16)))\n(defun solve (a)\n (declare (list a))\n (the fixnum\n (if (null (rest a))\n (1- (first a))\n (max\n 0\n (- (1- (first a))\n (reduce #'+ (subseq a 1)))))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((k (read))\n (total (read))\n (a (fast-sort (read-numbers-to-list total)\n :test #'>)))\n (declare (uint16 k)\n (uint16 total)\n (list a))\n (format t \"~a~&\" (solve a))))\n\n#-swank (main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are K pieces of cakes.\nMr. Takahashi would like to eat one cake per day, taking K days to eat them all.\n\nThere are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i.\n\nEating the same type of cake two days in a row would be no fun,\nso Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before.\n\nCompute the minimum number of days on which the same type of cake as the previous day will be eaten.\n\nConstraints\n\n1 ≤ K ≤ 10000\n\n1 ≤ T ≤ 100\n\n1 ≤ a_i ≤ 100\n\na_1 + a_2 + ... + a_T = K\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nK T\na_1 a_2 ... a_T\n\nOutput\n\nPrint the minimum number of days on which the same type of cake as the previous day will be eaten.\n\nSample Input 1\n\n7 3\n3 2 2\n\nSample Output 1\n\n0\n\nFor example, if Mr. Takahashi eats cakes in the order of 2, 1, 2, 3, 1, 3, 1, he can avoid eating the same type of cake as the previous day.\n\nSample Input 2\n\n6 3\n1 4 1\n\nSample Output 2\n\n1\n\nThere are 6 cakes.\nFor example, if Mr. Takahashi eats cakes in the order of 2, 3, 2, 2, 1, 2, he has to eat the same type of cake (i.e., type 2) as the previous day only on the fourth day.\nSince this is the minimum number, the answer is 1.\n\nSample Input 3\n\n100 1\n100\n\nSample Output 3\n\n99\n\nSince Mr. Takahashi has only one type of cake, he has no choice but to eat the same type of cake as the previous day from the second day and after.", "sample_input": "7 3\n3 2 2\n"}, "reference_outputs": ["0\n"], "source_document_id": "p03958", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are K pieces of cakes.\nMr. Takahashi would like to eat one cake per day, taking K days to eat them all.\n\nThere are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i.\n\nEating the same type of cake two days in a row would be no fun,\nso Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before.\n\nCompute the minimum number of days on which the same type of cake as the previous day will be eaten.\n\nConstraints\n\n1 ≤ K ≤ 10000\n\n1 ≤ T ≤ 100\n\n1 ≤ a_i ≤ 100\n\na_1 + a_2 + ... + a_T = K\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nK T\na_1 a_2 ... a_T\n\nOutput\n\nPrint the minimum number of days on which the same type of cake as the previous day will be eaten.\n\nSample Input 1\n\n7 3\n3 2 2\n\nSample Output 1\n\n0\n\nFor example, if Mr. Takahashi eats cakes in the order of 2, 1, 2, 3, 1, 3, 1, he can avoid eating the same type of cake as the previous day.\n\nSample Input 2\n\n6 3\n1 4 1\n\nSample Output 2\n\n1\n\nThere are 6 cakes.\nFor example, if Mr. Takahashi eats cakes in the order of 2, 3, 2, 2, 1, 2, he has to eat the same type of cake (i.e., type 2) as the previous day only on the fourth day.\nSince this is the minimum number, the answer is 1.\n\nSample Input 3\n\n100 1\n100\n\nSample Output 3\n\n99\n\nSince Mr. Takahashi has only one type of cake, he has no choice but to eat the same type of cake as the previous day from the second day and after.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3566, "cpu_time_ms": 27, "memory_kb": 28108}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s412094924", "group_id": "codeNet:p03959", "input_text": "(defun input (n)\n (let ((A (make-array n)))\n (dotimes (i n)\n (setf (aref A i) (read)))\n A))\n(defun solve (n A B)\n (unless (= (aref A (1- n)) (aref B 0))\n (return-from solve 0))\n (let ((ans 1))\n (loop for i from 1 below (1- n)\n if (and (= (aref A i) (aref A (1- i)))\n (= (aref B i) (aref B (1+ i))))\n do (progn (setq ans (* ans (min (aref A i) (aref B i))))\n (setq ans (mod ans 1000000007))))\n ans))\n(let* ((n (read))\n (A (input n))\n (B (input n)))\n (format t \"~A~%\" (solve n A B)))", "language": "Lisp", "metadata": {"date": 1522269269, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03959.html", "problem_id": "p03959", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03959/input.txt", "sample_output_relpath": "derived/input_output/data/p03959/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03959/Lisp/s412094924.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s412094924", "user_id": "u672956630"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun input (n)\n (let ((A (make-array n)))\n (dotimes (i n)\n (setf (aref A i) (read)))\n A))\n(defun solve (n A B)\n (unless (= (aref A (1- n)) (aref B 0))\n (return-from solve 0))\n (let ((ans 1))\n (loop for i from 1 below (1- n)\n if (and (= (aref A i) (aref A (1- i)))\n (= (aref B i) (aref B (1+ i))))\n do (progn (setq ans (* ans (min (aref A i) (aref B i))))\n (setq ans (mod ans 1000000007))))\n ans))\n(let* ((n (read))\n (A (input n))\n (B (input n)))\n (format t \"~A~%\" (solve n A B)))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nMountaineers Mr. Takahashi and Mr. Aoki recently trekked across a certain famous mountain range.\nThe mountain range consists of N mountains, extending from west to east in a straight line as Mt. 1, Mt. 2, ..., Mt. N.\nMr. Takahashi traversed the range from the west and Mr. Aoki from the east.\n\nThe height of Mt. i is h_i, but they have forgotten the value of each h_i.\nInstead, for each i (1 ≤ i ≤ N), they recorded the maximum height of the mountains climbed up to the time they reached the peak of Mt. i (including Mt. i).\nMr. Takahashi's record is T_i and Mr. Aoki's record is A_i.\n\nWe know that the height of each mountain h_i is a positive integer.\nCompute the number of the possible sequences of the mountains' heights, modulo 10^9 + 7.\n\nNote that the records may be incorrect and thus there may be no possible sequence of the mountains' heights.\nIn such a case, output 0.\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n1 ≤ T_i ≤ 10^9\n\n1 ≤ A_i ≤ 10^9\n\nT_i ≤ T_{i+1} (1 ≤ i ≤ N - 1)\n\nA_i ≥ A_{i+1} (1 ≤ i ≤ N - 1)\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nT_1 T_2 ... T_N\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the number of possible sequences of the mountains' heights, modulo 10^9 + 7.\n\nSample Input 1\n\n5\n1 3 3 3 3\n3 3 2 2 2\n\nSample Output 1\n\n4\n\nThe possible sequences of the mountains' heights are:\n\n1, 3, 2, 2, 2\n\n1, 3, 2, 1, 2\n\n1, 3, 1, 2, 2\n\n1, 3, 1, 1, 2\n\nfor a total of four sequences.\n\nSample Input 2\n\n5\n1 1 1 2 2\n3 2 1 1 1\n\nSample Output 2\n\n0\n\nThe records are contradictory, since Mr. Takahashi recorded 2 as the highest peak after climbing all the mountains but Mr. Aoki recorded 3.\n\nSample Input 3\n\n10\n1 3776 3776 8848 8848 8848 8848 8848 8848 8848\n8848 8848 8848 8848 8848 8848 8848 8848 3776 5\n\nSample Output 3\n\n884111967\n\nDon't forget to compute the number modulo 10^9 + 7.\n\nSample Input 4\n\n1\n17\n17\n\nSample Output 4\n\n1\n\nSome mountain ranges consist of only one mountain.", "sample_input": "5\n1 3 3 3 3\n3 3 2 2 2\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03959", "source_text": "Score : 400 points\n\nProblem Statement\n\nMountaineers Mr. Takahashi and Mr. Aoki recently trekked across a certain famous mountain range.\nThe mountain range consists of N mountains, extending from west to east in a straight line as Mt. 1, Mt. 2, ..., Mt. N.\nMr. Takahashi traversed the range from the west and Mr. Aoki from the east.\n\nThe height of Mt. i is h_i, but they have forgotten the value of each h_i.\nInstead, for each i (1 ≤ i ≤ N), they recorded the maximum height of the mountains climbed up to the time they reached the peak of Mt. i (including Mt. i).\nMr. Takahashi's record is T_i and Mr. Aoki's record is A_i.\n\nWe know that the height of each mountain h_i is a positive integer.\nCompute the number of the possible sequences of the mountains' heights, modulo 10^9 + 7.\n\nNote that the records may be incorrect and thus there may be no possible sequence of the mountains' heights.\nIn such a case, output 0.\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n1 ≤ T_i ≤ 10^9\n\n1 ≤ A_i ≤ 10^9\n\nT_i ≤ T_{i+1} (1 ≤ i ≤ N - 1)\n\nA_i ≥ A_{i+1} (1 ≤ i ≤ N - 1)\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nT_1 T_2 ... T_N\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the number of possible sequences of the mountains' heights, modulo 10^9 + 7.\n\nSample Input 1\n\n5\n1 3 3 3 3\n3 3 2 2 2\n\nSample Output 1\n\n4\n\nThe possible sequences of the mountains' heights are:\n\n1, 3, 2, 2, 2\n\n1, 3, 2, 1, 2\n\n1, 3, 1, 2, 2\n\n1, 3, 1, 1, 2\n\nfor a total of four sequences.\n\nSample Input 2\n\n5\n1 1 1 2 2\n3 2 1 1 1\n\nSample Output 2\n\n0\n\nThe records are contradictory, since Mr. Takahashi recorded 2 as the highest peak after climbing all the mountains but Mr. Aoki recorded 3.\n\nSample Input 3\n\n10\n1 3776 3776 8848 8848 8848 8848 8848 8848 8848\n8848 8848 8848 8848 8848 8848 8848 8848 3776 5\n\nSample Output 3\n\n884111967\n\nDon't forget to compute the number modulo 10^9 + 7.\n\nSample Input 4\n\n1\n17\n17\n\nSample Output 4\n\n1\n\nSome mountain ranges consist of only one mountain.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 569, "cpu_time_ms": 616, "memory_kb": 59752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s904185854", "group_id": "codeNet:p03962", "input_text": "(write (length (remove-duplicates (list (read) (read) (read)))))", "language": "Lisp", "metadata": {"date": 1598681719, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03962.html", "problem_id": "p03962", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03962/input.txt", "sample_output_relpath": "derived/input_output/data/p03962/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03962/Lisp/s904185854.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s904185854", "user_id": "u818498408"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(write (length (remove-duplicates (list (read) (read) (read)))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nAtCoDeer the deer recently bought three paint cans.\nThe color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c.\nHere, the color of each paint can is represented by an integer between 1 and 100, inclusive.\n\nSince he is forgetful, he might have bought more than one paint can in the same color.\nCount the number of different kinds of colors of these paint cans and tell him.\n\nConstraints\n\n1≦a,b,c≦100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b c\n\nOutput\n\nPrint the number of different kinds of colors of the paint cans.\n\nSample Input 1\n\n3 1 4\n\nSample Output 1\n\n3\n\nThree different colors: 1, 3, and 4.\n\nSample Input 2\n\n3 3 33\n\nSample Output 2\n\n2\n\nTwo different colors: 3 and 33.", "sample_input": "3 1 4\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03962", "source_text": "Score : 100 points\n\nProblem Statement\n\nAtCoDeer the deer recently bought three paint cans.\nThe color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c.\nHere, the color of each paint can is represented by an integer between 1 and 100, inclusive.\n\nSince he is forgetful, he might have bought more than one paint can in the same color.\nCount the number of different kinds of colors of these paint cans and tell him.\n\nConstraints\n\n1≦a,b,c≦100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b c\n\nOutput\n\nPrint the number of different kinds of colors of the paint cans.\n\nSample Input 1\n\n3 1 4\n\nSample Output 1\n\n3\n\nThree different colors: 1, 3, and 4.\n\nSample Input 2\n\n3 3 33\n\nSample Output 2\n\n2\n\nTwo different colors: 3 and 33.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 64, "cpu_time_ms": 14, "memory_kb": 24016}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s006219726", "group_id": "codeNet:p03962", "input_text": "(let ((l (cons 0 (sort (list (read) (read) (read)) #'<)) ))\n (princ (count-if #'identity (mapcar #'< l (cdr l)))))", "language": "Lisp", "metadata": {"date": 1585315928, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03962.html", "problem_id": "p03962", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03962/input.txt", "sample_output_relpath": "derived/input_output/data/p03962/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03962/Lisp/s006219726.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s006219726", "user_id": "u334552723"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((l (cons 0 (sort (list (read) (read) (read)) #'<)) ))\n (princ (count-if #'identity (mapcar #'< l (cdr l)))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nAtCoDeer the deer recently bought three paint cans.\nThe color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c.\nHere, the color of each paint can is represented by an integer between 1 and 100, inclusive.\n\nSince he is forgetful, he might have bought more than one paint can in the same color.\nCount the number of different kinds of colors of these paint cans and tell him.\n\nConstraints\n\n1≦a,b,c≦100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b c\n\nOutput\n\nPrint the number of different kinds of colors of the paint cans.\n\nSample Input 1\n\n3 1 4\n\nSample Output 1\n\n3\n\nThree different colors: 1, 3, and 4.\n\nSample Input 2\n\n3 3 33\n\nSample Output 2\n\n2\n\nTwo different colors: 3 and 33.", "sample_input": "3 1 4\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03962", "source_text": "Score : 100 points\n\nProblem Statement\n\nAtCoDeer the deer recently bought three paint cans.\nThe color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c.\nHere, the color of each paint can is represented by an integer between 1 and 100, inclusive.\n\nSince he is forgetful, he might have bought more than one paint can in the same color.\nCount the number of different kinds of colors of these paint cans and tell him.\n\nConstraints\n\n1≦a,b,c≦100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b c\n\nOutput\n\nPrint the number of different kinds of colors of the paint cans.\n\nSample Input 1\n\n3 1 4\n\nSample Output 1\n\n3\n\nThree different colors: 1, 3, and 4.\n\nSample Input 2\n\n3 3 33\n\nSample Output 2\n\n2\n\nTwo different colors: 3 and 33.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 117, "cpu_time_ms": 10, "memory_kb": 3428}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s114442727", "group_id": "codeNet:p03964", "input_text": "#|\n------------------------------------\n Utils \n------------------------------------\n|#\n\n(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (term-char #\\Space))\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let* ((,buffer (load-time-value (make-string ,buffer-size :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n ,(if (member :swank *features*)\n `(read-char ,in nil #\\Newline) ; on SLIME\n `(code-char (read-byte ,in nil #.(char-code #\\Newline))))\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,term-char))\n (return (values ,buffer ,idx))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare (inline read-byte)\n #-swank (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (read-byte in nil 0))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))\n (return (if minus (- result) result))))))))\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n(defmacro read-numbers-to-list (size)\n `(loop repeat ,size collect (read-fixnum)))\n\n(defmacro read-numbers-to-array (size)\n (let ((i (gensym))\n (arr (gensym)))\n `(let ((,arr (make-array ,size\n :element-type 'fixnum)))\n (declare ((array fixnum 1) ,arr))\n (loop for ,i of-type fixnum below ,size do\n (setf (aref ,arr ,i) (read))\n finally\n (return ,arr)))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (buffered-read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(declaim (inline unwrap))\n(defun unwrap (list)\n (the string\n (format nil \"~{~a~^ ~}\" list)))\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(defmacro maxf (place cand)\n `(setf ,place (max ,place ,cand)))\n\n(defmacro minf (place cand)\n `(setf ,place (min ,place ,cand)))\n\n(defmacro modf (place &optional (m +mod+))\n `(setf ,place (mod ,place ,m)))\n\n(defmacro alambda (parms &body body)\n `(labels ((self ,parms ,@body))\n #'self))\n\n(defun iota (count &optional (start 0) (step 1))\n (loop for i from 0 below count collect (+ start (* i step))))\n\n(defun int->lst (integer)\n (declare ((integer 0) integer))\n (labels ((sub (int &optional (acc nil))\n (declare ((integer 0) int)\n (list acc))\n (if (zerop int)\n acc\n (sub (floor int 10) (cons (rem int 10) acc)))))\n (sub integer)))\n\n(defun lst->int (list)\n (declare (list list))\n (labels ((sub (xs &optional (acc 0))\n (declare (ftype (function (list &optional (integer 0)) (integer 0)) sub))\n (declare (list xs)\n ((integer 0) acc))\n (if (null xs)\n acc\n (sub (rest xs) (+ (* acc 10)\n (rem (first xs) 10))))))\n (the fixnum\n (sub list))))\n\n(defun int->str (integer)\n (format nil \"~a\" integer))\n\n(defun str->int (str)\n (parse-integer str))\n\n(defun char->int (char)\n (declare (character char))\n (- (char-code char) #.(char-code #\\0)))\n\n(declaim (inline prime-factorize-to-list))\n(defun prime-factorize-to-list (integer)\n (declare ((integer 0) integer))\n (the list\n (if (<= integer 1)\n nil\n (loop\n while (<= (* f f) integer)\n with acc list = nil\n with f integer = 2\n do\n (if (zerop (rem integer f))\n (progn\n (push f acc)\n (setq integer (floor integer f)))\n (incf f))\n finally\n (when (/= integer 1)\n (push integer acc))\n (return (reverse acc))))))\n\n(declaim (inline prime-p))\n(defun prime-p (integer)\n (declare ((integer 1) integer))\n (if (= integer 1)\n nil\n (loop\n with f = 2\n while (<= (* f f) integer)\n do\n (when (zerop (rem integer f))\n (return nil))\n (incf f)\n finally\n (return t))))\n\n(defconstant +mod+ 1000000007)\n;(defconstant +mod+ 998244353)\n\n#|\n------------------------------------\n Body \n------------------------------------\n|#\n\n\n(defun solve (xs &optional (tak 0) (aoki 0) (ratio 1))\n (cond\n ((null xs) (+ tak aoki))\n ((and (>= (* (caar xs) ratio) tak)\n (>= (* (cdar xs) ratio) aoki))\n (solve (rest xs)\n (* (caar xs)\n ratio)\n (* (cdar xs)\n ratio)\n 1))\n (t (solve xs tak aoki (1+ ratio)))))\n\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (xs (loop repeat n collect (cons (read) (read)))))\n (princ (solve xs))\n (fresh-line)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1600644327, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03964.html", "problem_id": "p03964", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03964/input.txt", "sample_output_relpath": "derived/input_output/data/p03964/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03964/Lisp/s114442727.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s114442727", "user_id": "u425762225"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "#|\n------------------------------------\n Utils \n------------------------------------\n|#\n\n(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (term-char #\\Space))\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let* ((,buffer (load-time-value (make-string ,buffer-size :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n ,(if (member :swank *features*)\n `(read-char ,in nil #\\Newline) ; on SLIME\n `(code-char (read-byte ,in nil #.(char-code #\\Newline))))\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,term-char))\n (return (values ,buffer ,idx))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare (inline read-byte)\n #-swank (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (read-byte in nil 0))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))\n (return (if minus (- result) result))))))))\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n(defmacro read-numbers-to-list (size)\n `(loop repeat ,size collect (read-fixnum)))\n\n(defmacro read-numbers-to-array (size)\n (let ((i (gensym))\n (arr (gensym)))\n `(let ((,arr (make-array ,size\n :element-type 'fixnum)))\n (declare ((array fixnum 1) ,arr))\n (loop for ,i of-type fixnum below ,size do\n (setf (aref ,arr ,i) (read))\n finally\n (return ,arr)))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (buffered-read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(declaim (inline unwrap))\n(defun unwrap (list)\n (the string\n (format nil \"~{~a~^ ~}\" list)))\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(defmacro maxf (place cand)\n `(setf ,place (max ,place ,cand)))\n\n(defmacro minf (place cand)\n `(setf ,place (min ,place ,cand)))\n\n(defmacro modf (place &optional (m +mod+))\n `(setf ,place (mod ,place ,m)))\n\n(defmacro alambda (parms &body body)\n `(labels ((self ,parms ,@body))\n #'self))\n\n(defun iota (count &optional (start 0) (step 1))\n (loop for i from 0 below count collect (+ start (* i step))))\n\n(defun int->lst (integer)\n (declare ((integer 0) integer))\n (labels ((sub (int &optional (acc nil))\n (declare ((integer 0) int)\n (list acc))\n (if (zerop int)\n acc\n (sub (floor int 10) (cons (rem int 10) acc)))))\n (sub integer)))\n\n(defun lst->int (list)\n (declare (list list))\n (labels ((sub (xs &optional (acc 0))\n (declare (ftype (function (list &optional (integer 0)) (integer 0)) sub))\n (declare (list xs)\n ((integer 0) acc))\n (if (null xs)\n acc\n (sub (rest xs) (+ (* acc 10)\n (rem (first xs) 10))))))\n (the fixnum\n (sub list))))\n\n(defun int->str (integer)\n (format nil \"~a\" integer))\n\n(defun str->int (str)\n (parse-integer str))\n\n(defun char->int (char)\n (declare (character char))\n (- (char-code char) #.(char-code #\\0)))\n\n(declaim (inline prime-factorize-to-list))\n(defun prime-factorize-to-list (integer)\n (declare ((integer 0) integer))\n (the list\n (if (<= integer 1)\n nil\n (loop\n while (<= (* f f) integer)\n with acc list = nil\n with f integer = 2\n do\n (if (zerop (rem integer f))\n (progn\n (push f acc)\n (setq integer (floor integer f)))\n (incf f))\n finally\n (when (/= integer 1)\n (push integer acc))\n (return (reverse acc))))))\n\n(declaim (inline prime-p))\n(defun prime-p (integer)\n (declare ((integer 1) integer))\n (if (= integer 1)\n nil\n (loop\n with f = 2\n while (<= (* f f) integer)\n do\n (when (zerop (rem integer f))\n (return nil))\n (incf f)\n finally\n (return t))))\n\n(defconstant +mod+ 1000000007)\n;(defconstant +mod+ 998244353)\n\n#|\n------------------------------------\n Body \n------------------------------------\n|#\n\n\n(defun solve (xs &optional (tak 0) (aoki 0) (ratio 1))\n (cond\n ((null xs) (+ tak aoki))\n ((and (>= (* (caar xs) ratio) tak)\n (>= (* (cdar xs) ratio) aoki))\n (solve (rest xs)\n (* (caar xs)\n ratio)\n (* (cdar xs)\n ratio)\n 1))\n (t (solve xs tak aoki (1+ ratio)))))\n\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (xs (loop repeat n collect (cons (read) (read)))))\n (princ (solve xs))\n (fresh-line)))\n\n#-swank (main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nAtCoDeer the deer is seeing a quick report of election results on TV.\nTwo candidates are standing for the election: Takahashi and Aoki.\nThe report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes.\nAtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i.\nIt is known that each candidate had at least one vote when he checked the report for the first time.\n\nFind the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time.\nIt can be assumed that the number of votes obtained by each candidate never decreases.\n\nConstraints\n\n1≦N≦1000\n\n1≦T_i,A_i≦1000 (1≦i≦N)\n\nT_i and A_i (1≦i≦N) are coprime.\n\nIt is guaranteed that the correct answer is at most 10^{18}.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nT_1 A_1\nT_2 A_2\n:\nT_N A_N\n\nOutput\n\nPrint the minimum possible total number of votes obtained by Takahashi and Aoki when AtCoDeer checked the report for the N-th time.\n\nSample Input 1\n\n3\n2 3\n1 1\n3 2\n\nSample Output 1\n\n10\n\nWhen the numbers of votes obtained by the two candidates change as 2,3 → 3,3 → 6,4, the total number of votes at the end is 10, which is the minimum possible number.\n\nSample Input 2\n\n4\n1 1\n1 1\n1 5\n1 100\n\nSample Output 2\n\n101\n\nIt is possible that neither candidate obtained a vote between the moment when he checked the report, and the moment when he checked it for the next time.\n\nSample Input 3\n\n5\n3 10\n48 17\n31 199\n231 23\n3 2\n\nSample Output 3\n\n6930", "sample_input": "3\n2 3\n1 1\n3 2\n"}, "reference_outputs": ["10\n"], "source_document_id": "p03964", "source_text": "Score : 300 points\n\nProblem Statement\n\nAtCoDeer the deer is seeing a quick report of election results on TV.\nTwo candidates are standing for the election: Takahashi and Aoki.\nThe report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes.\nAtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i.\nIt is known that each candidate had at least one vote when he checked the report for the first time.\n\nFind the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time.\nIt can be assumed that the number of votes obtained by each candidate never decreases.\n\nConstraints\n\n1≦N≦1000\n\n1≦T_i,A_i≦1000 (1≦i≦N)\n\nT_i and A_i (1≦i≦N) are coprime.\n\nIt is guaranteed that the correct answer is at most 10^{18}.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nT_1 A_1\nT_2 A_2\n:\nT_N A_N\n\nOutput\n\nPrint the minimum possible total number of votes obtained by Takahashi and Aoki when AtCoDeer checked the report for the N-th time.\n\nSample Input 1\n\n3\n2 3\n1 1\n3 2\n\nSample Output 1\n\n10\n\nWhen the numbers of votes obtained by the two candidates change as 2,3 → 3,3 → 6,4, the total number of votes at the end is 10, which is the minimum possible number.\n\nSample Input 2\n\n4\n1 1\n1 1\n1 5\n1 100\n\nSample Output 2\n\n101\n\nIt is possible that neither candidate obtained a vote between the moment when he checked the report, and the moment when he checked it for the next time.\n\nSample Input 3\n\n5\n3 10\n48 17\n31 199\n231 23\n3 2\n\nSample Output 3\n\n6930", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8124, "cpu_time_ms": 2206, "memory_kb": 27408}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s750180934", "group_id": "codeNet:p03971", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n ,then\n ,else))\n\n(let ((n (read))\n (a (read))\n (b (read)))\n (loop repeat n\n for c = (read-char)\n do\n (block main\n (when (and (char= c #\\a) (null (zerop a)))\n (format t \"Yes~%\")\n (decf a)\n (return-from main))\n (when (and (or (char= c #\\a) (char= c #\\b)) (null (zerop b)))\n (format t \"Yes~%\")\n (decf b)\n (return-from main))\n (format t \"No~%\"))))\n", "language": "Lisp", "metadata": {"date": 1588310668, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03971.html", "problem_id": "p03971", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03971/input.txt", "sample_output_relpath": "derived/input_output/data/p03971/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03971/Lisp/s750180934.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s750180934", "user_id": "u493610446"}, "prompt_components": {"gold_output": "Yes\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nNo\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n(defmacro dp (name args memo-size &body body)\n (let ((memo (gensym)))\n `(let ((,memo (make-array ,memo-size :initial-element nil)))\n (defun ,name ,args\n (or (aref ,memo ,@args)\n (setf (aref ,memo ,@args)\n ,@body))))))\n\n(defun split (x str)\n (let ((pos (search x str))\n (size (length x)))\n (if pos\n (cons (subseq str 0 pos)\n (split x (subseq str (+ pos size))))\n (list str))))\n\n(defmacro collect-times (time body)\n `(loop repeat ,time collect ,body))\n\n(defun read-times (time)\n (collect-times time (read)))\n\n(defmacro aif (expr then else)\n `(let ((it ,expr))\n ,then\n ,else))\n\n(let ((n (read))\n (a (read))\n (b (read)))\n (loop repeat n\n for c = (read-char)\n do\n (block main\n (when (and (char= c #\\a) (null (zerop a)))\n (format t \"Yes~%\")\n (decf a)\n (return-from main))\n (when (and (or (char= c #\\a) (char= c #\\b)) (null (zerop b)))\n (format t \"Yes~%\")\n (decf b)\n (return-from main))\n (format t \"No~%\"))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these.\n\nOnly Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests.\n\nA Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B.\n\nAn overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students.\n\nA string S is assigned indicating attributes of all participants. If the i-th character of string S is a, this means the participant ranked i-th in the Qualification contests is a Japanese student; b means the participant ranked i-th is an overseas student; and c means the participant ranked i-th is neither of these.\n\nWrite a program that outputs for all the participants in descending rank either Yes if they passed the Qualification contests or No if they did not pass.\n\nConstraints\n\n1≦N,A,B≦100000\n\nA+B≦N\n\nS is N characters long.\n\nS consists only of the letters a, b and c.\n\nInput\n\nInputs are provided from Standard Input in the following form.\n\nN A B\nS\n\nOutput\n\nOutput N lines. On the i-th line, output Yes if the i-th participant passed the Qualification contests or No if that participant did not pass.\n\nSample Input 1\n\n10 2 3\nabccabaabb\n\nSample Output 1\n\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nNo\n\nThe first, second, fifth, sixth, and seventh participants pass the Qualification contests.\n\nSample Input 2\n\n12 5 2\ncabbabaacaba\n\nSample Output 2\n\nNo\nYes\nYes\nYes\nYes\nNo\nYes\nYes\nNo\nYes\nNo\nNo\n\nThe sixth participant is third among overseas students and thus does not pass the Qualification contests.\n\nSample Input 3\n\n5 2 2\nccccc\n\nSample Output 3\n\nNo\nNo\nNo\nNo\nNo", "sample_input": "10 2 3\nabccabaabb\n"}, "reference_outputs": ["Yes\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nNo\n"], "source_document_id": "p03971", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these.\n\nOnly Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests.\n\nA Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B.\n\nAn overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students.\n\nA string S is assigned indicating attributes of all participants. If the i-th character of string S is a, this means the participant ranked i-th in the Qualification contests is a Japanese student; b means the participant ranked i-th is an overseas student; and c means the participant ranked i-th is neither of these.\n\nWrite a program that outputs for all the participants in descending rank either Yes if they passed the Qualification contests or No if they did not pass.\n\nConstraints\n\n1≦N,A,B≦100000\n\nA+B≦N\n\nS is N characters long.\n\nS consists only of the letters a, b and c.\n\nInput\n\nInputs are provided from Standard Input in the following form.\n\nN A B\nS\n\nOutput\n\nOutput N lines. On the i-th line, output Yes if the i-th participant passed the Qualification contests or No if that participant did not pass.\n\nSample Input 1\n\n10 2 3\nabccabaabb\n\nSample Output 1\n\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nNo\n\nThe first, second, fifth, sixth, and seventh participants pass the Qualification contests.\n\nSample Input 2\n\n12 5 2\ncabbabaacaba\n\nSample Output 2\n\nNo\nYes\nYes\nYes\nYes\nNo\nYes\nYes\nNo\nYes\nNo\nNo\n\nThe sixth participant is third among overseas students and thus does not pass the Qualification contests.\n\nSample Input 3\n\n5 2 2\nccccc\n\nSample Output 3\n\nNo\nNo\nNo\nNo\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1605, "cpu_time_ms": 358, "memory_kb": 20284}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s091042542", "group_id": "codeNet:p03971", "input_text": "(let ((n (read))\n (a (read))\n (b (read))\n (str (read-line))\n (kokunai 0)\n (kaigai 0))\n (loop :as c :across str\n :do\n (case c\n (#\\a (if (< (+ kokunai kaigai) (+ a b))\n (progn\n (format t \"Yes~%\")\n (incf kokunai))\n (format t \"No~%\")))\n (#\\b (if (and (< (+ kokunai kaigai) (+ a b))\n (< kaigai b))\n (progn\n (format t \"Yes~%\")\n (incf kaigai))\n (format t \"No~%\")))\n (#\\c (format t \"No~%\")))))", "language": "Lisp", "metadata": {"date": 1586718013, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03971.html", "problem_id": "p03971", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03971/input.txt", "sample_output_relpath": "derived/input_output/data/p03971/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03971/Lisp/s091042542.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s091042542", "user_id": "u606976120"}, "prompt_components": {"gold_output": "Yes\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nNo\n", "input_to_evaluate": "(let ((n (read))\n (a (read))\n (b (read))\n (str (read-line))\n (kokunai 0)\n (kaigai 0))\n (loop :as c :across str\n :do\n (case c\n (#\\a (if (< (+ kokunai kaigai) (+ a b))\n (progn\n (format t \"Yes~%\")\n (incf kokunai))\n (format t \"No~%\")))\n (#\\b (if (and (< (+ kokunai kaigai) (+ a b))\n (< kaigai b))\n (progn\n (format t \"Yes~%\")\n (incf kaigai))\n (format t \"No~%\")))\n (#\\c (format t \"No~%\")))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these.\n\nOnly Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests.\n\nA Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B.\n\nAn overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students.\n\nA string S is assigned indicating attributes of all participants. If the i-th character of string S is a, this means the participant ranked i-th in the Qualification contests is a Japanese student; b means the participant ranked i-th is an overseas student; and c means the participant ranked i-th is neither of these.\n\nWrite a program that outputs for all the participants in descending rank either Yes if they passed the Qualification contests or No if they did not pass.\n\nConstraints\n\n1≦N,A,B≦100000\n\nA+B≦N\n\nS is N characters long.\n\nS consists only of the letters a, b and c.\n\nInput\n\nInputs are provided from Standard Input in the following form.\n\nN A B\nS\n\nOutput\n\nOutput N lines. On the i-th line, output Yes if the i-th participant passed the Qualification contests or No if that participant did not pass.\n\nSample Input 1\n\n10 2 3\nabccabaabb\n\nSample Output 1\n\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nNo\n\nThe first, second, fifth, sixth, and seventh participants pass the Qualification contests.\n\nSample Input 2\n\n12 5 2\ncabbabaacaba\n\nSample Output 2\n\nNo\nYes\nYes\nYes\nYes\nNo\nYes\nYes\nNo\nYes\nNo\nNo\n\nThe sixth participant is third among overseas students and thus does not pass the Qualification contests.\n\nSample Input 3\n\n5 2 2\nccccc\n\nSample Output 3\n\nNo\nNo\nNo\nNo\nNo", "sample_input": "10 2 3\nabccabaabb\n"}, "reference_outputs": ["Yes\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nNo\n"], "source_document_id": "p03971", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these.\n\nOnly Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests.\n\nA Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B.\n\nAn overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students.\n\nA string S is assigned indicating attributes of all participants. If the i-th character of string S is a, this means the participant ranked i-th in the Qualification contests is a Japanese student; b means the participant ranked i-th is an overseas student; and c means the participant ranked i-th is neither of these.\n\nWrite a program that outputs for all the participants in descending rank either Yes if they passed the Qualification contests or No if they did not pass.\n\nConstraints\n\n1≦N,A,B≦100000\n\nA+B≦N\n\nS is N characters long.\n\nS consists only of the letters a, b and c.\n\nInput\n\nInputs are provided from Standard Input in the following form.\n\nN A B\nS\n\nOutput\n\nOutput N lines. On the i-th line, output Yes if the i-th participant passed the Qualification contests or No if that participant did not pass.\n\nSample Input 1\n\n10 2 3\nabccabaabb\n\nSample Output 1\n\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nNo\n\nThe first, second, fifth, sixth, and seventh participants pass the Qualification contests.\n\nSample Input 2\n\n12 5 2\ncabbabaacaba\n\nSample Output 2\n\nNo\nYes\nYes\nYes\nYes\nNo\nYes\nYes\nNo\nYes\nNo\nNo\n\nThe sixth participant is third among overseas students and thus does not pass the Qualification contests.\n\nSample Input 3\n\n5 2 2\nccccc\n\nSample Output 3\n\nNo\nNo\nNo\nNo\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 657, "cpu_time_ms": 310, "memory_kb": 16100}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s375881237", "group_id": "codeNet:p03972", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare (inline sort))\n (let* ((h (read)) ;; swap H and W\n (w (read))\n (ps (make-array h :element-type 'uint32))\n (qs (make-array w :element-type 'uint32)))\n (dotimes (i h)\n (setf (aref ps i) (read-fixnum)))\n (dotimes (j w)\n (setf (aref qs j) (read-fixnum)))\n (setf ps (sort ps #'<)\n qs (sort qs #'<))\n (let ((y (+ h 1))\n (x (+ w 1))\n (i 0)\n (j 0)\n (res 0))\n (declare (uint32 y x i j res))\n (loop\n (cond ((and (= i h) (= j w))\n (println res)\n (return-from main))\n ((= i h)\n (incf res (* (aref qs j) y))\n (decf x)\n (incf j))\n ((= j w)\n (incf res (* (aref ps i) x))\n (decf y)\n (incf i))\n (t\n (if (< (aref qs j) (aref ps i))\n (progn (incf res (* (aref qs j) y))\n (decf x)\n (incf j))\n (progn (incf res (* (aref ps i) x))\n (decf y)\n (incf i)))))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1567107680, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03972.html", "problem_id": "p03972", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03972/input.txt", "sample_output_relpath": "derived/input_output/data/p03972/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03972/Lisp/s375881237.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s375881237", "user_id": "u352600849"}, "prompt_components": {"gold_output": "29\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare (inline sort))\n (let* ((h (read)) ;; swap H and W\n (w (read))\n (ps (make-array h :element-type 'uint32))\n (qs (make-array w :element-type 'uint32)))\n (dotimes (i h)\n (setf (aref ps i) (read-fixnum)))\n (dotimes (j w)\n (setf (aref qs j) (read-fixnum)))\n (setf ps (sort ps #'<)\n qs (sort qs #'<))\n (let ((y (+ h 1))\n (x (+ w 1))\n (i 0)\n (j 0)\n (res 0))\n (declare (uint32 y x i j res))\n (loop\n (cond ((and (= i h) (= j w))\n (println res)\n (return-from main))\n ((= i h)\n (incf res (* (aref qs j) y))\n (decf x)\n (incf j))\n ((= j w)\n (incf res (* (aref ps i) x))\n (decf y)\n (incf i))\n (t\n (if (< (aref qs j) (aref ps i))\n (progn (incf res (* (aref qs j) y))\n (decf x)\n (incf j))\n (progn (incf res (* (aref ps i) x))\n (decf y)\n (incf i)))))))))\n\n#-swank (main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nOn an xy plane, in an area satisfying 0 ≤ x ≤ W, 0 ≤ y ≤ H, there is one house at each and every point where both x and y are integers.\n\nThere are unpaved roads between every pair of points for which either the x coordinates are equal and the difference between the y coordinates is 1, or the y coordinates are equal and the difference between the x coordinates is 1.\n\nThe cost of paving a road between houses on coordinates (i,j) and (i+1,j) is p_i for any value of j, while the cost of paving a road between houses on coordinates (i,j) and (i,j+1) is q_j for any value of i.\n\nMr. Takahashi wants to pave some of these roads and be able to travel between any two houses on paved roads only. Find the solution with the minimum total cost.\n\nConstraints\n\n1 ≦ W,H ≦ 10^5\n\n1 ≦ p_i ≦ 10^8(0 ≦ i ≦ W-1)\n\n1 ≦ q_j ≦ 10^8(0 ≦ j ≦ H-1)\n\np_i (0 ≦ i ≦ W−1) is an integer.\n\nq_j (0 ≦ j ≦ H−1) is an integer.\n\nInput\n\nInputs are provided from Standard Input in the following form.\n\nW H\np_0\n:\np_{W-1}\nq_0\n:\nq_{H-1}\n\nOutput\n\nOutput an integer representing the minimum total cost.\n\nSample Input 1\n\n2 2\n3\n5\n2\n7\n\nSample Output 1\n\n29\n\nIt is enough to pave the following eight roads.\n\nRoad connecting houses at (0,0) and (0,1)\n\nRoad connecting houses at (0,1) and (1,1)\n\nRoad connecting houses at (0,2) and (1,2)\n\nRoad connecting houses at (1,0) and (1,1)\n\nRoad connecting houses at (1,0) and (2,0)\n\nRoad connecting houses at (1,1) and (1,2)\n\nRoad connecting houses at (1,2) and (2,2)\n\nRoad connecting houses at (2,0) and (2,1)\n\nSample Input 2\n\n4 3\n2\n4\n8\n1\n2\n9\n3\n\nSample Output 2\n\n60", "sample_input": "2 2\n3\n5\n2\n7\n"}, "reference_outputs": ["29\n"], "source_document_id": "p03972", "source_text": "Score : 500 points\n\nProblem Statement\n\nOn an xy plane, in an area satisfying 0 ≤ x ≤ W, 0 ≤ y ≤ H, there is one house at each and every point where both x and y are integers.\n\nThere are unpaved roads between every pair of points for which either the x coordinates are equal and the difference between the y coordinates is 1, or the y coordinates are equal and the difference between the x coordinates is 1.\n\nThe cost of paving a road between houses on coordinates (i,j) and (i+1,j) is p_i for any value of j, while the cost of paving a road between houses on coordinates (i,j) and (i,j+1) is q_j for any value of i.\n\nMr. Takahashi wants to pave some of these roads and be able to travel between any two houses on paved roads only. Find the solution with the minimum total cost.\n\nConstraints\n\n1 ≦ W,H ≦ 10^5\n\n1 ≦ p_i ≦ 10^8(0 ≦ i ≦ W-1)\n\n1 ≦ q_j ≦ 10^8(0 ≦ j ≦ H-1)\n\np_i (0 ≦ i ≦ W−1) is an integer.\n\nq_j (0 ≦ j ≦ H−1) is an integer.\n\nInput\n\nInputs are provided from Standard Input in the following form.\n\nW H\np_0\n:\np_{W-1}\nq_0\n:\nq_{H-1}\n\nOutput\n\nOutput an integer representing the minimum total cost.\n\nSample Input 1\n\n2 2\n3\n5\n2\n7\n\nSample Output 1\n\n29\n\nIt is enough to pave the following eight roads.\n\nRoad connecting houses at (0,0) and (0,1)\n\nRoad connecting houses at (0,1) and (1,1)\n\nRoad connecting houses at (0,2) and (1,2)\n\nRoad connecting houses at (1,0) and (1,1)\n\nRoad connecting houses at (1,0) and (2,0)\n\nRoad connecting houses at (1,1) and (1,2)\n\nRoad connecting houses at (1,2) and (2,2)\n\nRoad connecting houses at (2,0) and (2,1)\n\nSample Input 2\n\n4 3\n2\n4\n8\n1\n2\n9\n3\n\nSample Output 2\n\n60", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3606, "cpu_time_ms": 426, "memory_kb": 43620}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s422139888", "group_id": "codeNet:p03972", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare (inline sort))\n (let* ((w (read))\n (h (read))\n (ps (make-array h :element-type 'uint32))\n (qs (make-array w :element-type 'uint32)))\n (dotimes (i h)\n (setf (aref ps i) (read-fixnum)))\n (dotimes (j w)\n (setf (aref qs j) (read-fixnum)))\n (setf ps (sort ps #'<)\n qs (sort qs #'<))\n (let ((y (+ h 1))\n (x (+ w 1))\n (i 0)\n (j 0)\n (res 0))\n (declare (uint32 y x i j res))\n (loop\n (cond ((and (= i h) (= j w))\n (println res)\n (return-from main))\n ((= i h)\n (incf res (* (aref qs j) y))\n (decf x)\n (incf j))\n ((= j w)\n (incf res (* (aref ps i) x))\n (decf y)\n (incf i))\n (t\n (if (< (aref qs j) (aref ps i))\n (progn (incf res (* (aref qs j) y))\n (decf x)\n (incf j))\n (progn (incf res (* (aref ps i) x))\n (decf y)\n (incf i)))))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1567107602, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03972.html", "problem_id": "p03972", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03972/input.txt", "sample_output_relpath": "derived/input_output/data/p03972/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03972/Lisp/s422139888.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s422139888", "user_id": "u352600849"}, "prompt_components": {"gold_output": "29\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare (inline sort))\n (let* ((w (read))\n (h (read))\n (ps (make-array h :element-type 'uint32))\n (qs (make-array w :element-type 'uint32)))\n (dotimes (i h)\n (setf (aref ps i) (read-fixnum)))\n (dotimes (j w)\n (setf (aref qs j) (read-fixnum)))\n (setf ps (sort ps #'<)\n qs (sort qs #'<))\n (let ((y (+ h 1))\n (x (+ w 1))\n (i 0)\n (j 0)\n (res 0))\n (declare (uint32 y x i j res))\n (loop\n (cond ((and (= i h) (= j w))\n (println res)\n (return-from main))\n ((= i h)\n (incf res (* (aref qs j) y))\n (decf x)\n (incf j))\n ((= j w)\n (incf res (* (aref ps i) x))\n (decf y)\n (incf i))\n (t\n (if (< (aref qs j) (aref ps i))\n (progn (incf res (* (aref qs j) y))\n (decf x)\n (incf j))\n (progn (incf res (* (aref ps i) x))\n (decf y)\n (incf i)))))))))\n\n#-swank (main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nOn an xy plane, in an area satisfying 0 ≤ x ≤ W, 0 ≤ y ≤ H, there is one house at each and every point where both x and y are integers.\n\nThere are unpaved roads between every pair of points for which either the x coordinates are equal and the difference between the y coordinates is 1, or the y coordinates are equal and the difference between the x coordinates is 1.\n\nThe cost of paving a road between houses on coordinates (i,j) and (i+1,j) is p_i for any value of j, while the cost of paving a road between houses on coordinates (i,j) and (i,j+1) is q_j for any value of i.\n\nMr. Takahashi wants to pave some of these roads and be able to travel between any two houses on paved roads only. Find the solution with the minimum total cost.\n\nConstraints\n\n1 ≦ W,H ≦ 10^5\n\n1 ≦ p_i ≦ 10^8(0 ≦ i ≦ W-1)\n\n1 ≦ q_j ≦ 10^8(0 ≦ j ≦ H-1)\n\np_i (0 ≦ i ≦ W−1) is an integer.\n\nq_j (0 ≦ j ≦ H−1) is an integer.\n\nInput\n\nInputs are provided from Standard Input in the following form.\n\nW H\np_0\n:\np_{W-1}\nq_0\n:\nq_{H-1}\n\nOutput\n\nOutput an integer representing the minimum total cost.\n\nSample Input 1\n\n2 2\n3\n5\n2\n7\n\nSample Output 1\n\n29\n\nIt is enough to pave the following eight roads.\n\nRoad connecting houses at (0,0) and (0,1)\n\nRoad connecting houses at (0,1) and (1,1)\n\nRoad connecting houses at (0,2) and (1,2)\n\nRoad connecting houses at (1,0) and (1,1)\n\nRoad connecting houses at (1,0) and (2,0)\n\nRoad connecting houses at (1,1) and (1,2)\n\nRoad connecting houses at (1,2) and (2,2)\n\nRoad connecting houses at (2,0) and (2,1)\n\nSample Input 2\n\n4 3\n2\n4\n8\n1\n2\n9\n3\n\nSample Output 2\n\n60", "sample_input": "2 2\n3\n5\n2\n7\n"}, "reference_outputs": ["29\n"], "source_document_id": "p03972", "source_text": "Score : 500 points\n\nProblem Statement\n\nOn an xy plane, in an area satisfying 0 ≤ x ≤ W, 0 ≤ y ≤ H, there is one house at each and every point where both x and y are integers.\n\nThere are unpaved roads between every pair of points for which either the x coordinates are equal and the difference between the y coordinates is 1, or the y coordinates are equal and the difference between the x coordinates is 1.\n\nThe cost of paving a road between houses on coordinates (i,j) and (i+1,j) is p_i for any value of j, while the cost of paving a road between houses on coordinates (i,j) and (i,j+1) is q_j for any value of i.\n\nMr. Takahashi wants to pave some of these roads and be able to travel between any two houses on paved roads only. Find the solution with the minimum total cost.\n\nConstraints\n\n1 ≦ W,H ≦ 10^5\n\n1 ≦ p_i ≦ 10^8(0 ≦ i ≦ W-1)\n\n1 ≦ q_j ≦ 10^8(0 ≦ j ≦ H-1)\n\np_i (0 ≦ i ≦ W−1) is an integer.\n\nq_j (0 ≦ j ≦ H−1) is an integer.\n\nInput\n\nInputs are provided from Standard Input in the following form.\n\nW H\np_0\n:\np_{W-1}\nq_0\n:\nq_{H-1}\n\nOutput\n\nOutput an integer representing the minimum total cost.\n\nSample Input 1\n\n2 2\n3\n5\n2\n7\n\nSample Output 1\n\n29\n\nIt is enough to pave the following eight roads.\n\nRoad connecting houses at (0,0) and (0,1)\n\nRoad connecting houses at (0,1) and (1,1)\n\nRoad connecting houses at (0,2) and (1,2)\n\nRoad connecting houses at (1,0) and (1,1)\n\nRoad connecting houses at (1,0) and (2,0)\n\nRoad connecting houses at (1,1) and (1,2)\n\nRoad connecting houses at (1,2) and (2,2)\n\nRoad connecting houses at (2,0) and (2,1)\n\nSample Input 2\n\n4 3\n2\n4\n8\n1\n2\n9\n3\n\nSample Output 2\n\n60", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3590, "cpu_time_ms": 384, "memory_kb": 43624}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s405007725", "group_id": "codeNet:p03992", "input_text": "(defun in()\n (let ((s (read-char)))\n\t(if (or (eq s nil) (eq s #\\space) (eq s #\\newline))\n\t (in)\n\t s)))\n\n(defun func (x)\n (when (< x 12)\n\t(progn\n\t (when (eq x 4)\n\t\t(princ \" \"))\n\t (princ (in))\n\t (func (1+ x)))))\n\n(func 0)\n", "language": "Lisp", "metadata": {"date": 1576905120, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03992.html", "problem_id": "p03992", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03992/input.txt", "sample_output_relpath": "derived/input_output/data/p03992/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03992/Lisp/s405007725.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s405007725", "user_id": "u493610446"}, "prompt_components": {"gold_output": "CODE FESTIVAL\n", "input_to_evaluate": "(defun in()\n (let ((s (read-char)))\n\t(if (or (eq s nil) (eq s #\\space) (eq s #\\newline))\n\t (in)\n\t s)))\n\n(defun func (x)\n (when (< x 12)\n\t(progn\n\t (when (eq x 4)\n\t\t(princ \" \"))\n\t (princ (in))\n\t (func (1+ x)))))\n\n(func 0)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThis contest is CODE FESTIVAL.\nHowever, Mr. Takahashi always writes it CODEFESTIVAL, omitting the single space between CODE and FESTIVAL.\n\nSo he has decided to make a program that puts the single space he omitted.\n\nYou are given a string s with 12 letters.\nOutput the string putting a single space between the first 4 letters and last 8 letters in the string s.\n\nConstraints\n\ns contains exactly 12 letters.\n\nAll letters in s are uppercase English letters.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the string putting a single space between the first 4 letters and last 8 letters in the string s.\nPut a line break at the end.\n\nSample Input 1\n\nCODEFESTIVAL\n\nSample Output 1\n\nCODE FESTIVAL\n\nPutting a single space between the first 4 letters and last 8 letters in CODEFESTIVAL makes it CODE FESTIVAL.\n\nSample Input 2\n\nPOSTGRADUATE\n\nSample Output 2\n\nPOST GRADUATE\n\nSample Input 3\n\nABCDEFGHIJKL\n\nSample Output 3\n\nABCD EFGHIJKL", "sample_input": "CODEFESTIVAL\n"}, "reference_outputs": ["CODE FESTIVAL\n"], "source_document_id": "p03992", "source_text": "Score : 100 points\n\nProblem Statement\n\nThis contest is CODE FESTIVAL.\nHowever, Mr. Takahashi always writes it CODEFESTIVAL, omitting the single space between CODE and FESTIVAL.\n\nSo he has decided to make a program that puts the single space he omitted.\n\nYou are given a string s with 12 letters.\nOutput the string putting a single space between the first 4 letters and last 8 letters in the string s.\n\nConstraints\n\ns contains exactly 12 letters.\n\nAll letters in s are uppercase English letters.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the string putting a single space between the first 4 letters and last 8 letters in the string s.\nPut a line break at the end.\n\nSample Input 1\n\nCODEFESTIVAL\n\nSample Output 1\n\nCODE FESTIVAL\n\nPutting a single space between the first 4 letters and last 8 letters in CODEFESTIVAL makes it CODE FESTIVAL.\n\nSample Input 2\n\nPOSTGRADUATE\n\nSample Output 2\n\nPOST GRADUATE\n\nSample Input 3\n\nABCDEFGHIJKL\n\nSample Output 3\n\nABCD EFGHIJKL", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 227, "cpu_time_ms": 10, "memory_kb": 3432}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s682095526", "group_id": "codeNet:p03992", "input_text": "(defun func (x)\n (when (< x 12)\n\t(progn\n\t (when (eq x 4)\n\t\t(princ \" \"))\n\t (princ (read-char))\n\t (func (1+ x)))))\n\n(func 0)\n", "language": "Lisp", "metadata": {"date": 1576904886, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03992.html", "problem_id": "p03992", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03992/input.txt", "sample_output_relpath": "derived/input_output/data/p03992/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03992/Lisp/s682095526.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s682095526", "user_id": "u493610446"}, "prompt_components": {"gold_output": "CODE FESTIVAL\n", "input_to_evaluate": "(defun func (x)\n (when (< x 12)\n\t(progn\n\t (when (eq x 4)\n\t\t(princ \" \"))\n\t (princ (read-char))\n\t (func (1+ x)))))\n\n(func 0)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThis contest is CODE FESTIVAL.\nHowever, Mr. Takahashi always writes it CODEFESTIVAL, omitting the single space between CODE and FESTIVAL.\n\nSo he has decided to make a program that puts the single space he omitted.\n\nYou are given a string s with 12 letters.\nOutput the string putting a single space between the first 4 letters and last 8 letters in the string s.\n\nConstraints\n\ns contains exactly 12 letters.\n\nAll letters in s are uppercase English letters.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the string putting a single space between the first 4 letters and last 8 letters in the string s.\nPut a line break at the end.\n\nSample Input 1\n\nCODEFESTIVAL\n\nSample Output 1\n\nCODE FESTIVAL\n\nPutting a single space between the first 4 letters and last 8 letters in CODEFESTIVAL makes it CODE FESTIVAL.\n\nSample Input 2\n\nPOSTGRADUATE\n\nSample Output 2\n\nPOST GRADUATE\n\nSample Input 3\n\nABCDEFGHIJKL\n\nSample Output 3\n\nABCD EFGHIJKL", "sample_input": "CODEFESTIVAL\n"}, "reference_outputs": ["CODE FESTIVAL\n"], "source_document_id": "p03992", "source_text": "Score : 100 points\n\nProblem Statement\n\nThis contest is CODE FESTIVAL.\nHowever, Mr. Takahashi always writes it CODEFESTIVAL, omitting the single space between CODE and FESTIVAL.\n\nSo he has decided to make a program that puts the single space he omitted.\n\nYou are given a string s with 12 letters.\nOutput the string putting a single space between the first 4 letters and last 8 letters in the string s.\n\nConstraints\n\ns contains exactly 12 letters.\n\nAll letters in s are uppercase English letters.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the string putting a single space between the first 4 letters and last 8 letters in the string s.\nPut a line break at the end.\n\nSample Input 1\n\nCODEFESTIVAL\n\nSample Output 1\n\nCODE FESTIVAL\n\nPutting a single space between the first 4 letters and last 8 letters in CODEFESTIVAL makes it CODE FESTIVAL.\n\nSample Input 2\n\nPOSTGRADUATE\n\nSample Output 2\n\nPOST GRADUATE\n\nSample Input 3\n\nABCDEFGHIJKL\n\nSample Output 3\n\nABCD EFGHIJKL", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 127, "cpu_time_ms": 113, "memory_kb": 10852}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s567046085", "group_id": "codeNet:p03997", "input_text": "(let ((a (read))\n (b (read))\n (h (read)))\n \n (princ (/ (* h (+ a b)) 2)))\n \n", "language": "Lisp", "metadata": {"date": 1567537084, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03997.html", "problem_id": "p03997", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03997/input.txt", "sample_output_relpath": "derived/input_output/data/p03997/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03997/Lisp/s567046085.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s567046085", "user_id": "u643747754"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (h (read)))\n \n (princ (/ (* h (+ a b)) 2)))\n \n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.\n\nAn example of a trapezoid\n\nFind the area of this trapezoid.\n\nConstraints\n\n1≦a≦100\n\n1≦b≦100\n\n1≦h≦100\n\nAll input values are integers.\n\nh is even.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na\nb\nh\n\nOutput\n\nPrint the area of the given trapezoid. It is guaranteed that the area is an integer.\n\nSample Input 1\n\n3\n4\n2\n\nSample Output 1\n\n7\n\nWhen the lengths of the upper base, lower base, and height are 3, 4, and 2, respectively, the area of the trapezoid is (3+4)×2/2 = 7.\n\nSample Input 2\n\n4\n4\n4\n\nSample Output 2\n\n16\n\nIn this case, a parallelogram is given, which is also a trapezoid.", "sample_input": "3\n4\n2\n"}, "reference_outputs": ["7\n"], "source_document_id": "p03997", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.\n\nAn example of a trapezoid\n\nFind the area of this trapezoid.\n\nConstraints\n\n1≦a≦100\n\n1≦b≦100\n\n1≦h≦100\n\nAll input values are integers.\n\nh is even.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na\nb\nh\n\nOutput\n\nPrint the area of the given trapezoid. It is guaranteed that the area is an integer.\n\nSample Input 1\n\n3\n4\n2\n\nSample Output 1\n\n7\n\nWhen the lengths of the upper base, lower base, and height are 3, 4, and 2, respectively, the area of the trapezoid is (3+4)×2/2 = 7.\n\nSample Input 2\n\n4\n4\n4\n\nSample Output 2\n\n16\n\nIn this case, a parallelogram is given, which is also a trapezoid.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 100, "cpu_time_ms": 95, "memory_kb": 9700}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s382760987", "group_id": "codeNet:p03997", "input_text": "(format t \"~A~%\" (* (+ (read) (read)) (read) 1/2))", "language": "Lisp", "metadata": {"date": 1505368151, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03997.html", "problem_id": "p03997", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03997/input.txt", "sample_output_relpath": "derived/input_output/data/p03997/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03997/Lisp/s382760987.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s382760987", "user_id": "u140665374"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(format t \"~A~%\" (* (+ (read) (read)) (read) 1/2))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.\n\nAn example of a trapezoid\n\nFind the area of this trapezoid.\n\nConstraints\n\n1≦a≦100\n\n1≦b≦100\n\n1≦h≦100\n\nAll input values are integers.\n\nh is even.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na\nb\nh\n\nOutput\n\nPrint the area of the given trapezoid. It is guaranteed that the area is an integer.\n\nSample Input 1\n\n3\n4\n2\n\nSample Output 1\n\n7\n\nWhen the lengths of the upper base, lower base, and height are 3, 4, and 2, respectively, the area of the trapezoid is (3+4)×2/2 = 7.\n\nSample Input 2\n\n4\n4\n4\n\nSample Output 2\n\n16\n\nIn this case, a parallelogram is given, which is also a trapezoid.", "sample_input": "3\n4\n2\n"}, "reference_outputs": ["7\n"], "source_document_id": "p03997", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.\n\nAn example of a trapezoid\n\nFind the area of this trapezoid.\n\nConstraints\n\n1≦a≦100\n\n1≦b≦100\n\n1≦h≦100\n\nAll input values are integers.\n\nh is even.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na\nb\nh\n\nOutput\n\nPrint the area of the given trapezoid. It is guaranteed that the area is an integer.\n\nSample Input 1\n\n3\n4\n2\n\nSample Output 1\n\n7\n\nWhen the lengths of the upper base, lower base, and height are 3, 4, and 2, respectively, the area of the trapezoid is (3+4)×2/2 = 7.\n\nSample Input 2\n\n4\n4\n4\n\nSample Output 2\n\n16\n\nIn this case, a parallelogram is given, which is also a trapezoid.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 50, "cpu_time_ms": 18, "memory_kb": 3432}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s917108703", "group_id": "codeNet:p03998", "input_text": "(let ((a (concatenate 'list (read-line)))\n (b (concatenate 'list (read-line)))\n (c (concatenate 'list (read-line))))\n (defun f (chr)\n (cond ((char= #\\a chr) (if a (f (pop a)) (princ \"A\")))\n ((char= #\\b chr) (if b (f (pop b)) (princ \"B\")))\n ((char= #\\c chr) (if c (f (pop c)) (princ \"C\")))))\n (f #\\a))", "language": "Lisp", "metadata": {"date": 1555385362, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03998.html", "problem_id": "p03998", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03998/input.txt", "sample_output_relpath": "derived/input_output/data/p03998/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03998/Lisp/s917108703.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s917108703", "user_id": "u610490393"}, "prompt_components": {"gold_output": "A\n", "input_to_evaluate": "(let ((a (concatenate 'list (read-line)))\n (b (concatenate 'list (read-line)))\n (c (concatenate 'list (read-line))))\n (defun f (chr)\n (cond ((char= #\\a chr) (if a (f (pop a)) (princ \"A\")))\n ((char= #\\b chr) (if b (f (pop b)) (princ \"B\")))\n ((char= #\\c chr) (if c (f (pop c)) (princ \"C\")))))\n (f #\\a))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nAlice, Bob and Charlie are playing Card Game for Three, as below:\n\nAt first, each of the three players has a deck consisting of some number of cards. Each card has a letter a, b or c written on it. The orders of the cards in the decks cannot be rearranged.\n\nThe players take turns. Alice goes first.\n\nIf the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says a, Alice takes the next turn.)\n\nIf the current player's deck is empty, the game ends and the current player wins the game.\n\nYou are given the initial decks of the players.\nMore specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way.\n\nDetermine the winner of the game.\n\nConstraints\n\n1≦|S_A|≦100\n\n1≦|S_B|≦100\n\n1≦|S_C|≦100\n\nEach letter in S_A, S_B, S_C is a, b or c.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nS_A\nS_B\nS_C\n\nOutput\n\nIf Alice will win, print A. If Bob will win, print B. If Charlie will win, print C.\n\nSample Input 1\n\naca\naccc\nca\n\nSample Output 1\n\nA\n\nThe game will progress as below:\n\nAlice discards the top card in her deck, a. Alice takes the next turn.\n\nAlice discards the top card in her deck, c. Charlie takes the next turn.\n\nCharlie discards the top card in his deck, c. Charlie takes the next turn.\n\nCharlie discards the top card in his deck, a. Alice takes the next turn.\n\nAlice discards the top card in her deck, a. Alice takes the next turn.\n\nAlice's deck is empty. The game ends and Alice wins the game.\n\nSample Input 2\n\nabcb\naacb\nbccc\n\nSample Output 2\n\nC", "sample_input": "aca\naccc\nca\n"}, "reference_outputs": ["A\n"], "source_document_id": "p03998", "source_text": "Score : 200 points\n\nProblem Statement\n\nAlice, Bob and Charlie are playing Card Game for Three, as below:\n\nAt first, each of the three players has a deck consisting of some number of cards. Each card has a letter a, b or c written on it. The orders of the cards in the decks cannot be rearranged.\n\nThe players take turns. Alice goes first.\n\nIf the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says a, Alice takes the next turn.)\n\nIf the current player's deck is empty, the game ends and the current player wins the game.\n\nYou are given the initial decks of the players.\nMore specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way.\n\nDetermine the winner of the game.\n\nConstraints\n\n1≦|S_A|≦100\n\n1≦|S_B|≦100\n\n1≦|S_C|≦100\n\nEach letter in S_A, S_B, S_C is a, b or c.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nS_A\nS_B\nS_C\n\nOutput\n\nIf Alice will win, print A. If Bob will win, print B. If Charlie will win, print C.\n\nSample Input 1\n\naca\naccc\nca\n\nSample Output 1\n\nA\n\nThe game will progress as below:\n\nAlice discards the top card in her deck, a. Alice takes the next turn.\n\nAlice discards the top card in her deck, c. Charlie takes the next turn.\n\nCharlie discards the top card in his deck, c. Charlie takes the next turn.\n\nCharlie discards the top card in his deck, a. Alice takes the next turn.\n\nAlice discards the top card in her deck, a. Alice takes the next turn.\n\nAlice's deck is empty. The game ends and Alice wins the game.\n\nSample Input 2\n\nabcb\naacb\nbccc\n\nSample Output 2\n\nC", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 333, "cpu_time_ms": 111, "memory_kb": 11108}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s321184876", "group_id": "codeNet:p03998", "input_text": "(setq s(loop for i from 1 to 3 collect(map'list #'(lambda(c)(-(char-code c)97))(read-line))))\n(setq f 0)\n(loop\n (if(null(nth f s))(return))\n (setq v f)\n (setq f(car(nth f s)))\n (setf(nth f s)(cdr(nth f s))))\n(princ(code-char(+ f 65)))", "language": "Lisp", "metadata": {"date": 1537915781, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03998.html", "problem_id": "p03998", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03998/input.txt", "sample_output_relpath": "derived/input_output/data/p03998/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03998/Lisp/s321184876.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s321184876", "user_id": "u657913472"}, "prompt_components": {"gold_output": "A\n", "input_to_evaluate": "(setq s(loop for i from 1 to 3 collect(map'list #'(lambda(c)(-(char-code c)97))(read-line))))\n(setq f 0)\n(loop\n (if(null(nth f s))(return))\n (setq v f)\n (setq f(car(nth f s)))\n (setf(nth f s)(cdr(nth f s))))\n(princ(code-char(+ f 65)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nAlice, Bob and Charlie are playing Card Game for Three, as below:\n\nAt first, each of the three players has a deck consisting of some number of cards. Each card has a letter a, b or c written on it. The orders of the cards in the decks cannot be rearranged.\n\nThe players take turns. Alice goes first.\n\nIf the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says a, Alice takes the next turn.)\n\nIf the current player's deck is empty, the game ends and the current player wins the game.\n\nYou are given the initial decks of the players.\nMore specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way.\n\nDetermine the winner of the game.\n\nConstraints\n\n1≦|S_A|≦100\n\n1≦|S_B|≦100\n\n1≦|S_C|≦100\n\nEach letter in S_A, S_B, S_C is a, b or c.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nS_A\nS_B\nS_C\n\nOutput\n\nIf Alice will win, print A. If Bob will win, print B. If Charlie will win, print C.\n\nSample Input 1\n\naca\naccc\nca\n\nSample Output 1\n\nA\n\nThe game will progress as below:\n\nAlice discards the top card in her deck, a. Alice takes the next turn.\n\nAlice discards the top card in her deck, c. Charlie takes the next turn.\n\nCharlie discards the top card in his deck, c. Charlie takes the next turn.\n\nCharlie discards the top card in his deck, a. Alice takes the next turn.\n\nAlice discards the top card in her deck, a. Alice takes the next turn.\n\nAlice's deck is empty. The game ends and Alice wins the game.\n\nSample Input 2\n\nabcb\naacb\nbccc\n\nSample Output 2\n\nC", "sample_input": "aca\naccc\nca\n"}, "reference_outputs": ["A\n"], "source_document_id": "p03998", "source_text": "Score : 200 points\n\nProblem Statement\n\nAlice, Bob and Charlie are playing Card Game for Three, as below:\n\nAt first, each of the three players has a deck consisting of some number of cards. Each card has a letter a, b or c written on it. The orders of the cards in the decks cannot be rearranged.\n\nThe players take turns. Alice goes first.\n\nIf the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says a, Alice takes the next turn.)\n\nIf the current player's deck is empty, the game ends and the current player wins the game.\n\nYou are given the initial decks of the players.\nMore specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way.\n\nDetermine the winner of the game.\n\nConstraints\n\n1≦|S_A|≦100\n\n1≦|S_B|≦100\n\n1≦|S_C|≦100\n\nEach letter in S_A, S_B, S_C is a, b or c.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nS_A\nS_B\nS_C\n\nOutput\n\nIf Alice will win, print A. If Bob will win, print B. If Charlie will win, print C.\n\nSample Input 1\n\naca\naccc\nca\n\nSample Output 1\n\nA\n\nThe game will progress as below:\n\nAlice discards the top card in her deck, a. Alice takes the next turn.\n\nAlice discards the top card in her deck, c. Charlie takes the next turn.\n\nCharlie discards the top card in his deck, c. Charlie takes the next turn.\n\nCharlie discards the top card in his deck, a. Alice takes the next turn.\n\nAlice discards the top card in her deck, a. Alice takes the next turn.\n\nAlice's deck is empty. The game ends and Alice wins the game.\n\nSample Input 2\n\nabcb\naacb\nbccc\n\nSample Output 2\n\nC", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 238, "cpu_time_ms": 135, "memory_kb": 12772}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s489382650", "group_id": "codeNet:p03999", "input_text": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n(defun bit-full-serarch (n)\n (let ((result nil))\n (do ((bit 0 (1+ bit)))\n ((> bit (ash 1 n)))\n (let ((tmp nil))\n (do ((i 0 (1+ i)))\n ((> i n))\n (when (/= 0 (logand bit (ash 1 i)))\n (push i tmp)))\n (when tmp\n (push tmp result))\n ))\n result))\n\n(defmacro char-list-to-string-to-number (l)\n `(parse-integer (coerce ,l 'string)))\n\n(defun calc (target pos-list &optional (count 0) tmp result)\n (cond ((null target)\n (when tmp\n (let ((tmp-l (char-list-to-string-to-number (reverse tmp))))\n (if (null (listp tmp-l))\n (push tmp-l result)\n (push (reduce #'+ tmp-l) result))))\n (reverse result))\n ((and pos-list (= count (car pos-list)))\n (let ((tmp-l (char-list-to-string-to-number (reverse tmp))))\n (if (null (listp tmp-l))\n (push tmp-l result)\n (push (reduce #'+ tmp-l) result))\n (setq tmp nil))\n (push (car target) tmp)\n (calc (cdr target) (cdr pos-list) (- count 1) tmp result))\n (t\n (push (car target) tmp)\n (calc (cdr target) pos-list (- count 1) tmp result))))\n\n(defun main ()\n (let* ((target (coerce (read-line) 'list))\n (pos-list (bit-full-serarch (- (length target) 1)))\n (result 0)\n (size (- (length target) 1)))\n (dolist (x pos-list)\n (if (= size (car x))\n (let ((tmp (parse-integer (coerce target 'string))))\n (setq result (+ result tmp)))\n (let ((tmp (calc target x (- (length target) 1))))\n (setq result (+ result (reduce #'+ tmp)))\n )))\n (format t \"~A~%\" result)))", "language": "Lisp", "metadata": {"date": 1590895551, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03999.html", "problem_id": "p03999", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03999/input.txt", "sample_output_relpath": "derived/input_output/data/p03999/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03999/Lisp/s489382650.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s489382650", "user_id": "u631655863"}, "prompt_components": {"gold_output": "176\n", "input_to_evaluate": "#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n(defun bit-full-serarch (n)\n (let ((result nil))\n (do ((bit 0 (1+ bit)))\n ((> bit (ash 1 n)))\n (let ((tmp nil))\n (do ((i 0 (1+ i)))\n ((> i n))\n (when (/= 0 (logand bit (ash 1 i)))\n (push i tmp)))\n (when tmp\n (push tmp result))\n ))\n result))\n\n(defmacro char-list-to-string-to-number (l)\n `(parse-integer (coerce ,l 'string)))\n\n(defun calc (target pos-list &optional (count 0) tmp result)\n (cond ((null target)\n (when tmp\n (let ((tmp-l (char-list-to-string-to-number (reverse tmp))))\n (if (null (listp tmp-l))\n (push tmp-l result)\n (push (reduce #'+ tmp-l) result))))\n (reverse result))\n ((and pos-list (= count (car pos-list)))\n (let ((tmp-l (char-list-to-string-to-number (reverse tmp))))\n (if (null (listp tmp-l))\n (push tmp-l result)\n (push (reduce #'+ tmp-l) result))\n (setq tmp nil))\n (push (car target) tmp)\n (calc (cdr target) (cdr pos-list) (- count 1) tmp result))\n (t\n (push (car target) tmp)\n (calc (cdr target) pos-list (- count 1) tmp result))))\n\n(defun main ()\n (let* ((target (coerce (read-line) 'list))\n (pos-list (bit-full-serarch (- (length target) 1)))\n (result 0)\n (size (- (length target) 1)))\n (dolist (x pos-list)\n (if (= size (car x))\n (let ((tmp (parse-integer (coerce target 'string))))\n (setq result (+ result tmp)))\n (let ((tmp (calc target x (- (length target) 1))))\n (setq result (+ result (reduce #'+ tmp)))\n )))\n (format t \"~A~%\" result)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given a string S consisting of digits between 1 and 9, inclusive.\nYou can insert the letter + into some of the positions (possibly none) between two letters in this string.\nHere, + must not occur consecutively after insertion.\n\nAll strings that can be obtained in this way can be evaluated as formulas.\n\nEvaluate all possible formulas, and print the sum of the results.\n\nConstraints\n\n1 \\leq |S| \\leq 10\n\nAll letters in S are digits between 1 and 9, inclusive.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the sum of the evaluated value over all possible formulas.\n\nSample Input 1\n\n125\n\nSample Output 1\n\n176\n\nThere are 4 formulas that can be obtained: 125, 1+25, 12+5 and 1+2+5. When each formula is evaluated,\n\n125\n\n1+25=26\n\n12+5=17\n\n1+2+5=8\n\nThus, the sum is 125+26+17+8=176.\n\nSample Input 2\n\n9999999999\n\nSample Output 2\n\n12656242944", "sample_input": "125\n"}, "reference_outputs": ["176\n"], "source_document_id": "p03999", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given a string S consisting of digits between 1 and 9, inclusive.\nYou can insert the letter + into some of the positions (possibly none) between two letters in this string.\nHere, + must not occur consecutively after insertion.\n\nAll strings that can be obtained in this way can be evaluated as formulas.\n\nEvaluate all possible formulas, and print the sum of the results.\n\nConstraints\n\n1 \\leq |S| \\leq 10\n\nAll letters in S are digits between 1 and 9, inclusive.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the sum of the evaluated value over all possible formulas.\n\nSample Input 1\n\n125\n\nSample Output 1\n\n176\n\nThere are 4 formulas that can be obtained: 125, 1+25, 12+5 and 1+2+5. When each formula is evaluated,\n\n125\n\n1+25=26\n\n12+5=17\n\n1+2+5=8\n\nThus, the sum is 125+26+17+8=176.\n\nSample Input 2\n\n9999999999\n\nSample Output 2\n\n12656242944", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2159, "cpu_time_ms": 82, "memory_kb": 13500}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s890931625", "group_id": "codeNet:p04003", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Removes and returns the element at the front of QUEUE. Returns NIL if QUEUE\nis empty.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(define-modify-macro minf (new-value)\n (lambda (x y) (min x y)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (dists (make-hash-table :test #'equal :size (* 2 m)))\n (dist-seq (make-array n :element-type 'uint32 :initial-element #xffffffff))\n ;; ((station . color) . dist)\n (q (make-queue)))\n (declare (uint31 n m))\n (dotimes (i m)\n (let ((p (- (read-fixnum) 1))\n (q (- (read-fixnum) 1))\n (c (read-fixnum)))\n (push (cons q c) (aref graph p))\n (push (cons p c) (aref graph q))))\n (enqueue (cons (cons 0 0) 0) q)\n (setf (gethash (cons (cons 0 0) 0) dists) 0)\n (setf (aref dist-seq 0) 0)\n (loop until (queue-empty-p q)\n for element = (dequeue q)\n for (node . dist) of-type (cons . uint31) = element\n for (station . prevcolor) of-type (uint31 . uint31) = node\n do (when (= station (- n 1))\n (println dist)\n (return-from main))\n (when (or (null (gethash node dists))\n (< dist (the uint31 (gethash node dists))))\n (setf (gethash node dists) dist)\n (minf (aref dist-seq station) dist)\n (dolist (node (aref graph station))\n (let ((nextstop (car node))\n (nextcolor (cdr node)))\n (declare (uint32 nextcolor))\n (when (null (gethash node dists))\n (if (= nextcolor prevcolor)\n (when (<= dist (+ 1 (aref dist-seq nextstop)))\n (enqueue-front (cons node dist) q))\n (when (<= dist (aref dist-seq nextstop))\n (enqueue (cons node (+ dist 1)) q))))))))\n (println -1)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1566349990, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04003.html", "problem_id": "p04003", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04003/input.txt", "sample_output_relpath": "derived/input_output/data/p04003/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04003/Lisp/s890931625.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s890931625", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defstruct (queue (:constructor make-queue\n (&optional list &aux (tail (last list)))))\n (list nil :type list)\n (tail nil :type (or null (cons t null))))\n\n(declaim (inline enqueue))\n(defun enqueue (obj queue)\n \"Pushes OBJ to the end of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (setf (cdr tail) (list obj)\n tail (cdr tail))))\n queue)\n\n(declaim (inline dequeue))\n(defun dequeue (queue)\n \"Removes and returns the element at the front of QUEUE. Returns NIL if QUEUE\nis empty.\"\n (pop (queue-list queue)))\n\n(declaim (inline queue-empty-p))\n(defun queue-empty-p (queue)\n (null (queue-list queue)))\n\n(declaim (inline enqueue-front))\n(defun enqueue-front (obj queue)\n \"Pushes OBJ to the front of QUEUE.\"\n (symbol-macrolet ((list (queue-list queue))\n (tail (queue-tail queue)))\n (if (null list)\n (setf tail (list obj)\n list tail)\n (push obj list))\n queue))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(define-modify-macro minf (new-value)\n (lambda (x y) (min x y)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (dists (make-hash-table :test #'equal :size (* 2 m)))\n (dist-seq (make-array n :element-type 'uint32 :initial-element #xffffffff))\n ;; ((station . color) . dist)\n (q (make-queue)))\n (declare (uint31 n m))\n (dotimes (i m)\n (let ((p (- (read-fixnum) 1))\n (q (- (read-fixnum) 1))\n (c (read-fixnum)))\n (push (cons q c) (aref graph p))\n (push (cons p c) (aref graph q))))\n (enqueue (cons (cons 0 0) 0) q)\n (setf (gethash (cons (cons 0 0) 0) dists) 0)\n (setf (aref dist-seq 0) 0)\n (loop until (queue-empty-p q)\n for element = (dequeue q)\n for (node . dist) of-type (cons . uint31) = element\n for (station . prevcolor) of-type (uint31 . uint31) = node\n do (when (= station (- n 1))\n (println dist)\n (return-from main))\n (when (or (null (gethash node dists))\n (< dist (the uint31 (gethash node dists))))\n (setf (gethash node dists) dist)\n (minf (aref dist-seq station) dist)\n (dolist (node (aref graph station))\n (let ((nextstop (car node))\n (nextcolor (cdr node)))\n (declare (uint32 nextcolor))\n (when (null (gethash node dists))\n (if (= nextcolor prevcolor)\n (when (<= dist (+ 1 (aref dist-seq nextstop)))\n (enqueue-front (cons node dist) q))\n (when (<= dist (aref dist-seq nextstop))\n (enqueue (cons node (+ dist 1)) q))))))))\n (println -1)))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nSnuke's town has a subway system, consisting of N stations and M railway lines. The stations are numbered 1 through N. Each line is operated by a company. Each company has an identification number.\n\nThe i-th ( 1 \\leq i \\leq M ) line connects station p_i and q_i bidirectionally. There is no intermediate station. This line is operated by company c_i.\n\nYou can change trains at a station where multiple lines are available.\n\nThe fare system used in this subway system is a bit strange. When a passenger only uses lines that are operated by the same company, the fare is 1 yen (the currency of Japan). Whenever a passenger changes to a line that is operated by a different company from the current line, the passenger is charged an additional fare of 1 yen. In a case where a passenger who changed from some company A's line to another company's line changes to company A's line again, the additional fare is incurred again.\n\nSnuke is now at station 1 and wants to travel to station N by subway. Find the minimum required fare.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n0 \\leq M \\leq 2×10^5\n\n1 \\leq p_i \\leq N (1 \\leq i \\leq M)\n\n1 \\leq q_i \\leq N (1 \\leq i \\leq M)\n\n1 \\leq c_i \\leq 10^6 (1 \\leq i \\leq M)\n\np_i \\neq q_i (1 \\leq i \\leq M)\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN M\np_1 q_1 c_1\n:\np_M q_M c_M\n\nOutput\n\nPrint the minimum required fare. If it is impossible to get to station N by subway, print -1 instead.\n\nSample Input 1\n\n3 3\n1 2 1\n2 3 1\n3 1 2\n\nSample Output 1\n\n1\n\nUse company 1's lines: 1 → 2 → 3. The fare is 1 yen.\n\nSample Input 2\n\n8 11\n1 3 1\n1 4 2\n2 3 1\n2 5 1\n3 4 3\n3 6 3\n3 7 3\n4 8 4\n5 6 1\n6 7 5\n7 8 5\n\nSample Output 2\n\n2\n\nFirst, use company 1's lines: 1 → 3 → 2 → 5 → 6. Then, use company 5's lines: 6 → 7 → 8. The fare is 2 yen.\n\nSample Input 3\n\n2 0\n\nSample Output 3\n\n-1", "sample_input": "3 3\n1 2 1\n2 3 1\n3 1 2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p04003", "source_text": "Score : 600 points\n\nProblem Statement\n\nSnuke's town has a subway system, consisting of N stations and M railway lines. The stations are numbered 1 through N. Each line is operated by a company. Each company has an identification number.\n\nThe i-th ( 1 \\leq i \\leq M ) line connects station p_i and q_i bidirectionally. There is no intermediate station. This line is operated by company c_i.\n\nYou can change trains at a station where multiple lines are available.\n\nThe fare system used in this subway system is a bit strange. When a passenger only uses lines that are operated by the same company, the fare is 1 yen (the currency of Japan). Whenever a passenger changes to a line that is operated by a different company from the current line, the passenger is charged an additional fare of 1 yen. In a case where a passenger who changed from some company A's line to another company's line changes to company A's line again, the additional fare is incurred again.\n\nSnuke is now at station 1 and wants to travel to station N by subway. Find the minimum required fare.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n0 \\leq M \\leq 2×10^5\n\n1 \\leq p_i \\leq N (1 \\leq i \\leq M)\n\n1 \\leq q_i \\leq N (1 \\leq i \\leq M)\n\n1 \\leq c_i \\leq 10^6 (1 \\leq i \\leq M)\n\np_i \\neq q_i (1 \\leq i \\leq M)\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN M\np_1 q_1 c_1\n:\np_M q_M c_M\n\nOutput\n\nPrint the minimum required fare. If it is impossible to get to station N by subway, print -1 instead.\n\nSample Input 1\n\n3 3\n1 2 1\n2 3 1\n3 1 2\n\nSample Output 1\n\n1\n\nUse company 1's lines: 1 → 2 → 3. The fare is 1 yen.\n\nSample Input 2\n\n8 11\n1 3 1\n1 4 2\n2 3 1\n2 5 1\n3 4 3\n3 6 3\n3 7 3\n4 8 4\n5 6 1\n6 7 5\n7 8 5\n\nSample Output 2\n\n2\n\nFirst, use company 1's lines: 1 → 3 → 2 → 5 → 6. Then, use company 5's lines: 6 → 7 → 8. The fare is 2 yen.\n\nSample Input 3\n\n2 0\n\nSample Output 3\n\n-1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5344, "cpu_time_ms": 3160, "memory_kb": 914440}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s071190141", "group_id": "codeNet:p04005", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((a (read))\n (b (read))\n (c (read)))\n (labels ((calc (x y z)\n (* (- (ceiling x 2) (floor x 2))\n y z)))\n (println (min (calc a b c)\n (calc b c a)\n (calc c a b))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3 3\n\"\n \"9\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 2 4\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 3 5\n\"\n \"15\n\")))\n", "language": "Lisp", "metadata": {"date": 1585015897, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04005.html", "problem_id": "p04005", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04005/input.txt", "sample_output_relpath": "derived/input_output/data/p04005/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04005/Lisp/s071190141.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s071190141", "user_id": "u352600849"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((a (read))\n (b (read))\n (c (read)))\n (labels ((calc (x y z)\n (* (- (ceiling x 2) (floor x 2))\n y z)))\n (println (min (calc a b c)\n (calc b c a)\n (calc c a b))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3 3\n\"\n \"9\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 2 4\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 3 5\n\"\n \"15\n\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have a rectangular parallelepiped of size A×B×C, built with blocks of size 1×1×1. Snuke will paint each of the A×B×C blocks either red or blue, so that:\n\nThere is at least one red block and at least one blue block.\n\nThe union of all red blocks forms a rectangular parallelepiped.\n\nThe union of all blue blocks forms a rectangular parallelepiped.\n\nSnuke wants to minimize the difference between the number of red blocks and the number of blue blocks. Find the minimum possible difference.\n\nConstraints\n\n2≤A,B,C≤10^9\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the minimum possible difference between the number of red blocks and the number of blue blocks.\n\nSample Input 1\n\n3 3 3\n\nSample Output 1\n\n9\n\nFor example, Snuke can paint the blocks as shown in the diagram below.\nThere are 9 red blocks and 18 blue blocks, thus the difference is 9.\n\nSample Input 2\n\n2 2 4\n\nSample Output 2\n\n0\n\nFor example, Snuke can paint the blocks as shown in the diagram below.\nThere are 8 red blocks and 8 blue blocks, thus the difference is 0.\n\nSample Input 3\n\n5 3 5\n\nSample Output 3\n\n15\n\nFor example, Snuke can paint the blocks as shown in the diagram below.\nThere are 45 red blocks and 30 blue blocks, thus the difference is 9.", "sample_input": "3 3 3\n"}, "reference_outputs": ["9\n"], "source_document_id": "p04005", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have a rectangular parallelepiped of size A×B×C, built with blocks of size 1×1×1. Snuke will paint each of the A×B×C blocks either red or blue, so that:\n\nThere is at least one red block and at least one blue block.\n\nThe union of all red blocks forms a rectangular parallelepiped.\n\nThe union of all blue blocks forms a rectangular parallelepiped.\n\nSnuke wants to minimize the difference between the number of red blocks and the number of blue blocks. Find the minimum possible difference.\n\nConstraints\n\n2≤A,B,C≤10^9\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the minimum possible difference between the number of red blocks and the number of blue blocks.\n\nSample Input 1\n\n3 3 3\n\nSample Output 1\n\n9\n\nFor example, Snuke can paint the blocks as shown in the diagram below.\nThere are 9 red blocks and 18 blue blocks, thus the difference is 9.\n\nSample Input 2\n\n2 2 4\n\nSample Output 2\n\n0\n\nFor example, Snuke can paint the blocks as shown in the diagram below.\nThere are 8 red blocks and 8 blue blocks, thus the difference is 0.\n\nSample Input 3\n\n5 3 5\n\nSample Output 3\n\n15\n\nFor example, Snuke can paint the blocks as shown in the diagram below.\nThere are 45 red blocks and 30 blue blocks, thus the difference is 9.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3869, "cpu_time_ms": 154, "memory_kb": 18148}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s573743386", "group_id": "codeNet:p04011", "input_text": "(let ((n (read))\n (k (read))\n (x (read))\n (y (read)))\n\n (format t \"~A~%\"\n (if (<= k n)\n (+ (* k x) (* (- n k) y))\n (* n x))))\n\n", "language": "Lisp", "metadata": {"date": 1594433456, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p04011.html", "problem_id": "p04011", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04011/input.txt", "sample_output_relpath": "derived/input_output/data/p04011/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04011/Lisp/s573743386.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s573743386", "user_id": "u336541610"}, "prompt_components": {"gold_output": "48000\n", "input_to_evaluate": "(let ((n (read))\n (k (read))\n (x (read))\n (y (read)))\n\n (format t \"~A~%\"\n (if (<= k n)\n (+ (* k x) (* (- n k) y))\n (* n x))))\n\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere is a hotel with the following accommodation fee:\n\nX yen (the currency of Japan) per night, for the first K nights\n\nY yen per night, for the (K+1)-th and subsequent nights\n\nTak is staying at this hotel for N consecutive nights.\nFind his total accommodation fee.\n\nConstraints\n\n1 \\leq N, K \\leq 10000\n\n1 \\leq Y < X \\leq 10000\n\nN,\\,K,\\,X,\\,Y are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nK\nX\nY\n\nOutput\n\nPrint Tak's total accommodation fee.\n\nSample Input 1\n\n5\n3\n10000\n9000\n\nSample Output 1\n\n48000\n\nThe accommodation fee is as follows:\n\n10000 yen for the 1-st night\n\n10000 yen for the 2-nd night\n\n10000 yen for the 3-rd night\n\n9000 yen for the 4-th night\n\n9000 yen for the 5-th night\n\nThus, the total is 48000 yen.\n\nSample Input 2\n\n2\n3\n10000\n9000\n\nSample Output 2\n\n20000", "sample_input": "5\n3\n10000\n9000\n"}, "reference_outputs": ["48000\n"], "source_document_id": "p04011", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere is a hotel with the following accommodation fee:\n\nX yen (the currency of Japan) per night, for the first K nights\n\nY yen per night, for the (K+1)-th and subsequent nights\n\nTak is staying at this hotel for N consecutive nights.\nFind his total accommodation fee.\n\nConstraints\n\n1 \\leq N, K \\leq 10000\n\n1 \\leq Y < X \\leq 10000\n\nN,\\,K,\\,X,\\,Y are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nK\nX\nY\n\nOutput\n\nPrint Tak's total accommodation fee.\n\nSample Input 1\n\n5\n3\n10000\n9000\n\nSample Output 1\n\n48000\n\nThe accommodation fee is as follows:\n\n10000 yen for the 1-st night\n\n10000 yen for the 2-nd night\n\n10000 yen for the 3-rd night\n\n9000 yen for the 4-th night\n\n9000 yen for the 5-th night\n\nThus, the total is 48000 yen.\n\nSample Input 2\n\n2\n3\n10000\n9000\n\nSample Output 2\n\n20000", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 174, "cpu_time_ms": 19, "memory_kb": 23980}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s042441860", "group_id": "codeNet:p04012", "input_text": "(defun func(x)\n (or (not (car x)) (and (car x) (cdr x) (char= (car x) (cadr x)) (func (cddr x)))))\n\n(let ((x (concatenate 'list (sort (read-line) #'char<))))\n (princ (if (func x)\n\t\t \"Yes\"\n\t\t \"No\")))\n", "language": "Lisp", "metadata": {"date": 1576948863, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04012.html", "problem_id": "p04012", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04012/input.txt", "sample_output_relpath": "derived/input_output/data/p04012/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04012/Lisp/s042441860.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s042441860", "user_id": "u493610446"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun func(x)\n (or (not (car x)) (and (car x) (cdr x) (char= (car x) (cadr x)) (func (cddr x)))))\n\n(let ((x (concatenate 'list (sort (read-line) #'char<))))\n (princ (if (func x)\n\t\t \"Yes\"\n\t\t \"No\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nLet w be a string consisting of lowercase letters.\nWe will call w beautiful if the following condition is satisfied:\n\nEach lowercase letter of the English alphabet occurs even number of times in w.\n\nYou are given the string w. Determine if w is beautiful.\n\nConstraints\n\n1 \\leq |w| \\leq 100\n\nw consists of lowercase letters (a-z).\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nw\n\nOutput\n\nPrint Yes if w is beautiful. Print No otherwise.\n\nSample Input 1\n\nabaccaba\n\nSample Output 1\n\nYes\n\na occurs four times, b occurs twice, c occurs twice and the other letters occur zero times.\n\nSample Input 2\n\nhthth\n\nSample Output 2\n\nNo", "sample_input": "abaccaba\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p04012", "source_text": "Score : 200 points\n\nProblem Statement\n\nLet w be a string consisting of lowercase letters.\nWe will call w beautiful if the following condition is satisfied:\n\nEach lowercase letter of the English alphabet occurs even number of times in w.\n\nYou are given the string w. Determine if w is beautiful.\n\nConstraints\n\n1 \\leq |w| \\leq 100\n\nw consists of lowercase letters (a-z).\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nw\n\nOutput\n\nPrint Yes if w is beautiful. Print No otherwise.\n\nSample Input 1\n\nabaccaba\n\nSample Output 1\n\nYes\n\na occurs four times, b occurs twice, c occurs twice and the other letters occur zero times.\n\nSample Input 2\n\nhthth\n\nSample Output 2\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 205, "cpu_time_ms": 23, "memory_kb": 4200}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s736571744", "group_id": "codeNet:p04012", "input_text": "(let* ((str (read-line))\n (ans t))\n (map nil (lambda (n) (if (not (evenp (count n str))) (setf ans nil))))\n (if ans (princ \"Yes\") (princ \"No\")))", "language": "Lisp", "metadata": {"date": 1558730335, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04012.html", "problem_id": "p04012", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04012/input.txt", "sample_output_relpath": "derived/input_output/data/p04012/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04012/Lisp/s736571744.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s736571744", "user_id": "u610490393"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let* ((str (read-line))\n (ans t))\n (map nil (lambda (n) (if (not (evenp (count n str))) (setf ans nil))))\n (if ans (princ \"Yes\") (princ \"No\")))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nLet w be a string consisting of lowercase letters.\nWe will call w beautiful if the following condition is satisfied:\n\nEach lowercase letter of the English alphabet occurs even number of times in w.\n\nYou are given the string w. Determine if w is beautiful.\n\nConstraints\n\n1 \\leq |w| \\leq 100\n\nw consists of lowercase letters (a-z).\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nw\n\nOutput\n\nPrint Yes if w is beautiful. Print No otherwise.\n\nSample Input 1\n\nabaccaba\n\nSample Output 1\n\nYes\n\na occurs four times, b occurs twice, c occurs twice and the other letters occur zero times.\n\nSample Input 2\n\nhthth\n\nSample Output 2\n\nNo", "sample_input": "abaccaba\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p04012", "source_text": "Score : 200 points\n\nProblem Statement\n\nLet w be a string consisting of lowercase letters.\nWe will call w beautiful if the following condition is satisfied:\n\nEach lowercase letter of the English alphabet occurs even number of times in w.\n\nYou are given the string w. Determine if w is beautiful.\n\nConstraints\n\n1 \\leq |w| \\leq 100\n\nw consists of lowercase letters (a-z).\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nw\n\nOutput\n\nPrint Yes if w is beautiful. Print No otherwise.\n\nSample Input 1\n\nabaccaba\n\nSample Output 1\n\nYes\n\na occurs four times, b occurs twice, c occurs twice and the other letters occur zero times.\n\nSample Input 2\n\nhthth\n\nSample Output 2\n\nNo", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 152, "cpu_time_ms": 129, "memory_kb": 11492}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s145147409", "group_id": "codeNet:p04013", "input_text": "#|\n------------------------------------\n Utils \n------------------------------------\n|#\n\n(defconstant +mod+ 1000000007)\n\n(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (term-char #\\Space))\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let* ((,buffer (load-time-value (make-string ,buffer-size :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n ,(if (member :swank *features*)\n `(read-char ,in nil #\\Newline) ; on SLIME\n `(code-char (read-byte ,in nil #.(char-code #\\Newline))))\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,term-char))\n (return (values ,buffer ,idx))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare (inline read-byte)\n #-swank (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (read-byte in nil 0))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))\n (return (if minus (- result) result))))))))\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n(defmacro read-numbers-to-list (size)\n `(loop repeat ,size collect (read-fixnum)))\n\n(defmacro read-numbers-to-array (size)\n (let ((i (gensym))\n (arr (gensym)))\n `(let ((,arr (make-array ,size\n :element-type 'fixnum)))\n (declare ((array fixnum 1) ,arr))\n (loop for ,i of-type fixnum below ,size do\n (setf (aref ,arr ,i) (read))\n finally\n (return ,arr)))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (buffered-read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(declaim (inline unwrap))\n(defun unwrap (list)\n (the string\n (format nil \"~{~a~^ ~}\" list)))\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(defmacro maxf (place cand)\n `(setf ,place (max ,place ,cand)))\n\n(defmacro minf (place cand)\n `(setf ,place (min ,place ,cand)))\n\n(defmacro modf (place &optional (m +mod+))\n `(setf ,place (mod ,place ,m)))\n\n(defmacro alambda (parms &body body)\n `(labels ((self ,parms ,@body))\n #'self))\n\n(defun iota (count &optional (start 0) (step 1))\n (loop for i from 0 below count collect (+ start (* i step))))\n\n(defun int->lst (integer)\n (declare ((integer 0) integer))\n (labels ((sub (int &optional (acc nil))\n (declare ((integer 0) int)\n (list acc))\n (if (zerop int)\n acc\n (sub (floor int 10) (cons (rem int 10) acc)))))\n (sub integer)))\n\n(defun lst->int (list)\n (declare (list list))\n (labels ((sub (xs &optional (acc 0))\n (declare (ftype (function (list &optional (integer 0)) (integer 0)) sub))\n (declare (list xs)\n ((integer 0) acc))\n (if (null xs)\n acc\n (sub (rest xs) (+ (* acc 10)\n (rem (first xs) 10))))))\n (the fixnum\n (sub list))))\n\n(defun int->str (integer)\n (format nil \"~a\" integer))\n\n(defun str->int (str)\n (parse-integer str))\n\n(defun char->int (char)\n (declare (character char))\n (- (char-code char) #.(char-code #\\0)))\n\n(declaim (inline prime-factorize-to-list))\n(defun prime-factorize-to-list (integer)\n (declare ((integer 0) integer))\n (the list\n (if (<= integer 1)\n nil\n (loop\n while (<= (* f f) integer)\n with acc list = nil\n with f integer = 2\n do\n (if (zerop (rem integer f))\n (progn\n (push f acc)\n (setq integer (floor integer f)))\n (incf f))\n finally\n (when (/= integer 1)\n (push integer acc))\n (return (reverse acc))))))\n\n(declaim (inline prime-p))\n(defun prime-p (integer)\n (declare ((integer 1) integer))\n (if (= integer 1)\n nil\n (loop\n with f = 2\n while (<= (* f f) integer)\n do\n (when (zerop (rem integer f))\n (return nil))\n (incf f)\n finally\n (return t))))\n\n;(defconstant +mod+ 998244353)\n\n#|\n------------------------------------\n Body \n------------------------------------\n|#\n\n\n(defun solve (n a xs)\n (let ((memo (make-hash-table :test #'equal)))\n (labels ((dp (i x cnt)\n (multiple-value-bind (val win) (gethash (list i x cnt) memo)\n (cond\n ((zerop i) (if (and (zerop x)\n (zerop cnt))\n 1 0))\n ((minusp x) 0)\n ((minusp cnt) 0)\n (win val)\n (t\n (setf (gethash (list i x cnt) memo)\n (+ (dp (1- i) x cnt)\n (dp (1- i) (- x (aref xs (1- i))) (1- cnt)))))))))\n (reduce #'+\n (mapcar (lambda (c)\n (dp n (* c a) c))\n (iota n 1))))))\n\n\n(defun main ()\n (declare #.OPT)\n (let ((n (read))\n (a (read)))\n (let ((xs (read-numbers-to-array n)))\n (princ (solve n a xs))\n (fresh-line))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1600641642, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p04013.html", "problem_id": "p04013", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04013/input.txt", "sample_output_relpath": "derived/input_output/data/p04013/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04013/Lisp/s145147409.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s145147409", "user_id": "u425762225"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "#|\n------------------------------------\n Utils \n------------------------------------\n|#\n\n(defconstant +mod+ 1000000007)\n\n(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (term-char #\\Space))\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let* ((,buffer (load-time-value (make-string ,buffer-size :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n ,(if (member :swank *features*)\n `(read-char ,in nil #\\Newline) ; on SLIME\n `(code-char (read-byte ,in nil #.(char-code #\\Newline))))\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,term-char))\n (return (values ,buffer ,idx))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare (inline read-byte)\n #-swank (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (read-byte in nil 0))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))\n (return (if minus (- result) result))))))))\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n(defmacro read-numbers-to-list (size)\n `(loop repeat ,size collect (read-fixnum)))\n\n(defmacro read-numbers-to-array (size)\n (let ((i (gensym))\n (arr (gensym)))\n `(let ((,arr (make-array ,size\n :element-type 'fixnum)))\n (declare ((array fixnum 1) ,arr))\n (loop for ,i of-type fixnum below ,size do\n (setf (aref ,arr ,i) (read))\n finally\n (return ,arr)))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (buffered-read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(declaim (inline unwrap))\n(defun unwrap (list)\n (the string\n (format nil \"~{~a~^ ~}\" list)))\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(defmacro maxf (place cand)\n `(setf ,place (max ,place ,cand)))\n\n(defmacro minf (place cand)\n `(setf ,place (min ,place ,cand)))\n\n(defmacro modf (place &optional (m +mod+))\n `(setf ,place (mod ,place ,m)))\n\n(defmacro alambda (parms &body body)\n `(labels ((self ,parms ,@body))\n #'self))\n\n(defun iota (count &optional (start 0) (step 1))\n (loop for i from 0 below count collect (+ start (* i step))))\n\n(defun int->lst (integer)\n (declare ((integer 0) integer))\n (labels ((sub (int &optional (acc nil))\n (declare ((integer 0) int)\n (list acc))\n (if (zerop int)\n acc\n (sub (floor int 10) (cons (rem int 10) acc)))))\n (sub integer)))\n\n(defun lst->int (list)\n (declare (list list))\n (labels ((sub (xs &optional (acc 0))\n (declare (ftype (function (list &optional (integer 0)) (integer 0)) sub))\n (declare (list xs)\n ((integer 0) acc))\n (if (null xs)\n acc\n (sub (rest xs) (+ (* acc 10)\n (rem (first xs) 10))))))\n (the fixnum\n (sub list))))\n\n(defun int->str (integer)\n (format nil \"~a\" integer))\n\n(defun str->int (str)\n (parse-integer str))\n\n(defun char->int (char)\n (declare (character char))\n (- (char-code char) #.(char-code #\\0)))\n\n(declaim (inline prime-factorize-to-list))\n(defun prime-factorize-to-list (integer)\n (declare ((integer 0) integer))\n (the list\n (if (<= integer 1)\n nil\n (loop\n while (<= (* f f) integer)\n with acc list = nil\n with f integer = 2\n do\n (if (zerop (rem integer f))\n (progn\n (push f acc)\n (setq integer (floor integer f)))\n (incf f))\n finally\n (when (/= integer 1)\n (push integer acc))\n (return (reverse acc))))))\n\n(declaim (inline prime-p))\n(defun prime-p (integer)\n (declare ((integer 1) integer))\n (if (= integer 1)\n nil\n (loop\n with f = 2\n while (<= (* f f) integer)\n do\n (when (zerop (rem integer f))\n (return nil))\n (incf f)\n finally\n (return t))))\n\n;(defconstant +mod+ 998244353)\n\n#|\n------------------------------------\n Body \n------------------------------------\n|#\n\n\n(defun solve (n a xs)\n (let ((memo (make-hash-table :test #'equal)))\n (labels ((dp (i x cnt)\n (multiple-value-bind (val win) (gethash (list i x cnt) memo)\n (cond\n ((zerop i) (if (and (zerop x)\n (zerop cnt))\n 1 0))\n ((minusp x) 0)\n ((minusp cnt) 0)\n (win val)\n (t\n (setf (gethash (list i x cnt) memo)\n (+ (dp (1- i) x cnt)\n (dp (1- i) (- x (aref xs (1- i))) (1- cnt)))))))))\n (reduce #'+\n (mapcar (lambda (c)\n (dp n (* c a) c))\n (iota n 1))))))\n\n\n(defun main ()\n (declare #.OPT)\n (let ((n (read))\n (a (read)))\n (let ((xs (read-numbers-to-array n)))\n (princ (solve n a xs))\n (fresh-line))))\n\n#-swank (main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTak has N cards. On the i-th (1 \\leq i \\leq N) card is written an integer x_i.\nHe is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A.\nIn how many ways can he make his selection?\n\nConstraints\n\n1 \\leq N \\leq 50\n\n1 \\leq A \\leq 50\n\n1 \\leq x_i \\leq 50\n\nN,\\,A,\\,x_i are integers.\n\nPartial Score\n\n200 points will be awarded for passing the test set satisfying 1 \\leq N \\leq 16.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN A\nx_1 x_2 ... x_N\n\nOutput\n\nPrint the number of ways to select cards such that the average of the written integers is exactly A.\n\nSample Input 1\n\n4 8\n7 9 8 9\n\nSample Output 1\n\n5\n\nThe following are the 5 ways to select cards such that the average is 8:\n\nSelect the 3-rd card.\n\nSelect the 1-st and 2-nd cards.\n\nSelect the 1-st and 4-th cards.\n\nSelect the 1-st, 2-nd and 3-rd cards.\n\nSelect the 1-st, 3-rd and 4-th cards.\n\nSample Input 2\n\n3 8\n6 6 9\n\nSample Output 2\n\n0\n\nSample Input 3\n\n8 5\n3 6 2 8 7 6 5 9\n\nSample Output 3\n\n19\n\nSample Input 4\n\n33 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n\nSample Output 4\n\n8589934591\n\nThe answer may not fit into a 32-bit integer.", "sample_input": "4 8\n7 9 8 9\n"}, "reference_outputs": ["5\n"], "source_document_id": "p04013", "source_text": "Score : 300 points\n\nProblem Statement\n\nTak has N cards. On the i-th (1 \\leq i \\leq N) card is written an integer x_i.\nHe is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A.\nIn how many ways can he make his selection?\n\nConstraints\n\n1 \\leq N \\leq 50\n\n1 \\leq A \\leq 50\n\n1 \\leq x_i \\leq 50\n\nN,\\,A,\\,x_i are integers.\n\nPartial Score\n\n200 points will be awarded for passing the test set satisfying 1 \\leq N \\leq 16.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN A\nx_1 x_2 ... x_N\n\nOutput\n\nPrint the number of ways to select cards such that the average of the written integers is exactly A.\n\nSample Input 1\n\n4 8\n7 9 8 9\n\nSample Output 1\n\n5\n\nThe following are the 5 ways to select cards such that the average is 8:\n\nSelect the 3-rd card.\n\nSelect the 1-st and 2-nd cards.\n\nSelect the 1-st and 4-th cards.\n\nSelect the 1-st, 2-nd and 3-rd cards.\n\nSelect the 1-st, 3-rd and 4-th cards.\n\nSample Input 2\n\n3 8\n6 6 9\n\nSample Output 2\n\n0\n\nSample Input 3\n\n8 5\n3 6 2 8 7 6 5 9\n\nSample Output 3\n\n19\n\nSample Input 4\n\n33 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n\nSample Output 4\n\n8589934591\n\nThe answer may not fit into a 32-bit integer.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8563, "cpu_time_ms": 449, "memory_kb": 139100}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s959631464", "group_id": "codeNet:p04014", "input_text": "#|\n------------------------------------\n Utils \n------------------------------------\n|#\n\n(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (term-char #\\Space))\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let* ((,buffer (load-time-value (make-string ,buffer-size :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n ,(if (member :swank *features*)\n `(read-char ,in nil #\\Newline) ; on SLIME\n `(code-char (read-byte ,in nil #.(char-code #\\Newline))))\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,term-char))\n (return (values ,buffer ,idx))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare (inline read-byte)\n #-swank (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (read-byte in nil 0))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))\n (return (if minus (- result) result))))))))\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n(defmacro read-numbers-to-list (size)\n `(loop repeat ,size collect (read-fixnum)))\n\n(defmacro read-numbers-to-array (size)\n (let ((i (gensym))\n (arr (gensym)))\n `(let ((,arr (make-array ,size\n :element-type 'fixnum)))\n (declare ((array fixnum 1) ,arr))\n (loop for ,i of-type fixnum below ,size do\n (setf (aref ,arr ,i) (read))\n finally\n (return ,arr)))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (buffered-read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(declaim (inline unwrap))\n(defun unwrap (list)\n (the string\n (format nil \"~{~a~^ ~}\" list)))\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(defmacro maxf (place cand)\n `(setf ,place (max ,place ,cand)))\n\n(defmacro minf (place cand)\n `(setf ,place (min ,place ,cand)))\n\n(defmacro modf (place &optional (m +mod+))\n `(setf ,place (mod ,place ,m)))\n\n(defmacro alambda (parms &body body)\n `(labels ((self ,parms ,@body))\n #'self))\n\n(defun iota (count &optional (start 0) (step 1))\n (loop for i from 0 below count collect (+ start (* i step))))\n\n(defun int->lst (integer base)\n (declare ((integer 0) integer)\n ((integer 2) base))\n (labels ((sub (int b &optional (acc nil))\n (declare ((integer 0) int)\n ((integer 2) b)\n (list acc))\n (if (zerop int)\n acc\n (sub (floor int b) b (cons (rem int b) acc)))))\n (sub integer base)))\n\n(defun lst->int (list)\n (declare (list list))\n (labels ((sub (xs &optional (acc 0))\n (declare (ftype (function (list &optional (integer 0)) (integer 0)) sub))\n (declare (list xs)\n ((integer 0) acc))\n (if (null xs)\n acc\n (sub (rest xs) (+ (* acc 10)\n (rem (first xs) 10))))))\n (the fixnum\n (sub list))))\n\n(defun int->str (integer)\n (format nil \"~a\" integer))\n\n(defun str->int (str)\n (parse-integer str))\n\n(defun char->int (char)\n (declare (character char))\n (- (char-code char) #.(char-code #\\0)))\n\n(declaim (inline prime-factorize-to-list))\n(defun prime-factorize-to-list (integer)\n (declare ((integer 0) integer))\n (the list\n (if (<= integer 1)\n nil\n (loop\n while (<= (* f f) integer)\n with acc list = nil\n with f integer = 2\n do\n (if (zerop (rem integer f))\n (progn\n (push f acc)\n (setq integer (floor integer f)))\n (incf f))\n finally\n (when (/= integer 1)\n (push integer acc))\n (return (reverse acc))))))\n\n(declaim (inline prime-p))\n(defun prime-p (integer)\n (declare ((integer 1) integer))\n (if (= integer 1)\n nil\n (loop\n with f = 2\n while (<= (* f f) integer)\n do\n (when (zerop (rem integer f))\n (return nil))\n (incf f)\n finally\n (return t))))\n\n(defconstant +mod+ 1000000007)\n;(defconstant +mod+ 998244353)\n\n#|\n------------------------------------\n Body \n------------------------------------\n|#\n\n(defparameter *inf* 100000000000)\n\n\n(defun f (b n &optional (acc 0))\n (if (zerop n)\n acc\n (f b (floor n b) (+ acc (rem n b)))))\n\n(defun solve (n s)\n (if (= s n)\n (1+ n)\n (let ((ans *inf*))\n (loop\n for b from 2 to (isqrt n)\n do\n (when (= (f b n)\n s)\n (minf ans b)))\n (loop\n for p downfrom (isqrt n) to 1\n do\n (let ((b (1+ (/ (- n s) p))))\n (when (and (integerp b)\n (> b 1)\n (= (f b n) s))\n (minf ans b))))\n (if (/= ans *inf*)\n ans\n -1))))\n\n\n(defun main ()\n (declare #.OPT)\n (let ((n (read))\n (s (read)))\n (princ (solve n s))\n (fresh-line)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1600651112, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p04014.html", "problem_id": "p04014", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04014/input.txt", "sample_output_relpath": "derived/input_output/data/p04014/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04014/Lisp/s959631464.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s959631464", "user_id": "u425762225"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "#|\n------------------------------------\n Utils \n------------------------------------\n|#\n\n(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (term-char #\\Space))\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let* ((,buffer (load-time-value (make-string ,buffer-size :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n ,(if (member :swank *features*)\n `(read-char ,in nil #\\Newline) ; on SLIME\n `(code-char (read-byte ,in nil #.(char-code #\\Newline))))\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,term-char))\n (return (values ,buffer ,idx))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare (inline read-byte)\n #-swank (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (read-byte in nil 0))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))\n (return (if minus (- result) result))))))))\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n(defmacro read-numbers-to-list (size)\n `(loop repeat ,size collect (read-fixnum)))\n\n(defmacro read-numbers-to-array (size)\n (let ((i (gensym))\n (arr (gensym)))\n `(let ((,arr (make-array ,size\n :element-type 'fixnum)))\n (declare ((array fixnum 1) ,arr))\n (loop for ,i of-type fixnum below ,size do\n (setf (aref ,arr ,i) (read))\n finally\n (return ,arr)))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (buffered-read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(declaim (inline unwrap))\n(defun unwrap (list)\n (the string\n (format nil \"~{~a~^ ~}\" list)))\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(defmacro maxf (place cand)\n `(setf ,place (max ,place ,cand)))\n\n(defmacro minf (place cand)\n `(setf ,place (min ,place ,cand)))\n\n(defmacro modf (place &optional (m +mod+))\n `(setf ,place (mod ,place ,m)))\n\n(defmacro alambda (parms &body body)\n `(labels ((self ,parms ,@body))\n #'self))\n\n(defun iota (count &optional (start 0) (step 1))\n (loop for i from 0 below count collect (+ start (* i step))))\n\n(defun int->lst (integer base)\n (declare ((integer 0) integer)\n ((integer 2) base))\n (labels ((sub (int b &optional (acc nil))\n (declare ((integer 0) int)\n ((integer 2) b)\n (list acc))\n (if (zerop int)\n acc\n (sub (floor int b) b (cons (rem int b) acc)))))\n (sub integer base)))\n\n(defun lst->int (list)\n (declare (list list))\n (labels ((sub (xs &optional (acc 0))\n (declare (ftype (function (list &optional (integer 0)) (integer 0)) sub))\n (declare (list xs)\n ((integer 0) acc))\n (if (null xs)\n acc\n (sub (rest xs) (+ (* acc 10)\n (rem (first xs) 10))))))\n (the fixnum\n (sub list))))\n\n(defun int->str (integer)\n (format nil \"~a\" integer))\n\n(defun str->int (str)\n (parse-integer str))\n\n(defun char->int (char)\n (declare (character char))\n (- (char-code char) #.(char-code #\\0)))\n\n(declaim (inline prime-factorize-to-list))\n(defun prime-factorize-to-list (integer)\n (declare ((integer 0) integer))\n (the list\n (if (<= integer 1)\n nil\n (loop\n while (<= (* f f) integer)\n with acc list = nil\n with f integer = 2\n do\n (if (zerop (rem integer f))\n (progn\n (push f acc)\n (setq integer (floor integer f)))\n (incf f))\n finally\n (when (/= integer 1)\n (push integer acc))\n (return (reverse acc))))))\n\n(declaim (inline prime-p))\n(defun prime-p (integer)\n (declare ((integer 1) integer))\n (if (= integer 1)\n nil\n (loop\n with f = 2\n while (<= (* f f) integer)\n do\n (when (zerop (rem integer f))\n (return nil))\n (incf f)\n finally\n (return t))))\n\n(defconstant +mod+ 1000000007)\n;(defconstant +mod+ 998244353)\n\n#|\n------------------------------------\n Body \n------------------------------------\n|#\n\n(defparameter *inf* 100000000000)\n\n\n(defun f (b n &optional (acc 0))\n (if (zerop n)\n acc\n (f b (floor n b) (+ acc (rem n b)))))\n\n(defun solve (n s)\n (if (= s n)\n (1+ n)\n (let ((ans *inf*))\n (loop\n for b from 2 to (isqrt n)\n do\n (when (= (f b n)\n s)\n (minf ans b)))\n (loop\n for p downfrom (isqrt n) to 1\n do\n (let ((b (1+ (/ (- n s) p))))\n (when (and (integerp b)\n (> b 1)\n (= (f b n) s))\n (minf ans b))))\n (if (/= ans *inf*)\n ans\n -1))))\n\n\n(defun main ()\n (declare #.OPT)\n (let ((n (read))\n (s (read)))\n (princ (solve n s))\n (fresh-line)))\n\n#-swank (main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nFor integers b (b \\geq 2) and n (n \\geq 1), let the function f(b,n) be defined as follows:\n\nf(b,n) = n, when n < b\n\nf(b,n) = f(b,\\,{\\rm floor}(n / b)) + (n \\ {\\rm mod} \\ b), when n \\geq b\n\nHere, {\\rm floor}(n / b) denotes the largest integer not exceeding n / b,\nand n \\ {\\rm mod} \\ b denotes the remainder of n divided by b.\n\nLess formally, f(b,n) is equal to the sum of the digits of n written in base b.\nFor example, the following hold:\n\nf(10,\\,87654)=8+7+6+5+4=30\n\nf(100,\\,87654)=8+76+54=138\n\nYou are given integers n and s.\nDetermine if there exists an integer b (b \\geq 2) such that f(b,n)=s.\nIf the answer is positive, also find the smallest such b.\n\nConstraints\n\n1 \\leq n \\leq 10^{11}\n\n1 \\leq s \\leq 10^{11}\n\nn,\\,s are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nn\ns\n\nOutput\n\nIf there exists an integer b (b \\geq 2) such that f(b,n)=s, print the smallest such b.\nIf such b does not exist, print -1 instead.\n\nSample Input 1\n\n87654\n30\n\nSample Output 1\n\n10\n\nSample Input 2\n\n87654\n138\n\nSample Output 2\n\n100\n\nSample Input 3\n\n87654\n45678\n\nSample Output 3\n\n-1\n\nSample Input 4\n\n31415926535\n1\n\nSample Output 4\n\n31415926535\n\nSample Input 5\n\n1\n31415926535\n\nSample Output 5\n\n-1", "sample_input": "87654\n30\n"}, "reference_outputs": ["10\n"], "source_document_id": "p04014", "source_text": "Score : 500 points\n\nProblem Statement\n\nFor integers b (b \\geq 2) and n (n \\geq 1), let the function f(b,n) be defined as follows:\n\nf(b,n) = n, when n < b\n\nf(b,n) = f(b,\\,{\\rm floor}(n / b)) + (n \\ {\\rm mod} \\ b), when n \\geq b\n\nHere, {\\rm floor}(n / b) denotes the largest integer not exceeding n / b,\nand n \\ {\\rm mod} \\ b denotes the remainder of n divided by b.\n\nLess formally, f(b,n) is equal to the sum of the digits of n written in base b.\nFor example, the following hold:\n\nf(10,\\,87654)=8+7+6+5+4=30\n\nf(100,\\,87654)=8+76+54=138\n\nYou are given integers n and s.\nDetermine if there exists an integer b (b \\geq 2) such that f(b,n)=s.\nIf the answer is positive, also find the smallest such b.\n\nConstraints\n\n1 \\leq n \\leq 10^{11}\n\n1 \\leq s \\leq 10^{11}\n\nn,\\,s are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nn\ns\n\nOutput\n\nIf there exists an integer b (b \\geq 2) such that f(b,n)=s, print the smallest such b.\nIf such b does not exist, print -1 instead.\n\nSample Input 1\n\n87654\n30\n\nSample Output 1\n\n10\n\nSample Input 2\n\n87654\n138\n\nSample Output 2\n\n100\n\nSample Input 3\n\n87654\n45678\n\nSample Output 3\n\n-1\n\nSample Input 4\n\n31415926535\n1\n\nSample Output 4\n\n31415926535\n\nSample Input 5\n\n1\n31415926535\n\nSample Output 5\n\n-1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8500, "cpu_time_ms": 160, "memory_kb": 46084}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s857207583", "group_id": "codeNet:p04014", "input_text": "#|\n------------------------------------\n Utils \n------------------------------------\n|#\n\n(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (term-char #\\Space))\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let* ((,buffer (load-time-value (make-string ,buffer-size :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n ,(if (member :swank *features*)\n `(read-char ,in nil #\\Newline) ; on SLIME\n `(code-char (read-byte ,in nil #.(char-code #\\Newline))))\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,term-char))\n (return (values ,buffer ,idx))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare (inline read-byte)\n #-swank (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (read-byte in nil 0))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))\n (return (if minus (- result) result))))))))\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n(defmacro read-numbers-to-list (size)\n `(loop repeat ,size collect (read-fixnum)))\n\n(defmacro read-numbers-to-array (size)\n (let ((i (gensym))\n (arr (gensym)))\n `(let ((,arr (make-array ,size\n :element-type 'fixnum)))\n (declare ((array fixnum 1) ,arr))\n (loop for ,i of-type fixnum below ,size do\n (setf (aref ,arr ,i) (read))\n finally\n (return ,arr)))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (buffered-read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(declaim (inline unwrap))\n(defun unwrap (list)\n (the string\n (format nil \"~{~a~^ ~}\" list)))\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(defmacro maxf (place cand)\n `(setf ,place (max ,place ,cand)))\n\n(defmacro minf (place cand)\n `(setf ,place (min ,place ,cand)))\n\n(defmacro modf (place &optional (m +mod+))\n `(setf ,place (mod ,place ,m)))\n\n(defmacro alambda (parms &body body)\n `(labels ((self ,parms ,@body))\n #'self))\n\n(defun iota (count &optional (start 0) (step 1))\n (loop for i from 0 below count collect (+ start (* i step))))\n\n(defun int->lst (integer base)\n (declare ((integer 0) integer)\n ((integer 2) base))\n (labels ((sub (int b &optional (acc nil))\n (declare ((integer 0) int)\n ((integer 2) b)\n (list acc))\n (if (zerop int)\n acc\n (sub (floor int b) b (cons (rem int b) acc)))))\n (sub integer base)))\n\n(defun lst->int (list)\n (declare (list list))\n (labels ((sub (xs &optional (acc 0))\n (declare (ftype (function (list &optional (integer 0)) (integer 0)) sub))\n (declare (list xs)\n ((integer 0) acc))\n (if (null xs)\n acc\n (sub (rest xs) (+ (* acc 10)\n (rem (first xs) 10))))))\n (the fixnum\n (sub list))))\n\n(defun int->str (integer)\n (format nil \"~a\" integer))\n\n(defun str->int (str)\n (parse-integer str))\n\n(defun char->int (char)\n (declare (character char))\n (- (char-code char) #.(char-code #\\0)))\n\n(declaim (inline prime-factorize-to-list))\n(defun prime-factorize-to-list (integer)\n (declare ((integer 0) integer))\n (the list\n (if (<= integer 1)\n nil\n (loop\n while (<= (* f f) integer)\n with acc list = nil\n with f integer = 2\n do\n (if (zerop (rem integer f))\n (progn\n (push f acc)\n (setq integer (floor integer f)))\n (incf f))\n finally\n (when (/= integer 1)\n (push integer acc))\n (return (reverse acc))))))\n\n(declaim (inline prime-p))\n(defun prime-p (integer)\n (declare ((integer 1) integer))\n (if (= integer 1)\n nil\n (loop\n with f = 2\n while (<= (* f f) integer)\n do\n (when (zerop (rem integer f))\n (return nil))\n (incf f)\n finally\n (return t))))\n\n(defconstant +mod+ 1000000007)\n;(defconstant +mod+ 998244353)\n\n#|\n------------------------------------\n Body \n------------------------------------\n|#\n\n(defparameter *inf* 100000000000)\n\n\n(defun f (b n &optional (acc 0))\n (if (zerop n)\n acc\n (f b (floor n b) (+ acc (rem n b)))))\n\n(defun solve (n s)\n (if (= s n)\n (1+ n)\n (let ((ans *inf*))\n (loop\n for b from 2 to (isqrt n)\n do\n (when (= (f b n)\n s)\n (minf ans b)))\n (loop\n for p downfrom (isqrt n) to 1\n do\n (let ((b (1+ (/ (- n s) p))))\n (when (and (integerp b)\n (/= b 1)\n (= (f b n) s))\n (minf ans b))))\n (if (/= ans *inf*)\n ans\n -1))))\n\n\n(defun main ()\n (declare #.OPT)\n (let ((n (read))\n (s (read)))\n (princ (solve n s))\n (fresh-line)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1600650837, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p04014.html", "problem_id": "p04014", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04014/input.txt", "sample_output_relpath": "derived/input_output/data/p04014/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04014/Lisp/s857207583.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s857207583", "user_id": "u425762225"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "#|\n------------------------------------\n Utils \n------------------------------------\n|#\n\n(in-package :cl-user)\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n#-swank\n(unless (member :child-sbcl *features*)\n (quit\n :unix-status\n (process-exit-code\n (run-program *runtime-pathname*\n `(\"--control-stack-size\" \"128MB\"\n \"--noinform\" \"--disable-ldb\" \"--lose-on-corruption\" \"--end-runtime-options\"\n \"--eval\" \"(push :child-sbcl *features*)\"\n \"--script\" ,(namestring *load-pathname*))\n :output t :error t :input t))))\n\n\n\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~a\" b)) () '(signed-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~a\" b)) () '(unsigned-byte ,b))) bits)))\n\n(define-int-types 2 4 8 16 32 64)\n\n(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (term-char #\\Space))\n (let ((buffer (gensym))\n (character (gensym))\n (idx (gensym)))\n `(let* ((,buffer (load-time-value (make-string ,buffer-size :element-type 'base-char))))\n (declare (simple-base-string ,buffer)\n (inline read-byte))\n (loop for ,character of-type base-char =\n ,(if (member :swank *features*)\n `(read-char ,in nil #\\Newline) ; on SLIME\n `(code-char (read-byte ,in nil #.(char-code #\\Newline))))\n for ,idx from 0\n until (char= ,character #\\Newline)\n do (setf (schar ,buffer ,idx) ,character)\n finally (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,term-char))\n (return (values ,buffer ,idx))))))\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (declare (inline read-byte)\n #-swank (sb-kernel:ansi-stream in))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (read-byte in nil 0))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))\n (return (if minus (- result) result))))))))\n\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1\n (write obj :stream stream)\n (fresh-line stream))))\n\n(defmacro safe-sort (list test &key (key #'identity))\n `(progn\n (declaim (inline sort sb-impl::stable-sort-list))\n (sort (copy-seq ,list) ,test :key ,key)))\n\n(defmacro read-numbers-to-list (size)\n `(loop repeat ,size collect (read-fixnum)))\n\n(defmacro read-numbers-to-array (size)\n (let ((i (gensym))\n (arr (gensym)))\n `(let ((,arr (make-array ,size\n :element-type 'fixnum)))\n (declare ((array fixnum 1) ,arr))\n (loop for ,i of-type fixnum below ,size do\n (setf (aref ,arr ,i) (read))\n finally\n (return ,arr)))))\n\n(defmacro read-characters-to-board (row-size column-size)\n (let ((board (gensym))\n (r (gensym))\n (c (gensym))\n (tmp (gensym)))\n `(let ((,board (make-array '(,row-size ,column-size) :element-type 'character :adjustable nil)))\n (dotimes (,r ,row-size ,board)\n (let ((,tmp (buffered-read-line)))\n (dotimes (,c ,column-size)\n (setf (aref ,board ,r ,c) (char ,tmp ,c))))))))\n\n(defmethod princ-for-each-line ((sequence list))\n (format t \"~{~a~&~}\" sequence))\n\n(defmethod princ-for-each-line ((sequence vector))\n (loop for i below (length sequence) do\n (princ (aref sequence i))\n (fresh-line)))\n\n(declaim (inline unwrap))\n(defun unwrap (list)\n (the string\n (format nil \"~{~a~^ ~}\" list)))\n\n(defmacro with-buffered-stdout (&body body)\n (let ((out (gensym)))\n `(let ((,out (make-string-output-stream :element-type 'base-char)))\n (let ((*standard-output* ,out))\n ,@body)\n (write-string (get-output-stream-string ,out)))))\n\n(defmacro maxf (place cand)\n `(setf ,place (max ,place ,cand)))\n\n(defmacro minf (place cand)\n `(setf ,place (min ,place ,cand)))\n\n(defmacro modf (place &optional (m +mod+))\n `(setf ,place (mod ,place ,m)))\n\n(defmacro alambda (parms &body body)\n `(labels ((self ,parms ,@body))\n #'self))\n\n(defun iota (count &optional (start 0) (step 1))\n (loop for i from 0 below count collect (+ start (* i step))))\n\n(defun int->lst (integer base)\n (declare ((integer 0) integer)\n ((integer 2) base))\n (labels ((sub (int b &optional (acc nil))\n (declare ((integer 0) int)\n ((integer 2) b)\n (list acc))\n (if (zerop int)\n acc\n (sub (floor int b) b (cons (rem int b) acc)))))\n (sub integer base)))\n\n(defun lst->int (list)\n (declare (list list))\n (labels ((sub (xs &optional (acc 0))\n (declare (ftype (function (list &optional (integer 0)) (integer 0)) sub))\n (declare (list xs)\n ((integer 0) acc))\n (if (null xs)\n acc\n (sub (rest xs) (+ (* acc 10)\n (rem (first xs) 10))))))\n (the fixnum\n (sub list))))\n\n(defun int->str (integer)\n (format nil \"~a\" integer))\n\n(defun str->int (str)\n (parse-integer str))\n\n(defun char->int (char)\n (declare (character char))\n (- (char-code char) #.(char-code #\\0)))\n\n(declaim (inline prime-factorize-to-list))\n(defun prime-factorize-to-list (integer)\n (declare ((integer 0) integer))\n (the list\n (if (<= integer 1)\n nil\n (loop\n while (<= (* f f) integer)\n with acc list = nil\n with f integer = 2\n do\n (if (zerop (rem integer f))\n (progn\n (push f acc)\n (setq integer (floor integer f)))\n (incf f))\n finally\n (when (/= integer 1)\n (push integer acc))\n (return (reverse acc))))))\n\n(declaim (inline prime-p))\n(defun prime-p (integer)\n (declare ((integer 1) integer))\n (if (= integer 1)\n nil\n (loop\n with f = 2\n while (<= (* f f) integer)\n do\n (when (zerop (rem integer f))\n (return nil))\n (incf f)\n finally\n (return t))))\n\n(defconstant +mod+ 1000000007)\n;(defconstant +mod+ 998244353)\n\n#|\n------------------------------------\n Body \n------------------------------------\n|#\n\n(defparameter *inf* 100000000000)\n\n\n(defun f (b n &optional (acc 0))\n (if (zerop n)\n acc\n (f b (floor n b) (+ acc (rem n b)))))\n\n(defun solve (n s)\n (if (= s n)\n (1+ n)\n (let ((ans *inf*))\n (loop\n for b from 2 to (isqrt n)\n do\n (when (= (f b n)\n s)\n (minf ans b)))\n (loop\n for p downfrom (isqrt n) to 1\n do\n (let ((b (1+ (/ (- n s) p))))\n (when (and (integerp b)\n (/= b 1)\n (= (f b n) s))\n (minf ans b))))\n (if (/= ans *inf*)\n ans\n -1))))\n\n\n(defun main ()\n (declare #.OPT)\n (let ((n (read))\n (s (read)))\n (princ (solve n s))\n (fresh-line)))\n\n#-swank (main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nFor integers b (b \\geq 2) and n (n \\geq 1), let the function f(b,n) be defined as follows:\n\nf(b,n) = n, when n < b\n\nf(b,n) = f(b,\\,{\\rm floor}(n / b)) + (n \\ {\\rm mod} \\ b), when n \\geq b\n\nHere, {\\rm floor}(n / b) denotes the largest integer not exceeding n / b,\nand n \\ {\\rm mod} \\ b denotes the remainder of n divided by b.\n\nLess formally, f(b,n) is equal to the sum of the digits of n written in base b.\nFor example, the following hold:\n\nf(10,\\,87654)=8+7+6+5+4=30\n\nf(100,\\,87654)=8+76+54=138\n\nYou are given integers n and s.\nDetermine if there exists an integer b (b \\geq 2) such that f(b,n)=s.\nIf the answer is positive, also find the smallest such b.\n\nConstraints\n\n1 \\leq n \\leq 10^{11}\n\n1 \\leq s \\leq 10^{11}\n\nn,\\,s are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nn\ns\n\nOutput\n\nIf there exists an integer b (b \\geq 2) such that f(b,n)=s, print the smallest such b.\nIf such b does not exist, print -1 instead.\n\nSample Input 1\n\n87654\n30\n\nSample Output 1\n\n10\n\nSample Input 2\n\n87654\n138\n\nSample Output 2\n\n100\n\nSample Input 3\n\n87654\n45678\n\nSample Output 3\n\n-1\n\nSample Input 4\n\n31415926535\n1\n\nSample Output 4\n\n31415926535\n\nSample Input 5\n\n1\n31415926535\n\nSample Output 5\n\n-1", "sample_input": "87654\n30\n"}, "reference_outputs": ["10\n"], "source_document_id": "p04014", "source_text": "Score : 500 points\n\nProblem Statement\n\nFor integers b (b \\geq 2) and n (n \\geq 1), let the function f(b,n) be defined as follows:\n\nf(b,n) = n, when n < b\n\nf(b,n) = f(b,\\,{\\rm floor}(n / b)) + (n \\ {\\rm mod} \\ b), when n \\geq b\n\nHere, {\\rm floor}(n / b) denotes the largest integer not exceeding n / b,\nand n \\ {\\rm mod} \\ b denotes the remainder of n divided by b.\n\nLess formally, f(b,n) is equal to the sum of the digits of n written in base b.\nFor example, the following hold:\n\nf(10,\\,87654)=8+7+6+5+4=30\n\nf(100,\\,87654)=8+76+54=138\n\nYou are given integers n and s.\nDetermine if there exists an integer b (b \\geq 2) such that f(b,n)=s.\nIf the answer is positive, also find the smallest such b.\n\nConstraints\n\n1 \\leq n \\leq 10^{11}\n\n1 \\leq s \\leq 10^{11}\n\nn,\\,s are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nn\ns\n\nOutput\n\nIf there exists an integer b (b \\geq 2) such that f(b,n)=s, print the smallest such b.\nIf such b does not exist, print -1 instead.\n\nSample Input 1\n\n87654\n30\n\nSample Output 1\n\n10\n\nSample Input 2\n\n87654\n138\n\nSample Output 2\n\n100\n\nSample Input 3\n\n87654\n45678\n\nSample Output 3\n\n-1\n\nSample Input 4\n\n31415926535\n1\n\nSample Output 4\n\n31415926535\n\nSample Input 5\n\n1\n31415926535\n\nSample Output 5\n\n-1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8501, "cpu_time_ms": 162, "memory_kb": 47856}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s888840394", "group_id": "codeNet:p04016", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; Below is the variant that returns a sorted list.\n(defun enum-divisors (n)\n \"Returns the increasing list of all the divisors of N.\"\n (declare #.OPT\n ((integer 1 #.most-positive-fixnum) n))\n (if (= n 1)\n (list 1)\n (let* ((sqrt (isqrt n))\n (result (list 1)))\n (labels ((%enum (i first-half second-half)\n (declare ((integer 1 #.most-positive-fixnum) i))\n (cond ((or (< i sqrt)\n (and (= i sqrt) (/= (* sqrt sqrt) n)))\n (multiple-value-bind (quot rem) (floor n i)\n (if (zerop rem)\n (progn\n (setf (cdr first-half) (list i))\n (setf second-half (cons quot second-half))\n (%enum (1+ i) (cdr first-half) second-half))\n (%enum (1+ i) first-half second-half))))\n ((= i sqrt) ; N is a square number here\n (setf (cdr first-half) (cons i second-half)))\n (t ; (> i sqrt)\n (setf (cdr first-half) second-half)))))\n (%enum 2 result (list n))\n result))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(declaim (ftype (function * (values uint62 &optional)) calc))\n(defun calc (b n)\n (declare #.OPT\n (uint62 b n)\n (values uint62))\n (if (< n b)\n n\n (multiple-value-bind (quot rem) (floor n b)\n (+ rem (calc b quot)))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (s (read))\n (sqrt (+ 1 (isqrt (- n 1)))))\n (declare (uint62 n s sqrt))\n (println\n (cond ((> s n) -1)\n ((= s n) (+ n 1))\n (t (loop for b from 2 to sqrt\n when (= s (calc b n))\n do (return b))\n (let ((divisors (enum-divisors (- n s))))\n (dolist (div divisors -1)\n (let ((b (+ div 1)))\n (when (= s (calc b n))\n (return b))))))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1564368278, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04016.html", "problem_id": "p04016", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04016/input.txt", "sample_output_relpath": "derived/input_output/data/p04016/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04016/Lisp/s888840394.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s888840394", "user_id": "u352600849"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n;; Below is the variant that returns a sorted list.\n(defun enum-divisors (n)\n \"Returns the increasing list of all the divisors of N.\"\n (declare #.OPT\n ((integer 1 #.most-positive-fixnum) n))\n (if (= n 1)\n (list 1)\n (let* ((sqrt (isqrt n))\n (result (list 1)))\n (labels ((%enum (i first-half second-half)\n (declare ((integer 1 #.most-positive-fixnum) i))\n (cond ((or (< i sqrt)\n (and (= i sqrt) (/= (* sqrt sqrt) n)))\n (multiple-value-bind (quot rem) (floor n i)\n (if (zerop rem)\n (progn\n (setf (cdr first-half) (list i))\n (setf second-half (cons quot second-half))\n (%enum (1+ i) (cdr first-half) second-half))\n (%enum (1+ i) first-half second-half))))\n ((= i sqrt) ; N is a square number here\n (setf (cdr first-half) (cons i second-half)))\n (t ; (> i sqrt)\n (setf (cdr first-half) second-half)))))\n (%enum 2 result (list n))\n result))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(declaim (ftype (function * (values uint62 &optional)) calc))\n(defun calc (b n)\n (declare #.OPT\n (uint62 b n)\n (values uint62))\n (if (< n b)\n n\n (multiple-value-bind (quot rem) (floor n b)\n (+ rem (calc b quot)))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (s (read))\n (sqrt (+ 1 (isqrt (- n 1)))))\n (declare (uint62 n s sqrt))\n (println\n (cond ((> s n) -1)\n ((= s n) (+ n 1))\n (t (loop for b from 2 to sqrt\n when (= s (calc b n))\n do (return b))\n (let ((divisors (enum-divisors (- n s))))\n (dolist (div divisors -1)\n (let ((b (+ div 1)))\n (when (= s (calc b n))\n (return b))))))))))\n\n#-swank (main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nFor integers b (b \\geq 2) and n (n \\geq 1), let the function f(b,n) be defined as follows:\n\nf(b,n) = n, when n < b\n\nf(b,n) = f(b,\\,{\\rm floor}(n / b)) + (n \\ {\\rm mod} \\ b), when n \\geq b\n\nHere, {\\rm floor}(n / b) denotes the largest integer not exceeding n / b,\nand n \\ {\\rm mod} \\ b denotes the remainder of n divided by b.\n\nLess formally, f(b,n) is equal to the sum of the digits of n written in base b.\nFor example, the following hold:\n\nf(10,\\,87654)=8+7+6+5+4=30\n\nf(100,\\,87654)=8+76+54=138\n\nYou are given integers n and s.\nDetermine if there exists an integer b (b \\geq 2) such that f(b,n)=s.\nIf the answer is positive, also find the smallest such b.\n\nConstraints\n\n1 \\leq n \\leq 10^{11}\n\n1 \\leq s \\leq 10^{11}\n\nn,\\,s are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nn\ns\n\nOutput\n\nIf there exists an integer b (b \\geq 2) such that f(b,n)=s, print the smallest such b.\nIf such b does not exist, print -1 instead.\n\nSample Input 1\n\n87654\n30\n\nSample Output 1\n\n10\n\nSample Input 2\n\n87654\n138\n\nSample Output 2\n\n100\n\nSample Input 3\n\n87654\n45678\n\nSample Output 3\n\n-1\n\nSample Input 4\n\n31415926535\n1\n\nSample Output 4\n\n31415926535\n\nSample Input 5\n\n1\n31415926535\n\nSample Output 5\n\n-1", "sample_input": "87654\n30\n"}, "reference_outputs": ["10\n"], "source_document_id": "p04016", "source_text": "Score : 500 points\n\nProblem Statement\n\nFor integers b (b \\geq 2) and n (n \\geq 1), let the function f(b,n) be defined as follows:\n\nf(b,n) = n, when n < b\n\nf(b,n) = f(b,\\,{\\rm floor}(n / b)) + (n \\ {\\rm mod} \\ b), when n \\geq b\n\nHere, {\\rm floor}(n / b) denotes the largest integer not exceeding n / b,\nand n \\ {\\rm mod} \\ b denotes the remainder of n divided by b.\n\nLess formally, f(b,n) is equal to the sum of the digits of n written in base b.\nFor example, the following hold:\n\nf(10,\\,87654)=8+7+6+5+4=30\n\nf(100,\\,87654)=8+76+54=138\n\nYou are given integers n and s.\nDetermine if there exists an integer b (b \\geq 2) such that f(b,n)=s.\nIf the answer is positive, also find the smallest such b.\n\nConstraints\n\n1 \\leq n \\leq 10^{11}\n\n1 \\leq s \\leq 10^{11}\n\nn,\\,s are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nn\ns\n\nOutput\n\nIf there exists an integer b (b \\geq 2) such that f(b,n)=s, print the smallest such b.\nIf such b does not exist, print -1 instead.\n\nSample Input 1\n\n87654\n30\n\nSample Output 1\n\n10\n\nSample Input 2\n\n87654\n138\n\nSample Output 2\n\n100\n\nSample Input 3\n\n87654\n45678\n\nSample Output 3\n\n-1\n\nSample Input 4\n\n31415926535\n1\n\nSample Output 4\n\n31415926535\n\nSample Input 5\n\n1\n31415926535\n\nSample Output 5\n\n-1", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3368, "cpu_time_ms": 166, "memory_kb": 18408}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s111166118", "group_id": "codeNet:p04020", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (as (loop repeat n collect (read-fixnum)))\n (res 0))\n (loop for rest on as\n do (multiple-value-bind (quot rem) (floor (first rest) 2)\n (incf res quot)\n (when (cdr rest)\n (let ((min (min rem (second rest))))\n (incf res min)\n (decf (second rest) min)))))\n (println res)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n4\n0\n3\n2\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n2\n0\n1\n6\n0\n8\n2\n1\n\"\n \"9\n\")))\n", "language": "Lisp", "metadata": {"date": 1585195067, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04020.html", "problem_id": "p04020", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04020/input.txt", "sample_output_relpath": "derived/input_output/data/p04020/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04020/Lisp/s111166118.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s111166118", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (as (loop repeat n collect (read-fixnum)))\n (res 0))\n (loop for rest on as\n do (multiple-value-bind (quot rem) (floor (first rest) 2)\n (incf res quot)\n (when (cdr rest)\n (let ((min (min rem (second rest))))\n (incf res min)\n (decf (second rest) min)))))\n (println res)))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n4\n0\n3\n2\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n2\n0\n1\n6\n0\n8\n2\n1\n\"\n \"9\n\")))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nSnuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it.\nHe has A_i cards with an integer i.\n\nTwo cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.\n\nSnuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.\n\nConstraints\n\n1 ≦ N ≦ 10^5\n\n0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)\n\nAll input values are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nA_1\n:\nA_N\n\nOutput\n\nPrint the maximum number of pairs that Snuke can create.\n\nSample Input 1\n\n4\n4\n0\n3\n2\n\nSample Output 1\n\n4\n\nFor example, Snuke can create the following four pairs: (1,1),(1,1),(3,4),(3,4).\n\nSample Input 2\n\n8\n2\n0\n1\n6\n0\n8\n2\n1\n\nSample Output 2\n\n9", "sample_input": "4\n4\n0\n3\n2\n"}, "reference_outputs": ["4\n"], "source_document_id": "p04020", "source_text": "Score : 400 points\n\nProblem Statement\n\nSnuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it.\nHe has A_i cards with an integer i.\n\nTwo cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.\n\nSnuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.\n\nConstraints\n\n1 ≦ N ≦ 10^5\n\n0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)\n\nAll input values are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nA_1\n:\nA_N\n\nOutput\n\nPrint the maximum number of pairs that Snuke can create.\n\nSample Input 1\n\n4\n4\n0\n3\n2\n\nSample Output 1\n\n4\n\nFor example, Snuke can create the following four pairs: (1,1),(1,1),(3,4),(3,4).\n\nSample Input 2\n\n8\n2\n0\n1\n6\n0\n8\n2\n1\n\nSample Output 2\n\n9", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5122, "cpu_time_ms": 274, "memory_kb": 24424}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s208692067", "group_id": "codeNet:p04022", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(declaim (ftype (function * (values simple-bit-vector &optional)) make-prime-table))\n(defun make-prime-table (sup)\n \"Returns a simple-bit-vector of length SUP, whose (0-based) i-th bit is 1 if i\nis prime and 0 otherwise.\n\nExample: (make-prime-table 10) => #*0011010100\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-array sup :element-type 'bit :initial-element 0))\n (sup/64 (ceiling sup 64)))\n ;; special treatment for p = 2\n (dotimes (i sup/64)\n (setf (sb-kernel:%vector-raw-bits table i) #xAAAAAAAAAAAAAAAA))\n (setf (sbit table 1) 0\n (sbit table 2) 1)\n ;; p >= 3\n (loop for p from 3 to (+ 1 (isqrt (- sup 1))) by 2\n when (= 1 (sbit table p))\n do (loop for composite from (* p p) below sup by p\n do (setf (sbit table composite) 0)))\n table))\n\n;; FIXME: Currently the element type of the resultant vector is (UNSIGNED-BYTE 62).\n(declaim (ftype (function * (values (simple-array (integer 0 #.most-positive-fixnum) (*))\n simple-bit-vector\n &optional))\n make-prime-sequence))\n(defun make-prime-sequence (sup)\n \"Returns the ascending sequence of primes smaller than SUP.\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-prime-table sup)))\n (let* ((length (count 1 table))\n (result (make-array length :element-type '(integer 0 #.most-positive-fixnum)))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) length))\n (loop for x below sup\n when (= 1 (sbit table x))\n do (setf (aref result index) x)\n (incf index))\n (values result table))))\n\n(defstruct (prime-data (:constructor %make-prime-data (seq table)))\n (seq nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n (table nil :type simple-bit-vector))\n\n(defun make-prime-data (sup)\n (multiple-value-call #'%make-prime-data (make-prime-sequence sup)))\n\n(declaim (inline factorize)\n (ftype (function * (values list &optional)) factorize))\n(defun factorize (x prime-data)\n \"Returns the associative list of prime factors of X, which is composed\nof ( . ). E.g. (factorize 40 ) => '((2 . 3) (5\n. 1)).\n\n- Any numbers beyond the range of PRIME-DATA are regarded as prime.\n- The returned list is in descending order w.r.t. prime factors.\"\n (declare (integer x))\n (setq x (abs x))\n (when (<= x 1)\n (return-from factorize nil))\n (let ((prime-seq (prime-data-seq prime-data))\n result)\n (loop for prime of-type unsigned-byte across prime-seq\n do (when (= x 1)\n (return-from factorize result))\n (loop for exponent of-type (integer 0 #.most-positive-fixnum) from 0\n do (multiple-value-bind (quot rem) (floor x prime)\n (if (zerop rem)\n (setf x quot)\n (progn\n (when (> exponent 0)\n (push (cons prime exponent) result))\n (loop-finish))))))\n (if (= x 1)\n result\n (cons (cons x 1) result))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n(defun rho (n)\n (declare #.OPT\n (uint62 n))\n (let ((m (ash 1 (integer-length n))))\n (macrolet ((f (x) `(let ((xx ,x)) (mod (+ c (* xx xx)) n))))\n (loop for c from 1 below 99\n for y of-type uint62 = 2\n for r of-type uint62 = 1\n for q of-type uint62 = 1\n for g of-type uint62 = 1\n for ys of-type uint62 = y\n for x of-type uint62 = y\n do (loop while (= g 1)\n do (setq x y)\n (dotimes (_ r)\n (setq y (f y)))\n (let ((k 0))\n (declare (uint62 k))\n (loop while (and (< k r) (= g 1))\n do (setq ys y)\n (dotimes (_ (min m (- r k)))\n (setq y (f y)\n q (mod (* q (abs (- x y))) n)))\n (setq g (gcd q n))\n (incf k m)))\n (setq r (ash r 1)))\n (when (= g n)\n (loop while (= g 1)\n do (setq ys (f ys)\n g (gcd (abs (- x ys)) n))))\n (when (< g n)\n (return g))))))\n\n(defconstant +max+ 2160)\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (pdata (make-prime-data +max+))\n (table (make-hash-table :test #'equal))\n (null-count 0))\n (declare (uint32 n null-count))\n (labels\n ((%factorize (s)\n (let ((factors (factorize s pdata)))\n (and factors\n (let ((largest (caar factors)))\n (declare (uint62 largest))\n (if (< largest +max+)\n factors\n (let ((sqrt (isqrt largest)))\n (if (= (* sqrt sqrt) largest)\n (cons (cons sqrt 2) (cdr factors))\n factors)))))))\n (add (factors)\n (cond ((null factors)\n (incf null-count))\n ((= 1 (cdar factors))\n (if (gethash factors table)\n (incf (car (gethash factors table)))\n (setf (gethash factors table) (cons 1 0))))\n (t\n (let ((factors (loop for (p . exp) of-type (uint62 . uint62) in factors\n collect (cons p (- 3 exp)))))\n (if (gethash factors table)\n (incf (cdr (gethash factors table)))\n (setf (gethash factors table) (cons 0 1))))))))\n (dotimes (i n)\n (let* ((s (read-fixnum))\n (factors (loop for (p . exp) of-type (uint62 . uint62) in (%factorize s)\n unless (zerop (mod exp 3))\n collect (cons p (mod exp 3)))))\n (add factors)))\n (println\n (+ (min null-count 1)\n (loop for (count1 . count2) being each hash-value of table\n sum (max count1 count2)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n1\n2\n3\n4\n5\n6\n7\n8\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n2\n4\n8\n16\n32\n64\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\"\n \"9\n\")))\n", "language": "Lisp", "metadata": {"date": 1585114556, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04022.html", "problem_id": "p04022", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04022/input.txt", "sample_output_relpath": "derived/input_output/data/p04022/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04022/Lisp/s208692067.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s208692067", "user_id": "u352600849"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(declaim (ftype (function * (values simple-bit-vector &optional)) make-prime-table))\n(defun make-prime-table (sup)\n \"Returns a simple-bit-vector of length SUP, whose (0-based) i-th bit is 1 if i\nis prime and 0 otherwise.\n\nExample: (make-prime-table 10) => #*0011010100\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-array sup :element-type 'bit :initial-element 0))\n (sup/64 (ceiling sup 64)))\n ;; special treatment for p = 2\n (dotimes (i sup/64)\n (setf (sb-kernel:%vector-raw-bits table i) #xAAAAAAAAAAAAAAAA))\n (setf (sbit table 1) 0\n (sbit table 2) 1)\n ;; p >= 3\n (loop for p from 3 to (+ 1 (isqrt (- sup 1))) by 2\n when (= 1 (sbit table p))\n do (loop for composite from (* p p) below sup by p\n do (setf (sbit table composite) 0)))\n table))\n\n;; FIXME: Currently the element type of the resultant vector is (UNSIGNED-BYTE 62).\n(declaim (ftype (function * (values (simple-array (integer 0 #.most-positive-fixnum) (*))\n simple-bit-vector\n &optional))\n make-prime-sequence))\n(defun make-prime-sequence (sup)\n \"Returns the ascending sequence of primes smaller than SUP.\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-prime-table sup)))\n (let* ((length (count 1 table))\n (result (make-array length :element-type '(integer 0 #.most-positive-fixnum)))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) length))\n (loop for x below sup\n when (= 1 (sbit table x))\n do (setf (aref result index) x)\n (incf index))\n (values result table))))\n\n(defstruct (prime-data (:constructor %make-prime-data (seq table)))\n (seq nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n (table nil :type simple-bit-vector))\n\n(defun make-prime-data (sup)\n (multiple-value-call #'%make-prime-data (make-prime-sequence sup)))\n\n(declaim (inline factorize)\n (ftype (function * (values list &optional)) factorize))\n(defun factorize (x prime-data)\n \"Returns the associative list of prime factors of X, which is composed\nof ( . ). E.g. (factorize 40 ) => '((2 . 3) (5\n. 1)).\n\n- Any numbers beyond the range of PRIME-DATA are regarded as prime.\n- The returned list is in descending order w.r.t. prime factors.\"\n (declare (integer x))\n (setq x (abs x))\n (when (<= x 1)\n (return-from factorize nil))\n (let ((prime-seq (prime-data-seq prime-data))\n result)\n (loop for prime of-type unsigned-byte across prime-seq\n do (when (= x 1)\n (return-from factorize result))\n (loop for exponent of-type (integer 0 #.most-positive-fixnum) from 0\n do (multiple-value-bind (quot rem) (floor x prime)\n (if (zerop rem)\n (setf x quot)\n (progn\n (when (> exponent 0)\n (push (cons prime exponent) result))\n (loop-finish))))))\n (if (= x 1)\n result\n (cons (cons x 1) result))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n(defun rho (n)\n (declare #.OPT\n (uint62 n))\n (let ((m (ash 1 (integer-length n))))\n (macrolet ((f (x) `(let ((xx ,x)) (mod (+ c (* xx xx)) n))))\n (loop for c from 1 below 99\n for y of-type uint62 = 2\n for r of-type uint62 = 1\n for q of-type uint62 = 1\n for g of-type uint62 = 1\n for ys of-type uint62 = y\n for x of-type uint62 = y\n do (loop while (= g 1)\n do (setq x y)\n (dotimes (_ r)\n (setq y (f y)))\n (let ((k 0))\n (declare (uint62 k))\n (loop while (and (< k r) (= g 1))\n do (setq ys y)\n (dotimes (_ (min m (- r k)))\n (setq y (f y)\n q (mod (* q (abs (- x y))) n)))\n (setq g (gcd q n))\n (incf k m)))\n (setq r (ash r 1)))\n (when (= g n)\n (loop while (= g 1)\n do (setq ys (f ys)\n g (gcd (abs (- x ys)) n))))\n (when (< g n)\n (return g))))))\n\n(defconstant +max+ 2160)\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (pdata (make-prime-data +max+))\n (table (make-hash-table :test #'equal))\n (null-count 0))\n (declare (uint32 n null-count))\n (labels\n ((%factorize (s)\n (let ((factors (factorize s pdata)))\n (and factors\n (let ((largest (caar factors)))\n (declare (uint62 largest))\n (if (< largest +max+)\n factors\n (let ((sqrt (isqrt largest)))\n (if (= (* sqrt sqrt) largest)\n (cons (cons sqrt 2) (cdr factors))\n factors)))))))\n (add (factors)\n (cond ((null factors)\n (incf null-count))\n ((= 1 (cdar factors))\n (if (gethash factors table)\n (incf (car (gethash factors table)))\n (setf (gethash factors table) (cons 1 0))))\n (t\n (let ((factors (loop for (p . exp) of-type (uint62 . uint62) in factors\n collect (cons p (- 3 exp)))))\n (if (gethash factors table)\n (incf (cdr (gethash factors table)))\n (setf (gethash factors table) (cons 0 1))))))))\n (dotimes (i n)\n (let* ((s (read-fixnum))\n (factors (loop for (p . exp) of-type (uint62 . uint62) in (%factorize s)\n unless (zerop (mod exp 3))\n collect (cons p (mod exp 3)))))\n (add factors)))\n (println\n (+ (min null-count 1)\n (loop for (count1 . count2) being each hash-value of table\n sum (max count1 count2)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n1\n2\n3\n4\n5\n6\n7\n8\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n2\n4\n8\n16\n32\n64\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\"\n \"9\n\")))\n", "problem_context": "Score : 1100 points\n\nProblem Statement\n\nSnuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.\n\nHe will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.\n\nFind the maximum number of integers that Snuke can circle.\n\nConstraints\n\n1 ≦ N ≦ 10^5\n\n1 ≦ s_i ≦ 10^{10}\n\nAll input values are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\ns_1\n:\ns_N\n\nOutput\n\nPrint the maximum number of integers that Snuke can circle.\n\nSample Input 1\n\n8\n1\n2\n3\n4\n5\n6\n7\n8\n\nSample Output 1\n\n6\n\nSnuke can circle 1,2,3,5,6,7.\n\nSample Input 2\n\n6\n2\n4\n8\n16\n32\n64\n\nSample Output 2\n\n3\n\nSample Input 3\n\n10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\nSample Output 3\n\n9", "sample_input": "8\n1\n2\n3\n4\n5\n6\n7\n8\n"}, "reference_outputs": ["6\n"], "source_document_id": "p04022", "source_text": "Score : 1100 points\n\nProblem Statement\n\nSnuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.\n\nHe will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.\n\nFind the maximum number of integers that Snuke can circle.\n\nConstraints\n\n1 ≦ N ≦ 10^5\n\n1 ≦ s_i ≦ 10^{10}\n\nAll input values are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\ns_1\n:\ns_N\n\nOutput\n\nPrint the maximum number of integers that Snuke can circle.\n\nSample Input 1\n\n8\n1\n2\n3\n4\n5\n6\n7\n8\n\nSample Output 1\n\n6\n\nSnuke can circle 1,2,3,5,6,7.\n\nSample Input 2\n\n6\n2\n4\n8\n16\n32\n64\n\nSample Output 2\n\n3\n\nSample Input 3\n\n10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\nSample Output 3\n\n9", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11335, "cpu_time_ms": 998, "memory_kb": 70756}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s868554973", "group_id": "codeNet:p04022", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(declaim (ftype (function * (values simple-bit-vector &optional)) make-prime-table))\n(defun make-prime-table (sup)\n \"Returns a simple-bit-vector of length SUP, whose (0-based) i-th bit is 1 if i\nis prime and 0 otherwise.\n\nExample: (make-prime-table 10) => #*0011010100\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-array sup :element-type 'bit :initial-element 0))\n (sup/64 (ceiling sup 64)))\n ;; special treatment for p = 2\n (dotimes (i sup/64)\n (setf (sb-kernel:%vector-raw-bits table i) #xAAAAAAAAAAAAAAAA))\n (setf (sbit table 1) 0\n (sbit table 2) 1)\n ;; p >= 3\n (loop for p from 3 to (+ 1 (isqrt (- sup 1))) by 2\n when (= 1 (sbit table p))\n do (loop for composite from (* p p) below sup by p\n do (setf (sbit table composite) 0)))\n table))\n\n;; FIXME: Currently the element type of the resultant vector is (UNSIGNED-BYTE 62).\n(declaim (ftype (function * (values (simple-array (integer 0 #.most-positive-fixnum) (*))\n simple-bit-vector\n &optional))\n make-prime-sequence))\n(defun make-prime-sequence (sup)\n \"Returns the ascending sequence of primes smaller than SUP.\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-prime-table sup)))\n (let* ((length (count 1 table))\n (result (make-array length :element-type '(integer 0 #.most-positive-fixnum)))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) length))\n (loop for x below sup\n when (= 1 (sbit table x))\n do (setf (aref result index) x)\n (incf index))\n (values result table))))\n\n(defstruct (prime-data (:constructor %make-prime-data (seq table)))\n (seq nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n (table nil :type simple-bit-vector))\n\n(defun make-prime-data (sup)\n (multiple-value-call #'%make-prime-data (make-prime-sequence sup)))\n\n(declaim (inline factorize)\n (ftype (function * (values list &optional)) factorize))\n(defun factorize (x prime-data)\n \"Returns the associative list of prime factors of X, which is composed\nof ( . ). E.g. (factorize 40 ) => '((2 . 3) (5\n. 1)).\n\n- Any numbers beyond the range of PRIME-DATA are regarded as prime.\n- The returned list is in descending order w.r.t. prime factors.\"\n (declare (integer x))\n (setq x (abs x))\n (when (<= x 1)\n (return-from factorize nil))\n (let ((prime-seq (prime-data-seq prime-data))\n result)\n (loop for prime of-type unsigned-byte across prime-seq\n do (when (= x 1)\n (return-from factorize result))\n (loop for exponent of-type (integer 0 #.most-positive-fixnum) from 0\n do (multiple-value-bind (quot rem) (floor x prime)\n (if (zerop rem)\n (setf x quot)\n (progn\n (when (> exponent 0)\n (push (cons prime exponent) result))\n (loop-finish))))))\n (if (= x 1)\n result\n (cons (cons x 1) result))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n;; TODO: more efficient handling when modulus is (unsigned-byte 31) or\n;; (unsigned-byte 32)\n(declaim (inline mod-power))\n(defun mod-power (base power modulus)\n \"BASE := integer\nPOWER, MODULUS := non-negative fixnum\"\n (declare ((integer 0 #.most-positive-fixnum) modulus power)\n (integer base))\n (if (= modulus 1)\n 0\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) x p)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (cond ((zerop p) 1)\n ((evenp p) (recur (mod (* x x) modulus) (ash p -1)))\n (t (mod (* x (recur x (- p 1))) modulus)))))\n (recur (mod base modulus) power))))\n\n(defun %strong-probable-prime-p (n base)\n (declare (optimize (speed 3))\n ((unsigned-byte 62) n base))\n (or (= n base) ; KLUDGE: is it really approriate to put this form here?\n (let ((d (floor (- n 1) (logand (- n 1) (- 1 n)))))\n (labels ((mod-power (base power)\n (declare ((unsigned-byte 62) base power)\n #+sbcl (values (unsigned-byte 62) &optional))\n (cond ((zerop power) 1)\n ((evenp power)\n (mod-power (mod (* base base) n) (ash power -1)))\n (t (mod (* base (mod-power base (- power 1))) n)))))\n (let ((y (mod-power base d)))\n (declare ((unsigned-byte 62) y))\n (or (= y 1)\n (= y (- n 1))\n (let ((s (- (integer-length (logand (- n 1) (- 1 n))) 1)))\n (loop repeat (- s 1)\n do (setq y (mod (* y y) n))\n (when (<= y 1) (return nil))\n (when (= y (- n 1)) (return t))))))))))\n\n;; https://primes.utm.edu/prove/prove2_3.html\n;; TODO: more efficient SPRP\n(defun prime-p (n)\n (cond ((<= n 1) nil)\n ((evenp n) (= n 2))\n ((< n 4759123141)\n (loop for base in '(2 7 61)\n always (%strong-probable-prime-p n base)))\n ((< n 341550071728321)\n (loop for base in '(2 3 5 7 11 13 17)\n always (%strong-probable-prime-p n base)))\n (t\n (loop for base in '(2 3 5 7 11 13 17 19 23 29)\n always (%strong-probable-prime-p n base)))))\n\n(defun rho (n)\n (declare #.OPT\n (uint62 n))\n (let ((m (ash 1 (integer-length n))))\n (macrolet ((f (x) `(let ((xx ,x)) (mod (+ c (* xx xx)) n))))\n (loop for c from 1 below 99\n for y of-type uint62 = 2\n for r of-type uint62 = 1\n for q of-type uint62 = 1\n for g of-type uint62 = 1\n for ys of-type uint62 = y\n for x of-type uint62 = y\n do (loop while (= g 1)\n do (setq x y)\n (dotimes (_ r)\n (setq y (f y)))\n (let ((k 0))\n (declare (uint62 k))\n (loop while (and (< k r) (= g 1))\n do (setq ys y)\n (dotimes (_ (min m (- r k)))\n (setq y (f y)\n q (mod (* q (abs (- x y))) n)))\n (setq g (gcd q n))\n (incf k m)))\n (setq r (ash r 1)))\n (when (= g n)\n (loop while (= g 1)\n do (setq ys (f ys)\n g (gcd (abs (- x ys)) n))))\n (when (< g n)\n (return g))))))\n\n(defconstant +max+ 2500)\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (pdata (make-prime-data +max+))\n (table (make-hash-table :test #'equal))\n (null-count 0))\n (declare (uint32 n null-count))\n (labels\n ((%factorize (s)\n (let ((factors (factorize s pdata)))\n (if (null factors)\n nil\n (let ((largest (caar factors)))\n (declare (uint62 largest))\n (cond ((< largest +max+) factors)\n ((prime-p largest) factors)\n (t\n (let* ((p1 (rho largest))\n (p2 (floor largest p1)))\n (cond ((> p1 p2)\n (cons (cons p1 1) (cons (cons p2 1) (cdr factors))))\n ((< p1 p2)\n (cons (cons p2 1) (cons (cons p1 1) (cdr factors))))\n (t\n (cons (cons p1 2) (cdr factors)))))))))))\n (add (factors)\n (cond ((null factors)\n (incf null-count))\n ((= 1 (cdar factors))\n (if (gethash factors table)\n (incf (car (gethash factors table)))\n (setf (gethash factors table) (cons 1 0))))\n (t\n (let ((factors (loop for (p . exp) of-type (uint62 . uint62) in factors\n collect (cons p (- 3 exp)))))\n (if (gethash factors table)\n (incf (cdr (gethash factors table)))\n (setf (gethash factors table) (cons 0 1))))))))\n (dotimes (i n)\n (let* ((s (read-fixnum))\n (factors (loop for (p . exp) of-type (uint62 . uint62) in (%factorize s)\n unless (zerop (mod exp 3))\n collect (cons p (mod exp 3)))))\n (add factors)))\n (println\n (+ (min null-count 1)\n (loop for (count1 . count2) being each hash-value of table\n sum (max count1 count2)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n1\n2\n3\n4\n5\n6\n7\n8\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n2\n4\n8\n16\n32\n64\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\"\n \"9\n\")))\n", "language": "Lisp", "metadata": {"date": 1585015433, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04022.html", "problem_id": "p04022", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04022/input.txt", "sample_output_relpath": "derived/input_output/data/p04022/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04022/Lisp/s868554973.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s868554973", "user_id": "u352600849"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(declaim (ftype (function * (values simple-bit-vector &optional)) make-prime-table))\n(defun make-prime-table (sup)\n \"Returns a simple-bit-vector of length SUP, whose (0-based) i-th bit is 1 if i\nis prime and 0 otherwise.\n\nExample: (make-prime-table 10) => #*0011010100\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-array sup :element-type 'bit :initial-element 0))\n (sup/64 (ceiling sup 64)))\n ;; special treatment for p = 2\n (dotimes (i sup/64)\n (setf (sb-kernel:%vector-raw-bits table i) #xAAAAAAAAAAAAAAAA))\n (setf (sbit table 1) 0\n (sbit table 2) 1)\n ;; p >= 3\n (loop for p from 3 to (+ 1 (isqrt (- sup 1))) by 2\n when (= 1 (sbit table p))\n do (loop for composite from (* p p) below sup by p\n do (setf (sbit table composite) 0)))\n table))\n\n;; FIXME: Currently the element type of the resultant vector is (UNSIGNED-BYTE 62).\n(declaim (ftype (function * (values (simple-array (integer 0 #.most-positive-fixnum) (*))\n simple-bit-vector\n &optional))\n make-prime-sequence))\n(defun make-prime-sequence (sup)\n \"Returns the ascending sequence of primes smaller than SUP.\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-prime-table sup)))\n (let* ((length (count 1 table))\n (result (make-array length :element-type '(integer 0 #.most-positive-fixnum)))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) length))\n (loop for x below sup\n when (= 1 (sbit table x))\n do (setf (aref result index) x)\n (incf index))\n (values result table))))\n\n(defstruct (prime-data (:constructor %make-prime-data (seq table)))\n (seq nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n (table nil :type simple-bit-vector))\n\n(defun make-prime-data (sup)\n (multiple-value-call #'%make-prime-data (make-prime-sequence sup)))\n\n(declaim (inline factorize)\n (ftype (function * (values list &optional)) factorize))\n(defun factorize (x prime-data)\n \"Returns the associative list of prime factors of X, which is composed\nof ( . ). E.g. (factorize 40 ) => '((2 . 3) (5\n. 1)).\n\n- Any numbers beyond the range of PRIME-DATA are regarded as prime.\n- The returned list is in descending order w.r.t. prime factors.\"\n (declare (integer x))\n (setq x (abs x))\n (when (<= x 1)\n (return-from factorize nil))\n (let ((prime-seq (prime-data-seq prime-data))\n result)\n (loop for prime of-type unsigned-byte across prime-seq\n do (when (= x 1)\n (return-from factorize result))\n (loop for exponent of-type (integer 0 #.most-positive-fixnum) from 0\n do (multiple-value-bind (quot rem) (floor x prime)\n (if (zerop rem)\n (setf x quot)\n (progn\n (when (> exponent 0)\n (push (cons prime exponent) result))\n (loop-finish))))))\n (if (= x 1)\n result\n (cons (cons x 1) result))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n;; TODO: more efficient handling when modulus is (unsigned-byte 31) or\n;; (unsigned-byte 32)\n(declaim (inline mod-power))\n(defun mod-power (base power modulus)\n \"BASE := integer\nPOWER, MODULUS := non-negative fixnum\"\n (declare ((integer 0 #.most-positive-fixnum) modulus power)\n (integer base))\n (if (= modulus 1)\n 0\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) x p)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (cond ((zerop p) 1)\n ((evenp p) (recur (mod (* x x) modulus) (ash p -1)))\n (t (mod (* x (recur x (- p 1))) modulus)))))\n (recur (mod base modulus) power))))\n\n(defun %strong-probable-prime-p (n base)\n (declare (optimize (speed 3))\n ((unsigned-byte 62) n base))\n (or (= n base) ; KLUDGE: is it really approriate to put this form here?\n (let ((d (floor (- n 1) (logand (- n 1) (- 1 n)))))\n (labels ((mod-power (base power)\n (declare ((unsigned-byte 62) base power)\n #+sbcl (values (unsigned-byte 62) &optional))\n (cond ((zerop power) 1)\n ((evenp power)\n (mod-power (mod (* base base) n) (ash power -1)))\n (t (mod (* base (mod-power base (- power 1))) n)))))\n (let ((y (mod-power base d)))\n (declare ((unsigned-byte 62) y))\n (or (= y 1)\n (= y (- n 1))\n (let ((s (- (integer-length (logand (- n 1) (- 1 n))) 1)))\n (loop repeat (- s 1)\n do (setq y (mod (* y y) n))\n (when (<= y 1) (return nil))\n (when (= y (- n 1)) (return t))))))))))\n\n;; https://primes.utm.edu/prove/prove2_3.html\n;; TODO: more efficient SPRP\n(defun prime-p (n)\n (cond ((<= n 1) nil)\n ((evenp n) (= n 2))\n ((< n 4759123141)\n (loop for base in '(2 7 61)\n always (%strong-probable-prime-p n base)))\n ((< n 341550071728321)\n (loop for base in '(2 3 5 7 11 13 17)\n always (%strong-probable-prime-p n base)))\n (t\n (loop for base in '(2 3 5 7 11 13 17 19 23 29)\n always (%strong-probable-prime-p n base)))))\n\n(defun rho (n)\n (declare #.OPT\n (uint62 n))\n (let ((m (ash 1 (integer-length n))))\n (macrolet ((f (x) `(let ((xx ,x)) (mod (+ c (* xx xx)) n))))\n (loop for c from 1 below 99\n for y of-type uint62 = 2\n for r of-type uint62 = 1\n for q of-type uint62 = 1\n for g of-type uint62 = 1\n for ys of-type uint62 = y\n for x of-type uint62 = y\n do (loop while (= g 1)\n do (setq x y)\n (dotimes (_ r)\n (setq y (f y)))\n (let ((k 0))\n (declare (uint62 k))\n (loop while (and (< k r) (= g 1))\n do (setq ys y)\n (dotimes (_ (min m (- r k)))\n (setq y (f y)\n q (mod (* q (abs (- x y))) n)))\n (setq g (gcd q n))\n (incf k m)))\n (setq r (ash r 1)))\n (when (= g n)\n (loop while (= g 1)\n do (setq ys (f ys)\n g (gcd (abs (- x ys)) n))))\n (when (< g n)\n (return g))))))\n\n(defconstant +max+ 2500)\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (pdata (make-prime-data +max+))\n (table (make-hash-table :test #'equal))\n (null-count 0))\n (declare (uint32 n null-count))\n (labels\n ((%factorize (s)\n (let ((factors (factorize s pdata)))\n (if (null factors)\n nil\n (let ((largest (caar factors)))\n (declare (uint62 largest))\n (cond ((< largest +max+) factors)\n ((prime-p largest) factors)\n (t\n (let* ((p1 (rho largest))\n (p2 (floor largest p1)))\n (cond ((> p1 p2)\n (cons (cons p1 1) (cons (cons p2 1) (cdr factors))))\n ((< p1 p2)\n (cons (cons p2 1) (cons (cons p1 1) (cdr factors))))\n (t\n (cons (cons p1 2) (cdr factors)))))))))))\n (add (factors)\n (cond ((null factors)\n (incf null-count))\n ((= 1 (cdar factors))\n (if (gethash factors table)\n (incf (car (gethash factors table)))\n (setf (gethash factors table) (cons 1 0))))\n (t\n (let ((factors (loop for (p . exp) of-type (uint62 . uint62) in factors\n collect (cons p (- 3 exp)))))\n (if (gethash factors table)\n (incf (cdr (gethash factors table)))\n (setf (gethash factors table) (cons 0 1))))))))\n (dotimes (i n)\n (let* ((s (read-fixnum))\n (factors (loop for (p . exp) of-type (uint62 . uint62) in (%factorize s)\n unless (zerop (mod exp 3))\n collect (cons p (mod exp 3)))))\n (add factors)))\n (println\n (+ (min null-count 1)\n (loop for (count1 . count2) being each hash-value of table\n sum (max count1 count2)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n1\n2\n3\n4\n5\n6\n7\n8\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n2\n4\n8\n16\n32\n64\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\"\n \"9\n\")))\n", "problem_context": "Score : 1100 points\n\nProblem Statement\n\nSnuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.\n\nHe will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.\n\nFind the maximum number of integers that Snuke can circle.\n\nConstraints\n\n1 ≦ N ≦ 10^5\n\n1 ≦ s_i ≦ 10^{10}\n\nAll input values are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\ns_1\n:\ns_N\n\nOutput\n\nPrint the maximum number of integers that Snuke can circle.\n\nSample Input 1\n\n8\n1\n2\n3\n4\n5\n6\n7\n8\n\nSample Output 1\n\n6\n\nSnuke can circle 1,2,3,5,6,7.\n\nSample Input 2\n\n6\n2\n4\n8\n16\n32\n64\n\nSample Output 2\n\n3\n\nSample Input 3\n\n10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\nSample Output 3\n\n9", "sample_input": "8\n1\n2\n3\n4\n5\n6\n7\n8\n"}, "reference_outputs": ["6\n"], "source_document_id": "p04022", "source_text": "Score : 1100 points\n\nProblem Statement\n\nSnuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.\n\nHe will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.\n\nFind the maximum number of integers that Snuke can circle.\n\nConstraints\n\n1 ≦ N ≦ 10^5\n\n1 ≦ s_i ≦ 10^{10}\n\nAll input values are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\ns_1\n:\ns_N\n\nOutput\n\nPrint the maximum number of integers that Snuke can circle.\n\nSample Input 1\n\n8\n1\n2\n3\n4\n5\n6\n7\n8\n\nSample Output 1\n\n6\n\nSnuke can circle 1,2,3,5,6,7.\n\nSample Input 2\n\n6\n2\n4\n8\n16\n32\n64\n\nSample Output 2\n\n3\n\nSample Input 3\n\n10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\nSample Output 3\n\n9", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 14058, "cpu_time_ms": 2367, "memory_kb": 83168}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s423341852", "group_id": "codeNet:p04022", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(declaim (ftype (function * (values simple-bit-vector &optional)) make-prime-table))\n(defun make-prime-table (sup)\n \"Returns a simple-bit-vector of length SUP, whose (0-based) i-th bit is 1 if i\nis prime and 0 otherwise.\n\nExample: (make-prime-table 10) => #*0011010100\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-array sup :element-type 'bit :initial-element 0))\n (sup/64 (ceiling sup 64)))\n ;; special treatment for p = 2\n (dotimes (i sup/64)\n (setf (sb-kernel:%vector-raw-bits table i) #xAAAAAAAAAAAAAAAA))\n (setf (sbit table 1) 0\n (sbit table 2) 1)\n ;; p >= 3\n (loop for p from 3 to (+ 1 (isqrt (- sup 1))) by 2\n when (= 1 (sbit table p))\n do (loop for composite from (* p p) below sup by p\n do (setf (sbit table composite) 0)))\n table))\n\n;; FIXME: Currently the element type of the resultant vector is (UNSIGNED-BYTE 62).\n(declaim (ftype (function * (values (simple-array (integer 0 #.most-positive-fixnum) (*))\n simple-bit-vector\n &optional))\n make-prime-sequence))\n(defun make-prime-sequence (sup)\n \"Returns the ascending sequence of primes smaller than SUP.\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-prime-table sup)))\n (let* ((length (count 1 table))\n (result (make-array length :element-type '(integer 0 #.most-positive-fixnum)))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) length))\n (loop for x below sup\n when (= 1 (sbit table x))\n do (setf (aref result index) x)\n (incf index))\n (values result table))))\n\n(defstruct (prime-data (:constructor %make-prime-data (seq table)))\n (seq nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n (table nil :type simple-bit-vector))\n\n(defun make-prime-data (sup)\n (multiple-value-call #'%make-prime-data (make-prime-sequence sup)))\n\n(declaim (inline factorize)\n (ftype (function * (values list &optional)) factorize))\n(defun factorize (x prime-data)\n \"Returns the associative list of prime factors of X, which is composed\nof ( . ). E.g. (factorize 40 ) => '((2 . 3) (5\n. 1)).\n\n- Any numbers beyond the range of PRIME-DATA are regarded as prime.\n- The returned list is in descending order w.r.t. prime factors.\"\n (declare (integer x))\n (setq x (abs x))\n (when (<= x 1)\n (return-from factorize nil))\n (let ((prime-seq (prime-data-seq prime-data))\n result)\n (loop for prime of-type unsigned-byte across prime-seq\n do (when (= x 1)\n (return-from factorize result))\n (loop for exponent of-type (integer 0 #.most-positive-fixnum) from 0\n do (multiple-value-bind (quot rem) (floor x prime)\n (if (zerop rem)\n (setf x quot)\n (progn\n (when (> exponent 0)\n (push (cons prime exponent) result))\n (loop-finish))))))\n (if (= x 1)\n result\n (cons (cons x 1) result))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n;; TODO: more efficient handling when modulus is (unsigned-byte 31) or\n;; (unsigned-byte 32)\n(declaim (inline mod-power))\n(defun mod-power (base power modulus)\n \"BASE := integer\nPOWER, MODULUS := non-negative fixnum\"\n (declare ((integer 0 #.most-positive-fixnum) modulus power)\n (integer base))\n (if (= modulus 1)\n 0\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) x p)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (cond ((zerop p) 1)\n ((evenp p) (recur (mod (* x x) modulus) (ash p -1)))\n (t (mod (* x (recur x (- p 1))) modulus)))))\n (recur (mod base modulus) power))))\n\n(defun prime-p (n)\n (declare #.OPT\n (uint62 n))\n (let ((d (- n 1)))\n (let ((d (floor d (logand d (- d))))\n (ls (cond ((< n #.(ash 1 32)) #(2 7 61))\n ((< n #.(ash 1 48)) #(2 3 5 7 11 13 17))\n (t #(2 3 5 7 11 13 17 19 23 29)))))\n (loop for l of-type uint8 across ls\n for tt of-type uint62 = d\n for y of-type uint62 = (mod-power l tt n)\n do (when (= l n)\n (return-from prime-p t))\n (unless (= y 1)\n (loop until (= y (- n 1))\n do (setq y (mod (* y y) n))\n (when (or (= y 1) (= tt (- n 1)))\n (return-from prime-p nil))\n (setq tt (ash tt 1)))))\n t)))\n\n(defun rho (n)\n (declare #.OPT\n (uint62 n))\n (let ((m (ash 1 (integer-length n))))\n (macrolet ((f (x) `(let ((xx ,x)) (mod (+ c (* xx xx)) n))))\n (loop for c from 1 below 99\n for y of-type uint62 = 2\n for r of-type uint62 = 1\n for q of-type uint62 = 1\n for g of-type uint62 = 1\n for ys of-type uint62 = y\n for x of-type uint62 = y\n do (loop while (= g 1)\n do (setq x y)\n (dotimes (_ r)\n (setq y (f y)))\n (let ((k 0))\n (declare (uint62 k))\n (loop while (and (< k r) (= g 1))\n do (setq ys y)\n (dotimes (_ (min m (- r k)))\n (setq y (f y)\n q (mod (* q (abs (- x y))) n)))\n (setq g (gcd q n))\n (incf k m)))\n (setq r (ash r 1)))\n (when (= g n)\n (loop while (= g 1)\n do (setq ys (f ys)\n g (gcd (abs (- x ys)) n))))\n (when (< g n)\n (return g))))))\n\n(defconstant +max+ 2500)\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (pdata (make-prime-data +max+))\n (table (make-hash-table :test #'equal))\n (null-count 0))\n (declare (uint32 n null-count))\n (labels\n ((%factorize (s)\n (let ((factors (factorize s pdata)))\n (if (null factors)\n nil\n (let ((largest (caar factors)))\n (declare (uint62 largest))\n (cond ((< largest +max+) factors)\n ((prime-p largest) factors)\n (t\n (let* ((p1 (rho largest))\n (p2 (floor largest p1)))\n (cond ((> p1 p2)\n (cons (cons p1 1) (cons (cons p2 1) (cdr factors))))\n ((< p1 p2)\n (cons (cons p2 1) (cons (cons p1 1) (cdr factors))))\n (t\n (cons (cons p1 2) (cdr factors)))))))))))\n (add (factors)\n (cond ((null factors)\n (incf null-count))\n ((= 1 (cdar factors))\n (if (gethash factors table)\n (incf (car (gethash factors table)))\n (setf (gethash factors table) (cons 1 0))))\n (t\n (let ((factors (loop for (p . exp) of-type (uint62 . uint62) in factors\n collect (cons p (- 3 exp)))))\n (if (gethash factors table)\n (incf (cdr (gethash factors table)))\n (setf (gethash factors table) (cons 0 1))))))))\n (dotimes (i n)\n (let* ((s (read-fixnum))\n (factors (loop for (p . exp) of-type (uint62 . uint62) in (%factorize s)\n unless (zerop (mod exp 3))\n collect (cons p (mod exp 3)))))\n (add factors)))\n (println\n (+ (min null-count 1)\n (loop for (count1 . count2) being each hash-value of table\n sum (max count1 count2)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n1\n2\n3\n4\n5\n6\n7\n8\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n2\n4\n8\n16\n32\n64\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\"\n \"9\n\")))\n", "language": "Lisp", "metadata": {"date": 1584949185, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04022.html", "problem_id": "p04022", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04022/input.txt", "sample_output_relpath": "derived/input_output/data/p04022/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04022/Lisp/s423341852.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s423341852", "user_id": "u352600849"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(declaim (ftype (function * (values simple-bit-vector &optional)) make-prime-table))\n(defun make-prime-table (sup)\n \"Returns a simple-bit-vector of length SUP, whose (0-based) i-th bit is 1 if i\nis prime and 0 otherwise.\n\nExample: (make-prime-table 10) => #*0011010100\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-array sup :element-type 'bit :initial-element 0))\n (sup/64 (ceiling sup 64)))\n ;; special treatment for p = 2\n (dotimes (i sup/64)\n (setf (sb-kernel:%vector-raw-bits table i) #xAAAAAAAAAAAAAAAA))\n (setf (sbit table 1) 0\n (sbit table 2) 1)\n ;; p >= 3\n (loop for p from 3 to (+ 1 (isqrt (- sup 1))) by 2\n when (= 1 (sbit table p))\n do (loop for composite from (* p p) below sup by p\n do (setf (sbit table composite) 0)))\n table))\n\n;; FIXME: Currently the element type of the resultant vector is (UNSIGNED-BYTE 62).\n(declaim (ftype (function * (values (simple-array (integer 0 #.most-positive-fixnum) (*))\n simple-bit-vector\n &optional))\n make-prime-sequence))\n(defun make-prime-sequence (sup)\n \"Returns the ascending sequence of primes smaller than SUP.\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-prime-table sup)))\n (let* ((length (count 1 table))\n (result (make-array length :element-type '(integer 0 #.most-positive-fixnum)))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) length))\n (loop for x below sup\n when (= 1 (sbit table x))\n do (setf (aref result index) x)\n (incf index))\n (values result table))))\n\n(defstruct (prime-data (:constructor %make-prime-data (seq table)))\n (seq nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n (table nil :type simple-bit-vector))\n\n(defun make-prime-data (sup)\n (multiple-value-call #'%make-prime-data (make-prime-sequence sup)))\n\n(declaim (inline factorize)\n (ftype (function * (values list &optional)) factorize))\n(defun factorize (x prime-data)\n \"Returns the associative list of prime factors of X, which is composed\nof ( . ). E.g. (factorize 40 ) => '((2 . 3) (5\n. 1)).\n\n- Any numbers beyond the range of PRIME-DATA are regarded as prime.\n- The returned list is in descending order w.r.t. prime factors.\"\n (declare (integer x))\n (setq x (abs x))\n (when (<= x 1)\n (return-from factorize nil))\n (let ((prime-seq (prime-data-seq prime-data))\n result)\n (loop for prime of-type unsigned-byte across prime-seq\n do (when (= x 1)\n (return-from factorize result))\n (loop for exponent of-type (integer 0 #.most-positive-fixnum) from 0\n do (multiple-value-bind (quot rem) (floor x prime)\n (if (zerop rem)\n (setf x quot)\n (progn\n (when (> exponent 0)\n (push (cons prime exponent) result))\n (loop-finish))))))\n (if (= x 1)\n result\n (cons (cons x 1) result))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n;; TODO: more efficient handling when modulus is (unsigned-byte 31) or\n;; (unsigned-byte 32)\n(declaim (inline mod-power))\n(defun mod-power (base power modulus)\n \"BASE := integer\nPOWER, MODULUS := non-negative fixnum\"\n (declare ((integer 0 #.most-positive-fixnum) modulus power)\n (integer base))\n (if (= modulus 1)\n 0\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) x p)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (cond ((zerop p) 1)\n ((evenp p) (recur (mod (* x x) modulus) (ash p -1)))\n (t (mod (* x (recur x (- p 1))) modulus)))))\n (recur (mod base modulus) power))))\n\n(defun prime-p (n)\n (declare #.OPT\n (uint62 n))\n (let ((d (- n 1)))\n (let ((d (floor d (logand d (- d))))\n (ls (cond ((< n #.(ash 1 32)) #(2 7 61))\n ((< n #.(ash 1 48)) #(2 3 5 7 11 13 17))\n (t #(2 3 5 7 11 13 17 19 23 29)))))\n (loop for l of-type uint8 across ls\n for tt of-type uint62 = d\n for y of-type uint62 = (mod-power l tt n)\n do (when (= l n)\n (return-from prime-p t))\n (unless (= y 1)\n (loop until (= y (- n 1))\n do (setq y (mod (* y y) n))\n (when (or (= y 1) (= tt (- n 1)))\n (return-from prime-p nil))\n (setq tt (ash tt 1)))))\n t)))\n\n(defun rho (n)\n (declare #.OPT\n (uint62 n))\n (let ((m (ash 1 (integer-length n))))\n (macrolet ((f (x) `(let ((xx ,x)) (mod (+ c (* xx xx)) n))))\n (loop for c from 1 below 99\n for y of-type uint62 = 2\n for r of-type uint62 = 1\n for q of-type uint62 = 1\n for g of-type uint62 = 1\n for ys of-type uint62 = y\n for x of-type uint62 = y\n do (loop while (= g 1)\n do (setq x y)\n (dotimes (_ r)\n (setq y (f y)))\n (let ((k 0))\n (declare (uint62 k))\n (loop while (and (< k r) (= g 1))\n do (setq ys y)\n (dotimes (_ (min m (- r k)))\n (setq y (f y)\n q (mod (* q (abs (- x y))) n)))\n (setq g (gcd q n))\n (incf k m)))\n (setq r (ash r 1)))\n (when (= g n)\n (loop while (= g 1)\n do (setq ys (f ys)\n g (gcd (abs (- x ys)) n))))\n (when (< g n)\n (return g))))))\n\n(defconstant +max+ 2500)\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (pdata (make-prime-data +max+))\n (table (make-hash-table :test #'equal))\n (null-count 0))\n (declare (uint32 n null-count))\n (labels\n ((%factorize (s)\n (let ((factors (factorize s pdata)))\n (if (null factors)\n nil\n (let ((largest (caar factors)))\n (declare (uint62 largest))\n (cond ((< largest +max+) factors)\n ((prime-p largest) factors)\n (t\n (let* ((p1 (rho largest))\n (p2 (floor largest p1)))\n (cond ((> p1 p2)\n (cons (cons p1 1) (cons (cons p2 1) (cdr factors))))\n ((< p1 p2)\n (cons (cons p2 1) (cons (cons p1 1) (cdr factors))))\n (t\n (cons (cons p1 2) (cdr factors)))))))))))\n (add (factors)\n (cond ((null factors)\n (incf null-count))\n ((= 1 (cdar factors))\n (if (gethash factors table)\n (incf (car (gethash factors table)))\n (setf (gethash factors table) (cons 1 0))))\n (t\n (let ((factors (loop for (p . exp) of-type (uint62 . uint62) in factors\n collect (cons p (- 3 exp)))))\n (if (gethash factors table)\n (incf (cdr (gethash factors table)))\n (setf (gethash factors table) (cons 0 1))))))))\n (dotimes (i n)\n (let* ((s (read-fixnum))\n (factors (loop for (p . exp) of-type (uint62 . uint62) in (%factorize s)\n unless (zerop (mod exp 3))\n collect (cons p (mod exp 3)))))\n (add factors)))\n (println\n (+ (min null-count 1)\n (loop for (count1 . count2) being each hash-value of table\n sum (max count1 count2)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n1\n2\n3\n4\n5\n6\n7\n8\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n2\n4\n8\n16\n32\n64\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\"\n \"9\n\")))\n", "problem_context": "Score : 1100 points\n\nProblem Statement\n\nSnuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.\n\nHe will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.\n\nFind the maximum number of integers that Snuke can circle.\n\nConstraints\n\n1 ≦ N ≦ 10^5\n\n1 ≦ s_i ≦ 10^{10}\n\nAll input values are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\ns_1\n:\ns_N\n\nOutput\n\nPrint the maximum number of integers that Snuke can circle.\n\nSample Input 1\n\n8\n1\n2\n3\n4\n5\n6\n7\n8\n\nSample Output 1\n\n6\n\nSnuke can circle 1,2,3,5,6,7.\n\nSample Input 2\n\n6\n2\n4\n8\n16\n32\n64\n\nSample Output 2\n\n3\n\nSample Input 3\n\n10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\nSample Output 3\n\n9", "sample_input": "8\n1\n2\n3\n4\n5\n6\n7\n8\n"}, "reference_outputs": ["6\n"], "source_document_id": "p04022", "source_text": "Score : 1100 points\n\nProblem Statement\n\nSnuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.\n\nHe will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.\n\nFind the maximum number of integers that Snuke can circle.\n\nConstraints\n\n1 ≦ N ≦ 10^5\n\n1 ≦ s_i ≦ 10^{10}\n\nAll input values are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\ns_1\n:\ns_N\n\nOutput\n\nPrint the maximum number of integers that Snuke can circle.\n\nSample Input 1\n\n8\n1\n2\n3\n4\n5\n6\n7\n8\n\nSample Output 1\n\n6\n\nSnuke can circle 1,2,3,5,6,7.\n\nSample Input 2\n\n6\n2\n4\n8\n16\n32\n64\n\nSample Output 2\n\n3\n\nSample Input 3\n\n10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\nSample Output 3\n\n9", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 13240, "cpu_time_ms": 2355, "memory_kb": 91236}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s121555521", "group_id": "codeNet:p04022", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(declaim (ftype (function * (values simple-bit-vector &optional)) make-prime-table))\n(defun make-prime-table (sup)\n \"Returns a simple-bit-vector of length SUP, whose (0-based) i-th bit is 1 if i\nis prime and 0 otherwise.\n\nExample: (make-prime-table 10) => #*0011010100\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-array sup :element-type 'bit :initial-element 0))\n (sup/64 (ceiling sup 64)))\n ;; special treatment for p = 2\n (dotimes (i sup/64)\n (setf (sb-kernel:%vector-raw-bits table i) #xAAAAAAAAAAAAAAAA))\n (setf (sbit table 1) 0\n (sbit table 2) 1)\n ;; p >= 3\n (loop for p from 3 to (+ 1 (isqrt (- sup 1))) by 2\n when (= 1 (sbit table p))\n do (loop for composite from (* p p) below sup by p\n do (setf (sbit table composite) 0)))\n table))\n\n;; FIXME: Currently the element type of the resultant vector is (UNSIGNED-BYTE 62).\n(declaim (ftype (function * (values (simple-array (integer 0 #.most-positive-fixnum) (*))\n simple-bit-vector\n &optional))\n make-prime-sequence))\n(defun make-prime-sequence (sup)\n \"Returns the ascending sequence of primes smaller than SUP.\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-prime-table sup)))\n (let* ((length (count 1 table))\n (result (make-array length :element-type '(integer 0 #.most-positive-fixnum)))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) length))\n (loop for x below sup\n when (= 1 (sbit table x))\n do (setf (aref result index) x)\n (incf index))\n (values result table))))\n\n(defstruct (prime-data (:constructor %make-prime-data (seq table)))\n (seq nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n (table nil :type simple-bit-vector))\n\n(defun make-prime-data (sup)\n (multiple-value-call #'%make-prime-data (make-prime-sequence sup)))\n\n(declaim (inline factorize)\n (ftype (function * (values list &optional)) factorize))\n(defun factorize (x prime-data)\n \"Returns the associative list of prime factors of X, which is composed\nof ( . ). E.g. (factorize 40 ) => '((2 . 3) (5\n. 1)).\n\n- Any numbers beyond the range of PRIME-DATA are regarded as prime.\n- The returned list is in descending order w.r.t. prime factors.\"\n (declare (integer x))\n (setq x (abs x))\n (when (<= x 1)\n (return-from factorize nil))\n (let ((prime-seq (prime-data-seq prime-data))\n result)\n (loop for prime of-type unsigned-byte across prime-seq\n do (when (= x 1)\n (return-from factorize result))\n (loop for exponent of-type (integer 0 #.most-positive-fixnum) from 0\n do (multiple-value-bind (quot rem) (floor x prime)\n (if (zerop rem)\n (setf x quot)\n (progn\n (when (> exponent 0)\n (push (cons prime exponent) result))\n (loop-finish))))))\n (if (= x 1)\n result\n (cons (cons x 1) result))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n;; TODO: more efficient handling when modulus is (unsigned-byte 31) or\n;; (unsigned-byte 32)\n(declaim (inline mod-power))\n(defun mod-power (base power modulus)\n \"BASE := integer\nPOWER, MODULUS := non-negative fixnum\"\n (declare ((integer 0 #.most-positive-fixnum) modulus power)\n (integer base))\n (if (= modulus 1)\n 0\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) x p)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (cond ((zerop p) 1)\n ((evenp p) (recur (mod (* x x) modulus) (ash p -1)))\n (t (mod (* x (recur x (- p 1))) modulus)))))\n (recur (mod base modulus) power))))\n\n(defun prime-p (n)\n (declare #.OPT\n (uint62 n))\n (let ((d (- n 1)))\n (let ((d (floor d (logand d (- d))))\n (ls (cond ((< n #.(ash 1 32)) #(2 7 61))\n ((< n #.(ash 1 48)) #(2 3 5 7 11 13 17))\n (t #(2 3 5 7 11 13 17 19 23 29)))))\n (loop for l of-type uint8 across ls\n for tt of-type uint62 = d\n for y of-type uint62 = (mod-power l tt n)\n do (when (= l n)\n (return-from prime-p t))\n (unless (= y 1)\n (loop until (= y (- n 1))\n do (setq y (mod (* y y) n))\n (when (or (= y 1) (= tt (- n 1)))\n (return-from prime-p nil))\n (setq tt (ash tt 1)))))\n t)))\n\n(declaim (inline rho))\n(defun rho (n)\n (declare (uint62 n))\n (let ((m (ash 1 (integer-length n))))\n (macrolet ((f (x) `(let ((xx ,x)) (mod (+ c (* xx xx)) n))))\n (loop for c from 1 below 99\n for y of-type uint62 = 2\n for r of-type uint62 = 1\n for q of-type uint62 = 1\n for g of-type uint62 = 1\n for ys of-type uint62 = y\n for x of-type uint62 = y\n do (loop while (= g 1)\n do (setq x y)\n (dotimes (_ r)\n (setq y (f y)))\n (let ((k 0))\n (declare (uint62 k))\n (loop while (and (< k r) (= g 1))\n do (setq ys y)\n (dotimes (_ (min m (- r k)))\n (setq y (f y)\n q (mod (* q (abs (- x y))) n)))\n (setq g (gcd q n))\n (incf k m)))\n (setq r (ash r 1)))\n (when (= g n)\n (loop while (= g 1)\n do (setq ys (f ys)\n g (gcd (abs (- x ys)) n))))\n (when (< g n)\n (return g))))))\n\n(defconstant +max+ 2500)\n(defun main ()\n (let* ((n (read))\n (pdata (make-prime-data +max+))\n (table (make-hash-table :test #'equal))\n (null-count 0))\n (declare (uint32 n null-count))\n (labels ((%factorize (s)\n (let ((factors (factorize s pdata)))\n (if (null factors)\n nil\n (let ((largest (caar factors)))\n (declare (uint62 largest))\n (cond ((< largest +max+) factors)\n ((prime-p largest) factors)\n ((= largest (expt (isqrt largest) 2))\n (cons (cons (isqrt largest) 2) (cdr factors)))\n (t (let* ((p1 (rho largest))\n (p2 (floor largest p1)))\n (when (< p1 p2)\n (rotatef p1 p2))\n (cons (cons p1 1) (cons (cons p2 1) (cdr factors))))))))))\n (add (factors)\n (cond ((null factors)\n (incf null-count))\n ((= 1 (cdar factors))\n (if (gethash factors table)\n (incf (car (gethash factors table)))\n (setf (gethash factors table) (cons 1 0))))\n (t\n (assert (= 2 (cdar factors)))\n (let ((factors (loop for (p . exp) of-type (uint62 . uint62) in factors\n collect (cons p (- 3 exp)))))\n (if (gethash factors table)\n (incf (cdr (gethash factors table)))\n (setf (gethash factors table) (cons 0 1))))))))\n (dotimes (i n)\n (let* ((s (read-fixnum))\n (factors (loop for (p . exp) of-type (uint62 . uint62) in (%factorize s)\n unless (zerop (mod exp 3))\n collect (cons p (mod exp 3)))))\n (add factors)))\n #>null-count\n (println\n (+ (min null-count 1)\n (loop for (count1 . count2) being each hash-value of table\n sum (max count1 count2)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n1\n2\n3\n4\n5\n6\n7\n8\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n2\n4\n8\n16\n32\n64\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\"\n \"9\n\")))\n", "language": "Lisp", "metadata": {"date": 1584948854, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04022.html", "problem_id": "p04022", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04022/input.txt", "sample_output_relpath": "derived/input_output/data/p04022/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04022/Lisp/s121555521.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s121555521", "user_id": "u352600849"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n\n\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(declaim (ftype (function * (values simple-bit-vector &optional)) make-prime-table))\n(defun make-prime-table (sup)\n \"Returns a simple-bit-vector of length SUP, whose (0-based) i-th bit is 1 if i\nis prime and 0 otherwise.\n\nExample: (make-prime-table 10) => #*0011010100\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-array sup :element-type 'bit :initial-element 0))\n (sup/64 (ceiling sup 64)))\n ;; special treatment for p = 2\n (dotimes (i sup/64)\n (setf (sb-kernel:%vector-raw-bits table i) #xAAAAAAAAAAAAAAAA))\n (setf (sbit table 1) 0\n (sbit table 2) 1)\n ;; p >= 3\n (loop for p from 3 to (+ 1 (isqrt (- sup 1))) by 2\n when (= 1 (sbit table p))\n do (loop for composite from (* p p) below sup by p\n do (setf (sbit table composite) 0)))\n table))\n\n;; FIXME: Currently the element type of the resultant vector is (UNSIGNED-BYTE 62).\n(declaim (ftype (function * (values (simple-array (integer 0 #.most-positive-fixnum) (*))\n simple-bit-vector\n &optional))\n make-prime-sequence))\n(defun make-prime-sequence (sup)\n \"Returns the ascending sequence of primes smaller than SUP.\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-prime-table sup)))\n (let* ((length (count 1 table))\n (result (make-array length :element-type '(integer 0 #.most-positive-fixnum)))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) length))\n (loop for x below sup\n when (= 1 (sbit table x))\n do (setf (aref result index) x)\n (incf index))\n (values result table))))\n\n(defstruct (prime-data (:constructor %make-prime-data (seq table)))\n (seq nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n (table nil :type simple-bit-vector))\n\n(defun make-prime-data (sup)\n (multiple-value-call #'%make-prime-data (make-prime-sequence sup)))\n\n(declaim (inline factorize)\n (ftype (function * (values list &optional)) factorize))\n(defun factorize (x prime-data)\n \"Returns the associative list of prime factors of X, which is composed\nof ( . ). E.g. (factorize 40 ) => '((2 . 3) (5\n. 1)).\n\n- Any numbers beyond the range of PRIME-DATA are regarded as prime.\n- The returned list is in descending order w.r.t. prime factors.\"\n (declare (integer x))\n (setq x (abs x))\n (when (<= x 1)\n (return-from factorize nil))\n (let ((prime-seq (prime-data-seq prime-data))\n result)\n (loop for prime of-type unsigned-byte across prime-seq\n do (when (= x 1)\n (return-from factorize result))\n (loop for exponent of-type (integer 0 #.most-positive-fixnum) from 0\n do (multiple-value-bind (quot rem) (floor x prime)\n (if (zerop rem)\n (setf x quot)\n (progn\n (when (> exponent 0)\n (push (cons prime exponent) result))\n (loop-finish))))))\n (if (= x 1)\n result\n (cons (cons x 1) result))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n;; TODO: more efficient handling when modulus is (unsigned-byte 31) or\n;; (unsigned-byte 32)\n(declaim (inline mod-power))\n(defun mod-power (base power modulus)\n \"BASE := integer\nPOWER, MODULUS := non-negative fixnum\"\n (declare ((integer 0 #.most-positive-fixnum) modulus power)\n (integer base))\n (if (= modulus 1)\n 0\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) x p)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (cond ((zerop p) 1)\n ((evenp p) (recur (mod (* x x) modulus) (ash p -1)))\n (t (mod (* x (recur x (- p 1))) modulus)))))\n (recur (mod base modulus) power))))\n\n(defun prime-p (n)\n (declare #.OPT\n (uint62 n))\n (let ((d (- n 1)))\n (let ((d (floor d (logand d (- d))))\n (ls (cond ((< n #.(ash 1 32)) #(2 7 61))\n ((< n #.(ash 1 48)) #(2 3 5 7 11 13 17))\n (t #(2 3 5 7 11 13 17 19 23 29)))))\n (loop for l of-type uint8 across ls\n for tt of-type uint62 = d\n for y of-type uint62 = (mod-power l tt n)\n do (when (= l n)\n (return-from prime-p t))\n (unless (= y 1)\n (loop until (= y (- n 1))\n do (setq y (mod (* y y) n))\n (when (or (= y 1) (= tt (- n 1)))\n (return-from prime-p nil))\n (setq tt (ash tt 1)))))\n t)))\n\n(declaim (inline rho))\n(defun rho (n)\n (declare (uint62 n))\n (let ((m (ash 1 (integer-length n))))\n (macrolet ((f (x) `(let ((xx ,x)) (mod (+ c (* xx xx)) n))))\n (loop for c from 1 below 99\n for y of-type uint62 = 2\n for r of-type uint62 = 1\n for q of-type uint62 = 1\n for g of-type uint62 = 1\n for ys of-type uint62 = y\n for x of-type uint62 = y\n do (loop while (= g 1)\n do (setq x y)\n (dotimes (_ r)\n (setq y (f y)))\n (let ((k 0))\n (declare (uint62 k))\n (loop while (and (< k r) (= g 1))\n do (setq ys y)\n (dotimes (_ (min m (- r k)))\n (setq y (f y)\n q (mod (* q (abs (- x y))) n)))\n (setq g (gcd q n))\n (incf k m)))\n (setq r (ash r 1)))\n (when (= g n)\n (loop while (= g 1)\n do (setq ys (f ys)\n g (gcd (abs (- x ys)) n))))\n (when (< g n)\n (return g))))))\n\n(defconstant +max+ 2500)\n(defun main ()\n (let* ((n (read))\n (pdata (make-prime-data +max+))\n (table (make-hash-table :test #'equal))\n (null-count 0))\n (declare (uint32 n null-count))\n (labels ((%factorize (s)\n (let ((factors (factorize s pdata)))\n (if (null factors)\n nil\n (let ((largest (caar factors)))\n (declare (uint62 largest))\n (cond ((< largest +max+) factors)\n ((prime-p largest) factors)\n ((= largest (expt (isqrt largest) 2))\n (cons (cons (isqrt largest) 2) (cdr factors)))\n (t (let* ((p1 (rho largest))\n (p2 (floor largest p1)))\n (when (< p1 p2)\n (rotatef p1 p2))\n (cons (cons p1 1) (cons (cons p2 1) (cdr factors))))))))))\n (add (factors)\n (cond ((null factors)\n (incf null-count))\n ((= 1 (cdar factors))\n (if (gethash factors table)\n (incf (car (gethash factors table)))\n (setf (gethash factors table) (cons 1 0))))\n (t\n (assert (= 2 (cdar factors)))\n (let ((factors (loop for (p . exp) of-type (uint62 . uint62) in factors\n collect (cons p (- 3 exp)))))\n (if (gethash factors table)\n (incf (cdr (gethash factors table)))\n (setf (gethash factors table) (cons 0 1))))))))\n (dotimes (i n)\n (let* ((s (read-fixnum))\n (factors (loop for (p . exp) of-type (uint62 . uint62) in (%factorize s)\n unless (zerop (mod exp 3))\n collect (cons p (mod exp 3)))))\n (add factors)))\n #>null-count\n (println\n (+ (min null-count 1)\n (loop for (count1 . count2) being each hash-value of table\n sum (max count1 count2)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n1\n2\n3\n4\n5\n6\n7\n8\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n2\n4\n8\n16\n32\n64\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\"\n \"9\n\")))\n", "problem_context": "Score : 1100 points\n\nProblem Statement\n\nSnuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.\n\nHe will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.\n\nFind the maximum number of integers that Snuke can circle.\n\nConstraints\n\n1 ≦ N ≦ 10^5\n\n1 ≦ s_i ≦ 10^{10}\n\nAll input values are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\ns_1\n:\ns_N\n\nOutput\n\nPrint the maximum number of integers that Snuke can circle.\n\nSample Input 1\n\n8\n1\n2\n3\n4\n5\n6\n7\n8\n\nSample Output 1\n\n6\n\nSnuke can circle 1,2,3,5,6,7.\n\nSample Input 2\n\n6\n2\n4\n8\n16\n32\n64\n\nSample Output 2\n\n3\n\nSample Input 3\n\n10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\nSample Output 3\n\n9", "sample_input": "8\n1\n2\n3\n4\n5\n6\n7\n8\n"}, "reference_outputs": ["6\n"], "source_document_id": "p04022", "source_text": "Score : 1100 points\n\nProblem Statement\n\nSnuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.\n\nHe will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.\n\nFind the maximum number of integers that Snuke can circle.\n\nConstraints\n\n1 ≦ N ≦ 10^5\n\n1 ≦ s_i ≦ 10^{10}\n\nAll input values are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\ns_1\n:\ns_N\n\nOutput\n\nPrint the maximum number of integers that Snuke can circle.\n\nSample Input 1\n\n8\n1\n2\n3\n4\n5\n6\n7\n8\n\nSample Output 1\n\n6\n\nSnuke can circle 1,2,3,5,6,7.\n\nSample Input 2\n\n6\n2\n4\n8\n16\n32\n64\n\nSample Output 2\n\n3\n\nSample Input 3\n\n10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\nSample Output 3\n\n9", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 13315, "cpu_time_ms": 2380, "memory_kb": 80488}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s460824256", "group_id": "codeNet:p04022", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(declaim (ftype (function * (values simple-bit-vector &optional)) make-prime-table))\n(defun make-prime-table (sup)\n \"Returns a simple-bit-vector of length SUP, whose (0-based) i-th bit is 1 if i\nis prime and 0 otherwise.\n\nExample: (make-prime-table 10) => #*0011010100\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-array sup :element-type 'bit :initial-element 0))\n (sup/64 (ceiling sup 64)))\n ;; special treatment for p = 2\n (dotimes (i sup/64)\n (setf (sb-kernel:%vector-raw-bits table i) #xAAAAAAAAAAAAAAAA))\n (setf (sbit table 1) 0\n (sbit table 2) 1)\n ;; p >= 3\n (loop for p from 3 to (+ 1 (isqrt (- sup 1))) by 2\n when (= 1 (sbit table p))\n do (loop for composite from (* p p) below sup by p\n do (setf (sbit table composite) 0)))\n table))\n\n;; FIXME: Currently the element type of the resultant vector is (UNSIGNED-BYTE 62).\n(declaim (ftype (function * (values (simple-array (integer 0 #.most-positive-fixnum) (*))\n simple-bit-vector\n &optional))\n make-prime-sequence))\n(defun make-prime-sequence (sup)\n \"Returns the ascending sequence of primes smaller than SUP.\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-prime-table sup)))\n (let* ((length (count 1 table))\n (result (make-array length :element-type '(integer 0 #.most-positive-fixnum)))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) length))\n (loop for x below sup\n when (= 1 (sbit table x))\n do (setf (aref result index) x)\n (incf index))\n (values result table))))\n\n(defstruct (prime-data (:constructor %make-prime-data (seq table)))\n (seq nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n (table nil :type simple-bit-vector))\n\n(defun make-prime-data (sup)\n (multiple-value-call #'%make-prime-data (make-prime-sequence sup)))\n\n(declaim (inline factorize)\n (ftype (function * (values list &optional)) factorize))\n(defun factorize (x prime-data)\n \"Returns the associative list of prime factors of X, which is composed\nof ( . ). E.g. (factorize 40 ) => '((2 . 3) (5\n. 1)).\n\n- Any numbers beyond the range of PRIME-DATA are regarded as prime.\n- The returned list is in descending order w.r.t. prime factors.\"\n (declare (integer x))\n (setq x (abs x))\n (when (<= x 1)\n (return-from factorize nil))\n (let ((prime-seq (prime-data-seq prime-data))\n result)\n (loop for prime of-type unsigned-byte across prime-seq\n do (when (= x 1)\n (return-from factorize result))\n (loop for exponent of-type (integer 0 #.most-positive-fixnum) from 0\n do (multiple-value-bind (quot rem) (floor x prime)\n (if (zerop rem)\n (setf x quot)\n (progn\n (when (> exponent 0)\n (push (cons prime exponent) result))\n (loop-finish))))))\n (if (= x 1)\n result\n (cons (cons x 1) result))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline rho))\n(defun rho (n)\n (declare (uint62 n))\n (let ((m (ash 1 (integer-length n))))\n (macrolet ((f (x) `(let ((xx ,x)) (+ c (* xx xx)))))\n (loop for c from 1 below 99\n for y of-type uint62 = 2\n for r of-type uint62 = 1\n for q of-type uint62 = 1\n for g of-type uint62 = 1\n for ys of-type uint62 = y\n for x of-type uint62 = y\n do (loop while (= g 1)\n do (setq x y)\n (dotimes (_ r)\n (setq y (f y)))\n (let ((k 0))\n (declare (uint62 k))\n (loop while (and (< k r) (= g 1))\n do (setq ys y)\n (dotimes (_ (min m (- r k)))\n (setq y (f y)\n q (mod (* q (abs (- x y))) n)))\n (setq g (gcd q n))\n (incf k m)))\n (setq r (ash r 1)))\n (when (= g n)\n (loop while (= g 1)\n do (setq ys (f ys)\n g (gcd (abs (- x ys)) n))))\n (when (< g n)\n (return\n (if (sb-int:positive-primep g)\n g\n (floor n g))))))))\n\n(defconstant +max+ 3000)\n(defun main ()\n (let* ((n (read))\n (pdata (make-prime-data +max+))\n (table (make-hash-table :test #'equal))\n (null-count 0))\n (declare (uint32 n null-count))\n (labels ((%factorize (s)\n (let ((factors (factorize s pdata)))\n (if (null factors)\n nil\n (let ((largest (caar factors)))\n (declare (uint62 largest))\n (cond ((< largest +max+) factors)\n ((sb-int:positive-primep largest) factors)\n ((= largest (expt (isqrt largest) 2))\n (cons (cons (isqrt largest) 2) (cdr factors)))\n (t (let* ((p1 (rho largest))\n (p2 (floor largest p1)))\n (when (< p1 p2)\n (rotatef p1 p2))\n (cons (cons p1 1) (cons (cons p2 1) (cdr factors))))))))))\n (add (factors)\n (cond ((null factors)\n (incf null-count))\n ((= 1 (cdar factors))\n (if (gethash factors table)\n (incf (car (gethash factors table)))\n (setf (gethash factors table) (cons 1 0))))\n (t\n (assert (= 2 (cdar factors)))\n (let ((factors (loop for (p . exp) of-type (uint62 . uint62) in factors\n collect (cons p (- 3 exp)))))\n (if (gethash factors table)\n (incf (cdr (gethash factors table)))\n (setf (gethash factors table) (cons 0 1))))))))\n (dotimes (i n)\n (let* ((s (read-fixnum))\n (factors (loop for (p . exp) of-type (uint62 . uint62) in (%factorize s)\n unless (zerop (mod exp 3))\n collect (cons p (mod exp 3)))))\n (add factors)))\n #>null-count\n (println\n (+ (min null-count 1)\n (loop for (count1 . count2) being each hash-value of table\n sum (max count1 count2)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n1\n2\n3\n4\n5\n6\n7\n8\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n2\n4\n8\n16\n32\n64\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\"\n \"9\n\")))\n", "language": "Lisp", "metadata": {"date": 1584947446, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04022.html", "problem_id": "p04022", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04022/input.txt", "sample_output_relpath": "derived/input_output/data/p04022/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04022/Lisp/s460824256.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s460824256", "user_id": "u352600849"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setq minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))\n result))))\n (return (if minus (- result) result))))))))\n\n(declaim (ftype (function * (values simple-bit-vector &optional)) make-prime-table))\n(defun make-prime-table (sup)\n \"Returns a simple-bit-vector of length SUP, whose (0-based) i-th bit is 1 if i\nis prime and 0 otherwise.\n\nExample: (make-prime-table 10) => #*0011010100\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-array sup :element-type 'bit :initial-element 0))\n (sup/64 (ceiling sup 64)))\n ;; special treatment for p = 2\n (dotimes (i sup/64)\n (setf (sb-kernel:%vector-raw-bits table i) #xAAAAAAAAAAAAAAAA))\n (setf (sbit table 1) 0\n (sbit table 2) 1)\n ;; p >= 3\n (loop for p from 3 to (+ 1 (isqrt (- sup 1))) by 2\n when (= 1 (sbit table p))\n do (loop for composite from (* p p) below sup by p\n do (setf (sbit table composite) 0)))\n table))\n\n;; FIXME: Currently the element type of the resultant vector is (UNSIGNED-BYTE 62).\n(declaim (ftype (function * (values (simple-array (integer 0 #.most-positive-fixnum) (*))\n simple-bit-vector\n &optional))\n make-prime-sequence))\n(defun make-prime-sequence (sup)\n \"Returns the ascending sequence of primes smaller than SUP.\"\n (declare (optimize (speed 3) (safety 0)))\n (check-type sup (integer 2 (#.array-total-size-limit)))\n (let ((table (make-prime-table sup)))\n (let* ((length (count 1 table))\n (result (make-array length :element-type '(integer 0 #.most-positive-fixnum)))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) length))\n (loop for x below sup\n when (= 1 (sbit table x))\n do (setf (aref result index) x)\n (incf index))\n (values result table))))\n\n(defstruct (prime-data (:constructor %make-prime-data (seq table)))\n (seq nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n (table nil :type simple-bit-vector))\n\n(defun make-prime-data (sup)\n (multiple-value-call #'%make-prime-data (make-prime-sequence sup)))\n\n(declaim (inline factorize)\n (ftype (function * (values list &optional)) factorize))\n(defun factorize (x prime-data)\n \"Returns the associative list of prime factors of X, which is composed\nof ( . ). E.g. (factorize 40 ) => '((2 . 3) (5\n. 1)).\n\n- Any numbers beyond the range of PRIME-DATA are regarded as prime.\n- The returned list is in descending order w.r.t. prime factors.\"\n (declare (integer x))\n (setq x (abs x))\n (when (<= x 1)\n (return-from factorize nil))\n (let ((prime-seq (prime-data-seq prime-data))\n result)\n (loop for prime of-type unsigned-byte across prime-seq\n do (when (= x 1)\n (return-from factorize result))\n (loop for exponent of-type (integer 0 #.most-positive-fixnum) from 0\n do (multiple-value-bind (quot rem) (floor x prime)\n (if (zerop rem)\n (setf x quot)\n (progn\n (when (> exponent 0)\n (push (cons prime exponent) result))\n (loop-finish))))))\n (if (= x 1)\n result\n (cons (cons x 1) result))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(declaim (inline rho))\n(defun rho (n)\n (declare (uint62 n))\n (let ((m (ash 1 (integer-length n))))\n (macrolet ((f (x) `(let ((xx ,x)) (+ c (* xx xx)))))\n (loop for c from 1 below 99\n for y of-type uint62 = 2\n for r of-type uint62 = 1\n for q of-type uint62 = 1\n for g of-type uint62 = 1\n for ys of-type uint62 = y\n for x of-type uint62 = y\n do (loop while (= g 1)\n do (setq x y)\n (dotimes (_ r)\n (setq y (f y)))\n (let ((k 0))\n (declare (uint62 k))\n (loop while (and (< k r) (= g 1))\n do (setq ys y)\n (dotimes (_ (min m (- r k)))\n (setq y (f y)\n q (mod (* q (abs (- x y))) n)))\n (setq g (gcd q n))\n (incf k m)))\n (setq r (ash r 1)))\n (when (= g n)\n (loop while (= g 1)\n do (setq ys (f ys)\n g (gcd (abs (- x ys)) n))))\n (when (< g n)\n (return\n (if (sb-int:positive-primep g)\n g\n (floor n g))))))))\n\n(defconstant +max+ 3000)\n(defun main ()\n (let* ((n (read))\n (pdata (make-prime-data +max+))\n (table (make-hash-table :test #'equal))\n (null-count 0))\n (declare (uint32 n null-count))\n (labels ((%factorize (s)\n (let ((factors (factorize s pdata)))\n (if (null factors)\n nil\n (let ((largest (caar factors)))\n (declare (uint62 largest))\n (cond ((< largest +max+) factors)\n ((sb-int:positive-primep largest) factors)\n ((= largest (expt (isqrt largest) 2))\n (cons (cons (isqrt largest) 2) (cdr factors)))\n (t (let* ((p1 (rho largest))\n (p2 (floor largest p1)))\n (when (< p1 p2)\n (rotatef p1 p2))\n (cons (cons p1 1) (cons (cons p2 1) (cdr factors))))))))))\n (add (factors)\n (cond ((null factors)\n (incf null-count))\n ((= 1 (cdar factors))\n (if (gethash factors table)\n (incf (car (gethash factors table)))\n (setf (gethash factors table) (cons 1 0))))\n (t\n (assert (= 2 (cdar factors)))\n (let ((factors (loop for (p . exp) of-type (uint62 . uint62) in factors\n collect (cons p (- 3 exp)))))\n (if (gethash factors table)\n (incf (cdr (gethash factors table)))\n (setf (gethash factors table) (cons 0 1))))))))\n (dotimes (i n)\n (let* ((s (read-fixnum))\n (factors (loop for (p . exp) of-type (uint62 . uint62) in (%factorize s)\n unless (zerop (mod exp 3))\n collect (cons p (mod exp 3)))))\n (add factors)))\n #>null-count\n (println\n (+ (min null-count 1)\n (loop for (count1 . count2) being each hash-value of table\n sum (max count1 count2)))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n1\n2\n3\n4\n5\n6\n7\n8\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n2\n4\n8\n16\n32\n64\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\"\n \"9\n\")))\n", "problem_context": "Score : 1100 points\n\nProblem Statement\n\nSnuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.\n\nHe will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.\n\nFind the maximum number of integers that Snuke can circle.\n\nConstraints\n\n1 ≦ N ≦ 10^5\n\n1 ≦ s_i ≦ 10^{10}\n\nAll input values are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\ns_1\n:\ns_N\n\nOutput\n\nPrint the maximum number of integers that Snuke can circle.\n\nSample Input 1\n\n8\n1\n2\n3\n4\n5\n6\n7\n8\n\nSample Output 1\n\n6\n\nSnuke can circle 1,2,3,5,6,7.\n\nSample Input 2\n\n6\n2\n4\n8\n16\n32\n64\n\nSample Output 2\n\n3\n\nSample Input 3\n\n10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\nSample Output 3\n\n9", "sample_input": "8\n1\n2\n3\n4\n5\n6\n7\n8\n"}, "reference_outputs": ["6\n"], "source_document_id": "p04022", "source_text": "Score : 1100 points\n\nProblem Statement\n\nSnuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.\n\nHe will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.\n\nFind the maximum number of integers that Snuke can circle.\n\nConstraints\n\n1 ≦ N ≦ 10^5\n\n1 ≦ s_i ≦ 10^{10}\n\nAll input values are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\ns_1\n:\ns_N\n\nOutput\n\nPrint the maximum number of integers that Snuke can circle.\n\nSample Input 1\n\n8\n1\n2\n3\n4\n5\n6\n7\n8\n\nSample Output 1\n\n6\n\nSnuke can circle 1,2,3,5,6,7.\n\nSample Input 2\n\n6\n2\n4\n8\n16\n32\n64\n\nSample Output 2\n\n3\n\nSample Input 3\n\n10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999\n\nSample Output 3\n\n9", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11881, "cpu_time_ms": 5256, "memory_kb": 68324}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s820443715", "group_id": "codeNet:p04025", "input_text": ";;; body\n\n(defconstant +inf+ 10000000)\n\n(defun main ()\n (let ((n (read)))\n (declare ((unsigned-byte 8) n))\n (let ((a (loop repeat n collect (read))))\n (declare (list a))\n (princ\n (reduce #'min\n (mapcar (lambda (y)\n (reduce #'+\n (mapcar (lambda (x)\n (expt (- x y) 2))\n a)))\n (loop for y of-type (signed-byte 16) from -100 to 100 collect y))))\n (fresh-line))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1599850203, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p04025.html", "problem_id": "p04025", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04025/input.txt", "sample_output_relpath": "derived/input_output/data/p04025/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04025/Lisp/s820443715.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s820443715", "user_id": "u425762225"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": ";;; body\n\n(defconstant +inf+ 10000000)\n\n(defun main ()\n (let ((n (read)))\n (declare ((unsigned-byte 8) n))\n (let ((a (loop repeat n collect (read))))\n (declare (list a))\n (princ\n (reduce #'min\n (mapcar (lambda (y)\n (reduce #'+\n (mapcar (lambda (x)\n (expt (- x y) 2))\n a)))\n (loop for y of-type (signed-byte 16) from -100 to 100 collect y))))\n (fresh-line))))\n\n#-swank (main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nEvi has N integers a_1,a_2,..,a_N. His objective is to have N equal integers by transforming some of them.\n\nHe may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2).\n\nFind the minimum total cost to achieve his objective.\n\nConstraints\n\n1≦N≦100\n\n-100≦a_i≦100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the minimum total cost to achieve Evi's objective.\n\nSample Input 1\n\n2\n4 8\n\nSample Output 1\n\n8\n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is the minimum.\n\nSample Input 2\n\n3\n1 1 3\n\nSample Output 2\n\n3\n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note that Evi has to pay (1-2)^2 dollar separately for transforming each of the two 1s.\n\nSample Input 3\n\n3\n4 2 5\n\nSample Output 3\n\n5\n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve the total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\nSample Input 4\n\n4\n-100 -100 -100 -100\n\nSample Output 4\n\n0\n\nWithout transforming anything, Evi's objective is already achieved. Thus, the necessary cost is 0.", "sample_input": "2\n4 8\n"}, "reference_outputs": ["8\n"], "source_document_id": "p04025", "source_text": "Score : 200 points\n\nProblem Statement\n\nEvi has N integers a_1,a_2,..,a_N. His objective is to have N equal integers by transforming some of them.\n\nHe may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2).\n\nFind the minimum total cost to achieve his objective.\n\nConstraints\n\n1≦N≦100\n\n-100≦a_i≦100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the minimum total cost to achieve Evi's objective.\n\nSample Input 1\n\n2\n4 8\n\nSample Output 1\n\n8\n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is the minimum.\n\nSample Input 2\n\n3\n1 1 3\n\nSample Output 2\n\n3\n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note that Evi has to pay (1-2)^2 dollar separately for transforming each of the two 1s.\n\nSample Input 3\n\n3\n4 2 5\n\nSample Output 3\n\n5\n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve the total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\nSample Input 4\n\n4\n-100 -100 -100 -100\n\nSample Output 4\n\n0\n\nWithout transforming anything, Evi's objective is already achieved. Thus, the necessary cost is 0.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 577, "cpu_time_ms": 18, "memory_kb": 24840}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s375844521", "group_id": "codeNet:p04029", "input_text": "(let ((n (read)))\n (format t \"~A~%\"\n (/ (* n (1+ n)) 2)))\n", "language": "Lisp", "metadata": {"date": 1594406919, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p04029.html", "problem_id": "p04029", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04029/input.txt", "sample_output_relpath": "derived/input_output/data/p04029/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04029/Lisp/s375844521.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s375844521", "user_id": "u336541610"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(let ((n (read)))\n (format t \"~A~%\"\n (/ (* n (1+ n)) 2)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?\n\nConstraints\n\n1≦N≦100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the necessary number of candies in total.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\nThe answer is 1+2+3=6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n55\n\nThe sum of the integers from 1 to 10 is 55.\n\nSample Input 3\n\n1\n\nSample Output 3\n\n1\n\nOnly one child. The answer is 1 in this case.", "sample_input": "3\n"}, "reference_outputs": ["6\n"], "source_document_id": "p04029", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?\n\nConstraints\n\n1≦N≦100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the necessary number of candies in total.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\nThe answer is 1+2+3=6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n55\n\nThe sum of the integers from 1 to 10 is 55.\n\nSample Input 3\n\n1\n\nSample Output 3\n\n1\n\nOnly one child. The answer is 1 in this case.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 68, "cpu_time_ms": 14, "memory_kb": 24016}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s916679449", "group_id": "codeNet:p04029", "input_text": "(defvar N (read))\n(princ (/ (* N (1+ N)) 2))", "language": "Lisp", "metadata": {"date": 1585265043, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04029.html", "problem_id": "p04029", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04029/input.txt", "sample_output_relpath": "derived/input_output/data/p04029/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04029/Lisp/s916679449.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s916679449", "user_id": "u334552723"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(defvar N (read))\n(princ (/ (* N (1+ N)) 2))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?\n\nConstraints\n\n1≦N≦100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the necessary number of candies in total.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\nThe answer is 1+2+3=6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n55\n\nThe sum of the integers from 1 to 10 is 55.\n\nSample Input 3\n\n1\n\nSample Output 3\n\n1\n\nOnly one child. The answer is 1 in this case.", "sample_input": "3\n"}, "reference_outputs": ["6\n"], "source_document_id": "p04029", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?\n\nConstraints\n\n1≦N≦100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the necessary number of candies in total.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\nThe answer is 1+2+3=6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n55\n\nThe sum of the integers from 1 to 10 is 55.\n\nSample Input 3\n\n1\n\nSample Output 3\n\n1\n\nOnly one child. The answer is 1 in this case.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 44, "cpu_time_ms": 24, "memory_kb": 4320}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s887078860", "group_id": "codeNet:p04029", "input_text": "(defun calc (x) (/ (* x (+ x 1)) 2))\n(write (calc (read)))", "language": "Lisp", "metadata": {"date": 1499946839, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04029.html", "problem_id": "p04029", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04029/input.txt", "sample_output_relpath": "derived/input_output/data/p04029/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04029/Lisp/s887078860.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s887078860", "user_id": "u079330987"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(defun calc (x) (/ (* x (+ x 1)) 2))\n(write (calc (read)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?\n\nConstraints\n\n1≦N≦100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the necessary number of candies in total.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\nThe answer is 1+2+3=6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n55\n\nThe sum of the integers from 1 to 10 is 55.\n\nSample Input 3\n\n1\n\nSample Output 3\n\n1\n\nOnly one child. The answer is 1 in this case.", "sample_input": "3\n"}, "reference_outputs": ["6\n"], "source_document_id": "p04029", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?\n\nConstraints\n\n1≦N≦100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the necessary number of candies in total.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n6\n\nThe answer is 1+2+3=6.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n55\n\nThe sum of the integers from 1 to 10 is 55.\n\nSample Input 3\n\n1\n\nSample Output 3\n\n1\n\nOnly one child. The answer is 1 in this case.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 58, "cpu_time_ms": 115, "memory_kb": 10212}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s197173496", "group_id": "codeNet:p04030", "input_text": "(let ((s (concatenate 'list (read-line)))\n (lst '()))\n\n (loop for i in s\n if (char= i #\\0) do (push \"0\" lst)\n else if (char= i #\\1) do (push \"1\" lst)\n else do (pop lst))\n\n (format t \"~a~%\" (reverse (apply #'concatenate 'string lst))))\n", "language": "Lisp", "metadata": {"date": 1572219092, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04030.html", "problem_id": "p04030", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04030/input.txt", "sample_output_relpath": "derived/input_output/data/p04030/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04030/Lisp/s197173496.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s197173496", "user_id": "u336541610"}, "prompt_components": {"gold_output": "00\n", "input_to_evaluate": "(let ((s (concatenate 'list (read-line)))\n (lst '()))\n\n (loop for i in s\n if (char= i #\\0) do (push \"0\" lst)\n else if (char= i #\\1) do (push \"1\" lst)\n else do (pop lst))\n\n (format t \"~a~%\" (reverse (apply #'concatenate 'string lst))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nSig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the 0 key, the 1 key and the backspace key.\n\nTo begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:\n\nThe 0 key: a letter 0 will be inserted to the right of the string.\n\nThe 1 key: a letter 1 will be inserted to the right of the string.\n\nThe backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.\n\nSig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter 0 stands for the 0 key, the letter 1 stands for the 1 key and the letter B stands for the backspace key. What string is displayed in the editor now?\n\nConstraints\n\n1 ≦ |s| ≦ 10 (|s| denotes the length of s)\n\ns consists of the letters 0, 1 and B.\n\nThe correct answer is not an empty string.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the string displayed in the editor in the end.\n\nSample Input 1\n\n01B0\n\nSample Output 1\n\n00\n\nEach time the key is pressed, the string in the editor will change as follows: 0, 01, 0, 00.\n\nSample Input 2\n\n0BB1\n\nSample Output 2\n\n1\n\nEach time the key is pressed, the string in the editor will change as follows: 0, (empty), (empty), 1.", "sample_input": "01B0\n"}, "reference_outputs": ["00\n"], "source_document_id": "p04030", "source_text": "Score : 200 points\n\nProblem Statement\n\nSig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the 0 key, the 1 key and the backspace key.\n\nTo begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:\n\nThe 0 key: a letter 0 will be inserted to the right of the string.\n\nThe 1 key: a letter 1 will be inserted to the right of the string.\n\nThe backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.\n\nSig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter 0 stands for the 0 key, the letter 1 stands for the 1 key and the letter B stands for the backspace key. What string is displayed in the editor now?\n\nConstraints\n\n1 ≦ |s| ≦ 10 (|s| denotes the length of s)\n\ns consists of the letters 0, 1 and B.\n\nThe correct answer is not an empty string.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the string displayed in the editor in the end.\n\nSample Input 1\n\n01B0\n\nSample Output 1\n\n00\n\nEach time the key is pressed, the string in the editor will change as follows: 0, 01, 0, 00.\n\nSample Input 2\n\n0BB1\n\nSample Output 2\n\n1\n\nEach time the key is pressed, the string in the editor will change as follows: 0, (empty), (empty), 1.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 263, "cpu_time_ms": 100, "memory_kb": 10848}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s323128918", "group_id": "codeNet:p04030", "input_text": "(setq c 0)(setq s(read-line))(setq a\"\")\n(loop for i from(1-(length s))downto 0 do(if(char=(char s i)#\\B)(incf c)(if(> c 0)(decf c)(setq a(format nil\"~A~A\"(char s i)a)))))\n(princ a)", "language": "Lisp", "metadata": {"date": 1537865215, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04030.html", "problem_id": "p04030", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04030/input.txt", "sample_output_relpath": "derived/input_output/data/p04030/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04030/Lisp/s323128918.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s323128918", "user_id": "u657913472"}, "prompt_components": {"gold_output": "00\n", "input_to_evaluate": "(setq c 0)(setq s(read-line))(setq a\"\")\n(loop for i from(1-(length s))downto 0 do(if(char=(char s i)#\\B)(incf c)(if(> c 0)(decf c)(setq a(format nil\"~A~A\"(char s i)a)))))\n(princ a)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nSig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the 0 key, the 1 key and the backspace key.\n\nTo begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:\n\nThe 0 key: a letter 0 will be inserted to the right of the string.\n\nThe 1 key: a letter 1 will be inserted to the right of the string.\n\nThe backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.\n\nSig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter 0 stands for the 0 key, the letter 1 stands for the 1 key and the letter B stands for the backspace key. What string is displayed in the editor now?\n\nConstraints\n\n1 ≦ |s| ≦ 10 (|s| denotes the length of s)\n\ns consists of the letters 0, 1 and B.\n\nThe correct answer is not an empty string.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the string displayed in the editor in the end.\n\nSample Input 1\n\n01B0\n\nSample Output 1\n\n00\n\nEach time the key is pressed, the string in the editor will change as follows: 0, 01, 0, 00.\n\nSample Input 2\n\n0BB1\n\nSample Output 2\n\n1\n\nEach time the key is pressed, the string in the editor will change as follows: 0, (empty), (empty), 1.", "sample_input": "01B0\n"}, "reference_outputs": ["00\n"], "source_document_id": "p04030", "source_text": "Score : 200 points\n\nProblem Statement\n\nSig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the 0 key, the 1 key and the backspace key.\n\nTo begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:\n\nThe 0 key: a letter 0 will be inserted to the right of the string.\n\nThe 1 key: a letter 1 will be inserted to the right of the string.\n\nThe backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.\n\nSig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter 0 stands for the 0 key, the letter 1 stands for the 1 key and the letter B stands for the backspace key. What string is displayed in the editor now?\n\nConstraints\n\n1 ≦ |s| ≦ 10 (|s| denotes the length of s)\n\ns consists of the letters 0, 1 and B.\n\nThe correct answer is not an empty string.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the string displayed in the editor in the end.\n\nSample Input 1\n\n01B0\n\nSample Output 1\n\n00\n\nEach time the key is pressed, the string in the editor will change as follows: 0, 01, 0, 00.\n\nSample Input 2\n\n0BB1\n\nSample Output 2\n\n1\n\nEach time the key is pressed, the string in the editor will change as follows: 0, (empty), (empty), 1.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 180, "cpu_time_ms": 141, "memory_kb": 16224}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s002214794", "group_id": "codeNet:p04031", "input_text": "(defun split (string &key (delimiterp #'delimiterp))\n (loop :for beg = (position-if-not delimiterp string)\n :then (position-if-not delimiterp string :start (1+ end))\n :for end = (and beg (position-if delimiterp string :start beg))\n :when beg :collect (subseq string beg end)\n :while end))\n(defun delimiterp (c) (position c \" ,.;/\"))\n\n(defun main ()\n (let ((n (read))\n (a_list (map 'list #'parse-integer (split (read-line))))\n (x nil))\n (setq x (/ (reduce #'+ a_list) n))\n (if (>= (- x (floor x)) (- (ceiling x) x))\n (setq x (ceiling x))\n (setq x (floor x)))\n\n (princ\n (reduce\n #'+\n (map 'list #'(lambda (l) (* (- l x) (- l x))) a_list)))\n (princ #\\newline)\n\n ))\n(main)", "language": "Lisp", "metadata": {"date": 1509146405, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04031.html", "problem_id": "p04031", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04031/input.txt", "sample_output_relpath": "derived/input_output/data/p04031/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04031/Lisp/s002214794.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s002214794", "user_id": "u055459962"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(defun split (string &key (delimiterp #'delimiterp))\n (loop :for beg = (position-if-not delimiterp string)\n :then (position-if-not delimiterp string :start (1+ end))\n :for end = (and beg (position-if delimiterp string :start beg))\n :when beg :collect (subseq string beg end)\n :while end))\n(defun delimiterp (c) (position c \" ,.;/\"))\n\n(defun main ()\n (let ((n (read))\n (a_list (map 'list #'parse-integer (split (read-line))))\n (x nil))\n (setq x (/ (reduce #'+ a_list) n))\n (if (>= (- x (floor x)) (- (ceiling x) x))\n (setq x (ceiling x))\n (setq x (floor x)))\n\n (princ\n (reduce\n #'+\n (map 'list #'(lambda (l) (* (- l x) (- l x))) a_list)))\n (princ #\\newline)\n\n ))\n(main)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nEvi has N integers a_1,a_2,..,a_N. His objective is to have N equal integers by transforming some of them.\n\nHe may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2).\n\nFind the minimum total cost to achieve his objective.\n\nConstraints\n\n1≦N≦100\n\n-100≦a_i≦100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the minimum total cost to achieve Evi's objective.\n\nSample Input 1\n\n2\n4 8\n\nSample Output 1\n\n8\n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is the minimum.\n\nSample Input 2\n\n3\n1 1 3\n\nSample Output 2\n\n3\n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note that Evi has to pay (1-2)^2 dollar separately for transforming each of the two 1s.\n\nSample Input 3\n\n3\n4 2 5\n\nSample Output 3\n\n5\n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve the total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\nSample Input 4\n\n4\n-100 -100 -100 -100\n\nSample Output 4\n\n0\n\nWithout transforming anything, Evi's objective is already achieved. Thus, the necessary cost is 0.", "sample_input": "2\n4 8\n"}, "reference_outputs": ["8\n"], "source_document_id": "p04031", "source_text": "Score : 200 points\n\nProblem Statement\n\nEvi has N integers a_1,a_2,..,a_N. His objective is to have N equal integers by transforming some of them.\n\nHe may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2).\n\nFind the minimum total cost to achieve his objective.\n\nConstraints\n\n1≦N≦100\n\n-100≦a_i≦100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the minimum total cost to achieve Evi's objective.\n\nSample Input 1\n\n2\n4 8\n\nSample Output 1\n\n8\n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is the minimum.\n\nSample Input 2\n\n3\n1 1 3\n\nSample Output 2\n\n3\n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note that Evi has to pay (1-2)^2 dollar separately for transforming each of the two 1s.\n\nSample Input 3\n\n3\n4 2 5\n\nSample Output 3\n\n5\n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve the total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\nSample Input 4\n\n4\n-100 -100 -100 -100\n\nSample Output 4\n\n0\n\nWithout transforming anything, Evi's objective is already achieved. Thus, the necessary cost is 0.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 740, "cpu_time_ms": 148, "memory_kb": 18784}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s521967133", "group_id": "codeNet:p04031", "input_text": "(defmacro avg (list)\n `(/ (apply #'+ ,list)\n (length ,list)))\n\n(defun nearest (n)\n (values (floor (+ 0.5 n))))\n\n(defparameter a nil)\n(dotimes (i (read))\n (setf a (cons (read) a)))\n(defparameter avg_a (nearest (avg a)))\n \n(defparameter cost 0)\n(print (dolist (i a cost)\n (incf cost (expt (- i avg_a) 2))))\n(terpri)\n", "language": "Lisp", "metadata": {"date": 1471138878, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04031.html", "problem_id": "p04031", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04031/input.txt", "sample_output_relpath": "derived/input_output/data/p04031/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04031/Lisp/s521967133.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s521967133", "user_id": "u328322317"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(defmacro avg (list)\n `(/ (apply #'+ ,list)\n (length ,list)))\n\n(defun nearest (n)\n (values (floor (+ 0.5 n))))\n\n(defparameter a nil)\n(dotimes (i (read))\n (setf a (cons (read) a)))\n(defparameter avg_a (nearest (avg a)))\n \n(defparameter cost 0)\n(print (dolist (i a cost)\n (incf cost (expt (- i avg_a) 2))))\n(terpri)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nEvi has N integers a_1,a_2,..,a_N. His objective is to have N equal integers by transforming some of them.\n\nHe may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2).\n\nFind the minimum total cost to achieve his objective.\n\nConstraints\n\n1≦N≦100\n\n-100≦a_i≦100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the minimum total cost to achieve Evi's objective.\n\nSample Input 1\n\n2\n4 8\n\nSample Output 1\n\n8\n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is the minimum.\n\nSample Input 2\n\n3\n1 1 3\n\nSample Output 2\n\n3\n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note that Evi has to pay (1-2)^2 dollar separately for transforming each of the two 1s.\n\nSample Input 3\n\n3\n4 2 5\n\nSample Output 3\n\n5\n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve the total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\nSample Input 4\n\n4\n-100 -100 -100 -100\n\nSample Output 4\n\n0\n\nWithout transforming anything, Evi's objective is already achieved. Thus, the necessary cost is 0.", "sample_input": "2\n4 8\n"}, "reference_outputs": ["8\n"], "source_document_id": "p04031", "source_text": "Score : 200 points\n\nProblem Statement\n\nEvi has N integers a_1,a_2,..,a_N. His objective is to have N equal integers by transforming some of them.\n\nHe may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2).\n\nFind the minimum total cost to achieve his objective.\n\nConstraints\n\n1≦N≦100\n\n-100≦a_i≦100\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\na_1 a_2 ... a_N\n\nOutput\n\nPrint the minimum total cost to achieve Evi's objective.\n\nSample Input 1\n\n2\n4 8\n\nSample Output 1\n\n8\n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is the minimum.\n\nSample Input 2\n\n3\n1 1 3\n\nSample Output 2\n\n3\n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note that Evi has to pay (1-2)^2 dollar separately for transforming each of the two 1s.\n\nSample Input 3\n\n3\n4 2 5\n\nSample Output 3\n\n5\n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve the total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\nSample Input 4\n\n4\n-100 -100 -100 -100\n\nSample Output 4\n\n0\n\nWithout transforming anything, Evi's objective is already achieved. Thus, the necessary cost is 0.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 337, "cpu_time_ms": 1641, "memory_kb": 12512}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s150398949", "group_id": "codeNet:p04032", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((s (read-line))\n (prevs (make-array 26 :element-type 'int32 :initial-element #x-80000000)))\n (dotimes (i (length s))\n (let ((c (- (char-code (aref s i)) 97)))\n (if (>= (- i (aref prevs c)) 3)\n (setf (aref prevs c) i)\n (progn\n (format t \"~D ~D~%\" (+ 1 (aref prevs c)) (+ 1 i))\n (return-from main)))))\n (write-line \"-1 -1\")))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1564696929, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04032.html", "problem_id": "p04032", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04032/input.txt", "sample_output_relpath": "derived/input_output/data/p04032/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04032/Lisp/s150398949.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s150398949", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2 5\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (ql:quickload '(:cl-debug-print :fiveam))\n #-swank (set-dispatch-macro-character #\\# #\\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((s (read-line))\n (prevs (make-array 26 :element-type 'int32 :initial-element #x-80000000)))\n (dotimes (i (length s))\n (let ((c (- (char-code (aref s i)) 97)))\n (if (>= (- i (aref prevs c)) 3)\n (setf (aref prevs c) i)\n (progn\n (format t \"~D ~D~%\" (+ 1 (aref prevs c)) (+ 1 i))\n (return-from main)))))\n (write-line \"-1 -1\")))\n\n#-swank (main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nGiven a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both voodoo and melee are unbalanced, while neither noon nor a is.\n\nYou are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.\n\nConstraints\n\n2 ≦ |s| ≦ 10^5\n\ns consists of lowercase letters.\n\nPartial Score\n\n200 points will be awarded for passing the test set satisfying 2 ≦ N ≦ 100.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\ns\n\nOutput\n\nIf there exists no unbalanced substring of s, print -1 -1.\n\nIf there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print a b. If there exists more than one such substring, any of them will be accepted.\n\nSample Input 1\n\nneeded\n\nSample Output 1\n\n2 5\n\nThe string s_2 s_3 s_4 s_5 = eede is unbalanced. There are also other unbalanced substrings. For example, the output 2 6 will also be accepted.\n\nSample Input 2\n\natcoder\n\nSample Output 2\n\n-1 -1\n\nThe string atcoder contains no unbalanced substring.", "sample_input": "needed\n"}, "reference_outputs": ["2 5\n"], "source_document_id": "p04032", "source_text": "Score : 400 points\n\nProblem Statement\n\nGiven a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both voodoo and melee are unbalanced, while neither noon nor a is.\n\nYou are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.\n\nConstraints\n\n2 ≦ |s| ≦ 10^5\n\ns consists of lowercase letters.\n\nPartial Score\n\n200 points will be awarded for passing the test set satisfying 2 ≦ N ≦ 100.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\ns\n\nOutput\n\nIf there exists no unbalanced substring of s, print -1 -1.\n\nIf there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print a b. If there exists more than one such substring, any of them will be accepted.\n\nSample Input 1\n\nneeded\n\nSample Output 1\n\n2 5\n\nThe string s_2 s_3 s_4 s_5 = eede is unbalanced. There are also other unbalanced substrings. For example, the output 2 6 will also be accepted.\n\nSample Input 2\n\natcoder\n\nSample Output 2\n\n-1 -1\n\nThe string atcoder contains no unbalanced substring.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1711, "cpu_time_ms": 391, "memory_kb": 31716}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s588539692", "group_id": "codeNet:p04033", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((a (read))\n (b (read)))\n (write-line\n (cond ((<= a 0 b) \"Zero\")\n ((>= a 0) \"Positive\")\n ((evenp (abs a)) \"Positive\")\n (t \"Negative\")))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 3\n\"\n \"Positive\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"-3 -1\n\"\n \"Negative\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"-1 1\n\"\n \"Zero\n\")))\n", "language": "Lisp", "metadata": {"date": 1584914589, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04033.html", "problem_id": "p04033", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04033/input.txt", "sample_output_relpath": "derived/input_output/data/p04033/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04033/Lisp/s588539692.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s588539692", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Positive\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((a (read))\n (b (read)))\n (write-line\n (cond ((<= a 0 b) \"Zero\")\n ((>= a 0) \"Positive\")\n ((evenp (abs a)) \"Positive\")\n (t \"Negative\")))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 3\n\"\n \"Positive\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"-3 -1\n\"\n \"Negative\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"-1 1\n\"\n \"Zero\n\")))\n", "problem_context": "Problem Statement\n\nYou are given two integers a and b (a≤b). Determine if the product of the integers a, a+1, …, b is positive, negative or zero.\n\nConstraints\n\na and b are integers.\n\n-10^9≤a≤b≤10^9\n\nPartial Score\n\nIn test cases worth 100 points, -10≤a≤b≤10.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf the product is positive, print Positive. If it is negative, print Negative. If it is zero, print Zero.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\nPositive\n\n1×2×3=6 is positive.\n\nSample Input 2\n\n-3 -1\n\nSample Output 2\n\nNegative\n\n(-3)×(-2)×(-1)=-6 is negative.\n\nSample Input 3\n\n-1 1\n\nSample Output 3\n\nZero\n\n(-1)×0×1=0.", "sample_input": "1 3\n"}, "reference_outputs": ["Positive\n"], "source_document_id": "p04033", "source_text": "Problem Statement\n\nYou are given two integers a and b (a≤b). Determine if the product of the integers a, a+1, …, b is positive, negative or zero.\n\nConstraints\n\na and b are integers.\n\n-10^9≤a≤b≤10^9\n\nPartial Score\n\nIn test cases worth 100 points, -10≤a≤b≤10.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf the product is positive, print Positive. If it is negative, print Negative. If it is zero, print Zero.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\nPositive\n\n1×2×3=6 is positive.\n\nSample Input 2\n\n-3 -1\n\nSample Output 2\n\nNegative\n\n(-3)×(-2)×(-1)=-6 is negative.\n\nSample Input 3\n\n-1 1\n\nSample Output 3\n\nZero\n\n(-1)×0×1=0.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3808, "cpu_time_ms": 33, "memory_kb": 7012}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s497770179", "group_id": "codeNet:p04033", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (let* ((a (read))\n (b (read)))\n (println\n (cond ((<= (* a b) 0) \"Zero\")\n ((and (< b 0)\n (evenp (- b a))) \"Negative\")\n (t \"Positive\")))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1551315424, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04033.html", "problem_id": "p04033", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04033/input.txt", "sample_output_relpath": "derived/input_output/data/p04033/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04033/Lisp/s497770179.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s497770179", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Positive\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(defmacro println (obj &optional (stream '*standard-output*))\n `(let ((*read-default-float-format* 'double-float))\n (prog1 (princ ,obj ,stream) (terpri ,stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Hauptteil\n\n(defun main ()\n (let* ((a (read))\n (b (read)))\n (println\n (cond ((<= (* a b) 0) \"Zero\")\n ((and (< b 0)\n (evenp (- b a))) \"Negative\")\n (t \"Positive\")))))\n\n#-swank(main)\n", "problem_context": "Problem Statement\n\nYou are given two integers a and b (a≤b). Determine if the product of the integers a, a+1, …, b is positive, negative or zero.\n\nConstraints\n\na and b are integers.\n\n-10^9≤a≤b≤10^9\n\nPartial Score\n\nIn test cases worth 100 points, -10≤a≤b≤10.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf the product is positive, print Positive. If it is negative, print Negative. If it is zero, print Zero.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\nPositive\n\n1×2×3=6 is positive.\n\nSample Input 2\n\n-3 -1\n\nSample Output 2\n\nNegative\n\n(-3)×(-2)×(-1)=-6 is negative.\n\nSample Input 3\n\n-1 1\n\nSample Output 3\n\nZero\n\n(-1)×0×1=0.", "sample_input": "1 3\n"}, "reference_outputs": ["Positive\n"], "source_document_id": "p04033", "source_text": "Problem Statement\n\nYou are given two integers a and b (a≤b). Determine if the product of the integers a, a+1, …, b is positive, negative or zero.\n\nConstraints\n\na and b are integers.\n\n-10^9≤a≤b≤10^9\n\nPartial Score\n\nIn test cases worth 100 points, -10≤a≤b≤10.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf the product is positive, print Positive. If it is negative, print Negative. If it is zero, print Zero.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\nPositive\n\n1×2×3=6 is positive.\n\nSample Input 2\n\n-3 -1\n\nSample Output 2\n\nNegative\n\n(-3)×(-2)×(-1)=-6 is negative.\n\nSample Input 3\n\n-1 1\n\nSample Output 3\n\nZero\n\n(-1)×0×1=0.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1138, "cpu_time_ms": 206, "memory_kb": 16352}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s720469154", "group_id": "codeNet:p04033", "input_text": "(let* ((a (read))\n (b (read))\n (zp (or (and (minusp a) (plusp b))\n (zerop a)\n (zerop b)))\n (nm (if (minusp a)\n (if (minusp b)\n (abs (- b a))\n (abs a))\n 0)))\n (format t \"~A~%\"\n (cond\n (zp \"Zero\")\n ((or (zerop nm)\n (and (minusp a) (oddp nm))\n (and (plusp a) (evenp nm)))\n \"Positive\")\n ((or (and (minusp a) (evenp nm))\n (and (plusp a) (oddp nm))) \"Negative\"))))", "language": "Lisp", "metadata": {"date": 1513275451, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04033.html", "problem_id": "p04033", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04033/input.txt", "sample_output_relpath": "derived/input_output/data/p04033/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04033/Lisp/s720469154.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s720469154", "user_id": "u275710783"}, "prompt_components": {"gold_output": "Positive\n", "input_to_evaluate": "(let* ((a (read))\n (b (read))\n (zp (or (and (minusp a) (plusp b))\n (zerop a)\n (zerop b)))\n (nm (if (minusp a)\n (if (minusp b)\n (abs (- b a))\n (abs a))\n 0)))\n (format t \"~A~%\"\n (cond\n (zp \"Zero\")\n ((or (zerop nm)\n (and (minusp a) (oddp nm))\n (and (plusp a) (evenp nm)))\n \"Positive\")\n ((or (and (minusp a) (evenp nm))\n (and (plusp a) (oddp nm))) \"Negative\"))))", "problem_context": "Problem Statement\n\nYou are given two integers a and b (a≤b). Determine if the product of the integers a, a+1, …, b is positive, negative or zero.\n\nConstraints\n\na and b are integers.\n\n-10^9≤a≤b≤10^9\n\nPartial Score\n\nIn test cases worth 100 points, -10≤a≤b≤10.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf the product is positive, print Positive. If it is negative, print Negative. If it is zero, print Zero.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\nPositive\n\n1×2×3=6 is positive.\n\nSample Input 2\n\n-3 -1\n\nSample Output 2\n\nNegative\n\n(-3)×(-2)×(-1)=-6 is negative.\n\nSample Input 3\n\n-1 1\n\nSample Output 3\n\nZero\n\n(-1)×0×1=0.", "sample_input": "1 3\n"}, "reference_outputs": ["Positive\n"], "source_document_id": "p04033", "source_text": "Problem Statement\n\nYou are given two integers a and b (a≤b). Determine if the product of the integers a, a+1, …, b is positive, negative or zero.\n\nConstraints\n\na and b are integers.\n\n-10^9≤a≤b≤10^9\n\nPartial Score\n\nIn test cases worth 100 points, -10≤a≤b≤10.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf the product is positive, print Positive. If it is negative, print Negative. If it is zero, print Zero.\n\nSample Input 1\n\n1 3\n\nSample Output 1\n\nPositive\n\n1×2×3=6 is positive.\n\nSample Input 2\n\n-3 -1\n\nSample Output 2\n\nNegative\n\n(-3)×(-2)×(-1)=-6 is negative.\n\nSample Input 3\n\n-1 1\n\nSample Output 3\n\nZero\n\n(-1)×0×1=0.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 523, "cpu_time_ms": 136, "memory_kb": 13412}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s407434200", "group_id": "codeNet:p04034", "input_text": "(let* ((n (read))\n (m (read))\n (c (make-array `(,(1+ n)) :initial-element 1))\n (ans (make-array `(,(1+ n)) :initial-element nil)))\n (setf (aref ans 1) t)\n (loop :for i :from 1 :to m\n ;:do (format t \"~A~%\" ans)\n ;:do (format t \"~A~%\" c)\n :do (let ((x (read))\n (y (read)))\n (decf (aref c x))\n (incf (aref c y))\n (when (aref ans x)\n (setf (aref ans y) t)\n (when (= (aref c x) 0)\n (setf (aref ans x) nil)))))\n ;(format t \"~A~%\" ans)\n ;(format t \"~A~%\" c)\n (format t \"~A~%\" (loop :for i :from 1 :to n\n :sum (if (aref ans i) 1 0))))\n", "language": "Lisp", "metadata": {"date": 1593485737, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p04034.html", "problem_id": "p04034", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04034/input.txt", "sample_output_relpath": "derived/input_output/data/p04034/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04034/Lisp/s407434200.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s407434200", "user_id": "u608227593"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (c (make-array `(,(1+ n)) :initial-element 1))\n (ans (make-array `(,(1+ n)) :initial-element nil)))\n (setf (aref ans 1) t)\n (loop :for i :from 1 :to m\n ;:do (format t \"~A~%\" ans)\n ;:do (format t \"~A~%\" c)\n :do (let ((x (read))\n (y (read)))\n (decf (aref c x))\n (incf (aref c y))\n (when (aref ans x)\n (setf (aref ans y) t)\n (when (= (aref c x) 0)\n (setf (aref ans x) nil)))))\n ;(format t \"~A~%\" ans)\n ;(format t \"~A~%\" c)\n (format t \"~A~%\" (loop :for i :from 1 :to n\n :sum (if (aref ans i) 1 0))))\n", "problem_context": "Problem Statement\n\nWe have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball.\n\nSnuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i.\n\nFind the number of boxes that may contain the red ball after all operations are performed.\n\nConstraints\n\n2≤N≤10^5\n\n1≤M≤10^5\n\n1≤x_i,y_i≤N\n\nx_i≠y_i\n\nJust before the i-th operation is performed, box x_i contains at least 1 ball.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN M\nx_1 y_1\n:\nx_M y_M\n\nOutput\n\nPrint the number of boxes that may contain the red ball after all operations are performed.\n\nSample Input 1\n\n3 2\n1 2\n2 3\n\nSample Output 1\n\n2\n\nJust after the first operation, box 1 is empty, box 2 contains one red ball and one white ball, and box 3 contains one white ball.\n\nNow, consider the second operation. If Snuke picks the red ball from box 2, the red ball will go into box 3. If he picks the white ball instead, the red ball will stay in box 2.\nThus, the number of boxes that may contain the red ball after all operations, is 2.\n\nSample Input 2\n\n3 3\n1 2\n2 3\n2 3\n\nSample Output 2\n\n1\n\nAll balls will go into box 3.\n\nSample Input 3\n\n4 4\n1 2\n2 3\n4 1\n3 4\n\nSample Output 3\n\n3", "sample_input": "3 2\n1 2\n2 3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p04034", "source_text": "Problem Statement\n\nWe have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball.\n\nSnuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i.\n\nFind the number of boxes that may contain the red ball after all operations are performed.\n\nConstraints\n\n2≤N≤10^5\n\n1≤M≤10^5\n\n1≤x_i,y_i≤N\n\nx_i≠y_i\n\nJust before the i-th operation is performed, box x_i contains at least 1 ball.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN M\nx_1 y_1\n:\nx_M y_M\n\nOutput\n\nPrint the number of boxes that may contain the red ball after all operations are performed.\n\nSample Input 1\n\n3 2\n1 2\n2 3\n\nSample Output 1\n\n2\n\nJust after the first operation, box 1 is empty, box 2 contains one red ball and one white ball, and box 3 contains one white ball.\n\nNow, consider the second operation. If Snuke picks the red ball from box 2, the red ball will go into box 3. If he picks the white ball instead, the red ball will stay in box 2.\nThus, the number of boxes that may contain the red ball after all operations, is 2.\n\nSample Input 2\n\n3 3\n1 2\n2 3\n2 3\n\nSample Output 2\n\n1\n\nAll balls will go into box 3.\n\nSample Input 3\n\n4 4\n1 2\n2 3\n4 1\n3 4\n\nSample Output 3\n\n3", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 698, "cpu_time_ms": 187, "memory_kb": 78704}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s075893739", "group_id": "codeNet:p04043", "input_text": "(setq li (list (read) (read) (read)))\n(setq cnt5 0)\n(setq cnt7 0)\n\n(setq num (car li))\n(if (= num 5) (setq cnt5 (+ cnt5 1)) ())\n(if (= num 7) (setq cnt7 (+ cnt7 1)) ())\n\n(setq num (car (cdr li)))\n(if (= num 5) (setq cnt5 (+ cnt5 1)) ())\n(if (= num 7) (setq cnt7 (+ cnt7 1)) ())\n\n(setq num (car (cdr (cdr li))))\n(if (= num 5) (setq cnt5 (+ cnt5 1)) ())\n(if (= num 7) (setq cnt7 (+ cnt7 1)) ())\n\n(princ (if (and (= cnt5 2) (= cnt7 1)) \"YES\" \"NO\"))", "language": "Lisp", "metadata": {"date": 1598229544, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p04043.html", "problem_id": "p04043", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04043/input.txt", "sample_output_relpath": "derived/input_output/data/p04043/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04043/Lisp/s075893739.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s075893739", "user_id": "u818498408"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(setq li (list (read) (read) (read)))\n(setq cnt5 0)\n(setq cnt7 0)\n\n(setq num (car li))\n(if (= num 5) (setq cnt5 (+ cnt5 1)) ())\n(if (= num 7) (setq cnt7 (+ cnt7 1)) ())\n\n(setq num (car (cdr li)))\n(if (= num 5) (setq cnt5 (+ cnt5 1)) ())\n(if (= num 7) (setq cnt7 (+ cnt7 1)) ())\n\n(setq num (car (cdr (cdr li))))\n(if (= num 5) (setq cnt5 (+ cnt5 1)) ())\n(if (= num 7) (setq cnt7 (+ cnt7 1)) ())\n\n(princ (if (and (= cnt5 2) (= cnt7 1)) \"YES\" \"NO\"))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIroha loves Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.\n\nTo create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.\n\nConstraints\n\n1≦A,B,C≦10\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf it is possible to construct a Haiku by using each of the phrases once, print YES (case-sensitive). Otherwise, print NO.\n\nSample Input 1\n\n5 5 7\n\nSample Output 1\n\nYES\n\nUsing three phrases of length 5, 5 and 7, it is possible to construct a Haiku.\n\nSample Input 2\n\n7 7 5\n\nSample Output 2\n\nNO", "sample_input": "5 5 7\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p04043", "source_text": "Score : 100 points\n\nProblem Statement\n\nIroha loves Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.\n\nTo create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.\n\nConstraints\n\n1≦A,B,C≦10\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nIf it is possible to construct a Haiku by using each of the phrases once, print YES (case-sensitive). Otherwise, print NO.\n\nSample Input 1\n\n5 5 7\n\nSample Output 1\n\nYES\n\nUsing three phrases of length 5, 5 and 7, it is possible to construct a Haiku.\n\nSample Input 2\n\n7 7 5\n\nSample Output 2\n\nNO", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 445, "cpu_time_ms": 18, "memory_kb": 24340}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s010554707", "group_id": "codeNet:p04046", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defconstant +binom-size+ 200000)\n(defconstant +binom-mod+ #.(+ (expt 10 9) 7))\n\n(declaim ((simple-array (unsigned-byte 32) (*)) *fact* *fact-inv* *inv*))\n(defparameter *fact* (make-array +binom-size+ :element-type '(unsigned-byte 32)))\n(defparameter *fact-inv* (make-array +binom-size+ :element-type '(unsigned-byte 32)))\n(defparameter *inv* (make-array +binom-size+ :element-type '(unsigned-byte 32)))\n\n(defun initialize-binom ()\n (setf (aref *fact* 0) 1\n (aref *fact* 1) 1\n (aref *fact-inv* 0) 1\n (aref *fact-inv* 1) 1\n (aref *inv* 1) 1)\n (loop for i from 2 below +binom-size+\n do (setf (aref *fact* i) (mod (* i (aref *fact* (- i 1))) +binom-mod+)\n (aref *inv* i) (mod (- (* (aref *inv* (rem +binom-mod+ i))\n (floor +binom-mod+ i)))\n +binom-mod+)\n (aref *fact-inv* i) (mod (* (aref *inv* i)\n (aref *fact-inv* (- i 1)))\n +binom-mod+))))\n\n(initialize-binom)\n\n(declaim (inline binom))\n(defun binom (n k)\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (mod (* (aref *fact* n)\n (mod (* (aref *fact-inv* k) (aref *fact-inv* (- n k))) +binom-mod+))\n +binom-mod+)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((h (read))\n (w (read))\n (a (read))\n (b (read))\n (res 0))\n (declare (uint31 h w a b res))\n (loop for j from (+ b 1) to w\n do (setf res (mod (+ res\n (mod (* (binom (+ (- h a 1) (- j 1)) (- j 1))\n (binom (+ (- a 1) (- w j)) (- w j)))\n +mod+))\n +mod+)))\n (println res)))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1555720038, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04046.html", "problem_id": "p04046", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04046/input.txt", "sample_output_relpath": "derived/input_output/data/p04046/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04046/Lisp/s010554707.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s010554707", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defparameter OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0)))\n #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n;; BEGIN_INSERTED_CONTENTS\n(defconstant +binom-size+ 200000)\n(defconstant +binom-mod+ #.(+ (expt 10 9) 7))\n\n(declaim ((simple-array (unsigned-byte 32) (*)) *fact* *fact-inv* *inv*))\n(defparameter *fact* (make-array +binom-size+ :element-type '(unsigned-byte 32)))\n(defparameter *fact-inv* (make-array +binom-size+ :element-type '(unsigned-byte 32)))\n(defparameter *inv* (make-array +binom-size+ :element-type '(unsigned-byte 32)))\n\n(defun initialize-binom ()\n (setf (aref *fact* 0) 1\n (aref *fact* 1) 1\n (aref *fact-inv* 0) 1\n (aref *fact-inv* 1) 1\n (aref *inv* 1) 1)\n (loop for i from 2 below +binom-size+\n do (setf (aref *fact* i) (mod (* i (aref *fact* (- i 1))) +binom-mod+)\n (aref *inv* i) (mod (- (* (aref *inv* (rem +binom-mod+ i))\n (floor +binom-mod+ i)))\n +binom-mod+)\n (aref *fact-inv* i) (mod (* (aref *inv* i)\n (aref *fact-inv* (- i 1)))\n +binom-mod+))))\n\n(initialize-binom)\n\n(declaim (inline binom))\n(defun binom (n k)\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (mod (* (aref *fact* n)\n (mod (* (aref *fact-inv* k) (aref *fact-inv* (- n k))) +binom-mod+))\n +binom-mod+)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;; Body\n\n(defun main ()\n (let* ((h (read))\n (w (read))\n (a (read))\n (b (read))\n (res 0))\n (declare (uint31 h w a b res))\n (loop for j from (+ b 1) to w\n do (setf res (mod (+ res\n (mod (* (binom (+ (- h a 1) (- j 1)) (- j 1))\n (binom (+ (- a 1) (- w j)) (- w j)))\n +mod+))\n +mod+)))\n (println res)))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have a large square grid with H rows and W columns.\nIroha is now standing in the top-left cell.\nShe will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.\n\nHowever, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells.\n\nFind the number of ways she can travel to the bottom-right cell.\n\nSince this number can be extremely large, print the number modulo 10^9+7.\n\nConstraints\n\n1 ≦ H, W ≦ 100,000\n\n1 ≦ A < H\n\n1 ≦ B < W\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nH W A B\n\nOutput\n\nPrint the number of ways she can travel to the bottom-right cell, modulo 10^9+7.\n\nSample Input 1\n\n2 3 1 1\n\nSample Output 1\n\n2\n\nWe have a 2×3 grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: \"Right, Right, Down\" and \"Right, Down, Right\".\n\nSample Input 2\n\n10 7 3 4\n\nSample Output 2\n\n3570\n\nThere are 12 forbidden cells.\n\nSample Input 3\n\n100000 100000 99999 99999\n\nSample Output 3\n\n1\n\nSample Input 4\n\n100000 100000 44444 55555\n\nSample Output 4\n\n738162020", "sample_input": "2 3 1 1\n"}, "reference_outputs": ["2\n"], "source_document_id": "p04046", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have a large square grid with H rows and W columns.\nIroha is now standing in the top-left cell.\nShe will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.\n\nHowever, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells.\n\nFind the number of ways she can travel to the bottom-right cell.\n\nSince this number can be extremely large, print the number modulo 10^9+7.\n\nConstraints\n\n1 ≦ H, W ≦ 100,000\n\n1 ≦ A < H\n\n1 ≦ B < W\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nH W A B\n\nOutput\n\nPrint the number of ways she can travel to the bottom-right cell, modulo 10^9+7.\n\nSample Input 1\n\n2 3 1 1\n\nSample Output 1\n\n2\n\nWe have a 2×3 grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: \"Right, Right, Down\" and \"Right, Down, Right\".\n\nSample Input 2\n\n10 7 3 4\n\nSample Output 2\n\n3570\n\nThere are 12 forbidden cells.\n\nSample Input 3\n\n100000 100000 99999 99999\n\nSample Output 3\n\n1\n\nSample Input 4\n\n100000 100000 44444 55555\n\nSample Output 4\n\n738162020", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3000, "cpu_time_ms": 212, "memory_kb": 25824}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s721009660", "group_id": "codeNet:p04047", "input_text": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (ls (make-array (* 2 n) :element-type 'uint32)))\n (dotimes (i (* 2 n))\n (setf (aref ls i) (read)))\n (setq ls (sort ls #'<))\n (println\n (loop for i from 0 below (* 2 n) by 2\n sum (aref ls i)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 3 1 2\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n100 1 2 3 14 15 58 58 58 29\n\"\n \"135\n\")))\n", "language": "Lisp", "metadata": {"date": 1584859891, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04047.html", "problem_id": "p04047", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04047/input.txt", "sample_output_relpath": "derived/input_output/data/p04047/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04047/Lisp/s721009660.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s721009660", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (ls (make-array (* 2 n) :element-type 'uint32)))\n (dotimes (i (* 2 n))\n (setf (aref ls i) (read)))\n (setq ls (sort ls #'<))\n (println\n (loop for i from 0 below (* 2 n) by 2\n sum (aref ls i)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"powershell.exe\" '(\"-Command\" \"Get-Clipboard\") :output out :search t)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 3 1 2\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n100 1 2 3 14 15 58 58 58 29\n\"\n \"135\n\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nSnuke is having a barbeque party.\n\nAt the party, he will make N servings of Skewer Meal.\n\nExample of a serving of Skewer Meal\n\nHe has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i.\nAlso, he has an infinite supply of ingredients.\n\nTo make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers.\nLet the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.\n\nWhat is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?\n\nConstraints\n\n1≦N≦100\n\n1≦L_i≦100\n\nFor each i, L_i is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nL_1 L_2 ... L_{2N}\n\nOutput\n\nPrint the maximum total number of ingredients that Snuke's N servings of Skewer Meal can hold.\n\nSample Input 1\n\n2\n1 3 1 2\n\nSample Output 1\n\n3\n\nIf he makes a serving using the first and third skewers, and another using the second and fourth skewers, each serving will hold 1 and 2 ingredients, for the total of 3.\n\nSample Input 2\n\n5\n100 1 2 3 14 15 58 58 58 29\n\nSample Output 2\n\n135", "sample_input": "2\n1 3 1 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p04047", "source_text": "Score : 200 points\n\nProblem Statement\n\nSnuke is having a barbeque party.\n\nAt the party, he will make N servings of Skewer Meal.\n\nExample of a serving of Skewer Meal\n\nHe has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i.\nAlso, he has an infinite supply of ingredients.\n\nTo make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers.\nLet the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.\n\nWhat is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?\n\nConstraints\n\n1≦N≦100\n\n1≦L_i≦100\n\nFor each i, L_i is an integer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nL_1 L_2 ... L_{2N}\n\nOutput\n\nPrint the maximum total number of ingredients that Snuke's N servings of Skewer Meal can hold.\n\nSample Input 1\n\n2\n1 3 1 2\n\nSample Output 1\n\n3\n\nIf he makes a serving using the first and third skewers, and another using the second and fourth skewers, each serving will hold 1 and 2 ingredients, for the total of 3.\n\nSample Input 2\n\n5\n100 1 2 3 14 15 58 58 58 29\n\nSample Output 2\n\n135", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3812, "cpu_time_ms": 185, "memory_kb": 19936}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s628131610", "group_id": "codeNet:p04049", "input_text": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n;;;\n;;; Diameter of tree\n;;;\n\n(defun find-diameter (graph)\n \"Finds a diameter of a tree. Returns three values: the length of the diameter\nand its two ends.\"\n (declare ((array list (*)) graph))\n (let ((end 0)\n (max-depth 0))\n (assert (> (length graph) 0))\n (labels ((traverse (v parent depth)\n (declare ((integer 0 #.array-total-size-limit) v parent depth))\n (when (> depth max-depth)\n (setq max-depth depth\n end v))\n (dolist (child (aref graph v))\n (declare ((integer 0 #.most-positive-fixnum) child))\n (unless (= child parent)\n (traverse child v (+ depth 1))))))\n (traverse 0 array-total-size-limit 0)\n (let ((end1 end))\n (setq max-depth 0)\n (traverse end1 array-total-size-limit 0)\n (values max-depth end1 end)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #xffffffff)\n(defun main ()\n (declare (inline sort))\n (let* ((n (read))\n (k (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n edges\n (res #xffffffff))\n (declare (uint32 n k res))\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))\n (push (cons a b) edges)))\n (when (<= (find-diameter graph) k)\n (println 0)\n (return-from main))\n (let ((k/2 (floor k 2))\n (dists (make-array n :element-type 'uint32)))\n (declare (uint32 k/2))\n (labels ((fill-dists! (v parent depth)\n (declare (int32 v parent depth))\n (setf (aref dists v) depth)\n (dolist (child (aref graph v))\n (declare (uint32 child))\n (unless (= child parent)\n (fill-dists! child v (+ depth 1)))))\n (get-max-depth (v parent)\n (let ((res (aref dists v)))\n (declare (uint32 res))\n (dolist (child (aref graph v))\n (declare (uint32 child))\n (unless (= child parent)\n (maxf res (get-max-depth child v))))\n res)))\n (if (evenp k)\n (dotimes (root n)\n (when (cdr (aref graph root)) ;; exclude one branch case\n (fill dists +inf+)\n (fill-dists! root -1 0)\n (let ((branch-depths (loop for child in (aref graph root)\n collect (get-max-depth child root))))\n (setq branch-depths (sort branch-depths\n (lambda (x y)\n (declare (uint32 x y))\n (> x y))))\n (when (>= (second branch-depths) k/2)\n (minf res (count-if (lambda (x) (> (the uint32 x) k/2)) dists))))))\n (loop\n for (root1 . root2) in edges\n when (and (car (aref graph root1))\n (car (aref graph root2)))\n do (fill dists +inf+)\n (fill-dists! root1 root2 0)\n (fill-dists! root2 root1 0)\n (let ((branch-depths1 (loop for child in (aref graph root1)\n collect (get-max-depth child root1)))\n (branch-depths2 (loop for child in (aref graph root2)\n collect (get-max-depth child root2))))\n (when (and (>= (reduce #'max branch-depths1) k/2)\n (>= (reduce #'max branch-depths2) k/2))\n (minf res (count-if (lambda (x) (> (the uint32 x) k/2)) dists))))))\n (println res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 3 1 2\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n100 1 2 3 14 15 58 58 58 29\n\"\n \"135\n\")))\n", "language": "Lisp", "metadata": {"date": 1576740365, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04049.html", "problem_id": "p04049", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04049/input.txt", "sample_output_relpath": "derived/input_output/data/p04049/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04049/Lisp/s628131610.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s628131610", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; -*- coding: utf-8 -*-\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 3) (safety 0) (debug 0))\n #'equal)\n #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)\n #-swank (set-dispatch-macro-character\n ;; enclose the form with VALUES to avoid being captured by LOOP macro\n #\\# #\\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n#-swank (disable-debugger) ; for CS Academy\n\n;; BEGIN_INSERTED_CONTENTS\n(declaim (ftype (function * (values fixnum &optional)) read-fixnum))\n(defun read-fixnum (&optional (in *standard-input*))\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\n (cond ((<= 48 byte 57)\n (return (- byte 48)))\n ((zerop byte) ; #\\Nul\n (error \"Read EOF or #\\Nul.\"))\n ((= byte #.(char-code #\\-))\n (setf minus t)))))))\n (declare ((integer 0 #.most-positive-fixnum) result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte 57)\n (setq result (+ (- byte 48)\n (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))\n (return (if minus (- result) result))))))))\n\n(macrolet ((def (name fname)\n `(define-modify-macro ,name (new-value) ,fname)))\n (def minf min)\n (def maxf max)\n (def mulf *)\n (def divf /)\n (def iorf logior)\n (def xorf logxor)\n (def andf logand))\n\n;;;\n;;; Diameter of tree\n;;;\n\n(defun find-diameter (graph)\n \"Finds a diameter of a tree. Returns three values: the length of the diameter\nand its two ends.\"\n (declare ((array list (*)) graph))\n (let ((end 0)\n (max-depth 0))\n (assert (> (length graph) 0))\n (labels ((traverse (v parent depth)\n (declare ((integer 0 #.array-total-size-limit) v parent depth))\n (when (> depth max-depth)\n (setq max-depth depth\n end v))\n (dolist (child (aref graph v))\n (declare ((integer 0 #.most-positive-fixnum) child))\n (unless (= child parent)\n (traverse child v (+ depth 1))))))\n (traverse 0 array-total-size-limit 0)\n (let ((end1 end))\n (setq max-depth 0)\n (traverse end1 array-total-size-limit 0)\n (values max-depth end1 end)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defconstant +inf+ #xffffffff)\n(defun main ()\n (declare (inline sort))\n (let* ((n (read))\n (k (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n edges\n (res #xffffffff))\n (declare (uint32 n k res))\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (push a (aref graph b))\n (push b (aref graph a))\n (push (cons a b) edges)))\n (when (<= (find-diameter graph) k)\n (println 0)\n (return-from main))\n (let ((k/2 (floor k 2))\n (dists (make-array n :element-type 'uint32)))\n (declare (uint32 k/2))\n (labels ((fill-dists! (v parent depth)\n (declare (int32 v parent depth))\n (setf (aref dists v) depth)\n (dolist (child (aref graph v))\n (declare (uint32 child))\n (unless (= child parent)\n (fill-dists! child v (+ depth 1)))))\n (get-max-depth (v parent)\n (let ((res (aref dists v)))\n (declare (uint32 res))\n (dolist (child (aref graph v))\n (declare (uint32 child))\n (unless (= child parent)\n (maxf res (get-max-depth child v))))\n res)))\n (if (evenp k)\n (dotimes (root n)\n (when (cdr (aref graph root)) ;; exclude one branch case\n (fill dists +inf+)\n (fill-dists! root -1 0)\n (let ((branch-depths (loop for child in (aref graph root)\n collect (get-max-depth child root))))\n (setq branch-depths (sort branch-depths\n (lambda (x y)\n (declare (uint32 x y))\n (> x y))))\n (when (>= (second branch-depths) k/2)\n (minf res (count-if (lambda (x) (> (the uint32 x) k/2)) dists))))))\n (loop\n for (root1 . root2) in edges\n when (and (car (aref graph root1))\n (car (aref graph root2)))\n do (fill dists +inf+)\n (fill-dists! root1 root2 0)\n (fill-dists! root2 root1 0)\n (let ((branch-depths1 (loop for child in (aref graph root1)\n collect (get-max-depth child root1)))\n (branch-depths2 (loop for child in (aref graph root2)\n collect (get-max-depth child root2))))\n (when (and (>= (reduce #'max branch-depths1) k/2)\n (>= (reduce #'max branch-depths2) k/2))\n (minf res (count-if (lambda (x) (> (the uint32 x) k/2)) dists))))))\n (println res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(defun io-equal (in-string out-string &key (function #'main) (test #'equal))\n \"Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if\nthe string output to *STANDARD-OUTPUT* is equal to OUT-STRING.\"\n (labels ((ensure-last-lf (s)\n (if (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*standard-input* (ensure-last-lf in-string))\n (funcall function)))))))\n\n#+swank\n(defun get-clipbrd ()\n (with-output-to-string (out)\n (run-program \"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe\" '(\"get-clipboard\") :output out)))\n\n#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))\n#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *this-pathname*))\n\n#+swank\n(defun run (&optional thing (out *standard-output*))\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'MAIN using the string as input.\nsymbol: alias of FIVEAM:RUN!.\npathname: run #'MAIN using the text file as input.\"\n (let ((*standard-output* out))\n (etypecase thing\n (null\n (with-input-from-string (*standard-input* (delete #\\Return (get-clipbrd)))\n (main)))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (main)))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (main))))))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)\n (format out \"\")))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 3 1 2\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n100 1 2 3 14 15 58 58 58 29\n\"\n \"135\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven an undirected tree, let the distance between vertices u and v be the\nnumber of edges on the simple path from u to v.\nThe diameter of a tree is the maximum among the distances between any two vertices.\nWe will call a tree good if and only if its diameter is at most K.\n\nYou are given an undirected tree with N vertices numbered 1 through N.\nFor each i (1≦i≦N-1), there is an edge connecting vertices A_i and B_i.\n\nYou want to remove zero or more vertices from the tree, so that the resulting tree is good.\nWhen a vertex is removed, all incident edges will also be removed.\nThe resulting graph must be connected.\n\nFind the minimum number of vertices that you need to remove in order to produce a good tree.\n\nConstraints\n\n2≦N≦2000\n\n1≦K≦N-1\n\n1≦A_i≦N, 1≦B_i≦N\n\nThe graph defined by A_i and B_i is a tree.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN K\nA_1 B_1\nA_2 B_2\n:\nA_{N-1} B_{N-1}\n\nOutput\n\nPrint the minimum number of vertices that you need to remove in order to produce a good tree.\n\nSample Input 1\n\n6 2\n1 2\n3 2\n4 2\n1 6\n5 6\n\nSample Output 1\n\n2\n\nThe tree is shown below. Removing vertices 5 and 6 will result in a good tree with the diameter of 2.\n\nSample Input 2\n\n6 5\n1 2\n3 2\n4 2\n1 6\n5 6\n\nSample Output 2\n\n0\n\nSince the given tree is already good, you do not need to remove any vertex.", "sample_input": "6 2\n1 2\n3 2\n4 2\n1 6\n5 6\n"}, "reference_outputs": ["2\n"], "source_document_id": "p04049", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven an undirected tree, let the distance between vertices u and v be the\nnumber of edges on the simple path from u to v.\nThe diameter of a tree is the maximum among the distances between any two vertices.\nWe will call a tree good if and only if its diameter is at most K.\n\nYou are given an undirected tree with N vertices numbered 1 through N.\nFor each i (1≦i≦N-1), there is an edge connecting vertices A_i and B_i.\n\nYou want to remove zero or more vertices from the tree, so that the resulting tree is good.\nWhen a vertex is removed, all incident edges will also be removed.\nThe resulting graph must be connected.\n\nFind the minimum number of vertices that you need to remove in order to produce a good tree.\n\nConstraints\n\n2≦N≦2000\n\n1≦K≦N-1\n\n1≦A_i≦N, 1≦B_i≦N\n\nThe graph defined by A_i and B_i is a tree.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN K\nA_1 B_1\nA_2 B_2\n:\nA_{N-1} B_{N-1}\n\nOutput\n\nPrint the minimum number of vertices that you need to remove in order to produce a good tree.\n\nSample Input 1\n\n6 2\n1 2\n3 2\n4 2\n1 6\n5 6\n\nSample Output 1\n\n2\n\nThe tree is shown below. Removing vertices 5 and 6 will result in a good tree with the diameter of 2.\n\nSample Input 2\n\n6 5\n1 2\n3 2\n4 2\n1 6\n5 6\n\nSample Output 2\n\n0\n\nSince the given tree is already good, you do not need to remove any vertex.", "split": "test_in_distribution", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8750, "cpu_time_ms": 440, "memory_kb": 62180}, "variant": "low_resource"}